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 2010/01/19 16:32:20 noferini 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 ESD 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,
26 // the momentum and the time of flight
27 // given by the TOF detector.
28 // Let consider now only one set of 10 tracks (the algorithm is the same for all sets).
29 // Assuming the (mass) hypothesis that each track can be AUT a pion, AUT a kaon, AUT a proton,
30 // we consider all the 3 at 10 possible cases.
31 // For each track in each (mass) configuration
32 // (a configuration can be e.g. pion/pion/kaon/proton/pion/proton/kaon/kaon/pion/pion)
33 // we calculate the time zero (we know in fact the velocity of the track after
34 // the assumption about its mass, the time of flight given by the TOF, and the
35 // corresponding path travelled till the TOF detector). Then for each mass configuration we have
36 // 10 time zero and we can calculate the ChiSquare for the current configuration using the
37 // weighted mean over all 10 time zero.
38 // We call the best assignment the mass configuration that gives the minimum value of the ChiSquare.
39 // We plot the weighted mean over all 10 time zero for the best assignment,
40 // the ChiSquare for the best assignment and the corresponding confidence level.
41 // The strong assumption is the MC selection of primary particles. It will be introduced
42 // in the future also some more realistic simulation about this point.
44 // root [0] AliTOFT0v1 * tzero = new AliTOFT0v1("galice.root")
45 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
46 // root [1] tzero->ExecuteTask()
47 // root [2] tzero->ExecuteTask("tim")
48 // // available parameters:
49 // tim - print benchmarking information
50 // all - print usefull informations about the number of misidentified tracks
51 // and a comparison about the true configuration (known from MC) and the best
53 // Different Selections for pp and Pb-Pb: Momentum Range, Max Time, # pions
54 //-- Author: F. Pierella
55 //-- Mod By Silvia Arcelli, Francesco Noferini, Barbara Guerzoni
56 //-- AliTOFT0v1 contains code speed up provided by Jens Wiechula (look-up table
58 //////////////////////////////////////////////////////////////////////////////
60 #include "AliESDtrack.h"
61 #include "AliESDEvent.h"
62 #include "AliTOFT0v1.h"
63 #include "TBenchmark.h"
65 #include "AliESDpid.h"
69 //____________________________________________________________________________
70 AliTOFT0v1::AliTOFT0v1(AliESDpid *extPID):
77 fTracks(new TObjArray(10)),
78 fGTracks(new TObjArray(10)),
79 fTracksT0(new TObjArray(10)),
83 // default constructor
85 if(AliPID::ParticleMass(0) == 0) new AliPID();
88 fPIDesd = new AliESDpid();
93 //initialise lookup table for power 3
94 // a set should only have 10 tracks a t maximum
95 // so up to 15 should be more than enough
96 for (Int_t i=0; i<15; ++i) {
97 fLookupPowerThree[i]=ToCalculatePower(3,i);
101 //____________________________________________________________________________
102 AliTOFT0v1::AliTOFT0v1(AliESDEvent* event,AliESDpid *extPID):
109 fTracks(new TObjArray(10)),
110 fGTracks(new TObjArray(10)),
111 fTracksT0(new TObjArray(10)),
117 if(AliPID::ParticleMass(0) == 0) new AliPID();
120 fPIDesd = new AliESDpid();
124 //initialise lookup table for power 3
125 for (Int_t i=0; i<15; ++i) {
126 fLookupPowerThree[i]=Int_t(TMath::Power(3,i));
129 //____________________________________________________________________________
130 AliTOFT0v1& AliTOFT0v1::operator=(const AliTOFT0v1 &tzero)
139 fLowerMomBound=tzero.fLowerMomBound;
140 fUpperMomBound=tzero.fUpperMomBound;
141 fTimeCorr=tzero.fTimeCorr;
143 fT0SigmaT0def[0]=tzero.fT0SigmaT0def[0];
144 fT0SigmaT0def[1]=tzero.fT0SigmaT0def[1];
145 fT0SigmaT0def[2]=tzero.fT0SigmaT0def[2];
146 fT0SigmaT0def[3]=tzero.fT0SigmaT0def[3];
148 fTracks=tzero.fTracks;
149 fGTracks=tzero.fGTracks;
150 fTracksT0=tzero.fTracksT0;
152 for (Int_t ii=0; ii<tzero.fTracks->GetEntries(); ii++)
153 fTracks->AddLast(tzero.fTracks->At(ii));
155 for (Int_t ii=0; ii<tzero.fGTracks->GetEntries(); ii++)
156 fGTracks->AddLast(tzero.fGTracks->At(ii));
158 for (Int_t ii=0; ii<tzero.fTracksT0->GetEntries(); ii++)
159 fTracksT0->AddLast(tzero.fTracksT0->At(ii));
161 fOptFlag=tzero.fOptFlag;
166 //____________________________________________________________________________
167 AliTOFT0v1::~AliTOFT0v1()
192 //____________________________________________________________________________
195 AliTOFT0v1::Init(AliESDEvent *event)
204 fT0SigmaT0def[1]=0.6;
209 //____________________________________________________________________________
210 Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut)
212 TBenchmark *bench=new TBenchmark();
213 bench->Start("t0computation");
215 // Caluclate the Event Time using the ESD TOF time
218 fT0SigmaT0def[1]=0.600;
222 const Int_t nmaxtracksinsetMax=10;
223 Int_t nmaxtracksinset=10;
224 // if(strstr(option,"all")){
225 // cout << "Selecting primary tracks with momentum between " << fLowerMomBound << " GeV/c and " << fUpperMomBound << " GeV/c" << endl;
226 // cout << "Memorandum: 0 means PION | 1 means KAON | 2 means PROTON" << endl;
232 Int_t ngoodsetsSel= 0;
233 Float_t t0bestSel[300];
234 Float_t eT0bestSel[300];
235 Float_t chiSquarebestSel[300];
236 Float_t confLevelbestSel[300];
237 Float_t t0bestallSel=0.;
238 Float_t eT0bestallSel=0.;
239 Float_t sumWt0bestallSel=0.;
240 Float_t eMeanTzeroPi=0.;
241 Float_t meantzeropi=0.;
242 Float_t sumAllweightspi=0.;
244 Double_t deltat0def=999;
245 Int_t ngoodtrktrulyused=0;
246 Int_t ntracksinsetmyCut = 0;
248 Int_t ntrk=fEvent->GetNumberOfTracks();
254 // First Track loop, Selection of good tracks
257 for (Int_t itrk=0; itrk<ntrk; itrk++) {
258 AliESDtrack *t=fEvent->GetTrack(itrk);
259 Double_t momOld=t->GetP();
260 Double_t mom=momOld-0.0036*momOld;
261 if ((t->GetStatus()&AliESDtrack::kTIME)==0) continue;
262 if ((t->GetStatus()&AliESDtrack::kTOFout)==0) continue;
263 Double_t time=t->GetTOFsignal();
265 time*=1.E-3; // tof given in nanoseconds
266 if (!(mom<=fUpperMomBound && mom>=fLowerMomBound))continue;
268 if (!AcceptTrack(t)) continue;
270 if(t->GetIntegratedLength() < 350)continue; //skip decays
271 if(t->GetP() > pMinCut && t->GetP() < pMaxCut) continue;
278 if(ngoodtrk > 1) meantime /= ngoodtrk;
280 if(ngoodtrk>22) nmaxtracksinset = 6;
283 for (Int_t jtrk=0; jtrk< fTracks->GetEntries(); jtrk++) {
284 AliESDtrack *t=(AliESDtrack*)fTracks->At(jtrk);
285 // Double_t time=t->GetTOFsignal();
286 // if((time-meantime*1.E3)<50.E3){ // For pp and per
287 fGTracks->AddLast(t);
294 Int_t nseteq = (ngoodtrkt0-1)/nmaxtracksinset + 1;
295 Int_t nmaxtracksinsetCurrent=ngoodtrkt0/nseteq;
296 if(nmaxtracksinsetCurrent*nseteq < ngoodtrkt0) nmaxtracksinsetCurrent++;
302 fT0SigmaT0def[0]=t0def;
303 fT0SigmaT0def[1]=deltat0def;
304 fT0SigmaT0def[2]=ngoodtrkt0;
305 fT0SigmaT0def[3]=ngoodtrkt0;
309 // Decide how many tracks in set
310 Int_t ntracksinset = std::min(ngoodtrkt0,nmaxtracksinsetCurrent);
313 if(ngoodtrkt0>nmaxtracksinsetCurrent) {nset= (Int_t)(ngoodtrkt0/ntracksinset)+1;}
315 // Loop over selected sets
318 for (Int_t i=0; i< nset; i++) {
319 // printf("Set %i of %i\n",i+1,nset);
321 Float_t eT0best=999.;
322 Float_t chisquarebest=99999.;
326 Int_t ntracksinsetmy=0;
327 for (Int_t itrk=0; itrk<ntracksinset; itrk++) {
328 Int_t index = itrk+i*ntracksinset;
329 if(index < fGTracks->GetEntries()){
330 AliESDtrack *t=(AliESDtrack*)fGTracks->At(index);
331 fTracksT0->AddLast(t);
338 Int_t assparticle[nmaxtracksinsetMax];
339 Float_t exptof[nmaxtracksinsetMax][3];
340 Float_t momErr[nmaxtracksinsetMax][3];
341 Float_t timeofflight[nmaxtracksinsetMax];
342 Float_t momentum[nmaxtracksinsetMax];
343 Float_t timezero[nmaxtracksinsetMax];
344 Float_t weightedtimezero[nmaxtracksinsetMax];
345 Float_t beta[nmaxtracksinsetMax];
346 Float_t texp[nmaxtracksinsetMax];
347 Float_t dtexp[nmaxtracksinsetMax];
348 Float_t sqMomError[nmaxtracksinsetMax];
349 Float_t sqTrackError[nmaxtracksinsetMax];
350 Float_t massarray[3]={0.13957,0.493677,0.9382723};
351 Float_t tracktoflen[nmaxtracksinsetMax];
352 Float_t besttimezero[nmaxtracksinsetMax];
353 Float_t besttexp[nmaxtracksinsetMax];
354 Float_t besttimeofflight[nmaxtracksinsetMax];
355 Float_t bestmomentum[nmaxtracksinsetMax];
356 Float_t bestchisquare[nmaxtracksinsetMax];
357 Float_t bestweightedtimezero[nmaxtracksinsetMax];
358 Float_t bestsqTrackError[nmaxtracksinsetMax];
359 Int_t imass[nmaxtracksinsetMax];
361 for (Int_t j=0; j<ntracksinset; j++) {
366 weightedtimezero[j] = 0;
375 besttimeofflight[j] = 0;
377 bestchisquare[j] = 0;
378 bestweightedtimezero[j] = 0;
379 bestsqTrackError[j] = 0;
383 for (Int_t j=0; j<fTracksT0->GetEntries(); j++) {
384 AliESDtrack *t=(AliESDtrack*)fTracksT0->At(j);
385 Double_t momOld=t->GetP();
386 Double_t mom=momOld-0.0036*momOld;
387 Double_t time=t->GetTOFsignal();
389 time*=1.E-3; // tof given in nanoseconds
390 Double_t exptime[AliPID::kSPECIESC];
391 t->GetIntegratedTimes(exptime,AliPID::kSPECIESC);
392 Double_t toflen=t->GetIntegratedLength();
393 toflen=toflen/100.; // toflen given in m
395 timeofflight[j]=time;
396 tracktoflen[j]=toflen;
397 exptof[j][0]=exptime[2]*1.E-3+fTimeCorr;// in ns
398 exptof[j][1]=exptime[3]*1.E-3+fTimeCorr;
399 exptof[j][2]=exptime[4]*1.E-3+fTimeCorr;
403 // in principle GetMomError only depends on two indices k=imass[j] and j itslef (see blow in the ncombinatorial loop)
404 // so it should be possible to make a lookup in order to speed up the code:
406 momErr[j][0]=GetMomError(0, momentum[j], exptof[j][0]);
407 momErr[j][1]=GetMomError(1, momentum[j], exptof[j][1]);
408 momErr[j][2]=GetMomError(2, momentum[j], exptof[j][2]);
410 } //end for (Int_t j=0; j<ntracksinsetmy; j++) {
412 for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
413 beta[itz]=momentum[itz]/sqrt(massarray[0]*massarray[0]
414 +momentum[itz]*momentum[itz]);
415 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]));
416 sqTrackError[itz]=sqMomError[itz]; //in ns
417 timezero[itz]=exptof[itz][0]-timeofflight[itz];// in ns
418 weightedtimezero[itz]=timezero[itz]/sqTrackError[itz];
419 sumAllweightspi+=1./sqTrackError[itz];
420 meantzeropi+=weightedtimezero[itz];
421 } // end loop for (Int_t itz=0; itz< ntracksinset;itz++)
424 // Then, Combinatorial Algorithm
426 if(ntracksinsetmy<2 )break;
428 for (Int_t j=0; j<ntracksinsetmy; j++) {
432 Int_t ncombinatorial;
433 if (fOptFlag) ncombinatorial = fLookupPowerThree[ntracksinsetmy];
434 else ncombinatorial = ToCalculatePower(3,ntracksinsetmy);
437 // Loop on mass hypotheses
438 for (Int_t k=0; k < ncombinatorial;k++) {
439 for (Int_t j=0; j<ntracksinsetmy; j++) {
440 imass[j] = (k % fLookupPowerThree[ntracksinsetmy-j])/fLookupPowerThree[ntracksinsetmy-j-1];
441 texp[j]=exptof[j][imass[j]];
442 if (fOptFlag) dtexp[j]=momErr[j][imass[j]]; // see comments above in the initialisation of momErr
443 else dtexp[j]=GetMomError(imass[j], momentum[j], texp[j]);
446 Float_t sumAllweights=0.;
447 Float_t meantzero=0.;
448 Float_t eMeanTzero=0.;
450 for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
451 sqTrackError[itz]=dtexp[itz]*dtexp[itz]*1E-6; //in ns2
453 timezero[itz]=texp[itz]-timeofflight[itz];// in ns
455 weightedtimezero[itz]=timezero[itz]/sqTrackError[itz];
456 sumAllweights+=1./sqTrackError[itz];
457 meantzero+=weightedtimezero[itz];
459 } // end loop for (Int_t itz=0; itz<15;itz++)
461 meantzero=meantzero/sumAllweights; // it is given in [ns]
462 eMeanTzero=sqrt(1./sumAllweights); // it is given in [ns]
464 // calculate chisquare
465 Float_t chisquare=0.;
466 for (Int_t icsq=0; icsq<ntracksinsetmy;icsq++) {
467 chisquare+=(timezero[icsq]-meantzero)*(timezero[icsq]-meantzero)/sqTrackError[icsq];
468 } // end loop for (Int_t icsq=0; icsq<15;icsq++)
470 if(chisquare<=chisquarebest){
471 for(Int_t iqsq = 0; iqsq<ntracksinsetmy; iqsq++) {
473 bestsqTrackError[iqsq]=sqTrackError[iqsq];
474 besttimezero[iqsq]=timezero[iqsq];
475 bestmomentum[iqsq]=momentum[iqsq];
476 besttimeofflight[iqsq]=timeofflight[iqsq];
477 besttexp[iqsq]=texp[iqsq];
478 bestweightedtimezero[iqsq]=weightedtimezero[iqsq];
479 bestchisquare[iqsq]=(timezero[iqsq]-meantzero)*(timezero[iqsq]-meantzero)/sqTrackError[iqsq];
483 for (Int_t j=0; j<ntracksinsetmy; j++) {
484 assparticle[j]=imass[j];
485 if(imass[j] == 0) npion++;
488 chisquarebest=chisquare;
491 } // close if(dummychisquare<=chisquare)
494 Double_t chi2cut[nmaxtracksinsetMax];
496 chi2cut[1] = 6.6; // corresponding to a C.L. of 0.01
497 for (Int_t j=2; j<ntracksinset; j++) {
498 chi2cut[j] = chi2cut[1] * TMath::Sqrt(j*1.);
501 Double_t chi2singlecut = chi2cut[ntracksinsetmy-1]/ntracksinsetmy + TMath::Abs(chisquarebest-chi2cut[ntracksinsetmy-1])/ntracksinsetmy;
503 // printf("tracks removed with a chi2 > %f (chi2total = %f w.r.t. the limit of %f)\n",chi2singlecut,chisquarebest,chi2cut[ntracksinsetmy-1]);
505 Bool_t kRedoT0 = kFALSE;
506 ntracksinsetmyCut = ntracksinsetmy;
507 Bool_t usetrack[nmaxtracksinsetMax];
508 for (Int_t icsq=0; icsq<ntracksinsetmy;icsq++) {
509 usetrack[icsq] = kTRUE;
510 if((bestchisquare[icsq] > chisquarebest*0.5 && ntracksinsetmy > 2) || (bestchisquare[icsq] > chi2singlecut)){
513 usetrack[icsq] = kFALSE;
514 // printf("tracks chi2 = %f\n",bestchisquare[icsq]);
516 } // end loop for (Int_t icsq=0; icsq<15;icsq++)
518 // Loop on mass hypotheses Redo
519 if(kRedoT0 && ntracksinsetmyCut > 1){
520 // printf("Redo T0\n");
521 for (Int_t k=0; k < ncombinatorial;k++) {
522 for (Int_t j=0; j<ntracksinsetmy; j++) {
523 imass[j] = (k % fLookupPowerThree[ntracksinsetmy-j]) / fLookupPowerThree[ntracksinsetmy-j-1];
524 texp[j]=exptof[j][imass[j]];
525 if (fOptFlag) dtexp[j]=momErr[j][imass[j]]; // see comments above in the initialisation of momErr
526 else dtexp[j]=GetMomError(imass[j], momentum[j], texp[j]);
529 Float_t sumAllweights=0.;
530 Float_t meantzero=0.;
531 Float_t eMeanTzero=0.;
533 for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
534 if(! usetrack[itz]) continue;
535 sqTrackError[itz]=dtexp[itz]*dtexp[itz]*1E-6; //in ns2
537 timezero[itz]=texp[itz]-timeofflight[itz];// in ns
539 weightedtimezero[itz]=timezero[itz]/sqTrackError[itz];
540 sumAllweights+=1./sqTrackError[itz];
541 meantzero+=weightedtimezero[itz];
543 } // end loop for (Int_t itz=0; itz<15;itz++)
545 meantzero=meantzero/sumAllweights; // it is given in [ns]
546 eMeanTzero=sqrt(1./sumAllweights); // it is given in [ns]
548 // calculate chisquare
550 Float_t chisquare=0.;
551 for (Int_t icsq=0; icsq<ntracksinsetmy;icsq++) {
552 if(! usetrack[icsq]) continue;
553 chisquare+=(timezero[icsq]-meantzero)*(timezero[icsq]-meantzero)/sqTrackError[icsq];
554 } // end loop for (Int_t icsq=0; icsq<15;icsq++)
557 for (Int_t j=0; j<ntracksinsetmy; j++) {
558 assparticle[j]=imass[j];
559 if(imass[j] == 0) npion++;
562 if(chisquare<=chisquarebest && npion>0){
563 for(Int_t iqsq = 0; iqsq<ntracksinsetmy; iqsq++) {
564 if(! usetrack[iqsq]) continue;
565 bestsqTrackError[iqsq]=sqTrackError[iqsq];
566 besttimezero[iqsq]=timezero[iqsq];
567 bestmomentum[iqsq]=momentum[iqsq];
568 besttimeofflight[iqsq]=timeofflight[iqsq];
569 besttexp[iqsq]=texp[iqsq];
570 bestweightedtimezero[iqsq]=weightedtimezero[iqsq];
571 bestchisquare[iqsq]=(timezero[iqsq]-meantzero)*(timezero[iqsq]-meantzero)/sqTrackError[iqsq];
575 chisquarebest=chisquare;
578 } // close if(dummychisquare<=chisquare)
584 Float_t confLevel=999;
586 // Sets with decent chisquares
587 // printf("Chi2best of the set = %f \n",chisquarebest);
589 if(chisquarebest<999.){
590 Double_t dblechisquare=(Double_t)chisquarebest;
591 confLevel=(Float_t)TMath::Prob(dblechisquare,ntracksinsetmyCut-1);
593 Int_t ntrackincurrentsel=0;
594 for(Int_t icsq=0; icsq<ntracksinsetmy;icsq++){
596 if(! usetrack[icsq]) continue;
598 ntrackincurrentsel++;
601 // printf("%i) CL(Chi2) = %f < 0.01\n",ngoodsetsSel,confLevel);
603 // Pick up only those with C.L. >1%
604 if(confLevel>0.01 && ngoodsetsSel<200){
605 chiSquarebestSel[ngoodsetsSel]=chisquarebest;
606 confLevelbestSel[ngoodsetsSel]=confLevel;
607 t0bestSel[ngoodsetsSel]=t0best/eT0best/eT0best;
608 eT0bestSel[ngoodsetsSel]=1./eT0best/eT0best;
609 t0bestallSel += t0best/eT0best/eT0best;
610 sumWt0bestallSel += 1./eT0best/eT0best;
612 ngoodtrktrulyused+=ntracksinsetmyCut;
613 // printf("T0best = %f +/- %f (%i-%i) -- conflevel = %f\n",t0best,eT0best,ntrackincurrentsel,npionbest,confLevel);
616 // printf("conflevel = %f -- ngoodsetsSel = %i -- ntrackset = %i\n",confLevel,ngoodsetsSel,ntracksinsetmy);
622 } // end for the current set
624 //Redo the computation of the best in order to esclude very bad samples
625 if(ngoodsetsSel > 1){
626 Double_t t0BestStep1 = t0bestallSel/sumWt0bestallSel;
627 Int_t nsamples=ngoodsetsSel;
631 for (Int_t itz=0; itz<nsamples;itz++) {
632 if(TMath::Abs(t0bestSel[itz]/eT0bestSel[itz]-t0BestStep1)<1.0){
633 t0bestallSel += t0bestSel[itz];
634 sumWt0bestallSel += eT0bestSel[itz];
636 // printf("not rejected %f +/- %f\n",t0bestSel[itz]/eT0bestSel[itz],1./TMath::Sqrt(eT0bestSel[itz]));
639 // printf("rejected %f +/- %f\n",t0bestSel[itz]/eT0bestSel[itz],1./TMath::Sqrt(eT0bestSel[itz]));
643 if(ngoodsetsSel < 1){
644 sumWt0bestallSel = 0.0;
646 //--------------------------------End recomputation
648 nUsedTracks = ngoodtrkt0;
649 if(strstr(option,"all")){
650 if(sumAllweightspi>0.){
651 meantzeropi=meantzeropi/sumAllweightspi; // it is given in [ns]
652 eMeanTzeroPi=sqrt(1./sumAllweightspi); // it is given in [ns]
655 // printf("t0bestallSel = %f -- eT0bestallSel = %f\n",t0bestallSel,sumWt0bestallSel);
657 if(sumWt0bestallSel>0){
658 t0bestallSel = t0bestallSel/sumWt0bestallSel;
659 eT0bestallSel = sqrt(1./sumWt0bestallSel);
660 // printf("Final) t0bestallSel = %f -- eT0bestallSel = %f\n",t0bestallSel,eT0bestallSel);
661 }// end of if(sumWt0bestallSel>0){
666 deltat0def=eT0bestallSel;
668 fT0SigmaT0def[0]=t0def;
669 fT0SigmaT0def[1]=TMath::Sqrt(deltat0def*deltat0def);//*ngoodtrktrulyused/(ngoodtrktrulyused-1));
670 fT0SigmaT0def[2]=ngoodtrkt0;
671 fT0SigmaT0def[3]=ngoodtrktrulyused;
677 if(fT0SigmaT0def[1] < 0.00001) fT0SigmaT0def[1] = 0.6;
679 bench->Stop("t0computation");
681 fT0SigmaT0def[4]=bench->GetRealTime("t0computation");
682 fT0SigmaT0def[5]=bench->GetCpuTime("t0computation");
684 // bench->Print("t0computation");
685 // printf("(%4.1f < p < %4.1f GeV/c) T0-TOF =%9.1f +/- %5.1f ps (n_track = %i)\n\n",pMinCut,pMaxCut,-fT0SigmaT0def[0]*1000,fT0SigmaT0def[1]*1000,Int_t(fT0SigmaT0def[3]));
690 return fT0SigmaT0def;
692 //__________________________________________________________________
693 Float_t AliTOFT0v1::GetMomError(Int_t index, Float_t mom, Float_t texp) const
695 // Take the error extimate for the TOF time in the track reconstruction
697 static const Double_t kMasses[]={
698 0.000511, 0.105658, 0.139570, 0.493677, 0.938272, 1.875613
701 Double_t mass=kMasses[index+2];
703 Float_t sigma = fPIDesd->GetTOFResponse().GetExpectedSigma(mom,texp,mass);
708 //__________________________________________________________________
709 Bool_t AliTOFT0v1::AcceptTrack(AliESDtrack *track)
713 if (!(track->GetStatus() & AliESDtrack::kTPCrefit)) return kFALSE;
714 /* do not accept kink daughters */
715 if (track->GetKinkIndex(0)>0) return kFALSE;
717 if (track->GetTPCclusters(0) < 50) return kFALSE;
719 if (track->GetTPCchi2()/Float_t(track->GetTPCclusters(0)) > 3.5) return kFALSE;
720 /* sigma to vertex */
721 if (GetSigmaToVertex(track) > 4.) return kFALSE;
728 //____________________________________________________________________
729 Float_t AliTOFT0v1::GetSigmaToVertex(AliESDtrack* esdTrack) const
731 // Calculates the number of sigma to the vertex.
736 esdTrack->GetImpactParameters(b,bCov);
738 if (bCov[0]<=0 || bCov[2]<=0) {
739 bCov[0]=0; bCov[2]=0;
741 bRes[0] = TMath::Sqrt(bCov[0]);
742 bRes[1] = TMath::Sqrt(bCov[2]);
744 // -----------------------------------
745 // How to get to a n-sigma cut?
747 // The accumulated statistics from 0 to d is
749 // -> Erf(d/Sqrt(2)) for a 1-dim gauss (d = n_sigma)
750 // -> 1 - Exp(-d**2) for a 2-dim gauss (d*d = dx*dx + dy*dy != n_sigma)
752 // It means that for a 2-dim gauss: n_sigma(d) = Sqrt(2)*ErfInv(1 - Exp((-d**2)/2)
753 // Can this be expressed in a different way?
755 if (bRes[0] == 0 || bRes[1] ==0)
758 //Float_t d = TMath::Sqrt(TMath::Power(b[0]/bRes[0],2) + TMath::Power(b[1]/bRes[1],2));
759 Float_t d = TMath::Sqrt(ToCalculatePower(b[0]/bRes[0],2) + ToCalculatePower(b[1]/bRes[1],2));
761 // work around precision problem
762 // if d is too big, TMath::Exp(...) gets 0, and TMath::ErfInverse(1) that should be infinite, gets 0 :(
763 // 1e-15 corresponds to nsigma ~ 7.7
764 if (TMath::Exp(-d * d / 2) < 1e-15)
767 Float_t nSigma = TMath::ErfInverse(1 - TMath::Exp(-d * d / 2)) * TMath::Sqrt(2);
770 //____________________________________________________________________
772 Bool_t AliTOFT0v1::CheckTPCMatching(AliESDtrack *track,Int_t imass) const{
773 Bool_t status = kFALSE;
775 Double_t exptimes[AliPID::kSPECIESC];
776 track->GetIntegratedTimes(exptimes,AliPID::kSPECIESC);
778 Float_t dedx = track->GetTPCsignal();
781 track->GetInnerPxPyPz(ptpc);
782 Float_t momtpc=TMath::Sqrt(ptpc[0]*ptpc[0] + ptpc[1]*ptpc[1] + ptpc[2]*ptpc[2]);
784 if(imass > 2 || imass < 0) return status;
787 AliPID::EParticleType type=AliPID::EParticleType(i);
789 Float_t dedxExp = fPIDesd->GetTPCResponse().GetExpectedSignal(momtpc,type);
790 Float_t resolutionTPC = fPIDesd->GetTPCResponse().GetExpectedSigma(momtpc,track->GetTPCsignalN(),type);
792 if(TMath::Abs(dedx - dedxExp) < 5 * resolutionTPC){
799 //____________________________________________________________________
800 Float_t AliTOFT0v1::ToCalculatePower(Float_t base, Int_t exponent) const
803 // Returns base^exponent
808 for (Int_t ii=exponent; ii>0; ii--)
814 //____________________________________________________________________
815 Int_t AliTOFT0v1::ToCalculatePower(Int_t base, Int_t exponent) const
818 // Returns base^exponent
823 for (Int_t ii=exponent; ii>0; ii--)