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"
116 #include "AliTOFDeltaBCOffset.h"
117 #include "AliTOFCTPLatency.h"
118 #include "AliTOFT0Fill.h"
119 #include "AliTOFRunParams.h"
120 #include "AliTOFResponseParams.h"
121 #include "AliESDEvent.h"
122 #include "AliESDtrack.h"
128 extern TStyle *gStyle;
130 ClassImp(AliTOFcalib)
132 //_______________________________________________________________________
133 AliTOFcalib::AliTOFcalib():
134 TTask("AliTOFcalib",""),
137 fTOFCalOnlinePulser(0x0),
138 fTOFCalOnlineNoise(0x0),
139 fTOFCalOnlineHW(0x0),
149 fLastRun(AliCDBRunRange::Infinity()),
150 fConfigMap(new TMap),
151 fDeltaBCOffset(NULL),
155 fResponseParams(NULL),
157 fRemoveMeanT0(kTRUE),
160 //TOF Calibration Class ctor
161 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
163 //____________________________________________________________________________
165 AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib):
167 fNChannels(calib.fNChannels),
169 fTOFCalOnlinePulser(0x0),
170 fTOFCalOnlineNoise(0x0),
171 fTOFCalOnlineHW(0x0),
174 fStatus(calib.fStatus),
175 fTOFSimToT(calib.fTOFSimToT),
176 fkValidity(calib.fkValidity),
178 fChain(calib.fChain),
179 fNruns(calib.fNruns),
180 fFirstRun(calib.fFirstRun),
181 fLastRun(calib.fLastRun),
182 fConfigMap(calib.fConfigMap),
183 fDeltaBCOffset(NULL),
187 fResponseParams(NULL),
188 fInitFlag(calib.fInitFlag),
189 fRemoveMeanT0(calib.fRemoveMeanT0),
190 fCorrectTExp(calib.fCorrectTExp)
192 //TOF Calibration Class copy ctor
193 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
194 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
195 AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
196 AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
197 AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
198 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
199 fTOFCalOnline->AddAt(calChOnline,iarray);
200 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
201 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
202 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
203 fTOFCalOffline->AddAt(calChOffline,iarray);
206 if (calib.fDeltaBCOffset) fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset);
207 if (calib.fCTPLatency) fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency);
208 if (calib.fT0Fill) fT0Fill = new AliTOFT0Fill(*calib.fT0Fill);
209 if (calib.fRunParams) fRunParams = new AliTOFRunParams(*calib.fRunParams);
210 if (calib.fResponseParams) fResponseParams = new AliTOFResponseParams(*calib.fResponseParams);
213 //____________________________________________________________________________
215 AliTOFcalib& AliTOFcalib::operator=(const AliTOFcalib &calib)
217 //TOF Calibration Class assignment operator
222 TTask::operator=(calib);
223 fNChannels = calib.fNChannels;
225 fStatus = calib.fStatus;
226 fTOFSimToT = calib.fTOFSimToT;
227 fkValidity = calib.fkValidity;
229 fChain = calib.fChain;
230 fNruns = calib.fNruns;
231 fFirstRun = calib.fFirstRun;
232 fLastRun = calib.fLastRun;
233 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
234 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
235 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
236 AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
237 AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
238 AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
239 fTOFCalOnline->AddAt(calChOnline,iarray);
240 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
241 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
242 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
243 fTOFCalOffline->AddAt(calChOffline,iarray);
246 if (calib.fDeltaBCOffset) {
247 if (fDeltaBCOffset) *fDeltaBCOffset = *calib.fDeltaBCOffset;
248 else fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset);
251 if (calib.fCTPLatency) {
252 if (fCTPLatency) *fCTPLatency = *calib.fCTPLatency;
253 else fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency);
257 if (fT0Fill) *fT0Fill = *calib.fT0Fill;
258 else fT0Fill = new AliTOFT0Fill(*calib.fT0Fill);
260 if (calib.fRunParams) {
261 if (fRunParams) *fRunParams = *calib.fRunParams;
262 else fRunParams = new AliTOFRunParams(*calib.fRunParams);
264 if (calib.fResponseParams) {
265 if (fResponseParams) *fResponseParams = *calib.fResponseParams;
266 else fResponseParams = new AliTOFResponseParams(*calib.fResponseParams);
268 fInitFlag = calib.fInitFlag;
269 fRemoveMeanT0 = calib.fRemoveMeanT0;
270 fCorrectTExp = calib.fCorrectTExp;
275 //____________________________________________________________________________
277 AliTOFcalib::~AliTOFcalib()
279 //TOF Calibration Class dtor
280 if(!(AliCDBManager::Instance()->GetCacheFlag())){ // CDB objects must NOT be deleted if cache is active!
282 delete fTOFCalOnline;
284 if (fTOFCalOnlinePulser){
285 delete fTOFCalOnlinePulser;
287 if (fTOFCalOnlineNoise){
288 delete fTOFCalOnlineNoise;
290 if (fTOFCalOnlineHW){
291 delete fTOFCalOnlineHW;
294 delete fTOFCalOffline;
305 if (fDeltaBCOffset) delete fDeltaBCOffset;
306 if (fCTPLatency) delete fCTPLatency;
307 if (fT0Fill) delete fT0Fill;
308 if (fRunParams) delete fRunParams;
310 if (fTree!=0x0) delete fTree;
311 if (fChain!=0x0) delete fChain;
314 //_____________________________________________________________________________
315 void AliTOFcalib::CreateCalArrays(){
317 // creating arrays for online/offline calibration objs
319 fTOFCalOnline = new TObjArray(fNChannels);
320 fTOFCalOnlinePulser = new TObjArray(fNChannels);
321 fTOFCalOnlineNoise = new TObjArray(fNChannels);
322 fTOFCalOnlineHW = new TObjArray(fNChannels);
323 fTOFCalOffline = new TObjArray(fNChannels);
324 fTOFCalOnline->SetOwner();
325 fTOFCalOnlinePulser->SetOwner();
326 fTOFCalOnlineNoise->SetOwner();
327 fTOFCalOnlineHW->SetOwner();
328 fTOFCalOffline->SetOwner();
329 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
330 AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline();
331 AliTOFChannelOnlineStatus * calChOnlineStPulser = new AliTOFChannelOnlineStatus();
332 AliTOFChannelOnlineStatus * calChOnlineStNoise = new AliTOFChannelOnlineStatus();
333 AliTOFChannelOnlineStatus * calChOnlineStHW = new AliTOFChannelOnlineStatus();
334 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
335 fTOFCalOnline->AddAt(calChOnline,iarray);
336 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
337 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
338 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
339 fTOFCalOffline->AddAt(calChOffline,iarray);
341 fCal = new AliTOFChannelOnlineArray(fNChannels);
342 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
344 //_____________________________________________________________________________
345 void AliTOFcalib::CreateCalObjects(){
347 // creating arrays for online/offline calibration objs
349 fTOFCalOffline = new TObjArray(fNChannels);
350 fTOFCalOffline->SetOwner();
351 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
352 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
353 fTOFCalOffline->AddAt(calChOffline,iarray);
355 fCal = new AliTOFChannelOnlineArray(fNChannels);
356 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
358 //_____________________________________________________________________________
359 void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
361 //Write calibration parameters to the CDB
364 AliCDBManager *man = AliCDBManager::Instance();
365 const Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
367 sprintf(out,"%s/%s",sel,sel1);
368 AliDebug(2,Form("Writing TOF configuration map for online calib on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
369 AliCDBId id(out,fFirstRun,fLastRun);
370 AliCDBMetaData *md = new AliCDBMetaData();
371 md->SetResponsible("Chiara Zampolli");
375 man->Put(fConfigMap,id,md);
378 //_____________________________________________________________________________
380 void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel)
382 //Write calibration parameters to the CDB with infinite validity
383 AliCDBManager *man = AliCDBManager::Instance();
384 const Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
386 sprintf(out,"%s/%s",sel,sel1);
387 AliCDBRunRange runrange(fFirstRun,fLastRun);
388 AliDebug(2,Form("Writing TOF config map for online calib 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(fConfigMap,id,md);
398 //_____________________________________________________________________________
399 void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
401 //Write calibration parameters to the CDB -------> new calib objs!!!!!
404 AliCDBManager *man = AliCDBManager::Instance();
405 const Char_t *sel1 = "ParOnlineDelay" ; // 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");
415 man->Put(fCal,id,md);
418 //_____________________________________________________________________________
419 void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
421 //Write calibration parameters to the CDB -------> new calib objs!!!!!
424 AliCDBManager *man = AliCDBManager::Instance();
425 const Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
427 sprintf(out,"%s/%s",sel,sel1);
428 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
429 AliCDBId id(out,fFirstRun,fLastRun);
430 AliCDBMetaData *md = new AliCDBMetaData();
431 md->SetResponsible("Chiara Zampolli");
435 man->Put(fStatus,id,md);
438 //_____________________________________________________________________________
440 void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel)
442 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
443 AliCDBManager *man = AliCDBManager::Instance();
444 const Char_t *sel1 = "ParOnlineDelay" ; // to be consistent with TOFPreprocessor
446 sprintf(out,"%s/%s",sel,sel1);
447 AliCDBRunRange runrange(fFirstRun,fLastRun);
448 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
449 AliCDBId id(out,runrange);
450 AliCDBMetaData *md = new AliCDBMetaData();
451 md->SetResponsible("Chiara Zampolli");
455 man->Put(fCal,id,md);
458 //_____________________________________________________________________________
460 void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel)
462 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
463 AliCDBManager *man = AliCDBManager::Instance();
464 const Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
466 sprintf(out,"%s/%s",sel,sel1);
467 AliCDBRunRange runrange(fFirstRun,fLastRun);
468 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
469 AliCDBId id(out,runrange);
470 AliCDBMetaData *md = new AliCDBMetaData();
471 md->SetResponsible("Chiara Zampolli");
475 man->Put(fStatus,id,md);
478 //_____________________________________________________________________________
479 void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
481 //Write calibration parameters to the CDB
484 AliCDBManager *man = AliCDBManager::Instance();
485 const Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
487 sprintf(out,"%s/%s",sel,sel1);
488 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
489 AliCDBId id(out,fFirstRun,fLastRun);
490 AliCDBMetaData *md = new AliCDBMetaData();
491 md->SetResponsible("Chiara Zampolli");
492 if (!fTOFCalOnline) {
495 man->Put(fTOFCalOnline,id,md);
498 //_____________________________________________________________________________
499 void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
501 //Write calibration parameters from pulser to the CDB
504 AliCDBManager *man = AliCDBManager::Instance();
505 const Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
507 sprintf(out,"%s/%s",sel,sel1);
508 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
509 AliCDBId id(out,fFirstRun,fLastRun);
510 AliCDBMetaData *md = new AliCDBMetaData();
511 md->SetResponsible("Chiara Zampolli");
512 if (!fTOFCalOnlinePulser) {
515 man->Put(fTOFCalOnlinePulser,id,md);
518 //_____________________________________________________________________________
519 void AliTOFcalib::WriteParOnlineNoiseOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
521 //Write calibration parameters from noise to the CDB
524 AliCDBManager *man = AliCDBManager::Instance();
525 const Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
527 sprintf(out,"%s/%s",sel,sel1);
528 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
529 AliCDBId id(out,fFirstRun,fLastRun);
530 AliCDBMetaData *md = new AliCDBMetaData();
531 md->SetResponsible("Chiara Zampolli");
532 if (!fTOFCalOnlineNoise) {
535 man->Put(fTOFCalOnlineNoise,id,md);
538 //_____________________________________________________________________________
539 void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
541 //Write calibration parameters from hardware to the CDB
544 AliCDBManager *man = AliCDBManager::Instance();
545 const Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
547 sprintf(out,"%s/%s",sel,sel1);
548 AliDebug(2,Form("Writing TOF online calib obj from hardware on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
549 AliCDBId id(out,fFirstRun,fLastRun);
550 AliCDBMetaData *md = new AliCDBMetaData();
551 md->SetResponsible("Chiara Zampolli");
552 if (!fTOFCalOnlineHW) {
555 man->Put(fTOFCalOnlineHW,id,md);
558 //_____________________________________________________________________________
560 void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel)
562 //Write calibration parameters to the CDB with infinite validity
563 AliCDBManager *man = AliCDBManager::Instance();
564 const Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
566 sprintf(out,"%s/%s",sel,sel1);
567 AliCDBRunRange runrange(fFirstRun,fLastRun);
568 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
569 AliCDBId id(out,runrange);
570 AliCDBMetaData *md = new AliCDBMetaData();
571 md->SetResponsible("Chiara Zampolli");
572 if (!fTOFCalOnline) {
575 man->Put(fTOFCalOnline,id,md);
578 //_____________________________________________________________________________
580 void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel)
582 //Write calibration parameters from pulser to the CDB with infinite validity
583 AliCDBManager *man = AliCDBManager::Instance();
584 const Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
586 sprintf(out,"%s/%s",sel,sel1);
587 AliCDBRunRange runrange(fFirstRun,fLastRun);
588 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
589 AliCDBId id(out,runrange);
590 AliCDBMetaData *md = new AliCDBMetaData();
591 md->SetResponsible("Chiara Zampolli");
592 if (!fTOFCalOnlinePulser) {
595 man->Put(fTOFCalOnlinePulser,id,md);
598 //_____________________________________________________________________________
600 void AliTOFcalib::WriteParOnlineNoiseOnCDB(const Char_t *sel)
602 //Write calibration parameters from noise to the CDB with infinite validity
603 AliCDBManager *man = AliCDBManager::Instance();
604 const Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
606 sprintf(out,"%s/%s",sel,sel1);
607 AliCDBRunRange runrange(fFirstRun,fLastRun);
608 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
609 AliCDBId id(out,runrange);
610 AliCDBMetaData *md = new AliCDBMetaData();
611 md->SetResponsible("Chiara Zampolli");
612 if (!fTOFCalOnlineNoise) {
615 man->Put(fTOFCalOnlineNoise,id,md);
618 //_____________________________________________________________________________
620 void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel)
622 //Write calibration parameters from hardware to the CDB with infinite validity
623 AliCDBManager *man = AliCDBManager::Instance();
624 const Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
626 sprintf(out,"%s/%s",sel,sel1);
627 AliCDBRunRange runrange(fFirstRun,fLastRun);
628 AliDebug(2,Form("Writing TOF online calib obj from harware on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
629 AliCDBId id(out,runrange);
630 AliCDBMetaData *md = new AliCDBMetaData();
631 md->SetResponsible("Chiara Zampolli");
632 if (!fTOFCalOnlineHW) {
635 man->Put(fTOFCalOnlineHW,id,md);
638 //_____________________________________________________________________________
640 void AliTOFcalib::WriteParOfflineOnCDB(const Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun)
642 //Write calibration parameters to the CDB
645 AliCDBManager *man = AliCDBManager::Instance();
646 const Char_t *sel1 = "ParOffline" ;
648 sprintf(out,"%s/%s",sel,sel1);
649 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
650 AliCDBId id(out,fFirstRun,fLastRun);
651 AliCDBMetaData *md = new AliCDBMetaData();
652 md->SetResponsible("Chiara Zampolli");
653 md->SetComment(validity);
654 man->Put(fTOFCalOffline,id,md);
657 //_____________________________________________________________________________
659 void AliTOFcalib::WriteParOfflineOnCDB(const Char_t *sel, const Char_t *validity)
661 //Write calibration parameters to the CDB with infinite validity
662 AliCDBManager *man = AliCDBManager::Instance();
663 const Char_t *sel1 = "ParOffline" ;
665 sprintf(out,"%s/%s",sel,sel1);
666 AliCDBRunRange runrange(fFirstRun,fLastRun);
667 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
668 AliCDBId id(out,runrange);
669 AliCDBMetaData *md = new AliCDBMetaData();
670 md->SetResponsible("Chiara Zampolli");
671 md->SetComment(validity);
672 man->Put(fTOFCalOffline,id,md);
675 //_____________________________________________________________________________
677 Bool_t AliTOFcalib::ReadConfigMapFromCDB(const Char_t *sel, Int_t nrun)
679 //Read calibration parameters from the CDB
680 AliCDBManager *man = AliCDBManager::Instance();
681 const Char_t *sel1 = "Config" ;
683 sprintf(out,"%s/%s",sel,sel1);
684 AliCDBEntry *entry = man->Get(out,nrun);
686 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
689 if(!entry->GetObject()){
690 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
694 fConfigMap =(TMap*)entry->GetObject();
699 //_____________________________________________________________________________
701 Bool_t AliTOFcalib::ReadParOnlineDelayFromCDB(const Char_t *sel, Int_t nrun)
703 //Read calibration parameters from the CDB -------> new calib objs!!!!!
704 AliCDBManager *man = AliCDBManager::Instance();
705 const Char_t *sel1 = "ParOnlineDelay" ;
707 sprintf(out,"%s/%s",sel,sel1);
708 AliCDBEntry *entry = man->Get(out,nrun);
710 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
713 if(!entry->GetObject()){
714 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
718 fCal =(AliTOFChannelOnlineArray*)entry->GetObject();
723 //_____________________________________________________________________________
725 Bool_t AliTOFcalib::ReadParOnlineStatusFromCDB(const Char_t *sel, Int_t nrun)
727 //Read calibration parameters from the CDB -------> new calib objs!!!!!
728 AliCDBManager *man = AliCDBManager::Instance();
729 const Char_t *sel1 = "Status" ;
731 sprintf(out,"%s/%s",sel,sel1);
732 AliCDBEntry *entry = man->Get(out,nrun);
734 AliFatal("Exiting, no CDB object (Status) found!!!");
737 if(!entry->GetObject()){
738 AliFatal("Exiting, no CDB object (Status) found!!!");
742 fStatus =(AliTOFChannelOnlineStatusArray*)entry->GetObject();
747 //_____________________________________________________________________________
749 Bool_t AliTOFcalib::ReadParOnlineFromCDB(const Char_t *sel, Int_t nrun)
751 //Read calibration parameters from the CDB
752 AliCDBManager *man = AliCDBManager::Instance();
753 const Char_t *sel1 = "ParOnline" ;
755 sprintf(out,"%s/%s",sel,sel1);
756 AliCDBEntry *entry = man->Get(out,nrun);
758 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
761 if(!entry->GetObject()){
762 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
766 fTOFCalOnline =(TObjArray*)entry->GetObject();
771 //_____________________________________________________________________________
773 Bool_t AliTOFcalib::ReadParOnlinePulserFromCDB(const Char_t *sel, Int_t nrun)
775 //Read calibration parameters from pulser from the CDB
776 AliCDBManager *man = AliCDBManager::Instance();
777 const Char_t *sel1 = "Pulser" ;
779 sprintf(out,"%s/%s",sel,sel1);
780 AliCDBEntry *entry = man->Get(out,nrun);
782 AliFatal("Exiting, no CDB object (Pulser) found!!!");
785 if(!entry->GetObject()){
786 AliFatal("Exiting, no CDB object (Pulser) found!!!");
790 fTOFCalOnlinePulser =(TObjArray*)entry->GetObject();
795 //_____________________________________________________________________________
797 Bool_t AliTOFcalib::ReadParOnlineNoiseFromCDB(const Char_t *sel, Int_t nrun)
799 //Read calibration parameters from noise from the CDB
800 AliCDBManager *man = AliCDBManager::Instance();
801 const Char_t *sel1 = "Noise" ;
803 sprintf(out,"%s/%s",sel,sel1);
804 AliCDBEntry *entry = man->Get(out,nrun);
806 AliFatal("Exiting, no CDB object (Noise) found!!!");
809 if(!entry->GetObject()){
810 AliFatal("Exiting, no CDB object (Noise) found!!!");
814 fTOFCalOnlineNoise =(TObjArray*)entry->GetObject();
819 //_____________________________________________________________________________
821 Bool_t AliTOFcalib::ReadParOnlineHWFromCDB(const Char_t *sel, Int_t nrun)
823 //Read calibration parameters from hardware from the CDB
824 AliCDBManager *man = AliCDBManager::Instance();
825 const Char_t *sel1 = "HW" ;
827 sprintf(out,"%s/%s",sel,sel1);
828 AliCDBEntry *entry = man->Get(out,nrun);
830 AliFatal("Exiting, no CDB object (HW map) found!!!");
833 if(!entry->GetObject()){
834 AliFatal("Exiting, no CDB object (HW map) found!!!");
838 fTOFCalOnlineHW =(TObjArray*)entry->GetObject();
843 //_____________________________________________________________________________
845 Bool_t AliTOFcalib::ReadParOfflineFromCDB(const Char_t *sel, Int_t nrun)
847 //Read calibration parameters from the CDB
848 AliCDBManager *man = AliCDBManager::Instance();
849 const Char_t *sel1 = "ParOffline" ;
851 sprintf(out,"%s/%s",sel,sel1);
852 AliCDBEntry *entry = man->Get(out,nrun);
854 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
857 if(!entry->GetObject()){
858 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
861 AliCDBMetaData * md = entry->GetMetaData();
862 fkValidity = md->GetComment();
863 fTOFCalOffline =(TObjArray*)entry->GetObject();
868 //_____________________________________________________________________________
869 void AliTOFcalib::WriteSimHistoOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, TH1F *histo){
870 //Write Sim miscalibration parameters to the CDB
873 AliCDBManager *man = AliCDBManager::Instance();
874 const Char_t *sel1 = "SimHisto" ;
876 sprintf(out,"%s/%s",sel,sel1);
877 AliCDBMetaData *mdhisto = new AliCDBMetaData();
878 mdhisto->SetResponsible("Chiara Zampolli");
879 AliCDBId id(out,minrun,maxrun);
880 man->Put(fTOFSimToT,id,mdhisto);
883 //_____________________________________________________________________________
884 Bool_t AliTOFcalib::ReadSimHistoFromCDB(const Char_t *sel, Int_t nrun)
886 //Read miscalibration parameters from the CDB
887 AliCDBManager *man = AliCDBManager::Instance();
891 const Char_t *sel1 = "SimHisto" ;
893 sprintf(out,"%s/%s",sel,sel1);
894 AliCDBEntry *entry = man->Get(out,nrun);
896 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
899 if(!entry->GetObject()){
900 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
903 TH1F *histo =(TH1F*)entry->GetObject();
907 //_____________________________________________________________________________
908 void AliTOFcalib::WriteRecParOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){
909 //Write reconstruction parameters to the CDB
911 AliCDBManager *man = AliCDBManager::Instance();
912 AliCDBMetaData *md = new AliCDBMetaData();
913 md->SetResponsible("Silvia Arcelli");
914 const Char_t *sel1 = "RecoParam" ;
916 sprintf(out,"%s/%s",sel,sel1);
917 AliCDBId id(out,minrun,maxrun);
918 man->Put(param,id,md);
921 //_____________________________________________________________________________
922 AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(const Char_t *sel, Int_t nrun)
924 //Read reconstruction parameters from the CDB
925 AliCDBManager *man = AliCDBManager::Instance();
926 const Char_t *sel1 = "RecoParam" ;
928 sprintf(out,"%s/%s",sel,sel1);
929 AliCDBEntry *entry = man->Get(out,nrun);
931 AliFatal("Exiting, no CDB object (RecoParam) found!!!");
934 if(!entry->GetObject()){
935 AliFatal("Exiting, no CDB object (RecoParam) found!!!");
939 AliTOFRecoParam *param=(AliTOFRecoParam*)entry->GetObject();
942 //-----------------------------------------------------------------------------
943 // Calibration methods
944 //-----------------------------------------------------------------------------
945 void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
947 // creating the chain with the trees for calibration
948 // collecting them from reference data
949 // from minrun to maxrun
951 Float_t p[CHENTRIESSMALL];
953 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
954 fTree->Branch("nentries",&nentries,"nentries/I");
955 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
956 AliCDBManager *man = AliCDBManager::Instance();
957 AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT/OCDB");
958 for (Int_t irun = minrun;irun<=maxrun;irun++){
959 AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
961 AliInfo(Form("No entry found for run %i",irun));
964 TTree *tree = new TTree();
965 tree = (TTree*)entry->GetObject();
966 tree->SetBranchAddress("nentries",&nentries);
967 tree->SetBranchAddress("TOFentries",p);
968 fTree->CopyEntries(tree);
973 AliInfo(Form("Number of runs being analyzed %i",fNruns));
975 //-----------------------------------------------------------------------------
976 void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
978 // creating the chain with the trees for calibration
979 // collecting them from the Grid
980 // from minrun to maxrun
982 Float_t p[CHENTRIESSMALL];
984 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
985 fTree->SetDirectory(0);
986 fTree->Branch("nentries",&nentries,"nentries/I");
987 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
988 AliInfo("connected to alien");
989 TGrid::Connect("alien://");
991 Char_t filename[100];
992 for (Int_t irun = minrun;irun<=maxrun;irun++){
993 sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
994 TFile *filegrid = TFile::Open(filename,"READ");
995 TTree *tree = (TTree*)filegrid->Get("T");
996 tree->SetBranchAddress("nentries",&nentries);
997 tree->SetBranchAddress("TOFentries",p);
998 fTree->CopyEntries(tree);
1003 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1005 //-----------------------------------------------------------------------------
1006 void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
1008 // creating the tree with the trees for calibration
1009 // collecting them from reference data (from file)
1010 // from minrun to maxrun
1012 Float_t p[CHENTRIESSMALL];
1014 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
1015 fTree->SetDirectory(0);
1016 fTree->Branch("nentries",&nentries,"nentries/I");
1017 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
1018 Char_t filename[100];
1019 for (Int_t irun = minrun;irun<=maxrun;irun++){
1020 sprintf(filename,"$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
1021 TFile *file = new TFile(filename,"READ");
1022 TTree *tree = (TTree*)file->Get("T");
1023 tree->SetBranchAddress("nentries",&nentries);
1024 tree->SetBranchAddress("TOFentries",p);
1025 fTree->CopyEntries(tree);
1032 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1034 //-----------------------------------------------------------------------------
1035 void AliTOFcalib::CreateChainFromGrid(Int_t minrun, Int_t maxrun){
1037 // creating the chain with the trees for calibration
1038 // collecting them from the Grid
1039 // from minrun to maxrun
1041 fChain = new TChain("T");
1042 AliInfo("connected to alien");
1043 TGrid::Connect("alien://");
1045 Char_t filename[100];
1046 for (Int_t irun = minrun;irun<=maxrun;irun++){
1047 sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
1048 fChain->Add(filename);
1052 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1054 //-----------------------------------------------------------------------------
1055 Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
1057 // calibrating summing more than one channels
1058 // computing calibration parameters
1060 // 0 -> everything was ok
1061 // 1 -> no tree for calibration found
1062 // 2 -> not enough statistics to perform calibration
1063 // 3 -> problems with arrays
1065 TH1::AddDirectory(0);
1067 AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ;
1068 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1069 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1071 Float_t p[CHENTRIESSMALL];
1073 //fTree->SetBranchAddress("nentries",&nentries);
1074 //fTree->SetBranchAddress("TOFentries",p);
1075 fChain->SetBranchAddress("nentries",&nentries);
1076 fChain->SetBranchAddress("TOFentries",p);
1078 Float_t ntracksTotalmean =0;
1079 for (Int_t i=ichmin; i<ichmax; i++){
1081 for (Int_t irun=0;irun<fNruns;irun++){
1082 ientry = i+irun*fNChannels;
1083 //fTree->GetEntry(ientry);
1084 fChain->GetEntry(ientry);
1085 Int_t ntracksRun=nentries/3;
1086 ntracksTotalmean+=ntracksRun;
1090 if (ntracksTotalmean < MEANENTRIES) {
1091 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1095 //filling ToT and Time arrays
1097 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1098 Float_t minToT = 0; // ns
1099 Float_t maxToT = 4.88; // ns
1101 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1102 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1103 Int_t ntracksTotal = 0;
1104 Int_t ntracksRun = 0;
1105 Double_t binsProfile[101]; // sized larger than necessary, the correct
1106 // dim being set in the booking of the profile
1107 Int_t nusefulbins=0;
1109 for (Int_t i = ichmin;i<ichmax;i++){
1111 for (Int_t irun=0;irun<fNruns;irun++){
1112 ientry = i+irun*fNChannels;
1113 //fTree->GetEntry(ientry);
1114 fChain->GetEntry(ientry);
1115 ntracksTotal+=nentries/3;
1116 ntracksRun=nentries/3;
1117 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun));
1118 for (Int_t j=0;j<ntracksRun;j++){
1119 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1120 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1121 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1122 Float_t tot = p[idxexToT];
1123 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1124 meantime+=p[idxexTime]-p[idxexExTime];
1129 nusefulbins = FindBins(hToT,&binsProfile[0]);
1130 meantime/=ntracksTotal;
1131 AliDebug(2, Form("meantime = %f",meantime));
1133 for (Int_t j=1;j<=nusefulbins;j++) {
1134 AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j]));
1137 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1138 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1140 for (Int_t irun=0;irun<fNruns;irun++){
1142 for (Int_t i=ichmin; i<ichmax; i++){
1143 ientry = i+irun*fNChannels;
1144 //fTree->GetEntry(ientry);
1145 fChain->GetEntry(ientry);
1146 ntracksRun=nentries/3;
1147 for (Int_t j=0;j<ntracksRun;j++){
1148 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1149 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1150 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1151 Float_t tot = p[idxexToT];
1152 Float_t time = p[idxexTime]-p[idxexExTime];
1153 AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1154 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1155 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1160 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1161 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1163 for(Int_t kk=0;kk<6;kk++){
1164 par[kk]=calibfunc->GetParameter(kk);
1165 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1168 if(strstr(optionSave,"save")){
1169 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1171 TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
1172 TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
1173 TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
1174 TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
1175 hSlewingProf->Write(profName);
1176 htimetot->Write(timeTotName);
1177 hToT->Write(totName);
1178 hdeltaTime->Write(deltaName);
1186 delete hSlewingProf;
1193 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin);
1194 calChannel->SetSlewPar(par);
1195 WriteParOfflineOnCDB("TOF/Calib","valid");
1198 //----------------------------------------------------------------------------
1199 Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
1201 // computing calibration parameters for channel i
1203 // 0 -> everything was ok
1204 // 1 -> no tree for calibration found
1205 // 2 -> not enough statistics to perform calibration
1206 // 3 -> problems with arrays
1208 TH1::AddDirectory(0);
1210 AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ;
1211 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1212 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1214 Float_t p[MAXCHENTRIESSMALL];
1216 //fTree->SetBranchAddress("nentries",&nentries);
1217 //fTree->SetBranchAddress("TOFentries",p);
1218 fChain->SetBranchAddress("nentries",&nentries);
1219 fChain->SetBranchAddress("TOFentries",p);
1221 Float_t ntracksTotal =0;
1222 for (Int_t irun=0;irun<fNruns;irun++){
1224 ientry = i+irun*fNChannels;
1225 //fTree->GetEntry(ientry);
1226 fChain->GetEntry(ientry);
1227 ntracksTotal+=nentries/3;
1230 if (ntracksTotal < MEANENTRIES) {
1231 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1235 //filling ToT and Time arrays
1237 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1238 Float_t minToT = 0; // ns
1239 Float_t maxToT = 4.88; // ns
1241 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1242 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1243 Int_t ntracksRun = 0;
1244 Double_t binsProfile[101]; // sized larger than necessary, the correct
1245 // dim being set in the booking of the profile
1246 Int_t nusefulbins=0;
1248 for (Int_t irun=0;irun<fNruns;irun++){
1250 ientry = i+irun*fNChannels;
1251 //fTree->GetEntry(ientry);
1252 fChain->GetEntry(ientry);
1253 ntracksRun=nentries/3;
1254 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun));
1255 for (Int_t j=0;j<ntracksRun;j++){
1256 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1257 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1258 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1259 Float_t tot = p[idxexToT];
1260 meantime+=p[idxexTime]-p[idxexExTime];
1261 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1266 nusefulbins = FindBins(hToT,&binsProfile[0]);
1267 meantime/=ntracksTotal;
1268 AliDebug(2,Form("meantime = %f",meantime));
1270 for (Int_t j=1;j<=nusefulbins;j++) {
1271 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1274 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1275 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1276 for (Int_t irun=0;irun<fNruns;irun++){
1278 ientry = i+irun*fNChannels;
1279 //fTree->GetEntry(ientry);
1280 fChain->GetEntry(ientry);
1281 ntracksRun=nentries/3;
1282 for (Int_t j=0;j<ntracksRun;j++){
1283 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1284 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1285 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1286 Float_t tot = p[idxexToT];
1287 Float_t time = p[idxexTime]-p[idxexExTime];
1288 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1289 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1290 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1294 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1295 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1297 for(Int_t kk=0;kk<6;kk++){
1298 par[kk]=calibfunc->GetParameter(kk);
1299 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1303 if(strstr(optionSave,"save")){
1304 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1306 TString profName=Form("Profile%06i",i);
1307 TString timeTotName=Form("TimeTot%06i",i);
1308 TString totName=Form("Tot%06i",i);
1309 TString deltaName=Form("Delta%06i",i);
1310 hSlewingProf->Write(profName);
1311 htimetot->Write(timeTotName);
1312 hToT->Write(totName);
1313 hdeltaTime->Write(deltaName);
1321 delete hSlewingProf;
1328 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1329 calChannel->SetSlewPar(par);
1330 WriteParOfflineOnCDB("TOF/Calib","valid");
1333 //----------------------------------------------------------------------------
1334 Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
1336 // calibrating an array of channels
1337 // computing calibration parameters
1339 // 0 -> everything was ok
1340 // 1 -> no tree for calibration found
1341 // 2 -> not enough statistics to perform calibration
1342 // 3 -> problems with arrays
1344 TH1::AddDirectory(0);
1346 AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ;
1347 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1348 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1349 for (Int_t ich=0; ich<nch; ich++){
1351 AliInfo(Form("Calibrating channel = %i",i )) ;
1353 Float_t p[MAXCHENTRIESSMALL];
1355 //fTree->SetBranchAddress("nentries",&nentries);
1356 //fTree->SetBranchAddress("TOFentries",p);
1357 fChain->SetBranchAddress("nentries",&nentries);
1358 fChain->SetBranchAddress("TOFentries",p);
1360 Float_t ntracksTotalmean =0;
1361 for (Int_t ich=0; ich<nch; ich++){
1364 for (Int_t irun=0;irun<fNruns;irun++){
1365 ientry = i+irun*fNChannels;
1366 //fTree->GetEntry(ientry);
1367 fChain->GetEntry(ientry);
1368 ntracksTotalmean+=nentries/3;
1372 ntracksTotalmean/=nch;
1373 if (ntracksTotalmean < MEANENTRIES) {
1374 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1378 //filling ToT and Time arrays
1380 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1381 Float_t minToT = 0; // ns
1382 Float_t maxToT = 4.88; // ns
1383 TFile * fileProf=0x0;
1384 if(strstr(optionSave,"save")){
1385 fileProf = new TFile("TOFCalibSave.root","recreate");
1387 for (Int_t ich=0; ich<nch; ich++) {
1388 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1389 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1390 Double_t binsProfile[101]; // sized larger than necessary, the correct
1391 // dim being set in the booking of the profile
1392 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1393 Int_t ntracksTotal = 0;
1394 Int_t ntracksRun = 0;
1395 Int_t nusefulbins=0;
1398 for (Int_t irun=0;irun<fNruns;irun++){
1399 i = ch[ich]+irun*fNChannels;
1400 AliDebug(2,Form("Calibrating channel %i",i));
1401 //fTree->GetEntry(i);
1402 fChain->GetEntry(i);
1403 ntracksTotal+=nentries/3;
1405 if (ntracksTotal < MEANENTRIES) {
1406 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",i,ntracksTotal));
1410 for (Int_t irun=0;irun<fNruns;irun++){
1411 i = ch[ich]+irun*fNChannels;
1412 //fTree->GetEntry(i);
1413 fChain->GetEntry(i);
1414 ntracksRun=nentries/3;
1415 for (Int_t j=0;j<ntracksRun;j++){
1416 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1417 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1418 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1419 Float_t tot = p[idxexToT];
1420 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1421 meantime+=p[idxexTime]-p[idxexExTime];
1426 nusefulbins = FindBins(hToT,&binsProfile[0]);
1427 meantime/=ntracksTotal;
1428 for (Int_t j=1;j<=nusefulbins;j++) {
1429 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1432 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1433 for (Int_t irun=0;irun<fNruns;irun++){
1434 i = ch[ich]+irun*fNChannels;
1435 //fTree->GetEntry(i);
1436 fChain->GetEntry(i);
1437 ntracksRun=nentries/3;
1438 for (Int_t j=0;j<ntracksRun;j++){
1439 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1440 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1441 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1442 Float_t tot = p[idxexToT];
1443 Float_t time = p[idxexTime]-p[idxexExTime];
1444 AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1445 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1446 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1450 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1451 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1453 for(Int_t kk=0;kk<6;kk++){
1454 par[kk]=calibfunc->GetParameter(kk);
1455 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1458 if(strstr(optionSave,"save") && fileProf){
1459 TString profName=Form("Profile%06i",i);
1460 TString timeTotName=Form("TimeTot%06i",i);
1461 TString totName=Form("Tot%06i",i);
1462 TString deltaName=Form("Delta%06i",i);
1464 hSlewingProf->Write(profName);
1465 htimetot->Write(timeTotName);
1466 hToT->Write(totName);
1467 hdeltaTime->Write(deltaName);
1470 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1471 calChannel->SetSlewPar(par);
1474 delete hSlewingProf;
1482 if(strstr(optionSave,"save") && fileProf){
1487 WriteParOfflineOnCDB("TOF/Calib","valid");
1491 //----------------------------------------------------------------------------
1492 Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){
1494 // computing calibration parameters using the old profiling algo
1496 // 0 -> everything was ok
1497 // 1 -> no tree for calibration found
1498 // 2 -> not enough statistics to perform calibration
1499 // 3 -> problems with arrays
1501 TH1::AddDirectory(0);
1503 AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ;
1504 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1505 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1506 Float_t p[MAXCHENTRIESSMALL];
1508 Int_t ntracksTotal=0;
1509 //fTree->SetBranchAddress("nentries",&nentries);
1510 //fTree->SetBranchAddress("TOFentries",p);
1511 fChain->SetBranchAddress("nentries",&nentries);
1512 fChain->SetBranchAddress("TOFentries",p);
1514 for (Int_t irun=0;irun<fNruns;irun++){
1515 Int_t i = ich+irun*fNChannels;
1516 //fTree->GetEntry(i);
1517 fChain->GetEntry(i);
1518 ntracksTotal+=nentries/3;
1521 if (ntracksTotal < MEANENTRIES) {
1522 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1526 TH1F * hProf = new TH1F();
1527 hProf = Profile(ich);
1528 hProf->Fit("pol5",optionFit,"",0,4);
1529 TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
1531 for(Int_t kk=0;kk<6;kk++){
1532 par[kk]=calibfunc->GetParameter(kk);
1533 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1536 if(strstr(optionSave,"save")){
1537 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1539 TString profName=Form("Profile%06i",ich);
1540 hProf->Write(profName);
1548 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich);
1549 calChannel->SetSlewPar(par);
1550 WriteParOfflineOnCDB("TOF/Calib","valid");
1553 //----------------------------------------------------------------------------
1554 Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
1556 // calibrating the whole TOF
1557 // computing calibration parameters
1559 // 0 -> everything was ok
1560 // 1 -> no tree for calibration found
1561 // 2 -> not enough statistics to perform calibration
1562 // 3 -> problems with arrays
1564 TH1::AddDirectory(0);
1566 AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ;
1567 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1568 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1570 TFile * fileProf=0x0;
1571 if(strstr(optionSave,"save")){
1572 fileProf = new TFile("TOFCalibSave.root","recreate");
1575 Float_t p[MAXCHENTRIESSMALL];
1577 //fTree->SetBranchAddress("nentries",&nentries);
1578 //fTree->SetBranchAddress("TOFentries",p);
1579 fChain->SetBranchAddress("nentries",&nentries);
1580 fChain->SetBranchAddress("TOFentries",p);
1582 Float_t ntracksTotalmean =0;
1583 for (Int_t ii=0; ii<fNChannels; ii++){
1584 for (Int_t irun=0;irun<fNruns;irun++){
1585 Int_t i = ii+irun*fNChannels;
1586 //fTree->GetEntry(i);
1587 fChain->GetEntry(i);
1588 ntracksTotalmean+=nentries/3;
1592 ntracksTotalmean/=fNChannels;
1593 if (ntracksTotalmean < MEANENTRIES) {
1594 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1598 //filling ToT and Time arrays
1600 Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps
1601 Float_t minToT = 0; // ns
1602 Float_t maxToT = 4.88;// ns
1603 for (Int_t ii=0; ii<fNChannels; ii++) {
1604 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1605 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1606 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1607 if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
1609 Int_t nusefulbins=0;
1610 Double_t binsProfile[101]; // sized larger than necessary, the correct
1611 // dim being set in the booking of the profile
1612 Int_t ntracksRun = 0;
1613 Int_t ntracksTotal = 0;
1614 for (Int_t irun=0;irun<fNruns;irun++){
1615 Int_t i = ii+irun*fNChannels;
1616 //fTree->GetEntry(i);
1617 fChain->GetEntry(i);
1618 ntracksTotal+=nentries/3;
1620 if (ntracksTotal < MEANENTRIES) {
1621 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",ii,ntracksTotal));
1625 for (Int_t irun=0;irun<fNruns;irun++){
1626 Int_t i = ii+irun*fNChannels;
1627 //fTree->GetEntry(i);
1628 fChain->GetEntry(i);
1629 ntracksRun=nentries/3;
1630 for (Int_t j=0;j<ntracksRun;j++){
1631 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1632 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1633 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1634 Float_t tot = p[idxexToT];
1635 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1636 meantime+=p[idxexTime]-p[idxexExTime];
1640 nusefulbins = FindBins(hToT,&binsProfile[0]);
1641 meantime/=ntracksTotal;
1642 for (Int_t j=0;j<nusefulbins;j++) {
1643 AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j]));
1645 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1646 for (Int_t irun=0;irun<fNruns;irun++){
1647 Int_t i = ii+irun*fNChannels;
1648 //fTree->GetEntry(i);
1649 fChain->GetEntry(i);
1650 ntracksRun=nentries/3;
1651 for (Int_t j=0;j<ntracksRun;j++){
1652 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1653 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1654 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1655 Float_t tot = p[idxexToT];
1656 Float_t time = p[idxexTime]-p[idxexExTime];
1657 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1658 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1659 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1662 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1663 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1665 for(Int_t kk=0;kk<6;kk++){
1666 par[kk]=calibfunc->GetParameter(kk);
1667 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1670 if(strstr(optionSave,"save") && fileProf){
1671 TString profName=Form("Profile%06i",ii);
1672 TString timeTotName=Form("TimeTot%06i",ii);
1673 TString totName=Form("Tot%06i",ii);
1674 TString deltaName=Form("Delta%06i",ii);
1676 hSlewingProf->Write(profName);
1677 htimetot->Write(timeTotName);
1678 hToT->Write(totName);
1679 hdeltaTime->Write(deltaName);
1681 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii);
1682 calChannel->SetSlewPar(par);
1686 delete hSlewingProf;
1694 if(strstr(optionSave,"save")){
1699 WriteParOfflineOnCDB("TOF/Calib","valid");
1703 //-----------------------------------------------------------------------
1704 TH1F* AliTOFcalib::Profile(Int_t ich)
1708 Float_t p[MAXCHENTRIESSMALL];
1710 //fTree->SetBranchAddress("nentries",&nentries);
1711 //fTree->SetBranchAddress("TOFentries",p);
1712 fChain->SetBranchAddress("nentries",&nentries);
1713 fChain->SetBranchAddress("TOFentries",p);
1715 //Prepare histograms for Slewing Correction
1716 const Int_t knbinToT = 100;
1717 Int_t nbinTime = 200;
1718 Float_t minTime = -5.5; //ns
1719 Float_t maxTime = 5.5; //ns
1720 Float_t minToT = 0; //ns
1721 Float_t maxToT = 5.; //ns
1722 Float_t deltaToT = (maxToT-minToT)/knbinToT;
1723 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];
1724 Int_t n[knbinToT+1], nentrx[knbinToT+1];
1725 Double_t sigmaToT[knbinToT+1];
1726 for (Int_t i = 0; i < knbinToT+1 ; i++){
1744 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
1745 Int_t ntracksRun = 0;
1746 TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
1747 for (Int_t irun=0;irun<fNruns;irun++){
1748 Int_t i = ich+irun*fNChannels;
1749 //fTree->GetEntry(i);
1750 fChain->GetEntry(i);
1751 ntracksRun=nentries/3;
1752 for (Int_t j=0;j<ntracksRun;j++){
1753 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1754 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1755 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1756 Float_t tot = p[idxexToT];
1757 Float_t time = p[idxexTime]-p[idxexExTime];
1758 Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
1759 if ((tot != 0) && ( time!= 0)){
1761 vTime2[nx]+=time*time;
1765 hSlewing->Fill(tot,time);
1769 Int_t nbinsToT=hSlewing->GetNbinsX();
1770 if (nbinsToT != knbinToT) {
1771 AliError("Profile :: incompatible numbers of bins");
1776 for (Int_t i=1;i<=nbinsToT;i++){
1778 n[usefulBins]+=nentrx[i];
1779 if (n[usefulBins]==0 && i == nbinsToT) {
1782 meanTime[usefulBins]+=vTime[i];
1783 meanTime2[usefulBins]+=vTime2[i];
1784 meanToT[usefulBins]+=vToT[i];
1785 meanToT2[usefulBins]+=vToT2[i];
1786 if (n[usefulBins]<10 && i!=nbinsToT) continue;
1787 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
1788 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
1789 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1790 *(meanTime2[usefulBins]-meanTime[usefulBins]
1791 *meanTime[usefulBins]/n[usefulBins]));
1792 if ((1./n[usefulBins]/n[usefulBins]
1793 *(meanToT2[usefulBins]-meanToT[usefulBins]
1794 *meanToT[usefulBins]/n[usefulBins]))< 0) {
1795 AliError(" too small radical" );
1796 sigmaToT[usefulBins]=0;
1799 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1800 *(meanToT2[usefulBins]-meanToT[usefulBins]
1801 *meanToT[usefulBins]/n[usefulBins]));
1806 for (Int_t i=0;i<usefulBins;i++){
1807 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
1808 histo->Fill(mToT[i],mTime[i]);
1809 histo->SetBinError(binN,sigmaTime[i]);
1816 //----------------------------------------------------------------------------
1817 Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
1819 // to determine the bins for ToT histo
1823 Int_t nbin = h->GetNbinsX();
1824 Int_t nentries = (Int_t)h->GetEntries();
1825 Float_t max = h->GetBinLowEdge(nbin);
1826 Int_t nusefulbins=0;
1828 // setting maxvalue of entries per bin
1829 if (nentries <= 60) maxcont = 2;
1830 else if (nentries <= 100) maxcont = 5;
1831 else if (nentries <= 500) maxcont = 10;
1833 for (Int_t j=1;j<=nbin;j++) {
1834 cont += (Int_t)h->GetBinContent(j);
1838 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1847 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1848 binsProfile[nusefulbins]=max;
1851 binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);
1859 //----------------------------------------------------------------------------
1862 AliTOFcalib::CreateDeltaBCOffset()
1865 * create deltaBC offset
1868 if (fDeltaBCOffset) {
1869 AliWarning("DeltaBCOffset object already defined, cannot create a new one");
1872 fDeltaBCOffset = new AliTOFDeltaBCOffset();
1875 //----------------------------------------------------------------------------
1878 AliTOFcalib::CreateCTPLatency()
1881 * create CTP latency
1885 AliWarning("CTPLatency object already defined, cannot create a new one");
1888 fCTPLatency = new AliTOFCTPLatency();
1891 //----------------------------------------------------------------------------
1894 AliTOFcalib::CreateT0Fill()
1901 AliWarning("T0Fill object already defined, cannot create a new one");
1904 fT0Fill = new AliTOFT0Fill();
1907 //----------------------------------------------------------------------------
1910 AliTOFcalib::CreateRunParams()
1917 AliWarning("RunParams object already defined, cannot create a new one");
1920 fRunParams = new AliTOFRunParams();
1923 //----------------------------------------------------------------------------
1926 AliTOFcalib::WriteDeltaBCOffsetOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1929 * deltaBC offset on CDB
1932 if (!fDeltaBCOffset) return;
1933 AliCDBId id(Form("%s/DeltaBCOffset", sel), minrun, maxrun);
1934 AliCDBMetaData *md = new AliCDBMetaData();
1935 md->SetResponsible("Roberto Preghenella");
1936 AliCDBManager *man = AliCDBManager::Instance();
1937 man->Put(fDeltaBCOffset, id, md);
1938 AliDebug(2,Form("DeltaBCOffset written on CDB with run range [%i, %i] ",minrun ,maxrun));
1942 //----------------------------------------------------------------------------
1945 AliTOFcalib::WriteCTPLatencyOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1948 * write CTP latency on CDB
1951 if (!fCTPLatency) return;
1952 AliCDBId id(Form("%s/CTPLatency", sel), minrun, maxrun);
1953 AliCDBMetaData *md = new AliCDBMetaData();
1954 md->SetResponsible("Roberto Preghenella");
1955 AliCDBManager *man = AliCDBManager::Instance();
1956 man->Put(fCTPLatency, id, md);
1957 AliDebug(2,Form("CTPLatency written on CDB with run range [%i, %i] ",minrun ,maxrun));
1961 //----------------------------------------------------------------------------
1964 AliTOFcalib::WriteT0FillOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1967 * write event-time on CDB
1970 if (!fT0Fill) return;
1971 AliCDBId id(Form("%s/T0Fill", sel), minrun, maxrun);
1972 AliCDBMetaData *md = new AliCDBMetaData();
1973 md->SetResponsible("Roberto Preghenella");
1974 AliCDBManager *man = AliCDBManager::Instance();
1975 man->Put(fT0Fill, id, md);
1976 AliDebug(2,Form("T0Fill written on CDB with run range [%i, %i] ",minrun ,maxrun));
1980 //----------------------------------------------------------------------------
1983 AliTOFcalib::WriteRunParamsOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1986 * write run params on CDB
1989 if (!fRunParams) return;
1990 AliCDBId id(Form("%s/RunParams", sel), minrun, maxrun);
1991 AliCDBMetaData *md = new AliCDBMetaData();
1992 md->SetResponsible("Roberto Preghenella");
1993 AliCDBManager *man = AliCDBManager::Instance();
1994 man->Put(fRunParams, id, md);
1995 AliDebug(2,Form("RunParams written on CDB with run range [%i, %i] ",minrun ,maxrun));
1999 //----------------------------------------------------------------------------
2002 AliTOFcalib::ReadDeltaBCOffsetFromCDB(const Char_t *sel , Int_t nrun)
2005 * read deltaBC offset from CDB
2008 AliCDBManager *man = AliCDBManager::Instance();
2009 AliCDBEntry *entry = man->Get(Form("%s/DeltaBCOffset", sel),nrun);
2011 AliFatal("No DeltaBCOffset entry found in CDB");
2014 fDeltaBCOffset =(AliTOFDeltaBCOffset *)entry->GetObject();
2015 if(!fDeltaBCOffset){
2016 AliFatal("No DeltaBCOffset object found in CDB entry");
2022 //----------------------------------------------------------------------------
2025 AliTOFcalib::ReadCTPLatencyFromCDB(const Char_t *sel , Int_t nrun)
2028 * read CTP latency from CDB
2031 AliCDBManager *man = AliCDBManager::Instance();
2032 AliCDBEntry *entry = man->Get(Form("%s/CTPLatency", sel),nrun);
2034 AliFatal("No CTPLatency entry found in CDB");
2037 fCTPLatency =(AliTOFCTPLatency *)entry->GetObject();
2039 AliFatal("No CTPLatency object found in CDB entry");
2045 //----------------------------------------------------------------------------
2048 AliTOFcalib::ReadT0FillFromCDB(const Char_t *sel , Int_t nrun)
2051 * read event-time from CDB
2054 AliCDBManager *man = AliCDBManager::Instance();
2055 AliCDBEntry *entry = man->Get(Form("%s/T0Fill", sel),nrun);
2057 AliFatal("No T0Fill entry found in CDB");
2060 fT0Fill =(AliTOFT0Fill *)entry->GetObject();
2062 AliFatal("No T0Fill object found in CDB entry");
2068 //----------------------------------------------------------------------------
2071 AliTOFcalib::ReadRunParamsFromCDB(const Char_t *sel , Int_t nrun)
2074 * read run params from CDB
2077 AliCDBManager *man = AliCDBManager::Instance();
2078 AliCDBEntry *entry = man->Get(Form("%s/RunParams", sel),nrun);
2080 AliFatal("No RunParams entry found in CDB");
2083 fRunParams =(AliTOFRunParams *)entry->GetObject();
2085 AliFatal("No RunParams object found in CDB entry");
2091 //----------------------------------------------------------------------------
2094 AliTOFcalib::Init(Int_t run)
2101 AliWarning("the class was already initialized, re-initialize it");
2105 /* read channel status array */
2106 if (!ReadParOnlineStatusFromCDB("TOF/Calib", run)) {
2107 AliError("cannot get \"Status\" object from OCDB");
2110 /* get par offline array */
2111 if (!ReadParOfflineFromCDB("TOF/Calib", run)) {
2112 AliError("cannot get \"ParOffline\" object from OCDB");
2115 /* get deltaBC offset obj */
2116 if (!ReadDeltaBCOffsetFromCDB("TOF/Calib", run)) {
2117 AliError("cannot get \"DeltaBCOffset\" object from OCDB");
2120 /* get CTP latency obj */
2121 if (!ReadCTPLatencyFromCDB("TOF/Calib", run)) {
2122 AliError("cannot get \"CTPLatency\" object from OCDB");
2125 /* get run params obj */
2126 if (!ReadRunParamsFromCDB("TOF/Calib", run)) {
2127 AliError("cannot get \"RunParams\" object from OCDB");
2130 /* get response params */
2132 TFile *responseFile = TFile::Open("$ALICE_ROOT/TOF/data/AliTOFresponsePar.root");
2133 if (!responseFile || !responseFile->IsOpen()) {
2134 AliError("cannot open \"ResponseParams\" local file");
2137 fResponseParams = (AliTOFResponseParams *)responseFile->Get("ResponseParams");
2138 if (!fResponseParams) {
2139 AliError("cannot get \"ResponseParams\" object from local file");
2142 responseFile->Close();
2151 //----------------------------------------------------------------------------
2154 AliTOFcalib::GetTimeCorrection(Int_t index, Double_t tot, Int_t deltaBC, Int_t l0l1, UInt_t timestamp)
2157 * get time correction
2161 AliError("class not yet initialized. Initialize it before.");
2165 /* get calibration params */
2166 AliTOFChannelOffline *parOffline = (AliTOFChannelOffline *)fTOFCalOffline->At(index);
2167 Int_t deltaBCOffset = fDeltaBCOffset->GetDeltaBCOffset();
2168 Float_t ctpLatency = fCTPLatency->GetCTPLatency();
2169 Float_t tdcLatencyWindow = fStatus->GetLatencyWindow(index) * 1.e3;
2170 Float_t timezero = fRunParams->EvalT0(timestamp);
2171 /* check whether to remove mean T0.
2172 * useful when one wants to compute mean T0 */
2173 if (!fRemoveMeanT0) timezero = 0.;
2175 /* compute correction */
2177 /* deltaBC correction */
2178 deltaBC = deltaBCOffset; /* inhibit deltaBC correction for the time being */
2179 corr += (deltaBC - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth();
2180 /* L0-L1 latency correction */
2181 corr -= l0l1 * AliTOFGeometry::BunchCrossingBinWidth();
2182 /* CTP latency correction */
2184 /* TDC latency window correction */
2185 corr += tdcLatencyWindow;
2186 /* time-zero correction */
2188 /* time calibration correction */
2189 if (tot < AliTOFGeometry::SlewTOTMin())
2190 tot = AliTOFGeometry::SlewTOTMin();
2191 if (tot > AliTOFGeometry::SlewTOTMax())
2192 tot = AliTOFGeometry::SlewTOTMax();
2193 for (Int_t islew = 0; islew < 6; islew++)
2194 corr += parOffline->GetSlewPar(islew) * TMath::Power(tot, islew) * 1.e3;
2196 /* return correction */
2200 //----------------------------------------------------------------------------
2203 AliTOFcalib::CalibrateESD(AliESDEvent *event)
2210 AliError("class not yet initialized. Initialize it before.");
2214 /* loop over tracks */
2215 AliESDtrack *track = NULL;
2216 Int_t index, l0l1, deltaBC;
2217 Double_t time, tot, corr, texp[AliPID::kSPECIES];
2218 UInt_t timestamp = event->GetTimeStamp();
2219 for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
2222 track = event->GetTrack(itrk);
2223 if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) continue;
2226 index = track->GetTOFCalChannel();
2227 time = track->GetTOFsignalRaw();
2228 tot = track->GetTOFsignalToT();
2229 l0l1 = track->GetTOFL0L1();
2230 deltaBC = track->GetTOFDeltaBC();
2232 /* get correction */
2233 corr = GetTimeCorrection(index, tot, deltaBC, l0l1, timestamp);
2235 /* apply correction */
2238 /* set new TOF signal */
2239 track->SetTOFsignal(time);
2241 /* correct expected time */
2243 /* get integrated times */
2244 track->GetIntegratedTimes(texp);
2245 /* loop over particle types and correct expected time */
2246 for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++)
2247 texp[ipart] += fResponseParams->EvalTExpCorr(ipart, track->P());
2248 /* set integrated times */
2249 track->SetIntegratedTimes(texp);
2256 //----------------------------------------------------------------------------
2259 AliTOFcalib::IsChannelEnabled(Int_t index)
2262 * is channel enabled
2266 AliError("class not yet initialized. Initialize it before.");
2270 /* check bad status */
2271 if (fStatus->GetPulserStatus(index) == AliTOFChannelOnlineStatusArray::kTOFPulserBad) return kFALSE;
2272 if (fStatus->GetNoiseStatus(index) == AliTOFChannelOnlineStatusArray::kTOFNoiseBad) return kFALSE;
2273 if (fStatus->GetHWStatus(index) == AliTOFChannelOnlineStatusArray::kTOFHWBad) return kFALSE;