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 AliCDBEntry *entry = man->Get(out,nrun);
465 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
468 if(!entry->GetObject()){
469 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
473 fTOFCalOnline =(TObjArray*)entry->GetObject();
478 //_____________________________________________________________________________
480 Bool_t AliTOFcalib::ReadParOnlinePulserFromCDB(Char_t *sel, Int_t nrun)
482 //Read calibration parameters from pulser from the CDB
483 AliCDBManager *man = AliCDBManager::Instance();
484 Char_t *sel1 = "Pulser" ;
486 sprintf(out,"%s/%s",sel,sel1);
487 AliCDBEntry *entry = man->Get(out,nrun);
489 AliFatal("Exiting, no CDB object (Pulser) found!!!");
492 if(!entry->GetObject()){
493 AliFatal("Exiting, no CDB object (Pulser) found!!!");
497 fTOFCalOnlinePulser =(TObjArray*)entry->GetObject();
502 //_____________________________________________________________________________
504 Bool_t AliTOFcalib::ReadParOnlineNoiseFromCDB(Char_t *sel, Int_t nrun)
506 //Read calibration parameters from noise from the CDB
507 AliCDBManager *man = AliCDBManager::Instance();
508 Char_t *sel1 = "Noise" ;
510 sprintf(out,"%s/%s",sel,sel1);
511 AliCDBEntry *entry = man->Get(out,nrun);
513 AliFatal("Exiting, no CDB object (Noise) found!!!");
516 if(!entry->GetObject()){
517 AliFatal("Exiting, no CDB object (Noise) found!!!");
521 fTOFCalOnlineNoise =(TObjArray*)entry->GetObject();
526 //_____________________________________________________________________________
528 Bool_t AliTOFcalib::ReadParOnlineHWFromCDB(Char_t *sel, Int_t nrun)
530 //Read calibration parameters from hardware from the CDB
531 AliCDBManager *man = AliCDBManager::Instance();
532 Char_t *sel1 = "HW" ;
534 sprintf(out,"%s/%s",sel,sel1);
535 AliCDBEntry *entry = man->Get(out,nrun);
537 AliFatal("Exiting, no CDB object (HW map) found!!!");
540 if(!entry->GetObject()){
541 AliFatal("Exiting, no CDB object (HW map) found!!!");
545 fTOFCalOnlineHW =(TObjArray*)entry->GetObject();
550 //_____________________________________________________________________________
552 Bool_t AliTOFcalib::ReadParOfflineFromCDB(Char_t *sel, Int_t nrun)
554 //Read calibration parameters from the CDB
555 AliCDBManager *man = AliCDBManager::Instance();
556 Char_t *sel1 = "ParOffline" ;
558 sprintf(out,"%s/%s",sel,sel1);
559 AliCDBEntry *entry = man->Get(out,nrun);
561 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
564 if(!entry->GetObject()){
565 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
568 AliCDBMetaData * md = entry->GetMetaData();
569 fkValidity = md->GetComment();
570 fTOFCalOffline =(TObjArray*)entry->GetObject();
575 //_____________________________________________________________________________
576 void AliTOFcalib::WriteSimHistoOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, TH1F *histo){
577 //Write Sim miscalibration parameters to the CDB
580 AliCDBManager *man = AliCDBManager::Instance();
581 Char_t *sel1 = "SimHisto" ;
583 sprintf(out,"%s/%s",sel,sel1);
584 AliCDBMetaData *mdhisto = new AliCDBMetaData();
585 mdhisto->SetResponsible("Chiara Zampolli");
586 AliCDBId id(out,minrun,maxrun);
587 man->Put(fTOFSimToT,id,mdhisto);
590 //_____________________________________________________________________________
591 Bool_t AliTOFcalib::ReadSimHistoFromCDB(Char_t *sel, Int_t nrun)
593 //Read miscalibration parameters from the CDB
594 AliCDBManager *man = AliCDBManager::Instance();
598 Char_t *sel1 = "SimHisto" ;
600 sprintf(out,"%s/%s",sel,sel1);
601 AliCDBEntry *entry = man->Get(out,nrun);
603 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
606 if(!entry->GetObject()){
607 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
610 TH1F *histo =(TH1F*)entry->GetObject();
614 //_____________________________________________________________________________
615 void AliTOFcalib::WriteRecParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){
616 //Write reconstruction parameters to the CDB
618 AliCDBManager *man = AliCDBManager::Instance();
619 AliCDBMetaData *md = new AliCDBMetaData();
620 md->SetResponsible("Silvia Arcelli");
621 Char_t *sel1 = "RecPar" ;
623 sprintf(out,"%s/%s",sel,sel1);
624 AliCDBId id(out,minrun,maxrun);
625 man->Put(param,id,md);
628 //_____________________________________________________________________________
629 AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(Char_t *sel, Int_t nrun)
631 //Read reconstruction parameters from the CDB
632 AliCDBManager *man = AliCDBManager::Instance();
633 Char_t *sel1 = "RecPar" ;
635 sprintf(out,"%s/%s",sel,sel1);
636 AliCDBEntry *entry = man->Get(out,nrun);
638 AliFatal("Exiting, no CDB object (RecPar) found!!!");
641 if(!entry->GetObject()){
642 AliFatal("Exiting, no CDB object (RecPar) found!!!");
646 AliTOFRecoParam *param=(AliTOFRecoParam*)entry->GetObject();
649 //-----------------------------------------------------------------------------
650 // Calibration methods
651 //-----------------------------------------------------------------------------
652 void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
654 // creating the chain with the trees for calibration
655 // collecting them from reference data
656 // from minrun to maxrun
658 Float_t p[CHENTRIESSMALL];
660 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
661 fTree->Branch("nentries",&nentries,"nentries/I");
662 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
663 AliCDBManager *man = AliCDBManager::Instance();
664 AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT");
665 for (Int_t irun = minrun;irun<=maxrun;irun++){
666 AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
668 AliInfo(Form("No entry found for run %i",irun));
671 TTree *tree = new TTree();
672 tree = (TTree*)entry->GetObject();
673 tree->SetBranchAddress("nentries",&nentries);
674 tree->SetBranchAddress("TOFentries",p);
675 fTree->CopyEntries(tree);
680 AliInfo(Form("Number of runs being analyzed %i",fNruns));
682 //-----------------------------------------------------------------------------
683 void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
685 // creating the chain with the trees for calibration
686 // collecting them from the Grid
687 // from minrun to maxrun
689 Float_t p[CHENTRIESSMALL];
691 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
692 fTree->SetDirectory(0);
693 fTree->Branch("nentries",&nentries,"nentries/I");
694 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
695 AliInfo("connected to alien");
696 TGrid::Connect("alien://");
698 Char_t filename[100];
699 for (Int_t irun = minrun;irun<=maxrun;irun++){
700 sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
701 TFile *filegrid = TFile::Open(filename,"READ");
702 TTree *tree = (TTree*)filegrid->Get("T");
703 tree->SetBranchAddress("nentries",&nentries);
704 tree->SetBranchAddress("TOFentries",p);
705 fTree->CopyEntries(tree);
710 AliInfo(Form("Number of runs being analyzed %i",fNruns));
712 //-----------------------------------------------------------------------------
713 void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
715 // creating the tree with the trees for calibration
716 // collecting them from reference data (from file)
717 // from minrun to maxrun
719 Float_t p[CHENTRIESSMALL];
721 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
722 fTree->SetDirectory(0);
723 fTree->Branch("nentries",&nentries,"nentries/I");
724 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
725 Char_t filename[100];
726 for (Int_t irun = minrun;irun<=maxrun;irun++){
727 sprintf(filename,"$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
728 TFile *file = new TFile(filename,"READ");
729 TTree *tree = (TTree*)file->Get("T");
730 tree->SetBranchAddress("nentries",&nentries);
731 tree->SetBranchAddress("TOFentries",p);
732 fTree->CopyEntries(tree);
739 AliInfo(Form("Number of runs being analyzed %i",fNruns));
741 //-----------------------------------------------------------------------------
742 void AliTOFcalib::CreateChainFromGrid(Int_t minrun, Int_t maxrun){
744 // creating the chain with the trees for calibration
745 // collecting them from the Grid
746 // from minrun to maxrun
748 fChain = new TChain("T");
749 AliInfo("connected to alien");
750 TGrid::Connect("alien://");
752 Char_t filename[100];
753 for (Int_t irun = minrun;irun<=maxrun;irun++){
754 sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
755 fChain->Add(filename);
759 AliInfo(Form("Number of runs being analyzed %i",fNruns));
761 //-----------------------------------------------------------------------------
762 Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
764 // calibrating summing more than one channels
765 // computing calibration parameters
767 // 0 -> everything was ok
768 // 1 -> no tree for calibration found
769 // 2 -> not enough statistics to perform calibration
770 // 3 -> problems with arrays
772 TH1::AddDirectory(0);
774 AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ;
775 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
776 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
778 Float_t p[CHENTRIESSMALL];
780 //fTree->SetBranchAddress("nentries",&nentries);
781 //fTree->SetBranchAddress("TOFentries",p);
782 fChain->SetBranchAddress("nentries",&nentries);
783 fChain->SetBranchAddress("TOFentries",p);
785 Float_t ntracksTotalmean =0;
786 for (Int_t i=ichmin; i<ichmax; i++){
788 for (Int_t irun=0;irun<fNruns;irun++){
789 ientry = i+irun*fNChannels;
790 //fTree->GetEntry(ientry);
791 fChain->GetEntry(ientry);
792 Int_t ntracksRun=nentries/3;
793 ntracksTotalmean+=ntracksRun;
797 if (ntracksTotalmean < MEANENTRIES) {
798 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
802 //filling ToT and Time arrays
804 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
805 Float_t minToT = 0; // ns
806 Float_t maxToT = 4.88; // ns
808 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
809 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
810 Int_t ntracksTotal = 0;
811 Int_t ntracksRun = 0;
812 Double_t binsProfile[101]; // sized larger than necessary, the correct
813 // dim being set in the booking of the profile
816 for (Int_t i = ichmin;i<ichmax;i++){
818 for (Int_t irun=0;irun<fNruns;irun++){
819 ientry = i+irun*fNChannels;
820 //fTree->GetEntry(ientry);
821 fChain->GetEntry(ientry);
822 ntracksTotal+=nentries/3;
823 ntracksRun=nentries/3;
824 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun));
825 for (Int_t j=0;j<ntracksRun;j++){
826 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
827 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
828 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
829 Float_t tot = p[idxexToT];
830 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
831 meantime+=p[idxexTime]-p[idxexExTime];
836 nusefulbins = FindBins(hToT,&binsProfile[0]);
837 meantime/=ntracksTotal;
838 AliDebug(2, Form("meantime = %f",meantime));
840 for (Int_t j=1;j<=nusefulbins;j++) {
841 AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j]));
844 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
845 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
847 for (Int_t irun=0;irun<fNruns;irun++){
849 for (Int_t i=ichmin; i<ichmax; i++){
850 ientry = i+irun*fNChannels;
851 //fTree->GetEntry(ientry);
852 fChain->GetEntry(ientry);
853 ntracksRun=nentries/3;
854 for (Int_t j=0;j<ntracksRun;j++){
855 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
856 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
857 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
858 Float_t tot = p[idxexToT];
859 Float_t time = p[idxexTime]-p[idxexExTime];
860 AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
861 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
862 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
867 hSlewingProf->Fit("pol5",optionFit,"",0,4);
868 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
870 for(Int_t kk=0;kk<6;kk++){
871 par[kk]=calibfunc->GetParameter(kk);
872 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
875 if(strstr(optionSave,"save")){
876 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
878 TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
879 TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
880 TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
881 TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
882 hSlewingProf->Write(profName);
883 htimetot->Write(timeTotName);
884 hToT->Write(totName);
885 hdeltaTime->Write(deltaName);
900 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin);
901 calChannel->SetSlewPar(par);
902 WriteParOfflineOnCDB("TOF/Calib","valid");
905 //----------------------------------------------------------------------------
906 Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
908 // computing calibration parameters for channel i
910 // 0 -> everything was ok
911 // 1 -> no tree for calibration found
912 // 2 -> not enough statistics to perform calibration
913 // 3 -> problems with arrays
915 TH1::AddDirectory(0);
917 AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ;
918 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
919 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
921 Float_t p[MAXCHENTRIESSMALL];
923 //fTree->SetBranchAddress("nentries",&nentries);
924 //fTree->SetBranchAddress("TOFentries",p);
925 fChain->SetBranchAddress("nentries",&nentries);
926 fChain->SetBranchAddress("TOFentries",p);
928 Float_t ntracksTotal =0;
929 for (Int_t irun=0;irun<fNruns;irun++){
931 ientry = i+irun*fNChannels;
932 //fTree->GetEntry(ientry);
933 fChain->GetEntry(ientry);
934 ntracksTotal+=nentries/3;
937 if (ntracksTotal < MEANENTRIES) {
938 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
942 //filling ToT and Time arrays
944 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
945 Float_t minToT = 0; // ns
946 Float_t maxToT = 4.88; // ns
948 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
949 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
950 Int_t ntracksRun = 0;
951 Double_t binsProfile[101]; // sized larger than necessary, the correct
952 // dim being set in the booking of the profile
955 for (Int_t irun=0;irun<fNruns;irun++){
957 ientry = i+irun*fNChannels;
958 //fTree->GetEntry(ientry);
959 fChain->GetEntry(ientry);
960 ntracksRun=nentries/3;
961 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun));
962 for (Int_t j=0;j<ntracksRun;j++){
963 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
964 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
965 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
966 Float_t tot = p[idxexToT];
967 meantime+=p[idxexTime]-p[idxexExTime];
968 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
973 nusefulbins = FindBins(hToT,&binsProfile[0]);
974 meantime/=ntracksTotal;
975 AliDebug(2,Form("meantime = %f",meantime));
977 for (Int_t j=1;j<=nusefulbins;j++) {
978 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
981 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
982 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
983 for (Int_t irun=0;irun<fNruns;irun++){
985 ientry = i+irun*fNChannels;
986 //fTree->GetEntry(ientry);
987 fChain->GetEntry(ientry);
988 ntracksRun=nentries/3;
989 for (Int_t j=0;j<ntracksRun;j++){
990 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
991 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
992 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
993 Float_t tot = p[idxexToT];
994 Float_t time = p[idxexTime]-p[idxexExTime];
995 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
996 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
997 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1001 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1002 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1004 for(Int_t kk=0;kk<6;kk++){
1005 par[kk]=calibfunc->GetParameter(kk);
1006 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1010 if(strstr(optionSave,"save")){
1011 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1013 TString profName=Form("Profile%06i",i);
1014 TString timeTotName=Form("TimeTot%06i",i);
1015 TString totName=Form("Tot%06i",i);
1016 TString deltaName=Form("Delta%06i",i);
1017 hSlewingProf->Write(profName);
1018 htimetot->Write(timeTotName);
1019 hToT->Write(totName);
1020 hdeltaTime->Write(deltaName);
1028 delete hSlewingProf;
1035 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1036 calChannel->SetSlewPar(par);
1037 WriteParOfflineOnCDB("TOF/Calib","valid");
1040 //----------------------------------------------------------------------------
1041 Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
1043 // calibrating an array of channels
1044 // computing calibration parameters
1046 // 0 -> everything was ok
1047 // 1 -> no tree for calibration found
1048 // 2 -> not enough statistics to perform calibration
1049 // 3 -> problems with arrays
1051 TH1::AddDirectory(0);
1053 AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ;
1054 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1055 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1056 for (Int_t ich=0; ich<nch; ich++){
1058 AliInfo(Form("Calibrating channel = %i",i )) ;
1060 Float_t p[MAXCHENTRIESSMALL];
1062 //fTree->SetBranchAddress("nentries",&nentries);
1063 //fTree->SetBranchAddress("TOFentries",p);
1064 fChain->SetBranchAddress("nentries",&nentries);
1065 fChain->SetBranchAddress("TOFentries",p);
1067 Float_t ntracksTotalmean =0;
1068 for (Int_t ich=0; ich<nch; ich++){
1071 for (Int_t irun=0;irun<fNruns;irun++){
1072 ientry = i+irun*fNChannels;
1073 //fTree->GetEntry(ientry);
1074 fChain->GetEntry(ientry);
1075 ntracksTotalmean+=nentries/3;
1079 ntracksTotalmean/=nch;
1080 if (ntracksTotalmean < MEANENTRIES) {
1081 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1085 //filling ToT and Time arrays
1087 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1088 Float_t minToT = 0; // ns
1089 Float_t maxToT = 4.88; // ns
1090 TFile * fileProf=0x0;
1091 if(strstr(optionSave,"save")){
1092 fileProf = new TFile("TOFCalibSave.root","recreate");
1094 for (Int_t ich=0; ich<nch; ich++) {
1095 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1096 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1097 Double_t binsProfile[101]; // sized larger than necessary, the correct
1098 // dim being set in the booking of the profile
1099 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1100 Int_t ntracksTotal = 0;
1101 Int_t ntracksRun = 0;
1102 Int_t nusefulbins=0;
1105 for (Int_t irun=0;irun<fNruns;irun++){
1106 i = ch[ich]+irun*fNChannels;
1107 AliDebug(2,Form("Calibrating channel %i",i));
1108 //fTree->GetEntry(i);
1109 fChain->GetEntry(i);
1110 ntracksTotal+=nentries/3;
1112 if (ntracksTotal < MEANENTRIES) {
1113 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",i,ntracksTotal));
1117 for (Int_t irun=0;irun<fNruns;irun++){
1118 Int_t i = ch[ich]+irun*fNChannels;
1119 //fTree->GetEntry(i);
1120 fChain->GetEntry(i);
1121 ntracksRun=nentries/3;
1122 for (Int_t j=0;j<ntracksRun;j++){
1123 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1124 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1125 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1126 Float_t tot = p[idxexToT];
1127 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1128 meantime+=p[idxexTime]-p[idxexExTime];
1133 nusefulbins = FindBins(hToT,&binsProfile[0]);
1134 meantime/=ntracksTotal;
1135 for (Int_t j=1;j<=nusefulbins;j++) {
1136 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1139 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1140 for (Int_t irun=0;irun<fNruns;irun++){
1141 Int_t i = ch[ich]+irun*fNChannels;
1142 //fTree->GetEntry(i);
1143 fChain->GetEntry(i);
1144 ntracksRun=nentries/3;
1145 for (Int_t j=0;j<ntracksRun;j++){
1146 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1147 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1148 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1149 Float_t tot = p[idxexToT];
1150 Float_t time = p[idxexTime]-p[idxexExTime];
1151 AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1152 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1153 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1157 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1158 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1160 for(Int_t kk=0;kk<6;kk++){
1161 par[kk]=calibfunc->GetParameter(kk);
1162 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1165 if(strstr(optionSave,"save") && fileProf){
1166 TString profName=Form("Profile%06i",i);
1167 TString timeTotName=Form("TimeTot%06i",i);
1168 TString totName=Form("Tot%06i",i);
1169 TString deltaName=Form("Delta%06i",i);
1171 hSlewingProf->Write(profName);
1172 htimetot->Write(timeTotName);
1173 hToT->Write(totName);
1174 hdeltaTime->Write(deltaName);
1177 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1178 calChannel->SetSlewPar(par);
1181 delete hSlewingProf;
1189 if(strstr(optionSave,"save") && fileProf){
1194 WriteParOfflineOnCDB("TOF/Calib","valid");
1198 //----------------------------------------------------------------------------
1199 Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){
1201 // computing calibration parameters using the old profiling algo
1203 // 0 -> everything was ok
1204 // 1 -> no tree for calibration found
1205 // 2 -> not enough statistics to perform calibration
1206 // 3 -> problems with arrays
1208 TH1::AddDirectory(0);
1210 AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ;
1211 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1212 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1213 Float_t p[MAXCHENTRIESSMALL];
1215 Int_t ntracksTotal=0;
1216 //fTree->SetBranchAddress("nentries",&nentries);
1217 //fTree->SetBranchAddress("TOFentries",p);
1218 fChain->SetBranchAddress("nentries",&nentries);
1219 fChain->SetBranchAddress("TOFentries",p);
1221 for (Int_t irun=0;irun<fNruns;irun++){
1222 Int_t i = ich+irun*fNChannels;
1223 //fTree->GetEntry(i);
1224 fChain->GetEntry(i);
1225 ntracksTotal+=nentries/3;
1228 if (ntracksTotal < MEANENTRIES) {
1229 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1233 TH1F * hProf = new TH1F();
1234 hProf = Profile(ich);
1235 hProf->Fit("pol5",optionFit,"",0,4);
1236 TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
1238 for(Int_t kk=0;kk<6;kk++){
1239 par[kk]=calibfunc->GetParameter(kk);
1240 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1243 if(strstr(optionSave,"save")){
1244 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1246 TString profName=Form("Profile%06i",ich);
1247 hProf->Write(profName);
1255 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich);
1256 calChannel->SetSlewPar(par);
1257 WriteParOfflineOnCDB("TOF/Calib","valid");
1260 //----------------------------------------------------------------------------
1261 Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
1263 // calibrating the whole TOF
1264 // computing calibration parameters
1266 // 0 -> everything was ok
1267 // 1 -> no tree for calibration found
1268 // 2 -> not enough statistics to perform calibration
1269 // 3 -> problems with arrays
1271 TH1::AddDirectory(0);
1273 AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ;
1274 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1275 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1277 TFile * fileProf=0x0;
1278 if(strstr(optionSave,"save")){
1279 fileProf = new TFile("TOFCalibSave.root","recreate");
1282 Float_t p[MAXCHENTRIESSMALL];
1284 //fTree->SetBranchAddress("nentries",&nentries);
1285 //fTree->SetBranchAddress("TOFentries",p);
1286 fChain->SetBranchAddress("nentries",&nentries);
1287 fChain->SetBranchAddress("TOFentries",p);
1289 Float_t ntracksTotalmean =0;
1290 for (Int_t ii=0; ii<fNChannels; ii++){
1291 for (Int_t irun=0;irun<fNruns;irun++){
1292 Int_t i = ii+irun*fNChannels;
1293 //fTree->GetEntry(i);
1294 fChain->GetEntry(i);
1295 ntracksTotalmean+=nentries/3;
1299 ntracksTotalmean/=fNChannels;
1300 if (ntracksTotalmean < MEANENTRIES) {
1301 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1305 //filling ToT and Time arrays
1307 Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps
1308 Float_t minToT = 0; // ns
1309 Float_t maxToT = 4.88;// ns
1310 for (Int_t ii=0; ii<fNChannels; ii++) {
1311 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1312 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1313 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1314 if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
1316 Int_t nusefulbins=0;
1317 Double_t binsProfile[101]; // sized larger than necessary, the correct
1318 // dim being set in the booking of the profile
1319 Int_t ntracksRun = 0;
1320 Int_t ntracksTotal = 0;
1321 for (Int_t irun=0;irun<fNruns;irun++){
1322 Int_t i = ii+irun*fNChannels;
1323 //fTree->GetEntry(i);
1324 fChain->GetEntry(i);
1325 ntracksTotal+=nentries/3;
1327 if (ntracksTotal < MEANENTRIES) {
1328 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",ii,ntracksTotal));
1332 for (Int_t irun=0;irun<fNruns;irun++){
1333 Int_t i = ii+irun*fNChannels;
1334 //fTree->GetEntry(i);
1335 fChain->GetEntry(i);
1336 ntracksRun=nentries/3;
1337 for (Int_t j=0;j<ntracksRun;j++){
1338 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1339 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1340 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1341 Float_t tot = p[idxexToT];
1342 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1343 meantime+=p[idxexTime]-p[idxexExTime];
1347 nusefulbins = FindBins(hToT,&binsProfile[0]);
1348 meantime/=ntracksTotal;
1349 for (Int_t j=0;j<nusefulbins;j++) {
1350 AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j]));
1352 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1353 for (Int_t irun=0;irun<fNruns;irun++){
1354 Int_t i = ii+irun*fNChannels;
1355 //fTree->GetEntry(i);
1356 fChain->GetEntry(i);
1357 ntracksRun=nentries/3;
1358 for (Int_t j=0;j<ntracksRun;j++){
1359 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1360 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1361 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1362 Float_t tot = p[idxexToT];
1363 Float_t time = p[idxexTime]-p[idxexExTime];
1364 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1365 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1366 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1369 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1370 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1372 for(Int_t kk=0;kk<6;kk++){
1373 par[kk]=calibfunc->GetParameter(kk);
1374 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1377 if(strstr(optionSave,"save") && fileProf){
1378 TString profName=Form("Profile%06i",ii);
1379 TString timeTotName=Form("TimeTot%06i",ii);
1380 TString totName=Form("Tot%06i",ii);
1381 TString deltaName=Form("Delta%06i",ii);
1383 hSlewingProf->Write(profName);
1384 htimetot->Write(timeTotName);
1385 hToT->Write(totName);
1386 hdeltaTime->Write(deltaName);
1388 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii);
1389 calChannel->SetSlewPar(par);
1393 delete hSlewingProf;
1401 if(strstr(optionSave,"save")){
1406 WriteParOfflineOnCDB("TOF/Calib","valid");
1410 //-----------------------------------------------------------------------
1411 TH1F* AliTOFcalib::Profile(Int_t ich)
1415 Float_t p[MAXCHENTRIESSMALL];
1417 //fTree->SetBranchAddress("nentries",&nentries);
1418 //fTree->SetBranchAddress("TOFentries",p);
1419 fChain->SetBranchAddress("nentries",&nentries);
1420 fChain->SetBranchAddress("TOFentries",p);
1422 //Prepare histograms for Slewing Correction
1423 const Int_t knbinToT = 100;
1424 Int_t nbinTime = 200;
1425 Float_t minTime = -5.5; //ns
1426 Float_t maxTime = 5.5; //ns
1427 Float_t minToT = 0; //ns
1428 Float_t maxToT = 5.; //ns
1429 Float_t deltaToT = (maxToT-minToT)/knbinToT;
1430 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];
1431 Int_t n[knbinToT+1], nentrx[knbinToT+1];
1432 Double_t sigmaToT[knbinToT+1];
1433 for (Int_t i = 0; i < knbinToT+1 ; i++){
1451 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
1452 Int_t ntracksRun = 0;
1453 TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
1454 for (Int_t irun=0;irun<fNruns;irun++){
1455 Int_t i = ich+irun*fNChannels;
1456 //fTree->GetEntry(i);
1457 fChain->GetEntry(i);
1458 ntracksRun=nentries/3;
1459 for (Int_t j=0;j<ntracksRun;j++){
1460 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1461 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1462 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1463 Float_t tot = p[idxexToT];
1464 Float_t time = p[idxexTime]-p[idxexExTime];
1465 Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
1466 if ((tot != 0) && ( time!= 0)){
1468 vTime2[nx]+=time*time;
1472 hSlewing->Fill(tot,time);
1476 Int_t nbinsToT=hSlewing->GetNbinsX();
1477 if (nbinsToT != knbinToT) {
1478 AliError("Profile :: incompatible numbers of bins");
1483 for (Int_t i=1;i<=nbinsToT;i++){
1485 n[usefulBins]+=nentrx[i];
1486 if (n[usefulBins]==0 && i == nbinsToT) {
1489 meanTime[usefulBins]+=vTime[i];
1490 meanTime2[usefulBins]+=vTime2[i];
1491 meanToT[usefulBins]+=vToT[i];
1492 meanToT2[usefulBins]+=vToT2[i];
1493 if (n[usefulBins]<10 && i!=nbinsToT) continue;
1494 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
1495 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
1496 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1497 *(meanTime2[usefulBins]-meanTime[usefulBins]
1498 *meanTime[usefulBins]/n[usefulBins]));
1499 if ((1./n[usefulBins]/n[usefulBins]
1500 *(meanToT2[usefulBins]-meanToT[usefulBins]
1501 *meanToT[usefulBins]/n[usefulBins]))< 0) {
1502 AliError(" too small radical" );
1503 sigmaToT[usefulBins]=0;
1506 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1507 *(meanToT2[usefulBins]-meanToT[usefulBins]
1508 *meanToT[usefulBins]/n[usefulBins]));
1513 for (Int_t i=0;i<usefulBins;i++){
1514 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
1515 histo->Fill(mToT[i],mTime[i]);
1516 histo->SetBinError(binN,sigmaTime[i]);
1523 //----------------------------------------------------------------------------
1524 Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
1526 // to determine the bins for ToT histo
1530 Int_t nbin = h->GetNbinsX();
1531 Int_t nentries = (Int_t)h->GetEntries();
1532 Float_t max = h->GetBinLowEdge(nbin);
1533 Int_t nusefulbins=0;
1535 // setting maxvalue of entries per bin
1536 if (nentries <= 60) maxcont = 2;
1537 else if (nentries <= 100) maxcont = 5;
1538 else if (nentries <= 500) maxcont = 10;
1540 for (Int_t j=1;j<=nbin;j++) {
1541 cont += (Int_t)h->GetBinContent(j);
1545 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1554 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1555 binsProfile[nusefulbins]=max;
1558 binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);