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):
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
193 TTask::operator=(calib);
194 fNChannels = calib.fNChannels;
196 fStatus = calib.fStatus;
197 fTOFSimToT = calib.fTOFSimToT;
198 fkValidity = calib.fkValidity;
200 fChain = calib.fChain;
201 fNruns = calib.fNruns;
202 fFirstRun = calib.fFirstRun;
203 fLastRun = calib.fLastRun;
204 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
205 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
206 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
207 AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
208 AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
209 AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
210 fTOFCalOnline->AddAt(calChOnline,iarray);
211 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
212 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
213 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
214 fTOFCalOffline->AddAt(calChOffline,iarray);
219 //____________________________________________________________________________
221 AliTOFcalib::~AliTOFcalib()
223 //TOF Calibration Class dtor
224 if(!(AliCDBManager::Instance()->GetCacheFlag())){ // CDB objects must NOT be deleted if cache is active!
226 delete fTOFCalOnline;
228 if (fTOFCalOnlinePulser){
229 delete fTOFCalOnlinePulser;
231 if (fTOFCalOnlineNoise){
232 delete fTOFCalOnlineNoise;
234 if (fTOFCalOnlineHW){
235 delete fTOFCalOnlineHW;
238 delete fTOFCalOffline;
250 if (fTree!=0x0) delete fTree;
251 if (fChain!=0x0) delete fChain;
253 //_____________________________________________________________________________
254 void AliTOFcalib::CreateCalArrays(){
256 // creating arrays for online/offline calibration objs
258 fTOFCalOnline = new TObjArray(fNChannels);
259 fTOFCalOnlinePulser = new TObjArray(fNChannels);
260 fTOFCalOnlineNoise = new TObjArray(fNChannels);
261 fTOFCalOnlineHW = new TObjArray(fNChannels);
262 fTOFCalOffline = new TObjArray(fNChannels);
263 fTOFCalOnline->SetOwner();
264 fTOFCalOnlinePulser->SetOwner();
265 fTOFCalOnlineNoise->SetOwner();
266 fTOFCalOnlineHW->SetOwner();
267 fTOFCalOffline->SetOwner();
268 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
269 AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline();
270 AliTOFChannelOnlineStatus * calChOnlineStPulser = new AliTOFChannelOnlineStatus();
271 AliTOFChannelOnlineStatus * calChOnlineStNoise = new AliTOFChannelOnlineStatus();
272 AliTOFChannelOnlineStatus * calChOnlineStHW = new AliTOFChannelOnlineStatus();
273 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
274 fTOFCalOnline->AddAt(calChOnline,iarray);
275 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
276 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
277 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
278 fTOFCalOffline->AddAt(calChOffline,iarray);
280 fCal = new AliTOFChannelOnlineArray(fNChannels);
281 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
283 //_____________________________________________________________________________
284 void AliTOFcalib::CreateCalObjects(){
286 // creating arrays for online/offline calibration objs
288 fTOFCalOffline = new TObjArray(fNChannels);
289 fTOFCalOffline->SetOwner();
290 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
291 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
292 fTOFCalOffline->AddAt(calChOffline,iarray);
294 fCal = new AliTOFChannelOnlineArray(fNChannels);
295 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
297 //_____________________________________________________________________________
298 void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
300 //Write calibration parameters to the CDB
303 AliCDBManager *man = AliCDBManager::Instance();
304 const Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
306 sprintf(out,"%s/%s",sel,sel1);
307 AliDebug(2,Form("Writing TOF configuration map for online calib on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
308 AliCDBId id(out,fFirstRun,fLastRun);
309 AliCDBMetaData *md = new AliCDBMetaData();
310 md->SetResponsible("Chiara Zampolli");
314 man->Put(fConfigMap,id,md);
317 //_____________________________________________________________________________
319 void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel)
321 //Write calibration parameters to the CDB with infinite validity
322 AliCDBManager *man = AliCDBManager::Instance();
323 const Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
325 sprintf(out,"%s/%s",sel,sel1);
326 AliCDBRunRange runrange(fFirstRun,fLastRun);
327 AliDebug(2,Form("Writing TOF config map for online calib on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
328 AliCDBId id(out,runrange);
329 AliCDBMetaData *md = new AliCDBMetaData();
330 md->SetResponsible("Chiara Zampolli");
334 man->Put(fConfigMap,id,md);
337 //_____________________________________________________________________________
338 void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
340 //Write calibration parameters to the CDB -------> new calib objs!!!!!
343 AliCDBManager *man = AliCDBManager::Instance();
344 const Char_t *sel1 = "ParOnlineDelay" ; // to be consistent with TOFPreprocessor
346 sprintf(out,"%s/%s",sel,sel1);
347 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
348 AliCDBId id(out,fFirstRun,fLastRun);
349 AliCDBMetaData *md = new AliCDBMetaData();
350 md->SetResponsible("Chiara Zampolli");
354 man->Put(fCal,id,md);
357 //_____________________________________________________________________________
358 void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
360 //Write calibration parameters to the CDB -------> new calib objs!!!!!
363 AliCDBManager *man = AliCDBManager::Instance();
364 const Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
366 sprintf(out,"%s/%s",sel,sel1);
367 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
368 AliCDBId id(out,fFirstRun,fLastRun);
369 AliCDBMetaData *md = new AliCDBMetaData();
370 md->SetResponsible("Chiara Zampolli");
374 man->Put(fStatus,id,md);
377 //_____________________________________________________________________________
379 void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel)
381 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
382 AliCDBManager *man = AliCDBManager::Instance();
383 const Char_t *sel1 = "ParOnlineDelay" ; // to be consistent with TOFPreprocessor
385 sprintf(out,"%s/%s",sel,sel1);
386 AliCDBRunRange runrange(fFirstRun,fLastRun);
387 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
388 AliCDBId id(out,runrange);
389 AliCDBMetaData *md = new AliCDBMetaData();
390 md->SetResponsible("Chiara Zampolli");
394 man->Put(fCal,id,md);
397 //_____________________________________________________________________________
399 void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel)
401 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
402 AliCDBManager *man = AliCDBManager::Instance();
403 const Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
405 sprintf(out,"%s/%s",sel,sel1);
406 AliCDBRunRange runrange(fFirstRun,fLastRun);
407 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
408 AliCDBId id(out,runrange);
409 AliCDBMetaData *md = new AliCDBMetaData();
410 md->SetResponsible("Chiara Zampolli");
414 man->Put(fStatus,id,md);
417 //_____________________________________________________________________________
418 void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
420 //Write calibration parameters to the CDB
423 AliCDBManager *man = AliCDBManager::Instance();
424 const Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
426 sprintf(out,"%s/%s",sel,sel1);
427 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
428 AliCDBId id(out,fFirstRun,fLastRun);
429 AliCDBMetaData *md = new AliCDBMetaData();
430 md->SetResponsible("Chiara Zampolli");
431 if (!fTOFCalOnline) {
434 man->Put(fTOFCalOnline,id,md);
437 //_____________________________________________________________________________
438 void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
440 //Write calibration parameters from pulser to the CDB
443 AliCDBManager *man = AliCDBManager::Instance();
444 const Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
446 sprintf(out,"%s/%s",sel,sel1);
447 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
448 AliCDBId id(out,fFirstRun,fLastRun);
449 AliCDBMetaData *md = new AliCDBMetaData();
450 md->SetResponsible("Chiara Zampolli");
451 if (!fTOFCalOnlinePulser) {
454 man->Put(fTOFCalOnlinePulser,id,md);
457 //_____________________________________________________________________________
458 void AliTOFcalib::WriteParOnlineNoiseOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
460 //Write calibration parameters from noise to the CDB
463 AliCDBManager *man = AliCDBManager::Instance();
464 const Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
466 sprintf(out,"%s/%s",sel,sel1);
467 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
468 AliCDBId id(out,fFirstRun,fLastRun);
469 AliCDBMetaData *md = new AliCDBMetaData();
470 md->SetResponsible("Chiara Zampolli");
471 if (!fTOFCalOnlineNoise) {
474 man->Put(fTOFCalOnlineNoise,id,md);
477 //_____________________________________________________________________________
478 void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
480 //Write calibration parameters from hardware to the CDB
483 AliCDBManager *man = AliCDBManager::Instance();
484 const Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
486 sprintf(out,"%s/%s",sel,sel1);
487 AliDebug(2,Form("Writing TOF online calib obj from hardware on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
488 AliCDBId id(out,fFirstRun,fLastRun);
489 AliCDBMetaData *md = new AliCDBMetaData();
490 md->SetResponsible("Chiara Zampolli");
491 if (!fTOFCalOnlineHW) {
494 man->Put(fTOFCalOnlineHW,id,md);
497 //_____________________________________________________________________________
499 void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel)
501 //Write calibration parameters to the CDB with infinite validity
502 AliCDBManager *man = AliCDBManager::Instance();
503 const Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
505 sprintf(out,"%s/%s",sel,sel1);
506 AliCDBRunRange runrange(fFirstRun,fLastRun);
507 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
508 AliCDBId id(out,runrange);
509 AliCDBMetaData *md = new AliCDBMetaData();
510 md->SetResponsible("Chiara Zampolli");
511 if (!fTOFCalOnline) {
514 man->Put(fTOFCalOnline,id,md);
517 //_____________________________________________________________________________
519 void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel)
521 //Write calibration parameters from pulser to the CDB with infinite validity
522 AliCDBManager *man = AliCDBManager::Instance();
523 const Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
525 sprintf(out,"%s/%s",sel,sel1);
526 AliCDBRunRange runrange(fFirstRun,fLastRun);
527 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
528 AliCDBId id(out,runrange);
529 AliCDBMetaData *md = new AliCDBMetaData();
530 md->SetResponsible("Chiara Zampolli");
531 if (!fTOFCalOnlinePulser) {
534 man->Put(fTOFCalOnlinePulser,id,md);
537 //_____________________________________________________________________________
539 void AliTOFcalib::WriteParOnlineNoiseOnCDB(const Char_t *sel)
541 //Write calibration parameters from noise to the CDB with infinite validity
542 AliCDBManager *man = AliCDBManager::Instance();
543 const Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
545 sprintf(out,"%s/%s",sel,sel1);
546 AliCDBRunRange runrange(fFirstRun,fLastRun);
547 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
548 AliCDBId id(out,runrange);
549 AliCDBMetaData *md = new AliCDBMetaData();
550 md->SetResponsible("Chiara Zampolli");
551 if (!fTOFCalOnlineNoise) {
554 man->Put(fTOFCalOnlineNoise,id,md);
557 //_____________________________________________________________________________
559 void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel)
561 //Write calibration parameters from hardware to the CDB with infinite validity
562 AliCDBManager *man = AliCDBManager::Instance();
563 const Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
565 sprintf(out,"%s/%s",sel,sel1);
566 AliCDBRunRange runrange(fFirstRun,fLastRun);
567 AliDebug(2,Form("Writing TOF online calib obj from harware on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
568 AliCDBId id(out,runrange);
569 AliCDBMetaData *md = new AliCDBMetaData();
570 md->SetResponsible("Chiara Zampolli");
571 if (!fTOFCalOnlineHW) {
574 man->Put(fTOFCalOnlineHW,id,md);
577 //_____________________________________________________________________________
579 void AliTOFcalib::WriteParOfflineOnCDB(const Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun)
581 //Write calibration parameters to the CDB
584 AliCDBManager *man = AliCDBManager::Instance();
585 const Char_t *sel1 = "ParOffline" ;
587 sprintf(out,"%s/%s",sel,sel1);
588 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
589 AliCDBId id(out,fFirstRun,fLastRun);
590 AliCDBMetaData *md = new AliCDBMetaData();
591 md->SetResponsible("Chiara Zampolli");
592 md->SetComment(validity);
593 man->Put(fTOFCalOffline,id,md);
596 //_____________________________________________________________________________
598 void AliTOFcalib::WriteParOfflineOnCDB(const Char_t *sel, const Char_t *validity)
600 //Write calibration parameters to the CDB with infinite validity
601 AliCDBManager *man = AliCDBManager::Instance();
602 const Char_t *sel1 = "ParOffline" ;
604 sprintf(out,"%s/%s",sel,sel1);
605 AliCDBRunRange runrange(fFirstRun,fLastRun);
606 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
607 AliCDBId id(out,runrange);
608 AliCDBMetaData *md = new AliCDBMetaData();
609 md->SetResponsible("Chiara Zampolli");
610 md->SetComment(validity);
611 man->Put(fTOFCalOffline,id,md);
614 //_____________________________________________________________________________
616 Bool_t AliTOFcalib::ReadConfigMapFromCDB(const Char_t *sel, Int_t nrun)
618 //Read calibration parameters from the CDB
619 AliCDBManager *man = AliCDBManager::Instance();
620 const Char_t *sel1 = "Config" ;
622 sprintf(out,"%s/%s",sel,sel1);
623 AliCDBEntry *entry = man->Get(out,nrun);
625 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
628 if(!entry->GetObject()){
629 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
633 fConfigMap =(TMap*)entry->GetObject();
638 //_____________________________________________________________________________
640 Bool_t AliTOFcalib::ReadParOnlineDelayFromCDB(const Char_t *sel, Int_t nrun)
642 //Read calibration parameters from the CDB -------> new calib objs!!!!!
643 AliCDBManager *man = AliCDBManager::Instance();
644 const Char_t *sel1 = "ParOnlineDelay" ;
646 sprintf(out,"%s/%s",sel,sel1);
647 AliCDBEntry *entry = man->Get(out,nrun);
649 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
652 if(!entry->GetObject()){
653 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
657 fCal =(AliTOFChannelOnlineArray*)entry->GetObject();
662 //_____________________________________________________________________________
664 Bool_t AliTOFcalib::ReadParOnlineStatusFromCDB(const Char_t *sel, Int_t nrun)
666 //Read calibration parameters from the CDB -------> new calib objs!!!!!
667 AliCDBManager *man = AliCDBManager::Instance();
668 const Char_t *sel1 = "Status" ;
670 sprintf(out,"%s/%s",sel,sel1);
671 AliCDBEntry *entry = man->Get(out,nrun);
673 AliFatal("Exiting, no CDB object (Status) found!!!");
676 if(!entry->GetObject()){
677 AliFatal("Exiting, no CDB object (Status) found!!!");
681 fStatus =(AliTOFChannelOnlineStatusArray*)entry->GetObject();
686 //_____________________________________________________________________________
688 Bool_t AliTOFcalib::ReadParOnlineFromCDB(const Char_t *sel, Int_t nrun)
690 //Read calibration parameters from the CDB
691 AliCDBManager *man = AliCDBManager::Instance();
692 const Char_t *sel1 = "ParOnline" ;
694 sprintf(out,"%s/%s",sel,sel1);
695 AliCDBEntry *entry = man->Get(out,nrun);
697 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
700 if(!entry->GetObject()){
701 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
705 fTOFCalOnline =(TObjArray*)entry->GetObject();
710 //_____________________________________________________________________________
712 Bool_t AliTOFcalib::ReadParOnlinePulserFromCDB(const Char_t *sel, Int_t nrun)
714 //Read calibration parameters from pulser from the CDB
715 AliCDBManager *man = AliCDBManager::Instance();
716 const Char_t *sel1 = "Pulser" ;
718 sprintf(out,"%s/%s",sel,sel1);
719 AliCDBEntry *entry = man->Get(out,nrun);
721 AliFatal("Exiting, no CDB object (Pulser) found!!!");
724 if(!entry->GetObject()){
725 AliFatal("Exiting, no CDB object (Pulser) found!!!");
729 fTOFCalOnlinePulser =(TObjArray*)entry->GetObject();
734 //_____________________________________________________________________________
736 Bool_t AliTOFcalib::ReadParOnlineNoiseFromCDB(const Char_t *sel, Int_t nrun)
738 //Read calibration parameters from noise from the CDB
739 AliCDBManager *man = AliCDBManager::Instance();
740 const Char_t *sel1 = "Noise" ;
742 sprintf(out,"%s/%s",sel,sel1);
743 AliCDBEntry *entry = man->Get(out,nrun);
745 AliFatal("Exiting, no CDB object (Noise) found!!!");
748 if(!entry->GetObject()){
749 AliFatal("Exiting, no CDB object (Noise) found!!!");
753 fTOFCalOnlineNoise =(TObjArray*)entry->GetObject();
758 //_____________________________________________________________________________
760 Bool_t AliTOFcalib::ReadParOnlineHWFromCDB(const Char_t *sel, Int_t nrun)
762 //Read calibration parameters from hardware from the CDB
763 AliCDBManager *man = AliCDBManager::Instance();
764 const Char_t *sel1 = "HW" ;
766 sprintf(out,"%s/%s",sel,sel1);
767 AliCDBEntry *entry = man->Get(out,nrun);
769 AliFatal("Exiting, no CDB object (HW map) found!!!");
772 if(!entry->GetObject()){
773 AliFatal("Exiting, no CDB object (HW map) found!!!");
777 fTOFCalOnlineHW =(TObjArray*)entry->GetObject();
782 //_____________________________________________________________________________
784 Bool_t AliTOFcalib::ReadParOfflineFromCDB(const Char_t *sel, Int_t nrun)
786 //Read calibration parameters from the CDB
787 AliCDBManager *man = AliCDBManager::Instance();
788 const Char_t *sel1 = "ParOffline" ;
790 sprintf(out,"%s/%s",sel,sel1);
791 AliCDBEntry *entry = man->Get(out,nrun);
793 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
796 if(!entry->GetObject()){
797 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
800 AliCDBMetaData * md = entry->GetMetaData();
801 fkValidity = md->GetComment();
802 fTOFCalOffline =(TObjArray*)entry->GetObject();
807 //_____________________________________________________________________________
808 void AliTOFcalib::WriteSimHistoOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, TH1F *histo){
809 //Write Sim miscalibration parameters to the CDB
812 AliCDBManager *man = AliCDBManager::Instance();
813 const Char_t *sel1 = "SimHisto" ;
815 sprintf(out,"%s/%s",sel,sel1);
816 AliCDBMetaData *mdhisto = new AliCDBMetaData();
817 mdhisto->SetResponsible("Chiara Zampolli");
818 AliCDBId id(out,minrun,maxrun);
819 man->Put(fTOFSimToT,id,mdhisto);
822 //_____________________________________________________________________________
823 Bool_t AliTOFcalib::ReadSimHistoFromCDB(const Char_t *sel, Int_t nrun)
825 //Read miscalibration parameters from the CDB
826 AliCDBManager *man = AliCDBManager::Instance();
830 const Char_t *sel1 = "SimHisto" ;
832 sprintf(out,"%s/%s",sel,sel1);
833 AliCDBEntry *entry = man->Get(out,nrun);
835 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
838 if(!entry->GetObject()){
839 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
842 TH1F *histo =(TH1F*)entry->GetObject();
846 //_____________________________________________________________________________
847 void AliTOFcalib::WriteRecParOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){
848 //Write reconstruction parameters to the CDB
850 AliCDBManager *man = AliCDBManager::Instance();
851 AliCDBMetaData *md = new AliCDBMetaData();
852 md->SetResponsible("Silvia Arcelli");
853 const Char_t *sel1 = "RecoParam" ;
855 sprintf(out,"%s/%s",sel,sel1);
856 AliCDBId id(out,minrun,maxrun);
857 man->Put(param,id,md);
860 //_____________________________________________________________________________
861 AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(const Char_t *sel, Int_t nrun)
863 //Read reconstruction parameters from the CDB
864 AliCDBManager *man = AliCDBManager::Instance();
865 const Char_t *sel1 = "RecoParam" ;
867 sprintf(out,"%s/%s",sel,sel1);
868 AliCDBEntry *entry = man->Get(out,nrun);
870 AliFatal("Exiting, no CDB object (RecoParam) found!!!");
873 if(!entry->GetObject()){
874 AliFatal("Exiting, no CDB object (RecoParam) found!!!");
878 AliTOFRecoParam *param=(AliTOFRecoParam*)entry->GetObject();
881 //-----------------------------------------------------------------------------
882 // Calibration methods
883 //-----------------------------------------------------------------------------
884 void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
886 // creating the chain with the trees for calibration
887 // collecting them from reference data
888 // from minrun to maxrun
890 Float_t p[CHENTRIESSMALL];
892 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
893 fTree->Branch("nentries",&nentries,"nentries/I");
894 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
895 AliCDBManager *man = AliCDBManager::Instance();
896 AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT/OCDB");
897 for (Int_t irun = minrun;irun<=maxrun;irun++){
898 AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
900 AliInfo(Form("No entry found for run %i",irun));
903 TTree *tree = new TTree();
904 tree = (TTree*)entry->GetObject();
905 tree->SetBranchAddress("nentries",&nentries);
906 tree->SetBranchAddress("TOFentries",p);
907 fTree->CopyEntries(tree);
912 AliInfo(Form("Number of runs being analyzed %i",fNruns));
914 //-----------------------------------------------------------------------------
915 void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
917 // creating the chain with the trees for calibration
918 // collecting them from the Grid
919 // from minrun to maxrun
921 Float_t p[CHENTRIESSMALL];
923 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
924 fTree->SetDirectory(0);
925 fTree->Branch("nentries",&nentries,"nentries/I");
926 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
927 AliInfo("connected to alien");
928 TGrid::Connect("alien://");
930 Char_t filename[100];
931 for (Int_t irun = minrun;irun<=maxrun;irun++){
932 sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
933 TFile *filegrid = TFile::Open(filename,"READ");
934 TTree *tree = (TTree*)filegrid->Get("T");
935 tree->SetBranchAddress("nentries",&nentries);
936 tree->SetBranchAddress("TOFentries",p);
937 fTree->CopyEntries(tree);
942 AliInfo(Form("Number of runs being analyzed %i",fNruns));
944 //-----------------------------------------------------------------------------
945 void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
947 // creating the tree with the trees for calibration
948 // collecting them from reference data (from file)
949 // from minrun to maxrun
951 Float_t p[CHENTRIESSMALL];
953 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
954 fTree->SetDirectory(0);
955 fTree->Branch("nentries",&nentries,"nentries/I");
956 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
957 Char_t filename[100];
958 for (Int_t irun = minrun;irun<=maxrun;irun++){
959 sprintf(filename,"$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
960 TFile *file = new TFile(filename,"READ");
961 TTree *tree = (TTree*)file->Get("T");
962 tree->SetBranchAddress("nentries",&nentries);
963 tree->SetBranchAddress("TOFentries",p);
964 fTree->CopyEntries(tree);
971 AliInfo(Form("Number of runs being analyzed %i",fNruns));
973 //-----------------------------------------------------------------------------
974 void AliTOFcalib::CreateChainFromGrid(Int_t minrun, Int_t maxrun){
976 // creating the chain with the trees for calibration
977 // collecting them from the Grid
978 // from minrun to maxrun
980 fChain = new TChain("T");
981 AliInfo("connected to alien");
982 TGrid::Connect("alien://");
984 Char_t filename[100];
985 for (Int_t irun = minrun;irun<=maxrun;irun++){
986 sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
987 fChain->Add(filename);
991 AliInfo(Form("Number of runs being analyzed %i",fNruns));
993 //-----------------------------------------------------------------------------
994 Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
996 // calibrating summing more than one channels
997 // computing calibration parameters
999 // 0 -> everything was ok
1000 // 1 -> no tree for calibration found
1001 // 2 -> not enough statistics to perform calibration
1002 // 3 -> problems with arrays
1004 TH1::AddDirectory(0);
1006 AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ;
1007 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1008 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1010 Float_t p[CHENTRIESSMALL];
1012 //fTree->SetBranchAddress("nentries",&nentries);
1013 //fTree->SetBranchAddress("TOFentries",p);
1014 fChain->SetBranchAddress("nentries",&nentries);
1015 fChain->SetBranchAddress("TOFentries",p);
1017 Float_t ntracksTotalmean =0;
1018 for (Int_t i=ichmin; i<ichmax; i++){
1020 for (Int_t irun=0;irun<fNruns;irun++){
1021 ientry = i+irun*fNChannels;
1022 //fTree->GetEntry(ientry);
1023 fChain->GetEntry(ientry);
1024 Int_t ntracksRun=nentries/3;
1025 ntracksTotalmean+=ntracksRun;
1029 if (ntracksTotalmean < MEANENTRIES) {
1030 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1034 //filling ToT and Time arrays
1036 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1037 Float_t minToT = 0; // ns
1038 Float_t maxToT = 4.88; // ns
1040 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1041 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1042 Int_t ntracksTotal = 0;
1043 Int_t ntracksRun = 0;
1044 Double_t binsProfile[101]; // sized larger than necessary, the correct
1045 // dim being set in the booking of the profile
1046 Int_t nusefulbins=0;
1048 for (Int_t i = ichmin;i<ichmax;i++){
1050 for (Int_t irun=0;irun<fNruns;irun++){
1051 ientry = i+irun*fNChannels;
1052 //fTree->GetEntry(ientry);
1053 fChain->GetEntry(ientry);
1054 ntracksTotal+=nentries/3;
1055 ntracksRun=nentries/3;
1056 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun));
1057 for (Int_t j=0;j<ntracksRun;j++){
1058 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1059 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1060 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1061 Float_t tot = p[idxexToT];
1062 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1063 meantime+=p[idxexTime]-p[idxexExTime];
1068 nusefulbins = FindBins(hToT,&binsProfile[0]);
1069 meantime/=ntracksTotal;
1070 AliDebug(2, Form("meantime = %f",meantime));
1072 for (Int_t j=1;j<=nusefulbins;j++) {
1073 AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j]));
1076 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1077 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1079 for (Int_t irun=0;irun<fNruns;irun++){
1081 for (Int_t i=ichmin; i<ichmax; i++){
1082 ientry = i+irun*fNChannels;
1083 //fTree->GetEntry(ientry);
1084 fChain->GetEntry(ientry);
1085 ntracksRun=nentries/3;
1086 for (Int_t j=0;j<ntracksRun;j++){
1087 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1088 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1089 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1090 Float_t tot = p[idxexToT];
1091 Float_t time = p[idxexTime]-p[idxexExTime];
1092 AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1093 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1094 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1099 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1100 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1102 for(Int_t kk=0;kk<6;kk++){
1103 par[kk]=calibfunc->GetParameter(kk);
1104 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1107 if(strstr(optionSave,"save")){
1108 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1110 TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
1111 TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
1112 TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
1113 TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
1114 hSlewingProf->Write(profName);
1115 htimetot->Write(timeTotName);
1116 hToT->Write(totName);
1117 hdeltaTime->Write(deltaName);
1125 delete hSlewingProf;
1132 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin);
1133 calChannel->SetSlewPar(par);
1134 WriteParOfflineOnCDB("TOF/Calib","valid");
1137 //----------------------------------------------------------------------------
1138 Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
1140 // computing calibration parameters for channel i
1142 // 0 -> everything was ok
1143 // 1 -> no tree for calibration found
1144 // 2 -> not enough statistics to perform calibration
1145 // 3 -> problems with arrays
1147 TH1::AddDirectory(0);
1149 AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ;
1150 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1151 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1153 Float_t p[MAXCHENTRIESSMALL];
1155 //fTree->SetBranchAddress("nentries",&nentries);
1156 //fTree->SetBranchAddress("TOFentries",p);
1157 fChain->SetBranchAddress("nentries",&nentries);
1158 fChain->SetBranchAddress("TOFentries",p);
1160 Float_t ntracksTotal =0;
1161 for (Int_t irun=0;irun<fNruns;irun++){
1163 ientry = i+irun*fNChannels;
1164 //fTree->GetEntry(ientry);
1165 fChain->GetEntry(ientry);
1166 ntracksTotal+=nentries/3;
1169 if (ntracksTotal < MEANENTRIES) {
1170 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1174 //filling ToT and Time arrays
1176 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1177 Float_t minToT = 0; // ns
1178 Float_t maxToT = 4.88; // ns
1180 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1181 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1182 Int_t ntracksRun = 0;
1183 Double_t binsProfile[101]; // sized larger than necessary, the correct
1184 // dim being set in the booking of the profile
1185 Int_t nusefulbins=0;
1187 for (Int_t irun=0;irun<fNruns;irun++){
1189 ientry = i+irun*fNChannels;
1190 //fTree->GetEntry(ientry);
1191 fChain->GetEntry(ientry);
1192 ntracksRun=nentries/3;
1193 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun));
1194 for (Int_t j=0;j<ntracksRun;j++){
1195 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1196 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1197 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1198 Float_t tot = p[idxexToT];
1199 meantime+=p[idxexTime]-p[idxexExTime];
1200 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1205 nusefulbins = FindBins(hToT,&binsProfile[0]);
1206 meantime/=ntracksTotal;
1207 AliDebug(2,Form("meantime = %f",meantime));
1209 for (Int_t j=1;j<=nusefulbins;j++) {
1210 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1213 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1214 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1215 for (Int_t irun=0;irun<fNruns;irun++){
1217 ientry = i+irun*fNChannels;
1218 //fTree->GetEntry(ientry);
1219 fChain->GetEntry(ientry);
1220 ntracksRun=nentries/3;
1221 for (Int_t j=0;j<ntracksRun;j++){
1222 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1223 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1224 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1225 Float_t tot = p[idxexToT];
1226 Float_t time = p[idxexTime]-p[idxexExTime];
1227 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1228 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1229 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1233 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1234 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1236 for(Int_t kk=0;kk<6;kk++){
1237 par[kk]=calibfunc->GetParameter(kk);
1238 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1242 if(strstr(optionSave,"save")){
1243 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1245 TString profName=Form("Profile%06i",i);
1246 TString timeTotName=Form("TimeTot%06i",i);
1247 TString totName=Form("Tot%06i",i);
1248 TString deltaName=Form("Delta%06i",i);
1249 hSlewingProf->Write(profName);
1250 htimetot->Write(timeTotName);
1251 hToT->Write(totName);
1252 hdeltaTime->Write(deltaName);
1260 delete hSlewingProf;
1267 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1268 calChannel->SetSlewPar(par);
1269 WriteParOfflineOnCDB("TOF/Calib","valid");
1272 //----------------------------------------------------------------------------
1273 Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
1275 // calibrating an array of channels
1276 // computing calibration parameters
1278 // 0 -> everything was ok
1279 // 1 -> no tree for calibration found
1280 // 2 -> not enough statistics to perform calibration
1281 // 3 -> problems with arrays
1283 TH1::AddDirectory(0);
1285 AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ;
1286 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1287 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1288 for (Int_t ich=0; ich<nch; ich++){
1290 AliInfo(Form("Calibrating channel = %i",i )) ;
1292 Float_t p[MAXCHENTRIESSMALL];
1294 //fTree->SetBranchAddress("nentries",&nentries);
1295 //fTree->SetBranchAddress("TOFentries",p);
1296 fChain->SetBranchAddress("nentries",&nentries);
1297 fChain->SetBranchAddress("TOFentries",p);
1299 Float_t ntracksTotalmean =0;
1300 for (Int_t ich=0; ich<nch; ich++){
1303 for (Int_t irun=0;irun<fNruns;irun++){
1304 ientry = i+irun*fNChannels;
1305 //fTree->GetEntry(ientry);
1306 fChain->GetEntry(ientry);
1307 ntracksTotalmean+=nentries/3;
1311 ntracksTotalmean/=nch;
1312 if (ntracksTotalmean < MEANENTRIES) {
1313 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1317 //filling ToT and Time arrays
1319 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1320 Float_t minToT = 0; // ns
1321 Float_t maxToT = 4.88; // ns
1322 TFile * fileProf=0x0;
1323 if(strstr(optionSave,"save")){
1324 fileProf = new TFile("TOFCalibSave.root","recreate");
1326 for (Int_t ich=0; ich<nch; ich++) {
1327 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1328 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1329 Double_t binsProfile[101]; // sized larger than necessary, the correct
1330 // dim being set in the booking of the profile
1331 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1332 Int_t ntracksTotal = 0;
1333 Int_t ntracksRun = 0;
1334 Int_t nusefulbins=0;
1337 for (Int_t irun=0;irun<fNruns;irun++){
1338 i = ch[ich]+irun*fNChannels;
1339 AliDebug(2,Form("Calibrating channel %i",i));
1340 //fTree->GetEntry(i);
1341 fChain->GetEntry(i);
1342 ntracksTotal+=nentries/3;
1344 if (ntracksTotal < MEANENTRIES) {
1345 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",i,ntracksTotal));
1349 for (Int_t irun=0;irun<fNruns;irun++){
1350 i = ch[ich]+irun*fNChannels;
1351 //fTree->GetEntry(i);
1352 fChain->GetEntry(i);
1353 ntracksRun=nentries/3;
1354 for (Int_t j=0;j<ntracksRun;j++){
1355 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1356 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1357 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1358 Float_t tot = p[idxexToT];
1359 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1360 meantime+=p[idxexTime]-p[idxexExTime];
1365 nusefulbins = FindBins(hToT,&binsProfile[0]);
1366 meantime/=ntracksTotal;
1367 for (Int_t j=1;j<=nusefulbins;j++) {
1368 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1371 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1372 for (Int_t irun=0;irun<fNruns;irun++){
1373 i = ch[ich]+irun*fNChannels;
1374 //fTree->GetEntry(i);
1375 fChain->GetEntry(i);
1376 ntracksRun=nentries/3;
1377 for (Int_t j=0;j<ntracksRun;j++){
1378 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1379 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1380 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1381 Float_t tot = p[idxexToT];
1382 Float_t time = p[idxexTime]-p[idxexExTime];
1383 AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1384 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1385 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1389 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1390 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1392 for(Int_t kk=0;kk<6;kk++){
1393 par[kk]=calibfunc->GetParameter(kk);
1394 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1397 if(strstr(optionSave,"save") && fileProf){
1398 TString profName=Form("Profile%06i",i);
1399 TString timeTotName=Form("TimeTot%06i",i);
1400 TString totName=Form("Tot%06i",i);
1401 TString deltaName=Form("Delta%06i",i);
1403 hSlewingProf->Write(profName);
1404 htimetot->Write(timeTotName);
1405 hToT->Write(totName);
1406 hdeltaTime->Write(deltaName);
1409 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1410 calChannel->SetSlewPar(par);
1413 delete hSlewingProf;
1421 if(strstr(optionSave,"save") && fileProf){
1426 WriteParOfflineOnCDB("TOF/Calib","valid");
1430 //----------------------------------------------------------------------------
1431 Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){
1433 // computing calibration parameters using the old profiling algo
1435 // 0 -> everything was ok
1436 // 1 -> no tree for calibration found
1437 // 2 -> not enough statistics to perform calibration
1438 // 3 -> problems with arrays
1440 TH1::AddDirectory(0);
1442 AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ;
1443 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1444 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1445 Float_t p[MAXCHENTRIESSMALL];
1447 Int_t ntracksTotal=0;
1448 //fTree->SetBranchAddress("nentries",&nentries);
1449 //fTree->SetBranchAddress("TOFentries",p);
1450 fChain->SetBranchAddress("nentries",&nentries);
1451 fChain->SetBranchAddress("TOFentries",p);
1453 for (Int_t irun=0;irun<fNruns;irun++){
1454 Int_t i = ich+irun*fNChannels;
1455 //fTree->GetEntry(i);
1456 fChain->GetEntry(i);
1457 ntracksTotal+=nentries/3;
1460 if (ntracksTotal < MEANENTRIES) {
1461 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1465 TH1F * hProf = new TH1F();
1466 hProf = Profile(ich);
1467 hProf->Fit("pol5",optionFit,"",0,4);
1468 TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
1470 for(Int_t kk=0;kk<6;kk++){
1471 par[kk]=calibfunc->GetParameter(kk);
1472 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1475 if(strstr(optionSave,"save")){
1476 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1478 TString profName=Form("Profile%06i",ich);
1479 hProf->Write(profName);
1487 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich);
1488 calChannel->SetSlewPar(par);
1489 WriteParOfflineOnCDB("TOF/Calib","valid");
1492 //----------------------------------------------------------------------------
1493 Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
1495 // calibrating the whole TOF
1496 // computing calibration parameters
1498 // 0 -> everything was ok
1499 // 1 -> no tree for calibration found
1500 // 2 -> not enough statistics to perform calibration
1501 // 3 -> problems with arrays
1503 TH1::AddDirectory(0);
1505 AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ;
1506 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1507 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1509 TFile * fileProf=0x0;
1510 if(strstr(optionSave,"save")){
1511 fileProf = new TFile("TOFCalibSave.root","recreate");
1514 Float_t p[MAXCHENTRIESSMALL];
1516 //fTree->SetBranchAddress("nentries",&nentries);
1517 //fTree->SetBranchAddress("TOFentries",p);
1518 fChain->SetBranchAddress("nentries",&nentries);
1519 fChain->SetBranchAddress("TOFentries",p);
1521 Float_t ntracksTotalmean =0;
1522 for (Int_t ii=0; ii<fNChannels; ii++){
1523 for (Int_t irun=0;irun<fNruns;irun++){
1524 Int_t i = ii+irun*fNChannels;
1525 //fTree->GetEntry(i);
1526 fChain->GetEntry(i);
1527 ntracksTotalmean+=nentries/3;
1531 ntracksTotalmean/=fNChannels;
1532 if (ntracksTotalmean < MEANENTRIES) {
1533 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1537 //filling ToT and Time arrays
1539 Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps
1540 Float_t minToT = 0; // ns
1541 Float_t maxToT = 4.88;// ns
1542 for (Int_t ii=0; ii<fNChannels; ii++) {
1543 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1544 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1545 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1546 if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
1548 Int_t nusefulbins=0;
1549 Double_t binsProfile[101]; // sized larger than necessary, the correct
1550 // dim being set in the booking of the profile
1551 Int_t ntracksRun = 0;
1552 Int_t ntracksTotal = 0;
1553 for (Int_t irun=0;irun<fNruns;irun++){
1554 Int_t i = ii+irun*fNChannels;
1555 //fTree->GetEntry(i);
1556 fChain->GetEntry(i);
1557 ntracksTotal+=nentries/3;
1559 if (ntracksTotal < MEANENTRIES) {
1560 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",ii,ntracksTotal));
1564 for (Int_t irun=0;irun<fNruns;irun++){
1565 Int_t i = ii+irun*fNChannels;
1566 //fTree->GetEntry(i);
1567 fChain->GetEntry(i);
1568 ntracksRun=nentries/3;
1569 for (Int_t j=0;j<ntracksRun;j++){
1570 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1571 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1572 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1573 Float_t tot = p[idxexToT];
1574 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1575 meantime+=p[idxexTime]-p[idxexExTime];
1579 nusefulbins = FindBins(hToT,&binsProfile[0]);
1580 meantime/=ntracksTotal;
1581 for (Int_t j=0;j<nusefulbins;j++) {
1582 AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j]));
1584 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1585 for (Int_t irun=0;irun<fNruns;irun++){
1586 Int_t i = ii+irun*fNChannels;
1587 //fTree->GetEntry(i);
1588 fChain->GetEntry(i);
1589 ntracksRun=nentries/3;
1590 for (Int_t j=0;j<ntracksRun;j++){
1591 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1592 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1593 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1594 Float_t tot = p[idxexToT];
1595 Float_t time = p[idxexTime]-p[idxexExTime];
1596 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1597 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1598 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1601 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1602 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1604 for(Int_t kk=0;kk<6;kk++){
1605 par[kk]=calibfunc->GetParameter(kk);
1606 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1609 if(strstr(optionSave,"save") && fileProf){
1610 TString profName=Form("Profile%06i",ii);
1611 TString timeTotName=Form("TimeTot%06i",ii);
1612 TString totName=Form("Tot%06i",ii);
1613 TString deltaName=Form("Delta%06i",ii);
1615 hSlewingProf->Write(profName);
1616 htimetot->Write(timeTotName);
1617 hToT->Write(totName);
1618 hdeltaTime->Write(deltaName);
1620 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii);
1621 calChannel->SetSlewPar(par);
1625 delete hSlewingProf;
1633 if(strstr(optionSave,"save")){
1638 WriteParOfflineOnCDB("TOF/Calib","valid");
1642 //-----------------------------------------------------------------------
1643 TH1F* AliTOFcalib::Profile(Int_t ich)
1647 Float_t p[MAXCHENTRIESSMALL];
1649 //fTree->SetBranchAddress("nentries",&nentries);
1650 //fTree->SetBranchAddress("TOFentries",p);
1651 fChain->SetBranchAddress("nentries",&nentries);
1652 fChain->SetBranchAddress("TOFentries",p);
1654 //Prepare histograms for Slewing Correction
1655 const Int_t knbinToT = 100;
1656 Int_t nbinTime = 200;
1657 Float_t minTime = -5.5; //ns
1658 Float_t maxTime = 5.5; //ns
1659 Float_t minToT = 0; //ns
1660 Float_t maxToT = 5.; //ns
1661 Float_t deltaToT = (maxToT-minToT)/knbinToT;
1662 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];
1663 Int_t n[knbinToT+1], nentrx[knbinToT+1];
1664 Double_t sigmaToT[knbinToT+1];
1665 for (Int_t i = 0; i < knbinToT+1 ; i++){
1683 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
1684 Int_t ntracksRun = 0;
1685 TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
1686 for (Int_t irun=0;irun<fNruns;irun++){
1687 Int_t i = ich+irun*fNChannels;
1688 //fTree->GetEntry(i);
1689 fChain->GetEntry(i);
1690 ntracksRun=nentries/3;
1691 for (Int_t j=0;j<ntracksRun;j++){
1692 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1693 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1694 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1695 Float_t tot = p[idxexToT];
1696 Float_t time = p[idxexTime]-p[idxexExTime];
1697 Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
1698 if ((tot != 0) && ( time!= 0)){
1700 vTime2[nx]+=time*time;
1704 hSlewing->Fill(tot,time);
1708 Int_t nbinsToT=hSlewing->GetNbinsX();
1709 if (nbinsToT != knbinToT) {
1710 AliError("Profile :: incompatible numbers of bins");
1715 for (Int_t i=1;i<=nbinsToT;i++){
1717 n[usefulBins]+=nentrx[i];
1718 if (n[usefulBins]==0 && i == nbinsToT) {
1721 meanTime[usefulBins]+=vTime[i];
1722 meanTime2[usefulBins]+=vTime2[i];
1723 meanToT[usefulBins]+=vToT[i];
1724 meanToT2[usefulBins]+=vToT2[i];
1725 if (n[usefulBins]<10 && i!=nbinsToT) continue;
1726 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
1727 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
1728 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1729 *(meanTime2[usefulBins]-meanTime[usefulBins]
1730 *meanTime[usefulBins]/n[usefulBins]));
1731 if ((1./n[usefulBins]/n[usefulBins]
1732 *(meanToT2[usefulBins]-meanToT[usefulBins]
1733 *meanToT[usefulBins]/n[usefulBins]))< 0) {
1734 AliError(" too small radical" );
1735 sigmaToT[usefulBins]=0;
1738 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1739 *(meanToT2[usefulBins]-meanToT[usefulBins]
1740 *meanToT[usefulBins]/n[usefulBins]));
1745 for (Int_t i=0;i<usefulBins;i++){
1746 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
1747 histo->Fill(mToT[i],mTime[i]);
1748 histo->SetBinError(binN,sigmaTime[i]);
1755 //----------------------------------------------------------------------------
1756 Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
1758 // to determine the bins for ToT histo
1762 Int_t nbin = h->GetNbinsX();
1763 Int_t nentries = (Int_t)h->GetEntries();
1764 Float_t max = h->GetBinLowEdge(nbin);
1765 Int_t nusefulbins=0;
1767 // setting maxvalue of entries per bin
1768 if (nentries <= 60) maxcont = 2;
1769 else if (nentries <= 100) maxcont = 5;
1770 else if (nentries <= 500) maxcont = 10;
1772 for (Int_t j=1;j<=nbin;j++) {
1773 cont += (Int_t)h->GetBinContent(j);
1777 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1786 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1787 binsProfile[nusefulbins]=max;
1790 binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);