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