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 ///////////////////////////////////////////////////////////////////////////////
98 #include "AliCDBEntry.h"
99 #include "AliCDBRunRange.h"
100 #include "AliCDBId.h"
101 #include "AliCDBManager.h"
102 #include "AliCDBStorage.h"
103 #include "AliCDBMetaData.h"
104 //#include "AliESDtrack.h"
105 //#include "AliESD.h"
108 #include "AliTOFcalib.h"
109 #include "AliTOFChannelOnlineArray.h"
110 #include "AliTOFChannelOnline.h"
111 #include "AliTOFChannelOnlineStatus.h"
112 #include "AliTOFChannelOnlineStatusArray.h"
113 #include "AliTOFChannelOffline.h"
114 #include "AliTOFGeometry.h"
115 #include "AliTOFRecoParam.h"
121 extern TStyle *gStyle;
123 ClassImp(AliTOFcalib)
125 //_______________________________________________________________________
126 AliTOFcalib::AliTOFcalib():
127 TTask("AliTOFcalib",""),
130 fTOFCalOnlinePulser(0x0),
131 fTOFCalOnlineNoise(0x0),
132 fTOFCalOnlineHW(0x0),
142 fLastRun(AliCDBRunRange::Infinity()),
145 //TOF Calibration Class ctor
146 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
148 //____________________________________________________________________________
150 AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib):
151 TTask("AliTOFcalib",""),
152 fNChannels(calib.fNChannels),
154 fTOFCalOnlinePulser(0x0),
155 fTOFCalOnlineNoise(0x0),
156 fTOFCalOnlineHW(0x0),
159 fStatus(calib.fStatus),
160 fTOFSimToT(calib.fTOFSimToT),
161 fkValidity(calib.fkValidity),
163 fChain(calib.fChain),
164 fNruns(calib.fNruns),
165 fFirstRun(calib.fFirstRun),
166 fLastRun(calib.fLastRun),
167 fConfigMap(calib.fConfigMap)
169 //TOF Calibration Class copy ctor
170 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
171 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
172 AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
173 AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
174 AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
175 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
176 fTOFCalOnline->AddAt(calChOnline,iarray);
177 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
178 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
179 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
180 fTOFCalOffline->AddAt(calChOffline,iarray);
184 //____________________________________________________________________________
186 AliTOFcalib& AliTOFcalib::operator=(const AliTOFcalib &calib)
188 //TOF Calibration Class assignment operator
189 this->fNChannels = calib.fNChannels;
190 this->fCal = calib.fCal;
191 this->fStatus = calib.fStatus;
192 this->fTOFSimToT = calib.fTOFSimToT;
193 this->fkValidity = calib.fkValidity;
194 this->fTree = calib.fTree;
195 this->fChain = calib.fChain;
196 this->fNruns = calib.fNruns;
197 this->fFirstRun = calib.fFirstRun;
198 this->fLastRun = calib.fLastRun;
199 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
200 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
201 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
202 AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
203 AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
204 AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
205 this->fTOFCalOnline->AddAt(calChOnline,iarray);
206 this->fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
207 this->fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
208 this->fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
209 this->fTOFCalOffline->AddAt(calChOffline,iarray);
214 //____________________________________________________________________________
216 AliTOFcalib::~AliTOFcalib()
218 //TOF Calibration Class dtor
219 if(!(AliCDBManager::Instance()->GetCacheFlag())){ // CDB objects must NOT be deleted if cache is active!
221 delete fTOFCalOnline;
223 if (fTOFCalOnlinePulser){
224 delete fTOFCalOnlinePulser;
226 if (fTOFCalOnlineNoise){
227 delete fTOFCalOnlineNoise;
229 if (fTOFCalOnlineHW){
230 delete fTOFCalOnlineHW;
233 delete fTOFCalOffline;
245 if (fTree!=0x0) delete fTree;
246 if (fChain!=0x0) delete fChain;
248 //_____________________________________________________________________________
249 void AliTOFcalib::CreateCalArrays(){
251 // creating arrays for online/offline calibration objs
253 fTOFCalOnline = new TObjArray(fNChannels);
254 fTOFCalOnlinePulser = new TObjArray(fNChannels);
255 fTOFCalOnlineNoise = new TObjArray(fNChannels);
256 fTOFCalOnlineHW = new TObjArray(fNChannels);
257 fTOFCalOffline = new TObjArray(fNChannels);
258 fTOFCalOnline->SetOwner();
259 fTOFCalOnlinePulser->SetOwner();
260 fTOFCalOnlineNoise->SetOwner();
261 fTOFCalOnlineHW->SetOwner();
262 fTOFCalOffline->SetOwner();
263 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
264 AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline();
265 AliTOFChannelOnlineStatus * calChOnlineStPulser = new AliTOFChannelOnlineStatus();
266 AliTOFChannelOnlineStatus * calChOnlineStNoise = new AliTOFChannelOnlineStatus();
267 AliTOFChannelOnlineStatus * calChOnlineStHW = new AliTOFChannelOnlineStatus();
268 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
269 fTOFCalOnline->AddAt(calChOnline,iarray);
270 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
271 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
272 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
273 fTOFCalOffline->AddAt(calChOffline,iarray);
275 fCal = new AliTOFChannelOnlineArray(fNChannels);
276 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
278 //_____________________________________________________________________________
279 void AliTOFcalib::CreateCalObjects(){
281 // creating arrays for online/offline calibration objs
283 fTOFCalOffline = new TObjArray(fNChannels);
284 fTOFCalOffline->SetOwner();
285 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
286 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
287 fTOFCalOffline->AddAt(calChOffline,iarray);
289 fCal = new AliTOFChannelOnlineArray(fNChannels);
290 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
292 //_____________________________________________________________________________
293 void AliTOFcalib::WriteConfigMapOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
295 //Write calibration parameters to the CDB
298 AliCDBManager *man = AliCDBManager::Instance();
299 Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
301 sprintf(out,"%s/%s",sel,sel1);
302 AliDebug(2,Form("Writing TOF configuration map for online calib on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
303 AliCDBId id(out,fFirstRun,fLastRun);
304 AliCDBMetaData *md = new AliCDBMetaData();
305 md->SetResponsible("Chiara Zampolli");
309 man->Put(fConfigMap,id,md);
312 //_____________________________________________________________________________
314 void AliTOFcalib::WriteConfigMapOnCDB(Char_t *sel)
316 //Write calibration parameters to the CDB with infinite validity
317 AliCDBManager *man = AliCDBManager::Instance();
318 Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
320 sprintf(out,"%s/%s",sel,sel1);
321 AliCDBRunRange runrange(fFirstRun,fLastRun);
322 AliDebug(2,Form("Writing TOF config map for online calib on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
323 AliCDBId id(out,runrange);
324 AliCDBMetaData *md = new AliCDBMetaData();
325 md->SetResponsible("Chiara Zampolli");
329 man->Put(fConfigMap,id,md);
332 //_____________________________________________________________________________
333 void AliTOFcalib::WriteParOnlineDelayOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
335 //Write calibration parameters to the CDB -------> new calib objs!!!!!
338 AliCDBManager *man = AliCDBManager::Instance();
339 Char_t *sel1 = "ParOnlineDelay" ; // to be consistent with TOFPreprocessor
341 sprintf(out,"%s/%s",sel,sel1);
342 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
343 AliCDBId id(out,fFirstRun,fLastRun);
344 AliCDBMetaData *md = new AliCDBMetaData();
345 md->SetResponsible("Chiara Zampolli");
349 man->Put(fCal,id,md);
352 //_____________________________________________________________________________
353 void AliTOFcalib::WriteParOnlineStatusOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
355 //Write calibration parameters to the CDB -------> new calib objs!!!!!
358 AliCDBManager *man = AliCDBManager::Instance();
359 Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
361 sprintf(out,"%s/%s",sel,sel1);
362 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
363 AliCDBId id(out,fFirstRun,fLastRun);
364 AliCDBMetaData *md = new AliCDBMetaData();
365 md->SetResponsible("Chiara Zampolli");
369 man->Put(fStatus,id,md);
372 //_____________________________________________________________________________
374 void AliTOFcalib::WriteParOnlineDelayOnCDB(Char_t *sel)
376 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
377 AliCDBManager *man = AliCDBManager::Instance();
378 Char_t *sel1 = "ParOnlineDelay" ; // to be consistent with TOFPreprocessor
380 sprintf(out,"%s/%s",sel,sel1);
381 AliCDBRunRange runrange(fFirstRun,fLastRun);
382 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
383 AliCDBId id(out,runrange);
384 AliCDBMetaData *md = new AliCDBMetaData();
385 md->SetResponsible("Chiara Zampolli");
389 man->Put(fCal,id,md);
392 //_____________________________________________________________________________
394 void AliTOFcalib::WriteParOnlineStatusOnCDB(Char_t *sel)
396 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
397 AliCDBManager *man = AliCDBManager::Instance();
398 Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
400 sprintf(out,"%s/%s",sel,sel1);
401 AliCDBRunRange runrange(fFirstRun,fLastRun);
402 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
403 AliCDBId id(out,runrange);
404 AliCDBMetaData *md = new AliCDBMetaData();
405 md->SetResponsible("Chiara Zampolli");
409 man->Put(fStatus,id,md);
412 //_____________________________________________________________________________
413 void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
415 //Write calibration parameters to the CDB
418 AliCDBManager *man = AliCDBManager::Instance();
419 Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
421 sprintf(out,"%s/%s",sel,sel1);
422 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
423 AliCDBId id(out,fFirstRun,fLastRun);
424 AliCDBMetaData *md = new AliCDBMetaData();
425 md->SetResponsible("Chiara Zampolli");
426 if (!fTOFCalOnline) {
429 man->Put(fTOFCalOnline,id,md);
432 //_____________________________________________________________________________
433 void AliTOFcalib::WriteParOnlinePulserOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
435 //Write calibration parameters from pulser to the CDB
438 AliCDBManager *man = AliCDBManager::Instance();
439 Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
441 sprintf(out,"%s/%s",sel,sel1);
442 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
443 AliCDBId id(out,fFirstRun,fLastRun);
444 AliCDBMetaData *md = new AliCDBMetaData();
445 md->SetResponsible("Chiara Zampolli");
446 if (!fTOFCalOnlinePulser) {
449 man->Put(fTOFCalOnlinePulser,id,md);
452 //_____________________________________________________________________________
453 void AliTOFcalib::WriteParOnlineNoiseOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
455 //Write calibration parameters from noise to the CDB
458 AliCDBManager *man = AliCDBManager::Instance();
459 Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
461 sprintf(out,"%s/%s",sel,sel1);
462 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
463 AliCDBId id(out,fFirstRun,fLastRun);
464 AliCDBMetaData *md = new AliCDBMetaData();
465 md->SetResponsible("Chiara Zampolli");
466 if (!fTOFCalOnlineNoise) {
469 man->Put(fTOFCalOnlineNoise,id,md);
472 //_____________________________________________________________________________
473 void AliTOFcalib::WriteParOnlineHWOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
475 //Write calibration parameters from hardware to the CDB
478 AliCDBManager *man = AliCDBManager::Instance();
479 Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
481 sprintf(out,"%s/%s",sel,sel1);
482 AliDebug(2,Form("Writing TOF online calib obj from hardware on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
483 AliCDBId id(out,fFirstRun,fLastRun);
484 AliCDBMetaData *md = new AliCDBMetaData();
485 md->SetResponsible("Chiara Zampolli");
486 if (!fTOFCalOnlineHW) {
489 man->Put(fTOFCalOnlineHW,id,md);
492 //_____________________________________________________________________________
494 void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel)
496 //Write calibration parameters to the CDB with infinite validity
497 AliCDBManager *man = AliCDBManager::Instance();
498 Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
500 sprintf(out,"%s/%s",sel,sel1);
501 AliCDBRunRange runrange(fFirstRun,fLastRun);
502 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
503 AliCDBId id(out,runrange);
504 AliCDBMetaData *md = new AliCDBMetaData();
505 md->SetResponsible("Chiara Zampolli");
506 if (!fTOFCalOnline) {
509 man->Put(fTOFCalOnline,id,md);
512 //_____________________________________________________________________________
514 void AliTOFcalib::WriteParOnlinePulserOnCDB(Char_t *sel)
516 //Write calibration parameters from pulser to the CDB with infinite validity
517 AliCDBManager *man = AliCDBManager::Instance();
518 Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
520 sprintf(out,"%s/%s",sel,sel1);
521 AliCDBRunRange runrange(fFirstRun,fLastRun);
522 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
523 AliCDBId id(out,runrange);
524 AliCDBMetaData *md = new AliCDBMetaData();
525 md->SetResponsible("Chiara Zampolli");
526 if (!fTOFCalOnlinePulser) {
529 man->Put(fTOFCalOnlinePulser,id,md);
532 //_____________________________________________________________________________
534 void AliTOFcalib::WriteParOnlineNoiseOnCDB(Char_t *sel)
536 //Write calibration parameters from noise to the CDB with infinite validity
537 AliCDBManager *man = AliCDBManager::Instance();
538 Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
540 sprintf(out,"%s/%s",sel,sel1);
541 AliCDBRunRange runrange(fFirstRun,fLastRun);
542 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
543 AliCDBId id(out,runrange);
544 AliCDBMetaData *md = new AliCDBMetaData();
545 md->SetResponsible("Chiara Zampolli");
546 if (!fTOFCalOnlineNoise) {
549 man->Put(fTOFCalOnlineNoise,id,md);
552 //_____________________________________________________________________________
554 void AliTOFcalib::WriteParOnlineHWOnCDB(Char_t *sel)
556 //Write calibration parameters from hardware to the CDB with infinite validity
557 AliCDBManager *man = AliCDBManager::Instance();
558 Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
560 sprintf(out,"%s/%s",sel,sel1);
561 AliCDBRunRange runrange(fFirstRun,fLastRun);
562 AliDebug(2,Form("Writing TOF online calib obj from harware on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
563 AliCDBId id(out,runrange);
564 AliCDBMetaData *md = new AliCDBMetaData();
565 md->SetResponsible("Chiara Zampolli");
566 if (!fTOFCalOnlineHW) {
569 man->Put(fTOFCalOnlineHW,id,md);
572 //_____________________________________________________________________________
574 void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun)
576 //Write calibration parameters to the CDB
579 AliCDBManager *man = AliCDBManager::Instance();
580 Char_t *sel1 = "ParOffline" ;
582 sprintf(out,"%s/%s",sel,sel1);
583 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
584 AliCDBId id(out,fFirstRun,fLastRun);
585 AliCDBMetaData *md = new AliCDBMetaData();
586 md->SetResponsible("Chiara Zampolli");
587 md->SetComment(validity);
588 man->Put(fTOFCalOffline,id,md);
591 //_____________________________________________________________________________
593 void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity)
595 //Write calibration parameters to the CDB with infinite validity
596 AliCDBManager *man = AliCDBManager::Instance();
597 Char_t *sel1 = "ParOffline" ;
599 sprintf(out,"%s/%s",sel,sel1);
600 AliCDBRunRange runrange(fFirstRun,fLastRun);
601 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
602 AliCDBId id(out,runrange);
603 AliCDBMetaData *md = new AliCDBMetaData();
604 md->SetResponsible("Chiara Zampolli");
605 md->SetComment(validity);
606 man->Put(fTOFCalOffline,id,md);
609 //_____________________________________________________________________________
611 Bool_t AliTOFcalib::ReadConfigMapFromCDB(Char_t *sel, Int_t nrun)
613 //Read calibration parameters from the CDB
614 AliCDBManager *man = AliCDBManager::Instance();
615 Char_t *sel1 = "Config" ;
617 sprintf(out,"%s/%s",sel,sel1);
618 AliCDBEntry *entry = man->Get(out,nrun);
620 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
623 if(!entry->GetObject()){
624 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
628 fConfigMap =(TMap*)entry->GetObject();
633 //_____________________________________________________________________________
635 Bool_t AliTOFcalib::ReadParOnlineDelayFromCDB(Char_t *sel, Int_t nrun)
637 //Read calibration parameters from the CDB -------> new calib objs!!!!!
638 AliCDBManager *man = AliCDBManager::Instance();
639 Char_t *sel1 = "ParOnlineDelay" ;
641 sprintf(out,"%s/%s",sel,sel1);
642 AliCDBEntry *entry = man->Get(out,nrun);
644 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
647 if(!entry->GetObject()){
648 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
652 fCal =(AliTOFChannelOnlineArray*)entry->GetObject();
657 //_____________________________________________________________________________
659 Bool_t AliTOFcalib::ReadParOnlineStatusFromCDB(Char_t *sel, Int_t nrun)
661 //Read calibration parameters from the CDB -------> new calib objs!!!!!
662 AliCDBManager *man = AliCDBManager::Instance();
663 Char_t *sel1 = "Status" ;
665 sprintf(out,"%s/%s",sel,sel1);
666 AliCDBEntry *entry = man->Get(out,nrun);
668 AliFatal("Exiting, no CDB object (Status) found!!!");
671 if(!entry->GetObject()){
672 AliFatal("Exiting, no CDB object (Status) found!!!");
676 fStatus =(AliTOFChannelOnlineStatusArray*)entry->GetObject();
681 //_____________________________________________________________________________
683 Bool_t AliTOFcalib::ReadParOnlineFromCDB(Char_t *sel, Int_t nrun)
685 //Read calibration parameters from the CDB
686 AliCDBManager *man = AliCDBManager::Instance();
687 Char_t *sel1 = "ParOnline" ;
689 sprintf(out,"%s/%s",sel,sel1);
690 AliCDBEntry *entry = man->Get(out,nrun);
692 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
695 if(!entry->GetObject()){
696 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
700 fTOFCalOnline =(TObjArray*)entry->GetObject();
705 //_____________________________________________________________________________
707 Bool_t AliTOFcalib::ReadParOnlinePulserFromCDB(Char_t *sel, Int_t nrun)
709 //Read calibration parameters from pulser from the CDB
710 AliCDBManager *man = AliCDBManager::Instance();
711 Char_t *sel1 = "Pulser" ;
713 sprintf(out,"%s/%s",sel,sel1);
714 AliCDBEntry *entry = man->Get(out,nrun);
716 AliFatal("Exiting, no CDB object (Pulser) found!!!");
719 if(!entry->GetObject()){
720 AliFatal("Exiting, no CDB object (Pulser) found!!!");
724 fTOFCalOnlinePulser =(TObjArray*)entry->GetObject();
729 //_____________________________________________________________________________
731 Bool_t AliTOFcalib::ReadParOnlineNoiseFromCDB(Char_t *sel, Int_t nrun)
733 //Read calibration parameters from noise from the CDB
734 AliCDBManager *man = AliCDBManager::Instance();
735 Char_t *sel1 = "Noise" ;
737 sprintf(out,"%s/%s",sel,sel1);
738 AliCDBEntry *entry = man->Get(out,nrun);
740 AliFatal("Exiting, no CDB object (Noise) found!!!");
743 if(!entry->GetObject()){
744 AliFatal("Exiting, no CDB object (Noise) found!!!");
748 fTOFCalOnlineNoise =(TObjArray*)entry->GetObject();
753 //_____________________________________________________________________________
755 Bool_t AliTOFcalib::ReadParOnlineHWFromCDB(Char_t *sel, Int_t nrun)
757 //Read calibration parameters from hardware from the CDB
758 AliCDBManager *man = AliCDBManager::Instance();
759 Char_t *sel1 = "HW" ;
761 sprintf(out,"%s/%s",sel,sel1);
762 AliCDBEntry *entry = man->Get(out,nrun);
764 AliFatal("Exiting, no CDB object (HW map) found!!!");
767 if(!entry->GetObject()){
768 AliFatal("Exiting, no CDB object (HW map) found!!!");
772 fTOFCalOnlineHW =(TObjArray*)entry->GetObject();
777 //_____________________________________________________________________________
779 Bool_t AliTOFcalib::ReadParOfflineFromCDB(Char_t *sel, Int_t nrun)
781 //Read calibration parameters from the CDB
782 AliCDBManager *man = AliCDBManager::Instance();
783 Char_t *sel1 = "ParOffline" ;
785 sprintf(out,"%s/%s",sel,sel1);
786 AliCDBEntry *entry = man->Get(out,nrun);
788 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
791 if(!entry->GetObject()){
792 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
795 AliCDBMetaData * md = entry->GetMetaData();
796 fkValidity = md->GetComment();
797 fTOFCalOffline =(TObjArray*)entry->GetObject();
802 //_____________________________________________________________________________
803 void AliTOFcalib::WriteSimHistoOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, TH1F *histo){
804 //Write Sim miscalibration parameters to the CDB
807 AliCDBManager *man = AliCDBManager::Instance();
808 Char_t *sel1 = "SimHisto" ;
810 sprintf(out,"%s/%s",sel,sel1);
811 AliCDBMetaData *mdhisto = new AliCDBMetaData();
812 mdhisto->SetResponsible("Chiara Zampolli");
813 AliCDBId id(out,minrun,maxrun);
814 man->Put(fTOFSimToT,id,mdhisto);
817 //_____________________________________________________________________________
818 Bool_t AliTOFcalib::ReadSimHistoFromCDB(Char_t *sel, Int_t nrun)
820 //Read miscalibration parameters from the CDB
821 AliCDBManager *man = AliCDBManager::Instance();
825 Char_t *sel1 = "SimHisto" ;
827 sprintf(out,"%s/%s",sel,sel1);
828 AliCDBEntry *entry = man->Get(out,nrun);
830 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
833 if(!entry->GetObject()){
834 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
837 TH1F *histo =(TH1F*)entry->GetObject();
841 //_____________________________________________________________________________
842 void AliTOFcalib::WriteRecParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){
843 //Write reconstruction parameters to the CDB
845 AliCDBManager *man = AliCDBManager::Instance();
846 AliCDBMetaData *md = new AliCDBMetaData();
847 md->SetResponsible("Silvia Arcelli");
848 Char_t *sel1 = "RecPar" ;
850 sprintf(out,"%s/%s",sel,sel1);
851 AliCDBId id(out,minrun,maxrun);
852 man->Put(param,id,md);
855 //_____________________________________________________________________________
856 AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(Char_t *sel, Int_t nrun)
858 //Read reconstruction parameters from the CDB
859 AliCDBManager *man = AliCDBManager::Instance();
860 Char_t *sel1 = "RecPar" ;
862 sprintf(out,"%s/%s",sel,sel1);
863 AliCDBEntry *entry = man->Get(out,nrun);
865 AliFatal("Exiting, no CDB object (RecPar) found!!!");
868 if(!entry->GetObject()){
869 AliFatal("Exiting, no CDB object (RecPar) found!!!");
873 AliTOFRecoParam *param=(AliTOFRecoParam*)entry->GetObject();
876 //-----------------------------------------------------------------------------
877 // Calibration methods
878 //-----------------------------------------------------------------------------
879 void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
881 // creating the chain with the trees for calibration
882 // collecting them from reference data
883 // from minrun to maxrun
885 Float_t p[CHENTRIESSMALL];
887 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
888 fTree->Branch("nentries",&nentries,"nentries/I");
889 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
890 AliCDBManager *man = AliCDBManager::Instance();
891 AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT");
892 for (Int_t irun = minrun;irun<=maxrun;irun++){
893 AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
895 AliInfo(Form("No entry found for run %i",irun));
898 TTree *tree = new TTree();
899 tree = (TTree*)entry->GetObject();
900 tree->SetBranchAddress("nentries",&nentries);
901 tree->SetBranchAddress("TOFentries",p);
902 fTree->CopyEntries(tree);
907 AliInfo(Form("Number of runs being analyzed %i",fNruns));
909 //-----------------------------------------------------------------------------
910 void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
912 // creating the chain with the trees for calibration
913 // collecting them from the Grid
914 // from minrun to maxrun
916 Float_t p[CHENTRIESSMALL];
918 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
919 fTree->SetDirectory(0);
920 fTree->Branch("nentries",&nentries,"nentries/I");
921 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
922 AliInfo("connected to alien");
923 TGrid::Connect("alien://");
925 Char_t filename[100];
926 for (Int_t irun = minrun;irun<=maxrun;irun++){
927 sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
928 TFile *filegrid = TFile::Open(filename,"READ");
929 TTree *tree = (TTree*)filegrid->Get("T");
930 tree->SetBranchAddress("nentries",&nentries);
931 tree->SetBranchAddress("TOFentries",p);
932 fTree->CopyEntries(tree);
937 AliInfo(Form("Number of runs being analyzed %i",fNruns));
939 //-----------------------------------------------------------------------------
940 void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
942 // creating the tree with the trees for calibration
943 // collecting them from reference data (from file)
944 // from minrun to maxrun
946 Float_t p[CHENTRIESSMALL];
948 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
949 fTree->SetDirectory(0);
950 fTree->Branch("nentries",&nentries,"nentries/I");
951 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
952 Char_t filename[100];
953 for (Int_t irun = minrun;irun<=maxrun;irun++){
954 sprintf(filename,"$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
955 TFile *file = new TFile(filename,"READ");
956 TTree *tree = (TTree*)file->Get("T");
957 tree->SetBranchAddress("nentries",&nentries);
958 tree->SetBranchAddress("TOFentries",p);
959 fTree->CopyEntries(tree);
966 AliInfo(Form("Number of runs being analyzed %i",fNruns));
968 //-----------------------------------------------------------------------------
969 void AliTOFcalib::CreateChainFromGrid(Int_t minrun, Int_t maxrun){
971 // creating the chain with the trees for calibration
972 // collecting them from the Grid
973 // from minrun to maxrun
975 fChain = new TChain("T");
976 AliInfo("connected to alien");
977 TGrid::Connect("alien://");
979 Char_t filename[100];
980 for (Int_t irun = minrun;irun<=maxrun;irun++){
981 sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
982 fChain->Add(filename);
986 AliInfo(Form("Number of runs being analyzed %i",fNruns));
988 //-----------------------------------------------------------------------------
989 Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
991 // calibrating summing more than one channels
992 // computing calibration parameters
994 // 0 -> everything was ok
995 // 1 -> no tree for calibration found
996 // 2 -> not enough statistics to perform calibration
997 // 3 -> problems with arrays
999 TH1::AddDirectory(0);
1001 AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ;
1002 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1003 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1005 Float_t p[CHENTRIESSMALL];
1007 //fTree->SetBranchAddress("nentries",&nentries);
1008 //fTree->SetBranchAddress("TOFentries",p);
1009 fChain->SetBranchAddress("nentries",&nentries);
1010 fChain->SetBranchAddress("TOFentries",p);
1012 Float_t ntracksTotalmean =0;
1013 for (Int_t i=ichmin; i<ichmax; i++){
1015 for (Int_t irun=0;irun<fNruns;irun++){
1016 ientry = i+irun*fNChannels;
1017 //fTree->GetEntry(ientry);
1018 fChain->GetEntry(ientry);
1019 Int_t ntracksRun=nentries/3;
1020 ntracksTotalmean+=ntracksRun;
1024 if (ntracksTotalmean < MEANENTRIES) {
1025 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1029 //filling ToT and Time arrays
1031 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1032 Float_t minToT = 0; // ns
1033 Float_t maxToT = 4.88; // ns
1035 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1036 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1037 Int_t ntracksTotal = 0;
1038 Int_t ntracksRun = 0;
1039 Double_t binsProfile[101]; // sized larger than necessary, the correct
1040 // dim being set in the booking of the profile
1041 Int_t nusefulbins=0;
1043 for (Int_t i = ichmin;i<ichmax;i++){
1045 for (Int_t irun=0;irun<fNruns;irun++){
1046 ientry = i+irun*fNChannels;
1047 //fTree->GetEntry(ientry);
1048 fChain->GetEntry(ientry);
1049 ntracksTotal+=nentries/3;
1050 ntracksRun=nentries/3;
1051 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun));
1052 for (Int_t j=0;j<ntracksRun;j++){
1053 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1054 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1055 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1056 Float_t tot = p[idxexToT];
1057 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1058 meantime+=p[idxexTime]-p[idxexExTime];
1063 nusefulbins = FindBins(hToT,&binsProfile[0]);
1064 meantime/=ntracksTotal;
1065 AliDebug(2, Form("meantime = %f",meantime));
1067 for (Int_t j=1;j<=nusefulbins;j++) {
1068 AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j]));
1071 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1072 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1074 for (Int_t irun=0;irun<fNruns;irun++){
1076 for (Int_t i=ichmin; i<ichmax; i++){
1077 ientry = i+irun*fNChannels;
1078 //fTree->GetEntry(ientry);
1079 fChain->GetEntry(ientry);
1080 ntracksRun=nentries/3;
1081 for (Int_t j=0;j<ntracksRun;j++){
1082 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1083 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1084 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1085 Float_t tot = p[idxexToT];
1086 Float_t time = p[idxexTime]-p[idxexExTime];
1087 AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1088 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1089 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1094 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1095 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1097 for(Int_t kk=0;kk<6;kk++){
1098 par[kk]=calibfunc->GetParameter(kk);
1099 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1102 if(strstr(optionSave,"save")){
1103 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1105 TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
1106 TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
1107 TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
1108 TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
1109 hSlewingProf->Write(profName);
1110 htimetot->Write(timeTotName);
1111 hToT->Write(totName);
1112 hdeltaTime->Write(deltaName);
1120 delete hSlewingProf;
1127 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin);
1128 calChannel->SetSlewPar(par);
1129 WriteParOfflineOnCDB("TOF/Calib","valid");
1132 //----------------------------------------------------------------------------
1133 Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
1135 // computing calibration parameters for channel i
1137 // 0 -> everything was ok
1138 // 1 -> no tree for calibration found
1139 // 2 -> not enough statistics to perform calibration
1140 // 3 -> problems with arrays
1142 TH1::AddDirectory(0);
1144 AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ;
1145 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1146 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1148 Float_t p[MAXCHENTRIESSMALL];
1150 //fTree->SetBranchAddress("nentries",&nentries);
1151 //fTree->SetBranchAddress("TOFentries",p);
1152 fChain->SetBranchAddress("nentries",&nentries);
1153 fChain->SetBranchAddress("TOFentries",p);
1155 Float_t ntracksTotal =0;
1156 for (Int_t irun=0;irun<fNruns;irun++){
1158 ientry = i+irun*fNChannels;
1159 //fTree->GetEntry(ientry);
1160 fChain->GetEntry(ientry);
1161 ntracksTotal+=nentries/3;
1164 if (ntracksTotal < MEANENTRIES) {
1165 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1169 //filling ToT and Time arrays
1171 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1172 Float_t minToT = 0; // ns
1173 Float_t maxToT = 4.88; // ns
1175 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1176 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1177 Int_t ntracksRun = 0;
1178 Double_t binsProfile[101]; // sized larger than necessary, the correct
1179 // dim being set in the booking of the profile
1180 Int_t nusefulbins=0;
1182 for (Int_t irun=0;irun<fNruns;irun++){
1184 ientry = i+irun*fNChannels;
1185 //fTree->GetEntry(ientry);
1186 fChain->GetEntry(ientry);
1187 ntracksRun=nentries/3;
1188 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun));
1189 for (Int_t j=0;j<ntracksRun;j++){
1190 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1191 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1192 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1193 Float_t tot = p[idxexToT];
1194 meantime+=p[idxexTime]-p[idxexExTime];
1195 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1200 nusefulbins = FindBins(hToT,&binsProfile[0]);
1201 meantime/=ntracksTotal;
1202 AliDebug(2,Form("meantime = %f",meantime));
1204 for (Int_t j=1;j<=nusefulbins;j++) {
1205 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1208 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1209 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1210 for (Int_t irun=0;irun<fNruns;irun++){
1212 ientry = i+irun*fNChannels;
1213 //fTree->GetEntry(ientry);
1214 fChain->GetEntry(ientry);
1215 ntracksRun=nentries/3;
1216 for (Int_t j=0;j<ntracksRun;j++){
1217 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1218 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1219 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1220 Float_t tot = p[idxexToT];
1221 Float_t time = p[idxexTime]-p[idxexExTime];
1222 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1223 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1224 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1228 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1229 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1231 for(Int_t kk=0;kk<6;kk++){
1232 par[kk]=calibfunc->GetParameter(kk);
1233 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1237 if(strstr(optionSave,"save")){
1238 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1240 TString profName=Form("Profile%06i",i);
1241 TString timeTotName=Form("TimeTot%06i",i);
1242 TString totName=Form("Tot%06i",i);
1243 TString deltaName=Form("Delta%06i",i);
1244 hSlewingProf->Write(profName);
1245 htimetot->Write(timeTotName);
1246 hToT->Write(totName);
1247 hdeltaTime->Write(deltaName);
1255 delete hSlewingProf;
1262 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1263 calChannel->SetSlewPar(par);
1264 WriteParOfflineOnCDB("TOF/Calib","valid");
1267 //----------------------------------------------------------------------------
1268 Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
1270 // calibrating an array of channels
1271 // computing calibration parameters
1273 // 0 -> everything was ok
1274 // 1 -> no tree for calibration found
1275 // 2 -> not enough statistics to perform calibration
1276 // 3 -> problems with arrays
1278 TH1::AddDirectory(0);
1280 AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ;
1281 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1282 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1283 for (Int_t ich=0; ich<nch; ich++){
1285 AliInfo(Form("Calibrating channel = %i",i )) ;
1287 Float_t p[MAXCHENTRIESSMALL];
1289 //fTree->SetBranchAddress("nentries",&nentries);
1290 //fTree->SetBranchAddress("TOFentries",p);
1291 fChain->SetBranchAddress("nentries",&nentries);
1292 fChain->SetBranchAddress("TOFentries",p);
1294 Float_t ntracksTotalmean =0;
1295 for (Int_t ich=0; ich<nch; ich++){
1298 for (Int_t irun=0;irun<fNruns;irun++){
1299 ientry = i+irun*fNChannels;
1300 //fTree->GetEntry(ientry);
1301 fChain->GetEntry(ientry);
1302 ntracksTotalmean+=nentries/3;
1306 ntracksTotalmean/=nch;
1307 if (ntracksTotalmean < MEANENTRIES) {
1308 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1312 //filling ToT and Time arrays
1314 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1315 Float_t minToT = 0; // ns
1316 Float_t maxToT = 4.88; // ns
1317 TFile * fileProf=0x0;
1318 if(strstr(optionSave,"save")){
1319 fileProf = new TFile("TOFCalibSave.root","recreate");
1321 for (Int_t ich=0; ich<nch; ich++) {
1322 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1323 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1324 Double_t binsProfile[101]; // sized larger than necessary, the correct
1325 // dim being set in the booking of the profile
1326 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1327 Int_t ntracksTotal = 0;
1328 Int_t ntracksRun = 0;
1329 Int_t nusefulbins=0;
1332 for (Int_t irun=0;irun<fNruns;irun++){
1333 i = ch[ich]+irun*fNChannels;
1334 AliDebug(2,Form("Calibrating channel %i",i));
1335 //fTree->GetEntry(i);
1336 fChain->GetEntry(i);
1337 ntracksTotal+=nentries/3;
1339 if (ntracksTotal < MEANENTRIES) {
1340 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",i,ntracksTotal));
1344 for (Int_t irun=0;irun<fNruns;irun++){
1345 i = ch[ich]+irun*fNChannels;
1346 //fTree->GetEntry(i);
1347 fChain->GetEntry(i);
1348 ntracksRun=nentries/3;
1349 for (Int_t j=0;j<ntracksRun;j++){
1350 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1351 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1352 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1353 Float_t tot = p[idxexToT];
1354 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1355 meantime+=p[idxexTime]-p[idxexExTime];
1360 nusefulbins = FindBins(hToT,&binsProfile[0]);
1361 meantime/=ntracksTotal;
1362 for (Int_t j=1;j<=nusefulbins;j++) {
1363 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1366 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1367 for (Int_t irun=0;irun<fNruns;irun++){
1368 i = ch[ich]+irun*fNChannels;
1369 //fTree->GetEntry(i);
1370 fChain->GetEntry(i);
1371 ntracksRun=nentries/3;
1372 for (Int_t j=0;j<ntracksRun;j++){
1373 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1374 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1375 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1376 Float_t tot = p[idxexToT];
1377 Float_t time = p[idxexTime]-p[idxexExTime];
1378 AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1379 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1380 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1384 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1385 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1387 for(Int_t kk=0;kk<6;kk++){
1388 par[kk]=calibfunc->GetParameter(kk);
1389 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1392 if(strstr(optionSave,"save") && fileProf){
1393 TString profName=Form("Profile%06i",i);
1394 TString timeTotName=Form("TimeTot%06i",i);
1395 TString totName=Form("Tot%06i",i);
1396 TString deltaName=Form("Delta%06i",i);
1398 hSlewingProf->Write(profName);
1399 htimetot->Write(timeTotName);
1400 hToT->Write(totName);
1401 hdeltaTime->Write(deltaName);
1404 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1405 calChannel->SetSlewPar(par);
1408 delete hSlewingProf;
1416 if(strstr(optionSave,"save") && fileProf){
1421 WriteParOfflineOnCDB("TOF/Calib","valid");
1425 //----------------------------------------------------------------------------
1426 Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){
1428 // computing calibration parameters using the old profiling algo
1430 // 0 -> everything was ok
1431 // 1 -> no tree for calibration found
1432 // 2 -> not enough statistics to perform calibration
1433 // 3 -> problems with arrays
1435 TH1::AddDirectory(0);
1437 AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ;
1438 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1439 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1440 Float_t p[MAXCHENTRIESSMALL];
1442 Int_t ntracksTotal=0;
1443 //fTree->SetBranchAddress("nentries",&nentries);
1444 //fTree->SetBranchAddress("TOFentries",p);
1445 fChain->SetBranchAddress("nentries",&nentries);
1446 fChain->SetBranchAddress("TOFentries",p);
1448 for (Int_t irun=0;irun<fNruns;irun++){
1449 Int_t i = ich+irun*fNChannels;
1450 //fTree->GetEntry(i);
1451 fChain->GetEntry(i);
1452 ntracksTotal+=nentries/3;
1455 if (ntracksTotal < MEANENTRIES) {
1456 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1460 TH1F * hProf = new TH1F();
1461 hProf = Profile(ich);
1462 hProf->Fit("pol5",optionFit,"",0,4);
1463 TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
1465 for(Int_t kk=0;kk<6;kk++){
1466 par[kk]=calibfunc->GetParameter(kk);
1467 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1470 if(strstr(optionSave,"save")){
1471 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1473 TString profName=Form("Profile%06i",ich);
1474 hProf->Write(profName);
1482 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich);
1483 calChannel->SetSlewPar(par);
1484 WriteParOfflineOnCDB("TOF/Calib","valid");
1487 //----------------------------------------------------------------------------
1488 Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
1490 // calibrating the whole TOF
1491 // computing calibration parameters
1493 // 0 -> everything was ok
1494 // 1 -> no tree for calibration found
1495 // 2 -> not enough statistics to perform calibration
1496 // 3 -> problems with arrays
1498 TH1::AddDirectory(0);
1500 AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ;
1501 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1502 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1504 TFile * fileProf=0x0;
1505 if(strstr(optionSave,"save")){
1506 fileProf = new TFile("TOFCalibSave.root","recreate");
1509 Float_t p[MAXCHENTRIESSMALL];
1511 //fTree->SetBranchAddress("nentries",&nentries);
1512 //fTree->SetBranchAddress("TOFentries",p);
1513 fChain->SetBranchAddress("nentries",&nentries);
1514 fChain->SetBranchAddress("TOFentries",p);
1516 Float_t ntracksTotalmean =0;
1517 for (Int_t ii=0; ii<fNChannels; ii++){
1518 for (Int_t irun=0;irun<fNruns;irun++){
1519 Int_t i = ii+irun*fNChannels;
1520 //fTree->GetEntry(i);
1521 fChain->GetEntry(i);
1522 ntracksTotalmean+=nentries/3;
1526 ntracksTotalmean/=fNChannels;
1527 if (ntracksTotalmean < MEANENTRIES) {
1528 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1532 //filling ToT and Time arrays
1534 Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps
1535 Float_t minToT = 0; // ns
1536 Float_t maxToT = 4.88;// ns
1537 for (Int_t ii=0; ii<fNChannels; ii++) {
1538 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1539 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1540 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1541 if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
1543 Int_t nusefulbins=0;
1544 Double_t binsProfile[101]; // sized larger than necessary, the correct
1545 // dim being set in the booking of the profile
1546 Int_t ntracksRun = 0;
1547 Int_t ntracksTotal = 0;
1548 for (Int_t irun=0;irun<fNruns;irun++){
1549 Int_t i = ii+irun*fNChannels;
1550 //fTree->GetEntry(i);
1551 fChain->GetEntry(i);
1552 ntracksTotal+=nentries/3;
1554 if (ntracksTotal < MEANENTRIES) {
1555 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",ii,ntracksTotal));
1559 for (Int_t irun=0;irun<fNruns;irun++){
1560 Int_t i = ii+irun*fNChannels;
1561 //fTree->GetEntry(i);
1562 fChain->GetEntry(i);
1563 ntracksRun=nentries/3;
1564 for (Int_t j=0;j<ntracksRun;j++){
1565 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1566 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1567 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1568 Float_t tot = p[idxexToT];
1569 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1570 meantime+=p[idxexTime]-p[idxexExTime];
1574 nusefulbins = FindBins(hToT,&binsProfile[0]);
1575 meantime/=ntracksTotal;
1576 for (Int_t j=0;j<nusefulbins;j++) {
1577 AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j]));
1579 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1580 for (Int_t irun=0;irun<fNruns;irun++){
1581 Int_t i = ii+irun*fNChannels;
1582 //fTree->GetEntry(i);
1583 fChain->GetEntry(i);
1584 ntracksRun=nentries/3;
1585 for (Int_t j=0;j<ntracksRun;j++){
1586 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1587 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1588 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1589 Float_t tot = p[idxexToT];
1590 Float_t time = p[idxexTime]-p[idxexExTime];
1591 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1592 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1593 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1596 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1597 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1599 for(Int_t kk=0;kk<6;kk++){
1600 par[kk]=calibfunc->GetParameter(kk);
1601 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1604 if(strstr(optionSave,"save") && fileProf){
1605 TString profName=Form("Profile%06i",ii);
1606 TString timeTotName=Form("TimeTot%06i",ii);
1607 TString totName=Form("Tot%06i",ii);
1608 TString deltaName=Form("Delta%06i",ii);
1610 hSlewingProf->Write(profName);
1611 htimetot->Write(timeTotName);
1612 hToT->Write(totName);
1613 hdeltaTime->Write(deltaName);
1615 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii);
1616 calChannel->SetSlewPar(par);
1620 delete hSlewingProf;
1628 if(strstr(optionSave,"save")){
1633 WriteParOfflineOnCDB("TOF/Calib","valid");
1637 //-----------------------------------------------------------------------
1638 TH1F* AliTOFcalib::Profile(Int_t ich)
1642 Float_t p[MAXCHENTRIESSMALL];
1644 //fTree->SetBranchAddress("nentries",&nentries);
1645 //fTree->SetBranchAddress("TOFentries",p);
1646 fChain->SetBranchAddress("nentries",&nentries);
1647 fChain->SetBranchAddress("TOFentries",p);
1649 //Prepare histograms for Slewing Correction
1650 const Int_t knbinToT = 100;
1651 Int_t nbinTime = 200;
1652 Float_t minTime = -5.5; //ns
1653 Float_t maxTime = 5.5; //ns
1654 Float_t minToT = 0; //ns
1655 Float_t maxToT = 5.; //ns
1656 Float_t deltaToT = (maxToT-minToT)/knbinToT;
1657 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];
1658 Int_t n[knbinToT+1], nentrx[knbinToT+1];
1659 Double_t sigmaToT[knbinToT+1];
1660 for (Int_t i = 0; i < knbinToT+1 ; i++){
1678 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
1679 Int_t ntracksRun = 0;
1680 TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
1681 for (Int_t irun=0;irun<fNruns;irun++){
1682 Int_t i = ich+irun*fNChannels;
1683 //fTree->GetEntry(i);
1684 fChain->GetEntry(i);
1685 ntracksRun=nentries/3;
1686 for (Int_t j=0;j<ntracksRun;j++){
1687 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1688 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1689 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1690 Float_t tot = p[idxexToT];
1691 Float_t time = p[idxexTime]-p[idxexExTime];
1692 Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
1693 if ((tot != 0) && ( time!= 0)){
1695 vTime2[nx]+=time*time;
1699 hSlewing->Fill(tot,time);
1703 Int_t nbinsToT=hSlewing->GetNbinsX();
1704 if (nbinsToT != knbinToT) {
1705 AliError("Profile :: incompatible numbers of bins");
1710 for (Int_t i=1;i<=nbinsToT;i++){
1712 n[usefulBins]+=nentrx[i];
1713 if (n[usefulBins]==0 && i == nbinsToT) {
1716 meanTime[usefulBins]+=vTime[i];
1717 meanTime2[usefulBins]+=vTime2[i];
1718 meanToT[usefulBins]+=vToT[i];
1719 meanToT2[usefulBins]+=vToT2[i];
1720 if (n[usefulBins]<10 && i!=nbinsToT) continue;
1721 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
1722 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
1723 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1724 *(meanTime2[usefulBins]-meanTime[usefulBins]
1725 *meanTime[usefulBins]/n[usefulBins]));
1726 if ((1./n[usefulBins]/n[usefulBins]
1727 *(meanToT2[usefulBins]-meanToT[usefulBins]
1728 *meanToT[usefulBins]/n[usefulBins]))< 0) {
1729 AliError(" too small radical" );
1730 sigmaToT[usefulBins]=0;
1733 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1734 *(meanToT2[usefulBins]-meanToT[usefulBins]
1735 *meanToT[usefulBins]/n[usefulBins]));
1740 for (Int_t i=0;i<usefulBins;i++){
1741 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
1742 histo->Fill(mToT[i],mTime[i]);
1743 histo->SetBinError(binN,sigmaTime[i]);
1750 //----------------------------------------------------------------------------
1751 Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
1753 // to determine the bins for ToT histo
1757 Int_t nbin = h->GetNbinsX();
1758 Int_t nentries = (Int_t)h->GetEntries();
1759 Float_t max = h->GetBinLowEdge(nbin);
1760 Int_t nusefulbins=0;
1762 // setting maxvalue of entries per bin
1763 if (nentries <= 60) maxcont = 2;
1764 else if (nentries <= 100) maxcont = 5;
1765 else if (nentries <= 500) maxcont = 10;
1767 for (Int_t j=1;j<=nbin;j++) {
1768 cont += (Int_t)h->GetBinContent(j);
1772 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1781 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1782 binsProfile[nusefulbins]=max;
1785 binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);