@@ -178,10 +178,140 @@ class TOFResoParamsV2 : public o2::tof::Parameters<13>
178178 // LOG(info) << "TOFResoParamsV2 shift: correction for eta " << eta << " is for index " << etaIndex << " = " << shift;
179179 return mContent .at (etaIndex);
180180 }
181+
182+ void printMomentumChargeShiftParameters () const
183+ {
184+ LOG (info) << " TOF momentum shift parameters" ;
185+ LOG (info) << " etaN: " << mEtaN ;
186+ LOG (info) << " etaStart: " << mEtaStart ;
187+ LOG (info) << " etaStop: " << mEtaStop ;
188+ LOG (info) << " content size " << mContent .size ();
189+ for (int i = 0 ; i < mEtaN ; ++i) {
190+ LOG (info) << " etaC" << i << " : " << mContent [i];
191+ }
192+ }
193+
194+ // Time shift for post calibration
195+ void setTimeShiftParameters (std::unordered_map<std::string, float > const & pars, bool positive)
196+ {
197+ std::string baseOpt = positive ? " TimeShift.Pos." : " TimeShift.Neg." ;
198+
199+ if (pars.count (baseOpt + " GetN" ) == 0 ) { // If the map does not contain the number of eta bins, we assume that no correction has to be applied
200+ return ;
201+ }
202+ const int nPoints = static_cast <int >(pars.at (baseOpt + " GetN" ));
203+ if (nPoints <= 0 ) {
204+ LOG (fatal) << " TOFResoParamsV2 shift: time must be positive" ;
205+ }
206+ TGraph graph;
207+ for (int i = 0 ; i < nPoints; ++i) {
208+ graph.AddPoint (pars.at (Form (" TimeShift.eta%i" , i)), pars.at (Form (" TimeShift.cor%i" , i)));
209+ }
210+ setTimeShiftParameters (&graph, positive);
211+ }
212+ void setTimeShiftParameters (std::string const & filename, std::string const & objname, bool positive)
213+ {
214+ TFile f (filename.c_str (), " READ" );
215+ if (f.IsOpen ()) {
216+ if (positive) {
217+ f.GetObject (objname.c_str (), gPosEtaTimeCorr );
218+ } else {
219+ f.GetObject (objname.c_str (), gNegEtaTimeCorr );
220+ }
221+ f.Close ();
222+ }
223+ LOG (info) << " Set the Time Shift parameters from file " << filename << " and object " << objname << " for " << (positive ? " positive" : " negative" );
224+ }
225+ void setTimeShiftParameters (TGraph* g, bool positive)
226+ {
227+ if (positive) {
228+ gPosEtaTimeCorr = g;
229+ } else {
230+ gNegEtaTimeCorr = g;
231+ }
232+ LOG (info) << " Set the Time Shift parameters from object " << g->GetName () << " " << g->GetTitle () << " for " << (positive ? " positive" : " negative" );
233+ }
234+ float getTimeShift (float eta, int16_t sign) const
235+ {
236+ if (sign > 0 ) {
237+ if (!gPosEtaTimeCorr ) {
238+ return 0 .f ;
239+ }
240+ return gPosEtaTimeCorr ->Eval (eta);
241+ }
242+ if (!gNegEtaTimeCorr ) {
243+ return 0 .f ;
244+ }
245+ return gNegEtaTimeCorr ->Eval (eta);
246+ }
247+
248+ private:
249+ // Charge calibration
250+ int mEtaN = 0 ; // Number of eta bins, 0 means no correction
251+ float mEtaStart = 0 .f;
252+ float mEtaStop = 0 .f;
253+ float mInvEtaWidth = 9999 .f;
254+ std::vector<float > mContent ;
255+
256+ // Time shift for post calibration
257+ TGraph* gPosEtaTimeCorr = nullptr ; // / Time shift correction for positive tracks
258+ TGraph* gNegEtaTimeCorr = nullptr ; // / Time shift correction for negative tracks
259+ };
260+
261+ // / \brief Next implementation class to store TOF response parameters for exp. times
262+ class TOFResoParamsV3 : public o2 ::tof::Parameters<13 >
263+ {
264+ public:
265+ TOFResoParamsV3 () : Parameters(std::array<std::string, 13 >{" TrkRes.Pi.P0" , " TrkRes.Pi.P1" , " TrkRes.Pi.P2" , " TrkRes.Pi.P3" , " time_resolution" ,
266+ " TrkRes.Ka.P0" , " TrkRes.Ka.P1" , " TrkRes.Ka.P2" , " TrkRes.Ka.P3" ,
267+ " TrkRes.Pr.P0" , " TrkRes.Pr.P1" , " TrkRes.Pr.P2" , " TrkRes.Pr.P3" },
268+ " TOFResoParamsV3" )
269+ {
270+ setParameters (std::array<float , 13 >{0.008 , 0.008 , 0.002 , 40.0 , 60.0 ,
271+ 0.008 , 0.008 , 0.002 , 40.0 ,
272+ 0.008 , 0.008 , 0.002 , 40.0 });
273+ } // Default constructor with default parameters
274+
275+ ~TOFResoParamsV3 () = default ;
276+
277+ // Momentum shift for charge calibration
278+ void setMomentumChargeShiftParameters (std::unordered_map<std::string, float > const & pars)
279+ {
280+ if (pars.count (" Shift.etaN" ) == 0 ) { // If the map does not contain the number of eta bins, we assume that no correction has to be applied
281+ mEtaN = 0 ;
282+ return ;
283+ }
284+ mEtaN = static_cast <int >(pars.at (" Shift.etaN" ));
285+ if (mEtaN <= 0 ) {
286+ LOG (fatal) << " TOFResoParamsV3 shift: etaN must be positive" ;
287+ }
288+ mEtaStart = pars.at (" Shift.etaStart" );
289+ mEtaStop = pars.at (" Shift.etaStop" );
290+ if (mEtaStart >= mEtaStop ) {
291+ LOG (fatal) << " TOFResoParamsV3 shift: etaStart must be smaller than etaStop" ;
292+ }
293+ mInvEtaWidth = 1 .f / ((mEtaStop - mEtaStart ) / mEtaN );
294+ mContent .clear ();
295+ mContent .resize (mEtaN );
296+ for (int i = 0 ; i < mEtaN ; ++i) {
297+ mContent [i] = pars.at (Form (" Shift.etaC%i" , i));
298+ }
299+ }
181300 // To remove
182- float getShift (float eta) const
301+ void setShiftParameters (std::unordered_map<std::string, float > const & pars)
302+ {
303+ setMomentumChargeShiftParameters (pars);
304+ }
305+
306+ float getMomentumChargeShift (float eta) const
183307 {
184- return getMomentumChargeShift (eta);
308+ if (mEtaN == 0 ) { // No correction
309+ // LOG(info) << "TOFResoParamsV3 shift: no correction mEtaN is " << mEtaN;
310+ return 0 .f ;
311+ }
312+ const int & etaIndex = (eta <= mEtaStart ) ? 0 : (eta >= mEtaStop ? (mEtaN - 1 ) : (eta - mEtaStart ) * mInvEtaWidth );
313+ // LOG(info) << "TOFResoParamsV3 shift: correction for eta " << eta << " is for index " << etaIndex << " = " << shift;
314+ return mContent .at (etaIndex);
185315 }
186316
187317 void printMomentumChargeShiftParameters () const
@@ -195,12 +325,25 @@ class TOFResoParamsV2 : public o2::tof::Parameters<13>
195325 LOG (info) << " etaC" << i << " : " << mContent [i];
196326 }
197327 }
198- // To remove
199- void printShiftParameters () const
328+
329+ // Time shift for post calibration
330+ void setTimeShiftParameters (std::unordered_map<std::string, float > const & pars, bool positive)
200331 {
201- printMomentumChargeShiftParameters ();
202- }
332+ std::string baseOpt = positive ? " TimeShift.Pos." : " TimeShift.Neg." ;
203333
334+ if (pars.count (baseOpt + " GetN" ) == 0 ) { // If the map does not contain the number of eta bins, we assume that no correction has to be applied
335+ return ;
336+ }
337+ const int nPoints = static_cast <int >(pars.at (baseOpt + " GetN" ));
338+ if (nPoints <= 0 ) {
339+ LOG (fatal) << " TOFResoParamsV3 shift: time must be positive" ;
340+ }
341+ TGraph graph;
342+ for (int i = 0 ; i < nPoints; ++i) {
343+ graph.AddPoint (pars.at (Form (" TimeShift.eta%i" , i)), pars.at (Form (" TimeShift.cor%i" , i)));
344+ }
345+ setTimeShiftParameters (&graph, positive);
346+ }
204347 void setTimeShiftParameters (std::string const & filename, std::string const & objname, bool positive)
205348 {
206349 TFile f (filename.c_str (), " READ" );
@@ -285,10 +428,10 @@ class ExpTimes
285428 return defaultReturnValue;
286429 }
287430 if (track.trackType () == o2::aod::track::Run2Track) {
288- return ComputeExpectedTime (track.tofExpMom () * kCSPEDDInv / (1 .f + track.sign () * parameters.getShift (track.eta ())), track.length ());
431+ return ComputeExpectedTime (track.tofExpMom () * kCSPEDDInv / (1 .f + track.sign () * parameters.getMomentumChargeShift (track.eta ())), track.length ());
289432 }
290- LOG (debug) << " TOF exp. mom. " << track.tofExpMom () << " shifted = " << track.tofExpMom () / (1 .f + track.sign () * parameters.getShift (track.eta ()));
291- return ComputeExpectedTime (track.tofExpMom () / (1 .f + track.sign () * parameters.getShift (track.eta ())), track.length ()) + parameters.getTimeShift (track.eta (), track.sign ());
433+ LOG (debug) << " TOF exp. mom. " << track.tofExpMom () << " shifted = " << track.tofExpMom () / (1 .f + track.sign () * parameters.getMomentumChargeShift (track.eta ()));
434+ return ComputeExpectedTime (track.tofExpMom () / (1 .f + track.sign () * parameters.getMomentumChargeShift (track.eta ())), track.length ()) + parameters.getTimeShift (track.eta (), track.sign ());
292435 }
293436
294437 // / Gets the expected resolution of the t-texp-t0
0 commit comments