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 **************************************************************************/
16 /* $Id: AliTOFT0v1.cxx,v 1.8 2003/10/23 16:32:20 hristov Exp $ */
18 //_________________________________________________________________________
19 // This is a TTask that made the calculation of the Time zero using TOF.
20 // Description: The algorithm used to calculate the time zero of interaction
21 // using TOF detector is the following.
22 // We select in the MonteCarlo some primary particles - or tracks in the following -
23 // that strike the TOF detector (the larger part are pions, kaons or protons).
24 // We choose a set of 10 selected tracks, for each track You have the length
25 // of the track when the TOF is reached (a standard TOF hit does not contain this
26 // additional information, this is the reason why we implemented a new time zero
27 // dedicated TOF hit class AliTOFhitT0; in order to store this type of hit You
28 // have to use the AliTOFv4T0 as TOF class in Your Config.C. In AliTOFv4T0 the
29 // StepManager was modified in order to fill the TOF hit branch with this type
30 // of hits; in fact the AliTOF::AddT0Hit is called rather that the usual AliTOF::AddHit),
31 // the momentum at generation (from TreeK) and the time of flight
32 // given by the TOF detector.
33 // (Observe that the ctor of the AliTOF class, when the AliTOFv4T0 class is used, is called
34 // with the "tzero" option: it is in order create the fHits TClonesArray filled with
35 // AliTOFhitT0 objects, rather than with normal AliTOFhit)
36 // Then Momentum and time of flight for each track are smeared according to
37 // known experimental resolution (all sources of error have been token into account).
38 // Let consider now only one set of 10 tracks (the algorithm is the same for all sets).
39 // Assuming the (mass) hypothesis that each track can be AUT a pion, AUT a kaon, AUT a proton,
40 // we consider all the 3 at 10 possible cases.
41 // For each track in each (mass) configuration
42 // (a configuration can be e.g. pion/pion/kaon/proton/pion/proton/kaon/kaon/pion/pion)
43 // we calculate the time zero (we know in fact the velocity of the track after
44 // the assumption about its mass, the time of flight given by the TOF, and the
45 // corresponding path travelled till the TOF detector). Then for each mass configuration we have
46 // 10 time zero and we can calculate the ChiSquare for the current configuration using the
47 // weighted mean over all 10 time zero.
48 // We call the best assignment the mass configuration that gives the minimum value of the ChiSquare.
49 // We plot the weighted mean over all 10 time zero for the best assignment,
50 // the ChiSquare for the best assignment and the corresponding confidence level.
51 // The strong assumption is the MC selection of primary particles. It will be introduced
52 // in the future also some more realistic simulation about this point.
54 // root [0] AliTOFT0v1 * tzero = new AliTOFT0v1("galice.root")
55 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
56 // root [1] tzero->ExecuteTask()
57 // root [2] tzero->ExecuteTask("tim")
58 // // available parameters:
59 // tim - print benchmarking information
60 // all - print usefull informations about the number of misidentified tracks
61 // and a comparison about the true configuration (known from MC) and the best
63 // Different Selections for pp and Pb-Pb: Momentum Range, Max Time, # pions
64 //-- Author: F. Pierella
66 //////////////////////////////////////////////////////////////////////////////
68 #include <Riostream.h>
71 #include <TBenchmark.h>
73 #include <TClonesArray.h>
80 #include <TParticle.h>
84 #include <TVirtualMC.h>
85 #include "AliTOFT0v1.h"
87 #include "AliESDtrack.h"
90 #include "AliESDtrackCuts.h"
91 #include "AliTOFcalibHisto.h"
95 //____________________________________________________________________________
96 AliTOFT0v1::AliTOFT0v1(AliESDEvent* event)
98 fLowerMomBound=0.4; // [GeV/c] default value pp
99 fUpperMomBound=2.0 ; // [GeV/c] default value pp
100 fTimeResolution = 0.80e-10; // 80 ps by default
101 fTimeCorr = 0.0; // in ns by default
106 fT0SigmaT0def[0]=-999.;
107 fT0SigmaT0def[1]=999.;
108 fT0SigmaT0def[2]=-999.;
109 fT0SigmaT0def[3]=-999.;
111 fDeltaTfromMisallinement = 0.; // in ps
114 //____________________________________________________________________________
115 AliTOFT0v1::AliTOFT0v1(const AliTOFT0v1 & tzero)
117 ( (AliTOFT0v1 &)tzero ).Copy(*this);
120 //____________________________________________________________________________
121 AliTOFT0v1::~AliTOFT0v1()
126 void AliTOFT0v1::SetTimeResolution(Double_t timeresolution){
127 fTimeResolution=timeresolution;
129 //____________________________________________________________________________
130 //____________________________________________________________________________
131 Double_t * AliTOFT0v1::DefineT0(Option_t *option)
133 Float_t timeresolutioninns=fTimeResolution*(1.e+9) * TMath::Sqrt(2.); // convert in [ns]
135 const Int_t nmaxtracksinset=10;
136 if(strstr(option,"all")){
137 cout << "Selecting primary tracks with momentum between " << fLowerMomBound << " GeV/c and " << fUpperMomBound << " GeV/c" << endl;
138 cout << "Memorandum: 0 means PION | 1 means KAON | 2 means PROTON" << endl;
144 Int_t ngoodsetsSel= 0;
145 Float_t t0bestSel[300];
146 Float_t Et0bestSel[300];
147 Float_t ChisquarebestSel[300];
148 Float_t ConfLevelbestSel[300];
149 Float_t t0bestallSel=0.;
150 Float_t Et0bestallSel=0.;
151 Float_t sumWt0bestallSel=0.;
152 Float_t Emeantzeropi=0.;
153 Float_t meantzeropi=0.;
154 Float_t sumAllweightspi=0.;
156 Double_t deltat0def=999;
157 Int_t ngoodtrktrulyused=0;
158 Int_t ntracksinsetmyCut = 0;
160 Int_t ntrk=fEvent->GetNumberOfTracks();
162 AliESDtrack **tracks=new AliESDtrack*[ntrk];
165 Float_t mintime =1E6;
167 // First Track loop, Selection of good tracks
169 for (Int_t itrk=0; itrk<ntrk; itrk++) {
170 AliESDtrack *t=fEvent->GetTrack(itrk);
171 Double_t momOld=t->GetP();
172 Double_t mom=momOld-0.0036*momOld;
173 if ((t->GetStatus()&AliESDtrack::kTIME)==0) continue;
174 Double_t time=t->GetTOFsignal();
176 time*=1.E-3; // tof given in nanoseconds
177 if (!(mom<=fUpperMomBound && mom>=fLowerMomBound))continue;
180 AliESDtrackCuts* esdTrackCuts = new AliESDtrackCuts();
181 Bool_t tpcRefit = kTRUE;
183 Bool_t sigmaToVertex = kTRUE;
184 esdTrackCuts->SetRequireSigmaToVertex(sigmaToVertex);
186 esdTrackCuts->SetMaxNsigmaToVertex(nSigma);
189 esdTrackCuts->SetMaxDCAToVertexZ(3.0);
190 esdTrackCuts->SetMaxDCAToVertexXY(3.0);
192 esdTrackCuts->SetRequireTPCRefit(tpcRefit);
193 esdTrackCuts->SetAcceptKinkDaughters(kFALSE);
194 esdTrackCuts->SetMinNClustersTPC(50);
195 esdTrackCuts->SetMaxChi2PerClusterTPC(3.5);
197 accepted=esdTrackCuts->AcceptTrack(t);
198 if(!accepted) continue;
201 if(t->GetP() < fLowerMomBound || t->GetIntegratedLength() < 350 || t->GetTOFsignalToT() < 0.000000001)continue; //skip decays
202 if(time <= mintime) mintime=time;
208 cout << " T0 offset selected for this sample : " << fT0Offset << endl;
209 cout << " N. of ESD tracks : " << ntrk << endl;
210 cout << " N. of preselected tracks : " << ngoodtrk << endl;
211 cout << " Minimum tof time in set (in ns) : " << mintime << endl;
213 AliESDtrack **gtracks=new AliESDtrack*[ngoodtrk];
215 for (Int_t jtrk=0; jtrk< ngoodtrk; jtrk++) {
216 AliESDtrack *t=tracks[jtrk];
217 Double_t time=t->GetTOFsignal();
219 if((time-mintime*1.E3)<50.E3){ // For pp and per
220 gtracks[ngoodtrkt0]=t;
226 Int_t nseteq = (ngoodtrkt0-1)/nmaxtracksinset + 1;
227 Int_t nmaxtracksinsetCurrent=ngoodtrkt0/nseteq;
228 if(nmaxtracksinsetCurrent*nseteq < ngoodtrkt0) nmaxtracksinsetCurrent++;
231 cout << "less than 2 tracks, skip event " << endl;
234 fT0SigmaT0def[0]=t0def;
235 fT0SigmaT0def[1]=deltat0def;
236 fT0SigmaT0def[2]=ngoodtrkt0;
237 fT0SigmaT0def[3]=ngoodtrkt0;
241 // Decide how many tracks in set
242 Int_t ntracksinset = min(ngoodtrkt0,nmaxtracksinsetCurrent);
245 if(ngoodtrkt0>nmaxtracksinsetCurrent) {nset= (Int_t)(ngoodtrkt0/ntracksinset)+1;}
247 cout << " number of sets = " << nset << endl;
249 if(strstr(option,"tim") || strstr(option,"all"))gBenchmark->Start("TOFT0v1");
251 // Loop over selected sets
254 for (Int_t i=0; i< nset; i++) {
257 Float_t Et0best=999.;
258 Float_t chisquarebest=99999.;
261 Int_t ntracksinsetmy=0;
262 AliESDtrack **tracksT0=new AliESDtrack*[ntracksinset];
263 for (Int_t itrk=0; itrk<ntracksinset; itrk++) {
264 Int_t index = itrk+i*ntracksinset;
265 if(index < ngoodtrkt0){
266 AliESDtrack *t=gtracks[index];
274 Int_t assparticle[nmaxtracksinset];
275 Float_t exptof[nmaxtracksinset][3];
276 Float_t timeofflight[nmaxtracksinset];
277 Float_t momentum[nmaxtracksinset];
278 Float_t timezero[nmaxtracksinset];
279 Float_t weightedtimezero[nmaxtracksinset];
280 Float_t beta[nmaxtracksinset];
281 Float_t texp[nmaxtracksinset];
282 Float_t dtexp[nmaxtracksinset];
283 Float_t sqMomError[nmaxtracksinset];
284 Float_t sqTrackError[nmaxtracksinset];
285 Float_t massarray[3]={0.13957,0.493677,0.9382723};
286 Float_t tracktoflen[nmaxtracksinset];
287 Float_t besttimezero[nmaxtracksinset];
288 Float_t besttexp[nmaxtracksinset];
289 Float_t besttimeofflight[nmaxtracksinset];
290 Float_t bestmomentum[nmaxtracksinset];
291 Float_t bestchisquare[nmaxtracksinset];
292 Float_t bestweightedtimezero[nmaxtracksinset];
293 Float_t bestsqTrackError[nmaxtracksinset];
294 Int_t imass[nmaxtracksinset];
296 for (Int_t j=0; j<ntracksinset; j++) {
301 weightedtimezero[j] = 0;
310 besttimeofflight[j] = 0;
312 bestchisquare[j] = 0;
313 bestweightedtimezero[j] = 0;
314 bestsqTrackError[j] = 0;
318 for (Int_t j=0; j<ntracksinsetmy; j++) {
319 AliESDtrack *t=tracksT0[j];
320 Double_t momOld=t->GetP();
321 Double_t mom=momOld-0.0036*momOld;
322 Double_t time=t->GetTOFsignal();
324 time*=1.E-3; // tof given in nanoseconds
325 Double_t exptime[10]; t->GetIntegratedTimes(exptime);
326 Double_t toflen=t->GetIntegratedLength();
327 toflen=toflen/100.; // toflen given in m
329 timeofflight[j]=time+fT0Offset;
330 tracktoflen[j]=toflen+fLOffset;
331 exptof[j][0]=exptime[2]*1.E-3+fTimeCorr;// in ns
332 exptof[j][1]=exptime[3]*1.E-3+fTimeCorr;
333 exptof[j][2]=exptime[4]*1.E-3+fTimeCorr;
337 } //end for (Int_t j=0; j<ntracksinsetmy; j++) {
339 cout << "starting t0 calculation for current set" << endl;
340 for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
341 beta[itz]=momentum[itz]/sqrt(massarray[0]*massarray[0]
342 +momentum[itz]*momentum[itz]);
343 sqMomError[itz]= ((1.-beta[itz]*beta[itz])*0.01)*((1.-beta[itz]*beta[itz])*0.01)*(tracktoflen[itz]/(0.299792*beta[itz]))*(tracktoflen[itz]/(0.299792*beta[itz]));
344 sqTrackError[itz]=(timeresolutioninns*timeresolutioninns+sqMomError[itz]); //in ns
345 timezero[itz]=exptof[itz][0]-timeofflight[itz];// in ns
346 weightedtimezero[itz]=timezero[itz]/sqTrackError[itz];
347 sumAllweightspi+=1./sqTrackError[itz];
348 meantzeropi+=weightedtimezero[itz];
349 } // end loop for (Int_t itz=0; itz< ntracksinset;itz++)
352 // Then, Combinatorial Algorithm
354 if(ntracksinsetmy<2 )break;
356 for (Int_t j=0; j<ntracksinsetmy; j++) {
360 Int_t ncombinatorial = Int_t(TMath::Power(3,ntracksinsetmy));
362 // Loop on mass hypotheses
363 for (Int_t k=0; k < ncombinatorial;k++) {
364 for (Int_t j=0; j<ntracksinsetmy; j++) {
365 imass[j] = (k % Int_t(TMath::Power(3,ntracksinsetmy-j)))/Int_t(TMath::Power(3,ntracksinsetmy-j-1));
366 texp[j]=exptof[j][imass[j]];
367 dtexp[j]=GetMomError(imass[j], momentum[j], texp[j]);
369 Float_t sumAllweights=0.;
370 Float_t meantzero=0.;
371 Float_t Emeantzero=0.;
373 for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
377 +dtexp[itz]*dtexp[itz]*1E-6); //in ns2
379 timezero[itz]=texp[itz]-timeofflight[itz];// in ns
381 weightedtimezero[itz]=timezero[itz]/sqTrackError[itz];
382 sumAllweights+=1./sqTrackError[itz];
383 meantzero+=weightedtimezero[itz];
385 } // end loop for (Int_t itz=0; itz<15;itz++)
387 meantzero=meantzero/sumAllweights; // it is given in [ns]
388 Emeantzero=sqrt(1./sumAllweights); // it is given in [ns]
390 // calculate chisquare
392 Float_t chisquare=0.;
393 for (Int_t icsq=0; icsq<ntracksinsetmy;icsq++) {
394 chisquare+=(timezero[icsq]-meantzero)*(timezero[icsq]-meantzero)/sqTrackError[icsq];
396 } // end loop for (Int_t icsq=0; icsq<15;icsq++)
398 if(chisquare<=chisquarebest){
399 for(Int_t iqsq = 0; iqsq<ntracksinsetmy; iqsq++) {
401 bestsqTrackError[iqsq]=sqTrackError[iqsq];
402 besttimezero[iqsq]=timezero[iqsq];
403 bestmomentum[iqsq]=momentum[iqsq];
404 besttimeofflight[iqsq]=timeofflight[iqsq];
405 besttexp[iqsq]=texp[iqsq];
406 bestweightedtimezero[iqsq]=weightedtimezero[iqsq];
407 bestchisquare[iqsq]=(timezero[iqsq]-meantzero)*(timezero[iqsq]-meantzero)/sqTrackError[iqsq];
411 for (Int_t j=0; j<ntracksinsetmy; j++) {
412 assparticle[j]=imass[j];
413 if(imass[j] == 0) npion++;
416 chisquarebest=chisquare;
419 } // close if(dummychisquare<=chisquare)
423 Double_t chi2cut[nmaxtracksinset];
425 chi2cut[1] = 6.6; // corresponding to a C.L. of 0.01
426 for (Int_t j=2; j<ntracksinset; j++) {
427 chi2cut[j] = chi2cut[1] * TMath::Sqrt(j*1.);
430 Double_t chi2singlecut = chi2cut[ntracksinsetmy-1]/ntracksinsetmy + TMath::Abs(chisquarebest-chi2cut[ntracksinsetmy-1])/ntracksinsetmy;
432 printf("tracks removed with a chi2 > %f (chi2total = %f w.r.t. the limit of %f)\n",chi2singlecut,chisquarebest,chi2cut[ntracksinsetmy-1]);
434 Bool_t kRedoT0 = kFALSE;
435 ntracksinsetmyCut = ntracksinsetmy;
436 Bool_t usetrack[nmaxtracksinset];
437 for (Int_t icsq=0; icsq<ntracksinsetmy;icsq++) {
438 usetrack[icsq] = kTRUE;
439 if((bestchisquare[icsq] > chisquarebest*0.5 && ntracksinsetmy > 2) || (bestchisquare[icsq] > chi2singlecut)){
442 usetrack[icsq] = kFALSE;
444 } // end loop for (Int_t icsq=0; icsq<15;icsq++)
446 printf("ntrackinsetmy = %i - %i\n",ntracksinsetmy,ntracksinsetmyCut);
448 // Loop on mass hypotheses Redo
449 if(kRedoT0 && ntracksinsetmyCut > 1){
451 for (Int_t k=0; k < ncombinatorial;k++) {
452 for (Int_t j=0; j<ntracksinsetmy; j++) {
453 imass[j] = (k % Int_t(TMath::Power(3,ntracksinsetmy-j))) / Int_t(TMath::Power(3,ntracksinsetmy-j-1));
454 texp[j]=exptof[j][imass[j]];
455 dtexp[j]=GetMomError(imass[j], momentum[j], texp[j]);
458 Float_t sumAllweights=0.;
459 Float_t meantzero=0.;
460 Float_t Emeantzero=0.;
462 for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
463 if(! usetrack[itz]) continue;
467 +dtexp[itz]*dtexp[itz]*1E-6); //in ns2
469 timezero[itz]=texp[itz]-timeofflight[itz];// in ns
471 weightedtimezero[itz]=timezero[itz]/sqTrackError[itz];
472 sumAllweights+=1./sqTrackError[itz];
473 meantzero+=weightedtimezero[itz];
475 } // end loop for (Int_t itz=0; itz<15;itz++)
477 meantzero=meantzero/sumAllweights; // it is given in [ns]
478 Emeantzero=sqrt(1./sumAllweights); // it is given in [ns]
480 // calculate chisquare
482 Float_t chisquare=0.;
483 for (Int_t icsq=0; icsq<ntracksinsetmy;icsq++) {
484 if(! usetrack[icsq]) continue;
485 chisquare+=(timezero[icsq]-meantzero)*(timezero[icsq]-meantzero)/sqTrackError[icsq];
487 } // end loop for (Int_t icsq=0; icsq<15;icsq++)
490 for (Int_t j=0; j<ntracksinsetmy; j++) {
491 assparticle[j]=imass[j];
492 if(imass[j] == 0) npion++;
495 if(chisquare<=chisquarebest){
496 for(Int_t iqsq = 0; iqsq<ntracksinsetmy; iqsq++) {
497 if(! usetrack[iqsq]) continue;
498 bestsqTrackError[iqsq]=sqTrackError[iqsq];
499 besttimezero[iqsq]=timezero[iqsq];
500 bestmomentum[iqsq]=momentum[iqsq];
501 besttimeofflight[iqsq]=timeofflight[iqsq];
502 besttexp[iqsq]=texp[iqsq];
503 bestweightedtimezero[iqsq]=weightedtimezero[iqsq];
504 bestchisquare[iqsq]=(timezero[iqsq]-meantzero)*(timezero[iqsq]-meantzero)/sqTrackError[iqsq];
508 chisquarebest=chisquare;
511 } // close if(dummychisquare<=chisquare)
516 if(chisquarebest >= 999){
517 printf("How is it possible (chi2 = %f)? T0best = %f\n",chisquarebest,t0best);
519 for(Int_t icsq=0; icsq<ntracksinsetmy;icsq++){
520 cout << "Track # " << icsq << " T0 offsets = "
521 << besttimezero[icsq]-t0best <<
522 " track error = " << bestsqTrackError[icsq]
523 << " Chisquare = " << bestchisquare[icsq]
524 << " Momentum = " << bestmomentum[icsq]
525 << " TOF = " << besttimeofflight[icsq]
526 << " TOF tracking = " << besttexp[icsq]
527 << " is used = " << usetrack[icsq] << endl;
532 Float_t confLevel=999;
534 // Sets with decent chisquares
536 if(chisquarebest<999.){
537 Double_t dblechisquare=(Double_t)chisquarebest;
538 confLevel=(Float_t)TMath::Prob(dblechisquare,ntracksinsetmyCut-1);
539 cout << " Set Number " << nsets << endl;
540 cout << "Best Assignment, selection " << assparticle[0] <<
541 assparticle[1] << assparticle[2] <<
542 assparticle[3] << assparticle[4] <<
543 assparticle[5] << endl;
544 cout << " Chisquare of the set "<< chisquarebest <<endl;
545 cout << " C.L. of the set "<< confLevel <<endl;
546 cout << " T0 for this set (in ns) " << t0best << endl;
548 for(Int_t icsq=0; icsq<ntracksinsetmy;icsq++){
550 if(! usetrack[icsq]) continue;
552 cout << "Track # " << icsq << " T0 offsets = "
553 << besttimezero[icsq]-t0best <<
554 " track error = " << bestsqTrackError[icsq]
555 << " Chisquare = " << bestchisquare[icsq]
556 << " Momentum = " << bestmomentum[icsq]
557 << " TOF = " << besttimeofflight[icsq]
558 << " TOF tracking = " << besttexp[icsq]
559 << " is used = " << usetrack[icsq] << endl;
562 // Pick up only those with C.L. >1%
563 // if(confLevel>0.01 && ngoodsetsSel<200){
564 if(confLevel>0.01 && ngoodsetsSel<200){
565 ChisquarebestSel[ngoodsetsSel]=chisquarebest;
566 ConfLevelbestSel[ngoodsetsSel]=confLevel;
567 t0bestSel[ngoodsetsSel]=t0best/Et0best/Et0best;
568 Et0bestSel[ngoodsetsSel]=1./Et0best/Et0best;
569 t0bestallSel += t0best/Et0best/Et0best;
570 sumWt0bestallSel += 1./Et0best/Et0best;
572 ngoodtrktrulyused+=ntracksinsetmyCut;
575 printf("conflevel = %f -- ngoodsetsSel = %i -- ntrackset = %i\n",confLevel,ngoodsetsSel,ntracksinsetmy);
581 } // end for the current set
583 NusedTracks = ngoodtrkt0;
584 if(strstr(option,"all")){
585 if(sumAllweightspi>0.){
586 meantzeropi=meantzeropi/sumAllweightspi; // it is given in [ns]
587 Emeantzeropi=sqrt(1./sumAllweightspi); // it is given in [ns]
590 if(sumWt0bestallSel>0){
591 t0bestallSel = t0bestallSel/sumWt0bestallSel;
592 Et0bestallSel = sqrt(1./sumWt0bestallSel);
594 }// end of if(sumWt0bestallSel>0){
596 cout << "T0 all " << t0bestallSel << " +/- " << Et0bestallSel << "Number of tracks used: "<<ngoodtrktrulyused<<endl;
600 deltat0def=Et0bestallSel;
601 if ((t0bestallSel==0)&&(Et0bestallSel==0)){
602 t0def=-999; deltat0def=0.600;
605 fT0SigmaT0def[0]=t0def;
606 fT0SigmaT0def[1]=TMath::Sqrt(deltat0def*deltat0def*(ngoodtrktrulyused/(ngoodtrktrulyused-1)));
607 fT0SigmaT0def[2]=ngoodtrkt0;//ngoodtrktrulyused;
608 fT0SigmaT0def[3]=ngoodtrktrulyused;
612 if(strstr(option,"tim") || strstr(option,"all")){
613 gBenchmark->Stop("TOFT0v1");
614 cout << "AliTOFT0v1:" << endl ;
615 cout << " took " << gBenchmark->GetCpuTime("TOFT0v1") << " seconds in order to calculate T0 " << endl ;
617 printf("T0 from TOF = %f ns\n",fT0SigmaT0def[0]);
619 return fT0SigmaT0def;
621 //__________________________________________________________________
622 Double_t * AliTOFT0v1::DefineT0RawCorrection(Option_t *option)
624 Float_t timeresolutioninns=fTimeResolution*(1.e+9); // convert in [ns]
626 const Int_t nmaxtracksinset=10;
627 if(strstr(option,"all")){
628 cout << "Selecting primary tracks with momentum between " << fLowerMomBound << " GeV/c and " << fUpperMomBound << " GeV/c" << endl;
629 cout << "Memorandum: 0 means PION | 1 means KAON | 2 means PROTON" << endl;
632 Float_t stripmean = 0;
636 Int_t ngoodsetsSel= 0;
637 Float_t t0bestSel[300];
638 Float_t Et0bestSel[300];
639 Float_t ChisquarebestSel[300];
640 Float_t ConfLevelbestSel[300];
641 Float_t t0bestallSel=0.;
642 Float_t Et0bestallSel=0.;
643 Float_t sumWt0bestallSel=0.;
644 Float_t Emeantzeropi=0.;
645 Float_t meantzeropi=0.;
646 Float_t sumAllweightspi=0.;
648 Double_t deltat0def=999;
649 Int_t ngoodtrktrulyused=0;
650 Int_t ntracksinsetmyCut = 0;
652 Int_t ntrk=fEvent->GetNumberOfTracks();
654 AliESDtrack **tracks=new AliESDtrack*[ntrk];
657 Float_t mintime =1E6;
659 // First Track loop, Selection of good tracks
661 for (Int_t itrk=0; itrk<ntrk; itrk++) {
662 AliESDtrack *t=fEvent->GetTrack(itrk);
663 Double_t momOld=t->GetP();
664 Double_t mom=momOld-0.0036*momOld;
665 if ((t->GetStatus()&AliESDtrack::kTIME)==0) continue;
666 Double_t tot = t->GetTOFsignalToT();
667 Double_t time=t->GetTOFsignalRaw();
668 Int_t chan = t->GetTOFCalChannel();
669 Double_t corr = fCalib->GetFullCorrection(chan,tot) - fCalib->GetCorrection(AliTOFcalibHisto::kTimeSlewingCorr,chan,0);
672 Int_t crate = fCalib->GetCalibMap(AliTOFcalibHisto::kDDL,chan);
673 if(crate == 63 || crate == 62){
677 Int_t strip = fCalib->GetCalibMap(AliTOFcalibHisto::kSectorStrip,chan);
679 time*=1.E-3; // tof given in nanoseconds
680 if (!(mom<=fUpperMomBound && mom>=fLowerMomBound))continue;
683 AliESDtrackCuts* esdTrackCuts = new AliESDtrackCuts();
684 Bool_t tpcRefit = kTRUE;
686 Bool_t sigmaToVertex = kTRUE;
687 esdTrackCuts->SetRequireSigmaToVertex(sigmaToVertex);
689 esdTrackCuts->SetMaxNsigmaToVertex(nSigma);
692 esdTrackCuts->SetMaxDCAToVertexZ(3.0);
693 esdTrackCuts->SetMaxDCAToVertexXY(3.0);
695 esdTrackCuts->SetRequireTPCRefit(tpcRefit);
696 esdTrackCuts->SetAcceptKinkDaughters(kFALSE);
697 esdTrackCuts->SetMinNClustersTPC(50);
698 esdTrackCuts->SetMaxChi2PerClusterTPC(3.5);
700 accepted=esdTrackCuts->AcceptTrack(t);
701 if(!accepted) continue;
704 if(t->GetP() < fLowerMomBound || t->GetIntegratedLength() < 350 || t->GetTOFsignalToT() < 0.000000001)continue; //skip decays
705 if(time <= mintime) mintime=time;
710 if(ngoodtrk) stripmean /= ngoodtrk;
712 cout << " T0 offset selected for this sample : " << fT0Offset << endl;
713 cout << " N. of ESD tracks : " << ntrk << endl;
714 cout << " N. of preselected tracks : " << ngoodtrk << endl;
715 cout << " Minimum tof time in set (in ns) : " << mintime << endl;
717 AliESDtrack **gtracks=new AliESDtrack*[ngoodtrk];
719 for (Int_t jtrk=0; jtrk< ngoodtrk; jtrk++) {
720 AliESDtrack *t=tracks[jtrk];
721 Double_t tot = t->GetTOFsignalToT();
722 Double_t time=t->GetTOFsignalRaw();
723 Int_t chan = t->GetTOFCalChannel();
724 Double_t corr = fCalib->GetFullCorrection(chan,tot) - fCalib->GetCorrection(AliTOFcalibHisto::kTimeSlewingCorr,chan,0);
727 Int_t create = fCalib->GetCalibMap(AliTOFcalibHisto::kDDL,chan);
728 if(create == 63 || create == 62){
732 if((time-mintime*1.E3)<50.E3){ // For pp and per
733 gtracks[ngoodtrkt0]=t;
738 Int_t nseteq = (ngoodtrkt0-1)/nmaxtracksinset + 1;
739 Int_t nmaxtracksinsetCurrent=ngoodtrkt0/nseteq;
740 if(nmaxtracksinsetCurrent*nseteq < ngoodtrkt0) nmaxtracksinsetCurrent++;
743 Int_t nlastset = (ngoodtrkt0 % nmaxtracksinsetCurrent);
745 while(nlastset-nseteq+1 > 2 ){
746 nmaxtracksinsetCurrent++;
747 nlastset -= nseteq-1;
749 if(nmaxtracksinsetCurrent > nmaxtracksinset) nmaxtracksinsetCurrent = nmaxtracksinset;
753 cout << "less than 2 tracks, skip event " << endl;
756 fT0SigmaT0def[0]=t0def;
757 fT0SigmaT0def[1]=deltat0def;
758 fT0SigmaT0def[2]=ngoodtrkt0;
759 fT0SigmaT0def[3]=ngoodtrkt0;
763 // Decide how many tracks in set
764 Int_t ntracksinset = min(ngoodtrkt0,nmaxtracksinsetCurrent);
766 if(ngoodtrkt0>nmaxtracksinset) {nset= (Int_t)(ngoodtrkt0/ntracksinset)+1;}
768 cout << " number of sets = " << nset << endl;
770 if(strstr(option,"tim") || strstr(option,"all"))gBenchmark->Start("TOFT0v1");
772 // Loop over selected sets
775 for (Int_t i=0; i< nset; i++) {
778 Float_t Et0best=999.;
779 Float_t chisquarebest=99999.;
782 Int_t ntracksinsetmy=0;
783 AliESDtrack **tracksT0=new AliESDtrack*[ntracksinset];
784 for (Int_t itrk=0; itrk<ntracksinset; itrk++) {
785 Int_t index = itrk+i*ntracksinset;
786 if(index < ngoodtrkt0){
787 AliESDtrack *t=gtracks[index];
795 Int_t assparticle[nmaxtracksinset];
796 Float_t exptof[nmaxtracksinset][3];
797 Float_t timeofflight[nmaxtracksinset];
798 Float_t momentum[nmaxtracksinset];
799 Float_t timezero[nmaxtracksinset];
800 Float_t weightedtimezero[nmaxtracksinset];
801 Float_t beta[nmaxtracksinset];
802 Float_t texp[nmaxtracksinset];
803 Float_t dtexp[nmaxtracksinset];
804 Float_t sqMomError[nmaxtracksinset];
805 Float_t sqTrackError[nmaxtracksinset];
806 Float_t massarray[3]={0.13957,0.493677,0.9382723};
807 Float_t tracktoflen[nmaxtracksinset];
808 Float_t besttimezero[nmaxtracksinset];
809 Float_t besttexp[nmaxtracksinset];
810 Float_t besttimeofflight[nmaxtracksinset];
811 Float_t bestmomentum[nmaxtracksinset];
812 Float_t bestchisquare[nmaxtracksinset];
813 Float_t bestweightedtimezero[nmaxtracksinset];
814 Float_t bestsqTrackError[nmaxtracksinset];
815 Int_t imass[nmaxtracksinset];
817 for (Int_t j=0; j<ntracksinset; j++) {
822 weightedtimezero[j] = 0;
831 besttimeofflight[j] = 0;
833 bestchisquare[j] = 0;
834 bestweightedtimezero[j] = 0;
835 bestsqTrackError[j] = 0;
839 for (Int_t j=0; j<ntracksinsetmy; j++) {
840 AliESDtrack *t=tracksT0[j];
841 Double_t momOld=t->GetP();
842 Double_t mom=momOld-0.0036*momOld;
843 Double_t tot = t->GetTOFsignalToT();
844 Double_t time=t->GetTOFsignalRaw();
845 Int_t chan = t->GetTOFCalChannel();
846 Double_t corr = fCalib->GetFullCorrection(chan,tot) - fCalib->GetCorrection(AliTOFcalibHisto::kTimeSlewingCorr,chan,0);
849 Int_t create = fCalib->GetCalibMap(AliTOFcalibHisto::kDDL,chan);
850 if(create == 63 || create == 62){
854 time*=1.E-3; // tof given in nanoseconds
855 Double_t exptime[10]; t->GetIntegratedTimes(exptime);
856 Double_t toflen=t->GetIntegratedLength();
857 toflen=toflen/100.; // toflen given in m
859 timeofflight[j]=time+fT0Offset;
860 tracktoflen[j]=toflen+fLOffset;
861 exptof[j][0]=exptime[2]*1.E-3+fTimeCorr;// in ns
862 exptof[j][1]=exptime[3]*1.E-3+fTimeCorr;
863 exptof[j][2]=exptime[4]*1.E-3+fTimeCorr;
867 } //end for (Int_t j=0; j<ntracksinsetmy; j++) {
869 cout << "starting t0 calculation for current set" << endl;
870 for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
871 beta[itz]=momentum[itz]/sqrt(massarray[0]*massarray[0]
872 +momentum[itz]*momentum[itz]);
873 sqMomError[itz]= ((1.-beta[itz]*beta[itz])*0.01)*((1.-beta[itz]*beta[itz])*0.01)*(tracktoflen[itz]/(0.299792*beta[itz]))*(tracktoflen[itz]/(0.299792*beta[itz]));
874 sqTrackError[itz]=(timeresolutioninns*timeresolutioninns+sqMomError[itz]); //in ns
875 timezero[itz]=exptof[itz][0]-timeofflight[itz];// in ns
876 weightedtimezero[itz]=timezero[itz]/sqTrackError[itz];
877 sumAllweightspi+=1./sqTrackError[itz];
878 meantzeropi+=weightedtimezero[itz];
879 } // end loop for (Int_t itz=0; itz< ntracksinset;itz++)
882 // Then, Combinatorial Algorithm
884 if(ntracksinsetmy<2 )break;
886 for (Int_t j=0; j<ntracksinsetmy; j++) {
890 Int_t ncombinatorial = Int_t(TMath::Power(3,ntracksinsetmy));
892 // Loop on mass hypotheses
893 for (Int_t k=0; k < ncombinatorial;k++) {
894 for (Int_t j=0; j<ntracksinsetmy; j++) {
895 imass[j] = (k % Int_t(TMath::Power(3,ntracksinsetmy-j)))/Int_t(TMath::Power(3,ntracksinsetmy-j-1));
896 texp[j]=exptof[j][imass[j]];
897 dtexp[j]=GetMomError(imass[j], momentum[j], texp[j]);
899 Float_t sumAllweights=0.;
900 Float_t meantzero=0.;
901 Float_t Emeantzero=0.;
902 Double_t sumAllSquare=0.;
904 for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
908 +dtexp[itz]*dtexp[itz]*1E-6); //in ns2
910 // printf("pt=%f -- TOF res=%f -- track res=%f -- all res=%f\n",momentum[itz],timeresolutioninns,dtexp[itz],TMath::Sqrt(sqTrackError[itz]));
912 timezero[itz]=texp[itz]-timeofflight[itz];// in ns
914 weightedtimezero[itz]=timezero[itz]/sqTrackError[itz];
915 sumAllSquare += timezero[itz]*timezero[itz];
916 sumAllweights+=1./sqTrackError[itz];
917 meantzero+=weightedtimezero[itz];
919 } // end loop for (Int_t itz=0; itz<15;itz++)
921 meantzero=meantzero/sumAllweights; // it is given in [ns]
922 Emeantzero=sqrt(1./sumAllweights); // it is given in [ns]
925 for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
926 sumAllSquare+= (timezero[itz] - meantzero)*(timezero[itz] - meantzero);
928 // Emeantzero = TMath::Sqrt(sumAllSquare/ntracksinsetmy);
930 // calculate chisquare
932 Float_t chisquare=0.;
933 for (Int_t icsq=0; icsq<ntracksinsetmy;icsq++) {
934 chisquare+=(timezero[icsq]-meantzero)*(timezero[icsq]-meantzero)/sqTrackError[icsq];
936 } // end loop for (Int_t icsq=0; icsq<15;icsq++)
938 if(chisquare<=chisquarebest){
939 for(Int_t iqsq = 0; iqsq<ntracksinsetmy; iqsq++) {
941 bestsqTrackError[iqsq]=sqTrackError[iqsq];
942 besttimezero[iqsq]=timezero[iqsq];
943 bestmomentum[iqsq]=momentum[iqsq];
944 besttimeofflight[iqsq]=timeofflight[iqsq];
945 besttexp[iqsq]=texp[iqsq];
946 bestweightedtimezero[iqsq]=weightedtimezero[iqsq];
947 bestchisquare[iqsq]=(timezero[iqsq]-meantzero)*(timezero[iqsq]-meantzero)/sqTrackError[iqsq];
951 for (Int_t j=0; j<ntracksinsetmy; j++) {
952 assparticle[j]=imass[j];
953 if(imass[j] == 0) npion++;
956 chisquarebest=chisquare;
959 } // close if(dummychisquare<=chisquare)
963 Double_t chi2cut[nmaxtracksinset];
965 chi2cut[1] = 6.6; // corresponding to a C.L. of 0.01
966 for (Int_t j=2; j<ntracksinset; j++) {
967 chi2cut[j] = chi2cut[1] * TMath::Sqrt(j*1.);
970 Double_t chi2singlecut = chi2cut[ntracksinsetmy-1]/ntracksinsetmy + TMath::Abs(chisquarebest-chi2cut[ntracksinsetmy-1])/ntracksinsetmy;
972 printf("tracks removed with a chi2 > %f (chi2total = %f w.r.t. the limit of %f)\n",chi2singlecut,chisquarebest,chi2cut[ntracksinsetmy-1]);
974 Bool_t kRedoT0 = kFALSE;
975 ntracksinsetmyCut = ntracksinsetmy;
976 Bool_t usetrack[nmaxtracksinset];
977 for (Int_t icsq=0; icsq<ntracksinsetmy;icsq++) {
978 usetrack[icsq] = kTRUE;
979 if((bestchisquare[icsq] > chisquarebest*0.5 && ntracksinsetmy > 2) || (bestchisquare[icsq] > chi2singlecut)){
982 usetrack[icsq] = kFALSE;
984 } // end loop for (Int_t icsq=0; icsq<15;icsq++)
986 printf("ntrackinsetmy = %i - %i\n",ntracksinsetmy,ntracksinsetmyCut);
988 // Loop on mass hypotheses Redo
989 if(kRedoT0 && ntracksinsetmyCut > 1){
991 for (Int_t k=0; k < ncombinatorial;k++) {
992 for (Int_t j=0; j<ntracksinsetmy; j++) {
993 imass[j] = (k % Int_t(TMath::Power(3,ntracksinsetmy-j))) / Int_t(TMath::Power(3,ntracksinsetmy-j-1));
994 texp[j]=exptof[j][imass[j]];
995 dtexp[j]=GetMomError(imass[j], momentum[j], texp[j]);
998 Float_t sumAllweights=0.;
999 Float_t meantzero=0.;
1000 Float_t Emeantzero=0.;
1001 Double_t sumAllSquare=0;
1003 for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
1004 if(! usetrack[itz]) continue;
1006 (timeresolutioninns*
1008 +dtexp[itz]*dtexp[itz]*1E-6); //in ns2
1010 timezero[itz]=texp[itz]-timeofflight[itz];// in ns
1012 weightedtimezero[itz]=timezero[itz]/sqTrackError[itz];
1013 sumAllweights+=1./sqTrackError[itz];
1014 meantzero+=weightedtimezero[itz];
1015 } // end loop for (Int_t itz=0; itz<15;itz++)
1017 meantzero=meantzero/sumAllweights; // it is given in [ns]
1018 Emeantzero=sqrt(1./sumAllweights); // it is given in [ns]
1021 for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
1022 if(! usetrack[itz]) continue;
1023 sumAllSquare+= (timezero[itz] - meantzero)*(timezero[itz] - meantzero);
1025 // Emeantzero = TMath::Sqrt(sumAllSquare/ntracksinsetmyCut);
1027 // calculate chisquare
1029 Float_t chisquare=0.;
1030 for (Int_t icsq=0; icsq<ntracksinsetmy;icsq++) {
1031 if(! usetrack[icsq]) continue;
1032 chisquare+=(timezero[icsq]-meantzero)*(timezero[icsq]-meantzero)/sqTrackError[icsq];
1034 } // end loop for (Int_t icsq=0; icsq<15;icsq++)
1037 for (Int_t j=0; j<ntracksinsetmy; j++) {
1038 assparticle[j]=imass[j];
1039 if(imass[j] == 0) npion++;
1042 if(chisquare<=chisquarebest){
1043 for(Int_t iqsq = 0; iqsq<ntracksinsetmy; iqsq++) {
1044 if(! usetrack[iqsq]) continue;
1045 bestsqTrackError[iqsq]=sqTrackError[iqsq];
1046 besttimezero[iqsq]=timezero[iqsq];
1047 bestmomentum[iqsq]=momentum[iqsq];
1048 besttimeofflight[iqsq]=timeofflight[iqsq];
1049 besttexp[iqsq]=texp[iqsq];
1050 bestweightedtimezero[iqsq]=weightedtimezero[iqsq];
1051 bestchisquare[iqsq]=(timezero[iqsq]-meantzero)*(timezero[iqsq]-meantzero)/sqTrackError[iqsq];
1055 chisquarebest=chisquare;
1058 } // close if(dummychisquare<=chisquare)
1063 if(chisquarebest >= 999){
1064 printf("How is it possible (chi2 = %f)? T0best = %f\n",chisquarebest,t0best);
1066 for(Int_t icsq=0; icsq<ntracksinsetmy;icsq++){
1067 cout << "Track # " << icsq << " T0 offsets = "
1068 << besttimezero[icsq]-t0best <<
1069 " track error = " << bestsqTrackError[icsq]
1070 << " Chisquare = " << bestchisquare[icsq]
1071 << " Momentum = " << bestmomentum[icsq]
1072 << " TOF = " << besttimeofflight[icsq]
1073 << " TOF tracking = " << besttexp[icsq]
1074 << " is used = " << usetrack[icsq] << endl;
1079 Float_t confLevel=999;
1081 // Sets with decent chisquares
1083 if(chisquarebest<999.){
1084 Double_t dblechisquare=(Double_t)chisquarebest;
1085 confLevel=(Float_t)TMath::Prob(dblechisquare,ntracksinsetmyCut-1);
1086 cout << " Set Number " << nsets << endl;
1087 cout << "Best Assignment, selection " << assparticle[0] <<
1088 assparticle[1] << assparticle[2] <<
1089 assparticle[3] << assparticle[4] <<
1090 assparticle[5] << endl;
1091 cout << " Chisquare of the set "<< chisquarebest <<endl;
1092 cout << " C.L. of the set "<< confLevel <<endl;
1093 cout << " T0 for this set (in ns) " << t0best << endl;
1094 for(Int_t icsq=0; icsq<ntracksinsetmy;icsq++){
1096 if(! usetrack[icsq]) continue;
1098 cout << "Track # " << icsq << " T0 offsets = "
1099 << besttimezero[icsq]-t0best <<
1100 " track error = " << bestsqTrackError[icsq]
1101 << " Chisquare = " << bestchisquare[icsq]
1102 << " Momentum = " << bestmomentum[icsq]
1103 << " TOF = " << besttimeofflight[icsq]
1104 << " TOF tracking = " << besttexp[icsq]
1105 << " is used = " << usetrack[icsq] << endl;
1108 // Pick up only those with C.L. >1%
1109 // if(confLevel>0.01 && ngoodsetsSel<200){
1110 if(confLevel>0.01 && ngoodsetsSel<200){
1111 ChisquarebestSel[ngoodsetsSel]=chisquarebest;
1112 ConfLevelbestSel[ngoodsetsSel]=confLevel;
1113 t0bestSel[ngoodsetsSel]=t0best/Et0best/Et0best;
1114 Et0bestSel[ngoodsetsSel]=1./Et0best/Et0best;
1115 t0bestallSel += t0best/Et0best/Et0best;
1116 sumWt0bestallSel += 1./Et0best/Et0best;
1119 ngoodtrktrulyused+=ntracksinsetmyCut;
1122 printf("conflevel = %f -- ngoodsetsSel = %i -- ntrackset = %i\n",confLevel,ngoodsetsSel,ntracksinsetmy);
1128 } // end for the current set
1130 NusedTracks = ngoodtrkt0;
1131 if(strstr(option,"all")){
1132 if(sumAllweightspi>0.){
1133 meantzeropi=meantzeropi/sumAllweightspi; // it is given in [ns]
1134 Emeantzeropi=sqrt(1./sumAllweightspi); // it is given in [ns]
1137 if(sumWt0bestallSel>0){
1138 t0bestallSel = t0bestallSel/sumWt0bestallSel;
1139 Et0bestallSel = sqrt(1./sumWt0bestallSel);
1140 }// end of if(sumWt0bestallSel>0){
1142 cout << "T0 all " << t0bestallSel << " +/- " << Et0bestallSel << "Number of tracks used: "<<ngoodtrktrulyused<<endl;
1146 deltat0def=Et0bestallSel;
1147 if ((t0bestallSel==0)&&(Et0bestallSel==0)){
1148 t0def=-999; deltat0def=0.600;
1151 fT0SigmaT0def[0]=t0def;
1152 fT0SigmaT0def[1]=TMath::Sqrt(deltat0def*deltat0def*(ngoodtrktrulyused/(ngoodtrktrulyused-1)));
1153 fT0SigmaT0def[2]=ngoodtrkt0;//ngoodtrktrulyused;
1154 fT0SigmaT0def[3]=ngoodtrktrulyused;
1158 if(strstr(option,"tim") || strstr(option,"all")){
1159 gBenchmark->Stop("TOFT0v1");
1160 cout << "AliTOFT0v1:" << endl ;
1161 cout << " took " << gBenchmark->GetCpuTime("TOFT0v1") << " seconds in order to calculate T0 " << endl ;
1163 printf("T0 from TOF = %f ns\n",fT0SigmaT0def[0]);
1165 return fT0SigmaT0def;
1167 //__________________________________________________________________
1168 void AliTOFT0v1::SetTZeroFile(char * file ){
1169 cout << "Destination file : " << file << endl ;
1172 //__________________________________________________________________
1173 void AliTOFT0v1::Print(Option_t* /*option*/)const
1175 cout << "------------------- "<< GetName() << " -------------" << endl ;
1176 if(!fT0File.IsNull())
1177 cout << " Writing T0 Distribution to file " << (char*) fT0File.Data() << endl ;
1180 //__________________________________________________________________
1181 Bool_t AliTOFT0v1::operator==( AliTOFT0v1 const &tzero )const
1185 if( (fTimeResolution==tzero.fTimeResolution)&&(fLowerMomBound==tzero.fLowerMomBound)&&(fUpperMomBound==tzero.fUpperMomBound))
1192 //__________________________________________________________________
1193 Float_t AliTOFT0v1::GetMomError(Int_t index, Float_t mom, Float_t texp)
1195 static const Double_t kMasses[]={
1196 0.000511, 0.105658, 0.139570, 0.493677, 0.938272, 1.875613
1199 Double_t mass=kMasses[index+2];
1200 Double_t dpp=0.01; //mean relative pt resolution;
1201 Double_t sigma=dpp*texp*1E3/(1.+ mom*mom/(mass*mass));
1203 sigma =TMath::Sqrt(sigma*sigma);