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::WriteConfigMapOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
281 //Write calibration parameters to the CDB
284 AliCDBManager *man = AliCDBManager::Instance();
285 Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
287 sprintf(out,"%s/%s",sel,sel1);
288 AliDebug(2,Form("Writing TOF configuration map for online calib on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
289 AliCDBId id(out,fFirstRun,fLastRun);
290 AliCDBMetaData *md = new AliCDBMetaData();
291 md->SetResponsible("Chiara Zampolli");
295 man->Put(fConfigMap,id,md);
298 //_____________________________________________________________________________
300 void AliTOFcalib::WriteConfigMapOnCDB(Char_t *sel)
302 //Write calibration parameters to the CDB with infinite validity
303 AliCDBManager *man = AliCDBManager::Instance();
304 Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
306 sprintf(out,"%s/%s",sel,sel1);
307 AliCDBRunRange runrange(fFirstRun,fLastRun);
308 AliDebug(2,Form("Writing TOF config map for online calib on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
309 AliCDBId id(out,runrange);
310 AliCDBMetaData *md = new AliCDBMetaData();
311 md->SetResponsible("Chiara Zampolli");
315 man->Put(fConfigMap,id,md);
318 //_____________________________________________________________________________
319 void AliTOFcalib::WriteParOnlineDelayOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
321 //Write calibration parameters to the CDB -------> new calib objs!!!!!
324 AliCDBManager *man = AliCDBManager::Instance();
325 Char_t *sel1 = "ParOnlineDelay" ; // to be consistent with TOFPreprocessor
327 sprintf(out,"%s/%s",sel,sel1);
328 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
329 AliCDBId id(out,fFirstRun,fLastRun);
330 AliCDBMetaData *md = new AliCDBMetaData();
331 md->SetResponsible("Chiara Zampolli");
335 man->Put(fCal,id,md);
338 //_____________________________________________________________________________
339 void AliTOFcalib::WriteParOnlineStatusOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
341 //Write calibration parameters to the CDB -------> new calib objs!!!!!
344 AliCDBManager *man = AliCDBManager::Instance();
345 Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
347 sprintf(out,"%s/%s",sel,sel1);
348 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
349 AliCDBId id(out,fFirstRun,fLastRun);
350 AliCDBMetaData *md = new AliCDBMetaData();
351 md->SetResponsible("Chiara Zampolli");
355 man->Put(fStatus,id,md);
358 //_____________________________________________________________________________
360 void AliTOFcalib::WriteParOnlineDelayOnCDB(Char_t *sel)
362 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
363 AliCDBManager *man = AliCDBManager::Instance();
364 Char_t *sel1 = "ParOnlineDelay" ; // to be consistent with TOFPreprocessor
366 sprintf(out,"%s/%s",sel,sel1);
367 AliCDBRunRange runrange(fFirstRun,fLastRun);
368 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
369 AliCDBId id(out,runrange);
370 AliCDBMetaData *md = new AliCDBMetaData();
371 md->SetResponsible("Chiara Zampolli");
375 man->Put(fCal,id,md);
378 //_____________________________________________________________________________
380 void AliTOFcalib::WriteParOnlineStatusOnCDB(Char_t *sel)
382 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
383 AliCDBManager *man = AliCDBManager::Instance();
384 Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
386 sprintf(out,"%s/%s",sel,sel1);
387 AliCDBRunRange runrange(fFirstRun,fLastRun);
388 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
389 AliCDBId id(out,runrange);
390 AliCDBMetaData *md = new AliCDBMetaData();
391 md->SetResponsible("Chiara Zampolli");
395 man->Put(fStatus,id,md);
398 //_____________________________________________________________________________
399 void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
401 //Write calibration parameters to the CDB
404 AliCDBManager *man = AliCDBManager::Instance();
405 Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
407 sprintf(out,"%s/%s",sel,sel1);
408 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
409 AliCDBId id(out,fFirstRun,fLastRun);
410 AliCDBMetaData *md = new AliCDBMetaData();
411 md->SetResponsible("Chiara Zampolli");
412 if (!fTOFCalOnline) {
415 man->Put(fTOFCalOnline,id,md);
418 //_____________________________________________________________________________
419 void AliTOFcalib::WriteParOnlinePulserOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
421 //Write calibration parameters from pulser to the CDB
424 AliCDBManager *man = AliCDBManager::Instance();
425 Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
427 sprintf(out,"%s/%s",sel,sel1);
428 AliDebug(2,Form("Writing TOF online calib obj from pulser 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 if (!fTOFCalOnlinePulser) {
435 man->Put(fTOFCalOnlinePulser,id,md);
438 //_____________________________________________________________________________
439 void AliTOFcalib::WriteParOnlineNoiseOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
441 //Write calibration parameters from noise to the CDB
444 AliCDBManager *man = AliCDBManager::Instance();
445 Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
447 sprintf(out,"%s/%s",sel,sel1);
448 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
449 AliCDBId id(out,fFirstRun,fLastRun);
450 AliCDBMetaData *md = new AliCDBMetaData();
451 md->SetResponsible("Chiara Zampolli");
452 if (!fTOFCalOnlineNoise) {
455 man->Put(fTOFCalOnlineNoise,id,md);
458 //_____________________________________________________________________________
459 void AliTOFcalib::WriteParOnlineHWOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
461 //Write calibration parameters from hardware to the CDB
464 AliCDBManager *man = AliCDBManager::Instance();
465 Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
467 sprintf(out,"%s/%s",sel,sel1);
468 AliDebug(2,Form("Writing TOF online calib obj from hardware on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
469 AliCDBId id(out,fFirstRun,fLastRun);
470 AliCDBMetaData *md = new AliCDBMetaData();
471 md->SetResponsible("Chiara Zampolli");
472 if (!fTOFCalOnlineHW) {
475 man->Put(fTOFCalOnlineHW,id,md);
478 //_____________________________________________________________________________
480 void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel)
482 //Write calibration parameters to the CDB with infinite validity
483 AliCDBManager *man = AliCDBManager::Instance();
484 Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
486 sprintf(out,"%s/%s",sel,sel1);
487 AliCDBRunRange runrange(fFirstRun,fLastRun);
488 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
489 AliCDBId id(out,runrange);
490 AliCDBMetaData *md = new AliCDBMetaData();
491 md->SetResponsible("Chiara Zampolli");
492 if (!fTOFCalOnline) {
495 man->Put(fTOFCalOnline,id,md);
498 //_____________________________________________________________________________
500 void AliTOFcalib::WriteParOnlinePulserOnCDB(Char_t *sel)
502 //Write calibration parameters from pulser to the CDB with infinite validity
503 AliCDBManager *man = AliCDBManager::Instance();
504 Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
506 sprintf(out,"%s/%s",sel,sel1);
507 AliCDBRunRange runrange(fFirstRun,fLastRun);
508 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
509 AliCDBId id(out,runrange);
510 AliCDBMetaData *md = new AliCDBMetaData();
511 md->SetResponsible("Chiara Zampolli");
512 if (!fTOFCalOnlinePulser) {
515 man->Put(fTOFCalOnlinePulser,id,md);
518 //_____________________________________________________________________________
520 void AliTOFcalib::WriteParOnlineNoiseOnCDB(Char_t *sel)
522 //Write calibration parameters from noise to the CDB with infinite validity
523 AliCDBManager *man = AliCDBManager::Instance();
524 Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
526 sprintf(out,"%s/%s",sel,sel1);
527 AliCDBRunRange runrange(fFirstRun,fLastRun);
528 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
529 AliCDBId id(out,runrange);
530 AliCDBMetaData *md = new AliCDBMetaData();
531 md->SetResponsible("Chiara Zampolli");
532 if (!fTOFCalOnlineNoise) {
535 man->Put(fTOFCalOnlineNoise,id,md);
538 //_____________________________________________________________________________
540 void AliTOFcalib::WriteParOnlineHWOnCDB(Char_t *sel)
542 //Write calibration parameters from hardware to the CDB with infinite validity
543 AliCDBManager *man = AliCDBManager::Instance();
544 Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
546 sprintf(out,"%s/%s",sel,sel1);
547 AliCDBRunRange runrange(fFirstRun,fLastRun);
548 AliDebug(2,Form("Writing TOF online calib obj from harware on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
549 AliCDBId id(out,runrange);
550 AliCDBMetaData *md = new AliCDBMetaData();
551 md->SetResponsible("Chiara Zampolli");
552 if (!fTOFCalOnlineHW) {
555 man->Put(fTOFCalOnlineHW,id,md);
558 //_____________________________________________________________________________
560 void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun)
562 //Write calibration parameters to the CDB
565 AliCDBManager *man = AliCDBManager::Instance();
566 Char_t *sel1 = "ParOffline" ;
568 sprintf(out,"%s/%s",sel,sel1);
569 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
570 AliCDBId id(out,fFirstRun,fLastRun);
571 AliCDBMetaData *md = new AliCDBMetaData();
572 md->SetResponsible("Chiara Zampolli");
573 md->SetComment(validity);
574 man->Put(fTOFCalOffline,id,md);
577 //_____________________________________________________________________________
579 void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity)
581 //Write calibration parameters to the CDB with infinite validity
582 AliCDBManager *man = AliCDBManager::Instance();
583 Char_t *sel1 = "ParOffline" ;
585 sprintf(out,"%s/%s",sel,sel1);
586 AliCDBRunRange runrange(fFirstRun,fLastRun);
587 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
588 AliCDBId id(out,runrange);
589 AliCDBMetaData *md = new AliCDBMetaData();
590 md->SetResponsible("Chiara Zampolli");
591 md->SetComment(validity);
592 man->Put(fTOFCalOffline,id,md);
595 //_____________________________________________________________________________
597 Bool_t AliTOFcalib::ReadConfigMapFromCDB(Char_t *sel, Int_t nrun)
599 //Read calibration parameters from the CDB
600 AliCDBManager *man = AliCDBManager::Instance();
601 Char_t *sel1 = "Config" ;
603 sprintf(out,"%s/%s",sel,sel1);
604 AliCDBEntry *entry = man->Get(out,nrun);
606 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
609 if(!entry->GetObject()){
610 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
614 fConfigMap =(TMap*)entry->GetObject();
619 //_____________________________________________________________________________
621 Bool_t AliTOFcalib::ReadParOnlineDelayFromCDB(Char_t *sel, Int_t nrun)
623 //Read calibration parameters from the CDB -------> new calib objs!!!!!
624 AliCDBManager *man = AliCDBManager::Instance();
625 Char_t *sel1 = "ParOnlineDelay" ;
627 sprintf(out,"%s/%s",sel,sel1);
628 AliCDBEntry *entry = man->Get(out,nrun);
630 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
633 if(!entry->GetObject()){
634 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
638 fCal =(AliTOFChannelOnlineArray*)entry->GetObject();
643 //_____________________________________________________________________________
645 Bool_t AliTOFcalib::ReadParOnlineStatusFromCDB(Char_t *sel, Int_t nrun)
647 //Read calibration parameters from the CDB -------> new calib objs!!!!!
648 AliCDBManager *man = AliCDBManager::Instance();
649 Char_t *sel1 = "Status" ;
651 sprintf(out,"%s/%s",sel,sel1);
652 AliCDBEntry *entry = man->Get(out,nrun);
654 AliFatal("Exiting, no CDB object (Status) found!!!");
657 if(!entry->GetObject()){
658 AliFatal("Exiting, no CDB object (Status) found!!!");
662 fStatus =(AliTOFChannelOnlineStatusArray*)entry->GetObject();
667 //_____________________________________________________________________________
669 Bool_t AliTOFcalib::ReadParOnlineFromCDB(Char_t *sel, Int_t nrun)
671 //Read calibration parameters from the CDB
672 AliCDBManager *man = AliCDBManager::Instance();
673 Char_t *sel1 = "ParOnline" ;
675 sprintf(out,"%s/%s",sel,sel1);
676 AliCDBEntry *entry = man->Get(out,nrun);
678 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
681 if(!entry->GetObject()){
682 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
686 fTOFCalOnline =(TObjArray*)entry->GetObject();
691 //_____________________________________________________________________________
693 Bool_t AliTOFcalib::ReadParOnlinePulserFromCDB(Char_t *sel, Int_t nrun)
695 //Read calibration parameters from pulser from the CDB
696 AliCDBManager *man = AliCDBManager::Instance();
697 Char_t *sel1 = "Pulser" ;
699 sprintf(out,"%s/%s",sel,sel1);
700 AliCDBEntry *entry = man->Get(out,nrun);
702 AliFatal("Exiting, no CDB object (Pulser) found!!!");
705 if(!entry->GetObject()){
706 AliFatal("Exiting, no CDB object (Pulser) found!!!");
710 fTOFCalOnlinePulser =(TObjArray*)entry->GetObject();
715 //_____________________________________________________________________________
717 Bool_t AliTOFcalib::ReadParOnlineNoiseFromCDB(Char_t *sel, Int_t nrun)
719 //Read calibration parameters from noise from the CDB
720 AliCDBManager *man = AliCDBManager::Instance();
721 Char_t *sel1 = "Noise" ;
723 sprintf(out,"%s/%s",sel,sel1);
724 AliCDBEntry *entry = man->Get(out,nrun);
726 AliFatal("Exiting, no CDB object (Noise) found!!!");
729 if(!entry->GetObject()){
730 AliFatal("Exiting, no CDB object (Noise) found!!!");
734 fTOFCalOnlineNoise =(TObjArray*)entry->GetObject();
739 //_____________________________________________________________________________
741 Bool_t AliTOFcalib::ReadParOnlineHWFromCDB(Char_t *sel, Int_t nrun)
743 //Read calibration parameters from hardware from the CDB
744 AliCDBManager *man = AliCDBManager::Instance();
745 Char_t *sel1 = "HW" ;
747 sprintf(out,"%s/%s",sel,sel1);
748 AliCDBEntry *entry = man->Get(out,nrun);
750 AliFatal("Exiting, no CDB object (HW map) found!!!");
753 if(!entry->GetObject()){
754 AliFatal("Exiting, no CDB object (HW map) found!!!");
758 fTOFCalOnlineHW =(TObjArray*)entry->GetObject();
763 //_____________________________________________________________________________
765 Bool_t AliTOFcalib::ReadParOfflineFromCDB(Char_t *sel, Int_t nrun)
767 //Read calibration parameters from the CDB
768 AliCDBManager *man = AliCDBManager::Instance();
769 Char_t *sel1 = "ParOffline" ;
771 sprintf(out,"%s/%s",sel,sel1);
772 AliCDBEntry *entry = man->Get(out,nrun);
774 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
777 if(!entry->GetObject()){
778 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
781 AliCDBMetaData * md = entry->GetMetaData();
782 fkValidity = md->GetComment();
783 fTOFCalOffline =(TObjArray*)entry->GetObject();
788 //_____________________________________________________________________________
789 void AliTOFcalib::WriteSimHistoOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, TH1F *histo){
790 //Write Sim miscalibration parameters to the CDB
793 AliCDBManager *man = AliCDBManager::Instance();
794 Char_t *sel1 = "SimHisto" ;
796 sprintf(out,"%s/%s",sel,sel1);
797 AliCDBMetaData *mdhisto = new AliCDBMetaData();
798 mdhisto->SetResponsible("Chiara Zampolli");
799 AliCDBId id(out,minrun,maxrun);
800 man->Put(fTOFSimToT,id,mdhisto);
803 //_____________________________________________________________________________
804 Bool_t AliTOFcalib::ReadSimHistoFromCDB(Char_t *sel, Int_t nrun)
806 //Read miscalibration parameters from the CDB
807 AliCDBManager *man = AliCDBManager::Instance();
811 Char_t *sel1 = "SimHisto" ;
813 sprintf(out,"%s/%s",sel,sel1);
814 AliCDBEntry *entry = man->Get(out,nrun);
816 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
819 if(!entry->GetObject()){
820 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
823 TH1F *histo =(TH1F*)entry->GetObject();
827 //_____________________________________________________________________________
828 void AliTOFcalib::WriteRecParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){
829 //Write reconstruction parameters to the CDB
831 AliCDBManager *man = AliCDBManager::Instance();
832 AliCDBMetaData *md = new AliCDBMetaData();
833 md->SetResponsible("Silvia Arcelli");
834 Char_t *sel1 = "RecPar" ;
836 sprintf(out,"%s/%s",sel,sel1);
837 AliCDBId id(out,minrun,maxrun);
838 man->Put(param,id,md);
841 //_____________________________________________________________________________
842 AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(Char_t *sel, Int_t nrun)
844 //Read reconstruction parameters from the CDB
845 AliCDBManager *man = AliCDBManager::Instance();
846 Char_t *sel1 = "RecPar" ;
848 sprintf(out,"%s/%s",sel,sel1);
849 AliCDBEntry *entry = man->Get(out,nrun);
851 AliFatal("Exiting, no CDB object (RecPar) found!!!");
854 if(!entry->GetObject()){
855 AliFatal("Exiting, no CDB object (RecPar) found!!!");
859 AliTOFRecoParam *param=(AliTOFRecoParam*)entry->GetObject();
862 //-----------------------------------------------------------------------------
863 // Calibration methods
864 //-----------------------------------------------------------------------------
865 void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
867 // creating the chain with the trees for calibration
868 // collecting them from reference data
869 // from minrun to maxrun
871 Float_t p[CHENTRIESSMALL];
873 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
874 fTree->Branch("nentries",&nentries,"nentries/I");
875 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
876 AliCDBManager *man = AliCDBManager::Instance();
877 AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT");
878 for (Int_t irun = minrun;irun<=maxrun;irun++){
879 AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
881 AliInfo(Form("No entry found for run %i",irun));
884 TTree *tree = new TTree();
885 tree = (TTree*)entry->GetObject();
886 tree->SetBranchAddress("nentries",&nentries);
887 tree->SetBranchAddress("TOFentries",p);
888 fTree->CopyEntries(tree);
893 AliInfo(Form("Number of runs being analyzed %i",fNruns));
895 //-----------------------------------------------------------------------------
896 void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
898 // creating the chain with the trees for calibration
899 // collecting them from the Grid
900 // from minrun to maxrun
902 Float_t p[CHENTRIESSMALL];
904 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
905 fTree->SetDirectory(0);
906 fTree->Branch("nentries",&nentries,"nentries/I");
907 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
908 AliInfo("connected to alien");
909 TGrid::Connect("alien://");
911 Char_t filename[100];
912 for (Int_t irun = minrun;irun<=maxrun;irun++){
913 sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
914 TFile *filegrid = TFile::Open(filename,"READ");
915 TTree *tree = (TTree*)filegrid->Get("T");
916 tree->SetBranchAddress("nentries",&nentries);
917 tree->SetBranchAddress("TOFentries",p);
918 fTree->CopyEntries(tree);
923 AliInfo(Form("Number of runs being analyzed %i",fNruns));
925 //-----------------------------------------------------------------------------
926 void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
928 // creating the tree with the trees for calibration
929 // collecting them from reference data (from file)
930 // from minrun to maxrun
932 Float_t p[CHENTRIESSMALL];
934 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
935 fTree->SetDirectory(0);
936 fTree->Branch("nentries",&nentries,"nentries/I");
937 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
938 Char_t filename[100];
939 for (Int_t irun = minrun;irun<=maxrun;irun++){
940 sprintf(filename,"$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
941 TFile *file = new TFile(filename,"READ");
942 TTree *tree = (TTree*)file->Get("T");
943 tree->SetBranchAddress("nentries",&nentries);
944 tree->SetBranchAddress("TOFentries",p);
945 fTree->CopyEntries(tree);
952 AliInfo(Form("Number of runs being analyzed %i",fNruns));
954 //-----------------------------------------------------------------------------
955 void AliTOFcalib::CreateChainFromGrid(Int_t minrun, Int_t maxrun){
957 // creating the chain with the trees for calibration
958 // collecting them from the Grid
959 // from minrun to maxrun
961 fChain = new TChain("T");
962 AliInfo("connected to alien");
963 TGrid::Connect("alien://");
965 Char_t filename[100];
966 for (Int_t irun = minrun;irun<=maxrun;irun++){
967 sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
968 fChain->Add(filename);
972 AliInfo(Form("Number of runs being analyzed %i",fNruns));
974 //-----------------------------------------------------------------------------
975 Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
977 // calibrating summing more than one channels
978 // computing calibration parameters
980 // 0 -> everything was ok
981 // 1 -> no tree for calibration found
982 // 2 -> not enough statistics to perform calibration
983 // 3 -> problems with arrays
985 TH1::AddDirectory(0);
987 AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ;
988 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
989 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
991 Float_t p[CHENTRIESSMALL];
993 //fTree->SetBranchAddress("nentries",&nentries);
994 //fTree->SetBranchAddress("TOFentries",p);
995 fChain->SetBranchAddress("nentries",&nentries);
996 fChain->SetBranchAddress("TOFentries",p);
998 Float_t ntracksTotalmean =0;
999 for (Int_t i=ichmin; i<ichmax; i++){
1001 for (Int_t irun=0;irun<fNruns;irun++){
1002 ientry = i+irun*fNChannels;
1003 //fTree->GetEntry(ientry);
1004 fChain->GetEntry(ientry);
1005 Int_t ntracksRun=nentries/3;
1006 ntracksTotalmean+=ntracksRun;
1010 if (ntracksTotalmean < MEANENTRIES) {
1011 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1015 //filling ToT and Time arrays
1017 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1018 Float_t minToT = 0; // ns
1019 Float_t maxToT = 4.88; // ns
1021 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1022 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1023 Int_t ntracksTotal = 0;
1024 Int_t ntracksRun = 0;
1025 Double_t binsProfile[101]; // sized larger than necessary, the correct
1026 // dim being set in the booking of the profile
1027 Int_t nusefulbins=0;
1029 for (Int_t i = ichmin;i<ichmax;i++){
1031 for (Int_t irun=0;irun<fNruns;irun++){
1032 ientry = i+irun*fNChannels;
1033 //fTree->GetEntry(ientry);
1034 fChain->GetEntry(ientry);
1035 ntracksTotal+=nentries/3;
1036 ntracksRun=nentries/3;
1037 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun));
1038 for (Int_t j=0;j<ntracksRun;j++){
1039 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1040 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1041 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1042 Float_t tot = p[idxexToT];
1043 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1044 meantime+=p[idxexTime]-p[idxexExTime];
1049 nusefulbins = FindBins(hToT,&binsProfile[0]);
1050 meantime/=ntracksTotal;
1051 AliDebug(2, Form("meantime = %f",meantime));
1053 for (Int_t j=1;j<=nusefulbins;j++) {
1054 AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j]));
1057 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1058 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1060 for (Int_t irun=0;irun<fNruns;irun++){
1062 for (Int_t i=ichmin; i<ichmax; i++){
1063 ientry = i+irun*fNChannels;
1064 //fTree->GetEntry(ientry);
1065 fChain->GetEntry(ientry);
1066 ntracksRun=nentries/3;
1067 for (Int_t j=0;j<ntracksRun;j++){
1068 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1069 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1070 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1071 Float_t tot = p[idxexToT];
1072 Float_t time = p[idxexTime]-p[idxexExTime];
1073 AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1074 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1075 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1080 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1081 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1083 for(Int_t kk=0;kk<6;kk++){
1084 par[kk]=calibfunc->GetParameter(kk);
1085 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1088 if(strstr(optionSave,"save")){
1089 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1091 TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
1092 TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
1093 TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
1094 TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
1095 hSlewingProf->Write(profName);
1096 htimetot->Write(timeTotName);
1097 hToT->Write(totName);
1098 hdeltaTime->Write(deltaName);
1106 delete hSlewingProf;
1113 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin);
1114 calChannel->SetSlewPar(par);
1115 WriteParOfflineOnCDB("TOF/Calib","valid");
1118 //----------------------------------------------------------------------------
1119 Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
1121 // computing calibration parameters for channel i
1123 // 0 -> everything was ok
1124 // 1 -> no tree for calibration found
1125 // 2 -> not enough statistics to perform calibration
1126 // 3 -> problems with arrays
1128 TH1::AddDirectory(0);
1130 AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ;
1131 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1132 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1134 Float_t p[MAXCHENTRIESSMALL];
1136 //fTree->SetBranchAddress("nentries",&nentries);
1137 //fTree->SetBranchAddress("TOFentries",p);
1138 fChain->SetBranchAddress("nentries",&nentries);
1139 fChain->SetBranchAddress("TOFentries",p);
1141 Float_t ntracksTotal =0;
1142 for (Int_t irun=0;irun<fNruns;irun++){
1144 ientry = i+irun*fNChannels;
1145 //fTree->GetEntry(ientry);
1146 fChain->GetEntry(ientry);
1147 ntracksTotal+=nentries/3;
1150 if (ntracksTotal < MEANENTRIES) {
1151 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1155 //filling ToT and Time arrays
1157 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1158 Float_t minToT = 0; // ns
1159 Float_t maxToT = 4.88; // ns
1161 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1162 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1163 Int_t ntracksRun = 0;
1164 Double_t binsProfile[101]; // sized larger than necessary, the correct
1165 // dim being set in the booking of the profile
1166 Int_t nusefulbins=0;
1168 for (Int_t irun=0;irun<fNruns;irun++){
1170 ientry = i+irun*fNChannels;
1171 //fTree->GetEntry(ientry);
1172 fChain->GetEntry(ientry);
1173 ntracksRun=nentries/3;
1174 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun));
1175 for (Int_t j=0;j<ntracksRun;j++){
1176 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1177 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1178 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1179 Float_t tot = p[idxexToT];
1180 meantime+=p[idxexTime]-p[idxexExTime];
1181 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1186 nusefulbins = FindBins(hToT,&binsProfile[0]);
1187 meantime/=ntracksTotal;
1188 AliDebug(2,Form("meantime = %f",meantime));
1190 for (Int_t j=1;j<=nusefulbins;j++) {
1191 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1194 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1195 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1196 for (Int_t irun=0;irun<fNruns;irun++){
1198 ientry = i+irun*fNChannels;
1199 //fTree->GetEntry(ientry);
1200 fChain->GetEntry(ientry);
1201 ntracksRun=nentries/3;
1202 for (Int_t j=0;j<ntracksRun;j++){
1203 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1204 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1205 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1206 Float_t tot = p[idxexToT];
1207 Float_t time = p[idxexTime]-p[idxexExTime];
1208 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1209 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1210 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1214 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1215 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1217 for(Int_t kk=0;kk<6;kk++){
1218 par[kk]=calibfunc->GetParameter(kk);
1219 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1223 if(strstr(optionSave,"save")){
1224 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1226 TString profName=Form("Profile%06i",i);
1227 TString timeTotName=Form("TimeTot%06i",i);
1228 TString totName=Form("Tot%06i",i);
1229 TString deltaName=Form("Delta%06i",i);
1230 hSlewingProf->Write(profName);
1231 htimetot->Write(timeTotName);
1232 hToT->Write(totName);
1233 hdeltaTime->Write(deltaName);
1241 delete hSlewingProf;
1248 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1249 calChannel->SetSlewPar(par);
1250 WriteParOfflineOnCDB("TOF/Calib","valid");
1253 //----------------------------------------------------------------------------
1254 Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
1256 // calibrating an array of channels
1257 // computing calibration parameters
1259 // 0 -> everything was ok
1260 // 1 -> no tree for calibration found
1261 // 2 -> not enough statistics to perform calibration
1262 // 3 -> problems with arrays
1264 TH1::AddDirectory(0);
1266 AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ;
1267 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1268 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1269 for (Int_t ich=0; ich<nch; ich++){
1271 AliInfo(Form("Calibrating channel = %i",i )) ;
1273 Float_t p[MAXCHENTRIESSMALL];
1275 //fTree->SetBranchAddress("nentries",&nentries);
1276 //fTree->SetBranchAddress("TOFentries",p);
1277 fChain->SetBranchAddress("nentries",&nentries);
1278 fChain->SetBranchAddress("TOFentries",p);
1280 Float_t ntracksTotalmean =0;
1281 for (Int_t ich=0; ich<nch; ich++){
1284 for (Int_t irun=0;irun<fNruns;irun++){
1285 ientry = i+irun*fNChannels;
1286 //fTree->GetEntry(ientry);
1287 fChain->GetEntry(ientry);
1288 ntracksTotalmean+=nentries/3;
1292 ntracksTotalmean/=nch;
1293 if (ntracksTotalmean < MEANENTRIES) {
1294 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1298 //filling ToT and Time arrays
1300 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1301 Float_t minToT = 0; // ns
1302 Float_t maxToT = 4.88; // ns
1303 TFile * fileProf=0x0;
1304 if(strstr(optionSave,"save")){
1305 fileProf = new TFile("TOFCalibSave.root","recreate");
1307 for (Int_t ich=0; ich<nch; ich++) {
1308 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1309 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1310 Double_t binsProfile[101]; // sized larger than necessary, the correct
1311 // dim being set in the booking of the profile
1312 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1313 Int_t ntracksTotal = 0;
1314 Int_t ntracksRun = 0;
1315 Int_t nusefulbins=0;
1318 for (Int_t irun=0;irun<fNruns;irun++){
1319 i = ch[ich]+irun*fNChannels;
1320 AliDebug(2,Form("Calibrating channel %i",i));
1321 //fTree->GetEntry(i);
1322 fChain->GetEntry(i);
1323 ntracksTotal+=nentries/3;
1325 if (ntracksTotal < MEANENTRIES) {
1326 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",i,ntracksTotal));
1330 for (Int_t irun=0;irun<fNruns;irun++){
1331 i = ch[ich]+irun*fNChannels;
1332 //fTree->GetEntry(i);
1333 fChain->GetEntry(i);
1334 ntracksRun=nentries/3;
1335 for (Int_t j=0;j<ntracksRun;j++){
1336 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1337 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1338 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1339 Float_t tot = p[idxexToT];
1340 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1341 meantime+=p[idxexTime]-p[idxexExTime];
1346 nusefulbins = FindBins(hToT,&binsProfile[0]);
1347 meantime/=ntracksTotal;
1348 for (Int_t j=1;j<=nusefulbins;j++) {
1349 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,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 i = ch[ich]+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
1370 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1371 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1373 for(Int_t kk=0;kk<6;kk++){
1374 par[kk]=calibfunc->GetParameter(kk);
1375 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1378 if(strstr(optionSave,"save") && fileProf){
1379 TString profName=Form("Profile%06i",i);
1380 TString timeTotName=Form("TimeTot%06i",i);
1381 TString totName=Form("Tot%06i",i);
1382 TString deltaName=Form("Delta%06i",i);
1384 hSlewingProf->Write(profName);
1385 htimetot->Write(timeTotName);
1386 hToT->Write(totName);
1387 hdeltaTime->Write(deltaName);
1390 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1391 calChannel->SetSlewPar(par);
1394 delete hSlewingProf;
1402 if(strstr(optionSave,"save") && fileProf){
1407 WriteParOfflineOnCDB("TOF/Calib","valid");
1411 //----------------------------------------------------------------------------
1412 Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){
1414 // computing calibration parameters using the old profiling algo
1416 // 0 -> everything was ok
1417 // 1 -> no tree for calibration found
1418 // 2 -> not enough statistics to perform calibration
1419 // 3 -> problems with arrays
1421 TH1::AddDirectory(0);
1423 AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ;
1424 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1425 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1426 Float_t p[MAXCHENTRIESSMALL];
1428 Int_t ntracksTotal=0;
1429 //fTree->SetBranchAddress("nentries",&nentries);
1430 //fTree->SetBranchAddress("TOFentries",p);
1431 fChain->SetBranchAddress("nentries",&nentries);
1432 fChain->SetBranchAddress("TOFentries",p);
1434 for (Int_t irun=0;irun<fNruns;irun++){
1435 Int_t i = ich+irun*fNChannels;
1436 //fTree->GetEntry(i);
1437 fChain->GetEntry(i);
1438 ntracksTotal+=nentries/3;
1441 if (ntracksTotal < MEANENTRIES) {
1442 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1446 TH1F * hProf = new TH1F();
1447 hProf = Profile(ich);
1448 hProf->Fit("pol5",optionFit,"",0,4);
1449 TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
1451 for(Int_t kk=0;kk<6;kk++){
1452 par[kk]=calibfunc->GetParameter(kk);
1453 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1456 if(strstr(optionSave,"save")){
1457 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1459 TString profName=Form("Profile%06i",ich);
1460 hProf->Write(profName);
1468 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich);
1469 calChannel->SetSlewPar(par);
1470 WriteParOfflineOnCDB("TOF/Calib","valid");
1473 //----------------------------------------------------------------------------
1474 Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
1476 // calibrating the whole TOF
1477 // computing calibration parameters
1479 // 0 -> everything was ok
1480 // 1 -> no tree for calibration found
1481 // 2 -> not enough statistics to perform calibration
1482 // 3 -> problems with arrays
1484 TH1::AddDirectory(0);
1486 AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ;
1487 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1488 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1490 TFile * fileProf=0x0;
1491 if(strstr(optionSave,"save")){
1492 fileProf = new TFile("TOFCalibSave.root","recreate");
1495 Float_t p[MAXCHENTRIESSMALL];
1497 //fTree->SetBranchAddress("nentries",&nentries);
1498 //fTree->SetBranchAddress("TOFentries",p);
1499 fChain->SetBranchAddress("nentries",&nentries);
1500 fChain->SetBranchAddress("TOFentries",p);
1502 Float_t ntracksTotalmean =0;
1503 for (Int_t ii=0; ii<fNChannels; ii++){
1504 for (Int_t irun=0;irun<fNruns;irun++){
1505 Int_t i = ii+irun*fNChannels;
1506 //fTree->GetEntry(i);
1507 fChain->GetEntry(i);
1508 ntracksTotalmean+=nentries/3;
1512 ntracksTotalmean/=fNChannels;
1513 if (ntracksTotalmean < MEANENTRIES) {
1514 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1518 //filling ToT and Time arrays
1520 Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps
1521 Float_t minToT = 0; // ns
1522 Float_t maxToT = 4.88;// ns
1523 for (Int_t ii=0; ii<fNChannels; ii++) {
1524 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1525 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1526 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1527 if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
1529 Int_t nusefulbins=0;
1530 Double_t binsProfile[101]; // sized larger than necessary, the correct
1531 // dim being set in the booking of the profile
1532 Int_t ntracksRun = 0;
1533 Int_t ntracksTotal = 0;
1534 for (Int_t irun=0;irun<fNruns;irun++){
1535 Int_t i = ii+irun*fNChannels;
1536 //fTree->GetEntry(i);
1537 fChain->GetEntry(i);
1538 ntracksTotal+=nentries/3;
1540 if (ntracksTotal < MEANENTRIES) {
1541 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",ii,ntracksTotal));
1545 for (Int_t irun=0;irun<fNruns;irun++){
1546 Int_t i = ii+irun*fNChannels;
1547 //fTree->GetEntry(i);
1548 fChain->GetEntry(i);
1549 ntracksRun=nentries/3;
1550 for (Int_t j=0;j<ntracksRun;j++){
1551 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1552 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1553 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1554 Float_t tot = p[idxexToT];
1555 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1556 meantime+=p[idxexTime]-p[idxexExTime];
1560 nusefulbins = FindBins(hToT,&binsProfile[0]);
1561 meantime/=ntracksTotal;
1562 for (Int_t j=0;j<nusefulbins;j++) {
1563 AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j]));
1565 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1566 for (Int_t irun=0;irun<fNruns;irun++){
1567 Int_t i = ii+irun*fNChannels;
1568 //fTree->GetEntry(i);
1569 fChain->GetEntry(i);
1570 ntracksRun=nentries/3;
1571 for (Int_t j=0;j<ntracksRun;j++){
1572 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1573 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1574 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1575 Float_t tot = p[idxexToT];
1576 Float_t time = p[idxexTime]-p[idxexExTime];
1577 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1578 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1579 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1582 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1583 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1585 for(Int_t kk=0;kk<6;kk++){
1586 par[kk]=calibfunc->GetParameter(kk);
1587 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1590 if(strstr(optionSave,"save") && fileProf){
1591 TString profName=Form("Profile%06i",ii);
1592 TString timeTotName=Form("TimeTot%06i",ii);
1593 TString totName=Form("Tot%06i",ii);
1594 TString deltaName=Form("Delta%06i",ii);
1596 hSlewingProf->Write(profName);
1597 htimetot->Write(timeTotName);
1598 hToT->Write(totName);
1599 hdeltaTime->Write(deltaName);
1601 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii);
1602 calChannel->SetSlewPar(par);
1606 delete hSlewingProf;
1614 if(strstr(optionSave,"save")){
1619 WriteParOfflineOnCDB("TOF/Calib","valid");
1623 //-----------------------------------------------------------------------
1624 TH1F* AliTOFcalib::Profile(Int_t ich)
1628 Float_t p[MAXCHENTRIESSMALL];
1630 //fTree->SetBranchAddress("nentries",&nentries);
1631 //fTree->SetBranchAddress("TOFentries",p);
1632 fChain->SetBranchAddress("nentries",&nentries);
1633 fChain->SetBranchAddress("TOFentries",p);
1635 //Prepare histograms for Slewing Correction
1636 const Int_t knbinToT = 100;
1637 Int_t nbinTime = 200;
1638 Float_t minTime = -5.5; //ns
1639 Float_t maxTime = 5.5; //ns
1640 Float_t minToT = 0; //ns
1641 Float_t maxToT = 5.; //ns
1642 Float_t deltaToT = (maxToT-minToT)/knbinToT;
1643 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];
1644 Int_t n[knbinToT+1], nentrx[knbinToT+1];
1645 Double_t sigmaToT[knbinToT+1];
1646 for (Int_t i = 0; i < knbinToT+1 ; i++){
1664 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
1665 Int_t ntracksRun = 0;
1666 TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
1667 for (Int_t irun=0;irun<fNruns;irun++){
1668 Int_t i = ich+irun*fNChannels;
1669 //fTree->GetEntry(i);
1670 fChain->GetEntry(i);
1671 ntracksRun=nentries/3;
1672 for (Int_t j=0;j<ntracksRun;j++){
1673 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1674 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1675 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1676 Float_t tot = p[idxexToT];
1677 Float_t time = p[idxexTime]-p[idxexExTime];
1678 Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
1679 if ((tot != 0) && ( time!= 0)){
1681 vTime2[nx]+=time*time;
1685 hSlewing->Fill(tot,time);
1689 Int_t nbinsToT=hSlewing->GetNbinsX();
1690 if (nbinsToT != knbinToT) {
1691 AliError("Profile :: incompatible numbers of bins");
1696 for (Int_t i=1;i<=nbinsToT;i++){
1698 n[usefulBins]+=nentrx[i];
1699 if (n[usefulBins]==0 && i == nbinsToT) {
1702 meanTime[usefulBins]+=vTime[i];
1703 meanTime2[usefulBins]+=vTime2[i];
1704 meanToT[usefulBins]+=vToT[i];
1705 meanToT2[usefulBins]+=vToT2[i];
1706 if (n[usefulBins]<10 && i!=nbinsToT) continue;
1707 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
1708 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
1709 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1710 *(meanTime2[usefulBins]-meanTime[usefulBins]
1711 *meanTime[usefulBins]/n[usefulBins]));
1712 if ((1./n[usefulBins]/n[usefulBins]
1713 *(meanToT2[usefulBins]-meanToT[usefulBins]
1714 *meanToT[usefulBins]/n[usefulBins]))< 0) {
1715 AliError(" too small radical" );
1716 sigmaToT[usefulBins]=0;
1719 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1720 *(meanToT2[usefulBins]-meanToT[usefulBins]
1721 *meanToT[usefulBins]/n[usefulBins]));
1726 for (Int_t i=0;i<usefulBins;i++){
1727 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
1728 histo->Fill(mToT[i],mTime[i]);
1729 histo->SetBinError(binN,sigmaTime[i]);
1736 //----------------------------------------------------------------------------
1737 Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
1739 // to determine the bins for ToT histo
1743 Int_t nbin = h->GetNbinsX();
1744 Int_t nentries = (Int_t)h->GetEntries();
1745 Float_t max = h->GetBinLowEdge(nbin);
1746 Int_t nusefulbins=0;
1748 // setting maxvalue of entries per bin
1749 if (nentries <= 60) maxcont = 2;
1750 else if (nentries <= 100) maxcont = 5;
1751 else if (nentries <= 500) maxcont = 10;
1753 for (Int_t j=1;j<=nbin;j++) {
1754 cont += (Int_t)h->GetBinContent(j);
1758 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1767 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1768 binsProfile[nusefulbins]=max;
1771 binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);