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"
50 #include "AliESDpid.h"
51 #include "AliESDEvent.h"
54 #include "AliTOFcalib.h"
55 #include "AliTOFRunParams.h"
57 #include "AliTOFHeader.h"
59 ClassImp(AliTOFT0maker)
61 //____________________________________________________________________________
62 AliTOFT0maker::AliTOFT0maker():
66 fExternalPIDFlag(kFALSE),
87 if(AliPID::ParticleMass(0) == 0) new AliPID();
89 fPIDesd = new AliESDpid();
91 fNmomBins = fPIDesd->GetTOFResponse().GetNmomBins();
94 fT0TOF = new AliTOFT0v1(fPIDesd);
97 //____________________________________________________________________________
98 AliTOFT0maker::AliTOFT0maker(AliESDpid *externalPID, AliTOFcalib *tofCalib):
101 fPIDesd(externalPID),
102 fExternalPIDFlag(kTRUE),
106 fTimeResolution(100),
123 if(AliPID::ParticleMass(0) == 0) new AliPID();
126 fPIDesd = new AliESDpid();
127 fExternalPIDFlag = kFALSE;
130 fNmomBins = fPIDesd->GetTOFResponse().GetNmomBins();
133 fT0TOF = new AliTOFT0v1(fPIDesd);
137 //____________________________________________________________________________
138 AliTOFT0maker::~AliTOFT0maker()
143 if (!fExternalPIDFlag) delete fPIDesd;
145 //____________________________________________________________________________
146 Double_t* AliTOFT0maker::ComputeT0TOF(AliESDEvent *esd,Double_t t0time,Double_t t0sigma){
148 // Remake TOF PID probabilities
152 if(fKmask) ApplyMask(esd);
154 Double_t t0fill = 0.;
156 fPIDesd->GetTOFResponse().ResetT0info();
158 /* get T0 spread from TOFcalib if available otherwise use default value */
159 if (fTOFcalib && esd) {
160 AliTOFRunParams *runParams = fTOFcalib->GetRunParams();
161 if (runParams && runParams->GetTimestamp(0) != 0) {
162 Float_t t0spread = runParams->EvalT0Spread(esd->GetTimeStamp());
163 if(fT0spreadExt > 0) SetT0FillWidth(fT0spreadExt);
165 SetT0FillWidth(t0spread);
170 if(fT0spreadExt > 0) SetT0FillWidth(fT0spreadExt);
175 Float_t t0spread = esd->GetSigma2DiamondZ(); // vertex pread ^2
176 if(t0spread > 0) t0spread = TMath::Sqrt(t0spread)/0.0299792458;
178 if(fT0spreadExt > 0) SetT0FillWidth(fT0spreadExt);
180 SetT0FillWidth(t0spread);
185 Float_t thrGood = TMath::Max(Float_t(500.),fT0width*3);
188 AliTOFT0v1* t0maker= fT0TOF;
190 t0maker->DefineT0("all",1.5,3.0);
191 t0tof[0] = t0maker->GetResult(0);
192 t0tof[1] = t0maker->GetResult(1);
193 t0tof[2] = t0maker->GetResult(2);
194 t0tof[3] = t0maker->GetResult(3);
195 t0tof[4] = t0maker->GetResult(4);
196 t0tof[5] = t0maker->GetResult(5);
198 Float_t lT0Current=0.;
201 // Int_t nrun = esd->GetRunNumber();
205 Float_t sigmaFill = fT0width;
207 if(sigmaFill < 20) sigmaFill = 140;
209 fCalculated[0]=-1000*t0tof[0]; // best t0
210 fCalculated[1]=1000*t0tof[1]; // sigma best t0
211 fCalculated[2] = t0fill; //t0 fill
212 fCalculated[3] = t0tof[2]; // n TOF tracks
213 fCalculated[4]=-1000*t0tof[0]; // TOF t0
214 fCalculated[5]=1000*t0tof[1]; // TOF t0 sigma
215 fCalculated[6]=sigmaFill; // sigma t0 fill
216 fCalculated[7] = t0tof[3]; // n TOF tracks used for T0
218 if(fCalculated[7] > 30) thrGood = 10000000;
221 fCalculated[8] = t0tof[4]; // real time in s
222 fCalculated[9] = t0tof[5]; // cpu time in s
224 if(fCalculated[1] < sigmaFill && TMath::Abs(fCalculated[0] - t0fill) < thrGood && fCalculated[1] < fTimeResolution*1.2){
225 fT0sigma=fCalculated[1];
226 lT0Current=fCalculated[0];
229 fCalculated[4] = t0fill;
230 fCalculated[5] = sigmaFill;
233 if(fCalculated[1] < 1 || fT0sigma > sigmaFill || fCalculated[1] > fTimeResolution* 1.2){
235 fCalculated[4] = t0fill;
236 fCalculated[5] = sigmaFill;
241 Double_t w1 = 1./t0sigma/t0sigma;
242 Double_t w2 = 1./fCalculated[1]/fCalculated[1];
244 Double_t wtot = w1+w2;
246 lT0Current = (w1*t0time + w2*fCalculated[0]) / wtot;
247 fT0sigma = TMath::Sqrt(1./wtot);
255 if(fT0sigma < sigmaFill && TMath::Abs(lT0Current - t0fill) < thrGood){
256 fCalculated[1]=fT0sigma;
257 fCalculated[0]=lT0Current;
260 if(fT0sigma >= 1000 || fNoTOFT0){
262 fT0sigma = sigmaFill;
264 fCalculated[0] = t0fill;
265 fCalculated[1] = sigmaFill;
269 Float_t *t0values = new Float_t[fNmomBins];
270 Float_t *t0resolution = new Float_t[fNmomBins];
271 if(fCalculated[7] < 100){
272 for(Int_t i=0;i<fNmomBins;i++){
273 t0maker->DefineT0("all",fPIDesd->GetTOFResponse().GetMinMom(i),fPIDesd->GetTOFResponse().GetMaxMom(i));
274 t0tof[0] = t0maker->GetResult(0);
275 t0tof[1] = t0maker->GetResult(1);
276 t0tof[2] = t0maker->GetResult(2);
277 t0tof[3] = t0maker->GetResult(3);
279 Float_t t0bin =-1000*t0tof[0]; // best t0
280 Float_t t0binRes =1000*t0tof[1]; // sigma best t0
282 if(t0binRes < sigmaFill && t0binRes < fTimeResolution * 1.2 && TMath::Abs(t0bin - t0fill) < thrGood){
285 Double_t w1 = 1./t0sigma/t0sigma;
286 Double_t w2 = 1./t0binRes/t0binRes;
288 Double_t wtot = w1+w2;
290 t0bin = (w1*t0time + w2*t0bin) / wtot;
291 t0binRes = TMath::Sqrt(1./wtot);
296 t0binRes = sigmaFill;
303 t0resolution[i] = t0binRes;
307 for(Int_t i=0;i<fNmomBins;i++){
308 t0values[i] = lT0Current;
309 t0resolution[i] = fT0sigma;
312 for(Int_t i=0;i<fNmomBins;i++){
313 fPIDesd->GetTOFResponse().SetT0bin(i,t0values[i]);
314 fPIDesd->GetTOFResponse().SetT0binRes(i,t0resolution[i]);
318 delete[] t0resolution;
322 //____________________________________________________________________________
323 Double_t *AliTOFT0maker::GetT0p(Float_t p){// [0]=to -- [1] = sigma T0
324 Int_t i=fPIDesd->GetTOFResponse().GetMomBin(p);
326 fT0cur[0] = fPIDesd->GetTOFResponse().GetT0bin(i);
327 fT0cur[1] = fPIDesd->GetTOFResponse().GetT0binRes(i);
331 //____________________________________________________________________________
332 void AliTOFT0maker::SetTOFResponse(){
333 fPIDesd->GetTOFResponse().SetTimeResolution(fTimeResolution);
335 //____________________________________________________________________________
336 Float_t AliTOFT0maker::GetExpectedSigma(Float_t mom, Float_t tof, Float_t mass){
337 Float_t sigma = fPIDesd->GetTOFResponse().GetExpectedSigma(mom,tof,mass);
341 //____________________________________________________________________________
342 void AliTOFT0maker::ApplyT0TOF(AliESDEvent *esd){
344 // Recalculate TOF PID probabilities
347 // subtruct t0 for each track
348 Int_t ntracks = esd->GetNumberOfTracks();
351 AliESDtrack *t=esd->GetTrack(ntracks);
353 if ((t->GetStatus()&AliESDtrack::kTOFout)==0) continue;
355 Double_t time=t->GetTOFsignal();
356 Float_t p = t->GetP();
358 Double_t *t0=GetT0p(p);
360 t->SetTOFsignal(time);
363 for(Int_t i=0;i<fNmomBins;i++){
364 fPIDesd->GetTOFResponse().SetT0bin(i,0.0);
369 //____________________________________________________________________________
370 void AliTOFT0maker::LoadChannelMap(char *filename){
371 // Load the histo with the channel off map
372 TFile *f= new TFile(filename);
374 printf("Cannot open the channel map file (%s)\n",filename);
378 fHmapChannel = (TH1F *) f->Get("hChEnabled");
381 printf("Cannot laod the channel map histo (from %s)\n",filename);
386 //____________________________________________________________________________
387 void AliTOFT0maker::ApplyMask(AliESDEvent * const esd){
388 // Switch off the disable channel
390 printf("Channel Map is not available\n");
394 Int_t ntracks = esd->GetNumberOfTracks();
397 AliESDtrack *t=esd->GetTrack(ntracks);
399 if ((t->GetStatus()&AliESDtrack::kTOFout)==0) continue;
401 Int_t chan = t->GetTOFCalChannel();
403 if(fHmapChannel->GetBinContent(chan) < 0.01){
404 t->ResetStatus(AliESDtrack::kTOFout);
410 AliTOFT0maker::TuneForMC(AliESDEvent *esd){ // return true T0 event
415 Float_t TOFtimeResolutionDefault=80;
417 Float_t t0 = gRandom->Gaus(0.,fT0width);
419 Float_t extraSmearing = 0;
421 if(fTimeResolution > TOFtimeResolutionDefault){
422 extraSmearing = TMath::Sqrt(fTimeResolution*fTimeResolution - TOFtimeResolutionDefault*TOFtimeResolutionDefault);
425 // subtruct t0 for each track
426 Int_t ntracks = esd->GetNumberOfTracks();
429 AliESDtrack *t=esd->GetTrack(ntracks);
431 if ((t->GetStatus()&AliESDtrack::kTOFout)==0) continue;
433 /* check if channel is enabled */
435 if(!fTOFcalib->IsChannelEnabled(t->GetTOFCalChannel())) {
436 /* reset TOF status */
437 t->ResetStatus(AliESDtrack::kTOFin);
438 t->ResetStatus(AliESDtrack::kTOFout);
439 t->ResetStatus(AliESDtrack::kTOFmismatch);
440 t->ResetStatus(AliESDtrack::kTOFpid);
444 Double_t time=t->GetTOFsignal();
449 Float_t smearing = gRandom->Gaus(0.,extraSmearing);
453 t->SetTOFsignal(time);
458 //_________________________________________________________________________
459 void AliTOFT0maker::WriteInESD(AliESDEvent *esd){
461 // Write t0Gen, t0ResGen, nt0;
462 // t0resESD[0:nt0], it0ESD[0:nt0]
463 // in the AliESDEvent
465 Int_t nMomBins = fPIDesd->GetTOFResponse().GetNmomBins();
468 Float_t *t0 = new Float_t[nMomBins];
469 Float_t *t0res = new Float_t[nMomBins];
470 Int_t *multT0 = new Int_t[nMomBins];
472 for(Int_t i=0;i<nMomBins;i++){
473 // printf("START %i) %f %f\n",i,fT0event[i],fT0resolution[i]);
476 for(Int_t j=0;j < nt0;j++){
477 if(TMath::Abs(fPIDesd->GetTOFResponse().GetT0bin(i) - t0[j])<0.1){
484 t0[nt0]=fPIDesd->GetTOFResponse().GetT0bin(i);
485 t0res[nt0]=fPIDesd->GetTOFResponse().GetT0binRes(i);
490 Int_t iMultT0=0,nmult=0;
491 for(Int_t j=0;j < nt0;j++){ // find the most frequent
492 if(multT0[j] > nmult){
498 Float_t *t0ESD = new Float_t[nMomBins];
499 Float_t *t0resESD = new Float_t[nMomBins];
500 Int_t *it0ESD = new Int_t[nMomBins];
502 Float_t t0Gen,t0ResGen;
504 t0ResGen = t0res[iMultT0];
506 // printf("T0 to ESD\n%f %f\n",t0Gen,t0ResGen);
507 for(Int_t i=0;i<nMomBins;i++){
508 if(TMath::Abs(fPIDesd->GetTOFResponse().GetT0bin(i) - t0Gen)>0.1){
509 t0ESD[nt0]=fPIDesd->GetTOFResponse().GetT0bin(i);
510 t0resESD[nt0]=fPIDesd->GetTOFResponse().GetT0binRes(i);
512 // printf("%i) %f %f %i\n",nt0,t0ESD[nt0],t0resESD[nt0],it0ESD[nt0]);
517 // Write t0Gen,t0ResGen; nt0; t0resESD[0:nt0],it0ESD[0:nt0] in the AliESDEvent
519 AliTOFHeader *tofHeader =
520 new AliTOFHeader(t0Gen,t0ResGen,nt0,
521 t0ESD,t0resESD,it0ESD,fTimeResolution,fT0width);
523 esd->SetTOFHeader(tofHeader);
525 AliDebug(1,Form("resTOF=%f T0spread=%f t0Gen=%f t0resGen=%f",fTimeResolution,fT0width,t0Gen,t0ResGen));
526 AliDebug(1,Form("%d ",nt0));
527 for (Int_t ii=0; ii<nt0; ii++)
528 AliDebug(1,Form("pBin=%d t0val=%f t0res=%f",it0ESD[ii],t0ESD[ii],t0resESD[ii]));