]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/TenderSupplies/AliTOFTenderSupply.cxx
631134df92a3513778055e33004ecb83748a4ab3
[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 <TMath.h>
27 #include <TRandom.h>
28 #include <AliLog.h>
29 #include <AliESDEvent.h>
30 #include <AliESDtrack.h>
31 #include <AliESDInputHandler.h>
32 #include <AliAnalysisManager.h>
33 #include <AliESDpid.h>
34 #include <AliTender.h>
35
36 #include <AliTOFcalib.h>
37 #include <AliTOFT0maker.h>
38
39 #include <AliCDBManager.h>
40 #include <AliCDBEntry.h>
41 #include <AliT0CalibSeasonTimeShift.h>
42
43 #include "AliTOFTenderSupply.h"
44
45 Float_t AliTOFTenderSupply::fgT0Aresolution = 75.;
46 Float_t AliTOFTenderSupply::fgT0Cresolution = 65.;
47
48 AliTOFTenderSupply::AliTOFTenderSupply() :
49   AliTenderSupply(),
50   fESDpid(0x0),
51   fIsMC(kFALSE),
52   fTimeZeroType(AliESDpid::kBest_T0),
53   fCorrectExpTimes(kTRUE),
54   fLHC10dPatch(kFALSE),
55   fDebugLevel(0),
56   fAutomaticSettings(kTRUE),
57   fTOFCalib(0x0),
58   fTOFT0maker(0x0),
59   fTOFres(100.),
60   fT0IntercalibrationShift(0)
61
62
63 {
64   //
65   // default ctor
66   //
67   fT0shift[0] = 0;
68   fT0shift[1] = 0;
69   fT0shift[2] = 0;
70   fT0shift[3] = 0;
71 }
72
73 //_____________________________________________________
74 AliTOFTenderSupply::AliTOFTenderSupply(const char *name, const AliTender *tender) :
75   AliTenderSupply(name,tender),
76   fESDpid(0x0),
77   fIsMC(kFALSE),
78   fTimeZeroType(AliESDpid::kBest_T0),
79   fCorrectExpTimes(kTRUE),
80   fLHC10dPatch(kFALSE),
81   fDebugLevel(0),
82   fAutomaticSettings(kTRUE),
83   fTOFCalib(0x0),
84   fTOFT0maker(0x0),
85   fTOFres(100.),
86   fT0IntercalibrationShift(0)
87  
88 {
89   //
90   // named ctor
91   //
92
93   fT0shift[0] = 0;
94   fT0shift[1] = 0;
95   fT0shift[2] = 0;
96   fT0shift[3] = 0;
97 }
98
99 //_____________________________________________________
100 void AliTOFTenderSupply::Init()
101 {
102
103   
104   // Initialise TOF tender (this is called at each detected run change)
105   // Setup PID object, check for MC, set AliTOFcalib and TOFT0 maker conf
106   Int_t run = fTender->GetRun();
107   if (run == 0) return;                // to skip first init, when we don't have yet a run number
108
109   if (fAutomaticSettings) {
110     if (run>=114737&&run<=117223) {      //period="LHC10B";
111       fCorrectExpTimes=kTRUE;
112       fLHC10dPatch=kFALSE;
113       fTOFres=100.;
114       fTimeZeroType=AliESDpid::kTOF_T0;
115       fT0IntercalibrationShift = 0;
116     }
117     else if (run>=118503&&run<=121040) { //period="LHC10C";
118       fCorrectExpTimes=kTRUE;
119       fLHC10dPatch=kFALSE;
120       fTOFres=100.;
121       fTimeZeroType=AliESDpid::kTOF_T0;
122       fT0IntercalibrationShift = 0;
123     }
124     else if (run>=122195&&run<=126437) { //period="LHC10D";
125       fCorrectExpTimes=kFALSE;
126       fLHC10dPatch=kTRUE;
127       fTOFres=100.;
128       fTimeZeroType=AliESDpid::kBest_T0;
129       fT0IntercalibrationShift = 0;
130     }
131     else if (run>=127719&&run<=130850) { //period="LHC10E";
132       fCorrectExpTimes=kFALSE;
133       fLHC10dPatch=kFALSE;
134       fTOFres=100.;
135       fTimeZeroType=AliESDpid::kBest_T0;
136       fT0IntercalibrationShift = 30.;
137     }
138     else if (run>=133004&&run<=135029) { //period="LHC10F";
139       fCorrectExpTimes=kFALSE;
140       fLHC10dPatch=kFALSE;
141       fTOFres=100.;
142       fTimeZeroType=AliESDpid::kBest_T0;
143       fT0IntercalibrationShift = 0.;
144       AliWarning("TOF tender not supported for LHC10F period!! Settings are just a guess!!");
145     }
146     else if (run>=135654&&run<=136377) { //period="LHC10G";
147       fCorrectExpTimes=kFALSE;
148       fLHC10dPatch=kFALSE;
149       fTOFres=100.;
150       fTimeZeroType=AliESDpid::kBest_T0;
151       fT0IntercalibrationShift = 0.;
152       AliWarning("TOF tender not supported for LHC10G period!! Settings are just a guess!!");
153     }
154     else if (run>=136851&&run<=139517) { //period="LHC10H" - pass2;
155       fCorrectExpTimes=kFALSE;
156       fLHC10dPatch=kFALSE;                
157       fTOFres=90.;
158       fTimeZeroType=AliESDpid::kTOF_T0;
159       fT0IntercalibrationShift = 0.;
160     }
161     else if (run>=139699) {              //period="LHC11A";
162       fCorrectExpTimes=kFALSE;
163       fLHC10dPatch=kFALSE;
164       fTOFres=100.;
165       fTimeZeroType=AliESDpid::kBest_T0;
166       fT0IntercalibrationShift = 0.;
167       AliWarning("TOF tender not supported for LHC11A period!! Settings are just a guess!!");
168     }
169   }
170
171   // Check if another detector already created the esd pid object
172   // if not we create it and set it to the ESD input handler
173   fESDpid=fTender->GetESDhandler()->GetESDpid();
174   if (!fESDpid) {
175     fESDpid=new AliESDpid;
176     fTender->GetESDhandler()->SetESDpid(fESDpid);
177   }
178
179   // Even if the user didn't set fIsMC, we force it on if we find the MC handler 
180   AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();
181   if (mgr->GetMCtruthEventHandler() && !(fIsMC) ) {
182     AliWarning("This ESD is MC, fIsMC found OFF: fIsMC turned ON");
183     fIsMC=kTRUE;
184   }
185
186   // Configure TOF calibration class
187   if (!fTOFCalib)fTOFCalib=new AliTOFcalib();  // create if needed
188   fTOFCalib->SetRemoveMeanT0(!(fIsMC));        // must be kFALSE on MC (default is kTRUE)
189   fTOFCalib->SetCalibrateTOFsignal(!(fIsMC));  // must be kFALSE on MC (no new calibration) (default is kTRUE)
190   fTOFCalib->SetCorrectTExp(fCorrectExpTimes); // apply a fine tuning on the expected times at low momenta
191   
192
193   // Configure TOFT0 maker class
194   if (!fTOFT0maker) fTOFT0maker = new AliTOFT0maker(fESDpid,fTOFCalib); // create if needed
195   fTOFT0maker->SetTimeResolution(fTOFres);     // set TOF resolution for the PID
196   
197
198   AliInfo("|******************************************************|");
199   AliInfo(Form("|    Alice TOF Tender Initialisation (Run %d)  |",fTender->GetRun()));
200   AliInfo("|    Settings:                                         |");
201   AliInfo(Form("|    Correct Exp Times              :  %d               |",fCorrectExpTimes));
202   AliInfo(Form("|    LHC10d patch                   :  %d               |",fLHC10dPatch));
203   AliInfo(Form("|    TOF resolution for TOFT0 maker :  %5.2f (ps)     |",fTOFres));
204   AliInfo(Form("|    timeZero selection             :  %d               |",fTimeZeroType));
205   AliInfo(Form("|    MC flag                        :  %d               |",fIsMC));
206   AliInfo(Form("|    TOF/T0 intecalibration shift   :  %5.2f (ps)     |",fT0IntercalibrationShift));
207   AliInfo("|******************************************************|");
208
209
210 }
211
212 //_____________________________________________________
213 void AliTOFTenderSupply::ProcessEvent()
214 {
215   //
216   // Use updated calibrations for TOF and T0, reapply PID information
217   // For MC: timeZero sampling and additional smearing for T0
218
219   if (fDebugLevel > 1) AliInfo("process event");
220
221   AliESDEvent *event=fTender->GetEvent();
222   if (!event) return;
223   if (fDebugLevel > 1) AliInfo("event read");
224
225
226     
227   if (fTender->RunChanged()){ 
228
229     Init();            
230
231     fTOFCalib->Init(fTender->GetRun());
232     
233     if(event->GetT0TOF()){ // read T0 detector correction from OCDB
234       // OCDB instance
235       AliCDBManager* ocdbMan = AliCDBManager::Instance();
236       ocdbMan->SetRun(fTender->GetRun());    
237       AliCDBEntry *entry = ocdbMan->Get("T0/Calib/TimeAdjust/");
238       if(entry) {
239         AliT0CalibSeasonTimeShift *clb = (AliT0CalibSeasonTimeShift*) entry->GetObject();
240         Float_t *t0means= clb->GetT0Means();
241         //      Float_t *t0sigmas = clb->GetT0Sigmas();
242         fT0shift[0] = t0means[0] + fT0IntercalibrationShift;
243         fT0shift[1] = t0means[1] + fT0IntercalibrationShift;
244         fT0shift[2] = t0means[2] + fT0IntercalibrationShift;
245         fT0shift[3] = t0means[3] + fT0IntercalibrationShift;
246       } else {
247         for (Int_t i=0;i<4;i++) fT0shift[i]=0;
248         AliWarning("TofTender no T0 entry found T0shift set to 0");
249       }
250     }
251   }
252
253
254   fTOFCalib->CalibrateESD(event);   //recalculate TOF signal (no harm for MC, see settings inside init)
255   if (fLHC10dPatch && !(fIsMC)) RecomputeTExp(event);
256
257   Double_t startTime = 0.;
258   if(fIsMC) startTime = fTOFCalib->TuneForMC(event,fTOFres);
259
260   if (fDebugLevel > 1) Printf(" TofTender: startTime %f",startTime);
261   if (fDebugLevel > 1) Printf(" TofTender: T0 time (orig) %f %f %f",event->GetT0TOF(0),event->GetT0TOF(1),event->GetT0TOF(2));
262   // event by event TO detector treatment  
263   if(event->GetT0TOF()){   // protection: we adjust T0 only if it is there....
264
265     if (event->GetT0TOF(0) == 0) event->SetT0TOF(0, 9999999.); // in case no information we set to unknown
266     if (event->GetT0TOF(1) == 0) event->SetT0TOF(1, 99999.);
267     if (event->GetT0TOF(2) == 0) event->SetT0TOF(2, 99999.);
268
269     if(!fIsMC){   // data: apply shifts to align around Zero
270       event->SetT0TOF(0,event->GetT0TOF(0) - fT0shift[0]);
271       event->SetT0TOF(1,event->GetT0TOF(1) - fT0shift[1]);
272       event->SetT0TOF(2,event->GetT0TOF(2) - fT0shift[2]);
273     } else {
274       // MC: add smearing for realistic T0A and T0C resolution
275       Double_t defResolutionT0A = 33.;   // in future we will get this from ESDrun data structure or via OCDB
276       Double_t defResolutionT0C = 30.;   // for the moment we don't trust them
277       if ( (fgT0Aresolution > defResolutionT0A) && (event->GetT0TOF(1)<90000.) ) { // add smearing only if signal is there
278         Double_t addedSmearingT0A = TMath::Sqrt(fgT0Aresolution*fgT0Aresolution - defResolutionT0A*defResolutionT0A);
279         Double_t smearingT0A = gRandom->Gaus(0.,addedSmearingT0A);
280         event->SetT0TOF(1,event->GetT0TOF(1) + smearingT0A);
281       }
282       if ( (fgT0Cresolution > defResolutionT0C) && (event->GetT0TOF(2)<90000.) ) { // add smearing only if signal is there
283         Double_t addedSmearingT0C = TMath::Sqrt(fgT0Cresolution*fgT0Cresolution - defResolutionT0C*defResolutionT0C);
284         Double_t smearingT0C = gRandom->Gaus(0.,addedSmearingT0C);
285         event->SetT0TOF(2,event->GetT0TOF(2) + smearingT0C);
286       }
287       if (event->GetT0TOF(0)<90000.) { // we recompute the AND only if it is already there...
288         Double_t smearedT0AC = (event->GetT0TOF(1)+event->GetT0TOF(2))/2.;
289         event->SetT0TOF(0,smearedT0AC); 
290       }
291       if (fDebugLevel > 1) Printf(" TofTender: T0 time (postSmear) %f %f %f",event->GetT0TOF(0),event->GetT0TOF(1),event->GetT0TOF(2));
292       // add finally the timeZero offset also to the T0 detector information
293       event->SetT0TOF(0,event->GetT0TOF(0) + startTime);
294       event->SetT0TOF(1,event->GetT0TOF(1) + startTime);
295       event->SetT0TOF(2,event->GetT0TOF(2) + startTime);  
296       if (fDebugLevel > 1) Printf(" TofTender: T0 time (postStart) %f %f %f",event->GetT0TOF(0),event->GetT0TOF(1),event->GetT0TOF(2));
297     }
298     // after shifts adjust (data) or smearing+offset (MC) we 'clean' to default if signals not there 
299     if(event->GetT0TOF(0) > 900000) event->SetT0TOF(0, 999999.);
300     if(event->GetT0TOF(1) > 90000)  event->SetT0TOF(1, 99999.);
301     if(event->GetT0TOF(2) > 90000)  event->SetT0TOF(2, 99999.);
302   }
303   if (fDebugLevel > 1) Printf(" TofTender: T0 time (FINAL) %f %f %f",event->GetT0TOF(0),event->GetT0TOF(1),event->GetT0TOF(2));
304   
305   //compute timeZero of the event via TOF-TO
306   fTOFT0maker->ComputeT0TOF(event);
307   fTOFT0maker->WriteInESD(event);
308
309   // recalculate PID probabilities
310   fESDpid->SetTOFResponse(event, (AliESDpid::EStartTimeType_t)fTimeZeroType);
311
312   // this is for safety, especially if the user doesn't attach a PID tender after TOF tender  
313   Int_t ntracks=event->GetNumberOfTracks();
314   for(Int_t itrack = 0; itrack < ntracks; itrack++){
315     fESDpid->MakeTOFPID(event->GetTrack(itrack),0);   
316   }
317   
318   
319 }
320
321
322 //_____________________________________________________
323 void AliTOFTenderSupply::RecomputeTExp(AliESDEvent *event) const
324 {
325   /*
326    * calibrate TExp
327    */
328
329   
330   /* loop over tracks */
331   AliESDtrack *track = NULL;
332   for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
333     /* get track and calibrate */
334     track = event->GetTrack(itrk);
335     RecomputeTExp(track);
336   }
337   
338 }
339
340 //_____________________________________________________
341 void AliTOFTenderSupply::RecomputeTExp(AliESDtrack *track) const
342 {
343   /*** 
344        THIS METHOD IS BASED ON THEORETICAL EXPECTED TIME COMPUTED
345        USING AVERAGE MOMENTUM BETWEEN INNER/OUTER TRACK PARAMS 
346        IT IS A ROUGH APPROXIMATION APPLIED TO FIX LHC10d-pass2 DATA
347        WHERE A WRONG GEOMETRY (FULL TRD) WAS INSERTED
348   ***/
349
350   Double_t texp[AliPID::kSPECIES];
351   if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) return;
352
353
354   /* get track params */
355   Float_t l = track->GetIntegratedLength();
356   Float_t p = track->P();
357   if (track->GetInnerParam() && track->GetOuterParam()) {
358     Float_t pin = track->GetInnerParam()->P();
359     Float_t pout = track->GetOuterParam()->P();
360     p = 0.5 * (pin + pout);
361   }
362   /* loop over particle types and compute expected time */
363   for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++)
364     texp[ipart] = GetExpTimeTh(AliPID::ParticleMass(ipart), p, l) - 37.; 
365   // 37 is a final semiempirical offset to further adjust (calibrations were
366   // done with "standard" integratedTimes)
367   /* set integrated times */
368   track->SetIntegratedTimes(texp);
369
370 }
371
372