WCSimVertexFinder.hh

Go to the documentation of this file.
00001 #ifndef WCSIMVERTEXFINDER_HH
00002 #define WCSIMVERTEXFINDER_HH
00003 
00004 #include "TObject.h"
00005 #include "TMinuit.h"
00006 
00007 #include "WCSimRecoVertex.hh"
00008 
00009 class WCSimRecoDigit;
00010 class WCSimRecoEvent;
00011 
00012 #include <vector>
00013 
00014 class WCSimVertexFinder : public TObject {
00015 
00016  public:
00017 
00018   static WCSimVertexFinder* Instance();
00019 
00020   static void PointFitOnly(Bool_t yesno = 1);
00021   static void UseTrueVertex(Bool_t yesno = 1);
00022   static void UseTruePosition(Bool_t yesno = 1);
00023   static void UseTrueDirection(Bool_t yesno = 1);
00024   static void SeedWithTrueVertex(Bool_t yesno = 1);
00025   static void SeedWithSimpleVertex(Bool_t yesno = 1);
00026   static void SeedWithQuadruples(Bool_t yesno = 1);
00027   static void NumSeeds(Int_t nseeds);
00028 
00029   static void FitWeights(Double_t tw, Double_t cw);
00030 
00031   static void FitTimeParams();
00032   static void FixTimeParams(Double_t param0);
00033 
00034   static void FitConeParams();
00035   static void FixConeParams(Double_t param0, Double_t param1, Double_t param2);  
00036   
00037   static void FixVertexBias(Double_t bias);
00038 
00039   static void PrintParameters();
00040   void RunPrintParameters();
00041 
00042   void SetPointFitOnly(Bool_t yesno) { fPointFitOnly = yesno; }
00043   void UsingTrueVertex(Bool_t yesno) { fUseTrueVertex = yesno; }
00044   void UsingTruePosition(Bool_t yesno) { fUseTruePosition = yesno; }
00045   void UsingTrueDirection(Bool_t yesno) { fUseTrueDirection = yesno; }
00046   void SeedingWithTrueVertex(Bool_t yesno) { fSeedWithTrueVertex = yesno; }
00047   void SeedingWithSimpleVertex(Bool_t yesno) { fSeedWithSimpleVertex = yesno; }
00048   void SeedingWithQuadruples(Bool_t yesno) { fSeedWithQuadruples = yesno; }
00049   void SetNumSeeds(Int_t nseeds) { if(nseeds>0) fNumSeeds = nseeds; }
00050 
00051   void SetFitTimeParams() { fFitTimeParams = 1; }
00052   void SetFixTimeParams(Double_t param0) { 
00053     fFitTimeParams = 0; fFixTimeParam0 = param0; 
00054   }
00055   
00056   void SetFitConeParams() { fFitConeParams = 1; }
00057   void SetFixConeParams(Double_t param0, Double_t param1, Double_t param2) { 
00058     fFitConeParams = 0; fFixConeParam0 = param0; fFixConeParam1 = param1; fFixConeParam2 = param2; 
00059   }
00060   
00061   void SetFitWeights(Double_t tw, Double_t cw){ 
00062     fTimeFitWeight = tw; fConeFitWeight = cw; 
00063   }
00064 
00065   void SetVertexBias(Double_t bias) { 
00066     if( bias>0.0 ){ fFixVertexBias = 1; fVertexBias = bias; } 
00067     else { fFixVertexBias = 0; fVertexBias = bias; }
00068   }
00069 
00070   // Run Vertex Fitter
00071   WCSimRecoVertex* Run(WCSimRecoEvent* event);
00072   WCSimRecoVertex* RunPointFit(WCSimRecoEvent* event);
00073   WCSimRecoVertex* RunExtendedFit(WCSimRecoEvent* event);
00074 
00075   // Run Vertex Fitter (using True Vertex)
00076   WCSimRecoVertex* RunPointFitFromTruth(WCSimRecoEvent* event);
00077   WCSimRecoVertex* RunExtendedFitFromTruth(WCSimRecoEvent* event);
00078 
00079   // Run Vertex Fitter (using Given Vertex)
00080   WCSimRecoVertex* RunPointFit(WCSimRecoEvent* event, 
00081                                 Double_t vx, Double_t vy, Double_t vz);
00082   WCSimRecoVertex* RunPointFit(WCSimRecoEvent* event, 
00083                                 Double_t vx, Double_t vy, Double_t vz,
00084                                  Double_t px, Double_t py, Double_t pz);
00085   WCSimRecoVertex* RunExtendedFit(WCSimRecoEvent* event, 
00086                                    Double_t vx, Double_t vy, Double_t vz,
00087                                     Double_t px, Double_t py, Double_t pz);
00088   WCSimRecoVertex* Run(WCSimRecoEvent* event, 
00089                         Double_t vx, Double_t vy, Double_t vz,
00090                          Double_t px, Double_t py, Double_t pz);
00091 
00092   // External Methods: Access to Vertices
00093   WCSimRecoVertex* GetSimplePosition()  { return fSimplePosition; }
00094   WCSimRecoVertex* GetSimpleDirection() { return fSimpleDirection; }
00095   WCSimRecoVertex* GetPointPosition()   { return fPointPosition; }
00096   WCSimRecoVertex* GetPointDirection()  { return fPointDirection; }
00097   WCSimRecoVertex* GetPointVertex()     { return fPointVertex; }
00098   WCSimRecoVertex* GetExtendedVertex()  { return fExtendedVertex; }
00099 
00100  private:
00101 
00102   // Internal Methods: Build True Vertex
00103   WCSimRecoVertex* BuildTrueVertex();
00104 
00105   // Internal Methods: Build Dummy Vertex
00106   WCSimRecoVertex* BuildDummyVertex();
00107 
00108   // Internal Methods: Fit the Vertex and Direction
00109   WCSimRecoVertex* FindSimplePosition();
00110   WCSimRecoVertex* FindSeedPosition();
00111   WCSimRecoVertex* FindSimpleDirection(WCSimRecoVertex* vertex);
00112   WCSimRecoVertex* FindSeedDirection(WCSimRecoVertex* vertex);
00113   WCSimRecoVertex* FitPointPosition(WCSimRecoVertex* vertex);
00114   WCSimRecoVertex* FitPointDirection(WCSimRecoVertex* vertex);
00115   WCSimRecoVertex* FitPointVertex(WCSimRecoVertex* vertex);
00116   WCSimRecoVertex* FitExtendedVertex(WCSimRecoVertex* vertex);
00117 
00118   // Internal Methods: Correct Vertex Bias 
00119   WCSimRecoVertex* CorrectExtendedVertex(WCSimRecoVertex* vertex);
00120 
00121   // Internal Methods: Fit the Vertex and Direction (using Given Vertex)
00122   WCSimRecoVertex* FixSimplePosition(Double_t vx, Double_t vy, Double_t vz);
00123   WCSimRecoVertex* FixSimpleDirection(Double_t vx, Double_t vy, Double_t vz,
00124                                       Double_t px, Double_t py, Double_t pz);
00125   WCSimRecoVertex* FixPointPosition(Double_t vx, Double_t vy, Double_t vz);
00126   WCSimRecoVertex* FixPointDirection(Double_t vx, Double_t vy, Double_t vz,
00127                                       Double_t px, Double_t py, Double_t pz);
00128   WCSimRecoVertex* FixPointVertex(Double_t vx, Double_t vy, Double_t vz,
00129                                    Double_t px, Double_t py, Double_t pz);
00130   WCSimRecoVertex* FixExtendedVertex(Double_t vx, Double_t vy, Double_t vz,
00131                                       Double_t px, Double_t py, Double_t pz);
00132 
00133   // Internal Methods: Run Fits with Minuit
00134   WCSimRecoVertex* FitPointPositionWithMinuit(WCSimRecoVertex* vertex);
00135   WCSimRecoVertex* FitPointDirectionWithMinuit(WCSimRecoVertex* vertex);
00136   WCSimRecoVertex* FitPointVertexWithMinuit(WCSimRecoVertex* vertex);
00137   WCSimRecoVertex* FitExtendedVertexWithMinuit(WCSimRecoVertex* vertex);
00138 
00139   // Internal Methods: Calculate Residuals
00140   void PointResiduals(Double_t vx, Double_t vy, Double_t vz);
00141   void PointResiduals(Double_t vx, Double_t vy, Double_t vz,
00142                       Double_t px, Double_t py, Double_t pz);
00143   void ExtendedResiduals(Double_t vx, Double_t vy, Double_t vz,
00144                           Double_t px, Double_t py, Double_t pz);
00145 
00146  public:
00147 
00148   // External Methods: Point Position Figure of Merit
00149   void PointPositionChi2(Double_t vx, Double_t vy, Double_t vz,
00150                           Double_t& vtime, Double_t& chi2);
00151   void PointPositionChi2(Double_t& vtime, Double_t& chi2);
00152 
00153   // External Methods: Point Direction Figure of Merit
00154   void PointDirectionChi2(Double_t vx, Double_t vy, Double_t vz,
00155                            Double_t px, Double_t py, Double_t pz,
00156                             Double_t& vangle, Double_t& chi2);
00157   void PointDirectionChi2(Double_t& vangle, Double_t& chi2);
00158 
00159   // External Methods: Point Vertex Figure of Merit
00160   void PointVertexChi2(Double_t vx, Double_t vy, Double_t vz,  
00161                         Double_t px, Double_t py, Double_t pz,
00162                          Double_t& vangle, Double_t& vtime, Double_t& chi2);
00163   void PointVertexChi2(Double_t& vangle, Double_t& vtime, Double_t& chi2);
00164 
00165   // External Methods: Extended Vertex Figure of Merit
00166   void ExtendedVertexChi2(Double_t vx, Double_t vy, Double_t vz,
00167                            Double_t px, Double_t py, Double_t pz,
00168                             Double_t& vangle, Double_t& vtime, Double_t& chi2);  
00169   void ExtendedVertexChi2(Double_t& vangle, Double_t& vtime, Double_t& chi2);
00170 
00171   // External Methods: Penalty Term
00172   void PenaltyChi2(Double_t vx, Double_t vy, Double_t vz, Double_t& chi2);
00173 
00174   // External Methods: Penalty Term, to Fix Vertex or Direction
00175   void FixPositionChi2(Double_t vx, Double_t vy, Double_t vz, Double_t& chi2);
00176   void FixDirectionChi2(Double_t px, Double_t py, Double_t pz, Double_t& chi2);
00177 
00178   //  External Methods: Fit Profile in Angle  
00179   void FitConePropertiesFoM(Double_t& vangle, Double_t& chi2);
00180   void ConePropertiesFoM(Double_t& chi2);
00181 
00182   void FitPointConePropertiesLnL(Double_t& vangle, Double_t& chi2);
00183   void FitExtendedConePropertiesLnL(Double_t& vangle, Double_t& chi2);
00184   void ConePropertiesLnL(Double_t vparam0, Double_t vparam1, Double_t vparam2,
00185                          Double_t& vangle, Double_t& chi2);
00186 
00187   //  External Methods: Fit Profile in Time 
00188   void FindSimpleTimeProperties(Double_t& vtime);
00189   void FitTimePropertiesFoM(Double_t& vtime, Double_t& chi2);
00190   void TimePropertiesFoM(Double_t vtime, Double_t& chi2); 
00191  
00192   void FitPointTimePropertiesLnL(Double_t& vtime, Double_t& chi2);
00193   void FitExtendedTimePropertiesLnL(Double_t& vtime, Double_t& chi2);
00194   void TimePropertiesLnL(Double_t vtime, Double_t vparam, Double_t& chi2);
00195 
00196   // Count Iterations
00197   Int_t GetIterations() { return fItr; }
00198 
00199   void time_fit_itr()        { fTimeFitItr++; }
00200   void cone_fit_itr()        { fConeFitItr++; }
00201   void point_position_itr()  { fPointPosItr++; }
00202   void point_direction_itr() { fPointDirItr++; }
00203   void point_vertex_itr()    { fPointVtxItr++; }
00204   void extended_vertex_itr() { fExtendedVtxItr++; }
00205 
00206   void time_fit_reset_itr()        { fTimeFitItr = 0; }
00207   void cone_fit_reset_itr()        { fConeFitItr = 0; }
00208   void point_position_reset_itr()  { fPointPosItr = 0; }
00209   void point_direction_reset_itr() { fPointDirItr = 0; }
00210   void point_vertex_reset_itr()    { fPointVtxItr = 0; }
00211   void extended_vertex_reset_itr() { fExtendedVtxItr = 0; }
00212 
00213   Int_t time_fit_iterations()        { return fTimeFitItr; }
00214   Int_t cone_fit_iterations()        { return fConeFitItr; }
00215   Int_t point_position_iterations()  { return fPointPosItr; }
00216   Int_t point_direction_iterations() { return fPointDirItr; }
00217   Int_t point_vertex_iterations()    { return fPointVtxItr; }
00218   Int_t extended_vertex_iterations() { return fExtendedVtxItr; }
00219 
00220   // Reset Everything
00221   void Reset();
00222 
00223  private:
00224 
00225   WCSimVertexFinder();
00226   ~WCSimVertexFinder();
00227 
00228   void Clear();
00229 
00230   Double_t fBaseFOM;
00231   Bool_t fPointFitOnly;
00232   Bool_t fUseTrueVertex;
00233   Bool_t fUseTruePosition;
00234   Bool_t fUseTrueDirection;
00235   Bool_t fSeedWithTrueVertex;
00236   Bool_t fSeedWithSimpleVertex;
00237   Bool_t fSeedWithQuadruples;
00238   Int_t fNumSeeds;
00239 
00240   Double_t fTimeFitWeight;
00241   Double_t fConeFitWeight;
00242 
00243   Bool_t fFixVertexBias;
00244   Double_t fVertexBias;
00245 
00246   Double_t fInputVtxX;
00247   Double_t fInputVtxY;
00248   Double_t fInputVtxZ;
00249   Double_t fInputVtxTime;
00250 
00251   Double_t fInputDirX;
00252   Double_t fInputDirY;
00253   Double_t fInputDirZ;
00254 
00255   Double_t fInputVtxFOM;
00256   
00257   WCSimRecoVertex* fSimplePosition;
00258   WCSimRecoVertex* fSimpleDirection;
00259   WCSimRecoVertex* fPointPosition;
00260   WCSimRecoVertex* fPointDirection;
00261   WCSimRecoVertex* fPointVertex;
00262   WCSimRecoVertex* fExtendedVertex;
00263 
00264   TMinuit* fMinuitPointPosition;
00265   TMinuit* fMinuitPointDirection;
00266   TMinuit* fMinuitPointVertex; 
00267   TMinuit* fMinuitExtendedVertex; 
00268 
00269   TMinuit* fMinuitTimeFit;
00270   TMinuit* fMinuitConeFit;
00271 
00272   Bool_t fPass;
00273   Int_t fItr;
00274   
00275   Int_t fTimeFitItr;
00276   Int_t fConeFitItr;
00277   Int_t fPointPosItr;
00278   Int_t fPointDirItr;
00279   Int_t fPointVtxItr;
00280   Int_t fExtendedVtxItr;
00281 
00282   Double_t fSconeA;
00283   Double_t fSconeB;
00284   Double_t fSmu;
00285   Double_t fSel;
00286   Bool_t fIntegralsDone;
00287 
00288   std::vector<WCSimRecoVertex*> vVertexList;
00289 
00290  public:  
00291 
00292   Double_t fVtxX;
00293   Double_t fVtxY;
00294   Double_t fVtxZ;
00295   Double_t fVtxTime;
00296 
00297   Double_t fDirX;
00298   Double_t fDirY;
00299   Double_t fDirZ;
00300 
00301   Double_t fVtxFOM;
00302 
00303   // --- fitting ---
00304   Bool_t fFitTimeParams;
00305   Double_t fFixTimeParam0;
00306 
00307   Bool_t fFitConeParams;
00308   Double_t fFixConeParam0;
00309   Double_t fFixConeParam1;
00310   Double_t fFixConeParam2;
00311 
00312   // --- debug ---
00313   Double_t fTimeParam0;
00314   Double_t fConeParam0;
00315   Double_t fConeParam1;
00316   Double_t fConeParam2;
00317 
00318   ClassDef(WCSimVertexFinder,0)
00319 
00320 };
00321 
00322 #endif
00323 
00324 
00325 
00326 
00327 
00328 
00329