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 **************************************************************************/
15 /* $Id: AliTOFT0maker.cxx,v 1.8 2010/01/19 16:32:20 noferini Exp $ */
17 /////////////////////////////////////////////////////////////////////////////
19 // This class contains the basic functions for the time zero //
20 // evaluation with TOF detector informations. //
21 // Use case in an analysis task: //
23 // Create the object in the task constructor (fTOFmaker is a private var) //
24 // AliESDpid *extPID=new AliESDpid(); //
25 // fTOFmaker = new AliTOFT0maker(extPID); //
26 // fTOFmaker->SetTimeResolution(100.0); // if you want set the TOF res //
27 // 115 ps is the TOF default resolution value //
29 // Use the RemakePID method in the task::Exec //
30 // Double_t* calcolot0; //
31 // calcolot0=fTOFmaker->RemakePID(fESD); //
32 // //calcolot0[0] = calculated event time //
33 // //calcolot0[1] = event time time resolution //
34 // //calcolot0[2] = average event time for the current fill //
35 // //calcolot0[3] = tracks at TOF //
36 // //calcolot0[4] = calculated event time (only TOF) //
37 // //calcolot0[5] = event time time resolution (only TOF) //
38 // //calcolot0[6] = sigma t0 fill //
39 // //calcolot0[7] = tracks at TOF really used in tht algorithm //
41 // Let consider that: //
42 // - the PIF is automatically recalculated with the event time subtrction //
44 /////////////////////////////////////////////////////////////////////////////
46 #include "AliTOFT0v1.h"
47 #include "AliTOFT0maker.h"
49 #include "AliESDpid.h"
50 #include "AliESDEvent.h"
53 #include "AliTOFcalib.h"
54 #include "AliTOFRunParams.h"
57 ClassImp(AliTOFT0maker)
59 //____________________________________________________________________________
60 AliTOFT0maker::AliTOFT0maker():
64 fExternalPIDFlag(kFALSE),
79 fT0TOF = new AliTOFT0v1();
80 if(AliPID::ParticleMass(0) == 0) new AliPID();
82 fPIDesd = new AliESDpid();
107 for (Int_t i = 0; i < 10; i++) {
112 //____________________________________________________________________________
113 AliTOFT0maker::AliTOFT0maker(AliESDpid *externalPID, AliTOFcalib *tofCalib):
116 fPIDesd(externalPID),
117 fExternalPIDFlag(kTRUE),
120 fTimeResolution(100),
132 fT0TOF = new AliTOFT0v1();
133 if(AliPID::ParticleMass(0) == 0) new AliPID();
136 fPIDesd = new AliESDpid();
137 fExternalPIDFlag = kFALSE;
163 for (Int_t i = 0; i < 10; i++) {
169 /* copy-constructor and operator= suppressed
172 //____________________________________________________________________________
173 AliTOFT0maker::AliTOFT0maker(const AliTOFT0maker & t) :
177 fNoTOFT0(t.fNoTOFT0),
178 fTimeResolution(t.fTimeResolution),
179 fT0sigma(t.fT0sigma),
180 fHmapChannel(t.fHmapChannel),
186 //____________________________________________________________________________
187 AliTOFT0maker& AliTOFT0maker::operator=(const AliTOFT0maker &t)
196 TObject::operator=(t);
197 fTimeResolution = t.fTimeResolution;
198 fT0sigma = t.fT0sigma;
205 //____________________________________________________________________________
206 AliTOFT0maker::~AliTOFT0maker()
211 if (!fExternalPIDFlag) delete fPIDesd;
213 //____________________________________________________________________________
214 Double_t* AliTOFT0maker::ComputeT0TOF(AliESDEvent *esd,Double_t t0time,Double_t t0sigma){
216 // Remake TOF PID probabilities
221 if(fKmask) ApplyMask(esd);
223 /* get T0 spread from TOFcalib if available otherwise use default value */
224 if (fTOFcalib && esd) {
225 AliTOFRunParams *runParams = fTOFcalib->GetRunParams();
226 if (runParams && runParams->GetTimestamp(0) != 0) {
227 Float_t t0spread = runParams->EvalT0Spread(esd->GetTimeStamp());
228 SetT0FillWidth(t0spread);
233 AliTOFT0v1* t0maker= fT0TOF;
234 t0maker->SetTimeResolution(fTimeResolution*1e-12);
236 t0maker->DefineT0("all",1.5,3.0);
237 t0tof[0] = t0maker->GetResult(0);
238 t0tof[1] = t0maker->GetResult(1);
239 t0tof[2] = t0maker->GetResult(2);
240 t0tof[3] = t0maker->GetResult(3);
242 Float_t lT0Current=0.;
245 // Int_t nrun = esd->GetRunNumber();
246 Double_t t0fill = 0.;
250 Float_t sigmaFill = fT0width;
252 if(sigmaFill < 20) sigmaFill = 140;
254 fCalculated[0]=-1000*t0tof[0]; // best t0
255 fCalculated[1]=1000*t0tof[1]; // sigma best t0
256 fCalculated[2] = t0fill; //t0 fill
257 fCalculated[3] = t0tof[2]; // n TOF tracks
258 fCalculated[4]=-1000*t0tof[0]; // TOF t0
259 fCalculated[5]=1000*t0tof[1]; // TOF t0 sigma
260 fCalculated[6]=sigmaFill; // sigma t0 fill
261 fCalculated[7] = t0tof[3]; // n TOF tracks used for T0
263 if(fCalculated[1] < sigmaFill && TMath::Abs(fCalculated[0] - t0fill) < 500 && fCalculated[1] < fTimeResolution*1.2){
264 fT0sigma=fCalculated[1];
265 lT0Current=fCalculated[0];
268 fCalculated[4] = t0fill;
269 fCalculated[5] = sigmaFill;
272 if(fCalculated[1] < 1 || fT0sigma > sigmaFill || fCalculated[1] > fTimeResolution* 1.2){
274 fCalculated[4] = t0fill;
275 fCalculated[5] = sigmaFill;
280 Double_t w1 = 1./t0sigma/t0sigma;
281 Double_t w2 = 1./fCalculated[1]/fCalculated[1];
283 Double_t wtot = w1+w2;
285 lT0Current = (w1*t0time + w2*fCalculated[0]) / wtot;
286 fT0sigma = TMath::Sqrt(1./wtot);
294 if(fT0sigma < sigmaFill && TMath::Abs(lT0Current - t0fill) < 500){
295 fCalculated[1]=fT0sigma;
296 fCalculated[0]=lT0Current;
299 if(fT0sigma >= 1000 || fNoTOFT0){
301 fT0sigma = sigmaFill;
303 fCalculated[0] = t0fill;
304 fCalculated[1] = sigmaFill;
308 for(Int_t i=0;i<10;i++){
309 t0maker->DefineT0("all",fPtCutMin[i],fPtCutMax[i]);
310 t0tof[0] = t0maker->GetResult(0);
311 t0tof[1] = t0maker->GetResult(1);
312 t0tof[2] = t0maker->GetResult(2);
313 t0tof[3] = t0maker->GetResult(3);
314 fT0pt[i] =-1000*t0tof[0]; // best t0
315 fT0ptSigma[i] =1000*t0tof[1]; // sigma best t0
317 if(fT0ptSigma[i] < sigmaFill && fT0ptSigma[i] < fTimeResolution * 1.2 && TMath::Abs(fT0pt[i] - t0fill) < 500){
322 fT0ptSigma[i] = sigmaFill;
330 //____________________________________________________________________________
331 Double_t *AliTOFT0maker::GetT0p(Float_t p){// [0]=to -- [1] = sigma T0
333 while(p > fPtCutMin[i] && i < 10) i++;
336 fT0cur[0] = fT0pt[i];
337 fT0cur[1] = fT0ptSigma[i];
340 //____________________________________________________________________________
341 void AliTOFT0maker::SetTOFResponse(){
342 fPIDesd->GetTOFResponse().SetTimeResolution(TMath::Sqrt(fT0sigma*fT0sigma + fTimeResolution*fTimeResolution));
344 //____________________________________________________________________________
345 Float_t AliTOFT0maker::GetExpectedSigma(Float_t mom, Float_t tof, Float_t mass){
346 Double_t *sigmaT0 = GetT0p(mom);
347 fPIDesd->GetTOFResponse().SetTimeResolution(TMath::Sqrt(sigmaT0[1]*sigmaT0[1] + fTimeResolution*fTimeResolution));
348 Float_t sigma = fPIDesd->GetTOFResponse().GetExpectedSigma(mom,tof,mass);
349 fPIDesd->GetTOFResponse().SetTimeResolution(TMath::Sqrt(fT0sigma*fT0sigma + fTimeResolution*fTimeResolution));
353 //____________________________________________________________________________
354 void AliTOFT0maker::ApplyT0TOF(AliESDEvent *esd){
356 // Recalculate TOF PID probabilities
359 // subtruct t0 for each track
360 Int_t ntracks = esd->GetNumberOfTracks();
363 AliESDtrack *t=esd->GetTrack(ntracks);
365 if ((t->GetStatus()&AliESDtrack::kTOFout)==0) continue;
367 Double_t time=t->GetTOFsignal();
368 Float_t p = t->GetP();
370 Double_t *t0=GetT0p(p);
372 t->SetTOFsignal(time);
376 //____________________________________________________________________________
377 void AliTOFT0maker::LoadChannelMap(char *filename){
378 // Load the histo with the channel off map
379 TFile *f= new TFile(filename);
381 printf("Cannot open the channel map file (%s)\n",filename);
385 fHmapChannel = (TH1F *) f->Get("hChEnabled");
388 printf("Cannot laod the channel map histo (from %s)\n",filename);
393 //____________________________________________________________________________
394 void AliTOFT0maker::ApplyMask(AliESDEvent * const esd){
395 // Switch off the disable channel
397 printf("Channel Map is not available\n");
401 Int_t ntracks = esd->GetNumberOfTracks();
404 AliESDtrack *t=esd->GetTrack(ntracks);
406 if ((t->GetStatus()&AliESDtrack::kTOFout)==0) continue;
408 Int_t chan = t->GetTOFCalChannel();
410 if(fHmapChannel->GetBinContent(chan) < 0.01){
411 t->ResetStatus(AliESDtrack::kTOFout);
417 AliTOFT0maker::TuneForMC(AliESDEvent *esd){ // return true T0 event
422 Float_t TOFtimeResolutionDefault=80;
424 Float_t t0 = gRandom->Gaus(0.,fT0width);
426 Float_t extraSmearing = 0;
428 if(fTimeResolution > TOFtimeResolutionDefault){
429 extraSmearing = TMath::Sqrt(fTimeResolution*fTimeResolution - TOFtimeResolutionDefault*TOFtimeResolutionDefault);
432 // subtruct t0 for each track
433 Int_t ntracks = esd->GetNumberOfTracks();
436 AliESDtrack *t=esd->GetTrack(ntracks);
438 if ((t->GetStatus()&AliESDtrack::kTOFout)==0) continue;
440 /* check if channel is enabled */
441 if (fTOFcalib && !fTOFcalib->IsChannelEnabled(t->GetTOFCalChannel())) {
442 /* reset TOF status */
443 t->ResetStatus(AliESDtrack::kTOFin);
444 t->ResetStatus(AliESDtrack::kTOFout);
445 t->ResetStatus(AliESDtrack::kTOFrefit);
446 t->ResetStatus(AliESDtrack::kTOFpid);
449 Double_t time=t->GetTOFsignal();
454 Float_t smearing = gRandom->Gaus(0.,extraSmearing);
458 t->SetTOFsignal(time);