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),
158 fCalibrateTOFsignal(kTRUE),
161 //TOF Calibration Class ctor
162 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
164 //____________________________________________________________________________
166 AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib):
168 fNChannels(calib.fNChannels),
170 fTOFCalOnlinePulser(0x0),
171 fTOFCalOnlineNoise(0x0),
172 fTOFCalOnlineHW(0x0),
175 fStatus(calib.fStatus),
176 fTOFSimToT(calib.fTOFSimToT),
177 fkValidity(calib.fkValidity),
179 fChain(calib.fChain),
180 fNruns(calib.fNruns),
181 fFirstRun(calib.fFirstRun),
182 fLastRun(calib.fLastRun),
183 fConfigMap(calib.fConfigMap),
184 fDeltaBCOffset(NULL),
188 fResponseParams(NULL),
189 fInitFlag(calib.fInitFlag),
190 fRemoveMeanT0(calib.fRemoveMeanT0),
191 fCalibrateTOFsignal(calib.fCalibrateTOFsignal),
192 fCorrectTExp(calib.fCorrectTExp)
195 fTOFCalOnline = new TObjArray(fNChannels);
196 fTOFCalOnlinePulser = new TObjArray(fNChannels);
197 fTOFCalOnlineNoise = new TObjArray(fNChannels);
198 fTOFCalOnlineHW = new TObjArray(fNChannels);
199 fTOFCalOffline = new TObjArray(fNChannels);
200 fTOFCalOnline->SetOwner();
201 fTOFCalOnlinePulser->SetOwner();
202 fTOFCalOnlineNoise->SetOwner();
203 fTOFCalOnlineHW->SetOwner();
204 fTOFCalOffline->SetOwner();
206 //TOF Calibration Class copy ctor
207 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
208 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
209 AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
210 AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
211 AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
212 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
213 fTOFCalOnline->AddAt(calChOnline,iarray);
214 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
215 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
216 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
217 fTOFCalOffline->AddAt(calChOffline,iarray);
220 if (calib.fDeltaBCOffset) fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset);
221 if (calib.fCTPLatency) fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency);
222 if (calib.fT0Fill) fT0Fill = new AliTOFT0Fill(*calib.fT0Fill);
223 if (calib.fRunParams) fRunParams = new AliTOFRunParams(*calib.fRunParams);
224 if (calib.fResponseParams) fResponseParams = new AliTOFResponseParams(*calib.fResponseParams);
227 //____________________________________________________________________________
229 AliTOFcalib& AliTOFcalib::operator=(const AliTOFcalib &calib)
231 //TOF Calibration Class assignment operator
236 TTask::operator=(calib);
237 fNChannels = calib.fNChannels;
239 fStatus = calib.fStatus;
240 fTOFSimToT = calib.fTOFSimToT;
241 fkValidity = calib.fkValidity;
243 fChain = calib.fChain;
244 fNruns = calib.fNruns;
245 fFirstRun = calib.fFirstRun;
246 fLastRun = calib.fLastRun;
247 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
248 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
249 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
250 AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
251 AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
252 AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
253 fTOFCalOnline->AddAt(calChOnline,iarray);
254 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
255 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
256 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
257 fTOFCalOffline->AddAt(calChOffline,iarray);
260 if (calib.fDeltaBCOffset) {
261 if (fDeltaBCOffset) *fDeltaBCOffset = *calib.fDeltaBCOffset;
262 else fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset);
265 if (calib.fCTPLatency) {
266 if (fCTPLatency) *fCTPLatency = *calib.fCTPLatency;
267 else fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency);
271 if (fT0Fill) *fT0Fill = *calib.fT0Fill;
272 else fT0Fill = new AliTOFT0Fill(*calib.fT0Fill);
274 if (calib.fRunParams) {
275 if (fRunParams) *fRunParams = *calib.fRunParams;
276 else fRunParams = new AliTOFRunParams(*calib.fRunParams);
278 if (calib.fResponseParams) {
279 if (fResponseParams) *fResponseParams = *calib.fResponseParams;
280 else fResponseParams = new AliTOFResponseParams(*calib.fResponseParams);
282 fInitFlag = calib.fInitFlag;
283 fRemoveMeanT0 = calib.fRemoveMeanT0;
284 fCalibrateTOFsignal = calib.fCalibrateTOFsignal;
285 fCorrectTExp = calib.fCorrectTExp;
290 //____________________________________________________________________________
292 AliTOFcalib::~AliTOFcalib()
294 //TOF Calibration Class dtor
295 if(!(AliCDBManager::Instance()->GetCacheFlag())){ // CDB objects must NOT be deleted if cache is active!
297 delete fTOFCalOnline;
299 if (fTOFCalOnlinePulser){
300 delete fTOFCalOnlinePulser;
302 if (fTOFCalOnlineNoise){
303 delete fTOFCalOnlineNoise;
305 if (fTOFCalOnlineHW){
306 delete fTOFCalOnlineHW;
309 delete fTOFCalOffline;
320 if (fDeltaBCOffset) delete fDeltaBCOffset;
321 if (fCTPLatency) delete fCTPLatency;
322 if (fT0Fill) delete fT0Fill;
323 if (fRunParams) delete fRunParams;
325 if (fTree!=0x0) delete fTree;
326 if (fChain!=0x0) delete fChain;
329 //_____________________________________________________________________________
330 void AliTOFcalib::CreateCalArrays(){
332 // creating arrays for online/offline calibration objs
334 fTOFCalOnline = new TObjArray(fNChannels);
335 fTOFCalOnlinePulser = new TObjArray(fNChannels);
336 fTOFCalOnlineNoise = new TObjArray(fNChannels);
337 fTOFCalOnlineHW = new TObjArray(fNChannels);
338 fTOFCalOffline = new TObjArray(fNChannels);
339 fTOFCalOnline->SetOwner();
340 fTOFCalOnlinePulser->SetOwner();
341 fTOFCalOnlineNoise->SetOwner();
342 fTOFCalOnlineHW->SetOwner();
343 fTOFCalOffline->SetOwner();
344 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
345 AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline();
346 AliTOFChannelOnlineStatus * calChOnlineStPulser = new AliTOFChannelOnlineStatus();
347 AliTOFChannelOnlineStatus * calChOnlineStNoise = new AliTOFChannelOnlineStatus();
348 AliTOFChannelOnlineStatus * calChOnlineStHW = new AliTOFChannelOnlineStatus();
349 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
350 fTOFCalOnline->AddAt(calChOnline,iarray);
351 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
352 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
353 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
354 fTOFCalOffline->AddAt(calChOffline,iarray);
356 fCal = new AliTOFChannelOnlineArray(fNChannels);
357 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
359 //_____________________________________________________________________________
360 void AliTOFcalib::CreateCalObjects(){
362 // creating arrays for online/offline calibration objs
364 fTOFCalOffline = new TObjArray(fNChannels);
365 fTOFCalOffline->SetOwner();
366 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
367 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
368 fTOFCalOffline->AddAt(calChOffline,iarray);
370 fCal = new AliTOFChannelOnlineArray(fNChannels);
371 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
373 //_____________________________________________________________________________
374 void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
376 //Write calibration parameters to the CDB
379 AliCDBManager *man = AliCDBManager::Instance();
380 const Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
381 TString out(Form("%s/%s",sel,sel1));
382 AliDebug(2,Form("Writing TOF configuration map for online calib on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
383 AliCDBId id(out,fFirstRun,fLastRun);
384 AliCDBMetaData *md = new AliCDBMetaData();
385 md->SetResponsible("Chiara Zampolli");
389 man->Put(fConfigMap,id,md);
392 //_____________________________________________________________________________
394 void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel)
396 //Write calibration parameters to the CDB with infinite validity
397 AliCDBManager *man = AliCDBManager::Instance();
398 const Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
399 TString out(Form("%s/%s",sel,sel1));
400 AliCDBRunRange runrange(fFirstRun,fLastRun);
401 AliDebug(2,Form("Writing TOF config map for online calib on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
402 AliCDBId id(out,runrange);
403 AliCDBMetaData *md = new AliCDBMetaData();
404 md->SetResponsible("Chiara Zampolli");
408 man->Put(fConfigMap,id,md);
411 //_____________________________________________________________________________
412 void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
414 //Write calibration parameters to the CDB -------> new calib objs!!!!!
417 AliCDBManager *man = AliCDBManager::Instance();
418 const Char_t *sel1 = "ParOnlineDelay" ; // to be consistent with TOFPreprocessor
419 TString out(Form("%s/%s",sel,sel1));
420 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
421 AliCDBId id(out,fFirstRun,fLastRun);
422 AliCDBMetaData *md = new AliCDBMetaData();
423 md->SetResponsible("Chiara Zampolli");
427 man->Put(fCal,id,md);
430 //_____________________________________________________________________________
431 void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
433 //Write calibration parameters to the CDB -------> new calib objs!!!!!
436 AliCDBManager *man = AliCDBManager::Instance();
437 const Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
438 TString out(Form("%s/%s",sel,sel1));
439 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
440 AliCDBId id(out,fFirstRun,fLastRun);
441 AliCDBMetaData *md = new AliCDBMetaData();
442 md->SetResponsible("Chiara Zampolli");
446 man->Put(fStatus,id,md);
449 //_____________________________________________________________________________
451 void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel)
453 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
454 AliCDBManager *man = AliCDBManager::Instance();
455 const Char_t *sel1 = "ParOnlineDelay" ; // to be consistent with TOFPreprocessor
456 TString out(Form("%s/%s",sel,sel1));
457 AliCDBRunRange runrange(fFirstRun,fLastRun);
458 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
459 AliCDBId id(out,runrange);
460 AliCDBMetaData *md = new AliCDBMetaData();
461 md->SetResponsible("Chiara Zampolli");
465 man->Put(fCal,id,md);
468 //_____________________________________________________________________________
470 void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel)
472 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
473 AliCDBManager *man = AliCDBManager::Instance();
474 const Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
475 TString out(Form("%s/%s",sel,sel1));
476 AliCDBRunRange runrange(fFirstRun,fLastRun);
477 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
478 AliCDBId id(out,runrange);
479 AliCDBMetaData *md = new AliCDBMetaData();
480 md->SetResponsible("Chiara Zampolli");
484 man->Put(fStatus,id,md);
487 //_____________________________________________________________________________
488 void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
490 //Write calibration parameters to the CDB
493 AliCDBManager *man = AliCDBManager::Instance();
494 const Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
495 TString out(Form("%s/%s",sel,sel1));
496 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
497 AliCDBId id(out,fFirstRun,fLastRun);
498 AliCDBMetaData *md = new AliCDBMetaData();
499 md->SetResponsible("Chiara Zampolli");
500 if (!fTOFCalOnline) {
503 man->Put(fTOFCalOnline,id,md);
506 //_____________________________________________________________________________
507 void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
509 //Write calibration parameters from pulser to the CDB
512 AliCDBManager *man = AliCDBManager::Instance();
513 const Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
514 TString out(Form("%s/%s",sel,sel1));
515 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
516 AliCDBId id(out,fFirstRun,fLastRun);
517 AliCDBMetaData *md = new AliCDBMetaData();
518 md->SetResponsible("Chiara Zampolli");
519 if (!fTOFCalOnlinePulser) {
522 man->Put(fTOFCalOnlinePulser,id,md);
525 //_____________________________________________________________________________
526 void AliTOFcalib::WriteParOnlineNoiseOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
528 //Write calibration parameters from noise to the CDB
531 AliCDBManager *man = AliCDBManager::Instance();
532 const Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
533 TString out(Form("%s/%s",sel,sel1));
534 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
535 AliCDBId id(out,fFirstRun,fLastRun);
536 AliCDBMetaData *md = new AliCDBMetaData();
537 md->SetResponsible("Chiara Zampolli");
538 if (!fTOFCalOnlineNoise) {
541 man->Put(fTOFCalOnlineNoise,id,md);
544 //_____________________________________________________________________________
545 void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
547 //Write calibration parameters from hardware to the CDB
550 AliCDBManager *man = AliCDBManager::Instance();
551 const Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
552 TString out(Form("%s/%s",sel,sel1));
553 AliDebug(2,Form("Writing TOF online calib obj from hardware on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
554 AliCDBId id(out,fFirstRun,fLastRun);
555 AliCDBMetaData *md = new AliCDBMetaData();
556 md->SetResponsible("Chiara Zampolli");
557 if (!fTOFCalOnlineHW) {
560 man->Put(fTOFCalOnlineHW,id,md);
563 //_____________________________________________________________________________
565 void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel)
567 //Write calibration parameters to the CDB with infinite validity
568 AliCDBManager *man = AliCDBManager::Instance();
569 const Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
570 TString out(Form("%s/%s",sel,sel1));
571 AliCDBRunRange runrange(fFirstRun,fLastRun);
572 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
573 AliCDBId id(out,runrange);
574 AliCDBMetaData *md = new AliCDBMetaData();
575 md->SetResponsible("Chiara Zampolli");
576 if (!fTOFCalOnline) {
579 man->Put(fTOFCalOnline,id,md);
582 //_____________________________________________________________________________
584 void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel)
586 //Write calibration parameters from pulser to the CDB with infinite validity
587 AliCDBManager *man = AliCDBManager::Instance();
588 const Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
589 TString out(Form("%s/%s",sel,sel1));
590 AliCDBRunRange runrange(fFirstRun,fLastRun);
591 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
592 AliCDBId id(out,runrange);
593 AliCDBMetaData *md = new AliCDBMetaData();
594 md->SetResponsible("Chiara Zampolli");
595 if (!fTOFCalOnlinePulser) {
598 man->Put(fTOFCalOnlinePulser,id,md);
601 //_____________________________________________________________________________
603 void AliTOFcalib::WriteParOnlineNoiseOnCDB(const Char_t *sel)
605 //Write calibration parameters from noise to the CDB with infinite validity
606 AliCDBManager *man = AliCDBManager::Instance();
607 const Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
608 TString out(Form("%s/%s",sel,sel1));
609 AliCDBRunRange runrange(fFirstRun,fLastRun);
610 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
611 AliCDBId id(out,runrange);
612 AliCDBMetaData *md = new AliCDBMetaData();
613 md->SetResponsible("Chiara Zampolli");
614 if (!fTOFCalOnlineNoise) {
617 man->Put(fTOFCalOnlineNoise,id,md);
620 //_____________________________________________________________________________
622 void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel)
624 //Write calibration parameters from hardware to the CDB with infinite validity
625 AliCDBManager *man = AliCDBManager::Instance();
626 const Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
627 TString out(Form("%s/%s",sel,sel1));
628 AliCDBRunRange runrange(fFirstRun,fLastRun);
629 AliDebug(2,Form("Writing TOF online calib obj from harware on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
630 AliCDBId id(out,runrange);
631 AliCDBMetaData *md = new AliCDBMetaData();
632 md->SetResponsible("Chiara Zampolli");
633 if (!fTOFCalOnlineHW) {
636 man->Put(fTOFCalOnlineHW,id,md);
639 //_____________________________________________________________________________
641 void AliTOFcalib::WriteParOfflineOnCDB(const Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun)
643 //Write calibration parameters to the CDB
646 AliCDBManager *man = AliCDBManager::Instance();
647 const Char_t *sel1 = "ParOffline" ;
648 TString out(Form("%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" ;
664 TString out(Form("%s/%s",sel,sel1));
665 AliCDBRunRange runrange(fFirstRun,fLastRun);
666 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
667 AliCDBId id(out,runrange);
668 AliCDBMetaData *md = new AliCDBMetaData();
669 md->SetResponsible("Chiara Zampolli");
670 md->SetComment(validity);
671 man->Put(fTOFCalOffline,id,md);
674 //_____________________________________________________________________________
676 Bool_t AliTOFcalib::ReadConfigMapFromCDB(const Char_t *sel, Int_t nrun)
678 //Read calibration parameters from the CDB
679 AliCDBManager *man = AliCDBManager::Instance();
680 const Char_t *sel1 = "Config" ;
681 TString out(Form("%s/%s",sel,sel1));
682 AliCDBEntry *entry = man->Get(out,nrun);
684 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
687 if(!entry->GetObject()){
688 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
692 fConfigMap =(TMap*)entry->GetObject();
697 //_____________________________________________________________________________
699 Bool_t AliTOFcalib::ReadParOnlineDelayFromCDB(const Char_t *sel, Int_t nrun)
701 //Read calibration parameters from the CDB -------> new calib objs!!!!!
702 AliCDBManager *man = AliCDBManager::Instance();
703 const Char_t *sel1 = "ParOnlineDelay" ;
704 TString out(Form("%s/%s",sel,sel1));
705 AliCDBEntry *entry = man->Get(out,nrun);
707 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
710 if(!entry->GetObject()){
711 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
715 fCal =(AliTOFChannelOnlineArray*)entry->GetObject();
720 //_____________________________________________________________________________
722 Bool_t AliTOFcalib::ReadParOnlineStatusFromCDB(const Char_t *sel, Int_t nrun)
724 //Read calibration parameters from the CDB -------> new calib objs!!!!!
725 AliCDBManager *man = AliCDBManager::Instance();
726 const Char_t *sel1 = "Status" ;
727 TString out(Form("%s/%s",sel,sel1));
728 AliCDBEntry *entry = man->Get(out,nrun);
730 AliFatal("Exiting, no CDB object (Status) found!!!");
733 if(!entry->GetObject()){
734 AliFatal("Exiting, no CDB object (Status) found!!!");
738 fStatus =(AliTOFChannelOnlineStatusArray*)entry->GetObject();
743 //_____________________________________________________________________________
745 Bool_t AliTOFcalib::ReadParOnlineFromCDB(const Char_t *sel, Int_t nrun)
747 //Read calibration parameters from the CDB
748 AliCDBManager *man = AliCDBManager::Instance();
749 const Char_t *sel1 = "ParOnline" ;
750 TString out(Form("%s/%s",sel,sel1));
751 AliCDBEntry *entry = man->Get(out,nrun);
753 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
756 if(!entry->GetObject()){
757 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
761 fTOFCalOnline =(TObjArray*)entry->GetObject();
766 //_____________________________________________________________________________
768 Bool_t AliTOFcalib::ReadParOnlinePulserFromCDB(const Char_t *sel, Int_t nrun)
770 //Read calibration parameters from pulser from the CDB
771 AliCDBManager *man = AliCDBManager::Instance();
772 const Char_t *sel1 = "Pulser" ;
773 TString out(Form("%s/%s",sel,sel1));
774 AliCDBEntry *entry = man->Get(out,nrun);
776 AliFatal("Exiting, no CDB object (Pulser) found!!!");
779 if(!entry->GetObject()){
780 AliFatal("Exiting, no CDB object (Pulser) found!!!");
784 fTOFCalOnlinePulser =(TObjArray*)entry->GetObject();
789 //_____________________________________________________________________________
791 Bool_t AliTOFcalib::ReadParOnlineNoiseFromCDB(const Char_t *sel, Int_t nrun)
793 //Read calibration parameters from noise from the CDB
794 AliCDBManager *man = AliCDBManager::Instance();
795 const Char_t *sel1 = "Noise" ;
796 TString out(Form("%s/%s",sel,sel1));
797 AliCDBEntry *entry = man->Get(out,nrun);
799 AliFatal("Exiting, no CDB object (Noise) found!!!");
802 if(!entry->GetObject()){
803 AliFatal("Exiting, no CDB object (Noise) found!!!");
807 fTOFCalOnlineNoise =(TObjArray*)entry->GetObject();
812 //_____________________________________________________________________________
814 Bool_t AliTOFcalib::ReadParOnlineHWFromCDB(const Char_t *sel, Int_t nrun)
816 //Read calibration parameters from hardware from the CDB
817 AliCDBManager *man = AliCDBManager::Instance();
818 const Char_t *sel1 = "HW" ;
819 TString out(Form("%s/%s",sel,sel1));
820 AliCDBEntry *entry = man->Get(out,nrun);
822 AliFatal("Exiting, no CDB object (HW map) found!!!");
825 if(!entry->GetObject()){
826 AliFatal("Exiting, no CDB object (HW map) found!!!");
830 fTOFCalOnlineHW =(TObjArray*)entry->GetObject();
835 //_____________________________________________________________________________
837 Bool_t AliTOFcalib::ReadParOfflineFromCDB(const Char_t *sel, Int_t nrun)
839 //Read calibration parameters from the CDB
840 AliCDBManager *man = AliCDBManager::Instance();
841 const Char_t *sel1 = "ParOffline" ;
842 TString out(Form("%s/%s",sel,sel1));
843 AliCDBEntry *entry = man->Get(out,nrun);
845 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
848 if(!entry->GetObject()){
849 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
852 AliCDBMetaData * md = entry->GetMetaData();
853 fkValidity = md->GetComment();
854 fTOFCalOffline =(TObjArray*)entry->GetObject();
859 //_____________________________________________________________________________
860 void AliTOFcalib::WriteSimHistoOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, TH1F *histo){
861 //Write Sim miscalibration parameters to the CDB
864 AliCDBManager *man = AliCDBManager::Instance();
865 const Char_t *sel1 = "SimHisto" ;
866 TString out(Form("%s/%s",sel,sel1));
867 AliCDBMetaData *mdhisto = new AliCDBMetaData();
868 mdhisto->SetResponsible("Chiara Zampolli");
869 AliCDBId id(out,minrun,maxrun);
870 man->Put(fTOFSimToT,id,mdhisto);
873 //_____________________________________________________________________________
874 Bool_t AliTOFcalib::ReadSimHistoFromCDB(const Char_t *sel, Int_t nrun)
876 //Read miscalibration parameters from the CDB
877 AliCDBManager *man = AliCDBManager::Instance();
881 const Char_t *sel1 = "SimHisto" ;
882 TString out(Form("%s/%s",sel,sel1));
883 AliCDBEntry *entry = man->Get(out,nrun);
885 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
888 if(!entry->GetObject()){
889 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
892 TH1F *histo =(TH1F*)entry->GetObject();
896 //_____________________________________________________________________________
897 void AliTOFcalib::WriteRecParOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){
898 //Write reconstruction parameters to the CDB
900 AliCDBManager *man = AliCDBManager::Instance();
901 AliCDBMetaData *md = new AliCDBMetaData();
902 md->SetResponsible("Silvia Arcelli");
903 const Char_t *sel1 = "RecoParam" ;
904 TString out(Form("%s/%s",sel,sel1));
905 AliCDBId id(out,minrun,maxrun);
906 man->Put(param,id,md);
909 //_____________________________________________________________________________
910 AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(const Char_t *sel, Int_t nrun)
912 //Read reconstruction parameters from the CDB
913 AliCDBManager *man = AliCDBManager::Instance();
914 const Char_t *sel1 = "RecoParam" ;
915 TString out(Form("%s/%s",sel,sel1));
916 AliCDBEntry *entry = man->Get(out,nrun);
918 AliFatal("Exiting, no CDB object (RecoParam) found!!!");
921 if(!entry->GetObject()){
922 AliFatal("Exiting, no CDB object (RecoParam) found!!!");
926 AliTOFRecoParam *param=(AliTOFRecoParam*)entry->GetObject();
929 //-----------------------------------------------------------------------------
930 // Calibration methods
931 //-----------------------------------------------------------------------------
932 void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
934 // creating the chain with the trees for calibration
935 // collecting them from reference data
936 // from minrun to maxrun
938 Float_t p[CHENTRIESSMALL];
940 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
941 fTree->Branch("nentries",&nentries,"nentries/I");
942 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
943 AliCDBManager *man = AliCDBManager::Instance();
944 AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT/OCDB");
945 for (Int_t irun = minrun;irun<=maxrun;irun++){
946 AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
948 AliInfo(Form("No entry found for run %i",irun));
951 TTree *tree = new TTree();
952 tree = (TTree*)entry->GetObject();
953 tree->SetBranchAddress("nentries",&nentries);
954 tree->SetBranchAddress("TOFentries",p);
955 fTree->CopyEntries(tree);
960 AliInfo(Form("Number of runs being analyzed %i",fNruns));
962 //-----------------------------------------------------------------------------
963 void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
965 // creating the chain with the trees for calibration
966 // collecting them from the Grid
967 // from minrun to maxrun
969 Float_t p[CHENTRIESSMALL];
971 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
972 fTree->SetDirectory(0);
973 fTree->Branch("nentries",&nentries,"nentries/I");
974 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
975 AliInfo("connected to alien");
976 TGrid::Connect("alien://");
979 for (Int_t irun = minrun;irun<=maxrun;irun++){
980 filename = Form("alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
981 TFile *filegrid = TFile::Open(filename.Data(),"READ");
982 TTree *tree = (TTree*)filegrid->Get("T");
983 tree->SetBranchAddress("nentries",&nentries);
984 tree->SetBranchAddress("TOFentries",p);
985 fTree->CopyEntries(tree);
990 AliInfo(Form("Number of runs being analyzed %i",fNruns));
992 //-----------------------------------------------------------------------------
993 void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
995 // creating the tree with the trees for calibration
996 // collecting them from reference data (from file)
997 // from minrun to maxrun
999 Float_t p[CHENTRIESSMALL];
1001 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
1002 fTree->SetDirectory(0);
1003 fTree->Branch("nentries",&nentries,"nentries/I");
1004 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
1006 for (Int_t irun = minrun;irun<=maxrun;irun++){
1007 filename = Form("$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
1008 TFile *file = new TFile(filename.Data(),"READ");
1009 TTree *tree = (TTree*)file->Get("T");
1010 tree->SetBranchAddress("nentries",&nentries);
1011 tree->SetBranchAddress("TOFentries",p);
1012 fTree->CopyEntries(tree);
1019 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1021 //-----------------------------------------------------------------------------
1022 void AliTOFcalib::CreateChainFromGrid(Int_t minrun, Int_t maxrun){
1024 // creating the chain with the trees for calibration
1025 // collecting them from the Grid
1026 // from minrun to maxrun
1028 fChain = new TChain("T");
1029 AliInfo("connected to alien");
1030 TGrid::Connect("alien://");
1033 for (Int_t irun = minrun;irun<=maxrun;irun++){
1034 filename = Form("alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
1035 fChain->Add(filename.Data());
1039 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1041 //-----------------------------------------------------------------------------
1042 Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
1044 // calibrating summing more than one channels
1045 // computing calibration parameters
1047 // 0 -> everything was ok
1048 // 1 -> no tree for calibration found
1049 // 2 -> not enough statistics to perform calibration
1050 // 3 -> problems with arrays
1052 TH1::AddDirectory(0);
1054 AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ;
1055 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1056 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1058 Float_t p[CHENTRIESSMALL];
1060 //fTree->SetBranchAddress("nentries",&nentries);
1061 //fTree->SetBranchAddress("TOFentries",p);
1062 fChain->SetBranchAddress("nentries",&nentries);
1063 fChain->SetBranchAddress("TOFentries",p);
1065 Float_t ntracksTotalmean =0;
1066 for (Int_t i=ichmin; i<ichmax; i++){
1068 for (Int_t irun=0;irun<fNruns;irun++){
1069 ientry = i+irun*fNChannels;
1070 //fTree->GetEntry(ientry);
1071 fChain->GetEntry(ientry);
1072 Int_t ntracksRun=nentries/3;
1073 ntracksTotalmean+=ntracksRun;
1077 if (ntracksTotalmean < MEANENTRIES) {
1078 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1082 //filling ToT and Time arrays
1084 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1085 Float_t minToT = 0; // ns
1086 Float_t maxToT = 4.88; // ns
1088 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1089 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1090 Int_t ntracksTotal = 0;
1091 Int_t ntracksRun = 0;
1092 Double_t binsProfile[101]; // sized larger than necessary, the correct
1093 // dim being set in the booking of the profile
1094 Int_t nusefulbins=0;
1096 for (Int_t i = ichmin;i<ichmax;i++){
1098 for (Int_t irun=0;irun<fNruns;irun++){
1099 ientry = i+irun*fNChannels;
1100 //fTree->GetEntry(ientry);
1101 fChain->GetEntry(ientry);
1102 ntracksTotal+=nentries/3;
1103 ntracksRun=nentries/3;
1104 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun));
1105 for (Int_t j=0;j<ntracksRun;j++){
1106 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1107 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1108 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1109 Float_t tot = p[idxexToT];
1110 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1111 meantime+=p[idxexTime]-p[idxexExTime];
1116 nusefulbins = FindBins(hToT,&binsProfile[0]);
1117 meantime/=ntracksTotal;
1118 AliDebug(2, Form("meantime = %f",meantime));
1120 for (Int_t j=1;j<=nusefulbins;j++) {
1121 AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j]));
1124 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1125 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1127 for (Int_t irun=0;irun<fNruns;irun++){
1129 for (Int_t i=ichmin; i<ichmax; i++){
1130 ientry = i+irun*fNChannels;
1131 //fTree->GetEntry(ientry);
1132 fChain->GetEntry(ientry);
1133 ntracksRun=nentries/3;
1134 for (Int_t j=0;j<ntracksRun;j++){
1135 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1136 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1137 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1138 Float_t tot = p[idxexToT];
1139 Float_t time = p[idxexTime]-p[idxexExTime];
1140 AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1141 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1142 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1147 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1148 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1150 for(Int_t kk=0;kk<6;kk++){
1151 par[kk]=calibfunc->GetParameter(kk);
1152 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1155 if(strstr(optionSave,"save")){
1156 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1158 TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
1159 TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
1160 TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
1161 TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
1162 hSlewingProf->Write(profName);
1163 htimetot->Write(timeTotName);
1164 hToT->Write(totName);
1165 hdeltaTime->Write(deltaName);
1173 delete hSlewingProf;
1180 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin);
1181 calChannel->SetSlewPar(par);
1182 WriteParOfflineOnCDB("TOF/Calib","valid");
1185 //----------------------------------------------------------------------------
1186 Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
1188 // computing calibration parameters for channel i
1190 // 0 -> everything was ok
1191 // 1 -> no tree for calibration found
1192 // 2 -> not enough statistics to perform calibration
1193 // 3 -> problems with arrays
1195 TH1::AddDirectory(0);
1197 AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ;
1198 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1199 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1201 Float_t p[MAXCHENTRIESSMALL];
1203 //fTree->SetBranchAddress("nentries",&nentries);
1204 //fTree->SetBranchAddress("TOFentries",p);
1205 fChain->SetBranchAddress("nentries",&nentries);
1206 fChain->SetBranchAddress("TOFentries",p);
1208 Float_t ntracksTotal =0;
1209 for (Int_t irun=0;irun<fNruns;irun++){
1211 ientry = i+irun*fNChannels;
1212 //fTree->GetEntry(ientry);
1213 fChain->GetEntry(ientry);
1214 ntracksTotal+=nentries/3;
1217 if (ntracksTotal < MEANENTRIES) {
1218 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1222 //filling ToT and Time arrays
1224 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1225 Float_t minToT = 0; // ns
1226 Float_t maxToT = 4.88; // ns
1228 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1229 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1230 Int_t ntracksRun = 0;
1231 Double_t binsProfile[101]; // sized larger than necessary, the correct
1232 // dim being set in the booking of the profile
1233 Int_t nusefulbins=0;
1235 for (Int_t irun=0;irun<fNruns;irun++){
1237 ientry = i+irun*fNChannels;
1238 //fTree->GetEntry(ientry);
1239 fChain->GetEntry(ientry);
1240 ntracksRun=nentries/3;
1241 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun));
1242 for (Int_t j=0;j<ntracksRun;j++){
1243 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1244 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1245 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1246 Float_t tot = p[idxexToT];
1247 meantime+=p[idxexTime]-p[idxexExTime];
1248 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1253 nusefulbins = FindBins(hToT,&binsProfile[0]);
1254 meantime/=ntracksTotal;
1255 AliDebug(2,Form("meantime = %f",meantime));
1257 for (Int_t j=1;j<=nusefulbins;j++) {
1258 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1261 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1262 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1263 for (Int_t irun=0;irun<fNruns;irun++){
1265 ientry = i+irun*fNChannels;
1266 //fTree->GetEntry(ientry);
1267 fChain->GetEntry(ientry);
1268 ntracksRun=nentries/3;
1269 for (Int_t j=0;j<ntracksRun;j++){
1270 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1271 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1272 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1273 Float_t tot = p[idxexToT];
1274 Float_t time = p[idxexTime]-p[idxexExTime];
1275 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1276 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1277 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1281 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1282 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1284 for(Int_t kk=0;kk<6;kk++){
1285 par[kk]=calibfunc->GetParameter(kk);
1286 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1290 if(strstr(optionSave,"save")){
1291 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1293 TString profName=Form("Profile%06i",i);
1294 TString timeTotName=Form("TimeTot%06i",i);
1295 TString totName=Form("Tot%06i",i);
1296 TString deltaName=Form("Delta%06i",i);
1297 hSlewingProf->Write(profName);
1298 htimetot->Write(timeTotName);
1299 hToT->Write(totName);
1300 hdeltaTime->Write(deltaName);
1308 delete hSlewingProf;
1315 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1316 calChannel->SetSlewPar(par);
1317 WriteParOfflineOnCDB("TOF/Calib","valid");
1320 //----------------------------------------------------------------------------
1321 Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
1323 // calibrating an array of channels
1324 // computing calibration parameters
1326 // 0 -> everything was ok
1327 // 1 -> no tree for calibration found
1328 // 2 -> not enough statistics to perform calibration
1329 // 3 -> problems with arrays
1331 TH1::AddDirectory(0);
1333 AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ;
1334 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1335 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1336 for (Int_t ich=0; ich<nch; ich++){
1338 AliInfo(Form("Calibrating channel = %i",i )) ;
1340 Float_t p[MAXCHENTRIESSMALL];
1342 //fTree->SetBranchAddress("nentries",&nentries);
1343 //fTree->SetBranchAddress("TOFentries",p);
1344 fChain->SetBranchAddress("nentries",&nentries);
1345 fChain->SetBranchAddress("TOFentries",p);
1347 Float_t ntracksTotalmean =0;
1348 for (Int_t ich=0; ich<nch; ich++){
1351 for (Int_t irun=0;irun<fNruns;irun++){
1352 ientry = i+irun*fNChannels;
1353 //fTree->GetEntry(ientry);
1354 fChain->GetEntry(ientry);
1355 ntracksTotalmean+=nentries/3;
1359 ntracksTotalmean/=nch;
1360 if (ntracksTotalmean < MEANENTRIES) {
1361 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1365 //filling ToT and Time arrays
1367 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1368 Float_t minToT = 0; // ns
1369 Float_t maxToT = 4.88; // ns
1370 TFile * fileProf=0x0;
1371 if(strstr(optionSave,"save")){
1372 fileProf = new TFile("TOFCalibSave.root","recreate");
1374 for (Int_t ich=0; ich<nch; ich++) {
1375 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1376 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1377 Double_t binsProfile[101]; // sized larger than necessary, the correct
1378 // dim being set in the booking of the profile
1379 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1380 Int_t ntracksTotal = 0;
1381 Int_t ntracksRun = 0;
1382 Int_t nusefulbins=0;
1385 for (Int_t irun=0;irun<fNruns;irun++){
1386 i = ch[ich]+irun*fNChannels;
1387 AliDebug(2,Form("Calibrating channel %i",i));
1388 //fTree->GetEntry(i);
1389 fChain->GetEntry(i);
1390 ntracksTotal+=nentries/3;
1392 if (ntracksTotal < MEANENTRIES) {
1393 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",i,ntracksTotal));
1397 for (Int_t irun=0;irun<fNruns;irun++){
1398 i = ch[ich]+irun*fNChannels;
1399 //fTree->GetEntry(i);
1400 fChain->GetEntry(i);
1401 ntracksRun=nentries/3;
1402 for (Int_t j=0;j<ntracksRun;j++){
1403 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1404 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1405 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1406 Float_t tot = p[idxexToT];
1407 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1408 meantime+=p[idxexTime]-p[idxexExTime];
1413 nusefulbins = FindBins(hToT,&binsProfile[0]);
1414 meantime/=ntracksTotal;
1415 for (Int_t j=1;j<=nusefulbins;j++) {
1416 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1419 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1420 for (Int_t irun=0;irun<fNruns;irun++){
1421 i = ch[ich]+irun*fNChannels;
1422 //fTree->GetEntry(i);
1423 fChain->GetEntry(i);
1424 ntracksRun=nentries/3;
1425 for (Int_t j=0;j<ntracksRun;j++){
1426 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1427 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1428 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1429 Float_t tot = p[idxexToT];
1430 Float_t time = p[idxexTime]-p[idxexExTime];
1431 AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1432 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1433 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1437 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1438 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1440 for(Int_t kk=0;kk<6;kk++){
1441 par[kk]=calibfunc->GetParameter(kk);
1442 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1445 if(strstr(optionSave,"save") && fileProf){
1446 TString profName=Form("Profile%06i",i);
1447 TString timeTotName=Form("TimeTot%06i",i);
1448 TString totName=Form("Tot%06i",i);
1449 TString deltaName=Form("Delta%06i",i);
1451 hSlewingProf->Write(profName);
1452 htimetot->Write(timeTotName);
1453 hToT->Write(totName);
1454 hdeltaTime->Write(deltaName);
1457 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1458 calChannel->SetSlewPar(par);
1461 delete hSlewingProf;
1469 if(strstr(optionSave,"save") && fileProf){
1474 WriteParOfflineOnCDB("TOF/Calib","valid");
1478 //----------------------------------------------------------------------------
1479 Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){
1481 // computing calibration parameters using the old profiling algo
1483 // 0 -> everything was ok
1484 // 1 -> no tree for calibration found
1485 // 2 -> not enough statistics to perform calibration
1486 // 3 -> problems with arrays
1488 TH1::AddDirectory(0);
1490 AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ;
1491 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1492 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1493 Float_t p[MAXCHENTRIESSMALL];
1495 Int_t ntracksTotal=0;
1496 //fTree->SetBranchAddress("nentries",&nentries);
1497 //fTree->SetBranchAddress("TOFentries",p);
1498 fChain->SetBranchAddress("nentries",&nentries);
1499 fChain->SetBranchAddress("TOFentries",p);
1501 for (Int_t irun=0;irun<fNruns;irun++){
1502 Int_t i = ich+irun*fNChannels;
1503 //fTree->GetEntry(i);
1504 fChain->GetEntry(i);
1505 ntracksTotal+=nentries/3;
1508 if (ntracksTotal < MEANENTRIES) {
1509 AliInfo(Form(" Too small mean number of entires per channel (mean number = %d) not calibrating and exiting.....",ntracksTotal));
1513 TH1F * hProf = new TH1F();
1514 hProf = Profile(ich);
1515 hProf->Fit("pol5",optionFit,"",0,4);
1516 TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
1518 for(Int_t kk=0;kk<6;kk++){
1519 par[kk]=calibfunc->GetParameter(kk);
1520 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1523 if(strstr(optionSave,"save")){
1524 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1526 TString profName=Form("Profile%06i",ich);
1527 hProf->Write(profName);
1535 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich);
1536 calChannel->SetSlewPar(par);
1537 WriteParOfflineOnCDB("TOF/Calib","valid");
1540 //----------------------------------------------------------------------------
1541 Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
1543 // calibrating the whole TOF
1544 // computing calibration parameters
1546 // 0 -> everything was ok
1547 // 1 -> no tree for calibration found
1548 // 2 -> not enough statistics to perform calibration
1549 // 3 -> problems with arrays
1551 TH1::AddDirectory(0);
1553 AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ;
1554 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1555 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1557 TFile * fileProf=0x0;
1558 if(strstr(optionSave,"save")){
1559 fileProf = new TFile("TOFCalibSave.root","recreate");
1562 Float_t p[MAXCHENTRIESSMALL];
1564 //fTree->SetBranchAddress("nentries",&nentries);
1565 //fTree->SetBranchAddress("TOFentries",p);
1566 fChain->SetBranchAddress("nentries",&nentries);
1567 fChain->SetBranchAddress("TOFentries",p);
1569 Float_t ntracksTotalmean =0;
1570 for (Int_t ii=0; ii<fNChannels; ii++){
1571 for (Int_t irun=0;irun<fNruns;irun++){
1572 Int_t i = ii+irun*fNChannels;
1573 //fTree->GetEntry(i);
1574 fChain->GetEntry(i);
1575 ntracksTotalmean+=nentries/3;
1579 ntracksTotalmean/=fNChannels;
1580 if (ntracksTotalmean < MEANENTRIES) {
1581 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1585 //filling ToT and Time arrays
1587 Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps
1588 Float_t minToT = 0; // ns
1589 Float_t maxToT = 4.88;// ns
1590 for (Int_t ii=0; ii<fNChannels; ii++) {
1591 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1592 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1593 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1594 if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
1596 Int_t nusefulbins=0;
1597 Double_t binsProfile[101]; // sized larger than necessary, the correct
1598 // dim being set in the booking of the profile
1599 Int_t ntracksRun = 0;
1600 Int_t ntracksTotal = 0;
1601 for (Int_t irun=0;irun<fNruns;irun++){
1602 Int_t i = ii+irun*fNChannels;
1603 //fTree->GetEntry(i);
1604 fChain->GetEntry(i);
1605 ntracksTotal+=nentries/3;
1607 if (ntracksTotal < MEANENTRIES) {
1608 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",ii,ntracksTotal));
1612 for (Int_t irun=0;irun<fNruns;irun++){
1613 Int_t i = ii+irun*fNChannels;
1614 //fTree->GetEntry(i);
1615 fChain->GetEntry(i);
1616 ntracksRun=nentries/3;
1617 for (Int_t j=0;j<ntracksRun;j++){
1618 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1619 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1620 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1621 Float_t tot = p[idxexToT];
1622 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1623 meantime+=p[idxexTime]-p[idxexExTime];
1627 nusefulbins = FindBins(hToT,&binsProfile[0]);
1628 meantime/=ntracksTotal;
1629 for (Int_t j=0;j<nusefulbins;j++) {
1630 AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j]));
1632 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1633 for (Int_t irun=0;irun<fNruns;irun++){
1634 Int_t i = ii+irun*fNChannels;
1635 //fTree->GetEntry(i);
1636 fChain->GetEntry(i);
1637 ntracksRun=nentries/3;
1638 for (Int_t j=0;j<ntracksRun;j++){
1639 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1640 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1641 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1642 Float_t tot = p[idxexToT];
1643 Float_t time = p[idxexTime]-p[idxexExTime];
1644 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1645 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1646 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1649 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1650 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1652 for(Int_t kk=0;kk<6;kk++){
1653 par[kk]=calibfunc->GetParameter(kk);
1654 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1657 if(strstr(optionSave,"save") && fileProf){
1658 TString profName=Form("Profile%06i",ii);
1659 TString timeTotName=Form("TimeTot%06i",ii);
1660 TString totName=Form("Tot%06i",ii);
1661 TString deltaName=Form("Delta%06i",ii);
1663 hSlewingProf->Write(profName);
1664 htimetot->Write(timeTotName);
1665 hToT->Write(totName);
1666 hdeltaTime->Write(deltaName);
1668 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii);
1669 calChannel->SetSlewPar(par);
1673 delete hSlewingProf;
1681 if(strstr(optionSave,"save")){
1686 WriteParOfflineOnCDB("TOF/Calib","valid");
1690 //-----------------------------------------------------------------------
1691 TH1F* AliTOFcalib::Profile(Int_t ich)
1695 Float_t p[MAXCHENTRIESSMALL];
1697 //fTree->SetBranchAddress("nentries",&nentries);
1698 //fTree->SetBranchAddress("TOFentries",p);
1699 fChain->SetBranchAddress("nentries",&nentries);
1700 fChain->SetBranchAddress("TOFentries",p);
1702 //Prepare histograms for Slewing Correction
1703 const Int_t knbinToT = 100;
1704 Int_t nbinTime = 200;
1705 Float_t minTime = -5.5; //ns
1706 Float_t maxTime = 5.5; //ns
1707 Float_t minToT = 0; //ns
1708 Float_t maxToT = 5.; //ns
1709 Float_t deltaToT = (maxToT-minToT)/knbinToT;
1710 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];
1711 Int_t n[knbinToT+1], nentrx[knbinToT+1];
1712 Double_t sigmaToT[knbinToT+1];
1713 for (Int_t i = 0; i < knbinToT+1 ; i++){
1731 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
1732 Int_t ntracksRun = 0;
1733 TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
1734 for (Int_t irun=0;irun<fNruns;irun++){
1735 Int_t i = ich+irun*fNChannels;
1736 //fTree->GetEntry(i);
1737 fChain->GetEntry(i);
1738 ntracksRun=nentries/3;
1739 for (Int_t j=0;j<ntracksRun;j++){
1740 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1741 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1742 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1743 Float_t tot = p[idxexToT];
1744 Float_t time = p[idxexTime]-p[idxexExTime];
1745 Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
1746 if ((tot != 0) && ( time!= 0)){
1748 vTime2[nx]+=time*time;
1752 hSlewing->Fill(tot,time);
1756 Int_t nbinsToT=hSlewing->GetNbinsX();
1757 if (nbinsToT != knbinToT) {
1758 AliError("Profile :: incompatible numbers of bins");
1763 for (Int_t i=1;i<=nbinsToT;i++){
1765 n[usefulBins]+=nentrx[i];
1766 if (n[usefulBins]==0 && i == nbinsToT) {
1769 meanTime[usefulBins]+=vTime[i];
1770 meanTime2[usefulBins]+=vTime2[i];
1771 meanToT[usefulBins]+=vToT[i];
1772 meanToT2[usefulBins]+=vToT2[i];
1773 if (n[usefulBins]<10 && i!=nbinsToT) continue;
1774 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
1775 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
1776 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1777 *(meanTime2[usefulBins]-meanTime[usefulBins]
1778 *meanTime[usefulBins]/n[usefulBins]));
1779 if ((1./n[usefulBins]/n[usefulBins]
1780 *(meanToT2[usefulBins]-meanToT[usefulBins]
1781 *meanToT[usefulBins]/n[usefulBins]))< 0) {
1782 AliError(" too small radical" );
1783 sigmaToT[usefulBins]=0;
1786 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1787 *(meanToT2[usefulBins]-meanToT[usefulBins]
1788 *meanToT[usefulBins]/n[usefulBins]));
1793 for (Int_t i=0;i<usefulBins;i++){
1794 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
1795 histo->Fill(mToT[i],mTime[i]);
1796 histo->SetBinError(binN,sigmaTime[i]);
1803 //----------------------------------------------------------------------------
1804 Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
1806 // to determine the bins for ToT histo
1810 Int_t nbin = h->GetNbinsX();
1811 Int_t nentries = (Int_t)h->GetEntries();
1812 Float_t max = h->GetBinLowEdge(nbin);
1813 Int_t nusefulbins=0;
1815 // setting maxvalue of entries per bin
1816 if (nentries <= 60) maxcont = 2;
1817 else if (nentries <= 100) maxcont = 5;
1818 else if (nentries <= 500) maxcont = 10;
1820 for (Int_t j=1;j<=nbin;j++) {
1821 cont += (Int_t)h->GetBinContent(j);
1825 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1834 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1835 binsProfile[nusefulbins]=max;
1838 binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);
1846 //----------------------------------------------------------------------------
1849 AliTOFcalib::CreateDeltaBCOffset()
1852 * create deltaBC offset
1855 if (fDeltaBCOffset) {
1856 AliWarning("DeltaBCOffset object already defined, cannot create a new one");
1859 fDeltaBCOffset = new AliTOFDeltaBCOffset();
1862 //----------------------------------------------------------------------------
1865 AliTOFcalib::CreateCTPLatency()
1868 * create CTP latency
1872 AliWarning("CTPLatency object already defined, cannot create a new one");
1875 fCTPLatency = new AliTOFCTPLatency();
1878 //----------------------------------------------------------------------------
1881 AliTOFcalib::CreateT0Fill()
1888 AliWarning("T0Fill object already defined, cannot create a new one");
1891 fT0Fill = new AliTOFT0Fill();
1894 //----------------------------------------------------------------------------
1897 AliTOFcalib::CreateRunParams()
1904 AliWarning("RunParams object already defined, cannot create a new one");
1907 fRunParams = new AliTOFRunParams();
1910 //----------------------------------------------------------------------------
1913 AliTOFcalib::WriteDeltaBCOffsetOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1916 * deltaBC offset on CDB
1919 if (!fDeltaBCOffset) return;
1920 AliCDBId id(Form("%s/DeltaBCOffset", sel), minrun, maxrun);
1921 AliCDBMetaData *md = new AliCDBMetaData();
1922 md->SetResponsible("Roberto Preghenella");
1923 AliCDBManager *man = AliCDBManager::Instance();
1924 man->Put(fDeltaBCOffset, id, md);
1925 AliDebug(2,Form("DeltaBCOffset written on CDB with run range [%i, %i] ",minrun ,maxrun));
1929 //----------------------------------------------------------------------------
1932 AliTOFcalib::WriteCTPLatencyOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1935 * write CTP latency on CDB
1938 if (!fCTPLatency) return;
1939 AliCDBId id(Form("%s/CTPLatency", sel), minrun, maxrun);
1940 AliCDBMetaData *md = new AliCDBMetaData();
1941 md->SetResponsible("Roberto Preghenella");
1942 AliCDBManager *man = AliCDBManager::Instance();
1943 man->Put(fCTPLatency, id, md);
1944 AliDebug(2,Form("CTPLatency written on CDB with run range [%i, %i] ",minrun ,maxrun));
1948 //----------------------------------------------------------------------------
1951 AliTOFcalib::WriteT0FillOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1954 * write event-time on CDB
1957 if (!fT0Fill) return;
1958 AliCDBId id(Form("%s/T0Fill", sel), minrun, maxrun);
1959 AliCDBMetaData *md = new AliCDBMetaData();
1960 md->SetResponsible("Roberto Preghenella");
1961 AliCDBManager *man = AliCDBManager::Instance();
1962 man->Put(fT0Fill, id, md);
1963 AliDebug(2,Form("T0Fill written on CDB with run range [%i, %i] ",minrun ,maxrun));
1967 //----------------------------------------------------------------------------
1970 AliTOFcalib::WriteRunParamsOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1973 * write run params on CDB
1976 if (!fRunParams) return;
1977 AliCDBId id(Form("%s/RunParams", sel), minrun, maxrun);
1978 AliCDBMetaData *md = new AliCDBMetaData();
1979 md->SetResponsible("Roberto Preghenella");
1980 AliCDBManager *man = AliCDBManager::Instance();
1981 man->Put(fRunParams, id, md);
1982 AliDebug(2,Form("RunParams written on CDB with run range [%i, %i] ",minrun ,maxrun));
1986 //----------------------------------------------------------------------------
1989 AliTOFcalib::ReadDeltaBCOffsetFromCDB(const Char_t *sel , Int_t nrun)
1992 * read deltaBC offset from CDB
1995 AliCDBManager *man = AliCDBManager::Instance();
1996 AliCDBEntry *entry = man->Get(Form("%s/DeltaBCOffset", sel),nrun);
1998 AliFatal("No DeltaBCOffset entry found in CDB");
2001 fDeltaBCOffset =(AliTOFDeltaBCOffset *)entry->GetObject();
2002 if(!fDeltaBCOffset){
2003 AliFatal("No DeltaBCOffset object found in CDB entry");
2009 //----------------------------------------------------------------------------
2012 AliTOFcalib::ReadCTPLatencyFromCDB(const Char_t *sel , Int_t nrun)
2015 * read CTP latency from CDB
2018 AliCDBManager *man = AliCDBManager::Instance();
2019 AliCDBEntry *entry = man->Get(Form("%s/CTPLatency", sel),nrun);
2021 AliFatal("No CTPLatency entry found in CDB");
2024 fCTPLatency =(AliTOFCTPLatency *)entry->GetObject();
2026 AliFatal("No CTPLatency object found in CDB entry");
2032 //----------------------------------------------------------------------------
2035 AliTOFcalib::ReadT0FillFromCDB(const Char_t *sel , Int_t nrun)
2038 * read event-time from CDB
2041 AliCDBManager *man = AliCDBManager::Instance();
2042 AliCDBEntry *entry = man->Get(Form("%s/T0Fill", sel),nrun);
2044 AliFatal("No T0Fill entry found in CDB");
2047 fT0Fill =(AliTOFT0Fill *)entry->GetObject();
2049 AliFatal("No T0Fill object found in CDB entry");
2055 //----------------------------------------------------------------------------
2058 AliTOFcalib::ReadRunParamsFromCDB(const Char_t *sel , Int_t nrun)
2061 * read run params from CDB
2064 AliCDBManager *man = AliCDBManager::Instance();
2065 AliCDBEntry *entry = man->Get(Form("%s/RunParams", sel),nrun);
2067 AliFatal("No RunParams entry found in CDB");
2070 fRunParams =(AliTOFRunParams *)entry->GetObject();
2072 AliFatal("No RunParams object found in CDB entry");
2078 //----------------------------------------------------------------------------
2081 AliTOFcalib::Init(Int_t run)
2088 AliWarning("the class was already initialized, re-initialize it");
2092 /* read channel status array */
2093 if (!ReadParOnlineStatusFromCDB("TOF/Calib", run)) {
2094 AliError("cannot get \"Status\" object from OCDB");
2097 /* get par offline array */
2098 if (!ReadParOfflineFromCDB("TOF/Calib", run)) {
2099 AliError("cannot get \"ParOffline\" object from OCDB");
2102 /* get deltaBC offset obj */
2103 if (!ReadDeltaBCOffsetFromCDB("TOF/Calib", run)) {
2104 AliError("cannot get \"DeltaBCOffset\" object from OCDB");
2107 /* get CTP latency obj */
2108 if (!ReadCTPLatencyFromCDB("TOF/Calib", run)) {
2109 AliError("cannot get \"CTPLatency\" object from OCDB");
2112 /* get run params obj */
2113 if (!ReadRunParamsFromCDB("TOF/Calib", run)) {
2114 AliError("cannot get \"RunParams\" object from OCDB");
2117 /* get response params */
2119 TFile *responseFile = TFile::Open("$ALICE_ROOT/TOF/data/AliTOFresponsePar.root");
2120 if (!responseFile || !responseFile->IsOpen()) {
2121 AliError("cannot open \"ResponseParams\" local file");
2124 fResponseParams = (AliTOFResponseParams *)responseFile->Get("ResponseParams");
2125 if (!fResponseParams) {
2126 AliError("cannot get \"ResponseParams\" object from local file");
2129 responseFile->Close();
2138 //----------------------------------------------------------------------------
2141 AliTOFcalib::GetTimeCorrection(Int_t index, Double_t tot, Int_t deltaBC, Int_t l0l1, UInt_t timestamp)
2144 * get time correction
2148 AliError("class not yet initialized. Initialize it before.");
2152 /* get calibration params */
2153 AliTOFChannelOffline *parOffline = (AliTOFChannelOffline *)fTOFCalOffline->At(index);
2154 Int_t deltaBCOffset = fDeltaBCOffset->GetDeltaBCOffset();
2155 Float_t ctpLatency = fCTPLatency->GetCTPLatency();
2156 Float_t tdcLatencyWindow = fStatus->GetLatencyWindow(index) * 1.e3;
2157 Float_t timezero = fRunParams->EvalT0(timestamp);
2158 /* check whether to remove mean T0.
2159 * useful when one wants to compute mean T0 */
2160 if (!fRemoveMeanT0) timezero = 0.;
2162 /* compute correction */
2164 /* deltaBC correction */
2165 deltaBC = deltaBCOffset; /* inhibit deltaBC correction for the time being */
2166 corr += (deltaBC - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth();
2167 /* L0-L1 latency correction */
2168 corr -= l0l1 * AliTOFGeometry::BunchCrossingBinWidth();
2169 /* CTP latency correction */
2171 /* TDC latency window correction */
2172 corr += tdcLatencyWindow;
2173 /* time-zero correction */
2175 /* time calibration correction */
2176 if (tot < AliTOFGeometry::SlewTOTMin())
2177 tot = AliTOFGeometry::SlewTOTMin();
2178 if (tot > AliTOFGeometry::SlewTOTMax())
2179 tot = AliTOFGeometry::SlewTOTMax();
2180 for (Int_t islew = 0; islew < 6; islew++)
2181 corr += parOffline->GetSlewPar(islew) * TMath::Power(tot, islew) * 1.e3;
2183 /* return correction */
2187 //----------------------------------------------------------------------------
2190 AliTOFcalib::CalibrateESD(AliESDEvent *event)
2197 AliError("class not yet initialized. Initialize it before.");
2201 /* loop over tracks */
2202 AliESDtrack *track = NULL;
2203 Int_t index, l0l1, deltaBC;
2204 Double_t time, tot, corr, texp[AliPID::kSPECIES];
2205 UInt_t timestamp = event->GetTimeStamp();
2206 for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
2209 track = event->GetTrack(itrk);
2210 if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) continue;
2212 /* calibrate TOF signal */
2213 if (fCalibrateTOFsignal) {
2215 index = track->GetTOFCalChannel();
2216 time = track->GetTOFsignalRaw();
2217 tot = track->GetTOFsignalToT();
2218 l0l1 = track->GetTOFL0L1();
2219 deltaBC = track->GetTOFDeltaBC();
2220 /* get correction */
2221 corr = GetTimeCorrection(index, tot, deltaBC, l0l1, timestamp);
2222 /* apply correction */
2224 /* set new TOF signal */
2225 track->SetTOFsignal(time);
2228 /* correct expected time */
2230 /* get integrated times */
2231 track->GetIntegratedTimes(texp);
2232 /* loop over particle types and correct expected time */
2233 for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++)
2234 texp[ipart] += fResponseParams->EvalTExpCorr(ipart, track->P());
2235 /* set integrated times */
2236 track->SetIntegratedTimes(texp);
2243 //----------------------------------------------------------------------------
2246 AliTOFcalib::IsChannelEnabled(Int_t index)
2249 * is channel enabled
2253 AliError("class not yet initialized. Initialize it before.");
2257 /* check bad status */
2258 if (fStatus->GetPulserStatus(index) == AliTOFChannelOnlineStatusArray::kTOFPulserBad) return kFALSE;
2259 if (fStatus->GetNoiseStatus(index) == AliTOFChannelOnlineStatusArray::kTOFNoiseBad) return kFALSE;
2260 if (fStatus->GetHWStatus(index) == AliTOFChannelOnlineStatusArray::kTOFHWBad) return kFALSE;