StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMtdMatchMaker.h
1 
11 /*****************************************************************
12  *
13  * $Log: StMtdMatchMaker.h,v $
14  * Revision 1.20 2018/12/06 18:11:13 marr
15  * Improvement: extrapolate tracks to the proper primary vertex when available. This eliminates large negative dTof values
16  *
17  * Revision 1.19 2018/09/04 19:29:14 marr
18  * Use the pairD definition in StHelixD.hh
19  *
20  * Revision 1.18 2017/03/08 20:48:54 marr
21  * 1) Add a new data member mYear to indicate run year
22  * 2) Invoke appropriate functions in StMtdGeometry class to calculate local y
23  * to make the class backward compatible
24  *
25  * Revision 1.17 2016/08/05 16:12:24 marr
26  * Add MTD hit IdTruth to avoid applying dy shift for BL 8 and 24 for MC hits
27  *
28  * Revision 1.16 2016/07/28 14:31:23 marr
29  * Fix coverity check: initialization of data member
30  *
31  * Revision 1.15 2016/07/27 15:46:34 marr
32  * Fix coverity check: initialization of data members
33  *
34  * Revision 1.14 2015/10/16 19:04:55 marr
35  * Remove filling trees
36  *
37  * Revision 1.13 2015/07/10 16:07:40 marr
38  * Add the distance along radius to the calculation of the distance between
39  * a MTD hit and a projected track position
40  *
41  * Revision 1.12 2015/04/24 19:55:16 marr
42  * Add a member function cleanUpMtdPidTraits() to clean up the MTD pidTraits for
43  * all global and primary tracks before the matching process. This is needed when
44  * running MuDst in afterburner mode.
45  *
46  * Revision 1.11 2015/04/10 18:21:38 marr
47  * Comment on the meaning of different values of matchFlag
48  *
49  * Revision 1.10 2014/09/09 14:00:39 marr
50  * Fill the expected time-of-flight calculated via track extrapolation
51  *
52  * Revision 1.9 2014/08/06 11:43:27 jeromel
53  * Suffix on literals need to be space (later gcc compiler makes it an error) - first wave of fixes
54  *
55  * Revision 1.8 2014/07/24 02:53:04 marr
56  * 1) Add log info of the matched track-hit pair
57  * 2) Set DeltaY and DeltaZ in PidTraits
58  *
59  * Revision 1.7 2014/07/10 20:50:35 huangbc
60  * Use new MTD geometry class. Load geometry volume from geant.
61  * Choose closest one for multi-tracks which associated with same hit.
62  *
63  * Revision 1.5 2014/04/16 02:23:39 huangbc
64  * 1. fixed a bug of un-initialized variable nDedxPts in MtdTrack construction function.
65  * 2. reoriganized project2Mtd function. Made it more readable.
66  * 3. save pathlengths of extrapolated tracks.
67  * 4. tot selection < 40 ns. drop off maximum tot selection.
68  * 5. add hits <-> track index association in mMuDstIn=true mode.
69  *
70  * Revision 1.4 2013/12/09 22:53:25 geurts
71  * update: enable filling of MTD Pid traits and include a few more protections against zero-pointers [Bingchu]
72  *
73  * Revision 1.3 2013/11/19 22:30:34 jeromel
74  * Added name
75  *
76  * Revision 1.2 2013/03/21 11:21:45 jeromel
77  * Reviewd version 2013/03
78  *
79  *
80  *
81  *******************************************************************/
82 #ifndef STMTDMATCHMAKER_H
83 #define STMTDMATCHMAKER_H
84 
85 #include <vector>
86 #include <string>
87 #ifndef ST_NO_NAMESPACES
88 using std::vector;
89 using std::string;
90 #endif
91 
92 #include "StMaker.h"
93 #include "TH2.h"
94 #include "TF1.h"
95 #include "TF2.h"
96 #include <StPhysicalHelixD.hh>
97 #include "TNtuple.h"
98 #include "StThreeVectorD.hh"
99 #include "StThreeVectorF.hh"
100 
101 class StMuDstMaker;
102 class StMuDst;
103 class StEvent;
104 //class StMuBTofHit;
105 class StTrack;
106 class StMuTrack;
107 class StTriggerData;
108 class StMtdPidTraits;
109 class StMuMtdPidTraits;
110 class StMtdGeometry;
111 
112 #if !defined(ST_NO_TEMPLATE_DEF_ARGS) || defined(__CINT__)
113 typedef vector<Int_t> IntVec;
114 typedef vector<UInt_t> UIntVec;
115 typedef vector<Double_t> DoubleVec;
116 #else
117 typedef vector<Int_t, allocator<Int_t>> IntVec;
118 typedef vector<UInt_t, allocator<UInt_t>> UIntVec;
119 typedef vector<Double_t, allocator<Double_t>> DoubleVec;
120 #endif
121 
122 const Int_t mNBacklegs = 30;
123 const Int_t mNStrips = 12;
124 const Int_t mNAllTrays = 150;
125 
127 class MtdTrack{
128  public:
129  MtdTrack():pt(-999.),eta(-999.),nFtPts(0),nDedxPts(0),flag(0),nHitsPoss(999){};
130  MtdTrack(StTrack *stt);
131  MtdTrack(StMuTrack *mut);
132  ~MtdTrack(){}
133 
134  Double_t pt;
135  Double_t eta;
136  Int_t nFtPts;
137  Int_t nDedxPts;
138  Int_t flag;
139  Int_t nHitsPoss;
140 
141 };
142 
143 class StMtdMatchMaker: public StMaker
144 {
145 
146  public:
148  StMtdMatchMaker(const char* name = "MtdMatch");
149  virtual ~StMtdMatchMaker();
150 
151  virtual void Clear(const char* opt="");
153  virtual Int_t Init();
154  Int_t InitRun(int runnumber);
155 
157  virtual Int_t Make();
159  virtual Int_t Finish();
160  Int_t FinishRun(int runnumber);
161 
163  void setCosmicEvent(const Bool_t val);
165  void setELossFlag(const Bool_t val);
167  void setHisto(const Bool_t val);
168 
170  void setMinFitPoints(Int_t val);
172  void setMindEdxFitPoints(Int_t val);
174  void setEtaRange(Float_t etaMin, Float_t etaMax);
176  void setMinPt(Float_t val);
178  void setMatNeighbors(Bool_t val);
180  void setNExtraCells(Int_t val);
182  void setLockBField(Bool_t val);
184  void setGeomTag(const char *tag);
185 
187  bool validTrack(StTrack *track);
188  bool validTrack(StMuTrack *track);
189 
190  // calcuate global z of MTD hit
191  Float_t getMtdHitGlobalZ(Float_t leadingWestTime, Float_t leadingEastTime, Int_t module);
192  Int_t getProjModule(Float_t local_z, Float_t global_z);
193 
194 
195  protected:
196  StPhysicalHelixD* mBeamHelix;
197  Bool_t doPrintMemoryInfo;
198  Bool_t doPrintCpuInfo;
199  Bool_t mCosmicFlag;
200 
201  Int_t mMinFitPointsPerTrack;
204  Float_t mMinEta;
205  Float_t mMaxEta;
206  Float_t mMinPt;
207 
208 
209  private:
210  Bool_t mMuDstIn;
211  Bool_t mHisto;
212 
213  Double_t mVDrift[mNAllTrays][mNStrips];
214  Bool_t mnNeighbors;
215  Int_t mNExtraCells;
216  Int_t ngTracks;
217 
218  map<Int_t, Int_t> index2Primary;
219 
221  TH1D* mEventCounterHisto;
222  TH1D* mCellsMultInEvent;
223  TH1D* mHitsMultInEvent;
224  TH1D* mHitsPrimaryInEvent; // ! primary tracks
225  TH1D* mHitsGlobalInEvent; // ! global tracks
226  TH1D* mHitsMultPerTrack;
227  TH2D* mHitsPosition;
228  TH1D* mDaqOccupancy[mNBacklegs];
229  TH1D* mDaqOccupancyProj[mNBacklegs];
230 
231  TH2D* mHitCorr[mNBacklegs];
232  TH2D* mHitCorrModule[mNBacklegs];
233  TH2D* mDeltaHitFinal[mNBacklegs];
234 
235  TH2D* mTrackPtEta;
236  TH2D* mTrackPtPhi;
237  TH1D* mTrackNFitPts;
238  TH2D* mTrackdEdxvsp;
239  TH2D* mNSigmaPivsPt;
240 
241  TH1D* mCellsPerEventMatch1;
242  TH1D* mHitsPerEventMatch1;
243  TH1D* mCellsPerTrackMatch1;
244  TH1D* mTracksPerCellMatch1;
245  TH1D* mDaqOccupancyMatch1;
246  TH2D* mDeltaHitMatch1;
247 
248  TH1D* mCellsPerEventMatch2;
249  TH1D* mHitsPerEventMatch2;
250  TH1D* mCellsPerTrackMatch2;
251  TH1D* mTracksPerCellMatch2;
252  TH1D* mDaqOccupancyMatch2;
253  TH2D* mDeltaHitMatch2;
254 
255  TH1D* mCellsPerEventMatch3;
256  TH1D* mHitsPerEventMatch3;
257  TH1D* mCellsPerTrackMatch3;
258  TH1D* mTracksPerCellMatch3;
259  TH1D* mDaqOccupancyMatch3;
260  TH2D* mDeltaHitMatch3;
261 
262  TH1D* mCellsPrimaryPerEventMatch3;
263 
264  TH2F *hphivsz;
265  TH2F *hTofPhivsProj;
266  TH2F *hTofZvsProj;
267  TH2F *hMtdZvsProj;
268  TH2F *hMtdPhivsProj;
269  TH2F *hMtddPhivsBackleg;
270  TH2F *hMtddZvsBackleg;
271 
272  TF1 *fZReso;
273  TF1 *fPhiReso;
274 
275  StEvent *mEvent;
276  StMuDst *mMuDst;
277  Int_t mYear;
278  StMtdGeometry *mMtdGeom;
279 #ifndef ST_NO_TEMPLATE_DEF_ARGS
280  typedef vector<Int_t> idVector;
281 #else
282  typedef vector<Int_t,allocator<Int_t>> idVector;
283 #endif
284  typedef idVector::iterator idVectorIter;
285  struct StructCellHit{
286  Int_t backleg;
287  Int_t module;
288  Int_t cell;
289  StThreeVector<double> hitPosition;
290  idVector trackIdVec;
291  Int_t matchFlag; // 1: one hit - one track
292  // 2: multiple hits - one track; only 1 hit left after tot cut
293  // 3: mulitple hits - one track; pick the cloest hit after tot cut
294  // 7: one hit - multiple tracks; pick the closest track
295  // 8: multiple hits - multiple tracks; only 1 hit left after tot cut, pick the closest track
296  // 9: mulitple hits - multiple tracks; pick the closest track and cloest hit after tot cut
297  Float_t zhit;
298  Float_t yhit;
299  pair<Double_t,Double_t> tot;
300  pair<Double_t,Double_t> leadingEdgeTime;
301  Int_t index2MtdHit;
302  Double_t theta;
303  Double_t pathLength;
304  Double_t expTof2MTD;
305  Int_t idTruth;
306  };
307  Bool_t mELossFlag;
308  Bool_t mLockBField;
309  TString mGeomTag;
310 
311 #ifndef ST_NO_TEMPLATE_DEF_ARGSA
312  typedef vector<StructCellHit> mtdCellHitVector;
313 #else
314  typedef vector<StructCellHit,allocator<StructCellHit>> mtdCellHitVector;
315 #endif
316  typedef vector<StructCellHit>::iterator mtdCellHitVectorIter;
317 
318 
320  void bookHistograms();
322  void cleanUpMtdPidTraits();
324  Bool_t readMtdHits(mtdCellHitVector& daqCellsHitVec,idVector& validModuleVec);
326  void project2Mtd(mtdCellHitVector daqCellsHitVec,mtdCellHitVector& allCellsHitVec,Int_t& nPrimaryHits);
328  void matchMtdHits(mtdCellHitVector& dapCellsHitVec,mtdCellHitVector& allCellsHitVec,mtdCellHitVector& matchHitCellsVec);
330  void sortSingleAndMultiHits(mtdCellHitVector& matchHitCellsVec,mtdCellHitVector& singleHitCellsVec,mtdCellHitVector& multiHitsCellsVec);
332  void finalMatchedMtdHits(mtdCellHitVector& singleHitCellsVec,mtdCellHitVector& FinalMatchedCellsVec);
334  void fillPidTraits(mtdCellHitVector& FinalMatchedCellsVec,Int_t& nValidSingleHitCells,Int_t& nValidSinglePrimHitCells);
336  bool validTrack(MtdTrack mtt);
337 
339  bool matchTrack2Mtd(mtdCellHitVector daqCellsHitVec,const StPhysicalHelixD &helix, Int_t gq, mtdCellHitVector& allCellsHitVec,unsigned int iNode, StThreeVectorD pVtx);
340 
341  virtual const char *GetCVS() const
342  {static const char cvs[]="Tag $Name: $ $Id: StMtdMatchMaker.h,v 1.20 2018/12/06 18:11:13 marr Exp $ built " __DATE__ " " __TIME__ ; return cvs;}
343  ClassDef(StMtdMatchMaker,2)
344 };
345 
346 inline void StMtdMatchMaker::setCosmicEvent(const Bool_t val) { mCosmicFlag= val; }
347 inline void StMtdMatchMaker::setELossFlag(const Bool_t val) { mELossFlag= val; }
348 inline void StMtdMatchMaker::setHisto(const Bool_t val) { mHisto = val; }
349 inline void StMtdMatchMaker::setMinFitPoints(Int_t val) { mMinFitPointsPerTrack = val; }
351 inline void StMtdMatchMaker::setEtaRange(Float_t etaMin,Float_t etaMax) {mMinEta=etaMin;mMaxEta=etaMax; }
352 inline void StMtdMatchMaker::setMinPt(Float_t val) {mMinPt=val; }
353 inline void StMtdMatchMaker::setMatNeighbors(Bool_t val) {mnNeighbors=val; }
354 inline void StMtdMatchMaker::setNExtraCells(Int_t val) {mNExtraCells=val; }
355 inline void StMtdMatchMaker::setLockBField(Bool_t val) {mLockBField=val; }
356 inline void StMtdMatchMaker::setGeomTag(const char *tag) {mGeomTag=tag; }
357 #endif
void setMatNeighbors(Bool_t val)
set matching neighbor modules
void setMindEdxFitPoints(Int_t val)
set minimum ndEdx fit points
void setEtaRange(Float_t etaMin, Float_t etaMax)
set pseudo rapidity range
virtual Int_t Init()
initialize drifting velocity and histograms.
Float_t mMinFitPointsOverMax
minimum dE/dx fit points per track
MTD track class.
void setNExtraCells(Int_t val)
set n extra cells
void setELossFlag(const Bool_t val)
set energy loss in MTD
void setGeomTag(const char *tag)
set geometry tag, only use this option in reading mudst mode
bool validTrack(StTrack *track)
check track quality
Float_t mMinEta
minimum ratio
StMtdMatchMaker(const char *name="MtdMatch")
Default constructor.
Muon Telescope Detector (MTD) Match Maker.
void setMinPt(Float_t val)
set minimum nHitsFit
Int_t getProjModule(Float_t local_z, Float_t global_z)
calculate module of projected position
Float_t mMinPt
maximum pseudorapidity
Float_t mMaxEta
minimum pseudorapidity
virtual Int_t Make()
associate tracks with mtd hits
void setHisto(const Bool_t val)
save QA histogram or not
Int_t InitRun(int runnumber)
InitRun: initialize geometries (retrieve beam line constraint from database)
void setMinFitPoints(Int_t val)
set minimum nHitsFit
void setLockBField(Bool_t val)
set BField to FF, only use this option in simulation
virtual Int_t Finish()
write QA histograms
Int_t mMindEdxFitPoints
minimum fit points per track
Float_t getMtdHitGlobalZ(Float_t leadingWestTime, Float_t leadingEastTime, Int_t module)
calculate global z of the MTD hits based on its timing information
void setCosmicEvent(const Bool_t val)
set event trigger comsmic ray event has a reversed direction from outer to inner for tracks in upper ...
Int_t FinishRun(int runnumber)
FinishRun: clean up BeamHelix (will be reinitialized at the next initRun)