StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StETofMatchMaker.h
1 /***************************************************************************
2  *
3  * $Id: StETofMatchMaker.h,v 1.5 2020/01/16 03:53:37 fseck Exp $
4  *
5  * Author: Florian Seck, April 2018
6  ***************************************************************************
7  *
8  * Description: StETofMatchMaker - class to match StETofHits to tracks.
9  * The matching is done in several steps:
10  * - get a list of eTOF hits
11  * - check for each track if its helix has an intersection with
12  * the eTOF active volumes (MRPCs gas gaps)
13  * - resolve matching ambiguities
14  *
15  ***************************************************************************
16  *
17  * $Log: StETofMatchMaker.h,v $
18  * Revision 1.5 2020/01/16 03:53:37 fseck
19  * added etof-only and hybrid btof-etof start time calculations for on-the-fly corrections
20  *
21  * Revision 1.4 2019/12/10 16:00:31 fseck
22  * possibility to use step-wise track extrapolation in changing magnetic field via setting a flag
23  *
24  * Revision 1.3 2019/05/08 23:59:10 fseck
25  * changed match distances to become member variables
26  *
27  * Revision 1.2 2019/04/24 01:02:02 fseck
28  * fix to start time for simulation and more histograms added to doQA mode
29  *
30  * Revision 1.1 2019/02/19 19:52:28 jeromel
31  * Reviewed code provided by F.Seck
32  *
33  *
34  ***************************************************************************/
35 #ifndef STETOFMATCHMAKER_H
36 #define STETOFMATCHMAKER_H
37 
38 #include <string>
39 #include <vector>
40 #include <map>
41 
42 #include "StMaker.h"
43 #include "StThreeVectorD.hh"
44 #include "StPhysicalHelixD.hh"
45 
46 class StEvent;
47 class StMuDst;
48 class StETofGeometry;
49 class StTrack;
50 class StMuTrack;
51 class StTrackGeometry;
52 class StETofHitMaker;
53 
54 class TH1;
55 class TH2;
56 
58 class ETofTrack{
59  public:
60  ETofTrack():mom(-999.),pt(-999.),eta(-999.),phi(-999.),nFtPts(0),nDedxPts(0),flag(0),nHitsPoss(999),dEdx(-999.),nSigmaPion(-999.){};
61  ETofTrack( const StTrack *sttrack );
62  ETofTrack( const StMuTrack *mutrack );
63  ~ETofTrack(){}
64 
65  Double_t mom;
66  Double_t pt;
67  Double_t eta;
68  Double_t phi;
69  Int_t nFtPts;
70  Int_t nDedxPts;
71  Int_t flag;
72  Int_t nHitsPoss;
73  Double_t dEdx;
74  Double_t nSigmaPion;
75 };
76 
77 
78 class StETofMatchMaker : public StMaker {
79 
80 private:
81  struct StructETofHit{
82  Int_t sector;
83  Int_t plane;
84  Int_t counter;
85  Int_t strip;
86  Double_t hitTime;
87  Double_t localX;
88  Double_t localY;
89  Double_t tot;
90  Int_t clusterSize;
91  Int_t index2ETofHit;
92  StThreeVectorD globalPos;
93  Int_t trackId;
94  Double_t theta;
95  Int_t matchFlag;
96  Double_t deltaX;
97  Double_t deltaY;
98  Bool_t isPrimary;
99  Double_t beta;
100  Double_t pathLength;
101  Double_t tof;
102  Int_t IdTruth;
103  Int_t IdTruthHit;
104  Double_t totDiff;
105 
106  };
107 
108  typedef std::vector< StructETofHit > eTofHitVec;
109  typedef std::vector< StructETofHit >::iterator eTofHitVecIter;
110 
111 public:
112  StETofMatchMaker( const char* name = "etofMatch" ); // default constructor
113  ~StETofMatchMaker();
114 
115  Int_t Init(); // process start-up options
116  Int_t InitRun( Int_t ); // initialize geometry
117  Int_t FinishRun( Int_t ); // clean up geometry
118  Int_t Make(); // main match algorithm
119  Int_t Finish(); // print summary & write QA histograms
120 
121 
122 
124  void setFileNameMatchParam( const char* fileName );
125  void setFileNameAlignParam( const char* fileName );
126 
127  void setOuterGeometry( const bool outerGeom );
128  void setUseHelixSwimmer( const bool useSwimmer );
129  void setUseOnlyBTofHeaderStartTime( const bool useBTofT0 );
130 
131  void setT0corr( const double t0corr );
132  void setNupdatesT0( const int nUpdatesT0 );
133 
134  void setIsSim( const bool isSim );
135  void setDoQA( const bool doQA );
136  void setDebug( const bool debug );
137 
138  void setMatchDistXYT( const double x, const double y, const double t );
139 
140  void setYmax( const double ymax );
141 
142 
143 
144 private:
145  // internal subfunctions ----------------------------------------------------------------------
146  StETofGeometry* etofGeometry() const; // method to retrieve the ETofGeom
147 
148  void readETofDetectorHits( eTofHitVec& detectorHitVec );
149  void findTrackIntersections( eTofHitVec& intersectionVec, int& nPrimaryWithIntersection );
150 
151  void fillIndexToPrimaryMap();
152  void cleanUpTraits();
153 
154  bool validTrack( const StTrack* );
155  bool validTrack( const StMuTrack* );
156  bool validTrack( const ETofTrack& );
157 
158  void extrapolateTrackToETof( eTofHitVec& intersectionVec, const StPhysicalHelixD& theHelix, const int& iNode, int& nCrossings, bool isPrimary );
159 
160  void matchETofHits( eTofHitVec& detectorHitVec, eTofHitVec& intersectionVec, eTofHitVec& matchCandVec );
161  void sortSingleMultipleHits( eTofHitVec& matchCandVec, eTofHitVec& singleTrackMatchVec, std::vector< eTofHitVec >& multiTrackMatchVec );
162  void finalizeMatching( eTofHitVec& singleTrackMatchVec, eTofHitVec& finalMatchVec );
163 
164  void fillPidTraits( eTofHitVec& finalMatchVec );
165  void calculatePidVariables( eTofHitVec& finalMatchVec, int& nPrimaryWithPid );
166 
167  void sortandcluster(eTofHitVec& matchCandVec , eTofHitVec& detectorHitVec , eTofHitVec& intersectionVec , eTofHitVec& finalMatchVec);
168  void sortMatchCases( eTofHitVec inputVec , std::map< Int_t, eTofHitVec >& outputMap );
169  void sortOutOlDoubles( eTofHitVec& finalMatchVec);
170 
171  double startTimeBTof();
172  double startTimeETof( const eTofHitVec& finalMatchVec, unsigned int& nCand_etofT0 );
173 
174  double moduloDist( const double& dist, const double& mod );
175  double startTime( const eTofHitVec& finalMatchVec );
176 
177  double timeOfFlight( const double& startTime, const double& stopTime );
178  double expectedTimeOfFlight( const double& pathLength, const double& momentum, const double& mass );
179 
180  void checkClockJumps();
181  void fillQaHistograms( eTofHitVec& finalMatchVec );
182  void fillSlewHistograms( eTofHitVec& finalMatchVec );
183  void bookHistograms();
184  void setHistFileName();
185  void writeHistograms();
186 
187  int rotateHit( const int& sector, const int& rot );
188 
189  StTrackGeometry* trackGeometry( StTrack* ) const; // get track geometry for (outer) helix
190 
191 
192  // internal containers ------------------------------------------------------------------------
193  StEvent* mEvent;
194  StMuDst* mMuDst;
195  StETofGeometry* mETofGeom; // pointer to the ETof geometry utility class
196  StETofHitMaker* mETofHitMaker; // pointer to the HitMaker to pass over correction for clock jumps
197 
198  std::string mFileNameMatchParam; // name of parameter file for matching parameters
199  std::string mFileNameAlignParam;
200 
201  Bool_t mIsStEventIn;
202  Bool_t mIsMuDstIn;
203 
204  Bool_t mOuterTrackGeometry; // if true -> use outer track geometry for extrapolation
205  Bool_t mUseHelixSwimmer; // if true -> use changing magnetic field in track extrapolation
206  Bool_t mUseOnlyBTofHeaderStartTime; // if true -> use only start time from bTOF header
207  Bool_t mIsSim;
208  Bool_t mDoQA;
209  Bool_t mDebug;
210 
211  // maximum distance for track intersection to etof detector hit in cm (nanoseconds) to be counted as match candidate
212  Double_t mMatchDistX;
213  Double_t mMatchDistY;
214  Double_t mMatchDistT;
215 
216  std::vector< Double_t > mT0corrVec;
217  Double_t mT0corr;
218  UInt_t mT0switch;
219  UInt_t mNupdatesT0;
220 
221  std::map< Int_t, Int_t > mIndex2Primary;
222 
223  Double_t mMatchRadius;
224  double mLocalYmax;
225  std::vector< Double_t > mTrackCuts;
226 
227  std::map< Int_t, Int_t > mClockJumpCand;
228  std::map< Int_t, Int_t > mClockJumpDirection;
229 
230  std::string mHistFileName;
231 
232  std::map< std::string, TH1* > mHistograms;
233  std::map< std::string, TH2* > mHistograms2d;
234 
235  // used for single sided match cases
236  Double_t dx_3sig;
237  Double_t dy_3sig;
238  Double_t dt_3sig;
239  Double_t dy_max;
240 
241 
242  virtual const Char_t *GetCVS() const { static const char cvs[]="Tag $Name: $Id: built " __DATE__ " " __TIME__ ; return cvs; }
243 
244  ClassDef( StETofMatchMaker, 0 )
245 };
246 
247 
248 inline void StETofMatchMaker::setFileNameMatchParam( const char* fileName ) { mFileNameMatchParam = fileName; }
249 inline void StETofMatchMaker::setFileNameAlignParam( const char* fileName ) { mFileNameAlignParam = fileName; }
250 inline void StETofMatchMaker::setOuterGeometry( const bool outerGeom ) { mOuterTrackGeometry = outerGeom; }
251 inline void StETofMatchMaker::setUseHelixSwimmer( const bool useSwimmer ) { mUseHelixSwimmer = useSwimmer; }
252 inline void StETofMatchMaker::setUseOnlyBTofHeaderStartTime( const bool useBTofT0 ) { mUseOnlyBTofHeaderStartTime = useBTofT0; }
253 
254 inline void StETofMatchMaker::setT0corr( const double t0corr ) { mT0corr = t0corr; }
255 inline void StETofMatchMaker::setNupdatesT0( const int nUpdatesT0 ) { mNupdatesT0 = nUpdatesT0; }
256 
257 inline void StETofMatchMaker::setIsSim( const bool isSim ) { mIsSim = isSim; }
258 inline void StETofMatchMaker::setDoQA( const bool doQA ) { mDoQA = doQA; }
259 inline void StETofMatchMaker::setDebug( const bool debug ) { mDebug = debug; }
260 inline void StETofMatchMaker::setYmax( const double ymax ) { mLocalYmax = ymax; }
261 
262 inline StETofGeometry* StETofMatchMaker::etofGeometry() const { return mETofGeom; }
263 
264 #endif
Definition: tof.h:15
ETOF track class.
void setFileNameMatchParam(const char *fileName)
read matching parameters from file