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.16 2007/10/08 10:13:26 zampolli
19 First Run and Last Run members added, infinite validity of calib obj implemented.
21 Revision 1.15 2007/10/04 13:23:28 zampolli
22 Updates to handle functionalities in TOF online/offline calibration according to the latest schema
24 Revision 1.14 2007/06/06 16:26:30 arcelli
25 remove fall-back call to local CDB storage
27 Revision 1.13 2007/04/20 13:59:40 arcelli
28 make protections agains failed retrieval of the CDB object in a proper way
30 Revision 1.12 2007/03/23 11:31:16 arcelli
31 CDB Entry for TOF Reconstruction Parameters
33 Revision 1.11 2007/02/28 18:08:26 arcelli
34 Add protection against failed retrieval of the CDB cal object
36 Revision 1.10 2006/08/22 13:30:49 arcelli
37 removal of effective c++ warnings (C.Zampolli)
39 Revision 1.9 2006/04/20 22:30:50 hristov
40 Coding conventions (Annalisa)
42 Revision 1.8 2006/04/16 22:29:05 hristov
43 Coding conventions (Annalisa)
45 Revision 1.7 2006/04/16 20:12:46 hristov
46 Removing memory leak in case of cached CDB entries
48 Revision 1.6 2006/04/11 15:28:32 hristov
49 Checks on cache status before deleting calibration objects (A.Colla)
51 Revision 1.5 2006/04/05 08:35:38 hristov
52 Coding conventions (S.Arcelli, C.Zampolli)
54 Revision 1.4 2006/03/31 11:26:46 arcelli
55 changing CDB Ids according to standard convention
57 Revision 1.3 2006/03/28 14:57:02 arcelli
58 updates to handle new V5 geometry & some re-arrangements
60 Revision 1.2 2006/02/13 17:22:26 arcelli
63 Revision 1.1 2006/02/13 16:10:48 arcelli
64 Add classes for TOF Calibration (C.Zampolli)
66 author: Chiara Zampolli, zampolli@bo.infn.it
69 ///////////////////////////////////////////////////////////////////////////////
71 // class for TOF calibration //
73 ///////////////////////////////////////////////////////////////////////////////
86 #include "AliCDBEntry.h"
87 #include "AliCDBRunRange.h"
89 #include "AliCDBManager.h"
90 #include "AliCDBStorage.h"
91 #include "AliCDBMetaData.h"
92 #include "AliESDtrack.h"
96 #include "AliTOFcalib.h"
97 #include "AliTOFChannelOnline.h"
98 #include "AliTOFChannelOffline.h"
99 #include "AliTOFGeometry.h"
100 #include "AliTOFRecoParam.h"
103 extern TStyle *gStyle;
105 ClassImp(AliTOFcalib)
107 //_______________________________________________________________________
108 AliTOFcalib::AliTOFcalib():
109 TTask("AliTOFcalib",""),
118 fLastRun(AliCDBRunRange::Infinity())
120 //TOF Calibration Class ctor
121 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
123 //____________________________________________________________________________
125 AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib):
126 TTask("AliTOFcalib",""),
127 fNChannels(calib.fNChannels),
130 fTOFSimToT(calib.fTOFSimToT),
131 fkValidity(calib.fkValidity),
133 fNruns(calib.fNruns),
134 fFirstRun(calib.fFirstRun),
135 fLastRun(calib.fLastRun)
137 //TOF Calibration Class copy ctor
138 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
139 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
140 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
141 fTOFCalOnline->AddAt(calChOnline,iarray);
142 fTOFCalOffline->AddAt(calChOffline,iarray);
147 //____________________________________________________________________________
149 AliTOFcalib& AliTOFcalib::operator=(const AliTOFcalib &calib)
151 //TOF Calibration Class assignment operator
152 this->fNChannels = calib.fNChannels;
153 this->fTOFSimToT = calib.fTOFSimToT;
154 this->fkValidity = calib.fkValidity;
155 this->fTree = calib.fTree;
156 this->fNruns = calib.fNruns;
157 this->fFirstRun = calib.fFirstRun;
158 this->fLastRun = calib.fLastRun;
159 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
160 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
161 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
162 this->fTOFCalOnline->AddAt(calChOnline,iarray);
163 this->fTOFCalOffline->AddAt(calChOffline,iarray);
168 //____________________________________________________________________________
170 AliTOFcalib::~AliTOFcalib()
172 //TOF Calibration Class dtor
173 if(!(AliCDBManager::Instance()->GetCacheFlag())){ // CDB objects must NOT be deleted if cache is active!
175 // fTOFCalOnline->Clear();
176 delete fTOFCalOnline;
179 //fTOFCalOffline->Clear();
180 delete fTOFCalOffline;
183 if (fTree!=0x0) delete fTree;
185 //_____________________________________________________________________________
186 void AliTOFcalib::CreateCalArrays(){
188 // creating arrays for online/offline calibration objs
190 fTOFCalOnline = new TObjArray(fNChannels);
191 fTOFCalOffline = new TObjArray(fNChannels);
192 fTOFCalOnline->SetOwner();
193 fTOFCalOffline->SetOwner();
194 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
195 AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline();
196 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
197 fTOFCalOnline->AddAt(calChOnline,iarray);
198 fTOFCalOffline->AddAt(calChOffline,iarray);
201 //_____________________________________________________________________________
202 void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
204 //Write calibration parameters to the CDB
207 AliCDBManager *man = AliCDBManager::Instance();
208 Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
210 sprintf(out,"%s/%s",sel,sel1);
211 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
212 AliCDBId id(out,fFirstRun,fLastRun);
213 AliCDBMetaData *md = new AliCDBMetaData();
214 md->SetResponsible("Chiara Zampolli");
215 if (!fTOFCalOnline) {
218 man->Put(fTOFCalOnline,id,md);
221 //_____________________________________________________________________________
223 void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel)
225 //Write calibration parameters to the CDB with infinite validity
226 AliCDBManager *man = AliCDBManager::Instance();
227 Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
229 sprintf(out,"%s/%s",sel,sel1);
230 AliCDBRunRange runrange(fFirstRun,fLastRun);
231 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
232 AliCDBId id(out,runrange);
233 AliCDBMetaData *md = new AliCDBMetaData();
234 md->SetResponsible("Chiara Zampolli");
235 if (!fTOFCalOnline) {
238 man->Put(fTOFCalOnline,id,md);
241 //_____________________________________________________________________________
243 void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun)
245 //Write calibration parameters to the CDB
248 AliCDBManager *man = AliCDBManager::Instance();
249 Char_t *sel1 = "ParOffline" ;
251 sprintf(out,"%s/%s",sel,sel1);
252 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
253 AliCDBId id(out,fFirstRun,fLastRun);
254 AliCDBMetaData *md = new AliCDBMetaData();
255 md->SetResponsible("Chiara Zampolli");
256 md->SetComment(validity);
257 man->Put(fTOFCalOffline,id,md);
260 //_____________________________________________________________________________
262 void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity)
264 //Write calibration parameters to the CDB with infinite validity
265 AliCDBManager *man = AliCDBManager::Instance();
266 Char_t *sel1 = "ParOffline" ;
268 sprintf(out,"%s/%s",sel,sel1);
269 AliCDBRunRange runrange(fFirstRun,fLastRun);
270 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
271 AliCDBId id(out,runrange);
272 AliCDBMetaData *md = new AliCDBMetaData();
273 md->SetResponsible("Chiara Zampolli");
274 md->SetComment(validity);
275 man->Put(fTOFCalOffline,id,md);
278 //_____________________________________________________________________________
280 Bool_t AliTOFcalib::ReadParOnlineFromCDB(Char_t *sel, Int_t nrun)
282 //Read calibration parameters from the CDB
283 AliCDBManager *man = AliCDBManager::Instance();
284 Char_t *sel1 = "ParOnline" ;
286 sprintf(out,"%s/%s",sel,sel1);
287 if (!man->Get(out,nrun)) {
290 AliCDBEntry *entry = man->Get(out,nrun);
291 if(!entry->GetObject()){
295 fTOFCalOnline =(TObjArray*)entry->GetObject();
300 //_____________________________________________________________________________
302 Bool_t AliTOFcalib::ReadParOfflineFromCDB(Char_t *sel, Int_t nrun)
304 //Read calibration parameters from the CDB
305 AliCDBManager *man = AliCDBManager::Instance();
306 Char_t *sel1 = "ParOffline" ;
308 sprintf(out,"%s/%s",sel,sel1);
309 if (!man->Get(out,nrun)) {
312 AliCDBEntry *entry = man->Get(out,nrun);
313 if(!entry->GetObject()){
316 AliCDBMetaData * md = entry->GetMetaData();
317 fkValidity = md->GetComment();
318 fTOFCalOffline =(TObjArray*)entry->GetObject();
323 //_____________________________________________________________________________
324 void AliTOFcalib::WriteSimHistoOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, TH1F *histo){
325 //Write Sim miscalibration parameters to the CDB
328 AliCDBManager *man = AliCDBManager::Instance();
329 Char_t *sel1 = "SimHisto" ;
331 sprintf(out,"%s/%s",sel,sel1);
332 AliCDBMetaData *mdhisto = new AliCDBMetaData();
333 mdhisto->SetResponsible("Chiara Zampolli");
334 AliCDBId id(out,minrun,maxrun);
335 man->Put(fTOFSimToT,id,mdhisto);
338 //_____________________________________________________________________________
339 Bool_t AliTOFcalib::ReadSimHistoFromCDB(Char_t *sel, Int_t nrun)
341 //Read miscalibration parameters from the CDB
342 AliCDBManager *man = AliCDBManager::Instance();
346 Char_t *sel1 = "SimHisto" ;
348 sprintf(out,"%s/%s",sel,sel1);
349 if (!man->Get(out,nrun)) {
350 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
353 AliCDBEntry *entry = man->Get(out,nrun);
354 if(!entry->GetObject()){
355 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
358 TH1F *histo =(TH1F*)entry->GetObject();
361 //_____________________________________________________________________________
362 void AliTOFcalib::WriteRecParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){
363 //Write reconstruction parameters to the CDB
365 AliCDBManager *man = AliCDBManager::Instance();
366 AliCDBMetaData *md = new AliCDBMetaData();
367 md->SetResponsible("Silvia Arcelli");
368 Char_t *sel1 = "RecPar" ;
370 sprintf(out,"%s/%s",sel,sel1);
371 AliCDBId id(out,minrun,maxrun);
372 man->Put(param,id,md);
375 //_____________________________________________________________________________
376 AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(Char_t *sel, Int_t nrun)
378 //Read reconstruction parameters from the CDB
379 AliCDBManager *man = AliCDBManager::Instance();
380 Char_t *sel1 = "RecPar" ;
382 sprintf(out,"%s/%s",sel,sel1);
383 if (!man->Get(out,nrun)) {
384 AliFatal("Exiting, no CDB object (RecPar) found!!!");
387 AliCDBEntry *entry = man->Get(out,nrun);
388 if(!entry->GetObject()){
389 AliFatal("Exiting, no CDB object (RecPar) found!!!");
393 AliTOFRecoParam *param=(AliTOFRecoParam*)entry->GetObject();
396 //-----------------------------------------------------------------------------
397 // Calibration methods
398 //-----------------------------------------------------------------------------
399 void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
401 // creating the chain with the trees for calibration
402 // collecting them from reference data
403 // from minrun to maxrun
405 Float_t p[CHENTRIESSMALL];
407 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
408 fTree->Branch("nentries",&nentries,"nentries/I");
409 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
410 AliCDBManager *man = AliCDBManager::Instance();
411 AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT");
412 for (Int_t irun = minrun;irun<=maxrun;irun++){
413 AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
415 AliInfo(Form("No entry found for run %i",irun));
418 TTree *tree = new TTree();
419 tree = (TTree*)entry->GetObject();
420 tree->SetBranchAddress("nentries",&nentries);
421 tree->SetBranchAddress("TOFentries",p);
422 fTree->CopyEntries(tree);
427 AliInfo(Form("Number of runs being analyzed %i",fNruns));
429 //-----------------------------------------------------------------------------
430 void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
432 // creating the chain with the trees for calibration
433 // collecting them from the Grid
434 // from minrun to maxrun
436 Float_t p[CHENTRIESSMALL];
438 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
439 fTree->SetDirectory(0);
440 fTree->Branch("nentries",&nentries,"nentries/I");
441 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
442 AliInfo("connected to alien");
443 TGrid::Connect("alien://");
445 Char_t filename[100];
446 for (Int_t irun = minrun;irun<=maxrun;irun++){
447 sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
448 TFile *filegrid = TFile::Open(filename,"READ");
449 TTree *tree = (TTree*)filegrid->Get("T");
450 tree->SetBranchAddress("nentries",&nentries);
451 tree->SetBranchAddress("TOFentries",p);
452 fTree->CopyEntries(tree);
457 AliInfo(Form("Number of runs being analyzed %i",fNruns));
459 //-----------------------------------------------------------------------------
460 void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
462 // creating the tree with the trees for calibration
463 // collecting them from reference data (from file)
464 // from minrun to maxrun
466 Float_t p[CHENTRIESSMALL];
468 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
469 fTree->SetDirectory(0);
470 fTree->Branch("nentries",&nentries,"nentries/I");
471 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
472 Char_t filename[100];
473 for (Int_t irun = minrun;irun<=maxrun;irun++){
474 sprintf(filename,"$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
475 TFile *file = new TFile(filename,"READ");
476 TTree *tree = (TTree*)file->Get("T");
477 tree->SetBranchAddress("nentries",&nentries);
478 tree->SetBranchAddress("TOFentries",p);
479 fTree->CopyEntries(tree);
486 AliInfo(Form("Number of runs being analyzed %i",fNruns));
488 //-----------------------------------------------------------------------------
489 Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
491 // calibrating summing more than one channels
492 // computing calibration parameters
494 // 0 -> everything was ok
495 // 1 -> no tree for calibration found
496 // 2 -> not enough statistics to perform calibration
497 // 3 -> problems with arrays
499 TH1::AddDirectory(0);
501 AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ;
502 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
503 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
505 Float_t p[CHENTRIESSMALL];
507 fTree->SetBranchAddress("nentries",&nentries);
508 fTree->SetBranchAddress("TOFentries",p);
510 Float_t ntracksTotalmean =0;
511 for (Int_t i=ichmin; i<ichmax; i++){
513 for (Int_t irun=0;irun<fNruns;irun++){
514 ientry = i+irun*fNChannels;
515 fTree->GetEntry(ientry);
516 Int_t ntracksRun=nentries/3;
517 ntracksTotalmean+=ntracksRun;
521 if (ntracksTotalmean < MEANENTRIES) {
522 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
526 //filling ToT and Time arrays
528 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
529 Float_t minToT = 0; // ns
530 Float_t maxToT = 4.88; // ns
532 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
533 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
534 Int_t ntracksTotal = 0;
535 Int_t ntracksRun = 0;
536 Double_t binsProfile[101]; // sized larger than necessary, the correct
537 // dim being set in the booking of the profile
540 for (Int_t i = ichmin;i<ichmax;i++){
542 for (Int_t irun=0;irun<fNruns;irun++){
543 ientry = i+irun*fNChannels;
544 fTree->GetEntry(ientry);
545 ntracksTotal+=nentries/3;
546 ntracksRun=nentries/3;
547 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun));
548 for (Int_t j=0;j<ntracksRun;j++){
549 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
550 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
551 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
552 Float_t tot = p[idxexToT];
553 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
554 meantime+=p[idxexTime]-p[idxexExTime];
559 nusefulbins = FindBins(hToT,&binsProfile[0]);
560 meantime/=ntracksTotal;
561 AliDebug(2, Form("meantime = %f",meantime));
563 for (Int_t j=1;j<=nusefulbins;j++) {
564 AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j]));
567 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
568 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
570 for (Int_t irun=0;irun<fNruns;irun++){
572 for (Int_t i=ichmin; i<ichmax; i++){
573 ientry = i+irun*fNChannels;
574 fTree->GetEntry(ientry);
575 ntracksRun=nentries/3;
576 for (Int_t j=0;j<ntracksRun;j++){
577 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
578 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
579 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
580 Float_t tot = p[idxexToT];
581 Float_t time = p[idxexTime]-p[idxexExTime];
582 AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
583 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
584 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
589 hSlewingProf->Fit("pol5",optionFit,"",0,4);
590 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
592 for(Int_t kk=0;kk<6;kk++){
593 par[kk]=calibfunc->GetParameter(kk);
594 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
597 if(strstr(optionSave,"save")){
598 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
600 TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
601 TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
602 TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
603 TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
604 hSlewingProf->Write(profName);
605 htimetot->Write(timeTotName);
606 hToT->Write(totName);
607 hdeltaTime->Write(deltaName);
622 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin);
623 calChannel->SetSlewPar(par);
624 WriteParOfflineOnCDB("TOF/Calib","valid");
627 //----------------------------------------------------------------------------
628 Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
630 // computing calibration parameters for channel i
632 // 0 -> everything was ok
633 // 1 -> no tree for calibration found
634 // 2 -> not enough statistics to perform calibration
635 // 3 -> problems with arrays
637 TH1::AddDirectory(0);
639 AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ;
640 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
641 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
643 Float_t p[MAXCHENTRIESSMALL];
645 fTree->SetBranchAddress("nentries",&nentries);
646 fTree->SetBranchAddress("TOFentries",p);
648 Float_t ntracksTotal =0;
649 for (Int_t irun=0;irun<fNruns;irun++){
651 ientry = i+irun*fNChannels;
652 fTree->GetEntry(ientry);
653 ntracksTotal+=nentries/3;
656 if (ntracksTotal < MEANENTRIES) {
657 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
661 //filling ToT and Time arrays
663 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
664 Float_t minToT = 0; // ns
665 Float_t maxToT = 4.88; // ns
667 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
668 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
669 Int_t ntracksRun = 0;
670 Double_t binsProfile[101]; // sized larger than necessary, the correct
671 // dim being set in the booking of the profile
674 for (Int_t irun=0;irun<fNruns;irun++){
676 ientry = i+irun*fNChannels;
677 fTree->GetEntry(ientry);
678 ntracksRun=nentries/3;
679 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun));
680 for (Int_t j=0;j<ntracksRun;j++){
681 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
682 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
683 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
684 Float_t tot = p[idxexToT];
685 meantime+=p[idxexTime]-p[idxexExTime];
686 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
691 nusefulbins = FindBins(hToT,&binsProfile[0]);
692 meantime/=ntracksTotal;
693 AliDebug(2,Form("meantime = %f",meantime));
695 for (Int_t j=1;j<=nusefulbins;j++) {
696 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
699 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
700 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
701 for (Int_t irun=0;irun<fNruns;irun++){
703 ientry = i+irun*fNChannels;
704 fTree->GetEntry(ientry);
705 ntracksRun=nentries/3;
706 for (Int_t j=0;j<ntracksRun;j++){
707 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
708 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
709 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
710 Float_t tot = p[idxexToT];
711 Float_t time = p[idxexTime]-p[idxexExTime];
712 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
713 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
714 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
718 hSlewingProf->Fit("pol5",optionFit,"",0,4);
719 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
721 for(Int_t kk=0;kk<6;kk++){
722 par[kk]=calibfunc->GetParameter(kk);
723 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
727 if(strstr(optionSave,"save")){
728 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
730 TString profName=Form("Profile%06i",i);
731 TString timeTotName=Form("TimeTot%06i",i);
732 TString totName=Form("Tot%06i",i);
733 TString deltaName=Form("Delta%06i",i);
734 hSlewingProf->Write(profName);
735 htimetot->Write(timeTotName);
736 hToT->Write(totName);
737 hdeltaTime->Write(deltaName);
752 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
753 calChannel->SetSlewPar(par);
754 WriteParOfflineOnCDB("TOF/Calib","valid");
757 //----------------------------------------------------------------------------
758 Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
760 // calibrating an array of channels
761 // computing calibration parameters
763 // 0 -> everything was ok
764 // 1 -> no tree for calibration found
765 // 2 -> not enough statistics to perform calibration
766 // 3 -> problems with arrays
768 TH1::AddDirectory(0);
770 AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ;
771 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
772 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
773 for (Int_t ich=0; ich<nch; ich++){
775 AliInfo(Form("Calibrating channel = %i",i )) ;
777 Float_t p[MAXCHENTRIESSMALL];
779 fTree->SetBranchAddress("nentries",&nentries);
780 fTree->SetBranchAddress("TOFentries",p);
782 Float_t ntracksTotalmean =0;
783 for (Int_t ich=0; ich<nch; ich++){
786 for (Int_t irun=0;irun<fNruns;irun++){
787 ientry = i+irun*fNChannels;
788 fTree->GetEntry(ientry);
789 ntracksTotalmean+=nentries/3;
793 ntracksTotalmean/=nch;
794 if (ntracksTotalmean < MEANENTRIES) {
795 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
799 //filling ToT and Time arrays
801 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
802 Float_t minToT = 0; // ns
803 Float_t maxToT = 4.88; // ns
804 TFile * fileProf=0x0;
805 if(strstr(optionSave,"save")){
806 fileProf = new TFile("TOFCalibSave.root","recreate");
808 for (Int_t ich=0; ich<nch; ich++) {
809 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
810 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
811 Double_t binsProfile[101]; // sized larger than necessary, the correct
812 // dim being set in the booking of the profile
813 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
814 Int_t ntracksTotal = 0;
815 Int_t ntracksRun = 0;
819 for (Int_t irun=0;irun<fNruns;irun++){
820 i = ch[ich]+irun*fNChannels;
821 AliDebug(2,Form("Calibrating channel %i",i));
823 ntracksTotal+=nentries/3;
825 if (ntracksTotal < MEANENTRIES) {
826 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",i,ntracksTotal));
830 for (Int_t irun=0;irun<fNruns;irun++){
831 Int_t i = ch[ich]+irun*fNChannels;
833 ntracksRun=nentries/3;
834 for (Int_t j=0;j<ntracksRun;j++){
835 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
836 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
837 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
838 Float_t tot = p[idxexToT];
839 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
840 meantime+=p[idxexTime]-p[idxexExTime];
845 nusefulbins = FindBins(hToT,&binsProfile[0]);
846 meantime/=ntracksTotal;
847 for (Int_t j=1;j<=nusefulbins;j++) {
848 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
851 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
852 for (Int_t irun=0;irun<fNruns;irun++){
853 Int_t i = ch[ich]+irun*fNChannels;
855 ntracksRun=nentries/3;
856 for (Int_t j=0;j<ntracksRun;j++){
857 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
858 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
859 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
860 Float_t tot = p[idxexToT];
861 Float_t time = p[idxexTime]-p[idxexExTime];
862 AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
863 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
864 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
868 hSlewingProf->Fit("pol5",optionFit,"",1,4);
869 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
871 for(Int_t kk=0;kk<6;kk++){
872 par[kk]=calibfunc->GetParameter(kk);
873 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
876 if(strstr(optionSave,"save") && fileProf){
877 TString profName=Form("Profile%06i",i);
878 TString timeTotName=Form("TimeTot%06i",i);
879 TString totName=Form("Tot%06i",i);
880 TString deltaName=Form("Delta%06i",i);
882 hSlewingProf->Write(profName);
883 htimetot->Write(timeTotName);
884 hToT->Write(totName);
885 hdeltaTime->Write(deltaName);
888 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
889 calChannel->SetSlewPar(par);
900 if(strstr(optionSave,"save") && fileProf){
905 WriteParOfflineOnCDB("TOF/Calib","valid");
909 //----------------------------------------------------------------------------
910 Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){
912 // computing calibration parameters using the old profiling algo
914 // 0 -> everything was ok
915 // 1 -> no tree for calibration found
916 // 2 -> not enough statistics to perform calibration
917 // 3 -> problems with arrays
919 TH1::AddDirectory(0);
921 AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ;
922 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
923 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
924 Float_t p[MAXCHENTRIESSMALL];
926 Int_t ntracksTotal=0;
927 fTree->SetBranchAddress("nentries",&nentries);
928 fTree->SetBranchAddress("TOFentries",p);
930 for (Int_t irun=0;irun<fNruns;irun++){
931 Int_t i = ich+irun*fNChannels;
933 ntracksTotal+=nentries/3;
936 if (ntracksTotal < MEANENTRIES) {
937 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
941 TH1F * hProf = new TH1F();
942 hProf = Profile(ich);
943 hProf->Fit("pol5",optionFit,"",0,4);
944 TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
946 for(Int_t kk=0;kk<6;kk++){
947 par[kk]=calibfunc->GetParameter(kk);
948 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
951 if(strstr(optionSave,"save")){
952 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
954 TString profName=Form("Profile%06i",ich);
955 hProf->Write(profName);
963 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich);
964 calChannel->SetSlewPar(par);
965 WriteParOfflineOnCDB("TOF/Calib","valid");
968 //----------------------------------------------------------------------------
969 Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
971 // calibrating the whole TOF
972 // computing calibration parameters
974 // 0 -> everything was ok
975 // 1 -> no tree for calibration found
976 // 2 -> not enough statistics to perform calibration
977 // 3 -> problems with arrays
979 TH1::AddDirectory(0);
981 AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ;
982 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
983 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
985 TFile * fileProf=0x0;
986 if(strstr(optionSave,"save")){
987 fileProf = new TFile("TOFCalibSave.root","recreate");
990 Float_t p[MAXCHENTRIESSMALL];
992 fTree->SetBranchAddress("nentries",&nentries);
993 fTree->SetBranchAddress("TOFentries",p);
995 Float_t ntracksTotalmean =0;
996 for (Int_t ii=0; ii<fNChannels; ii++){
997 for (Int_t irun=0;irun<fNruns;irun++){
998 Int_t i = ii+irun*fNChannels;
1000 ntracksTotalmean+=nentries/3;
1004 ntracksTotalmean/=fNChannels;
1005 if (ntracksTotalmean < MEANENTRIES) {
1006 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1010 //filling ToT and Time arrays
1012 Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps
1013 Float_t minToT = 0; // ns
1014 Float_t maxToT = 4.88;// ns
1015 for (Int_t ii=0; ii<fNChannels; ii++) {
1016 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1017 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1018 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1019 if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
1021 Int_t nusefulbins=0;
1022 Double_t binsProfile[101]; // sized larger than necessary, the correct
1023 // dim being set in the booking of the profile
1024 Int_t ntracksRun = 0;
1025 Int_t ntracksTotal = 0;
1026 for (Int_t irun=0;irun<fNruns;irun++){
1027 Int_t i = ii+irun*fNChannels;
1029 ntracksTotal+=nentries/3;
1031 if (ntracksTotal < MEANENTRIES) {
1032 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",ii,ntracksTotal));
1036 for (Int_t irun=0;irun<fNruns;irun++){
1037 Int_t i = ii+irun*fNChannels;
1039 ntracksRun=nentries/3;
1040 for (Int_t j=0;j<ntracksRun;j++){
1041 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1042 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1043 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1044 Float_t tot = p[idxexToT];
1045 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1046 meantime+=p[idxexTime]-p[idxexExTime];
1050 nusefulbins = FindBins(hToT,&binsProfile[0]);
1051 meantime/=ntracksTotal;
1052 for (Int_t j=0;j<nusefulbins;j++) {
1053 AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j]));
1055 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1056 for (Int_t irun=0;irun<fNruns;irun++){
1057 Int_t i = ii+irun*fNChannels;
1059 ntracksRun=nentries/3;
1060 for (Int_t j=0;j<ntracksRun;j++){
1061 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1062 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1063 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1064 Float_t tot = p[idxexToT];
1065 Float_t time = p[idxexTime]-p[idxexExTime];
1066 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1067 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1068 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1071 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1072 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1074 for(Int_t kk=0;kk<6;kk++){
1075 par[kk]=calibfunc->GetParameter(kk);
1076 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1079 if(strstr(optionSave,"save") && fileProf){
1080 TString profName=Form("Profile%06i",ii);
1081 TString timeTotName=Form("TimeTot%06i",ii);
1082 TString totName=Form("Tot%06i",ii);
1083 TString deltaName=Form("Delta%06i",ii);
1085 hSlewingProf->Write(profName);
1086 htimetot->Write(timeTotName);
1087 hToT->Write(totName);
1088 hdeltaTime->Write(deltaName);
1090 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii);
1091 calChannel->SetSlewPar(par);
1095 delete hSlewingProf;
1103 if(strstr(optionSave,"save")){
1108 WriteParOfflineOnCDB("TOF/Calib","valid");
1112 //-----------------------------------------------------------------------
1113 TH1F* AliTOFcalib::Profile(Int_t ich)
1117 Float_t p[MAXCHENTRIESSMALL];
1119 fTree->SetBranchAddress("nentries",&nentries);
1120 fTree->SetBranchAddress("TOFentries",p);
1122 //Prepare histograms for Slewing Correction
1123 const Int_t knbinToT = 100;
1124 Int_t nbinTime = 200;
1125 Float_t minTime = -5.5; //ns
1126 Float_t maxTime = 5.5; //ns
1127 Float_t minToT = 0; //ns
1128 Float_t maxToT = 5.; //ns
1129 Float_t deltaToT = (maxToT-minToT)/knbinToT;
1130 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];
1131 Int_t n[knbinToT+1], nentrx[knbinToT+1];
1132 Double_t sigmaToT[knbinToT+1];
1133 for (Int_t i = 0; i < knbinToT+1 ; i++){
1151 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
1152 Int_t ntracksRun = 0;
1153 TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
1154 for (Int_t irun=0;irun<fNruns;irun++){
1155 Int_t i = ich+irun*fNChannels;
1157 ntracksRun=nentries/3;
1158 for (Int_t j=0;j<ntracksRun;j++){
1159 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1160 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1161 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1162 Float_t tot = p[idxexToT];
1163 Float_t time = p[idxexTime]-p[idxexExTime];
1164 Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
1165 if ((tot != 0) && ( time!= 0)){
1167 vTime2[nx]+=time*time;
1171 hSlewing->Fill(tot,time);
1175 Int_t nbinsToT=hSlewing->GetNbinsX();
1176 if (nbinsToT != knbinToT) {
1177 AliError("Profile :: incompatible numbers of bins");
1182 for (Int_t i=1;i<=nbinsToT;i++){
1184 n[usefulBins]+=nentrx[i];
1185 if (n[usefulBins]==0 && i == nbinsToT) {
1188 meanTime[usefulBins]+=vTime[i];
1189 meanTime2[usefulBins]+=vTime2[i];
1190 meanToT[usefulBins]+=vToT[i];
1191 meanToT2[usefulBins]+=vToT2[i];
1192 if (n[usefulBins]<10 && i!=nbinsToT) continue;
1193 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
1194 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
1195 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1196 *(meanTime2[usefulBins]-meanTime[usefulBins]
1197 *meanTime[usefulBins]/n[usefulBins]));
1198 if ((1./n[usefulBins]/n[usefulBins]
1199 *(meanToT2[usefulBins]-meanToT[usefulBins]
1200 *meanToT[usefulBins]/n[usefulBins]))< 0) {
1201 AliError(" too small radical" );
1202 sigmaToT[usefulBins]=0;
1205 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1206 *(meanToT2[usefulBins]-meanToT[usefulBins]
1207 *meanToT[usefulBins]/n[usefulBins]));
1212 for (Int_t i=0;i<usefulBins;i++){
1213 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
1214 histo->Fill(mToT[i],mTime[i]);
1215 histo->SetBinError(binN,sigmaTime[i]);
1222 //----------------------------------------------------------------------------
1223 Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
1225 // to determine the bins for ToT histo
1229 Int_t nbin = h->GetNbinsX();
1230 Int_t nentries = (Int_t)h->GetEntries();
1231 Float_t max = h->GetBinLowEdge(nbin);
1232 Int_t nusefulbins=0;
1234 // setting maxvalue of entries per bin
1235 if (nentries <= 60) maxcont = 2;
1236 else if (nentries <= 100) maxcont = 5;
1237 else if (nentries <= 500) maxcont = 10;
1239 for (Int_t j=1;j<=nbin;j++) {
1240 cont += (Int_t)h->GetBinContent(j);
1244 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1253 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1254 binsProfile[nusefulbins]=max;
1257 binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);