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 **************************************************************************/
18 Revision 1.9 2006/04/20 22:30:50 hristov
19 Coding conventions (Annalisa)
21 Revision 1.8 2006/04/16 22:29:05 hristov
22 Coding conventions (Annalisa)
24 Revision 1.7 2006/04/16 20:12:46 hristov
25 Removing memory leak in case of cached CDB entries
27 Revision 1.6 2006/04/11 15:28:32 hristov
28 Checks on cache status before deleting calibration objects (A.Colla)
30 Revision 1.5 2006/04/05 08:35:38 hristov
31 Coding conventions (S.Arcelli, C.Zampolli)
33 Revision 1.4 2006/03/31 11:26:46 arcelli
34 changing CDB Ids according to standard convention
36 Revision 1.3 2006/03/28 14:57:02 arcelli
37 updates to handle new V5 geometry & some re-arrangements
39 Revision 1.2 2006/02/13 17:22:26 arcelli
42 Revision 1.1 2006/02/13 16:10:48 arcelli
43 Add classes for TOF Calibration (C.Zampolli)
45 author: Chiara Zampolli, zampolli@bo.infn.it
48 ///////////////////////////////////////////////////////////////////////////////
50 // class for TOF calibration //
52 ///////////////////////////////////////////////////////////////////////////////
62 #include "AliCDBEntry.h"
64 #include "AliCDBManager.h"
65 #include "AliCDBMetaData.h"
66 #include "AliESDtrack.h"
70 #include "AliTOFCal.h"
71 #include "AliTOFcalibESD.h"
72 #include "AliTOFcalib.h"
73 #include "AliTOFChannel.h"
74 #include "AliTOFGeometryV5.h"
75 #include "AliTOFGeometry.h"
78 extern TStyle *gStyle;
82 const Int_t AliTOFcalib::fgkchannel = 5000;
83 //_______________________________________________________________________
84 AliTOFcalib::AliTOFcalib():
85 TTask("AliTOFcalib",""),
102 //TOF Calibration Class ctor
106 AliTOFGeometry *geom=new AliTOFGeometryV5();
107 AliInfo("V5 TOF Geometry is taken as the default");
108 fNSector = geom->NSectors();
109 fNPlate = geom->NPlates();
110 fNStripA = geom->NStripA();
111 fNStripB = geom->NStripB();
112 fNStripC = geom->NStripC();
113 fNpadZ = geom->NpadZ();
114 fNpadX = geom->NpadX();
115 fNChannels = fNSector*(2*(fNStripC+fNStripB)+fNStripA)*fNpadZ*fNpadX; //generalized version
121 //_______________________________________________________________________
122 AliTOFcalib::AliTOFcalib(AliTOFGeometry *geom):
123 TTask("AliTOFcalib",""),
140 //TOF Calibration Class ctor, taking the TOF geometry as input
144 fNSector = geom->NSectors();
145 fNPlate = geom->NPlates();
146 fNStripA = geom->NStripA();
147 fNStripB = geom->NStripB();
148 fNStripC = geom->NStripC();
149 fNpadZ = geom->NpadZ();
150 fNpadX = geom->NpadX();
151 fNChannels = fNSector*(2*(fNStripC+fNStripB)+fNStripA)*fNpadZ*fNpadX; //generalized version
156 //____________________________________________________________________________
158 AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib):
159 TTask("AliTOFcalib",""),
176 //TOF Calibration Class copy ctor
177 fNSector = calib.fNSector;
178 fNPlate = calib.fNPlate;
179 fNStripA = calib.fNStripA;
180 fNStripB = calib.fNStripB;
181 fNStripC = calib.fNStripC;
182 fNpadZ = calib.fNpadZ;
183 fNpadX = calib.fNpadX;
184 fNChannels = calib.fNChannels;
185 fArrayToT = calib.fArrayToT;
186 fArrayTime = calib.fArrayTime;
187 fTOFCal=calib.fTOFCal;
188 fTOFSimCal = calib.fTOFSimCal;
189 fTOFSimToT=calib.fTOFSimToT;
192 //____________________________________________________________________________
194 AliTOFcalib& AliTOFcalib::operator=(const AliTOFcalib &calib)
196 //TOF Calibration Class assignment operator
197 this->fNSector = calib.fNSector;
198 this->fNPlate = calib.fNPlate;
199 this->fNStripA = calib.fNStripA;
200 this->fNStripB = calib.fNStripB;
201 this->fNStripC = calib.fNStripC;
202 this->fNpadZ = calib.fNpadZ;
203 this->fNpadX = calib.fNpadX;
204 this->fNChannels = calib.fNChannels;
205 this->fArrayToT = calib.fArrayToT;
206 this->fArrayTime = calib.fArrayTime;
207 this->fTOFCal=calib.fTOFCal;
208 this->fTOFSimCal = calib.fTOFSimCal;
209 this->fTOFSimToT=calib.fTOFSimToT;
213 //____________________________________________________________________________
215 AliTOFcalib::~AliTOFcalib()
217 //TOF Calibration Class dtor
221 if(!(AliCDBManager::Instance()->GetCacheFlag())){ // CDB objects must NOT be deleted if cache is active!
228 //__________________________________________________________________________
230 TF1* AliTOFcalib::SetFitFunctions(TH1F *histo)
232 //Define Fit Functions for Slewing Correction
234 const Int_t knbins = histo->GetNbinsX();
235 Float_t delta = histo->GetBinWidth(1); //all the bins have the same width
236 Double_t max = histo->GetBinLowEdge(knbins)+delta;
238 fpol[0]=new TF1("poly3","pol3",5,max);
239 fpol[1]=new TF1("poly4","pol4",5,max);
240 fpol[2]=new TF1("poly5","pol5",5,max);
242 Double_t chi[3]={1E6,1E6,1E6};
243 Int_t ndf[3]={-1,-1,-1};
244 Double_t nchi[3]={1E6,1E6,1E6};
245 Double_t bestchi=1E6;
248 Int_t numberOfpar =0;
249 for (Int_t j=0; j<knbins; j++){
250 if (histo->GetBinContent(j)!=0) {
256 AliError(" Too few points in the histo. No fit performed.");
259 else if (nonzero<=5) {
261 AliInfo(" Only 3rd order polynomial fit possible.");
263 else if (nonzero<=6) {
265 AliInfo(" Only 3rd and 4th order polynomial fit possible.");
269 AliInfo(" All 3rd, 4th and 5th order polynomial fit possible.");
271 for (Int_t ifun=norderfit-3;ifun<norderfit-2;ifun++){
272 sprintf(npoly,"poly%i",ifun+3);
273 histo->Fit(npoly, "ERN", " ", 5.,14.);
274 chi[ifun] = fpol[ifun]->GetChisquare();
275 ndf[ifun] = fpol[ifun]->GetNDF();
276 nchi[ifun] = (Double_t)chi[ifun]/ndf[ifun];
277 if (nchi[ifun]<bestchi) {
280 numberOfpar = fGold->GetNpar();
283 fGold=fpol[2]; //Gold fit function set to pol5 in any case
284 histo->Fit(fGold,"ER " ," ",5.,15.);
287 //____________________________________________________________________________
289 void AliTOFcalib::SelectESD(AliESD *event)
291 //track selection for Calibration
292 Float_t lowerMomBound=0.8; // [GeV/c] default value Pb-Pb
293 Float_t upperMomBound=1.8 ; // [GeV/c] default value Pb-Pb
295 Int_t ngoodtrkfinalToT = 0;
296 ntrk=event->GetNumberOfTracks();
297 fESDsel = new TObjArray(ntrk);
299 TObjArray uCdatatemp(ntrk);
301 Int_t ngoodtrkfinal = 0;
302 Float_t mintime =1E6;
303 for (Int_t itrk=0; itrk<ntrk; itrk++) {
304 AliESDtrack *t=event->GetTrack(itrk);
305 //track selection: reconstrution to TOF:
306 if ((t->GetStatus()&AliESDtrack::kTOFout)==0) {
309 //IsStartedTimeIntegral
310 if ((t->GetStatus()&AliESDtrack::kTIME)==0) {
313 Double_t time=t->GetTOFsignal();
314 time*=1.E-3; // tof given in nanoseconds
315 if(time <= mintime)mintime=time;
316 Double_t mom=t->GetP();
317 if (!(mom<=upperMomBound && mom>=lowerMomBound))continue;
318 UInt_t assignedTOFcluster=t->GetTOFcluster();//index of the assigned TOF cluster, >0 ?
319 if(assignedTOFcluster==0){ // not matched
322 AliTOFcalibESD *unc = new AliTOFcalibESD;
323 unc->CopyFromAliESD(t);
325 unc->GetExternalCovariance(c1);
329 for (Int_t i = 0; i < ngoodtrk ; i ++){
330 AliTOFcalibESD *unc = (AliTOFcalibESD*)uCdatatemp.At(i);
331 if((unc->GetTOFsignal()-mintime*1.E3)<5.E3){
339 //_____________________________________________________________________________
341 void AliTOFcalib::CombESDId()
343 //track PID for calibration
346 Int_t ntracksinset=6;
347 Float_t exptof[6][3];
348 Float_t momentum[6]={0.,0.,0.,0.,0.,0.};
349 Int_t assparticle[6]={3,3,3,3,3,3};
350 Float_t massarray[3]={0.13957,0.493677,0.9382723};
351 Float_t timeofflight[6]={0.,0.,0.,0.,0.,0.};
352 Float_t beta[6]={0.,0.,0.,0.,0.,0.};
353 Float_t texp[6]={0.,0.,0.,0.,0.,0.};
354 Float_t sqMomError[6]={0.,0.,0.,0.,0.,0.};
355 Float_t sqTrackError[6]={0.,0.,0.,0.,0.,0.};
356 Float_t tracktoflen[6]={0.,0.,0.,0.,0.,0.};
357 Float_t timeResolution = 0.90e-10; // 90 ps by default
358 Float_t timeresolutioninns=timeResolution*(1.e+9); // convert in [ns]
359 Float_t timezero[6]={0.,0.,0.,0.,0.,0.};
360 Float_t weightedtimezero[6]={0.,0.,0.,0.,0.,0.};
361 Float_t besttimezero[6]={0.,0.,0.,0.,0.,0.};
362 Float_t bestchisquare[6]={0.,0.,0.,0.,0.,0.};
363 Float_t bestweightedtimezero[6]={0.,0.,0.,0.,0.,0.};
364 Float_t bestsqTrackError[6]={0.,0.,0.,0.,0.,0.};
366 Int_t nelements = fESDsel->GetEntries();
367 Int_t nset= (Int_t)(nelements/ntracksinset);
368 for (Int_t i=0; i< nset; i++) {
370 AliTOFcalibESD **unc=new AliTOFcalibESD*[ntracksinset];
371 for (Int_t itrk=0; itrk<ntracksinset; itrk++) {
372 Int_t index = itrk+i*ntracksinset;
373 AliTOFcalibESD *element=(AliTOFcalibESD*)fESDsel->At(index);
377 for (Int_t j=0; j<ntracksinset; j++) {
378 AliTOFcalibESD *element=unc[j];
379 Double_t mom=element->GetP();
380 Double_t time=element->GetTOFsignal()*1.E-3; // in ns
381 Double_t exptime[10];
382 element->GetIntegratedTimes(exptime);
383 Double_t toflen=element->GetIntegratedLength()/100.; // in m
384 timeofflight[j]=time+t0offset;
385 tracktoflen[j]=toflen+loffset;
386 exptof[j][0]=exptime[2]*1.E-3+0.005;
387 exptof[j][1]=exptime[3]*1.E-3+0.005;
388 exptof[j][2]=exptime[4]*1.E-3+0.005;
392 Float_t et0best=999.;
393 Float_t chisquarebest=999.;
394 for (Int_t i1=0; i1<3;i1++) {
395 beta[0]=momentum[0]/sqrt(massarray[i1]*massarray[i1]+momentum[0]*momentum[0]);
396 texp[0]=exptof[0][i1];
397 for (Int_t i2=0; i2<3;i2++) {
398 beta[1]=momentum[1]/sqrt(massarray[i2]*massarray[i2]+momentum[1]*momentum[1]);
399 texp[1]=exptof[1][i2];
400 for (Int_t i3=0; i3<3;i3++) {
401 beta[2]=momentum[2]/sqrt(massarray[i3]*massarray[i3]+momentum[2]*momentum[2]);
402 texp[2]=exptof[2][i3];
403 for (Int_t i4=0; i4<3;i4++) {
404 beta[3]=momentum[3]/sqrt(massarray[i4]*massarray[i4]+momentum[3]*momentum[3]);
405 texp[3]=exptof[3][i4];
407 for (Int_t i5=0; i5<3;i5++) {
408 beta[4]=momentum[4]/sqrt(massarray[i5]*massarray[i5]+momentum[4]*momentum[4]);
409 texp[4]=exptof[4][i5];
410 for (Int_t i6=0; i6<3;i6++) {
411 beta[5]=momentum[5]/sqrt(massarray[i6]*massarray[i6]+momentum[5]*momentum[5]);
412 texp[5]=exptof[5][i6];
414 Float_t sumAllweights=0.;
415 Float_t meantzero=0.;
416 Float_t emeantzero=0.;
418 for (Int_t itz=0; itz<ntracksinset;itz++) {
420 ((1.-beta[itz]*beta[itz])*0.025)*
421 ((1.-beta[itz]*beta[itz])*0.025)*
423 (0.299792*beta[itz]))*
425 (0.299792*beta[itz]));
431 timezero[itz]=texp[itz]-timeofflight[itz];
432 weightedtimezero[itz]=timezero[itz]/sqTrackError[itz];
433 sumAllweights+=1./sqTrackError[itz];
434 meantzero+=weightedtimezero[itz];
436 } // end loop for (Int_t itz=0; itz<15;itz++)
438 meantzero=meantzero/sumAllweights; // it is given in [ns]
439 emeantzero=sqrt(1./sumAllweights); // it is given in [ns]
441 // calculate chisquare
443 Float_t chisquare=0.;
444 for (Int_t icsq=0; icsq<ntracksinset;icsq++) {
445 chisquare+=(timezero[icsq]-meantzero)*(timezero[icsq]-meantzero)/sqTrackError[icsq];
446 } // end loop for (Int_t icsq=0; icsq<15;icsq++)
447 // cout << " chisquare " << chisquare << endl;
457 if(chisquare<=chisquarebest && ((Float_t) npion/ ((Float_t) ntracksinset)>0.3)){
458 // if(chisquare<=chisquarebest){
460 for(Int_t iqsq = 0; iqsq<ntracksinset; iqsq++) {
461 bestsqTrackError[iqsq]=sqTrackError[iqsq];
462 besttimezero[iqsq]=timezero[iqsq];
463 bestweightedtimezero[iqsq]=weightedtimezero[iqsq];
464 bestchisquare[iqsq]=(timezero[iqsq]-meantzero)*(timezero[iqsq]-meantzero)/sqTrackError[iqsq];
474 chisquarebest=chisquare;
477 } // close if(dummychisquare<=chisquare)
486 Float_t confLevel=999;
487 if(chisquarebest<999.){
488 Double_t dblechisquare=(Double_t)chisquarebest;
489 confLevel=(Float_t)TMath::Prob(dblechisquare,ntracksinset-1);
491 // assume they are all pions for fake sets
492 if(confLevel<0.01 || confLevel==999. ){
493 for (Int_t itrk=0; itrk<ntracksinset; itrk++)assparticle[itrk]=0;
495 for (Int_t itrk=0; itrk<ntracksinset; itrk++) {
496 Int_t index = itrk+i*ntracksinset;
497 AliTOFcalibESD *element=(AliTOFcalibESD*)fESDsel->At(index);
498 element->SetCombID(assparticle[itrk]);
503 //_____________________________________________________________________________
505 void AliTOFcalib::CalibrateESD(){
506 //Calibrate selected ESD times
507 Int_t nelements = fESDsel->GetEntries();
508 Int_t *number=new Int_t[fNChannels];
509 fArrayToT = new AliTOFArray(fNChannels);
510 fArrayTime = new AliTOFArray(fNChannels);
511 for (Int_t i=0; i<fNChannels; i++){
513 fArrayToT->AddArray(i, new TArrayF(fgkchannel));
514 TArrayF * parrToT = fArrayToT->GetArray(i);
515 TArrayF & refaToT = * parrToT;
516 fArrayTime->AddArray(i, new TArrayF(fgkchannel));
517 TArrayF * parrTime = fArrayToT->GetArray(i);
518 TArrayF & refaTime = * parrTime;
519 for (Int_t j = 0;j<AliTOFcalib::fgkchannel;j++){
520 refaToT[j]=0.; //ToT[i][j]=j;
521 refaTime[j]=0.; //Time[i][j]=j;
525 for (Int_t i=0; i< nelements; i++) {
526 AliTOFcalibESD *element=(AliTOFcalibESD*)fESDsel->At(i);
527 Int_t ipid = element->GetCombID();
528 Double_t etime = 0; //expected time
529 Double_t expTime[10];
530 element->GetIntegratedTimes(expTime);
531 if (ipid == 0) etime = expTime[2]*1E-3; //ns
532 else if (ipid == 1) etime = expTime[3]*1E-3; //ns
533 else if (ipid == 2) etime = expTime[4]*1E-3; //ns
534 else AliError("No pid from combinatorial algo for this track");
535 Double_t mtime = (Double_t)element->GetTOFsignal()*1E-3; //measured time
536 Double_t mToT = (Double_t) element->GetToT(); //measured ToT, ns
537 //select the correspondent channel with its simulated ToT spectrum
538 //summing up everything, index = 0 for all channels:
539 Int_t index = element->GetTOFCalChannel();
540 Int_t index2 = number[index];
541 TArrayF * parrToT = fArrayToT->GetArray(index);
542 TArrayF & refaToT = * parrToT;
543 refaToT[index2] = (Float_t)mToT;
544 TArrayF * parrTime = fArrayTime->GetArray(index);
545 TArrayF & refaTime = * parrTime;
546 refaTime[index2] = (Float_t)(mtime-etime);
550 for (Int_t i=0;i<1;i++){
551 TH1F * hProf = Profile(i);
552 TF1* fGold = SetFitFunctions(hProf);
553 Int_t nfpar = fGold->GetNpar();
555 for(Int_t kk=0;kk<6;kk++){
558 for (Int_t kk = 0; kk< nfpar; kk++){
559 par[kk]=fGold->GetParameter(kk);
562 AliTOFGeometry *geom=new AliTOFGeometryV5();
563 fTOFCal = new AliTOFCal(geom);
564 fTOFCal->CreateArray();
567 AliTOFChannel * calChannel = fTOFCal->GetChannel(i);
568 calChannel->SetSlewPar(par);
573 //___________________________________________________________________________
575 TH1F* AliTOFcalib::Profile(Int_t ich)
577 //Prepare histograms for Slewing Correction
578 const Int_t knbinToT = 650;
579 Int_t nbinTime = 400;
580 Float_t minTime = -10.5; //ns
581 Float_t maxTime = 10.5; //ns
582 Float_t minToT = 7.5; //ns
583 Float_t maxToT = 40.; //ns
584 Float_t deltaToT = (maxToT-minToT)/knbinToT;
585 Double_t mTime[knbinToT+1],mToT[knbinToT+1],meanTime[knbinToT+1], meanTime2[knbinToT+1],vToT[knbinToT+1], vToT2[knbinToT+1],meanToT[knbinToT+1],meanToT2[knbinToT+1],vTime[knbinToT+1],vTime2[knbinToT+1],xlow[knbinToT+1],sigmaTime[knbinToT+1];
586 Int_t n[knbinToT+1], nentrx[knbinToT+1];
587 Double_t sigmaToT[knbinToT+1];
588 for (Int_t i = 0; i < knbinToT+1 ; i++){
606 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
607 TArrayF * parrToT = fArrayToT->GetArray(ich);
608 TArrayF & refaToT = * parrToT;
609 TArrayF * parrTime = fArrayTime->GetArray(ich);
610 TArrayF & refaTime = * parrTime;
611 for (Int_t j = 0; j < AliTOFcalib::fgkchannel; j++){
612 if (refaToT[j] == 0) continue;
613 Int_t nx = (Int_t)((refaToT[j]-minToT)/deltaToT)+1;
614 if ((refaToT[j] != 0) && (refaTime[j] != 0)){
615 vTime[nx]+=refaTime[j];
616 vTime2[nx]+=(refaTime[j])*(refaTime[j]);
617 vToT[nx]+=refaToT[j];
618 vToT2[nx]+=refaToT[j]*refaToT[j];
620 hSlewing->Fill(refaToT[j],refaTime[j]);
623 Int_t nbinsToT=hSlewing->GetNbinsX();
624 if (nbinsToT != knbinToT) {
625 AliError("Profile :: incompatible numbers of bins");
630 TH1F *histo = new TH1F("histo", "1D Time vs ToT", nbinsToT, minToT, maxToT);
631 for (Int_t i=1;i<=nbinsToT;i++){
633 n[usefulBins]+=nentrx[i];
634 if (n[usefulBins]==0 && i == nbinsToT) {
637 meanTime[usefulBins]+=vTime[i];
638 meanTime2[usefulBins]+=vTime2[i];
639 meanToT[usefulBins]+=vToT[i];
640 meanToT2[usefulBins]+=vToT2[i];
641 if (n[usefulBins]<20 && i!=nbinsToT) continue;
642 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
643 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
644 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
645 *(meanTime2[usefulBins]-meanTime[usefulBins]
646 *meanTime[usefulBins]/n[usefulBins]));
647 if ((1./n[usefulBins]/n[usefulBins]
648 *(meanToT2[usefulBins]-meanToT[usefulBins]
649 *meanToT[usefulBins]/n[usefulBins]))< 0) {
650 AliError(" too small radical" );
651 sigmaToT[usefulBins]=0;
654 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
655 *(meanToT2[usefulBins]-meanToT[usefulBins]
656 *meanToT[usefulBins]/n[usefulBins]));
661 for (Int_t i=0;i<usefulBins;i++){
662 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
663 histo->Fill(mToT[i],mTime[i]);
664 histo->SetBinError(binN,sigmaTime[i]);
668 //_____________________________________________________________________________
670 void AliTOFcalib::CorrectESDTime()
672 //Calculate the corrected TOF time
673 Int_t nelements = fESDsel->GetEntries();
674 for (Int_t i=0; i< nelements; i++) {
675 AliTOFcalibESD *element=(AliTOFcalibESD*)fESDsel->At(i);
676 Int_t index = element->GetTOFCalChannel();
677 Float_t tToT = element->GetToT();
678 //select the correspondent channel with its simulated ToT spectrum
679 //summing up everything, index = 0 for all channels:
680 Int_t ipid = element->GetCombID();
681 Double_t etime = 0; //expected time
682 Double_t expTime[10];
683 element->GetIntegratedTimes(expTime);
684 if (ipid == 0) etime = expTime[2]*1E-3; //ns
685 else if (ipid == 1) etime = expTime[3]*1E-3; //ns
686 else if (ipid == 2) etime = expTime[4]*1E-3; //ns
689 AliTOFGeometry *geom=new AliTOFGeometryV5();
690 fTOFCal = new AliTOFCal(geom);
691 fTOFCal->CreateArray();
694 AliTOFChannel * calChannel = fTOFCal->GetChannel(index);
695 for (Int_t j = 0; j<6; j++){
696 par[j]=calChannel->GetSlewPar(j);
699 timeCorr= par[0]+par[1]*tToT+par[2]*tToT*tToT+par[3]*tToT*tToT*tToT+par[4]*tToT*tToT*tToT*tToT+par[5]*tToT*tToT*tToT*tToT*tToT;
702 //_____________________________________________________________________________
704 void AliTOFcalib::CorrectESDTime(AliESD *event){
705 //Calculate the corrected TOF time
708 ntrk=event->GetNumberOfTracks();
709 for (Int_t itrk=0; itrk<ntrk; itrk++) {
710 AliESDtrack *t=event->GetTrack(itrk);
711 if ((t->GetStatus()&AliESDtrack::kTOFout)==0) {
714 //IsStartedTimeIntegral
715 if ((t->GetStatus()&AliESDtrack::kTIME)==0) {
718 UInt_t assignedTOFcluster=t->GetTOFcluster();//index of the assigned TOF cluster, >0 ?
719 if(assignedTOFcluster==0){ // not matched
722 Int_t index = t->GetTOFCalChannel();
724 AliTOFGeometry *geom=new AliTOFGeometryV5();
725 fTOFCal = new AliTOFCal(geom);
726 fTOFCal->CreateArray();
729 AliTOFChannel * calChannel = fTOFCal->GetChannel(index);
731 for (Int_t j = 0; j<6; j++){
732 par[j]=calChannel->GetSlewPar(j);
734 Float_t tToT = t->GetTOFsignalToT();
736 timeCorr=par[0]+par[1]*tToT+par[2]*tToT*tToT+par[3]*tToT*tToT*tToT+par[4]*tToT*tToT*tToT*tToT+par[5]*tToT*tToT*tToT*tToT*tToT;
739 //_____________________________________________________________________________
741 void AliTOFcalib::WriteParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
743 //Write calibration parameters to the CDB
744 AliCDBManager *man = AliCDBManager::Instance();
745 if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
746 Char_t *sel1 = "Par" ;
748 sprintf(out,"%s/%s",sel,sel1);
749 AliCDBId id(out,minrun,maxrun);
750 AliCDBMetaData *md = new AliCDBMetaData();
751 md->SetResponsible("Chiara Zampolli");
753 AliTOFGeometry *geom=new AliTOFGeometryV5();
754 fTOFCal = new AliTOFCal(geom);
755 fTOFCal->CreateArray();
758 man->Put(fTOFCal,id,md);
761 //_____________________________________________________________________________
763 void AliTOFcalib::WriteParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFCal *cal){
764 //Write calibration parameters to the CDB
765 AliCDBManager *man = AliCDBManager::Instance();
766 if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
767 Char_t *sel1 = "Par" ;
769 sprintf(out,"%s/%s",sel,sel1);
770 AliCDBId id(out,minrun,maxrun);
771 AliCDBMetaData *md = new AliCDBMetaData();
772 md->SetResponsible("Chiara Zampolli");
776 //_____________________________________________________________________________
778 void AliTOFcalib::ReadParFromCDB(Char_t *sel, Int_t nrun)
780 //Read calibration parameters from the CDB
781 AliCDBManager *man = AliCDBManager::Instance();
782 if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
783 Char_t *sel1 = "Par" ;
785 sprintf(out,"%s/%s",sel,sel1);
786 AliCDBEntry *entry = man->Get(out,nrun);
787 AliTOFCal *cal =(AliTOFCal*)entry->GetObject();
790 //_____________________________________________________________________________
791 void AliTOFcalib::WriteSimParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
793 //Write Sim miscalibration parameters to the CDB
796 //for the time being, only one spectrum is used
797 TFile *spFile = new TFile("$ALICE_ROOT/TOF/data/spectrum.root","read");
799 // Retrieve ToT Spectrum
800 spFile->GetObject("ToT",hToT);
804 // Retrieve Time over TOT dependence
806 TH1F * h = (TH1F*)spFile->Get("TimeToTFit");
807 TList * list = (TList*)h->GetListOfFunctions();
808 TF1* f = (TF1*)list->At(0);
809 Float_t par[6] = {0,0,0,0,0,0};
810 Int_t npar=f->GetNpar();
811 for (Int_t ipar=0;ipar<npar;ipar++){
812 par[ipar]=f->GetParameter(ipar);
815 AliTOFGeometry *geom=new AliTOFGeometryV5();
816 fTOFSimCal = new AliTOFCal(geom);
817 fTOFSimCal->CreateArray();
820 for(Int_t iTOFch=0; iTOFch<fTOFSimCal->NPads();iTOFch++){
821 AliTOFChannel * calChannel = fTOFSimCal->GetChannel(iTOFch);
822 calChannel->SetSlewPar(par);
825 // Store them in the CDB
827 AliCDBManager *man = AliCDBManager::Instance();
828 if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
829 AliCDBMetaData *md = new AliCDBMetaData();
830 md->SetResponsible("Chiara Zampolli");
831 Char_t *sel1 = "SimPar" ;
833 sprintf(out,"%s/%s",sel,sel1);
834 AliCDBId id1(out,minrun,maxrun);
835 man->Put(fTOFSimCal,id1,md);
836 Char_t *sel2 = "SimHisto" ;
837 sprintf(out,"%s/%s",sel,sel2);
838 AliCDBId id2(out,minrun,maxrun);
839 man->Put(fTOFSimToT,id2,md);
843 //_____________________________________________________________________________
844 void AliTOFcalib::WriteSimParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFCal *cal, TH1F * histo){
845 //Write Sim miscalibration parameters to the CDB
849 AliCDBManager *man = AliCDBManager::Instance();
850 if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
851 AliCDBMetaData *md = new AliCDBMetaData();
852 md->SetResponsible("Chiara Zampolli");
853 Char_t *sel1 = "SimPar" ;
855 sprintf(out,"%s/%s",sel,sel1);
856 AliCDBId id1(out,minrun,maxrun);
857 man->Put(fTOFSimCal,id1,md);
858 Char_t *sel2 = "SimHisto" ;
859 sprintf(out,"%s/%s",sel,sel2);
860 AliCDBId id2(out,minrun,maxrun);
861 man->Put(fTOFSimToT,id2,md);
864 //_____________________________________________________________________________
865 void AliTOFcalib::ReadSimParFromCDB(Char_t *sel, Int_t nrun)
867 //Read miscalibration parameters from the CDB
868 AliCDBManager *man = AliCDBManager::Instance();
869 if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
870 Char_t *sel1 = "SimPar" ;
872 sprintf(out,"%s/%s",sel,sel1);
873 AliCDBEntry *entry1 = man->Get(out,nrun);
874 AliTOFCal *cal =(AliTOFCal*)entry1->GetObject();
876 Char_t *sel2 = "SimHisto" ;
877 sprintf(out,"%s/%s",sel,sel2);
878 AliCDBEntry *entry2 = man->Get(out,nrun);
879 TH1F *histo =(TH1F*)entry2->GetObject();
882 //_____________________________________________________________________________
884 Int_t AliTOFcalib::GetIndex(Int_t *detId)
886 //Retrieve calibration channel index
887 Int_t isector = detId[0];
888 if (isector >= fNSector)
889 AliError(Form("Wrong sector number in TOF (%d) !",isector));
890 Int_t iplate = detId[1];
891 if (iplate >= fNPlate)
892 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
893 Int_t istrip = detId[2];
894 Int_t ipadz = detId[3];
895 Int_t ipadx = detId[4];
896 Int_t stripOffset = 0;
902 stripOffset = fNStripC;
905 stripOffset = fNStripC+fNStripB;
908 stripOffset = fNStripC+fNStripB+fNStripA;
911 stripOffset = fNStripC+fNStripB+fNStripA+fNStripB;
914 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
918 Int_t idet = ((2*(fNStripC+fNStripB)+fNStripA)*fNpadZ*fNpadX)*isector +
919 (stripOffset*fNpadZ*fNpadX)+
920 (fNpadZ*fNpadX)*istrip+