1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
19 // TOF tender: - load updated calibrations (for TOF and T0)
20 // - set tofHeader if missing in ESDs (2010 data)
23 // Contacts: Pietro.Antonioli@bo.infn.it //
24 // Francesco.Noferini@bo.infn.it //
25 ///////////////////////////////////////////////////////////////////////////////
29 #include <AliESDEvent.h>
30 #include <AliESDtrack.h>
31 #include <AliESDInputHandler.h>
32 #include <AliAnalysisManager.h>
33 #include <AliESDpid.h>
34 #include <AliTender.h>
36 #include <AliTOFcalib.h>
37 #include <AliTOFT0maker.h>
39 #include <AliCDBManager.h>
40 #include <AliCDBEntry.h>
41 #include <AliT0CalibSeasonTimeShift.h>
43 #include "AliTOFTenderSupply.h"
45 Float_t AliTOFTenderSupply::fgT0Aresolution = 75.;
46 Float_t AliTOFTenderSupply::fgT0Cresolution = 65.;
48 AliTOFTenderSupply::AliTOFTenderSupply() :
52 fTimeZeroType(AliESDpid::kBest_T0),
53 fCorrectExpTimes(kTRUE),
56 fAutomaticSettings(kTRUE),
60 fT0IntercalibrationShift(0)
73 //_____________________________________________________
74 AliTOFTenderSupply::AliTOFTenderSupply(const char *name, const AliTender *tender) :
75 AliTenderSupply(name,tender),
78 fTimeZeroType(AliESDpid::kBest_T0),
79 fCorrectExpTimes(kTRUE),
82 fAutomaticSettings(kTRUE),
86 fT0IntercalibrationShift(0)
99 //_____________________________________________________
100 void AliTOFTenderSupply::Init()
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
109 if (fAutomaticSettings) {
110 if (run>=114737&&run<=117223) { //period="LHC10B";
111 fCorrectExpTimes=kTRUE;
114 fTimeZeroType=AliESDpid::kTOF_T0;
115 fT0IntercalibrationShift = 0;
117 else if (run>=118503&&run<=121040) { //period="LHC10C";
118 fCorrectExpTimes=kTRUE;
121 fTimeZeroType=AliESDpid::kTOF_T0;
122 fT0IntercalibrationShift = 0;
124 else if (run>=122195&&run<=126437) { //period="LHC10D";
125 fCorrectExpTimes=kFALSE;
128 fTimeZeroType=AliESDpid::kBest_T0;
129 fT0IntercalibrationShift = 0;
131 else if (run>=127719&&run<=130850) { //period="LHC10E";
132 fCorrectExpTimes=kFALSE;
135 fTimeZeroType=AliESDpid::kBest_T0;
136 fT0IntercalibrationShift = 30.;
138 else if (run>=133004&&run<=135029) { //period="LHC10F";
139 fCorrectExpTimes=kFALSE;
142 fTimeZeroType=AliESDpid::kBest_T0;
143 fT0IntercalibrationShift = 0.;
144 AliWarning("TOF tender not supported for LHC10F period!! Settings are just a guess!!");
146 else if (run>=135654&&run<=136377) { //period="LHC10G";
147 fCorrectExpTimes=kFALSE;
150 fTimeZeroType=AliESDpid::kBest_T0;
151 fT0IntercalibrationShift = 0.;
152 AliWarning("TOF tender not supported for LHC10G period!! Settings are just a guess!!");
154 else if (run>=136851&&run<=139517) { //period="LHC10H" - pass2;
155 fCorrectExpTimes=kFALSE;
158 fTimeZeroType=AliESDpid::kTOF_T0;
159 fT0IntercalibrationShift = 0.;
161 else if (run>=139699) { //period="LHC11A";
162 fCorrectExpTimes=kFALSE;
165 fTimeZeroType=AliESDpid::kBest_T0;
166 fT0IntercalibrationShift = 0.;
167 AliWarning("TOF tender not supported for LHC11A period!! Settings are just a guess!!");
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();
175 fESDpid=new AliESDpid;
176 fTender->GetESDhandler()->SetESDpid(fESDpid);
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");
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
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
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("|******************************************************|");
212 //_____________________________________________________
213 void AliTOFTenderSupply::ProcessEvent()
216 // Use updated calibrations for TOF and T0, reapply PID information
217 // For MC: timeZero sampling and additional smearing for T0
219 if (fDebugLevel > 1) AliInfo("process event");
221 AliESDEvent *event=fTender->GetEvent();
223 if (fDebugLevel > 1) AliInfo("event read");
227 if (fTender->RunChanged()){
231 fTOFCalib->Init(fTender->GetRun());
233 if(event->GetT0TOF()){ // read T0 detector correction from OCDB
235 AliCDBManager* ocdbMan = AliCDBManager::Instance();
236 ocdbMan->SetRun(fTender->GetRun());
237 AliCDBEntry *entry = ocdbMan->Get("T0/Calib/TimeAdjust/");
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;
247 for (Int_t i=0;i<4;i++) fT0shift[i]=0;
248 AliWarning("TofTender no T0 entry found T0shift set to 0");
254 fTOFCalib->CalibrateESD(event); //recalculate TOF signal (no harm for MC, see settings inside init)
255 if (fLHC10dPatch && !(fIsMC)) RecomputeTExp(event);
257 Double_t startTime = 0.;
258 if(fIsMC) startTime = fTOFCalib->TuneForMC(event,fTOFres);
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....
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.);
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]);
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);
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);
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);
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));
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.);
303 if (fDebugLevel > 1) Printf(" TofTender: T0 time (FINAL) %f %f %f",event->GetT0TOF(0),event->GetT0TOF(1),event->GetT0TOF(2));
305 //compute timeZero of the event via TOF-TO
306 fTOFT0maker->ComputeT0TOF(event);
307 fTOFT0maker->WriteInESD(event);
309 // recalculate PID probabilities
310 fESDpid->SetTOFResponse(event, (AliESDpid::EStartTimeType_t)fTimeZeroType);
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);
322 //_____________________________________________________
323 void AliTOFTenderSupply::RecomputeTExp(AliESDEvent *event) const
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);
340 //_____________________________________________________
341 void AliTOFTenderSupply::RecomputeTExp(AliESDtrack *track) const
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
350 Double_t texp[AliPID::kSPECIES];
351 if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) return;
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);
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);