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.4 2006/03/31 11:26:46 arcelli
19 changing CDB Ids according to standard convention
21 Revision 1.3 2006/03/28 14:57:02 arcelli
22 updates to handle new V5 geometry & some re-arrangements
24 Revision 1.2 2006/02/13 17:22:26 arcelli
27 Revision 1.1 2006/02/13 16:10:48 arcelli
28 Add classes for TOF Calibration (C.Zampolli)
30 author: Chiara Zampolli, zampolli@bo.infn.it
33 ///////////////////////////////////////////////////////////////////////////////
35 // class for TOF calibration //
37 ///////////////////////////////////////////////////////////////////////////////
39 #include "AliTOFcalib.h"
46 #include "AliTOFcalibESD.h"
52 #include "AliESDtrack.h"
53 #include "AliTOFChannel.h"
54 #include "AliTOFChSim.h"
55 #include "AliTOFGeometryV5.h"
56 #include "TClonesArray.h"
57 #include "AliTOFCal.h"
59 #include "AliTOFcluster.h"
61 #include "AliCDBManager.h"
62 #include "AliCDBMetaData.h"
63 #include "AliCDBStorage.h"
65 #include "AliCDBEntry.h"
68 extern TStyle *gStyle;
72 const Int_t AliTOFcalib::fgkchannel = 5000;
73 //_______________________________________________________________________
74 AliTOFcalib::AliTOFcalib():TTask("AliTOFcalib",""){
75 //TOF Calibration Class ctor
79 AliTOFGeometry *geom=new AliTOFGeometryV5();
80 AliInfo("V5 TOF Geometry is taken as the default");
81 fNSector = geom->NSectors();
82 fNPlate = geom->NPlates();
83 fNStripA = geom->NStripA();
84 fNStripB = geom->NStripB();
85 fNStripC = geom->NStripC();
86 fNpadZ = geom->NpadZ();
87 fNpadX = geom->NpadX();
88 fNChannels = fNSector*(2*(fNStripC+fNStripB)+fNStripA)*fNpadZ*fNpadX; //generalized version
89 fTOFCal = new AliTOFCal(geom);
90 fTOFSimCal = new AliTOFCal(geom);
91 fTOFCal->CreateArray();
92 fTOFSimCal->CreateArray();
96 //_______________________________________________________________________
97 AliTOFcalib::AliTOFcalib(AliTOFGeometry *geom):TTask("AliTOFcalib",""){
98 //TOF Calibration Class ctor, taking the TOF geometry as input
102 fNSector = geom->NSectors();
103 fNPlate = geom->NPlates();
104 fNStripA = geom->NStripA();
105 fNStripB = geom->NStripB();
106 fNStripC = geom->NStripC();
107 fNpadZ = geom->NpadZ();
108 fNpadX = geom->NpadX();
109 fNChannels = fNSector*(2*(fNStripC+fNStripB)+fNStripA)*fNpadZ*fNpadX; //generalized version
110 fTOFCal = new AliTOFCal(geom);
111 fTOFSimCal = new AliTOFCal(geom);
112 fTOFCal->CreateArray();
113 fTOFSimCal->CreateArray();
116 //____________________________________________________________________________
118 AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib):TTask("AliTOFcalib","")
120 //TOF Calibration Class copy ctor
121 fNSector = calib.fNSector;
122 fNPlate = calib.fNPlate;
123 fNStripA = calib.fNStripA;
124 fNStripB = calib.fNStripB;
125 fNStripC = calib.fNStripC;
126 fNpadZ = calib.fNpadZ;
127 fNpadX = calib.fNpadX;
128 fNChannels = calib.fNChannels;
129 fArrayToT = calib.fArrayToT;
130 fArrayTime = calib.fArrayTime;
131 fTOFCal=calib.fTOFCal;
132 fTOFSimCal = calib.fTOFSimCal;
133 fTOFSimToT=calib.fTOFSimToT;
136 //____________________________________________________________________________
138 AliTOFcalib::~AliTOFcalib()
140 //TOF Calibration Class dtor
147 //__________________________________________________________________________
149 TF1* AliTOFcalib::SetFitFunctions(TH1F *histo)
151 //Define Fit Functions for Slewing Correction
153 const Int_t knbins = histo->GetNbinsX();
154 Float_t delta = histo->GetBinWidth(1); //all the bins have the same width
155 Double_t max = histo->GetBinLowEdge(knbins)+delta;
157 fpol[0]=new TF1("poly3","pol3",5,max);
158 fpol[1]=new TF1("poly4","pol4",5,max);
159 fpol[2]=new TF1("poly5","pol5",5,max);
161 Double_t chi[3]={1E6,1E6,1E6};
162 Int_t ndf[3]={-1,-1,-1};
163 Double_t nchi[3]={1E6,1E6,1E6};
164 Double_t bestchi=1E6;
167 Int_t numberOfpar =0;
168 for (Int_t j=0; j<knbins; j++){
169 if (histo->GetBinContent(j)!=0) {
175 AliError(" Too few points in the histo. No fit performed.");
178 else if (nonzero<=5) {
180 AliInfo(" Only 3rd order polynomial fit possible.");
182 else if (nonzero<=6) {
184 AliInfo(" Only 3rd and 4th order polynomial fit possible.");
188 AliInfo(" All 3rd, 4th and 5th order polynomial fit possible.");
190 for (Int_t ifun=norderfit-3;ifun<norderfit-2;ifun++){
191 sprintf(npoly,"poly%i",ifun+3);
192 histo->Fit(npoly, "ERN", " ", 5.,14.);
193 chi[ifun] = fpol[ifun]->GetChisquare();
194 ndf[ifun] = fpol[ifun]->GetNDF();
195 nchi[ifun] = (Double_t)chi[ifun]/ndf[ifun];
196 if (nchi[ifun]<bestchi) {
199 numberOfpar = fGold->GetNpar();
202 fGold=fpol[2]; //Gold fit function set to pol5 in any case
203 histo->Fit(fGold,"ER " ," ",5.,15.);
206 //____________________________________________________________________________
208 void AliTOFcalib::SelectESD(AliESD *event)
210 //track selection for Calibration
211 Float_t lowerMomBound=0.8; // [GeV/c] default value Pb-Pb
212 Float_t upperMomBound=1.8 ; // [GeV/c] default value Pb-Pb
214 Int_t ngoodtrkfinalToT = 0;
215 ntrk=event->GetNumberOfTracks();
216 fESDsel = new TObjArray(ntrk);
218 TObjArray uCdatatemp(ntrk);
220 Int_t ngoodtrkfinal = 0;
221 Float_t mintime =1E6;
222 for (Int_t itrk=0; itrk<ntrk; itrk++) {
223 AliESDtrack *t=event->GetTrack(itrk);
224 //track selection: reconstrution to TOF:
225 if ((t->GetStatus()&AliESDtrack::kTOFout)==0) {
228 //IsStartedTimeIntegral
229 if ((t->GetStatus()&AliESDtrack::kTIME)==0) {
232 Double_t time=t->GetTOFsignal();
233 time*=1.E-3; // tof given in nanoseconds
234 if(time <= mintime)mintime=time;
235 Double_t mom=t->GetP();
236 if (!(mom<=upperMomBound && mom>=lowerMomBound))continue;
237 UInt_t assignedTOFcluster=t->GetTOFcluster();//index of the assigned TOF cluster, >0 ?
238 if(assignedTOFcluster==0){ // not matched
241 AliTOFcalibESD *unc = new AliTOFcalibESD;
242 unc->CopyFromAliESD(t);
244 unc->GetExternalCovariance(c1);
248 for (Int_t i = 0; i < ngoodtrk ; i ++){
249 AliTOFcalibESD *unc = (AliTOFcalibESD*)uCdatatemp.At(i);
250 if((unc->GetTOFsignal()-mintime*1.E3)<5.E3){
258 //_____________________________________________________________________________
260 void AliTOFcalib::CombESDId()
262 //track PID for calibration
265 Int_t ntracksinset=6;
266 Float_t exptof[6][3];
267 Float_t momentum[6]={0.,0.,0.,0.,0.,0.};
268 Int_t assparticle[6]={3,3,3,3,3,3};
269 Float_t massarray[3]={0.13957,0.493677,0.9382723};
270 Float_t timeofflight[6]={0.,0.,0.,0.,0.,0.};
271 Float_t beta[6]={0.,0.,0.,0.,0.,0.};
272 Float_t texp[6]={0.,0.,0.,0.,0.,0.};
273 Float_t sqMomError[6]={0.,0.,0.,0.,0.,0.};
274 Float_t sqTrackError[6]={0.,0.,0.,0.,0.,0.};
275 Float_t tracktoflen[6]={0.,0.,0.,0.,0.,0.};
276 Float_t timeResolution = 0.90e-10; // 90 ps by default
277 Float_t timeresolutioninns=timeResolution*(1.e+9); // convert in [ns]
278 Float_t timezero[6]={0.,0.,0.,0.,0.,0.};
279 Float_t weightedtimezero[6]={0.,0.,0.,0.,0.,0.};
280 Float_t besttimezero[6]={0.,0.,0.,0.,0.,0.};
281 Float_t bestchisquare[6]={0.,0.,0.,0.,0.,0.};
282 Float_t bestweightedtimezero[6]={0.,0.,0.,0.,0.,0.};
283 Float_t bestsqTrackError[6]={0.,0.,0.,0.,0.,0.};
285 Int_t nelements = fESDsel->GetEntries();
286 Int_t nset= (Int_t)(nelements/ntracksinset);
287 for (Int_t i=0; i< nset; i++) {
289 AliTOFcalibESD **unc=new AliTOFcalibESD*[ntracksinset];
290 for (Int_t itrk=0; itrk<ntracksinset; itrk++) {
291 Int_t index = itrk+i*ntracksinset;
292 AliTOFcalibESD *element=(AliTOFcalibESD*)fESDsel->At(index);
296 for (Int_t j=0; j<ntracksinset; j++) {
297 AliTOFcalibESD *element=unc[j];
298 Double_t mom=element->GetP();
299 Double_t time=element->GetTOFsignal()*1.E-3; // in ns
300 Double_t exptime[10];
301 element->GetIntegratedTimes(exptime);
302 Double_t toflen=element->GetIntegratedLength()/100.; // in m
303 timeofflight[j]=time+t0offset;
304 tracktoflen[j]=toflen+loffset;
305 exptof[j][0]=exptime[2]*1.E-3+0.005;
306 exptof[j][1]=exptime[3]*1.E-3+0.005;
307 exptof[j][2]=exptime[4]*1.E-3+0.005;
311 Float_t et0best=999.;
312 Float_t chisquarebest=999.;
313 for (Int_t i1=0; i1<3;i1++) {
314 beta[0]=momentum[0]/sqrt(massarray[i1]*massarray[i1]+momentum[0]*momentum[0]);
315 texp[0]=exptof[0][i1];
316 for (Int_t i2=0; i2<3;i2++) {
317 beta[1]=momentum[1]/sqrt(massarray[i2]*massarray[i2]+momentum[1]*momentum[1]);
318 texp[1]=exptof[1][i2];
319 for (Int_t i3=0; i3<3;i3++) {
320 beta[2]=momentum[2]/sqrt(massarray[i3]*massarray[i3]+momentum[2]*momentum[2]);
321 texp[2]=exptof[2][i3];
322 for (Int_t i4=0; i4<3;i4++) {
323 beta[3]=momentum[3]/sqrt(massarray[i4]*massarray[i4]+momentum[3]*momentum[3]);
324 texp[3]=exptof[3][i4];
326 for (Int_t i5=0; i5<3;i5++) {
327 beta[4]=momentum[4]/sqrt(massarray[i5]*massarray[i5]+momentum[4]*momentum[4]);
328 texp[4]=exptof[4][i5];
329 for (Int_t i6=0; i6<3;i6++) {
330 beta[5]=momentum[5]/sqrt(massarray[i6]*massarray[i6]+momentum[5]*momentum[5]);
331 texp[5]=exptof[5][i6];
333 Float_t sumAllweights=0.;
334 Float_t meantzero=0.;
335 Float_t emeantzero=0.;
337 for (Int_t itz=0; itz<ntracksinset;itz++) {
339 ((1.-beta[itz]*beta[itz])*0.025)*
340 ((1.-beta[itz]*beta[itz])*0.025)*
342 (0.299792*beta[itz]))*
344 (0.299792*beta[itz]));
350 timezero[itz]=texp[itz]-timeofflight[itz];
351 weightedtimezero[itz]=timezero[itz]/sqTrackError[itz];
352 sumAllweights+=1./sqTrackError[itz];
353 meantzero+=weightedtimezero[itz];
355 } // end loop for (Int_t itz=0; itz<15;itz++)
357 meantzero=meantzero/sumAllweights; // it is given in [ns]
358 emeantzero=sqrt(1./sumAllweights); // it is given in [ns]
360 // calculate chisquare
362 Float_t chisquare=0.;
363 for (Int_t icsq=0; icsq<ntracksinset;icsq++) {
364 chisquare+=(timezero[icsq]-meantzero)*(timezero[icsq]-meantzero)/sqTrackError[icsq];
365 } // end loop for (Int_t icsq=0; icsq<15;icsq++)
366 // cout << " chisquare " << chisquare << endl;
376 if(chisquare<=chisquarebest && ((Float_t) npion/ ((Float_t) ntracksinset)>0.3)){
377 // if(chisquare<=chisquarebest){
379 for(Int_t iqsq = 0; iqsq<ntracksinset; iqsq++) {
380 bestsqTrackError[iqsq]=sqTrackError[iqsq];
381 besttimezero[iqsq]=timezero[iqsq];
382 bestweightedtimezero[iqsq]=weightedtimezero[iqsq];
383 bestchisquare[iqsq]=(timezero[iqsq]-meantzero)*(timezero[iqsq]-meantzero)/sqTrackError[iqsq];
393 chisquarebest=chisquare;
396 } // close if(dummychisquare<=chisquare)
405 Float_t confLevel=999;
406 if(chisquarebest<999.){
407 Double_t dblechisquare=(Double_t)chisquarebest;
408 confLevel=(Float_t)TMath::Prob(dblechisquare,ntracksinset-1);
410 // assume they are all pions for fake sets
411 if(confLevel<0.01 || confLevel==999. ){
412 for (Int_t itrk=0; itrk<ntracksinset; itrk++)assparticle[itrk]=0;
414 for (Int_t itrk=0; itrk<ntracksinset; itrk++) {
415 Int_t index = itrk+i*ntracksinset;
416 AliTOFcalibESD *element=(AliTOFcalibESD*)fESDsel->At(index);
417 element->SetCombID(assparticle[itrk]);
422 //_____________________________________________________________________________
424 void AliTOFcalib::CalibrateESD(){
425 //Calibrate selected ESD times
426 Int_t nelements = fESDsel->GetEntries();
427 Int_t *number=new Int_t[fNChannels];
428 fArrayToT = new AliTOFArray(fNChannels);
429 fArrayTime = new AliTOFArray(fNChannels);
430 for (Int_t i=0; i<fNChannels; i++){
432 fArrayToT->AddArray(i, new TArrayF(fgkchannel));
433 TArrayF * parrToT = fArrayToT->GetArray(i);
434 TArrayF & refaToT = * parrToT;
435 fArrayTime->AddArray(i, new TArrayF(fgkchannel));
436 TArrayF * parrTime = fArrayToT->GetArray(i);
437 TArrayF & refaTime = * parrTime;
438 for (Int_t j = 0;j<AliTOFcalib::fgkchannel;j++){
439 refaToT[j]=0.; //ToT[i][j]=j;
440 refaTime[j]=0.; //Time[i][j]=j;
444 for (Int_t i=0; i< nelements; i++) {
445 AliTOFcalibESD *element=(AliTOFcalibESD*)fESDsel->At(i);
446 Int_t ipid = element->GetCombID();
447 Double_t etime = 0; //expected time
448 Double_t expTime[10];
449 element->GetIntegratedTimes(expTime);
450 if (ipid == 0) etime = expTime[2]*1E-3; //ns
451 else if (ipid == 1) etime = expTime[3]*1E-3; //ns
452 else if (ipid == 2) etime = expTime[4]*1E-3; //ns
453 else AliError("No pid from combinatorial algo for this track");
454 Double_t mtime = (Double_t)element->GetTOFsignal()*1E-3; //measured time
455 Double_t mToT = (Double_t) element->GetToT(); //measured ToT, ns
456 //select the correspondent channel with its simulated ToT spectrum
457 //summing up everything, index = 0 for all channels:
458 Int_t index = element->GetTOFCalChannel();
459 Int_t index2 = number[index];
460 TArrayF * parrToT = fArrayToT->GetArray(index);
461 TArrayF & refaToT = * parrToT;
462 refaToT[index2] = (Float_t)mToT;
463 TArrayF * parrTime = fArrayTime->GetArray(index);
464 TArrayF & refaTime = * parrTime;
465 refaTime[index2] = (Float_t)(mtime-etime);
469 for (Int_t i=0;i<1;i++){
470 TH1F * hProf = Profile(i);
471 TF1* fGold = SetFitFunctions(hProf);
472 Int_t nfpar = fGold->GetNpar();
474 for(Int_t kk=0;kk<6;kk++){
477 for (Int_t kk = 0; kk< nfpar; kk++){
478 par[kk]=fGold->GetParameter(kk);
480 AliTOFChannel * calChannel = fTOFCal->GetChannel(i);
481 calChannel->SetSlewPar(par);
486 //___________________________________________________________________________
488 TH1F* AliTOFcalib::Profile(Int_t ich)
490 //Prepare histograms for Slewing Correction
491 const Int_t knbinToT = 650;
492 Int_t nbinTime = 400;
493 Float_t minTime = -10.5; //ns
494 Float_t maxTime = 10.5; //ns
495 Float_t minToT = 7.5; //ns
496 Float_t maxToT = 40.; //ns
497 Float_t deltaToT = (maxToT-minToT)/knbinToT;
498 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];
499 Int_t n[knbinToT+1], nentrx[knbinToT+1];
500 Double_t sigmaToT[knbinToT+1];
501 for (Int_t i = 0; i < knbinToT+1 ; i++){
519 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
520 TArrayF * parrToT = fArrayToT->GetArray(ich);
521 TArrayF & refaToT = * parrToT;
522 TArrayF * parrTime = fArrayTime->GetArray(ich);
523 TArrayF & refaTime = * parrTime;
524 for (Int_t j = 0; j < AliTOFcalib::fgkchannel; j++){
525 if (refaToT[j] == 0) continue;
526 Int_t nx = (Int_t)((refaToT[j]-minToT)/deltaToT)+1;
527 if ((refaToT[j] != 0) && (refaTime[j] != 0)){
528 vTime[nx]+=refaTime[j];
529 vTime2[nx]+=(refaTime[j])*(refaTime[j]);
530 vToT[nx]+=refaToT[j];
531 vToT2[nx]+=refaToT[j]*refaToT[j];
533 hSlewing->Fill(refaToT[j],refaTime[j]);
536 Int_t nbinsToT=hSlewing->GetNbinsX();
537 if (nbinsToT != knbinToT) {
538 AliError("Profile :: incompatible numbers of bins");
543 TH1F *histo = new TH1F("histo", "1D Time vs ToT", nbinsToT, minToT, maxToT);
544 for (Int_t i=1;i<=nbinsToT;i++){
546 n[usefulBins]+=nentrx[i];
547 if (n[usefulBins]==0 && i == nbinsToT) {
550 meanTime[usefulBins]+=vTime[i];
551 meanTime2[usefulBins]+=vTime2[i];
552 meanToT[usefulBins]+=vToT[i];
553 meanToT2[usefulBins]+=vToT2[i];
554 if (n[usefulBins]<20 && i!=nbinsToT) continue;
555 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
556 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
557 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
558 *(meanTime2[usefulBins]-meanTime[usefulBins]
559 *meanTime[usefulBins]/n[usefulBins]));
560 if ((1./n[usefulBins]/n[usefulBins]
561 *(meanToT2[usefulBins]-meanToT[usefulBins]
562 *meanToT[usefulBins]/n[usefulBins]))< 0) {
563 AliError(" too small radical" );
564 sigmaToT[usefulBins]=0;
567 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
568 *(meanToT2[usefulBins]-meanToT[usefulBins]
569 *meanToT[usefulBins]/n[usefulBins]));
574 for (Int_t i=0;i<usefulBins;i++){
575 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
576 histo->Fill(mToT[i],mTime[i]);
577 histo->SetBinError(binN,sigmaTime[i]);
581 //_____________________________________________________________________________
583 void AliTOFcalib::CorrectESDTime()
585 //Calculate the corrected TOF time
586 Int_t nelements = fESDsel->GetEntries();
587 for (Int_t i=0; i< nelements; i++) {
588 AliTOFcalibESD *element=(AliTOFcalibESD*)fESDsel->At(i);
589 Int_t index = element->GetTOFCalChannel();
590 Float_t tToT = element->GetToT();
591 //select the correspondent channel with its simulated ToT spectrum
592 //summing up everything, index = 0 for all channels:
593 Int_t ipid = element->GetCombID();
594 Double_t etime = 0; //expected time
595 Double_t expTime[10];
596 element->GetIntegratedTimes(expTime);
597 if (ipid == 0) etime = expTime[2]*1E-3; //ns
598 else if (ipid == 1) etime = expTime[3]*1E-3; //ns
599 else if (ipid == 2) etime = expTime[4]*1E-3; //ns
601 AliTOFChannel * calChannel = fTOFCal->GetChannel(index);
602 for (Int_t j = 0; j<6; j++){
603 par[j]=calChannel->GetSlewPar(j);
606 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;
609 //_____________________________________________________________________________
611 void AliTOFcalib::CorrectESDTime(AliESD *event){
612 //Calculate the corrected TOF time
615 ntrk=event->GetNumberOfTracks();
616 for (Int_t itrk=0; itrk<ntrk; itrk++) {
617 AliESDtrack *t=event->GetTrack(itrk);
618 if ((t->GetStatus()&AliESDtrack::kTOFout)==0) {
621 //IsStartedTimeIntegral
622 if ((t->GetStatus()&AliESDtrack::kTIME)==0) {
625 UInt_t assignedTOFcluster=t->GetTOFcluster();//index of the assigned TOF cluster, >0 ?
626 if(assignedTOFcluster==0){ // not matched
629 Int_t index = t->GetTOFCalChannel();
630 AliTOFChannel * calChannel = fTOFCal->GetChannel(index);
632 for (Int_t j = 0; j<6; j++){
633 par[j]=calChannel->GetSlewPar(j);
635 Float_t tToT = t->GetTOFsignalToT();
637 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;
640 //_____________________________________________________________________________
642 void AliTOFcalib::WriteParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
644 //Write calibration parameters to the CDB
645 AliCDBManager *man = AliCDBManager::Instance();
646 if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
647 Char_t *sel1 = "Par" ;
649 sprintf(out,"%s/%s",sel,sel1);
650 AliCDBId id(out,minrun,maxrun);
651 AliCDBMetaData *md = new AliCDBMetaData();
652 md->SetResponsible("Chiara Zampolli");
653 man->Put(fTOFCal,id,md);
655 //_____________________________________________________________________________
657 void AliTOFcalib::WriteParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFCal *cal){
658 //Write calibration parameters to the CDB
659 AliCDBManager *man = AliCDBManager::Instance();
660 if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
661 Char_t *sel1 = "Par" ;
663 sprintf(out,"%s/%s",sel,sel1);
664 AliCDBId id(out,minrun,maxrun);
665 AliCDBMetaData *md = new AliCDBMetaData();
666 md->SetResponsible("Chiara Zampolli");
669 //_____________________________________________________________________________
671 void AliTOFcalib::ReadParFromCDB(Char_t *sel, Int_t nrun)
673 //Read calibration parameters from the CDB
674 AliCDBManager *man = AliCDBManager::Instance();
675 if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
676 Char_t *sel1 = "Par" ;
678 sprintf(out,"%s/%s",sel,sel1);
679 AliCDBEntry *entry = man->Get(out,nrun);
680 AliTOFCal *cal =(AliTOFCal*)entry->GetObject();
683 //_____________________________________________________________________________
684 void AliTOFcalib::WriteSimParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
686 //Write Sim miscalibration parameters to the CDB
689 //for the time being, only one spectrum is used
690 TFile *spFile = new TFile("$ALICE_ROOT/TOF/data/spectrum.root","read");
692 // Retrieve ToT Spectrum
693 spFile->GetObject("ToT",hToT);
697 // Retrieve Time over TOT dependence
699 TH1F * h = (TH1F*)spFile->Get("TimeToTFit");
700 TList * list = (TList*)h->GetListOfFunctions();
701 TF1* f = (TF1*)list->At(0);
702 Float_t par[6] = {0,0,0,0,0,0};
703 Int_t npar=f->GetNpar();
704 for (Int_t ipar=0;ipar<npar;ipar++){
705 par[ipar]=f->GetParameter(ipar);
708 for(Int_t iTOFch=0; iTOFch<fTOFSimCal->NPads();iTOFch++){
709 AliTOFChannel * calChannel = fTOFSimCal->GetChannel(iTOFch);
710 calChannel->SetSlewPar(par);
713 // Store them in the CDB
715 AliCDBManager *man = AliCDBManager::Instance();
716 if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
717 AliCDBMetaData *md = new AliCDBMetaData();
718 md->SetResponsible("Chiara Zampolli");
719 Char_t *sel1 = "SimPar" ;
721 sprintf(out,"%s/%s",sel,sel1);
722 AliCDBId id1(out,minrun,maxrun);
723 man->Put(fTOFSimCal,id1,md);
724 Char_t *sel2 = "SimHisto" ;
725 sprintf(out,"%s/%s",sel,sel2);
726 AliCDBId id2(out,minrun,maxrun);
727 man->Put(fTOFSimToT,id2,md);
730 //_____________________________________________________________________________
731 void AliTOFcalib::WriteSimParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFCal *cal, TH1F * histo){
732 //Write Sim miscalibration parameters to the CDB
736 AliCDBManager *man = AliCDBManager::Instance();
737 if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
738 AliCDBMetaData *md = new AliCDBMetaData();
739 md->SetResponsible("Chiara Zampolli");
740 Char_t *sel1 = "SimPar" ;
742 sprintf(out,"%s/%s",sel,sel1);
743 AliCDBId id1(out,minrun,maxrun);
744 man->Put(fTOFSimCal,id1,md);
745 Char_t *sel2 = "SimHisto" ;
746 sprintf(out,"%s/%s",sel,sel2);
747 AliCDBId id2(out,minrun,maxrun);
748 man->Put(fTOFSimToT,id2,md);
750 //_____________________________________________________________________________
751 void AliTOFcalib::ReadSimParFromCDB(Char_t *sel, Int_t nrun)
753 //Read miscalibration parameters from the CDB
754 AliCDBManager *man = AliCDBManager::Instance();
755 if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
756 AliCDBMetaData *md = new AliCDBMetaData();
757 md->SetResponsible("Chiara Zampolli");
758 Char_t *sel1 = "SimPar" ;
760 sprintf(out,"%s/%s",sel,sel1);
761 AliCDBEntry *entry1 = man->Get(out,nrun);
762 AliTOFCal *cal =(AliTOFCal*)entry1->GetObject();
764 Char_t *sel2 = "SimHisto" ;
765 sprintf(out,"%s/%s",sel,sel2);
766 AliCDBEntry *entry2 = man->Get(out,nrun);
767 TH1F *histo =(TH1F*)entry2->GetObject();
770 //_____________________________________________________________________________
772 Int_t AliTOFcalib::GetIndex(Int_t *detId)
774 //Retrieve calibration channel index
775 Int_t isector = detId[0];
776 if (isector >= fNSector)
777 AliError(Form("Wrong sector number in TOF (%d) !",isector));
778 Int_t iplate = detId[1];
779 if (iplate >= fNPlate)
780 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
781 Int_t istrip = detId[2];
782 Int_t ipadz = detId[3];
783 Int_t ipadx = detId[4];
784 Int_t stripOffset = 0;
790 stripOffset = fNStripC;
793 stripOffset = fNStripC+fNStripB;
796 stripOffset = fNStripC+fNStripB+fNStripA;
799 stripOffset = fNStripC+fNStripB+fNStripA+fNStripB;
802 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
806 Int_t idet = ((2*(fNStripC+fNStripB)+fNStripA)*fNpadZ*fNpadX)*isector +
807 (stripOffset*fNpadZ*fNpadX)+
808 (fNpadZ*fNpadX)*istrip+