StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StETofCalibMaker.h
1  /***************************************************************************
2  *
3  * $Id: StETofCalibMaker.h,v 1.6 2019/12/19 02:19:13 fseck Exp $
4  *
5  * Author: Florian Seck, April 2018
6  ***************************************************************************
7  *
8  * Description: StETofCalibMaker - class to read the eTofCollection from
9  * StEvent, do calibration, fill the collection with the updated information
10  * and write back to StEvent
11  *
12  ***************************************************************************
13  *
14  * $Log: StETofCalibMaker.h,v $
15  * Revision 1.6 2019/12/19 02:19:13 fseck
16  * use known pulser time differences inside one Gbtx to recover missing pulser signals
17  *
18  * Revision 1.5 2019/12/10 15:54:56 fseck
19  * added new database tables for pulsers, updated pulser handling and trigger time calculation
20  *
21  * Revision 1.4 2019/05/08 23:57:09 fseck
22  * added function to set the reference pulser
23  *
24  * Revision 1.3 2019/03/25 01:09:17 fseck
25  * added first version of pulser correction procedure
26  *
27  * Revision 1.2 2019/03/08 19:01:01 fseck
28  * pick up the right trigger and reset time on event-by-event basis + fix to clearing of calibrated tot in afterburner mode + flag pulser digis
29  *
30  * Revision 1.1 2019/02/19 19:52:28 jeromel
31  * Reviewed code provided by F.Seck
32  *
33  *
34  ***************************************************************************/
35 #ifndef STETOFCALIBMAKER_H
36 #define STETOFCALIBMAKER_H
37 
38 
39 #include <string>
40 #include <map>
41 #include <utility>
42 
43 #include "StMaker.h"
44 
45 class TH1F;
46 class TProfile;
47 
48 class StEvent;
49 class StMuDst;
50 
51 class StETofHeader;
52 class StETofDigi;
53 class StMuETofDigi;
54 class StMuETofHeader;
55 
56 class StETofHardwareMap;
57 
58 
59 class StETofCalibMaker: public StMaker {
60 public:
62  StETofCalibMaker( const char* name = "etofCalib" );
63 
65 
66 
67  Int_t Init();
68  Int_t InitRun( Int_t );
69  Int_t FinishRun( Int_t );
70  Int_t Finish();
71  Int_t Make();
72 
73  void processStEvent();
74  void processMuDst();
75 
77  void setFileNameCalibParam( const char* fileName );
78  void setFileNameElectronicsMap( const char* fileName );
79  void setFileNameStatusMap( const char* fileName );
80  void setFileNameTimingWindow( const char* fileName );
81  void setFileNameSignalVelocity( const char* fileName );
82  void setFileNameCalibHistograms( const char* fileName );
83  void setFileNameOffsetHistograms( const char* fileName );
84  void setFileNameResetTimeCorr( const char* fileName );
85  void setFileNamePulserTotPeak( const char* fileName );
86  void setFileNamePulserTimeDiffGbtx( const char* fileName );
87 
88  void setDoQA( const bool doQA );
89  void setDebug( const bool debug );
90  void setStrictPulserHandling( const bool debug );
91  void setReferencePulserIndex( const int index );
92 
93  //moved to public to avoid problem with root6
95  Int_t geomId;
96  Double_t time;
97  Double_t tot;
98 
99  bool operator==( const StructStuckFwDigi& r ) const {
100  return geomId == r.geomId && fabs( time - r.time ) < 1.e-5 && fabs( tot - r.tot ) < 1.e-5;
101  }
102  };
103 
104 
105 private:
106  bool isFileExisting( const std::string fileName );
107 
108  void resetToRaw ( StETofDigi* aDigi );
109  void applyMapping ( StETofDigi* aDigi );
110  void flagPulserDigis ( StETofDigi* aDigi, unsigned int index, std::map< unsigned int, std::vector< unsigned int > >& pulserCandMap );
111  void applyCalibration( StETofDigi* aDigi, StETofHeader* etofHeader );
112 
113 
114  void resetToRaw ( StMuETofDigi* aDigi );
115  void applyMapping ( StMuETofDigi* aDigi );
116  void flagPulserDigis ( StMuETofDigi* aDigi, unsigned int index, std::map< unsigned int, std::vector< unsigned int > >& pulserCandMap );
117  void applyCalibration( StMuETofDigi* aDigi, StMuETofHeader* etofHeader );
118 
119  void calculatePulserOffsets( std::map< unsigned int, std::vector< unsigned int > >& pulserCandMap );
120 
121 
122  double calibTotFactor ( StETofDigi* aDigi );
123  double calibTimeOffset( StETofDigi* aDigi );
124  double slewingTimeOffset( StETofDigi* aDigi );
125  double applyPulserOffset( StETofDigi* aDigi );
126 
127  double resetTimeCorr() const;
128 
129  double triggerTime( StETofHeader* etofHeader );
130  double resetTime ( StETofHeader* etofHeader );
131 
132  unsigned int channelToKey( const unsigned int channelId );
133  unsigned int detectorToKey( const unsigned int detectorId );
134  unsigned int sideToKey( const unsigned int sideId );
135 
136 
137  void bookHistograms();
138  void setHistFileName();
139  void writeHistograms();
140 
141 
142  StEvent* mEvent;
143  StMuDst* mMuDst;
144  StETofHardwareMap* mHwMap; // electronic channel to hardware/geometry map
145 
146  std::string mFileNameCalibParam; // name of parameter file for calibration parameters
147  std::string mFileNameElectronicsMap; // name of parameter file for electronics-to-hardware map
148  std::string mFileNameStatusMap; // name of parameter file for status map
149  std::string mFileNameTimingWindow; // name of parameter file for timing window
150  std::string mFileNameSignalVelocity; // name of parameter file for signal velocity
151  std::string mFileNameCalibHistograms; // name of parameter file for calibration histograms (output of QA maker)
152  std::string mFileNameOffsetHistograms; // name of parameter file for run by run offsets histograms (output of QA maker)
153  std::string mFileNameResetTimeCorr; // name of parameter file for reset time correction
154  std::string mFileNamePulserTotPeak; // name of parameter file for pulser peak tot
155  std::string mFileNamePulserTimeDiffGbtx; // name of parameter file for pulser time diff
156 
157  Int_t mRunYear; // "year" of operation by using roughly October 1st as reference
158  Float_t mGet4TotBinWidthNs; // conversion factor for Get4 chip TOT bin to nanoseconds
159  Int_t mMinDigisPerSlewBin; // minimal required statistics per channel and TOT bin to apply slewing corrections
160  Float_t mResetTimeCorr; // additional offset for the whole system in case reset time was not saved correctly
161 
162  Double_t mTriggerTime; // trigger time in ns
163  Double_t mResetTime; // reset time in ns
164  Long64_t mResetTs; // reset time stamp in clock ticks
165 
166  Float_t mPulserPeakTime; // pulser peak time relative to the trigger time in ns
167  Int_t mReferencePulserIndex; // index of reference pulser used in the pulser correction to correct time offset between different Gbtx
168 
169  std::map< UInt_t, std::pair< Float_t, Float_t > > mTimingWindow; // timing window for each AFCK
170  std::map< UInt_t, std::pair< Float_t, Float_t > > mPulserWindow; // pulser window for each AFCK
171  std::map< UInt_t, UInt_t > mStatus; // status of each channel: 0 - not existing/not working, 1 - working
172  std::map< UInt_t, Float_t > mSignalVelocity; // signal velocities in each detector
173 
174  std::map< UInt_t, TH1F* > mDigiTotCorr; // factor to calibrate TOT per channel saved in one histogram (64 bins) per counter accessed by detectorId as key
175  std::map< UInt_t, TH1F* > mDigiTimeCorr; // offset to calibrate time per channel saved in one histogram (64 bins) per counter accessed by detectorId as key
176  std::map< UInt_t, TProfile* > mDigiSlewCorr; // offset to account for slewing corrections per channel saved in a histogram (~30 TOT bins) accessed by channelId as key
177 
178  std::map< UInt_t, Float_t > mPulserPeakTot; // TOT of pulsers on each side of the RPC counters (as key)
179  std::map< UInt_t, Double_t > mPulserTimeDiff; // pulser time difference with respect to the reference pulser for each detector side as key
180  std::map< UInt_t, Double_t > mPulserTimeDiffGbtx; // pulser time difference with inside a Gbtx with respect to counter 1
181  std::map< UInt_t, UInt_t > mNPulsersCounter; // number of found pulsers on each counter. Has to be 2 for good the counter to be considered good in this event.
182  std::map< UInt_t, UInt_t > mNStatusBitsCounter; // number of Get4 status bits on each counter. Has to be 0 for good the counter to be considered good in this event.
183  std::map< UInt_t, Bool_t > mPulserPresent; // map of present pulsers for each event (by counter side)
184 
185  std::map< UInt_t, Int_t > mJumpingPulsers; // flag jumping pulsers
186 
187  std::map< UInt_t, Int_t > mUnlockPulserState; // map that counts pulser offsets to avoid locking into the wrong pulser offset state
188 
189  std::vector< StructStuckFwDigi > mStuckFwDigi; // list of digis to ignore for the rest of the run due to stuck firmware
190 
191  Bool_t mStrictPulserHandling;
192  Bool_t mUsePulserGbtxDiff;
193  Bool_t mDoQA;
194  Bool_t mDebug;
195  std::string mHistFileName;
196  std::map< std::string, TH1* > mHistograms;
197 
198 
199 
200 
201 
202  virtual const Char_t *GetCVS() const { static const char cvs[]="Tag $Name: $Id: built " __DATE__ " " __TIME__ ; return cvs; }
203 
204  ClassDef( StETofCalibMaker, 0 )
205 };
206 
207 inline void StETofCalibMaker::setFileNameCalibParam( const char* fileName ) { mFileNameCalibParam = fileName; }
208 inline void StETofCalibMaker::setFileNameElectronicsMap( const char* fileName ) { mFileNameElectronicsMap = fileName; }
209 inline void StETofCalibMaker::setFileNameStatusMap( const char* fileName ) { mFileNameStatusMap = fileName; }
210 inline void StETofCalibMaker::setFileNameTimingWindow( const char* fileName ) { mFileNameTimingWindow = fileName; }
211 inline void StETofCalibMaker::setFileNameSignalVelocity( const char* fileName ) { mFileNameSignalVelocity = fileName; }
212 inline void StETofCalibMaker::setFileNameCalibHistograms( const char* fileName ) { mFileNameCalibHistograms = fileName; }
213 inline void StETofCalibMaker::setFileNameOffsetHistograms( const char* fileName ) { mFileNameOffsetHistograms = fileName; }
214 inline void StETofCalibMaker::setFileNameResetTimeCorr( const char* fileName ) { mFileNameResetTimeCorr = fileName; }
215 inline void StETofCalibMaker::setFileNamePulserTotPeak( const char* fileName ) { mFileNamePulserTotPeak = fileName; }
216 inline void StETofCalibMaker::setFileNamePulserTimeDiffGbtx( const char* fileName ) { mFileNamePulserTimeDiffGbtx = fileName; }
217 
218 
219 inline double StETofCalibMaker::resetTimeCorr() const { return mResetTimeCorr; }
220 
221 inline void StETofCalibMaker::setStrictPulserHandling( const bool StrictPulserHandling ) { mStrictPulserHandling = StrictPulserHandling; }
222 inline void StETofCalibMaker::setDoQA( const bool doQA ) { mDoQA = doQA; }
223 inline void StETofCalibMaker::setDebug( const bool debug ) { mDebug = debug; }
224 inline void StETofCalibMaker::setReferencePulserIndex( const int index ) { mReferencePulserIndex = index; }
225 
226 #endif // STETOFCALIBMAKER_H
void setFileNameCalibParam(const char *fileName)
read calibration parameters from file
StETofCalibMaker(const char *name="etofCalib")
default constructor