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 
170  double startTimeBTof();
171  double startTimeETof( const eTofHitVec& finalMatchVec, unsigned int& nCand_etofT0 );
172 
173  double moduloDist( const double& dist, const double& mod );
174  double startTime( const eTofHitVec& finalMatchVec );
175 
176  double timeOfFlight( const double& startTime, const double& stopTime );
177  double expectedTimeOfFlight( const double& pathLength, const double& momentum, const double& mass );
178 
179  void checkClockJumps();
180  void fillQaHistograms( eTofHitVec& finalMatchVec );
181  void fillSlewHistograms( eTofHitVec& finalMatchVec );
182  void bookHistograms();
183  void setHistFileName();
184  void writeHistograms();
185 
186  int rotateHit( const int& sector, const int& rot );
187 
188  StTrackGeometry* trackGeometry( StTrack* ) const; // get track geometry for (outer) helix
189 
190 
191  // internal containers ------------------------------------------------------------------------
192  StEvent* mEvent;
193  StMuDst* mMuDst;
194  StETofGeometry* mETofGeom; // pointer to the ETof geometry utility class
195  StETofHitMaker* mETofHitMaker; // pointer to the HitMaker to pass over correction for clock jumps
196 
197  std::string mFileNameMatchParam; // name of parameter file for matching parameters
198  std::string mFileNameAlignParam;
199 
200  Bool_t mIsStEventIn;
201  Bool_t mIsMuDstIn;
202 
203  Bool_t mOuterTrackGeometry; // if true -> use outer track geometry for extrapolation
204  Bool_t mUseHelixSwimmer; // if true -> use changing magnetic field in track extrapolation
205  Bool_t mUseOnlyBTofHeaderStartTime; // if true -> use only start time from bTOF header
206  Bool_t mIsSim;
207  Bool_t mDoQA;
208  Bool_t mDebug;
209 
210  // maximum distance for track intersection to etof detector hit in cm (nanoseconds) to be counted as match candidate
211  Double_t mMatchDistX;
212  Double_t mMatchDistY;
213  Double_t mMatchDistT;
214 
215  std::vector< Double_t > mT0corrVec;
216  Double_t mT0corr;
217  UInt_t mT0switch;
218  UInt_t mNupdatesT0;
219 
220  std::map< Int_t, Int_t > mIndex2Primary;
221 
222  Double_t mMatchRadius;
223  double mLocalYmax;
224  std::vector< Double_t > mTrackCuts;
225 
226  std::map< Int_t, Int_t > mClockJumpCand;
227  std::map< Int_t, Int_t > mClockJumpDirection;
228 
229  std::string mHistFileName;
230 
231  std::map< std::string, TH1* > mHistograms;
232  std::map< std::string, TH2* > mHistograms2d;
233 
234  // used for single sided match cases
235  Double_t dx_3sig;
236  Double_t dy_3sig;
237  Double_t dt_3sig;
238  Double_t dy_max;
239 
240 
241  virtual const Char_t *GetCVS() const { static const char cvs[]="Tag $Name: $Id: built " __DATE__ " " __TIME__ ; return cvs; }
242 
243  ClassDef( StETofMatchMaker, 0 )
244 };
245 
246 
247 inline void StETofMatchMaker::setFileNameMatchParam( const char* fileName ) { mFileNameMatchParam = fileName; }
248 inline void StETofMatchMaker::setFileNameAlignParam( const char* fileName ) { mFileNameAlignParam = fileName; }
249 inline void StETofMatchMaker::setOuterGeometry( const bool outerGeom ) { mOuterTrackGeometry = outerGeom; }
250 inline void StETofMatchMaker::setUseHelixSwimmer( const bool useSwimmer ) { mUseHelixSwimmer = useSwimmer; }
251 inline void StETofMatchMaker::setUseOnlyBTofHeaderStartTime( const bool useBTofT0 ) { mUseOnlyBTofHeaderStartTime = useBTofT0; }
252 
253 inline void StETofMatchMaker::setT0corr( const double t0corr ) { mT0corr = t0corr; }
254 inline void StETofMatchMaker::setNupdatesT0( const int nUpdatesT0 ) { mNupdatesT0 = nUpdatesT0; }
255 
256 inline void StETofMatchMaker::setIsSim( const bool isSim ) { mIsSim = isSim; }
257 inline void StETofMatchMaker::setDoQA( const bool doQA ) { mDoQA = doQA; }
258 inline void StETofMatchMaker::setDebug( const bool debug ) { mDebug = debug; }
259 inline void StETofMatchMaker::setYmax( const double ymax ) { mLocalYmax = ymax; }
260 
261 inline StETofGeometry* StETofMatchMaker::etofGeometry() const { return mETofGeom; }
262 
263 #endif
Definition: tof.h:15
ETOF track class.
void setFileNameMatchParam(const char *fileName)
read matching parameters from file