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