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