StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StBTofCalibMaker.h
1 /*******************************************************************
2  *
3  * $Id: StBTofCalibMaker.h,v 1.15 2021/05/29 23:57:08 geurts Exp $
4  *
5  * Author: Xin Dong
6  *****************************************************************
7  *
8  * Description: Tof Calibration Maker to do the calibration for VPD
9  * (start timing) , TOF tray
10  * store into StBTofPidTraits
11  *
12  *****************************************************************
13  *
14  * $Log: StBTofCalibMaker.h,v $
15  * Revision 1.15 2021/05/29 23:57:08 geurts
16  * Updates to improve pp and pA handling - by Bassam Aboona (TAMU)
17  *
18  * Revision 1.14 2021/01/27 04:06:25 geurts
19  * Introducing meaningful nTofSigma calculations in VPDstartless mode.
20  *
21  * Revision 1.13 2020/04/10 20:41:38 zye20
22  * Xin add more pions and add protons for T0s in the FXT mode
23  *
24  * Revision 1.12 2019/04/23 05:49:57 jdb
25  * Added function to allow forcing 0 starttime for totally startless BTOF usage in UPC
26  *
27  * Revision 1.11 2017/10/20 17:50:32 smirnovd
28  * Squashed commit of the following:
29  *
30  * StBTof: Remove outdated ClassImp macro
31  *
32  * Prefer explicit namespace for std:: names in header files
33  *
34  * Removed unnecessary specification of default std::allocator
35  *
36  * Frank signed-off
37  *
38  * Revision 1.10 2017/03/02 18:30:44 jeromel
39  * Changes by jdb, nl - inData.open() of files on live disk TBF later
40  *
41  * Revision 1.10 2016/11/14 11:32:15 nluttrel
42  * Simulated hits no longer undergo electronics corrections
43  * If StVpdSimMaker used in chain, defaults to use Vpd start time
44  *
45  * Revision 1.9 2016/06/30 17:09:56 jdb
46  * Fixed Several errors identified by Coverity
47  *
48  * Revision 1.8 2014/08/06 11:42:53 jeromel
49  * Suffix on literals need to be space (later gcc compiler makes it an error) - first wave of fixes
50  *
51  * Revision 1.7 2010/10/31 05:51:06 geurts
52  * fixed array dimensions to accomodate cell-based calibrations
53  *
54  * Revision 1.6 2010/10/30 05:20:52 geurts
55  * Calibration Maker reads (file/dbase) in and applies cell-based, module-based, or board-based (TDIG) calibration parameters
56  *
57  * Revision 1.5 2010/05/12 22:46:21 geurts
58  * Startless BTOF self-calibration method (Xin)
59  *
60  * Revision 1.4 2010/03/04 23:10:20 dongx
61  * Added cleanup for PID variables in MuBTofPidTraits when processMuDst()
62  *
63  * Revision 1.3 2009/12/04 22:26:34 geurts
64  * Split original CalibMaker into dedicated StVpdCalibMaker and BTOF-specific StBTofCalibMaker (Xin):
65  * - function added to directly access the MuDst
66  * - clean up those VPD members and functions as they are moved to the StVpdCalibMaker
67  * - add VPD related functions to load/write the calibration VPD information in the BTofHeader
68  * - few small algorithm updates to be consistent with what is used in calibration procedures
69  * - several minor code cleanups
70  *
71  * Revision 1.2 2009/11/21 00:29:52 geurts
72  * Dtabase readout made more robust, static const moved to cxx.
73  *
74  * Revision 1.1 2009/09/23 02:28:41 geurts
75  * first version: Combined BTOF & VPD CalibMaker
76  *
77  *
78  *******************************************************************/
79 #ifndef STBTOFCALIMAKER_H
80 #define STBTOFCALIMAKER_H
81 
82 #include "phys_constants.h"
83 #include "TMath.h"
84 #include "StMaker.h"
85 
86 //#include "TProfile.h"
87 
88 #include <string>
89 #include <vector>
90 
91 class StEvent;
92 class StPrimaryVertex;
93 class StBTofGeometry;
94 class StBTofCollection;
95 class StBTofHeader;
97 class StBTofPidTraits;
98 class StMuDst;
99 class StMuPrimaryVertex;
100 class StMuBTofPidTraits;
101 class StVpdSimConfig;
102 class StBTofSimResParams;
103 
104 class TProfile;
105 
106 #include "StPhysicalHelixD.hh"
107 #include "StBTofUtil/StVpdSimConfig.h"
108 
109 typedef std::vector<Int_t> IntVec;
110 typedef std::vector<Double_t> DoubleVec;
111 
112 class StBTofCalibMaker : public StMaker{
113 public:
114 
116  StBTofCalibMaker(const char* name="btofCalib");
118  virtual ~StBTofCalibMaker();
119 
120  virtual Int_t Init();
121  virtual Int_t InitRun(int);
122  virtual Int_t FinishRun(int);
123  virtual Int_t Make();
124  virtual Int_t Finish();
125 
127  void setOuterGeometry(const bool val=kTRUE);
129  void setSlewingCorr(const bool val=kTRUE);
131  void setUseEventVertex(const bool);
133  void setVPDHitsCut(const Int_t, const Int_t);
135  void setMuDstIn(const bool val=kTRUE);
137  void setFXTMode(const bool val=kTRUE);
138 
140  void setPPPAMode(const Bool_t val=kFALSE);
142  void setPPPAPionSel(const Bool_t val=kFALSE);
144  void setPPPAOutlierRej(const Bool_t val=kFALSE);
146  void setNSigmaTofMode(const Bool_t val=kFALSE);
148  void setRun15Slew(const Bool_t val=kFALSE);
150  void setPPPAModeHist(const Bool_t val=kFALSE);
152  void setJP2015FF(const Bool_t val=kFALSE);
154  void setMB2015FF(const Bool_t val=kFALSE);
156  void setJP2017FF(const Bool_t val=kFALSE);
157 
159  void setCreateHistoFlag(Bool_t histos=kTRUE);
161  void setHistoFileName(const Char_t*);
162 
164  void setPPPAModeHistoFileName(const Char_t* filename);
165 
167  void setInitFromFile(const Bool_t val = kTRUE);
168  void setCalibFilePvpd(const Char_t*);
169  void setCalibFileTot(const Char_t*);
170  void setCalibFileZhit(const Char_t*);
171  void setCalibFileT0(const Char_t*);
172 
173  enum calibtype {NOTSET=0, BOARDCALIB=960, MODULECALIB=3840, CELLCALIB=23040};
174  Int_t getZCalibType();
175  Int_t getTotCalibType();
176 
177  void forceTStartZero();
178 
179 private:
180 
182  calibtype mZCalibType, mTotCalibType;
184  void resetPars();
186  void initEvent();
188  void resetVpd();
190  void loadVpdData();
192  void writeStartTime();
194  Int_t initParameters(Int_t runnumber);
195 
197  void processStEvent();
199  void processMuDst();
200 
201  void cleanCalibMuDst();
202  void cleanCalib(StMuBTofPidTraits&);
203 
205  void tstart(const Double_t Vz, Double_t *tstart, Double_t *tdiff);
206  Double_t tofAllCorr(const Double_t tof, const Double_t tot, const Double_t zlocal, const Int_t iTray, const Int_t iModuleChan);
208 
210  void tstart_NoVpd(const StBTofCollection *btofCollection, const StPrimaryVertex *pVtx, Double_t *tstart);
211  void tstart_NoVpd(const StMuDst *muDst, const StMuPrimaryVertex *pVtx, Double_t *tstart);
212 
214  void vpdTStartForBTofComparison(Double_t vz, Double_t *vpdStartTime);
215  double fudgeFactor(double eta, double zVtx);
216  void fillDtiVsPtotProfiles(double eta, double zVtx, double ptot, double Dti);
217 
218  void archiveVpdHitInfo();
219 
220 
222  float tofCellResolution(const Int_t iTray, const Int_t iModuleChan);
223 
225  void bookHistograms();
227  void writeHistograms();
228 
230  void bookPPPAHistograms();
232  void writePPPAHistograms();
233 
234 
235 private:
236  enum{
237  mNTOF = 192, // 192 for tof in Run 8++
238  mNTDIG = 8, // 8 per tray in Run 8++
239  mNModule = 32, // 32 for tofr5++
240  mNVPD = 19, // 19 tubes at each side
241  mNCell = 6, // 6 cells per module
242  mNBinMax = 60, // 60 bins for T-Tot, T-Z correction
243 
244  mNTray = 120, // 120 trays in full
245  mWestVpdTrayId = 121,
246  mEastVpdTrayId = 122
247  };
248 
249  static const Double_t VHRBIN2PS; // Very High resolution mode, pico-second per bin
250  // 1000*25/1024 (ps/chn)
251  static const Double_t HRBIN2PS; // High resolution mode, pico-second per bin
252  // 97.65625= 1000*100/1024 (ps/chn)
253  static const Double_t TMAX; // tdc limit
254  static const Double_t VZDIFFCUT; // VzVpd - VzProj cut
255  static const Double_t DCARCUT; // dcaR cut
256 
257  static const Double_t mC_Light; // = C_C_LIGHT/1.e9;
258 
259  static const Float_t BTHBLCHCNST; // Bethe-Bloch constant used for dE/dx
260  // correction in start-time calculations
261  // in pppAMode
262  static const Float_t DEDXTCORR[2];
263 
264  Bool_t mValidCalibPar = kFALSE;
265  Bool_t mValidStartTime = kFALSE;
266 
267  Int_t mVPDEastHitsCut = 0;
268  Int_t mVPDWestHitsCut = 0;
269 
270  Float_t mTofTotEdge[mNTray][mNModule][mNCell][mNBinMax];
271  Float_t mTofTotCorr[mNTray][mNModule][mNCell][mNBinMax];
272  Float_t mTofZEdge[mNTray][mNModule][mNCell][mNBinMax];
273  Float_t mTofZCorr[mNTray][mNModule][mNCell][mNBinMax];
274  Double_t mTofTZero[mNTray][mNModule][mNCell];
275 
276  Double_t mVPDLeTime[2*mNVPD];
277 
278  Double_t mTSumEast = 0.0;
279  Double_t mTSumWest = 0.0;
280  Double_t mTSumEastSigma = 0.0;
281  Double_t mTSumWestSigma = 0.0;
282  UInt_t mVPDHitPatternEast = 0;
283  UInt_t mVPDHitPatternWest = 0;
284  Int_t mNEast = 0;
285  Int_t mNWest = 0;
286  Double_t mVPDVtxZ = 0.0;
287  Double_t mProjVtxZ = 0.0;
288  Double_t mEvtVtxZ = 0.0;
289  Double_t mTDiff = 0.0;
290  Double_t mTStart = 0.0;
291  Int_t mNTzero = 0;
292 
293  Int_t mNTzeroCan = 0;
294  Double_t mTCanFirst = 0.0;
295  Double_t mTCanLast = 0.0;
296 
297  Double_t mVpdEHits = 0;
298  Double_t mVpdWHits = 0;
299  Double_t mVpdEGoodHits = 0;
300  Double_t mVpdWGoodHits = 0;
301  Double_t mEarliestVpdEHit = 0.0;
302  Double_t mEarliestVpdWHit = 0.0;
303  Double_t mClosestVpdEHit = 0.0;
304  Double_t mClosestVpdWHit = 0.0;
305  Double_t mLatestVpdEHit = 0.0;
306  Double_t mLatestVpdWHit = 0.0;
307 
308  StPhysicalHelixD* mBeamHelix;
309  StEvent* mEvent;
311  StBTofHeader* mBTofHeader;
312  StMuDst* mMuDst;
313  Bool_t mMuDstIn;
314  Bool_t isMcFlag;
315 
316  Bool_t mOuterGeometry;
317  Bool_t mSlewingCorr;
318  Bool_t mUseEventVertex = kFALSE;
319  Bool_t mInitFromFile;
320  Bool_t mUseVpdStart;
321  Bool_t mForceTStartZero = false;
322  Bool_t mFXTMode = kFALSE;
323 
324  StVpdSimConfig* mVpdResConfig;
325  std::map<int, StVpdSimConfig::SingleTubeParams> mVpdRes;
326  StBTofSimResParams* mBTofRes;
327 
328  Bool_t mPPPAMode = kFALSE;
329  Bool_t mPPPAPionSel = kFALSE;
330  Bool_t mPPPAOutlierRej = kFALSE;
331  Bool_t mNSigmaTofMode = kFALSE;
332  Bool_t mRun15Slew = kFALSE;
333 
334  string mCalibFilePvpd;
335  string mCalibFileTot;
336  string mCalibFileZhit;
337  string mCalibFileT0;
338 
339  Bool_t mHisto;
340  string mHistoFileName;
341  TH1D* hEventCounter = nullptr;
342 
343  Bool_t mPPPAModeHist = kFALSE;
344  string mPPPAModeHistoFileName;
345  Int_t iYr;
346  TH1D* hDtiArray[10];
347  TH1D* hGDcaArray[5];
348  TProfile* hDtiVsPtot[11][2];
349 
350  virtual const char *GetCVS() const
351  {static const char cvs[]="Tag $Name: $ $Id: StBTofCalibMaker.h,v 1.15 2021/05/29 23:57:08 geurts Exp $ built " __DATE__ " " __TIME__ ; return cvs;}
352 
353  ClassDef(StBTofCalibMaker,4)
354 };
355 
356 inline void StBTofCalibMaker::forceTStartZero( ) { mForceTStartZero = true; }
357 inline void StBTofCalibMaker::setVPDHitsCut(const Int_t ieast, const Int_t iwest) { mVPDEastHitsCut=ieast ; mVPDWestHitsCut=iwest; }
358 inline void StBTofCalibMaker::setOuterGeometry(const bool val) { mOuterGeometry=val; }
359 inline void StBTofCalibMaker::setSlewingCorr(const bool val) { mSlewingCorr=val; }
360 inline void StBTofCalibMaker::setUseEventVertex(const bool val) { mUseEventVertex=val; }
361 inline void StBTofCalibMaker::setMuDstIn(const bool val) { mMuDstIn = val; }
362 inline void StBTofCalibMaker::setHistoFileName(const Char_t* filename){ mHistoFileName=filename; }
363 inline void StBTofCalibMaker::setCreateHistoFlag(Bool_t histos) { mHisto = histos; }
364 inline void StBTofCalibMaker::setInitFromFile(const Bool_t val) {mInitFromFile = val; }
365 inline void StBTofCalibMaker::setCalibFilePvpd(const Char_t* filename) {mCalibFilePvpd = filename;}
366 inline void StBTofCalibMaker::setCalibFileTot(const Char_t* filename) {mCalibFileTot = filename;}
367 inline void StBTofCalibMaker::setCalibFileZhit(const Char_t* filename) {mCalibFileZhit = filename;}
368 inline void StBTofCalibMaker::setCalibFileT0(const Char_t* filename) {mCalibFileT0 = filename;}
369 inline Int_t StBTofCalibMaker::getZCalibType() {return Int_t(mZCalibType);}
370 inline Int_t StBTofCalibMaker::getTotCalibType() {return Int_t(mTotCalibType);}
371 inline void StBTofCalibMaker::setFXTMode(const Bool_t val) {mFXTMode = val;}
372 
373 inline void StBTofCalibMaker::setPPPAMode(const Bool_t val) { mPPPAMode = val; if(val){LOG_INFO << "You are now using PPPAMode!" << endm;} if(!val){mPPPAModeHist = kFALSE;}; }
374 inline void StBTofCalibMaker::setPPPAPionSel(const Bool_t val) { mPPPAPionSel = val; if(mPPPAPionSel) { LOG_INFO << "mPPPAPionSel is on!" << endm;}}
375 inline void StBTofCalibMaker::setPPPAOutlierRej(const Bool_t val) { mPPPAOutlierRej = val; if(mPPPAOutlierRej) { LOG_INFO << "mPPPAOutlierRej is on!" << endm;}}
376 inline void StBTofCalibMaker::setNSigmaTofMode(const Bool_t val) { mNSigmaTofMode = val; if(mNSigmaTofMode) { LOG_INFO << "mNSigmaTofMode is on!" << endm;}}
377 inline void StBTofCalibMaker::setPPPAModeHist(const Bool_t val) { if(mPPPAMode){mPPPAModeHist = val; if(mPPPAModeHist){LOG_INFO << "mPPPAModeHist is on!" << endm;}} else if(val){LOG_INFO << "setPPPAModeHist() is only valid when pppAMode is on! " << endm;} else{mPPPAModeHist = val;}; }
378 inline void StBTofCalibMaker::setPPPAModeHistoFileName(const Char_t* filename) { if(mPPPAMode && mPPPAModeHist){mPPPAModeHistoFileName = filename;} else {LOG_INFO << "setPPPAMode() and setPPPAModeHist() must be turned on first before calling setPPPAModeHistoFileName()!" << endm;}; }
379 inline void StBTofCalibMaker::setRun15Slew(const Bool_t val) {if(val){mRun15Slew = val; LOG_INFO << "Using Run 15 slewing corrections" << endm;}; }
380 
381 #endif
void setVPDHitsCut(const Int_t, const Int_t)
switch to set the VPD # of hits cut
void setPPPAPionSel(const Bool_t val=kFALSE)
switch to pp/pA pion selection
virtual Int_t InitRun(int)
void setFXTMode(const bool val=kTRUE)
switch to FXT mode to include protons in T0 calculation
void setHistoFileName(const Char_t *)
set histogram output file name
void setNSigmaTofMode(const Bool_t val=kFALSE)
enable nSigmTof mode
Definition: tof.h:15
void setJP2017FF(const Bool_t val=kFALSE)
enable JP 2017 fudge factor
void setMB2015FF(const Bool_t val=kFALSE)
enable MB 2015 fudge factor
void setMuDstIn(const bool val=kTRUE)
switch to read in StEvent/MuDst
void setOuterGeometry(const bool val=kTRUE)
switch to select the Helix Geometry
void setPPPAModeHistoFileName(const Char_t *filename)
set file name for pp/pA QA histograms
void setUseEventVertex(const bool)
switch to turn on the use of event vertex
virtual Int_t Finish()
void setPPPAMode(const Bool_t val=kFALSE)
switch to pp/pA mode
void setRun15Slew(const Bool_t val=kFALSE)
explicitly set Run15 slewing correction
StBTofCalibMaker(const char *name="btofCalib")
Default constructor.
void setJP2015FF(const Bool_t val=kFALSE)
enable JP 2015 fudge factor
void setPPPAOutlierRej(const Bool_t val=kFALSE)
switch outlier rejection in pp/pA
virtual ~StBTofCalibMaker()
Destructor.
void setInitFromFile(const Bool_t val=kTRUE)
read calibration parameters from file
void setPPPAModeHist(const Bool_t val=kFALSE)
enable pp/pA QA histograms
virtual Int_t Make()
void setCreateHistoFlag(Bool_t histos=kTRUE)
enable QA histogram filling
void setSlewingCorr(const bool val=kTRUE)
switch to turn on slewing correction or not - maybe only T0 in the first step.