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 **************************************************************************/
17 $Log: AliTOFcalib.cxx,v $
18 Revision 1.21 2007/11/02 15:41:49 hristov
19 Provide return value if the function is not void
21 Revision 1.20 2007/10/26 15:13:50 zampolli
22 Using a TChain instead of a TTree
24 Revision 1.19 2007/10/23 15:27:38 zampolli
25 Rearrangement of Calibration objects for simulation
27 Revision 1.16 2007/10/08 10:13:26 zampolli
28 First Run and Last Run members added, infinite validity of calib obj implemented.
30 Revision 1.15 2007/10/04 13:23:28 zampolli
31 Updates to handle functionalities in TOF online/offline calibration according to the latest schema
33 Revision 1.14 2007/06/06 16:26:30 arcelli
34 remove fall-back call to local CDB storage
36 Revision 1.13 2007/04/20 13:59:40 arcelli
37 make protections agains failed retrieval of the CDB object in a proper way
39 Revision 1.12 2007/03/23 11:31:16 arcelli
40 CDB Entry for TOF Reconstruction Parameters
42 Revision 1.11 2007/02/28 18:08:26 arcelli
43 Add protection against failed retrieval of the CDB cal object
45 Revision 1.10 2006/08/22 13:30:49 arcelli
46 removal of effective c++ warnings (C.Zampolli)
48 Revision 1.9 2006/04/20 22:30:50 hristov
49 Coding conventions (Annalisa)
51 Revision 1.8 2006/04/16 22:29:05 hristov
52 Coding conventions (Annalisa)
54 Revision 1.7 2006/04/16 20:12:46 hristov
55 Removing memory leak in case of cached CDB entries
57 Revision 1.6 2006/04/11 15:28:32 hristov
58 Checks on cache status before deleting calibration objects (A.Colla)
60 Revision 1.5 2006/04/05 08:35:38 hristov
61 Coding conventions (S.Arcelli, C.Zampolli)
63 Revision 1.4 2006/03/31 11:26:46 arcelli
64 changing CDB Ids according to standard convention
66 Revision 1.3 2006/03/28 14:57:02 arcelli
67 updates to handle new V5 geometry & some re-arrangements
69 Revision 1.2 2006/02/13 17:22:26 arcelli
72 Revision 1.1 2006/02/13 16:10:48 arcelli
73 Add classes for TOF Calibration (C.Zampolli)
75 author: Chiara Zampolli, zampolli@bo.infn.it
78 ///////////////////////////////////////////////////////////////////////////////
80 // class for TOF calibration //
82 ///////////////////////////////////////////////////////////////////////////////
97 #include "AliCDBEntry.h"
98 #include "AliCDBRunRange.h"
100 #include "AliCDBManager.h"
101 #include "AliCDBStorage.h"
102 #include "AliCDBMetaData.h"
103 //#include "AliESDtrack.h"
104 //#include "AliESD.h"
107 #include "AliTOFcalib.h"
108 #include "AliTOFChannelOnline.h"
109 #include "AliTOFChannelOnlineStatus.h"
110 #include "AliTOFChannelOffline.h"
111 #include "AliTOFGeometry.h"
112 #include "AliTOFRecoParam.h"
118 extern TStyle *gStyle;
120 ClassImp(AliTOFcalib)
122 //_______________________________________________________________________
123 AliTOFcalib::AliTOFcalib():
124 TTask("AliTOFcalib",""),
127 fTOFCalOnlinePulser(0x0),
128 fTOFCalOnlineNoise(0x0),
129 fTOFCalOnlineHW(0x0),
137 fLastRun(AliCDBRunRange::Infinity())
139 //TOF Calibration Class ctor
140 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
142 //____________________________________________________________________________
144 AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib):
145 TTask("AliTOFcalib",""),
146 fNChannels(calib.fNChannels),
148 fTOFCalOnlinePulser(0x0),
149 fTOFCalOnlineNoise(0x0),
150 fTOFCalOnlineHW(0x0),
152 fTOFSimToT(calib.fTOFSimToT),
153 fkValidity(calib.fkValidity),
155 fChain(calib.fChain),
156 fNruns(calib.fNruns),
157 fFirstRun(calib.fFirstRun),
158 fLastRun(calib.fLastRun)
160 //TOF Calibration Class copy ctor
161 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
162 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
163 AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
164 AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
165 AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
166 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
167 fTOFCalOnline->AddAt(calChOnline,iarray);
168 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
169 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
170 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
171 fTOFCalOffline->AddAt(calChOffline,iarray);
176 //____________________________________________________________________________
178 AliTOFcalib& AliTOFcalib::operator=(const AliTOFcalib &calib)
180 //TOF Calibration Class assignment operator
181 this->fNChannels = calib.fNChannels;
182 this->fTOFSimToT = calib.fTOFSimToT;
183 this->fkValidity = calib.fkValidity;
184 this->fTree = calib.fTree;
185 this->fChain = calib.fChain;
186 this->fNruns = calib.fNruns;
187 this->fFirstRun = calib.fFirstRun;
188 this->fLastRun = calib.fLastRun;
189 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
190 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
191 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
192 AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
193 AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
194 AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
195 this->fTOFCalOnline->AddAt(calChOnline,iarray);
196 this->fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
197 this->fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
198 this->fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
199 this->fTOFCalOffline->AddAt(calChOffline,iarray);
204 //____________________________________________________________________________
206 AliTOFcalib::~AliTOFcalib()
208 //TOF Calibration Class dtor
209 if(!(AliCDBManager::Instance()->GetCacheFlag())){ // CDB objects must NOT be deleted if cache is active!
211 delete fTOFCalOnline;
213 if (fTOFCalOnlinePulser){
214 delete fTOFCalOnlinePulser;
216 if (fTOFCalOnlineNoise){
217 delete fTOFCalOnlineNoise;
219 if (fTOFCalOnlineHW){
220 delete fTOFCalOnlineHW;
223 delete fTOFCalOffline;
226 if (fTree!=0x0) delete fTree;
227 if (fChain!=0x0) delete fChain;
229 //_____________________________________________________________________________
230 void AliTOFcalib::CreateCalArrays(){
232 // creating arrays for online/offline calibration objs
234 fTOFCalOnline = new TObjArray(fNChannels);
235 fTOFCalOnlinePulser = new TObjArray(fNChannels);
236 fTOFCalOnlineNoise = new TObjArray(fNChannels);
237 fTOFCalOnlineHW = new TObjArray(fNChannels);
238 fTOFCalOffline = new TObjArray(fNChannels);
239 fTOFCalOnline->SetOwner();
240 fTOFCalOnlinePulser->SetOwner();
241 fTOFCalOnlineNoise->SetOwner();
242 fTOFCalOnlineHW->SetOwner();
243 fTOFCalOffline->SetOwner();
244 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
245 AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline();
246 AliTOFChannelOnlineStatus * calChOnlineStPulser = new AliTOFChannelOnlineStatus();
247 AliTOFChannelOnlineStatus * calChOnlineStNoise = new AliTOFChannelOnlineStatus();
248 AliTOFChannelOnlineStatus * calChOnlineStHW = new AliTOFChannelOnlineStatus();
249 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
250 fTOFCalOnline->AddAt(calChOnline,iarray);
251 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
252 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
253 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
254 fTOFCalOffline->AddAt(calChOffline,iarray);
257 //_____________________________________________________________________________
258 void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
260 //Write calibration parameters to the CDB
263 AliCDBManager *man = AliCDBManager::Instance();
264 Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
266 sprintf(out,"%s/%s",sel,sel1);
267 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
268 AliCDBId id(out,fFirstRun,fLastRun);
269 AliCDBMetaData *md = new AliCDBMetaData();
270 md->SetResponsible("Chiara Zampolli");
271 if (!fTOFCalOnline) {
274 man->Put(fTOFCalOnline,id,md);
277 //_____________________________________________________________________________
278 void AliTOFcalib::WriteParOnlinePulserOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
280 //Write calibration parameters from pulser to the CDB
283 AliCDBManager *man = AliCDBManager::Instance();
284 Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
286 sprintf(out,"%s/%s",sel,sel1);
287 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
288 AliCDBId id(out,fFirstRun,fLastRun);
289 AliCDBMetaData *md = new AliCDBMetaData();
290 md->SetResponsible("Chiara Zampolli");
291 if (!fTOFCalOnlinePulser) {
294 man->Put(fTOFCalOnlinePulser,id,md);
297 //_____________________________________________________________________________
298 void AliTOFcalib::WriteParOnlineNoiseOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
300 //Write calibration parameters from noise to the CDB
303 AliCDBManager *man = AliCDBManager::Instance();
304 Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
306 sprintf(out,"%s/%s",sel,sel1);
307 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
308 AliCDBId id(out,fFirstRun,fLastRun);
309 AliCDBMetaData *md = new AliCDBMetaData();
310 md->SetResponsible("Chiara Zampolli");
311 if (!fTOFCalOnlineNoise) {
314 man->Put(fTOFCalOnlineNoise,id,md);
317 //_____________________________________________________________________________
318 void AliTOFcalib::WriteParOnlineHWOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
320 //Write calibration parameters from hardware to the CDB
323 AliCDBManager *man = AliCDBManager::Instance();
324 Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
326 sprintf(out,"%s/%s",sel,sel1);
327 AliDebug(2,Form("Writing TOF online calib obj from hardware on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
328 AliCDBId id(out,fFirstRun,fLastRun);
329 AliCDBMetaData *md = new AliCDBMetaData();
330 md->SetResponsible("Chiara Zampolli");
331 if (!fTOFCalOnlineHW) {
334 man->Put(fTOFCalOnlineHW,id,md);
337 //_____________________________________________________________________________
339 void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel)
341 //Write calibration parameters to the CDB with infinite validity
342 AliCDBManager *man = AliCDBManager::Instance();
343 Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
345 sprintf(out,"%s/%s",sel,sel1);
346 AliCDBRunRange runrange(fFirstRun,fLastRun);
347 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
348 AliCDBId id(out,runrange);
349 AliCDBMetaData *md = new AliCDBMetaData();
350 md->SetResponsible("Chiara Zampolli");
351 if (!fTOFCalOnline) {
354 man->Put(fTOFCalOnline,id,md);
357 //_____________________________________________________________________________
359 void AliTOFcalib::WriteParOnlinePulserOnCDB(Char_t *sel)
361 //Write calibration parameters from pulser to the CDB with infinite validity
362 AliCDBManager *man = AliCDBManager::Instance();
363 Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
365 sprintf(out,"%s/%s",sel,sel1);
366 AliCDBRunRange runrange(fFirstRun,fLastRun);
367 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
368 AliCDBId id(out,runrange);
369 AliCDBMetaData *md = new AliCDBMetaData();
370 md->SetResponsible("Chiara Zampolli");
371 if (!fTOFCalOnlinePulser) {
374 man->Put(fTOFCalOnlinePulser,id,md);
377 //_____________________________________________________________________________
379 void AliTOFcalib::WriteParOnlineNoiseOnCDB(Char_t *sel)
381 //Write calibration parameters from noise to the CDB with infinite validity
382 AliCDBManager *man = AliCDBManager::Instance();
383 Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
385 sprintf(out,"%s/%s",sel,sel1);
386 AliCDBRunRange runrange(fFirstRun,fLastRun);
387 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
388 AliCDBId id(out,runrange);
389 AliCDBMetaData *md = new AliCDBMetaData();
390 md->SetResponsible("Chiara Zampolli");
391 if (!fTOFCalOnlineNoise) {
394 man->Put(fTOFCalOnlineNoise,id,md);
397 //_____________________________________________________________________________
399 void AliTOFcalib::WriteParOnlineHWOnCDB(Char_t *sel)
401 //Write calibration parameters from hardware to the CDB with infinite validity
402 AliCDBManager *man = AliCDBManager::Instance();
403 Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
405 sprintf(out,"%s/%s",sel,sel1);
406 AliCDBRunRange runrange(fFirstRun,fLastRun);
407 AliDebug(2,Form("Writing TOF online calib obj from harware on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
408 AliCDBId id(out,runrange);
409 AliCDBMetaData *md = new AliCDBMetaData();
410 md->SetResponsible("Chiara Zampolli");
411 if (!fTOFCalOnlineHW) {
414 man->Put(fTOFCalOnlineHW,id,md);
417 //_____________________________________________________________________________
419 void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun)
421 //Write calibration parameters to the CDB
424 AliCDBManager *man = AliCDBManager::Instance();
425 Char_t *sel1 = "ParOffline" ;
427 sprintf(out,"%s/%s",sel,sel1);
428 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
429 AliCDBId id(out,fFirstRun,fLastRun);
430 AliCDBMetaData *md = new AliCDBMetaData();
431 md->SetResponsible("Chiara Zampolli");
432 md->SetComment(validity);
433 man->Put(fTOFCalOffline,id,md);
436 //_____________________________________________________________________________
438 void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity)
440 //Write calibration parameters to the CDB with infinite validity
441 AliCDBManager *man = AliCDBManager::Instance();
442 Char_t *sel1 = "ParOffline" ;
444 sprintf(out,"%s/%s",sel,sel1);
445 AliCDBRunRange runrange(fFirstRun,fLastRun);
446 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
447 AliCDBId id(out,runrange);
448 AliCDBMetaData *md = new AliCDBMetaData();
449 md->SetResponsible("Chiara Zampolli");
450 md->SetComment(validity);
451 man->Put(fTOFCalOffline,id,md);
454 //_____________________________________________________________________________
456 Bool_t AliTOFcalib::ReadParOnlineFromCDB(Char_t *sel, Int_t nrun)
458 //Read calibration parameters from the CDB
459 AliCDBManager *man = AliCDBManager::Instance();
460 Char_t *sel1 = "ParOnline" ;
462 sprintf(out,"%s/%s",sel,sel1);
463 if (!man->Get(out,nrun)) {
466 AliCDBEntry *entry = man->Get(out,nrun);
467 if(!entry->GetObject()){
471 fTOFCalOnline =(TObjArray*)entry->GetObject();
476 //_____________________________________________________________________________
478 Bool_t AliTOFcalib::ReadParOnlinePulserFromCDB(Char_t *sel, Int_t nrun)
480 //Read calibration parameters from pulser from the CDB
481 AliCDBManager *man = AliCDBManager::Instance();
482 Char_t *sel1 = "Pulser" ;
484 sprintf(out,"%s/%s",sel,sel1);
485 if (!man->Get(out,nrun)) {
488 AliCDBEntry *entry = man->Get(out,nrun);
489 if(!entry->GetObject()){
493 fTOFCalOnlinePulser =(TObjArray*)entry->GetObject();
498 //_____________________________________________________________________________
500 Bool_t AliTOFcalib::ReadParOnlineNoiseFromCDB(Char_t *sel, Int_t nrun)
502 //Read calibration parameters from noise from the CDB
503 AliCDBManager *man = AliCDBManager::Instance();
504 Char_t *sel1 = "Noise" ;
506 sprintf(out,"%s/%s",sel,sel1);
507 if (!man->Get(out,nrun)) {
510 AliCDBEntry *entry = man->Get(out,nrun);
511 if(!entry->GetObject()){
515 fTOFCalOnlineNoise =(TObjArray*)entry->GetObject();
520 //_____________________________________________________________________________
522 Bool_t AliTOFcalib::ReadParOnlineHWFromCDB(Char_t *sel, Int_t nrun)
524 //Read calibration parameters from hardware from the CDB
525 AliCDBManager *man = AliCDBManager::Instance();
526 Char_t *sel1 = "HW" ;
528 sprintf(out,"%s/%s",sel,sel1);
529 if (!man->Get(out,nrun)) {
532 AliCDBEntry *entry = man->Get(out,nrun);
533 if(!entry->GetObject()){
537 fTOFCalOnlineHW =(TObjArray*)entry->GetObject();
542 //_____________________________________________________________________________
544 Bool_t AliTOFcalib::ReadParOfflineFromCDB(Char_t *sel, Int_t nrun)
546 //Read calibration parameters from the CDB
547 AliCDBManager *man = AliCDBManager::Instance();
548 Char_t *sel1 = "ParOffline" ;
550 sprintf(out,"%s/%s",sel,sel1);
551 if (!man->Get(out,nrun)) {
554 AliCDBEntry *entry = man->Get(out,nrun);
555 if(!entry->GetObject()){
558 AliCDBMetaData * md = entry->GetMetaData();
559 fkValidity = md->GetComment();
560 fTOFCalOffline =(TObjArray*)entry->GetObject();
565 //_____________________________________________________________________________
566 void AliTOFcalib::WriteSimHistoOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, TH1F *histo){
567 //Write Sim miscalibration parameters to the CDB
570 AliCDBManager *man = AliCDBManager::Instance();
571 Char_t *sel1 = "SimHisto" ;
573 sprintf(out,"%s/%s",sel,sel1);
574 AliCDBMetaData *mdhisto = new AliCDBMetaData();
575 mdhisto->SetResponsible("Chiara Zampolli");
576 AliCDBId id(out,minrun,maxrun);
577 man->Put(fTOFSimToT,id,mdhisto);
580 //_____________________________________________________________________________
581 Bool_t AliTOFcalib::ReadSimHistoFromCDB(Char_t *sel, Int_t nrun)
583 //Read miscalibration parameters from the CDB
584 AliCDBManager *man = AliCDBManager::Instance();
588 Char_t *sel1 = "SimHisto" ;
590 sprintf(out,"%s/%s",sel,sel1);
591 if (!man->Get(out,nrun)) {
592 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
595 AliCDBEntry *entry = man->Get(out,nrun);
596 if(!entry->GetObject()){
597 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
600 TH1F *histo =(TH1F*)entry->GetObject();
604 //_____________________________________________________________________________
605 void AliTOFcalib::WriteRecParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){
606 //Write reconstruction parameters to the CDB
608 AliCDBManager *man = AliCDBManager::Instance();
609 AliCDBMetaData *md = new AliCDBMetaData();
610 md->SetResponsible("Silvia Arcelli");
611 Char_t *sel1 = "RecPar" ;
613 sprintf(out,"%s/%s",sel,sel1);
614 AliCDBId id(out,minrun,maxrun);
615 man->Put(param,id,md);
618 //_____________________________________________________________________________
619 AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(Char_t *sel, Int_t nrun)
621 //Read reconstruction parameters from the CDB
622 AliCDBManager *man = AliCDBManager::Instance();
623 Char_t *sel1 = "RecPar" ;
625 sprintf(out,"%s/%s",sel,sel1);
626 if (!man->Get(out,nrun)) {
627 AliFatal("Exiting, no CDB object (RecPar) found!!!");
630 AliCDBEntry *entry = man->Get(out,nrun);
631 if(!entry->GetObject()){
632 AliFatal("Exiting, no CDB object (RecPar) found!!!");
636 AliTOFRecoParam *param=(AliTOFRecoParam*)entry->GetObject();
639 //-----------------------------------------------------------------------------
640 // Calibration methods
641 //-----------------------------------------------------------------------------
642 void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
644 // creating the chain with the trees for calibration
645 // collecting them from reference data
646 // from minrun to maxrun
648 Float_t p[CHENTRIESSMALL];
650 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
651 fTree->Branch("nentries",&nentries,"nentries/I");
652 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
653 AliCDBManager *man = AliCDBManager::Instance();
654 AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT");
655 for (Int_t irun = minrun;irun<=maxrun;irun++){
656 AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
658 AliInfo(Form("No entry found for run %i",irun));
661 TTree *tree = new TTree();
662 tree = (TTree*)entry->GetObject();
663 tree->SetBranchAddress("nentries",&nentries);
664 tree->SetBranchAddress("TOFentries",p);
665 fTree->CopyEntries(tree);
670 AliInfo(Form("Number of runs being analyzed %i",fNruns));
672 //-----------------------------------------------------------------------------
673 void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
675 // creating the chain with the trees for calibration
676 // collecting them from the Grid
677 // from minrun to maxrun
679 Float_t p[CHENTRIESSMALL];
681 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
682 fTree->SetDirectory(0);
683 fTree->Branch("nentries",&nentries,"nentries/I");
684 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
685 AliInfo("connected to alien");
686 TGrid::Connect("alien://");
688 Char_t filename[100];
689 for (Int_t irun = minrun;irun<=maxrun;irun++){
690 sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
691 TFile *filegrid = TFile::Open(filename,"READ");
692 TTree *tree = (TTree*)filegrid->Get("T");
693 tree->SetBranchAddress("nentries",&nentries);
694 tree->SetBranchAddress("TOFentries",p);
695 fTree->CopyEntries(tree);
700 AliInfo(Form("Number of runs being analyzed %i",fNruns));
702 //-----------------------------------------------------------------------------
703 void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
705 // creating the tree with the trees for calibration
706 // collecting them from reference data (from file)
707 // from minrun to maxrun
709 Float_t p[CHENTRIESSMALL];
711 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
712 fTree->SetDirectory(0);
713 fTree->Branch("nentries",&nentries,"nentries/I");
714 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
715 Char_t filename[100];
716 for (Int_t irun = minrun;irun<=maxrun;irun++){
717 sprintf(filename,"$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
718 TFile *file = new TFile(filename,"READ");
719 TTree *tree = (TTree*)file->Get("T");
720 tree->SetBranchAddress("nentries",&nentries);
721 tree->SetBranchAddress("TOFentries",p);
722 fTree->CopyEntries(tree);
729 AliInfo(Form("Number of runs being analyzed %i",fNruns));
731 //-----------------------------------------------------------------------------
732 void AliTOFcalib::CreateChainFromGrid(Int_t minrun, Int_t maxrun){
734 // creating the chain with the trees for calibration
735 // collecting them from the Grid
736 // from minrun to maxrun
738 fChain = new TChain("T");
739 AliInfo("connected to alien");
740 TGrid::Connect("alien://");
742 Char_t filename[100];
743 for (Int_t irun = minrun;irun<=maxrun;irun++){
744 sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
745 fChain->Add(filename);
749 AliInfo(Form("Number of runs being analyzed %i",fNruns));
751 //-----------------------------------------------------------------------------
752 Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
754 // calibrating summing more than one channels
755 // computing calibration parameters
757 // 0 -> everything was ok
758 // 1 -> no tree for calibration found
759 // 2 -> not enough statistics to perform calibration
760 // 3 -> problems with arrays
762 TH1::AddDirectory(0);
764 AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ;
765 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
766 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
768 Float_t p[CHENTRIESSMALL];
770 //fTree->SetBranchAddress("nentries",&nentries);
771 //fTree->SetBranchAddress("TOFentries",p);
772 fChain->SetBranchAddress("nentries",&nentries);
773 fChain->SetBranchAddress("TOFentries",p);
775 Float_t ntracksTotalmean =0;
776 for (Int_t i=ichmin; i<ichmax; i++){
778 for (Int_t irun=0;irun<fNruns;irun++){
779 ientry = i+irun*fNChannels;
780 //fTree->GetEntry(ientry);
781 fChain->GetEntry(ientry);
782 Int_t ntracksRun=nentries/3;
783 ntracksTotalmean+=ntracksRun;
787 if (ntracksTotalmean < MEANENTRIES) {
788 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
792 //filling ToT and Time arrays
794 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
795 Float_t minToT = 0; // ns
796 Float_t maxToT = 4.88; // ns
798 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
799 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
800 Int_t ntracksTotal = 0;
801 Int_t ntracksRun = 0;
802 Double_t binsProfile[101]; // sized larger than necessary, the correct
803 // dim being set in the booking of the profile
806 for (Int_t i = ichmin;i<ichmax;i++){
808 for (Int_t irun=0;irun<fNruns;irun++){
809 ientry = i+irun*fNChannels;
810 //fTree->GetEntry(ientry);
811 fChain->GetEntry(ientry);
812 ntracksTotal+=nentries/3;
813 ntracksRun=nentries/3;
814 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun));
815 for (Int_t j=0;j<ntracksRun;j++){
816 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
817 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
818 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
819 Float_t tot = p[idxexToT];
820 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
821 meantime+=p[idxexTime]-p[idxexExTime];
826 nusefulbins = FindBins(hToT,&binsProfile[0]);
827 meantime/=ntracksTotal;
828 AliDebug(2, Form("meantime = %f",meantime));
830 for (Int_t j=1;j<=nusefulbins;j++) {
831 AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j]));
834 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
835 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
837 for (Int_t irun=0;irun<fNruns;irun++){
839 for (Int_t i=ichmin; i<ichmax; i++){
840 ientry = i+irun*fNChannels;
841 //fTree->GetEntry(ientry);
842 fChain->GetEntry(ientry);
843 ntracksRun=nentries/3;
844 for (Int_t j=0;j<ntracksRun;j++){
845 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
846 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
847 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
848 Float_t tot = p[idxexToT];
849 Float_t time = p[idxexTime]-p[idxexExTime];
850 AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
851 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
852 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
857 hSlewingProf->Fit("pol5",optionFit,"",0,4);
858 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
860 for(Int_t kk=0;kk<6;kk++){
861 par[kk]=calibfunc->GetParameter(kk);
862 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
865 if(strstr(optionSave,"save")){
866 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
868 TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
869 TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
870 TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
871 TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
872 hSlewingProf->Write(profName);
873 htimetot->Write(timeTotName);
874 hToT->Write(totName);
875 hdeltaTime->Write(deltaName);
890 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin);
891 calChannel->SetSlewPar(par);
892 WriteParOfflineOnCDB("TOF/Calib","valid");
895 //----------------------------------------------------------------------------
896 Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
898 // computing calibration parameters for channel i
900 // 0 -> everything was ok
901 // 1 -> no tree for calibration found
902 // 2 -> not enough statistics to perform calibration
903 // 3 -> problems with arrays
905 TH1::AddDirectory(0);
907 AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ;
908 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
909 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
911 Float_t p[MAXCHENTRIESSMALL];
913 //fTree->SetBranchAddress("nentries",&nentries);
914 //fTree->SetBranchAddress("TOFentries",p);
915 fChain->SetBranchAddress("nentries",&nentries);
916 fChain->SetBranchAddress("TOFentries",p);
918 Float_t ntracksTotal =0;
919 for (Int_t irun=0;irun<fNruns;irun++){
921 ientry = i+irun*fNChannels;
922 //fTree->GetEntry(ientry);
923 fChain->GetEntry(ientry);
924 ntracksTotal+=nentries/3;
927 if (ntracksTotal < MEANENTRIES) {
928 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
932 //filling ToT and Time arrays
934 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
935 Float_t minToT = 0; // ns
936 Float_t maxToT = 4.88; // ns
938 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
939 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
940 Int_t ntracksRun = 0;
941 Double_t binsProfile[101]; // sized larger than necessary, the correct
942 // dim being set in the booking of the profile
945 for (Int_t irun=0;irun<fNruns;irun++){
947 ientry = i+irun*fNChannels;
948 //fTree->GetEntry(ientry);
949 fChain->GetEntry(ientry);
950 ntracksRun=nentries/3;
951 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun));
952 for (Int_t j=0;j<ntracksRun;j++){
953 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
954 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
955 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
956 Float_t tot = p[idxexToT];
957 meantime+=p[idxexTime]-p[idxexExTime];
958 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
963 nusefulbins = FindBins(hToT,&binsProfile[0]);
964 meantime/=ntracksTotal;
965 AliDebug(2,Form("meantime = %f",meantime));
967 for (Int_t j=1;j<=nusefulbins;j++) {
968 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
971 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
972 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
973 for (Int_t irun=0;irun<fNruns;irun++){
975 ientry = i+irun*fNChannels;
976 //fTree->GetEntry(ientry);
977 fChain->GetEntry(ientry);
978 ntracksRun=nentries/3;
979 for (Int_t j=0;j<ntracksRun;j++){
980 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
981 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
982 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
983 Float_t tot = p[idxexToT];
984 Float_t time = p[idxexTime]-p[idxexExTime];
985 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
986 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
987 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
991 hSlewingProf->Fit("pol5",optionFit,"",0,4);
992 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
994 for(Int_t kk=0;kk<6;kk++){
995 par[kk]=calibfunc->GetParameter(kk);
996 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1000 if(strstr(optionSave,"save")){
1001 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1003 TString profName=Form("Profile%06i",i);
1004 TString timeTotName=Form("TimeTot%06i",i);
1005 TString totName=Form("Tot%06i",i);
1006 TString deltaName=Form("Delta%06i",i);
1007 hSlewingProf->Write(profName);
1008 htimetot->Write(timeTotName);
1009 hToT->Write(totName);
1010 hdeltaTime->Write(deltaName);
1018 delete hSlewingProf;
1025 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1026 calChannel->SetSlewPar(par);
1027 WriteParOfflineOnCDB("TOF/Calib","valid");
1030 //----------------------------------------------------------------------------
1031 Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
1033 // calibrating an array of channels
1034 // computing calibration parameters
1036 // 0 -> everything was ok
1037 // 1 -> no tree for calibration found
1038 // 2 -> not enough statistics to perform calibration
1039 // 3 -> problems with arrays
1041 TH1::AddDirectory(0);
1043 AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ;
1044 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1045 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1046 for (Int_t ich=0; ich<nch; ich++){
1048 AliInfo(Form("Calibrating channel = %i",i )) ;
1050 Float_t p[MAXCHENTRIESSMALL];
1052 //fTree->SetBranchAddress("nentries",&nentries);
1053 //fTree->SetBranchAddress("TOFentries",p);
1054 fChain->SetBranchAddress("nentries",&nentries);
1055 fChain->SetBranchAddress("TOFentries",p);
1057 Float_t ntracksTotalmean =0;
1058 for (Int_t ich=0; ich<nch; ich++){
1061 for (Int_t irun=0;irun<fNruns;irun++){
1062 ientry = i+irun*fNChannels;
1063 //fTree->GetEntry(ientry);
1064 fChain->GetEntry(ientry);
1065 ntracksTotalmean+=nentries/3;
1069 ntracksTotalmean/=nch;
1070 if (ntracksTotalmean < MEANENTRIES) {
1071 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1075 //filling ToT and Time arrays
1077 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1078 Float_t minToT = 0; // ns
1079 Float_t maxToT = 4.88; // ns
1080 TFile * fileProf=0x0;
1081 if(strstr(optionSave,"save")){
1082 fileProf = new TFile("TOFCalibSave.root","recreate");
1084 for (Int_t ich=0; ich<nch; ich++) {
1085 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1086 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1087 Double_t binsProfile[101]; // sized larger than necessary, the correct
1088 // dim being set in the booking of the profile
1089 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1090 Int_t ntracksTotal = 0;
1091 Int_t ntracksRun = 0;
1092 Int_t nusefulbins=0;
1095 for (Int_t irun=0;irun<fNruns;irun++){
1096 i = ch[ich]+irun*fNChannels;
1097 AliDebug(2,Form("Calibrating channel %i",i));
1098 //fTree->GetEntry(i);
1099 fChain->GetEntry(i);
1100 ntracksTotal+=nentries/3;
1102 if (ntracksTotal < MEANENTRIES) {
1103 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",i,ntracksTotal));
1107 for (Int_t irun=0;irun<fNruns;irun++){
1108 Int_t i = ch[ich]+irun*fNChannels;
1109 //fTree->GetEntry(i);
1110 fChain->GetEntry(i);
1111 ntracksRun=nentries/3;
1112 for (Int_t j=0;j<ntracksRun;j++){
1113 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1114 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1115 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1116 Float_t tot = p[idxexToT];
1117 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1118 meantime+=p[idxexTime]-p[idxexExTime];
1123 nusefulbins = FindBins(hToT,&binsProfile[0]);
1124 meantime/=ntracksTotal;
1125 for (Int_t j=1;j<=nusefulbins;j++) {
1126 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1129 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1130 for (Int_t irun=0;irun<fNruns;irun++){
1131 Int_t i = ch[ich]+irun*fNChannels;
1132 //fTree->GetEntry(i);
1133 fChain->GetEntry(i);
1134 ntracksRun=nentries/3;
1135 for (Int_t j=0;j<ntracksRun;j++){
1136 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1137 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1138 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1139 Float_t tot = p[idxexToT];
1140 Float_t time = p[idxexTime]-p[idxexExTime];
1141 AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1142 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1143 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1147 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1148 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1150 for(Int_t kk=0;kk<6;kk++){
1151 par[kk]=calibfunc->GetParameter(kk);
1152 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1155 if(strstr(optionSave,"save") && fileProf){
1156 TString profName=Form("Profile%06i",i);
1157 TString timeTotName=Form("TimeTot%06i",i);
1158 TString totName=Form("Tot%06i",i);
1159 TString deltaName=Form("Delta%06i",i);
1161 hSlewingProf->Write(profName);
1162 htimetot->Write(timeTotName);
1163 hToT->Write(totName);
1164 hdeltaTime->Write(deltaName);
1167 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1168 calChannel->SetSlewPar(par);
1171 delete hSlewingProf;
1179 if(strstr(optionSave,"save") && fileProf){
1184 WriteParOfflineOnCDB("TOF/Calib","valid");
1188 //----------------------------------------------------------------------------
1189 Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){
1191 // computing calibration parameters using the old profiling algo
1193 // 0 -> everything was ok
1194 // 1 -> no tree for calibration found
1195 // 2 -> not enough statistics to perform calibration
1196 // 3 -> problems with arrays
1198 TH1::AddDirectory(0);
1200 AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ;
1201 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1202 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1203 Float_t p[MAXCHENTRIESSMALL];
1205 Int_t ntracksTotal=0;
1206 //fTree->SetBranchAddress("nentries",&nentries);
1207 //fTree->SetBranchAddress("TOFentries",p);
1208 fChain->SetBranchAddress("nentries",&nentries);
1209 fChain->SetBranchAddress("TOFentries",p);
1211 for (Int_t irun=0;irun<fNruns;irun++){
1212 Int_t i = ich+irun*fNChannels;
1213 //fTree->GetEntry(i);
1214 fChain->GetEntry(i);
1215 ntracksTotal+=nentries/3;
1218 if (ntracksTotal < MEANENTRIES) {
1219 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1223 TH1F * hProf = new TH1F();
1224 hProf = Profile(ich);
1225 hProf->Fit("pol5",optionFit,"",0,4);
1226 TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
1228 for(Int_t kk=0;kk<6;kk++){
1229 par[kk]=calibfunc->GetParameter(kk);
1230 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1233 if(strstr(optionSave,"save")){
1234 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1236 TString profName=Form("Profile%06i",ich);
1237 hProf->Write(profName);
1245 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich);
1246 calChannel->SetSlewPar(par);
1247 WriteParOfflineOnCDB("TOF/Calib","valid");
1250 //----------------------------------------------------------------------------
1251 Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
1253 // calibrating the whole TOF
1254 // computing calibration parameters
1256 // 0 -> everything was ok
1257 // 1 -> no tree for calibration found
1258 // 2 -> not enough statistics to perform calibration
1259 // 3 -> problems with arrays
1261 TH1::AddDirectory(0);
1263 AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ;
1264 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1265 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1267 TFile * fileProf=0x0;
1268 if(strstr(optionSave,"save")){
1269 fileProf = new TFile("TOFCalibSave.root","recreate");
1272 Float_t p[MAXCHENTRIESSMALL];
1274 //fTree->SetBranchAddress("nentries",&nentries);
1275 //fTree->SetBranchAddress("TOFentries",p);
1276 fChain->SetBranchAddress("nentries",&nentries);
1277 fChain->SetBranchAddress("TOFentries",p);
1279 Float_t ntracksTotalmean =0;
1280 for (Int_t ii=0; ii<fNChannels; ii++){
1281 for (Int_t irun=0;irun<fNruns;irun++){
1282 Int_t i = ii+irun*fNChannels;
1283 //fTree->GetEntry(i);
1284 fChain->GetEntry(i);
1285 ntracksTotalmean+=nentries/3;
1289 ntracksTotalmean/=fNChannels;
1290 if (ntracksTotalmean < MEANENTRIES) {
1291 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1295 //filling ToT and Time arrays
1297 Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps
1298 Float_t minToT = 0; // ns
1299 Float_t maxToT = 4.88;// ns
1300 for (Int_t ii=0; ii<fNChannels; ii++) {
1301 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1302 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1303 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1304 if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
1306 Int_t nusefulbins=0;
1307 Double_t binsProfile[101]; // sized larger than necessary, the correct
1308 // dim being set in the booking of the profile
1309 Int_t ntracksRun = 0;
1310 Int_t ntracksTotal = 0;
1311 for (Int_t irun=0;irun<fNruns;irun++){
1312 Int_t i = ii+irun*fNChannels;
1313 //fTree->GetEntry(i);
1314 fChain->GetEntry(i);
1315 ntracksTotal+=nentries/3;
1317 if (ntracksTotal < MEANENTRIES) {
1318 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",ii,ntracksTotal));
1322 for (Int_t irun=0;irun<fNruns;irun++){
1323 Int_t i = ii+irun*fNChannels;
1324 //fTree->GetEntry(i);
1325 fChain->GetEntry(i);
1326 ntracksRun=nentries/3;
1327 for (Int_t j=0;j<ntracksRun;j++){
1328 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1329 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1330 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1331 Float_t tot = p[idxexToT];
1332 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1333 meantime+=p[idxexTime]-p[idxexExTime];
1337 nusefulbins = FindBins(hToT,&binsProfile[0]);
1338 meantime/=ntracksTotal;
1339 for (Int_t j=0;j<nusefulbins;j++) {
1340 AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j]));
1342 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1343 for (Int_t irun=0;irun<fNruns;irun++){
1344 Int_t i = ii+irun*fNChannels;
1345 //fTree->GetEntry(i);
1346 fChain->GetEntry(i);
1347 ntracksRun=nentries/3;
1348 for (Int_t j=0;j<ntracksRun;j++){
1349 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1350 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1351 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1352 Float_t tot = p[idxexToT];
1353 Float_t time = p[idxexTime]-p[idxexExTime];
1354 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1355 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1356 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1359 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1360 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1362 for(Int_t kk=0;kk<6;kk++){
1363 par[kk]=calibfunc->GetParameter(kk);
1364 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1367 if(strstr(optionSave,"save") && fileProf){
1368 TString profName=Form("Profile%06i",ii);
1369 TString timeTotName=Form("TimeTot%06i",ii);
1370 TString totName=Form("Tot%06i",ii);
1371 TString deltaName=Form("Delta%06i",ii);
1373 hSlewingProf->Write(profName);
1374 htimetot->Write(timeTotName);
1375 hToT->Write(totName);
1376 hdeltaTime->Write(deltaName);
1378 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii);
1379 calChannel->SetSlewPar(par);
1383 delete hSlewingProf;
1391 if(strstr(optionSave,"save")){
1396 WriteParOfflineOnCDB("TOF/Calib","valid");
1400 //-----------------------------------------------------------------------
1401 TH1F* AliTOFcalib::Profile(Int_t ich)
1405 Float_t p[MAXCHENTRIESSMALL];
1407 //fTree->SetBranchAddress("nentries",&nentries);
1408 //fTree->SetBranchAddress("TOFentries",p);
1409 fChain->SetBranchAddress("nentries",&nentries);
1410 fChain->SetBranchAddress("TOFentries",p);
1412 //Prepare histograms for Slewing Correction
1413 const Int_t knbinToT = 100;
1414 Int_t nbinTime = 200;
1415 Float_t minTime = -5.5; //ns
1416 Float_t maxTime = 5.5; //ns
1417 Float_t minToT = 0; //ns
1418 Float_t maxToT = 5.; //ns
1419 Float_t deltaToT = (maxToT-minToT)/knbinToT;
1420 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];
1421 Int_t n[knbinToT+1], nentrx[knbinToT+1];
1422 Double_t sigmaToT[knbinToT+1];
1423 for (Int_t i = 0; i < knbinToT+1 ; i++){
1441 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
1442 Int_t ntracksRun = 0;
1443 TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
1444 for (Int_t irun=0;irun<fNruns;irun++){
1445 Int_t i = ich+irun*fNChannels;
1446 //fTree->GetEntry(i);
1447 fChain->GetEntry(i);
1448 ntracksRun=nentries/3;
1449 for (Int_t j=0;j<ntracksRun;j++){
1450 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1451 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1452 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1453 Float_t tot = p[idxexToT];
1454 Float_t time = p[idxexTime]-p[idxexExTime];
1455 Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
1456 if ((tot != 0) && ( time!= 0)){
1458 vTime2[nx]+=time*time;
1462 hSlewing->Fill(tot,time);
1466 Int_t nbinsToT=hSlewing->GetNbinsX();
1467 if (nbinsToT != knbinToT) {
1468 AliError("Profile :: incompatible numbers of bins");
1473 for (Int_t i=1;i<=nbinsToT;i++){
1475 n[usefulBins]+=nentrx[i];
1476 if (n[usefulBins]==0 && i == nbinsToT) {
1479 meanTime[usefulBins]+=vTime[i];
1480 meanTime2[usefulBins]+=vTime2[i];
1481 meanToT[usefulBins]+=vToT[i];
1482 meanToT2[usefulBins]+=vToT2[i];
1483 if (n[usefulBins]<10 && i!=nbinsToT) continue;
1484 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
1485 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
1486 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1487 *(meanTime2[usefulBins]-meanTime[usefulBins]
1488 *meanTime[usefulBins]/n[usefulBins]));
1489 if ((1./n[usefulBins]/n[usefulBins]
1490 *(meanToT2[usefulBins]-meanToT[usefulBins]
1491 *meanToT[usefulBins]/n[usefulBins]))< 0) {
1492 AliError(" too small radical" );
1493 sigmaToT[usefulBins]=0;
1496 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1497 *(meanToT2[usefulBins]-meanToT[usefulBins]
1498 *meanToT[usefulBins]/n[usefulBins]));
1503 for (Int_t i=0;i<usefulBins;i++){
1504 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
1505 histo->Fill(mToT[i],mTime[i]);
1506 histo->SetBinError(binN,sigmaTime[i]);
1513 //----------------------------------------------------------------------------
1514 Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
1516 // to determine the bins for ToT histo
1520 Int_t nbin = h->GetNbinsX();
1521 Int_t nentries = (Int_t)h->GetEntries();
1522 Float_t max = h->GetBinLowEdge(nbin);
1523 Int_t nusefulbins=0;
1525 // setting maxvalue of entries per bin
1526 if (nentries <= 60) maxcont = 2;
1527 else if (nentries <= 100) maxcont = 5;
1528 else if (nentries <= 500) maxcont = 10;
1530 for (Int_t j=1;j<=nbin;j++) {
1531 cont += (Int_t)h->GetBinContent(j);
1535 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1544 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1545 binsProfile[nusefulbins]=max;
1548 binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);