]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/TenderSupplies/AliTOFTenderSupply.cxx
New version of Add task tender allowing to customize the components
[u/mrichter/AliRoot.git] / ANALYSIS / TenderSupplies / AliTOFTenderSupply.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16
17 ///////////////////////////////////////////////////////////////////////////////
18 //                                                                           //
19 // TOF tender: - load updated calibrations (for TOF and T0)
20 //             - set tofHeader if missing in ESDs (2010 data)
21 //             - re-apply PID 
22 //             
23 // Contacts: Pietro.Antonioli@bo.infn.it                                     //
24 //           Francesco.Noferini@bo.infn.it                                   //
25 ///////////////////////////////////////////////////////////////////////////////
26 #include <TFile.h>
27 #include <TChain.h>
28
29 #include <TMath.h>
30 #include <TRandom.h>
31 #include <AliLog.h>
32 #include <AliESDEvent.h>
33 #include <AliESDtrack.h>
34 #include <AliESDInputHandler.h>
35 #include <AliAnalysisManager.h>
36 #include <AliESDpid.h>
37 #include <AliTender.h>
38
39 #include <AliTOFcalib.h>
40 #include <AliTOFT0maker.h>
41
42 #include <AliGeomManager.h>
43 #include <AliCDBManager.h>
44 #include <AliCDBEntry.h>
45 #include <AliT0CalibSeasonTimeShift.h>
46
47 #include "AliTOFTenderSupply.h"
48
49 ClassImp(AliTOFTenderSupply)
50
51 Float_t AliTOFTenderSupply::fgT0Aresolution = 75.;
52 Float_t AliTOFTenderSupply::fgT0Cresolution = 65.;
53
54 AliTOFTenderSupply::AliTOFTenderSupply() :
55   AliTenderSupply(),
56   fESDpid(0x0),
57   fIsMC(kFALSE),
58   fTimeZeroType(AliESDpid::kBest_T0),
59   fCorrectExpTimes(kTRUE),
60   fCorrectTRDBug(kFALSE),
61   fLHC10dPatch(kFALSE),
62   fT0DetectorAdjust(kFALSE),
63   fDebugLevel(0),
64   fAutomaticSettings(kTRUE),
65   fRecoPass(0),
66   fUserRecoPass(0),
67   fTOFCalib(0x0),
68   fTOFT0maker(0x0),
69   fTOFres(100.),
70   fT0IntercalibrationShift(0),
71   fGeomSet(kFALSE),
72   fIsEnteringInTRD(kFALSE),
73   fInTRD(kFALSE),
74   fIsComingOutTRD(kFALSE),
75   fOutTRD(kFALSE),
76   fRhoTRDin(288.38), // cm
77   fRhoTRDout(366.38), // cm
78   fStep(0.5),
79   fMagField(0.),
80   fCDBkey(0)
81
82
83
84 {
85   //
86   // default ctor
87   //
88   fT0shift[0] = 0;
89   fT0shift[1] = 0;
90   fT0shift[2] = 0;
91   fT0shift[3] = 0;
92 }
93
94 //_____________________________________________________
95 AliTOFTenderSupply::AliTOFTenderSupply(const char *name, const AliTender *tender) :
96   AliTenderSupply(name,tender),
97   fESDpid(0x0),
98   fIsMC(kFALSE),
99   fTimeZeroType(AliESDpid::kBest_T0),
100   fCorrectExpTimes(kTRUE),
101   fCorrectTRDBug(kFALSE),
102   fLHC10dPatch(kFALSE),
103   fT0DetectorAdjust(kFALSE),
104   fDebugLevel(0),
105   fAutomaticSettings(kTRUE),
106   fRecoPass(0),
107   fUserRecoPass(0),
108   fTOFCalib(0x0),
109   fTOFT0maker(0x0),
110   fTOFres(100.),
111   fT0IntercalibrationShift(0),
112   fGeomSet(kFALSE),
113   fIsEnteringInTRD(kFALSE),
114   fInTRD(kFALSE),
115   fIsComingOutTRD(kFALSE),
116   fOutTRD(kFALSE),
117   fRhoTRDin(288.38), // cm
118   fRhoTRDout(366.38), // cm
119   fStep(0.5),
120   fMagField(0.),
121   fCDBkey(0)
122  
123 {
124   //
125   // named ctor
126   //
127
128   fT0shift[0] = 0;
129   fT0shift[1] = 0;
130   fT0shift[2] = 0;
131   fT0shift[3] = 0;
132 }
133
134 //_____________________________________________________
135 void AliTOFTenderSupply::Init()
136 {
137
138   Bool_t tenderUnsupported = kFALSE;
139   // Initialise TOF tender (this is called at each detected run change)
140   AliLog::SetClassDebugLevel("AliTOFTenderSupply",10); 
141
142   // Setup PID object, check for MC, set AliTOFcalib and TOFT0 maker conf
143   Int_t run = fTender->GetRun();
144   if (run == 0) return;                // to skip first init, when we don't have yet a run number
145
146   fGeomSet=kFALSE;                         
147   // Even if the user didn't set fIsMC, we force it on if we find the MC handler  
148   AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();
149   if (mgr->GetMCtruthEventHandler() && !(fIsMC) ) {
150     AliWarning("This ESD is MC, fIsMC found OFF: fIsMC turned ON");
151     fIsMC=kTRUE;
152   }
153
154   if (fAutomaticSettings) {
155     if (!fIsMC) {
156       if (fUserRecoPass == 0) DetectRecoPass();
157       else fRecoPass = fUserRecoPass;
158     }
159     if (run<114737) {
160       tenderUnsupported = kTRUE;
161     }
162     else if (run>=114737&&run<=117223) {      //period="LHC10B";
163       if (fRecoPass == 2) {fCorrectExpTimes=kTRUE; fCorrectTRDBug=kFALSE;}
164       else if (fRecoPass == 3) {fCorrectExpTimes=kFALSE; fCorrectTRDBug=kTRUE;}
165       fLHC10dPatch=kFALSE;
166       fTOFres=100.;
167       fTimeZeroType=AliESDpid::kTOF_T0;
168       fT0IntercalibrationShift = 0;
169       fT0DetectorAdjust=kTRUE;
170     }
171     else if (run>=118503&&run<=121040) { //period="LHC10C";
172       if (fRecoPass == 2) {fCorrectExpTimes=kTRUE; fCorrectTRDBug=kFALSE;}
173       else if (fRecoPass == 3) {fCorrectExpTimes=kFALSE; fCorrectTRDBug=kTRUE;}
174       fLHC10dPatch=kFALSE;
175       fTOFres=100.;
176       fTimeZeroType=AliESDpid::kTOF_T0;
177       fT0IntercalibrationShift = 0;
178       fT0DetectorAdjust=kFALSE;
179     }
180     else if (run>=122195&&run<=126437) { //period="LHC10D";
181       fCorrectExpTimes=kFALSE;
182       fLHC10dPatch=kTRUE;
183       fTOFres=100.;
184       fTimeZeroType=AliESDpid::kBest_T0;
185       fT0IntercalibrationShift = 0;
186       fT0DetectorAdjust=kTRUE;
187     }
188     else if (run>=127719&&run<=130850) { //period="LHC10E";
189       fCorrectExpTimes=kFALSE;
190       fLHC10dPatch=kFALSE;
191       fTOFres=100.;
192       fTimeZeroType=AliESDpid::kBest_T0;
193       fT0IntercalibrationShift = 30.;
194       fT0DetectorAdjust=kTRUE;
195     }
196     else if (run>=133004&&run<=135029) { //period="LHC10F";
197       fCorrectExpTimes=kFALSE;
198       fLHC10dPatch=kFALSE;
199       fTOFres=100.;
200       fTimeZeroType=AliESDpid::kBest_T0;
201       fT0IntercalibrationShift = 0.;
202       fT0DetectorAdjust=kTRUE;
203       AliWarning("TOF tender not supported for LHC10F period!! Settings are just a guess!!");
204     }
205     else if (run>=135654&&run<=136377) { //period="LHC10G";
206       fCorrectExpTimes=kFALSE;
207       fLHC10dPatch=kFALSE;
208       fTOFres=100.;
209       fTimeZeroType=AliESDpid::kBest_T0;
210       fT0IntercalibrationShift = 0.;
211       fT0DetectorAdjust=kTRUE;
212       AliWarning("TOF tender not supported for LHC10G period!! Settings are just a guess!!");
213     }
214     else if (run>=136851&&run<=139517) { //period="LHC10H" - pass2;
215       fCorrectExpTimes=kFALSE;
216       fLHC10dPatch=kFALSE;                
217       fTOFres=90.;
218       fTimeZeroType=AliESDpid::kTOF_T0;
219       fT0IntercalibrationShift = 0.;
220       fT0DetectorAdjust=kTRUE;
221     }
222     else if (run>=139699) {              //period="LHC11A";
223       /*
224       fCorrectExpTimes=kFALSE;
225       fLHC10dPatch=kFALSE;
226       fTOFres=100.;
227       fTimeZeroType=AliESDpid::kBest_T0;
228       fT0IntercalibrationShift = 0.;
229       fT0DetectorAdjust=kFALSE;
230       AliWarning("TOF tender not supported for LHC11A period!! Settings are just a guess!!");
231       */
232       AliError("TOF tender not supported for 2011 data!!!!!");
233       tenderUnsupported = kTRUE;
234     }
235   }
236
237   if (tenderUnsupported) {
238     AliInfo(" |---------------------------------------------------------------------------|");
239     AliInfo(" |                                                                           |");
240     AliInfo(Form(" |  TOF tender is not supported for run %d                               |",run));
241     AliInfo(" | You cannot use TOF tender for this run, your results can be spoiled       |");
242     AliInfo(" | Check TOF tender usage for run/periods at:                                |");
243     AliInfo(" |  https://twiki.cern.ch/twiki/bin/view/ALICE/TOF.                          |");
244     AliInfo(" |---------------------------------------------------------------------------|");
245     AliInfo(" ");
246     AliFatal(" ------- TOF tender not to be used in this run, issuing FATAL error -------- ");
247   }
248
249   // Check if another tender wagon already created the esd pid object
250   // if not we create it and set it to the ESD input handler
251   fESDpid=fTender->GetESDhandler()->GetESDpid();
252   if (!fESDpid) {
253     fESDpid=new AliESDpid;
254     fTender->GetESDhandler()->SetESDpid(fESDpid);
255   }
256
257
258   // Configure TOF calibration class
259   if (!fTOFCalib)fTOFCalib=new AliTOFcalib();  // create if needed
260   fTOFCalib->SetRemoveMeanT0(!(fIsMC));        // must be kFALSE on MC (default is kTRUE)
261   fTOFCalib->SetCalibrateTOFsignal(!(fIsMC));  // must be kFALSE on MC (no new calibration) (default is kTRUE)
262   fTOFCalib->SetCorrectTExp(fCorrectExpTimes); // apply a fine tuning on the expected times at low momenta
263                                                // (this is done for LHC10b/LHC10c pass2)
264
265   // Configure TOFT0 maker class
266   //  if (!fTOFT0maker) fTOFT0maker = new AliTOFT0maker(fESDpid,fTOFCalib); // create if needed
267   if (!fTOFT0maker) fTOFT0maker = new AliTOFT0maker(fESDpid); // without passing AliTOFCalib it uses the diamond
268   fTOFT0maker->SetTimeResolution(fTOFres);     // set TOF resolution for the PID
269   fTOFT0maker->SetTOFT0algorithm(2);
270
271   AliInfo("|******************************************************|");
272   AliInfo(Form("|    Alice TOF Tender Initialisation (Run %d)  |",fTender->GetRun()));
273   AliInfo("|    Settings:                                         |");
274   AliInfo(Form("|    Correct Exp Times              :  %d               |",fCorrectExpTimes));
275   AliInfo(Form("|    Correct TRD Bug                :  %d               |",fCorrectTRDBug));
276   AliInfo(Form("|    LHC10d patch                   :  %d               |",fLHC10dPatch));
277   AliInfo(Form("|    TOF resolution for TOFT0 maker :  %5.2f (ps)     |",fTOFres));
278   AliInfo(Form("|    timeZero selection             :  %d               |",fTimeZeroType));
279   AliInfo(Form("|    MC flag                        :  %d               |",fIsMC));
280   AliInfo(Form("|    T0 detector offsets applied    :  %d               |",fT0DetectorAdjust));
281   AliInfo(Form("|    TOF/T0 intecalibration shift   :  %5.2f (ps)     |",fT0IntercalibrationShift));
282   AliInfo("|******************************************************|");
283
284
285 }
286
287 //_____________________________________________________
288 void AliTOFTenderSupply::ProcessEvent()
289 {
290   //
291   // Use updated calibrations for TOF and T0, reapply PID information
292   // For MC: timeZero sampling and additional smearing for T0
293
294   if (fDebugLevel > 1) AliInfo("process event");
295
296   AliESDEvent *event=fTender->GetEvent();
297   if (!event) return;
298   if (fDebugLevel > 1) AliInfo("event read");
299
300
301     
302   if (fTender->RunChanged()){ 
303
304     Init();            
305     Int_t versionNumber = GetOCDBVersion(fTender->GetRun());
306     fTOFCalib->SetRunParamsSpecificVersion(versionNumber);
307     fTOFCalib->Init(fTender->GetRun());
308     
309     if(event->GetT0TOF()){ // read T0 detector correction from OCDB
310       // OCDB instance
311       if (fT0DetectorAdjust) {
312         AliCDBManager* ocdbMan = AliCDBManager::Instance();
313         ocdbMan->SetRun(fTender->GetRun());    
314         AliCDBEntry *entry = ocdbMan->Get("T0/Calib/TimeAdjust/");
315         if(entry) {
316           AliT0CalibSeasonTimeShift *clb = (AliT0CalibSeasonTimeShift*) entry->GetObject();
317           Float_t *t0means= clb->GetT0Means();
318           //      Float_t *t0sigmas = clb->GetT0Sigmas();
319           fT0shift[0] = t0means[0] + fT0IntercalibrationShift;
320           fT0shift[1] = t0means[1] + fT0IntercalibrationShift;
321           fT0shift[2] = t0means[2] + fT0IntercalibrationShift;
322           fT0shift[3] = t0means[3] + fT0IntercalibrationShift;
323         } else {
324           for (Int_t i=0;i<4;i++) fT0shift[i]=0;
325           AliWarning("TofTender no T0 entry found T0shift set to 0");
326         }
327       } else {
328         for (Int_t i=0;i<4;i++) fT0shift[i]=0;
329       }
330     }
331   }
332
333
334   fTOFCalib->CalibrateESD(event);   //recalculate TOF signal (no harm for MC, see settings inside init)
335
336
337   // patches for various reconstruction bugs
338   if (fLHC10dPatch && !(fIsMC)) RecomputeTExp(event);   // LHC10d pass2: fake full TRD geometry
339   if (fCorrectTRDBug && !(fIsMC)) FixTRDBug(event);     // LHC10b,c pass3: wrong TRD dE/dx 
340
341   Double_t startTime = 0.;
342   if(fIsMC) startTime = fTOFCalib->TuneForMC(event,fTOFres);   // this is for old MC when we didn't jitter startTime in MC
343
344   if (fDebugLevel > 1) Printf(" TofTender: startTime %f",startTime);
345   if (fDebugLevel > 1) Printf(" TofTender: T0 time (orig) %f %f %f",event->GetT0TOF(0),event->GetT0TOF(1),event->GetT0TOF(2));
346
347   // event by event TO detector treatment  
348   if(event->GetT0TOF()){   // protection: we adjust T0 only if it is there....
349
350     if (event->GetT0TOF(0) == 0) event->SetT0TOF(0, 9999999.); // in case no information we set to unknown
351     if (event->GetT0TOF(1) == 0) event->SetT0TOF(1, 99999.);
352     if (event->GetT0TOF(2) == 0) event->SetT0TOF(2, 99999.);
353
354     if(!fIsMC){   // data: apply shifts to align around Zero
355       event->SetT0TOF(0,event->GetT0TOF(0) - fT0shift[0]);
356       event->SetT0TOF(1,event->GetT0TOF(1) - fT0shift[1]);
357       event->SetT0TOF(2,event->GetT0TOF(2) - fT0shift[2]);
358     } else {
359       // MC: add smearing for realistic T0A and T0C resolution
360       Double_t defResolutionT0A = 33.;   // in future we will get this from ESDrun data structure or via OCDB
361       Double_t defResolutionT0C = 30.;   // for the moment we don't trust them
362       if ( (fgT0Aresolution > defResolutionT0A) && (event->GetT0TOF(1)<90000.) ) { // add smearing only if signal is there
363         Double_t addedSmearingT0A = TMath::Sqrt(fgT0Aresolution*fgT0Aresolution - defResolutionT0A*defResolutionT0A);
364         Double_t smearingT0A = gRandom->Gaus(0.,addedSmearingT0A);
365         event->SetT0TOF(1,event->GetT0TOF(1) + smearingT0A);
366       }
367       if ( (fgT0Cresolution > defResolutionT0C) && (event->GetT0TOF(2)<90000.) ) { // add smearing only if signal is there
368         Double_t addedSmearingT0C = TMath::Sqrt(fgT0Cresolution*fgT0Cresolution - defResolutionT0C*defResolutionT0C);
369         Double_t smearingT0C = gRandom->Gaus(0.,addedSmearingT0C);
370         event->SetT0TOF(2,event->GetT0TOF(2) + smearingT0C);
371       }
372       if (event->GetT0TOF(0)<90000.) { // we recompute the AND only if it is already there...
373         Double_t smearedT0AC = (event->GetT0TOF(1)+event->GetT0TOF(2))/2.;
374         event->SetT0TOF(0,smearedT0AC); 
375       }
376       if (fDebugLevel > 1) Printf(" TofTender: T0 time (postSmear) %f %f %f",event->GetT0TOF(0),event->GetT0TOF(1),event->GetT0TOF(2));
377       // add finally the timeZero offset also to the T0 detector information
378       event->SetT0TOF(0,event->GetT0TOF(0) + startTime);
379       event->SetT0TOF(1,event->GetT0TOF(1) + startTime);
380       event->SetT0TOF(2,event->GetT0TOF(2) + startTime);  
381       if (fDebugLevel > 1) Printf(" TofTender: T0 time (postStart) %f %f %f",event->GetT0TOF(0),event->GetT0TOF(1),event->GetT0TOF(2));
382     }
383     // after shifts adjust (data) or smearing+offset (MC) we 'clean' to default if signals not there 
384     if(event->GetT0TOF(0) > 900000) event->SetT0TOF(0, 999999.);
385     if(event->GetT0TOF(1) > 90000)  event->SetT0TOF(1, 99999.);
386     if(event->GetT0TOF(2) > 90000)  event->SetT0TOF(2, 99999.);
387   }
388   if (fDebugLevel > 1) Printf(" TofTender: T0 time (FINAL) %f %f %f",event->GetT0TOF(0),event->GetT0TOF(1),event->GetT0TOF(2));
389   
390   //compute timeZero of the event via TOF-TO
391   fTOFT0maker->ComputeT0TOF(event);
392   fTOFT0maker->WriteInESD(event);
393
394   //set preferred startTime
395   fESDpid->SetTOFResponse(event, (AliESDpid::EStartTimeType_t)fTimeZeroType);
396
397   // recalculate PID probabilities
398   // this is for safety, especially if the user doesn't attach a PID tender after TOF tender  
399   Int_t ntracks=event->GetNumberOfTracks();
400   //  AliESDtrack *track = NULL;
401   //  Float_t tzeroTrack = 0;
402   for(Int_t itrack = 0; itrack < ntracks; itrack++){
403     //    track = event->GetTrack(itrack);
404     //    tzeroTrack = fESDpid->GetTOFResponse().GetStartTime(track->P());
405     //    Printf("================> Track # %d mom: %f tzeroTrack %f",itrack,track->P(),tzeroTrack);
406     fESDpid->MakeTOFPID(event->GetTrack(itrack),0);   
407   }
408   
409   
410 }
411
412
413 //_____________________________________________________
414 void AliTOFTenderSupply::RecomputeTExp(AliESDEvent *event) const
415 {
416   /*
417    * calibrate TExp
418    */
419
420   
421   /* loop over tracks */
422   AliESDtrack *track = NULL;
423   for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
424     /* get track and calibrate */
425     track = event->GetTrack(itrk);
426     RecomputeTExp(track);
427   }
428   
429 }
430
431 //_____________________________________________________
432 void AliTOFTenderSupply::RecomputeTExp(AliESDtrack *track) const
433 {
434   /*** 
435        THIS METHOD IS BASED ON THEORETICAL EXPECTED TIME COMPUTED
436        USING AVERAGE MOMENTUM BETWEEN INNER/OUTER TRACK PARAMS 
437        IT IS A ROUGH APPROXIMATION APPLIED TO FIX LHC10d-pass2 DATA
438        WHERE A WRONG GEOMETRY (FULL TRD) WAS INSERTED
439   ***/
440
441   Double_t texp[AliPID::kSPECIES];
442   if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) return;
443
444
445   /* get track params */
446   Float_t l = track->GetIntegratedLength();
447   Float_t p = track->P();
448   if (track->GetInnerParam() && track->GetOuterParam()) {
449     Float_t pin = track->GetInnerParam()->P();
450     Float_t pout = track->GetOuterParam()->P();
451     p = 0.5 * (pin + pout);
452   }
453   /* loop over particle types and compute expected time */
454   for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++)
455     texp[ipart] = GetExpTimeTh(AliPID::ParticleMass(ipart), p, l) - 37.; 
456   // 37 is a final semiempirical offset to further adjust (calibrations were
457   // done with "standard" integratedTimes)
458   /* set integrated times */
459   track->SetIntegratedTimes(texp);
460
461 }
462
463
464 //______________________________________________________________________________
465 void AliTOFTenderSupply::DetectRecoPass()
466 {
467   //
468   // Detect reconstruction information
469   //
470   
471   //reset information
472   fRecoPass=0;
473   
474   //Get the current file to check the reconstruction pass (UGLY, but not stored in ESD... )
475   AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();
476   AliVEventHandler *inputHandler=mgr->GetInputEventHandler();
477   if (!inputHandler) return;
478   
479   TTree *tree= (TTree*)inputHandler->GetTree();
480   TFile *file= (TFile*)tree->GetCurrentFile();
481   
482   if (!file) {
483     AliFatal("Current file not found");
484     return; // coverity
485   }
486   
487   //find pass from file name (UGLY, but not stored in ESD... )
488   TString fileName(file->GetName());
489   if (fileName.Contains("pass1") ) {
490     fRecoPass=1;
491   } else if (fileName.Contains("pass2") ) {
492     fRecoPass=2;
493   } else if (fileName.Contains("pass3") ) {
494     fRecoPass=3;
495   }
496   if (fRecoPass == 0) {
497     AliInfo(Form("From file name %s reco pass cannot be detected",fileName.Data()));
498     AliInfo("Change file name or use SetUserRecoPass method");
499     AliFatal("------------- TOF tender cannot run with reco pass unspecified, issuing FATAL error ---------- ");
500   }
501 }
502
503
504 //______________________________________________________________________________
505 void AliTOFTenderSupply::InitGeom()
506 {
507
508   if (fGeomSet == kTRUE) return;
509
510   //  Printf("\n \n ----- calling InitGeom to fix TRD Bug ----- \n \n");
511   AliCDBManager * man = AliCDBManager::Instance();
512   man->SetDefaultStorage("raw://");
513   fCDBkey = man->SetLock(kFALSE, fCDBkey);
514   Int_t run = fTender->GetRun();
515   //  Printf(" ---------> run is %d",run);
516   man->SetRun(run);
517   AliCDBEntry *entry = (AliCDBEntry*)man->Get("GRP/Geometry/Data");
518   if (entry) {
519     AliGeomManager::LoadGeometry();
520     AliGeomManager::ApplyAlignObjsFromCDB("ITS TPC TRD TOF");
521     //    fCDBkey = man->SetLock(kTRUE, fCDBkey);
522     //    Printf("\n \n ----- Geometry loaded ------ \n \n");
523   }
524   fGeomSet=kTRUE;
525
526 }
527
528
529 //______________________________________________________________________________
530 void AliTOFTenderSupply::FixTRDBug(AliESDEvent* event)
531 //
532 // recompute texp fixing wrong dE/dx from TRD (LHC10b,c pass3)
533 //
534 {
535
536   if (fGeomSet == kFALSE) InitGeom();
537
538   //  Printf("Running FixTRD bug ");
539   /* loop over tracks */
540   AliESDtrack *track = NULL;
541   for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
542     track = event->GetTrack(itrk);
543     FixTRDBug(track);
544   }
545 }
546
547
548 //_____________________________________________________
549 void AliTOFTenderSupply::FixTRDBug(AliESDtrack *track)
550 {
551   // 
552   //
553   //
554
555
556     ULong_t status=track->GetStatus();
557     if (!( ( (status & AliVTrack::kITSrefit)==AliVTrack::kITSrefit ) &&
558            ( (status & AliVTrack::kTPCrefit)==AliVTrack::kTPCrefit ) &&
559            ( (status & AliVTrack::kTPCout)==AliVTrack::kTPCout ) &&
560            ( (status & AliVTrack::kTOFout)==AliVTrack::kTOFout ) &&
561            ( (status & AliVTrack::kTIME)==AliVTrack::kTIME ) ) ) return;
562
563     fIsEnteringInTRD=kFALSE;
564     fInTRD=kFALSE;
565     fIsComingOutTRD=kFALSE;
566     fOutTRD=kFALSE;
567
568     //    Printf("Track reached TOF %f",track->P());
569     Double_t correctionTimes[5] = {0.,0.,0.,0.,0.}; // to be added to the expected times
570     FindTRDFix(track, correctionTimes);
571     Double_t expectedTimes[5] = {0.,0.,0.,0.,0.}; track->GetIntegratedTimes(expectedTimes);
572     //    Printf("Exp. times: %f %f %f %f %f",
573     //     expectedTimes[0],expectedTimes[1],expectedTimes[2],expectedTimes[3],expectedTimes[4]);
574     //    Printf("Corr. times: %f %f %f %f %f",
575     //     correctionTimes[0],correctionTimes[1],correctionTimes[2],correctionTimes[3],correctionTimes[4]);
576
577     for (Int_t jj=0; jj<5; jj++) expectedTimes[jj]+=correctionTimes[jj];
578     track->SetIntegratedTimes(expectedTimes);
579   
580 }
581
582
583 //________________________________________________________________________
584 void AliTOFTenderSupply::FindTRDFix(AliESDtrack *track,Double_t *corrections)
585 {
586
587   Double_t pT = track->Pt();
588   ULong_t status=track->GetStatus();
589   Bool_t isTRDout = (status & AliVTrack::kTRDout)==AliVTrack::kTRDout;
590
591   Double_t length = 0.;
592
593   Double_t xyzIN[3]={0.,0.,0.};
594   fIsEnteringInTRD = track->GetXYZAt(fRhoTRDin,fMagField,xyzIN);
595
596   Double_t xyzOUT[3]={0.,0.,0.};
597   fIsComingOutTRD = track->GetXYZAt(fRhoTRDout,fMagField,xyzOUT);
598
599   if (fIsEnteringInTRD && fIsComingOutTRD) {
600
601
602     Double_t phiIN = TMath::Pi()+TMath::ATan2(-xyzIN[1],-xyzIN[0]);
603     phiIN *= TMath::RadToDeg();
604     fInTRD = ( (phiIN>=  0. && phiIN<= 40.) ||
605                (phiIN>=140. && phiIN<=220.) ||
606                (phiIN>=340. && phiIN<=360.) ); // TRD SMs installed @ 2010
607
608     Double_t phiOUT = TMath::Pi()+TMath::ATan2(-xyzOUT[1],-xyzOUT[0]);
609     phiOUT *= TMath::RadToDeg();
610     fOutTRD = ( (phiOUT>=  0. && phiOUT<= 40.) ||
611                 (phiOUT>=140. && phiOUT<=220.) ||
612                 (phiOUT>=340. && phiOUT<=360.) ); // TRD SMs installed @ 2010
613
614     length = 0.;
615
616     if (fInTRD || fOutTRD) {
617
618       if ( ( fInTRD && fOutTRD ) || ( fInTRD && !fOutTRD ) ) {
619         length = EstimateLengthInTRD1(track);
620       } else if ( !fInTRD && fOutTRD ) {
621         length = EstimateLengthInTRD2(track);
622       }
623
624     } else { // ( !fInTRD && !fOutTRD )
625
626       length = EstimateLengthOutTRD(track);
627
628     }
629
630   }
631   //  Printf("estimated length in TRD %f [isTRDout %d]",length,isTRDout);
632   CorrectDeltaTimes(pT,length,isTRDout,corrections);
633
634 }
635
636 //________________________________________________________________________
637 void AliTOFTenderSupply::CorrectDeltaTimes(Double_t pT,
638                                                 Double_t length,
639                                                 Bool_t flagTRDout,
640                                                 Double_t *corrections)
641 {
642
643   corrections[2] = CorrectExpectedPionTime(pT,length,flagTRDout);
644   corrections[0] = corrections[2]; // x electrons used pion corrections
645   corrections[1] = corrections[2]; // x muons used pion corrections
646   corrections[3] = CorrectExpectedKaonTime(pT,length,flagTRDout);
647   corrections[4] = CorrectExpectedProtonTime(pT,length,flagTRDout);
648
649 }
650
651 //________________________________________________________________________
652 Double_t AliTOFTenderSupply::CorrectExpectedPionTime(Double_t pT,
653                                                           Double_t length,
654                                                           Bool_t isTRDout)
655 {
656   // correction for expected time for pions
657
658   Double_t delta=0.;
659
660   //  Printf("Flags Ent In ComingOut Out %d %d %d %d",fIsEnteringInTRD,fInTRD,fIsComingOutTRD,fOutTRD);
661   if (!fIsEnteringInTRD || !fIsComingOutTRD) { // zone 5
662
663     Float_t p[2]={0.,0.};
664
665     if (isTRDout) {
666
667       if (pT<0.30) {
668         p[0] = 180.; p[1] = 0.;
669       } else if (pT>=0.30 && pT<0.35) {
670         p[0] = 740.; p[1] = -1800.;
671       } else if (pT>=0.35 && pT<0.40) {
672         p[0] = 488.; p[1] =-1080.;
673       } else if (pT>=0.40 && pT<0.45) {
674         p[0] = 179.; p[1] = -307.;
675       } else if (pT>=0.45 && pT<0.50) {
676         p[0] =  97.; p[1] = -123.;
677       } else { //if (pT>=0.50)
678         p[0] = 120.; p[1] = -172.;
679       }
680
681     } else {
682
683       if (pT<0.30) {
684         p[0] =  70.; p[1] =    0.;
685       } else if (pT>=0.30 && pT<0.35) {
686         p[0] = 339.; p[1] = -927.;
687       } else if (pT>=0.35 && pT<0.40) {
688         p[0] =  59.; p[1] = -121.;
689       } else if (pT>=0.40 && pT<0.50) {
690         p[0] =  21.; p[1] =  -24.;
691       } else { //if (pT>=0.50)
692         p[0] =  42.; p[1] =  -67.;
693       }
694
695     }
696
697     delta = p[0]+p[1]*pT;
698     //    Printf("Pion time: %f %f %f %f",p[0],p[1],length,delta);
699
700   } else {
701
702     Float_t p[2] = {0.,0.};
703
704     if ( fInTRD &&  fOutTRD) { // zone 1
705
706       if (isTRDout) {
707
708         if (length<130.) {
709           p[0] = 0.; p[1] = 0.;
710         } else if (length>=130. && length<170.) {
711           p[0] = -20.5; p[1] = 0.25;
712         } else {//if (length>=170.)
713           p[0] = 22.; p[1] = 0.;
714         }
715
716       } else { // !isTRDout
717
718         p[0] = 20.; p[1] = 0.;
719
720       }
721
722     } else if (!fInTRD && !fOutTRD) { // zone 2
723
724       p[0] = 0.; p[1] = 0.;
725
726     } else if ( fInTRD &&  !fOutTRD) { // zone 3
727
728       if (isTRDout) {
729
730         if (length< 75.) {
731           p[0] = 17.; p[1] =  0.;
732         } else if (length>= 75. && length< 95.) {
733           p[0] = 81.; p[1] = -0.85;
734         } else if (length>= 95. && length<155.) {
735           p[0] =  0.; p[1] =  0.;
736         } else {//if (length>=155.)
737           p[0] = 10.; p[1] =  0.;
738         }
739
740       } else { // !isTRDout
741
742         p[0] = 0.; p[1] = 0.;
743
744       }
745
746     } else if (!fInTRD &&  fOutTRD) { // zone 4
747
748       if (isTRDout) {
749
750         if (length<80.) {
751           p[0] =  0.; p[1] =  0.;
752         } else {//if (length>=80.)
753           p[0] = 10.; p[1] =  0.;
754         }
755
756       } else { // !isTRDout
757
758         if (length<30.) {
759           p[0] =  0.; p[1] =  0.;
760         } else {//if (length>=30.)
761           p[0] =  6.; p[1] =  0.;
762         }
763
764       }
765
766     }
767
768     delta = p[0]+p[1]*length;
769     //    Printf("Pion time: %f %f %f %f",p[0],p[1],length,delta);
770
771   }
772
773   return delta;
774
775 }
776
777 //________________________________________________________________________
778 Double_t AliTOFTenderSupply::CorrectExpectedKaonTime(Double_t pT,
779                                                           Double_t length,
780                                                           Bool_t isTRDout)
781 {
782   // correction for expected time for kaons
783
784   Double_t delta=0.;
785   //  Printf("Flags Ent In ComingOut Out %d %d %d %d",fIsEnteringInTRD,fInTRD,fIsComingOutTRD,fOutTRD);
786
787   if (!fIsEnteringInTRD || !fIsComingOutTRD) { // zone 5
788
789     Float_t p[2]={0.,0.};
790
791     if (isTRDout) {
792
793       if (pT<0.4) {
794         p[0] =  900.; p[1] = 0.;
795       } else if (pT>=0.40 && pT<0.45) {
796         p[0] = 3100.; p[1] = -6000.;
797       } else if (pT>=0.45 && pT<0.50) {
798         p[0] = 1660.; p[1] = -2800.;
799       } else if (pT>=0.50 && pT<0.55) {
800         p[0] =  860.; p[1] = -1200.;
801       } else { //if (pT>=0.55)
802         p[0] =  200.; p[1] = 0.;
803       }
804
805     } else {
806
807       if (pT<0.30) {
808         p[0] =   0.; p[1] =    0.;
809       } else if (pT>=0.30 && pT<0.32) {
810         p[0] = 570.; p[1] =    0.;
811       } else if (pT>=0.32 && pT<0.35) {
812         p[0] = 3171.; p[1] = -8133.;
813       } else if (pT>=0.35 && pT<0.40) {
814         p[0] = 1815.; p[1] = -4260.;
815       } else if (pT>=0.40 && pT<0.45) {
816         p[0] =  715.; p[1] =  -1471.;
817       } else if (pT>=0.45 && pT<0.50) {
818         p[0] =  233.; p[1] =  -407.;
819       } else if (pT>=0.50 && pT<0.55) {
820         p[0] =  408.; p[1] =  -752.;
821       } else { //if (pT>=0.55)
822         p[0] =  408.-752.*0.55; p[1] = 0.;
823       }
824
825     }
826
827     delta = p[0]+p[1]*pT;
828     //    Printf("Kaon time: %f %f %f %f",p[0],p[1],length,delta);
829
830   } else {
831
832     Float_t p[2] = {0.,0.};
833
834     if ( fInTRD &&  fOutTRD) { // zone 1
835
836       if (isTRDout) {
837
838         if (length<95.) {
839           p[0] = 20.; p[1] = 0.;
840         } else if (length>=95. && length<195.) {
841           p[0] = -24.0; p[1] = 0.10+0.0041*length;
842         } else {//if (length>=195.)
843           p[0] =  150.; p[1] = 0.;
844         }
845
846       } else { // !isTRDout
847
848         p[0] = 40.; p[1] = 0.;
849
850       }
851
852     } else if (!fInTRD && !fOutTRD) { // zone 2
853
854       p[0] = 0.; p[1] = 0.;
855
856     } else if ( fInTRD &&  !fOutTRD) { // zone 3
857
858       if (isTRDout) {
859
860         if (length< 15.) {
861           p[0] = 180.; p[1] =  0.;
862         } else if (length>= 15. && length< 55.) {
863           p[0] = 215.; p[1] = -2.5;
864         } else {//if (length>=55.)
865           p[0] = 78.; p[1] =  0.;
866         }
867
868       } else { // !isTRDout
869
870         p[0] = 0.; p[1] = 0.;
871
872       }
873
874     } else if (!fInTRD &&  fOutTRD) { // zone 4
875
876       if (isTRDout) {
877
878         if (length< 55.) {
879           p[0] =  0.; p[1] =  0.;
880         } else if (length>= 55. && length<115.) {
881           p[0] = -85.; p[1] = 1.9;
882         } else {//if (length>=115.)
883           p[0] = 100.; p[1] =  0.;
884         }
885
886       } else { // !isTRDout
887
888         p[0] =  0.; p[1] =  0.;
889
890       }
891
892     }
893
894     delta = p[0]+p[1]*length;
895     //    Printf("Kaon time: %f %f %f %f",p[0],p[1],length,delta);
896
897   }
898
899   return delta;
900
901 }
902
903 //________________________________________________________________________
904 Double_t AliTOFTenderSupply::CorrectExpectedProtonTime(Double_t pT,
905                                                             Double_t length,
906                                                             Bool_t isTRDout)
907 {
908   // correction for expected time for protons
909
910   Double_t delta=0.;
911   //  Printf("Flags Ent In ComingOut Out %d %d %d %d",fIsEnteringInTRD,fInTRD,fIsComingOutTRD,fOutTRD);
912
913   if (!fIsEnteringInTRD || !fIsComingOutTRD) { // zone 5
914     Float_t p[2]={0.,0.};
915
916
917     if (isTRDout) {
918
919       if (pT<0.375) {
920         p[0] = 1000.; p[1] = 0.;
921       } else if (pT>=0.375 && pT<0.45) {
922         p[0] = 1500.; p[1] = 0.;
923       } else if (pT>=0.45 && pT<0.50) {
924         p[0] = 4650.; p[1] = -7000.;
925       } else if (pT>=0.50 && pT<0.55) {
926         p[0] = 3150.; p[1] = -4000.;
927       } else { //if (pT>=0.55)
928         p[0] = 3150. -4000.*0.55; p[1] = 0.;
929       }
930
931     } else {
932
933       if (pT<0.32) {
934         p[0] = 2963.-5670.*0.032; p[1] = 0.;
935       } else if (pT>=0.32 && pT<0.35) {
936         p[0] = 2963.; p[1] =  -5670.;
937       } else if (pT>=0.35 && pT<0.40) {
938         p[0] = 4270.; p[1] =  -9400.;
939       } else if (pT>=0.40 && pT<0.45) {
940         p[0] = 1550.; p[1] =  -2600.;
941       } else if (pT>=0.45 && pT<0.50) {
942         p[0] = 1946.; p[1] =  -3480.;
943       } else if (pT>=0.50 && pT<0.55) {
944         p[0] = 1193.; p[1] =  -1974.;
945       } else { //if (pT>=0.55)
946         p[0] = 1193.-1974.*0.55; p[1] = 0.;
947       }
948
949     }
950
951     delta = p[0]+p[1]*pT;
952     //    Printf("Proton time: %f %f %f %f",p[0],p[1],length,delta);
953
954   } else {
955
956     Float_t p[2] = {0.,0.};
957
958     if ( fInTRD &&  fOutTRD) { // zone 1
959
960       if (isTRDout) {
961
962         if (length<90.) {
963           p[0] = 0.; p[1] = 0.;
964         } else if (length>=90. && length<200.) {
965           p[0] = 1063.; p[1] = -32.+0.30*length-0.00072*length*length;
966         } else {//if (length>=200.)
967           p[0] =  900.; p[1] = 0.;
968         }
969
970       } else { // !isTRDout
971
972         p[0] = 80.; p[1] = 0.;
973
974       }
975
976     } else if (!fInTRD && !fOutTRD) { // zone 2
977
978       if (isTRDout) {
979         p[0] = 0.; p[1] = 0.;
980       } else {
981         if (length<125.) {
982           p[0] = 0.; p[1] = 0.;
983         } else if (length>=125. && length<180.) {
984           p[0] = -132.; p[1] = 1.3;
985         } else {
986           p[0] = 100.; p[1] = 0.;
987         }
988
989       }
990
991     } else if ( fInTRD &&  !fOutTRD) { // zone 3
992
993       if (isTRDout) {
994
995         if (length< 30.) {
996           p[0] = 670.; p[1] =  0.;
997         } else if (length>= 30. && length<155.) {
998           p[0] = 944.; p[1] = -11.+0.064*length;
999         } else {//if (length>=155.)
1000           p[0] = 780.; p[1] =  0.;
1001         }
1002
1003       } else { // !isTRDout
1004
1005         if (length< 30.) {
1006           p[0] = 140.; p[1] = -4.5;
1007         } else {
1008           p[0] = 0.; p[1] = 0.;
1009         }
1010       
1011       }
1012
1013     } else if (!fInTRD &&  fOutTRD) { // zone 4
1014
1015       if (isTRDout) {
1016
1017         if (length< 45.) {
1018           p[0] = 130.; p[1] =  0.;
1019         } else if (length>= 45. && length<120.) {
1020           p[0] = -190.; p[1] = 6.5;
1021         } else {//if (length>=120.)
1022           p[0] = 750.; p[1] =  0.;
1023         }
1024
1025       } else { // !isTRDout
1026
1027         if (length<75.5) {
1028           p[0] =    0.; p[1] =  0.;
1029         } else if (length>= 75.5 && length<90.) {
1030           p[0] = -830.; p[1] = 11.;
1031         } else {
1032           p[0] =  160.; p[1] =  0.;
1033         }
1034
1035       }
1036
1037     }
1038
1039     delta = p[0]+p[1]*length;
1040     //    Printf("Proton time: %f %f %f %f",p[0],p[1],length,delta);
1041
1042   }
1043
1044   return delta;
1045
1046 }
1047
1048 //________________________________________________________________________
1049 Double_t AliTOFTenderSupply::EstimateLengthInTRD1(AliESDtrack *track)
1050 {
1051
1052   Double_t xyz0[3]={0.,0.,0.};
1053   Bool_t stayInTRD = track->GetXYZAt(fRhoTRDin,fMagField,xyz0);
1054
1055   Double_t phi0 = TMath::Pi()+TMath::ATan2(-xyz0[1],-xyz0[0]);
1056   phi0 *= TMath::RadToDeg();
1057   stayInTRD = stayInTRD && ( (phi0>=  0. && phi0<= 40.) ||
1058                              (phi0>=140. && phi0<=220.) ||
1059                              (phi0>=340. && phi0<=360.) );
1060
1061   Double_t trackLengthInTRD = 0.;
1062   Int_t iStep=0;
1063
1064   Double_t b[3];track->GetBxByBz(b);
1065
1066   Double_t xyz1[3]={0.,0.,0.};
1067   Double_t rho = fRhoTRDin;
1068   while (stayInTRD && rho<=fRhoTRDout) {
1069     iStep++;
1070     rho += fStep;
1071
1072     for (Int_t ii=0; ii<3; ii++) xyz1[ii]=0.;
1073     stayInTRD = track->GetXYZAt(rho,fMagField,xyz1);
1074     Double_t phi1 = TMath::Pi()+TMath::ATan2(-xyz1[1],-xyz1[0]);
1075     phi1 *= TMath::RadToDeg();
1076     stayInTRD = stayInTRD && ( (phi1>=  0. && phi1<= 40.) ||
1077                                (phi1>=140. && phi1<=220.) ||
1078                                (phi1>=340. && phi1<=360.) );
1079
1080     Double_t l2  = TMath::Sqrt((xyz1[0]-xyz0[0])*(xyz1[0]-xyz0[0]) +
1081                                (xyz1[1]-xyz0[1])*(xyz1[1]-xyz0[1]) +
1082                                (xyz1[2]-xyz0[2])*(xyz1[2]-xyz0[2]));
1083     trackLengthInTRD += l2;
1084
1085     for (Int_t ii=0; ii<3; ii++) xyz0[ii]=xyz1[ii];
1086   }
1087
1088   return trackLengthInTRD;
1089
1090 }
1091
1092 //________________________________________________________________________
1093 Double_t AliTOFTenderSupply::EstimateLengthInTRD2(AliESDtrack *track)
1094 {
1095
1096   Double_t xyz0[3]={0.,0.,0.};
1097   Bool_t stayInTRD = track->GetXYZAt(fRhoTRDout,fMagField,xyz0);
1098
1099   Double_t phi0 = TMath::Pi()+TMath::ATan2(-xyz0[1],-xyz0[0]);
1100   phi0 *= TMath::RadToDeg();
1101   stayInTRD = stayInTRD && ( (phi0>=  0. && phi0<= 40.) ||
1102                              (phi0>=140. && phi0<=220.) ||
1103                              (phi0>=340. && phi0<=360.) );
1104
1105   Double_t trackLengthInTRD = 0.;
1106   Int_t iStep=0;
1107
1108   Double_t b[3];track->GetBxByBz(b);
1109
1110   Double_t xyz1[3]={0.,0.,0.};
1111   Double_t rho = fRhoTRDout;
1112   while (stayInTRD && rho>=fRhoTRDin) {
1113     iStep++;
1114     rho -= fStep;
1115
1116     for (Int_t ii=0; ii<3; ii++) xyz1[ii]=0.;
1117     stayInTRD = track->GetXYZAt(rho,fMagField,xyz1);
1118     Double_t phi1 = TMath::Pi()+TMath::ATan2(-xyz1[1],-xyz1[0]);
1119     phi1 *= TMath::RadToDeg();
1120     stayInTRD = stayInTRD && ( (phi1>=  0. && phi1<= 40.) ||
1121                                (phi1>=140. && phi1<=220.) ||
1122                                (phi1>=340. && phi1<=360.) );
1123
1124     Double_t l2  = TMath::Sqrt((xyz0[0]-xyz1[0])*(xyz0[0]-xyz1[0]) +
1125                                (xyz0[1]-xyz1[1])*(xyz0[1]-xyz1[1]) +
1126                                (xyz0[2]-xyz1[2])*(xyz0[2]-xyz1[2]));
1127     trackLengthInTRD += l2;
1128
1129     for (Int_t ii=0; ii<3; ii++) xyz0[ii]=xyz1[ii];
1130   }
1131
1132   return trackLengthInTRD;
1133
1134 }
1135
1136 //________________________________________________________________________
1137 Double_t AliTOFTenderSupply::EstimateLengthOutTRD(AliESDtrack *track)
1138 {
1139
1140   Double_t xyz0[3]={0.,0.,0.};
1141   Bool_t stayInTRD = track->GetXYZAt(fRhoTRDin,fMagField,xyz0);
1142
1143   Double_t phi0 = TMath::Pi()+TMath::ATan2(-xyz0[1],-xyz0[0]);
1144   phi0 *= TMath::RadToDeg();
1145   stayInTRD = stayInTRD && !( (phi0>=  0. && phi0<= 40.) ||
1146                               (phi0>=140. && phi0<=220.) ||
1147                               (phi0>=340. && phi0<=360.) );
1148
1149   Double_t trackLengthInTRD = 0.;
1150   Int_t iStep=0;
1151
1152   Double_t b[3];track->GetBxByBz(b);
1153
1154   Double_t xyz1[3]={0.,0.,0.};
1155   Double_t rho = fRhoTRDin;
1156   while (stayInTRD && rho<=fRhoTRDout) {
1157     iStep++;
1158     rho += fStep;
1159
1160     for (Int_t ii=0; ii<3; ii++) xyz1[ii]=0.;
1161     stayInTRD = track->GetXYZAt(rho,fMagField,xyz1);
1162     Double_t phi1 = TMath::Pi()+TMath::ATan2(-xyz1[1],-xyz1[0]);
1163     phi1 *= TMath::RadToDeg();
1164     stayInTRD = stayInTRD && !( (phi1>=  0. && phi1<= 40.) ||
1165                                 (phi1>=140. && phi1<=220.) ||
1166                                 (phi1>=340. && phi1<=360.) );
1167
1168     Double_t l2  = TMath::Sqrt((xyz1[0]-xyz0[0])*(xyz1[0]-xyz0[0]) +
1169                                (xyz1[1]-xyz0[1])*(xyz1[1]-xyz0[1]) +
1170                                (xyz1[2]-xyz0[2])*(xyz1[2]-xyz0[2]));
1171     trackLengthInTRD += l2;
1172
1173     for (Int_t ii=0; ii<3; ii++) xyz0[ii]=xyz1[ii];
1174   }
1175
1176   return trackLengthInTRD;
1177
1178 }
1179
1180 //________________________________________________________________________
1181 Int_t AliTOFTenderSupply::GetOCDBVersion(Int_t runNo)
1182 {
1183   Int_t verNo = -1;
1184   if ( (runNo>=118503 && runNo <=121040) )  { // LHC10C
1185     if (fRecoPass == 2) {                     // on pass2
1186       if (runNo >= 119159 && runNo <= 119163) verNo=3;
1187       else if (runNo >= 119837 && runNo <= 119934) verNo=4;
1188       else if (runNo >= 120067 && runNo <= 120244) verNo=4;
1189       else if (runNo >= 120503 && runNo <= 120505) verNo=4;
1190       else if (runNo >= 120616 && runNo <= 120671) verNo=4;
1191       else if (runNo >= 120741 && runNo <= 120829) verNo=4;
1192     }
1193   }
1194   return verNo;
1195 }