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  void setCalState( const bool calTrue );
88  bool calState();
89 
90  void setDoQA( const bool doQA );
91  void setDebug( const bool debug );
92  void setStrictPulserHandling( const bool debug );
93  void setReferencePulserIndex( const int index );
94 
95  short GetState(int);
96  short GetDefaultState(int);
97 
98 
99  //moved to public to avoid problem with root6
101  Int_t geomId;
102  Double_t time;
103  Double_t tot;
104 
105  bool operator==( const StructStuckFwDigi& r ) const {
106  return geomId == r.geomId && fabs( time - r.time ) < 1.e-5 && fabs( tot - r.tot ) < 1.e-5;
107  }
108  };
109 
110  struct stateStruct{
111  int get4Id;
112  unsigned long int evtId;
113  Double_t state;
114  };
115 
116 
117 private:
118  bool isFileExisting( const std::string fileName );
119 
120  void resetToRaw ( StETofDigi* aDigi );
121  void applyMapping ( StETofDigi* aDigi );
122  void flagPulserDigis ( StETofDigi* aDigi, unsigned int index, std::map< unsigned int, std::vector< unsigned int > >& pulserCandMap );
123  void applyCalibration( StETofDigi* aDigi, StETofHeader* etofHeader );
124 
125 
126  void resetToRaw ( StMuETofDigi* aDigi );
127  void applyMapping ( StMuETofDigi* aDigi );
128  void flagPulserDigis ( StMuETofDigi* aDigi, unsigned int index, std::map< unsigned int, std::vector< unsigned int > >& pulserCandMap );
129  void applyCalibration( StMuETofDigi* aDigi, StMuETofHeader* etofHeader );
130 
131  void calculatePulserOffsets( std::map< unsigned int, std::vector< unsigned int > >& pulserCandMap );
132 
133 
134  double calibTotFactor ( StETofDigi* aDigi );
135  double calibTimeOffset( StETofDigi* aDigi );
136  double slewingTimeOffset( StETofDigi* aDigi );
137  double applyPulserOffset( StETofDigi* aDigi );
138 
139  double resetTimeCorr() const;
140 
141  double triggerTime( StETofHeader* etofHeader );
142  double resetTime ( StETofHeader* etofHeader );
143 
144  unsigned int channelToKey( const unsigned int channelId );
145  unsigned int detectorToKey( const unsigned int detectorId );
146  unsigned int sideToKey( const unsigned int sideId );
147 
148 
149  void bookHistograms();
150  void setHistFileName();
151  void writeHistograms();
152 
153  void readGet4State(int fileNr, short forward);
154  void checkGet4State( unsigned long int eventNr);
155 
156  StEvent* mEvent;
157  StMuDst* mMuDst;
158  StETofHardwareMap* mHwMap; // electronic channel to hardware/geometry map
159 
160  std::string mFileNameCalibParam; // name of parameter file for calibration parameters
161  std::string mFileNameElectronicsMap; // name of parameter file for electronics-to-hardware map
162  std::string mFileNameStatusMap; // name of parameter file for status map
163  std::string mFileNameTimingWindow; // name of parameter file for timing window
164  std::string mFileNameSignalVelocity; // name of parameter file for signal velocity
165  std::string mFileNameCalibHistograms; // name of parameter file for calibration histograms (output of QA maker)
166  std::string mFileNameOffsetHistograms; // name of parameter file for run by run offsets histograms (output of QA maker)
167  std::string mFileNameResetTimeCorr; // name of parameter file for reset time correction
168  std::string mFileNamePulserTotPeak; // name of parameter file for pulser peak tot
169  std::string mFileNamePulserTimeDiffGbtx; // name of parameter file for pulser time diff
170 
171  Int_t mRunYear; // "year" of operation by using roughly October 1st as reference
172  Float_t mGet4TotBinWidthNs; // conversion factor for Get4 chip TOT bin to nanoseconds
173  Int_t mMinDigisPerSlewBin; // minimal required statistics per channel and TOT bin to apply slewing corrections
174  Float_t mResetTimeCorr; // additional offset for the whole system in case reset time was not saved correctly
175 
176  Double_t mTriggerTime; // trigger time in ns
177  Double_t mResetTime; // reset time in ns
178  Long64_t mResetTs; // reset time stamp in clock ticks
179 
180  Float_t mPulserPeakTime; // pulser peak time relative to the trigger time in ns
181  Int_t mReferencePulserIndex; // index of reference pulser used in the pulser correction to correct time offset between different Gbtx
182 
183  std::map< UInt_t, std::pair< Float_t, Float_t > > mTimingWindow; // timing window for each AFCK
184  std::map< UInt_t, std::pair< Float_t, Float_t > > mPulserWindow; // pulser window for each AFCK
185  std::map< UInt_t, UInt_t > mStatus; // status of each channel: 0 - not existing/not working, 1 - working
186  std::map< UInt_t, Float_t > mSignalVelocity; // signal velocities in each detector
187 
188  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
189  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
190  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
191 
192  std::map< UInt_t, Float_t > mPulserPeakTot; // TOT of pulsers on each side of the RPC counters (as key)
193  std::map< UInt_t, Double_t > mPulserTimeDiff; // pulser time difference with respect to the reference pulser for each detector side as key
194  std::map< UInt_t, Double_t > mPulserTimeDiffGbtx; // pulser time difference with inside a Gbtx with respect to counter 1
195  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.
196  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.
197  std::map< UInt_t, Bool_t > mPulserPresent; // map of present pulsers for each event (by counter side)
198 
199  std::map< UInt_t, Int_t > mJumpingPulsers; // flag jumping pulsers
200 
201  std::map< UInt_t, Int_t > mUnlockPulserState; // map that counts pulser offsets to avoid locking into the wrong pulser offset state
202 
203  std::vector< StructStuckFwDigi > mStuckFwDigi; // list of digis to ignore for the rest of the run due to stuck firmware
204 
205  Bool_t mStrictPulserHandling;
206  Bool_t mUsePulserGbtxDiff;
207  Bool_t mDoQA;
208  Bool_t mDebug;
209  std::string mHistFileName;
210  std::map< std::string, TH1* > mHistograms;
211 
212 
213  std::string mFileNameGet4State;
214  std::vector<short> mStateVec[1728];
215  std::vector<unsigned long int> mStartVec[1728];
216  std::vector<unsigned long int> mMasterStartVec;
217  std::map<int , short> mGet4StateMap;
218  std::map<int , short> mGet4ZeroStateMap;
219  std::map<int , short> mGet4DefaultStateMap;
220 
221  unsigned long int mStateMapStart;
222  unsigned long int mStateMapStop;
223  unsigned long int mDbEntryStart;
224  unsigned long int mDbEntryStop;
225  int mGlobalCounter;
226  bool mCalState;
227 
228  void decodeInt( std::vector<unsigned long int>& intVec ,std::vector<unsigned long int>& startVec ,std::map<unsigned long int,vector<int>>& stateVec ,std::map<unsigned long int,vector<int>>& get4IdVec);
229 
230 
231  virtual const Char_t *GetCVS() const { static const char cvs[]="Tag $Name: $Id: built " __DATE__ " " __TIME__ ; return cvs; }
232 
233  ClassDef( StETofCalibMaker, 0 )
234 };
235 
236 inline bool StETofCalibMaker::calState( ) { return mCalState; }
237 inline short StETofCalibMaker::GetDefaultState( int get4 ) { return mGet4DefaultStateMap.at(get4); }
238 inline short StETofCalibMaker::GetState( int get4 ) { return mGet4StateMap.at(get4); }
239 inline void StETofCalibMaker::setCalState( const bool calTrue ) { mCalState = calTrue; }
240 
241 inline void StETofCalibMaker::setFileNameCalibParam( const char* fileName ) { mFileNameCalibParam = fileName; }
242 inline void StETofCalibMaker::setFileNameElectronicsMap( const char* fileName ) { mFileNameElectronicsMap = fileName; }
243 inline void StETofCalibMaker::setFileNameStatusMap( const char* fileName ) { mFileNameStatusMap = fileName; }
244 inline void StETofCalibMaker::setFileNameTimingWindow( const char* fileName ) { mFileNameTimingWindow = fileName; }
245 inline void StETofCalibMaker::setFileNameSignalVelocity( const char* fileName ) { mFileNameSignalVelocity = fileName; }
246 inline void StETofCalibMaker::setFileNameCalibHistograms( const char* fileName ) { mFileNameCalibHistograms = fileName; }
247 inline void StETofCalibMaker::setFileNameOffsetHistograms( const char* fileName ) { mFileNameOffsetHistograms = fileName; }
248 inline void StETofCalibMaker::setFileNameResetTimeCorr( const char* fileName ) { mFileNameResetTimeCorr = fileName; }
249 inline void StETofCalibMaker::setFileNamePulserTotPeak( const char* fileName ) { mFileNamePulserTotPeak = fileName; }
250 inline void StETofCalibMaker::setFileNamePulserTimeDiffGbtx( const char* fileName ) { mFileNamePulserTimeDiffGbtx = fileName; }
251 
252 
253 inline double StETofCalibMaker::resetTimeCorr() const { return mResetTimeCorr; }
254 
255 inline void StETofCalibMaker::setStrictPulserHandling( const bool StrictPulserHandling ) { mStrictPulserHandling = StrictPulserHandling; }
256 inline void StETofCalibMaker::setDoQA( const bool doQA ) { mDoQA = doQA; }
257 inline void StETofCalibMaker::setDebug( const bool debug ) { mDebug = debug; }
258 inline void StETofCalibMaker::setReferencePulserIndex( const int index ) { mReferencePulserIndex = index; }
259 
260 #endif // STETOFCALIBMAKER_H
void setFileNameCalibParam(const char *fileName)
read calibration parameters from file
StETofCalibMaker(const char *name="etofCalib")
default constructor