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);
907 TObjArray *arr=new TObjArray(1);
910 //man->Put(param,id,md);
913 //_____________________________________________________________________________
914 void AliTOFcalib::WriteRecParOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, TObjArray *arr){
915 //Write reconstruction parameters to the CDB
917 AliCDBManager *man = AliCDBManager::Instance();
918 AliCDBMetaData *md = new AliCDBMetaData();
919 md->SetResponsible("Silvia Arcelli");
920 const Char_t *sel1 = "RecoParam" ;
921 TString out(Form("%s/%s",sel,sel1));
922 AliCDBId id(out,minrun,maxrun);
926 //_____________________________________________________________________________
927 AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(const Char_t *sel, Int_t nrun, Int_t eventType)
929 //Read reconstruction parameters from the CDB
930 AliCDBManager *man = AliCDBManager::Instance();
931 const Char_t *sel1 = "RecoParam" ;
932 TString out(Form("%s/%s",sel,sel1));
933 AliCDBEntry *entry = man->Get(out,nrun);
935 AliFatal("Exiting, no CDB object (RecoParam) found!!!");
938 if(!entry->GetObject()){
939 AliFatal("Exiting, no CDB object (RecoParam) found!!!");
943 TObjArray *array = (TObjArray*)entry->GetObject();
944 AliTOFRecoParam *param=0x0;
945 if (eventType>=0 || eventType<array->GetEntries())
946 param=(AliTOFRecoParam*)array->At(eventType);
950 //-----------------------------------------------------------------------------
951 // Calibration methods
952 //-----------------------------------------------------------------------------
953 void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
955 // creating the chain with the trees for calibration
956 // collecting them from reference data
957 // from minrun to maxrun
959 Float_t p[CHENTRIESSMALL];
961 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
962 fTree->Branch("nentries",&nentries,"nentries/I");
963 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
964 AliCDBManager *man = AliCDBManager::Instance();
965 AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT/OCDB");
966 for (Int_t irun = minrun;irun<=maxrun;irun++){
967 AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
969 AliInfo(Form("No entry found for run %i",irun));
972 TTree *tree = (TTree*)entry->GetObject();
973 tree->SetBranchAddress("nentries",&nentries);
974 tree->SetBranchAddress("TOFentries",p);
975 fTree->CopyEntries(tree);
979 AliInfo(Form("Number of runs being analyzed %i",fNruns));
981 //-----------------------------------------------------------------------------
982 void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
984 // creating the chain with the trees for calibration
985 // collecting them from the Grid
986 // from minrun to maxrun
988 Float_t p[CHENTRIESSMALL];
990 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
991 fTree->SetDirectory(0);
992 fTree->Branch("nentries",&nentries,"nentries/I");
993 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
994 AliInfo("connected to alien");
995 TGrid::Connect("alien://");
998 for (Int_t irun = minrun;irun<=maxrun;irun++){
999 filename = Form("alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
1000 TFile *filegrid = TFile::Open(filename.Data(),"READ");
1001 TTree *tree = (TTree*)filegrid->Get("T");
1002 tree->SetBranchAddress("nentries",&nentries);
1003 tree->SetBranchAddress("TOFentries",p);
1004 fTree->CopyEntries(tree);
1009 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1011 //-----------------------------------------------------------------------------
1012 void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
1014 // creating the tree with the trees for calibration
1015 // collecting them from reference data (from file)
1016 // from minrun to maxrun
1018 Float_t p[CHENTRIESSMALL];
1020 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
1021 fTree->SetDirectory(0);
1022 fTree->Branch("nentries",&nentries,"nentries/I");
1023 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
1025 for (Int_t irun = minrun;irun<=maxrun;irun++){
1026 filename = Form("$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
1027 TFile *file = new TFile(filename.Data(),"READ");
1028 TTree *tree = (TTree*)file->Get("T");
1029 tree->SetBranchAddress("nentries",&nentries);
1030 tree->SetBranchAddress("TOFentries",p);
1031 fTree->CopyEntries(tree);
1038 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1040 //-----------------------------------------------------------------------------
1041 void AliTOFcalib::CreateChainFromGrid(Int_t minrun, Int_t maxrun){
1043 // creating the chain with the trees for calibration
1044 // collecting them from the Grid
1045 // from minrun to maxrun
1047 fChain = new TChain("T");
1048 AliInfo("connected to alien");
1049 TGrid::Connect("alien://");
1052 for (Int_t irun = minrun;irun<=maxrun;irun++){
1053 filename = Form("alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
1054 fChain->Add(filename.Data());
1058 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1060 //-----------------------------------------------------------------------------
1061 Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
1063 // calibrating summing more than one channels
1064 // computing calibration parameters
1066 // 0 -> everything was ok
1067 // 1 -> no tree for calibration found
1068 // 2 -> not enough statistics to perform calibration
1069 // 3 -> problems with arrays
1071 TH1::AddDirectory(0);
1073 AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ;
1074 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1075 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1077 Float_t p[CHENTRIESSMALL];
1079 //fTree->SetBranchAddress("nentries",&nentries);
1080 //fTree->SetBranchAddress("TOFentries",p);
1081 fChain->SetBranchAddress("nentries",&nentries);
1082 fChain->SetBranchAddress("TOFentries",p);
1084 Float_t ntracksTotalmean =0;
1085 for (Int_t i=ichmin; i<ichmax; i++){
1087 for (Int_t irun=0;irun<fNruns;irun++){
1088 ientry = i+irun*fNChannels;
1089 //fTree->GetEntry(ientry);
1090 fChain->GetEntry(ientry);
1091 Int_t ntracksRun=nentries/3;
1092 ntracksTotalmean+=ntracksRun;
1096 if (ntracksTotalmean < MEANENTRIES) {
1097 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1101 //filling ToT and Time arrays
1103 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1104 Float_t minToT = 0; // ns
1105 Float_t maxToT = 4.88; // ns
1107 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1108 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1109 Int_t ntracksTotal = 0;
1110 Int_t ntracksRun = 0;
1111 Double_t binsProfile[101]; // sized larger than necessary, the correct
1112 // dim being set in the booking of the profile
1113 Int_t nusefulbins=0;
1115 for (Int_t i = ichmin;i<ichmax;i++){
1117 for (Int_t irun=0;irun<fNruns;irun++){
1118 ientry = i+irun*fNChannels;
1119 //fTree->GetEntry(ientry);
1120 fChain->GetEntry(ientry);
1121 ntracksTotal+=nentries/3;
1122 ntracksRun=nentries/3;
1123 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun));
1124 for (Int_t j=0;j<ntracksRun;j++){
1125 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1126 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1127 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1128 Float_t tot = p[idxexToT];
1129 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1130 meantime+=p[idxexTime]-p[idxexExTime];
1135 nusefulbins = FindBins(hToT,&binsProfile[0]);
1136 meantime/=ntracksTotal;
1137 AliDebug(2, Form("meantime = %f",meantime));
1139 for (Int_t j=1;j<=nusefulbins;j++) {
1140 AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j]));
1143 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1144 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1146 for (Int_t irun=0;irun<fNruns;irun++){
1148 for (Int_t i=ichmin; i<ichmax; i++){
1149 ientry = i+irun*fNChannels;
1150 //fTree->GetEntry(ientry);
1151 fChain->GetEntry(ientry);
1152 ntracksRun=nentries/3;
1153 for (Int_t j=0;j<ntracksRun;j++){
1154 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1155 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1156 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1157 Float_t tot = p[idxexToT];
1158 Float_t time = p[idxexTime]-p[idxexExTime];
1159 AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1160 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1161 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1166 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1167 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1169 for(Int_t kk=0;kk<6;kk++){
1170 par[kk]=calibfunc->GetParameter(kk);
1171 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1174 if(strstr(optionSave,"save")){
1175 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1177 TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
1178 TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
1179 TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
1180 TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
1181 hSlewingProf->Write(profName);
1182 htimetot->Write(timeTotName);
1183 hToT->Write(totName);
1184 hdeltaTime->Write(deltaName);
1192 delete hSlewingProf;
1199 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin);
1200 calChannel->SetSlewPar(par);
1201 WriteParOfflineOnCDB("TOF/Calib","valid");
1204 //----------------------------------------------------------------------------
1205 Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
1207 // computing calibration parameters for channel i
1209 // 0 -> everything was ok
1210 // 1 -> no tree for calibration found
1211 // 2 -> not enough statistics to perform calibration
1212 // 3 -> problems with arrays
1214 TH1::AddDirectory(0);
1216 AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ;
1217 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1218 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1220 Float_t p[MAXCHENTRIESSMALL];
1222 //fTree->SetBranchAddress("nentries",&nentries);
1223 //fTree->SetBranchAddress("TOFentries",p);
1224 fChain->SetBranchAddress("nentries",&nentries);
1225 fChain->SetBranchAddress("TOFentries",p);
1227 Float_t ntracksTotal =0;
1228 for (Int_t irun=0;irun<fNruns;irun++){
1230 ientry = i+irun*fNChannels;
1231 //fTree->GetEntry(ientry);
1232 fChain->GetEntry(ientry);
1233 ntracksTotal+=nentries/3;
1236 if (ntracksTotal < MEANENTRIES) {
1237 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1241 //filling ToT and Time arrays
1243 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1244 Float_t minToT = 0; // ns
1245 Float_t maxToT = 4.88; // ns
1247 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1248 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1249 Int_t ntracksRun = 0;
1250 Double_t binsProfile[101]; // sized larger than necessary, the correct
1251 // dim being set in the booking of the profile
1252 Int_t nusefulbins=0;
1254 for (Int_t irun=0;irun<fNruns;irun++){
1256 ientry = i+irun*fNChannels;
1257 //fTree->GetEntry(ientry);
1258 fChain->GetEntry(ientry);
1259 ntracksRun=nentries/3;
1260 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun));
1261 for (Int_t j=0;j<ntracksRun;j++){
1262 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1263 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1264 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1265 Float_t tot = p[idxexToT];
1266 meantime+=p[idxexTime]-p[idxexExTime];
1267 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1272 nusefulbins = FindBins(hToT,&binsProfile[0]);
1273 meantime/=ntracksTotal;
1274 AliDebug(2,Form("meantime = %f",meantime));
1276 for (Int_t j=1;j<=nusefulbins;j++) {
1277 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1280 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1281 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1282 for (Int_t irun=0;irun<fNruns;irun++){
1284 ientry = i+irun*fNChannels;
1285 //fTree->GetEntry(ientry);
1286 fChain->GetEntry(ientry);
1287 ntracksRun=nentries/3;
1288 for (Int_t j=0;j<ntracksRun;j++){
1289 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1290 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1291 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1292 Float_t tot = p[idxexToT];
1293 Float_t time = p[idxexTime]-p[idxexExTime];
1294 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1295 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1296 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1300 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1301 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1303 for(Int_t kk=0;kk<6;kk++){
1304 par[kk]=calibfunc->GetParameter(kk);
1305 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1309 if(strstr(optionSave,"save")){
1310 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1312 TString profName=Form("Profile%06i",i);
1313 TString timeTotName=Form("TimeTot%06i",i);
1314 TString totName=Form("Tot%06i",i);
1315 TString deltaName=Form("Delta%06i",i);
1316 hSlewingProf->Write(profName);
1317 htimetot->Write(timeTotName);
1318 hToT->Write(totName);
1319 hdeltaTime->Write(deltaName);
1327 delete hSlewingProf;
1334 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1335 calChannel->SetSlewPar(par);
1336 WriteParOfflineOnCDB("TOF/Calib","valid");
1339 //----------------------------------------------------------------------------
1340 Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
1342 // calibrating an array of channels
1343 // computing calibration parameters
1345 // 0 -> everything was ok
1346 // 1 -> no tree for calibration found
1347 // 2 -> not enough statistics to perform calibration
1348 // 3 -> problems with arrays
1350 TH1::AddDirectory(0);
1352 AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ;
1353 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1354 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1355 for (Int_t ich=0; ich<nch; ich++){
1357 AliInfo(Form("Calibrating channel = %i",i )) ;
1359 Float_t p[MAXCHENTRIESSMALL];
1361 //fTree->SetBranchAddress("nentries",&nentries);
1362 //fTree->SetBranchAddress("TOFentries",p);
1363 fChain->SetBranchAddress("nentries",&nentries);
1364 fChain->SetBranchAddress("TOFentries",p);
1366 Float_t ntracksTotalmean =0;
1367 for (Int_t ich=0; ich<nch; ich++){
1370 for (Int_t irun=0;irun<fNruns;irun++){
1371 ientry = i+irun*fNChannels;
1372 //fTree->GetEntry(ientry);
1373 fChain->GetEntry(ientry);
1374 ntracksTotalmean+=nentries/3;
1378 ntracksTotalmean/=nch;
1379 if (ntracksTotalmean < MEANENTRIES) {
1380 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1384 //filling ToT and Time arrays
1386 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1387 Float_t minToT = 0; // ns
1388 Float_t maxToT = 4.88; // ns
1389 TFile * fileProf=0x0;
1390 if(strstr(optionSave,"save")){
1391 fileProf = new TFile("TOFCalibSave.root","recreate");
1393 for (Int_t ich=0; ich<nch; ich++) {
1394 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1395 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1396 Double_t binsProfile[101]; // sized larger than necessary, the correct
1397 // dim being set in the booking of the profile
1398 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1399 Int_t ntracksTotal = 0;
1400 Int_t ntracksRun = 0;
1401 Int_t nusefulbins=0;
1404 for (Int_t irun=0;irun<fNruns;irun++){
1405 i = ch[ich]+irun*fNChannels;
1406 AliDebug(2,Form("Calibrating channel %i",i));
1407 //fTree->GetEntry(i);
1408 fChain->GetEntry(i);
1409 ntracksTotal+=nentries/3;
1411 if (ntracksTotal < MEANENTRIES) {
1412 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",i,ntracksTotal));
1416 for (Int_t irun=0;irun<fNruns;irun++){
1417 i = ch[ich]+irun*fNChannels;
1418 //fTree->GetEntry(i);
1419 fChain->GetEntry(i);
1420 ntracksRun=nentries/3;
1421 for (Int_t j=0;j<ntracksRun;j++){
1422 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1423 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1424 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1425 Float_t tot = p[idxexToT];
1426 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1427 meantime+=p[idxexTime]-p[idxexExTime];
1432 nusefulbins = FindBins(hToT,&binsProfile[0]);
1433 meantime/=ntracksTotal;
1434 for (Int_t j=1;j<=nusefulbins;j++) {
1435 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1438 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1439 for (Int_t irun=0;irun<fNruns;irun++){
1440 i = ch[ich]+irun*fNChannels;
1441 //fTree->GetEntry(i);
1442 fChain->GetEntry(i);
1443 ntracksRun=nentries/3;
1444 for (Int_t j=0;j<ntracksRun;j++){
1445 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1446 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1447 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1448 Float_t tot = p[idxexToT];
1449 Float_t time = p[idxexTime]-p[idxexExTime];
1450 AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1451 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1452 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1456 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1457 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1459 for(Int_t kk=0;kk<6;kk++){
1460 par[kk]=calibfunc->GetParameter(kk);
1461 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1464 if(strstr(optionSave,"save") && fileProf){
1465 TString profName=Form("Profile%06i",i);
1466 TString timeTotName=Form("TimeTot%06i",i);
1467 TString totName=Form("Tot%06i",i);
1468 TString deltaName=Form("Delta%06i",i);
1470 hSlewingProf->Write(profName);
1471 htimetot->Write(timeTotName);
1472 hToT->Write(totName);
1473 hdeltaTime->Write(deltaName);
1476 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1477 calChannel->SetSlewPar(par);
1480 delete hSlewingProf;
1488 if(strstr(optionSave,"save") && fileProf){
1493 WriteParOfflineOnCDB("TOF/Calib","valid");
1497 //----------------------------------------------------------------------------
1498 Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){
1500 // computing calibration parameters using the old profiling algo
1502 // 0 -> everything was ok
1503 // 1 -> no tree for calibration found
1504 // 2 -> not enough statistics to perform calibration
1505 // 3 -> problems with arrays
1507 TH1::AddDirectory(0);
1509 AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ;
1510 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1511 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1512 Float_t p[MAXCHENTRIESSMALL];
1514 Int_t ntracksTotal=0;
1515 //fTree->SetBranchAddress("nentries",&nentries);
1516 //fTree->SetBranchAddress("TOFentries",p);
1517 fChain->SetBranchAddress("nentries",&nentries);
1518 fChain->SetBranchAddress("TOFentries",p);
1520 for (Int_t irun=0;irun<fNruns;irun++){
1521 Int_t i = ich+irun*fNChannels;
1522 //fTree->GetEntry(i);
1523 fChain->GetEntry(i);
1524 ntracksTotal+=nentries/3;
1527 if (ntracksTotal < MEANENTRIES) {
1528 AliInfo(Form(" Too small mean number of entires per channel (mean number = %d) not calibrating and exiting.....",ntracksTotal));
1532 TH1F * hProf = Profile(ich);
1533 hProf->Fit("pol5",optionFit,"",0,4);
1534 TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
1536 for(Int_t kk=0;kk<6;kk++){
1537 par[kk]=calibfunc->GetParameter(kk);
1538 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1541 if(strstr(optionSave,"save")){
1542 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1544 TString profName=Form("Profile%06i",ich);
1545 hProf->Write(profName);
1553 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich);
1554 calChannel->SetSlewPar(par);
1555 WriteParOfflineOnCDB("TOF/Calib","valid");
1558 //----------------------------------------------------------------------------
1559 Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
1561 // calibrating the whole TOF
1562 // computing calibration parameters
1564 // 0 -> everything was ok
1565 // 1 -> no tree for calibration found
1566 // 2 -> not enough statistics to perform calibration
1567 // 3 -> problems with arrays
1569 TH1::AddDirectory(0);
1571 AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ;
1572 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1573 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1575 TFile * fileProf=0x0;
1576 if(strstr(optionSave,"save")){
1577 fileProf = new TFile("TOFCalibSave.root","recreate");
1580 Float_t p[MAXCHENTRIESSMALL];
1582 //fTree->SetBranchAddress("nentries",&nentries);
1583 //fTree->SetBranchAddress("TOFentries",p);
1584 fChain->SetBranchAddress("nentries",&nentries);
1585 fChain->SetBranchAddress("TOFentries",p);
1587 Float_t ntracksTotalmean =0;
1588 for (Int_t ii=0; ii<fNChannels; ii++){
1589 for (Int_t irun=0;irun<fNruns;irun++){
1590 Int_t i = ii+irun*fNChannels;
1591 //fTree->GetEntry(i);
1592 fChain->GetEntry(i);
1593 ntracksTotalmean+=nentries/3;
1597 ntracksTotalmean/=fNChannels;
1598 if (ntracksTotalmean < MEANENTRIES) {
1599 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1603 //filling ToT and Time arrays
1605 Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps
1606 Float_t minToT = 0; // ns
1607 Float_t maxToT = 4.88;// ns
1608 for (Int_t ii=0; ii<fNChannels; ii++) {
1609 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1610 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1611 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1612 if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
1614 Int_t nusefulbins=0;
1615 Double_t binsProfile[101]; // sized larger than necessary, the correct
1616 // dim being set in the booking of the profile
1617 Int_t ntracksRun = 0;
1618 Int_t ntracksTotal = 0;
1619 for (Int_t irun=0;irun<fNruns;irun++){
1620 Int_t i = ii+irun*fNChannels;
1621 //fTree->GetEntry(i);
1622 fChain->GetEntry(i);
1623 ntracksTotal+=nentries/3;
1625 if (ntracksTotal < MEANENTRIES) {
1626 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",ii,ntracksTotal));
1630 for (Int_t irun=0;irun<fNruns;irun++){
1631 Int_t i = ii+irun*fNChannels;
1632 //fTree->GetEntry(i);
1633 fChain->GetEntry(i);
1634 ntracksRun=nentries/3;
1635 for (Int_t j=0;j<ntracksRun;j++){
1636 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1637 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1638 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1639 Float_t tot = p[idxexToT];
1640 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1641 meantime+=p[idxexTime]-p[idxexExTime];
1645 nusefulbins = FindBins(hToT,&binsProfile[0]);
1646 meantime/=ntracksTotal;
1647 for (Int_t j=0;j<nusefulbins;j++) {
1648 AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j]));
1650 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1651 for (Int_t irun=0;irun<fNruns;irun++){
1652 Int_t i = ii+irun*fNChannels;
1653 //fTree->GetEntry(i);
1654 fChain->GetEntry(i);
1655 ntracksRun=nentries/3;
1656 for (Int_t j=0;j<ntracksRun;j++){
1657 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1658 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1659 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1660 Float_t tot = p[idxexToT];
1661 Float_t time = p[idxexTime]-p[idxexExTime];
1662 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1663 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1664 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1667 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1668 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1670 for(Int_t kk=0;kk<6;kk++){
1671 par[kk]=calibfunc->GetParameter(kk);
1672 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1675 if(strstr(optionSave,"save") && fileProf){
1676 TString profName=Form("Profile%06i",ii);
1677 TString timeTotName=Form("TimeTot%06i",ii);
1678 TString totName=Form("Tot%06i",ii);
1679 TString deltaName=Form("Delta%06i",ii);
1681 hSlewingProf->Write(profName);
1682 htimetot->Write(timeTotName);
1683 hToT->Write(totName);
1684 hdeltaTime->Write(deltaName);
1686 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii);
1687 calChannel->SetSlewPar(par);
1691 delete hSlewingProf;
1699 if(strstr(optionSave,"save")){
1704 WriteParOfflineOnCDB("TOF/Calib","valid");
1708 //-----------------------------------------------------------------------
1709 TH1F* AliTOFcalib::Profile(Int_t ich)
1713 Float_t p[MAXCHENTRIESSMALL];
1715 //fTree->SetBranchAddress("nentries",&nentries);
1716 //fTree->SetBranchAddress("TOFentries",p);
1717 fChain->SetBranchAddress("nentries",&nentries);
1718 fChain->SetBranchAddress("TOFentries",p);
1720 //Prepare histograms for Slewing Correction
1721 const Int_t knbinToT = 100;
1722 Int_t nbinTime = 200;
1723 Float_t minTime = -5.5; //ns
1724 Float_t maxTime = 5.5; //ns
1725 Float_t minToT = 0; //ns
1726 Float_t maxToT = 5.; //ns
1727 Float_t deltaToT = (maxToT-minToT)/knbinToT;
1728 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];
1729 Int_t n[knbinToT+1], nentrx[knbinToT+1];
1730 Double_t sigmaToT[knbinToT+1];
1731 for (Int_t i = 0; i < knbinToT+1 ; i++){
1749 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
1750 Int_t ntracksRun = 0;
1751 TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
1752 for (Int_t irun=0;irun<fNruns;irun++){
1753 Int_t i = ich+irun*fNChannels;
1754 //fTree->GetEntry(i);
1755 fChain->GetEntry(i);
1756 ntracksRun=nentries/3;
1757 for (Int_t j=0;j<ntracksRun;j++){
1758 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1759 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1760 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1761 Float_t tot = p[idxexToT];
1762 Float_t time = p[idxexTime]-p[idxexExTime];
1763 Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
1764 if ((tot != 0) && ( time!= 0)){
1766 vTime2[nx]+=time*time;
1770 hSlewing->Fill(tot,time);
1774 Int_t nbinsToT=hSlewing->GetNbinsX();
1775 if (nbinsToT != knbinToT) {
1776 AliError("Profile :: incompatible numbers of bins");
1781 for (Int_t i=1;i<=nbinsToT;i++){
1783 n[usefulBins]+=nentrx[i];
1784 if (n[usefulBins]==0 && i == nbinsToT) {
1787 meanTime[usefulBins]+=vTime[i];
1788 meanTime2[usefulBins]+=vTime2[i];
1789 meanToT[usefulBins]+=vToT[i];
1790 meanToT2[usefulBins]+=vToT2[i];
1791 if (n[usefulBins]<10 && i!=nbinsToT) continue;
1792 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
1793 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
1794 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1795 *(meanTime2[usefulBins]-meanTime[usefulBins]
1796 *meanTime[usefulBins]/n[usefulBins]));
1797 if ((1./n[usefulBins]/n[usefulBins]
1798 *(meanToT2[usefulBins]-meanToT[usefulBins]
1799 *meanToT[usefulBins]/n[usefulBins]))< 0) {
1800 AliError(" too small radical" );
1801 sigmaToT[usefulBins]=0;
1804 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1805 *(meanToT2[usefulBins]-meanToT[usefulBins]
1806 *meanToT[usefulBins]/n[usefulBins]));
1811 for (Int_t i=0;i<usefulBins;i++){
1812 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
1813 histo->Fill(mToT[i],mTime[i]);
1814 histo->SetBinError(binN,sigmaTime[i]);
1821 //----------------------------------------------------------------------------
1822 Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
1824 // to determine the bins for ToT histo
1828 Int_t nbin = h->GetNbinsX();
1829 Int_t nentries = (Int_t)h->GetEntries();
1830 Float_t max = h->GetBinLowEdge(nbin);
1831 Int_t nusefulbins=0;
1833 // setting maxvalue of entries per bin
1834 if (nentries <= 60) maxcont = 2;
1835 else if (nentries <= 100) maxcont = 5;
1836 else if (nentries <= 500) maxcont = 10;
1838 for (Int_t j=1;j<=nbin;j++) {
1839 cont += (Int_t)h->GetBinContent(j);
1843 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1852 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1853 binsProfile[nusefulbins]=max;
1856 binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);
1864 //----------------------------------------------------------------------------
1867 AliTOFcalib::CreateDeltaBCOffset()
1870 * create deltaBC offset
1873 if (fDeltaBCOffset) {
1874 AliWarning("DeltaBCOffset object already defined, cannot create a new one");
1877 fDeltaBCOffset = new AliTOFDeltaBCOffset();
1880 //----------------------------------------------------------------------------
1883 AliTOFcalib::CreateCTPLatency()
1886 * create CTP latency
1890 AliWarning("CTPLatency object already defined, cannot create a new one");
1893 fCTPLatency = new AliTOFCTPLatency();
1896 //----------------------------------------------------------------------------
1899 AliTOFcalib::CreateT0Fill()
1906 AliWarning("T0Fill object already defined, cannot create a new one");
1909 fT0Fill = new AliTOFT0Fill();
1912 //----------------------------------------------------------------------------
1915 AliTOFcalib::CreateRunParams()
1922 AliWarning("RunParams object already defined, cannot create a new one");
1925 fRunParams = new AliTOFRunParams();
1928 //----------------------------------------------------------------------------
1931 AliTOFcalib::WriteDeltaBCOffsetOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1934 * deltaBC offset on CDB
1937 if (!fDeltaBCOffset) return;
1938 AliCDBId id(Form("%s/DeltaBCOffset", sel), minrun, maxrun);
1939 AliCDBMetaData *md = new AliCDBMetaData();
1940 md->SetResponsible("Roberto Preghenella");
1941 AliCDBManager *man = AliCDBManager::Instance();
1942 man->Put(fDeltaBCOffset, id, md);
1943 AliDebug(2,Form("DeltaBCOffset written on CDB with run range [%i, %i] ",minrun ,maxrun));
1947 //----------------------------------------------------------------------------
1950 AliTOFcalib::WriteCTPLatencyOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1953 * write CTP latency on CDB
1956 if (!fCTPLatency) return;
1957 AliCDBId id(Form("%s/CTPLatency", sel), minrun, maxrun);
1958 AliCDBMetaData *md = new AliCDBMetaData();
1959 md->SetResponsible("Roberto Preghenella");
1960 AliCDBManager *man = AliCDBManager::Instance();
1961 man->Put(fCTPLatency, id, md);
1962 AliDebug(2,Form("CTPLatency written on CDB with run range [%i, %i] ",minrun ,maxrun));
1966 //----------------------------------------------------------------------------
1969 AliTOFcalib::WriteT0FillOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1972 * write event-time on CDB
1975 if (!fT0Fill) return;
1976 AliCDBId id(Form("%s/T0Fill", sel), minrun, maxrun);
1977 AliCDBMetaData *md = new AliCDBMetaData();
1978 md->SetResponsible("Roberto Preghenella");
1979 AliCDBManager *man = AliCDBManager::Instance();
1980 man->Put(fT0Fill, id, md);
1981 AliDebug(2,Form("T0Fill written on CDB with run range [%i, %i] ",minrun ,maxrun));
1985 //----------------------------------------------------------------------------
1988 AliTOFcalib::WriteRunParamsOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1991 * write run params on CDB
1994 if (!fRunParams) return;
1995 AliCDBId id(Form("%s/RunParams", sel), minrun, maxrun);
1996 AliCDBMetaData *md = new AliCDBMetaData();
1997 md->SetResponsible("Roberto Preghenella");
1998 AliCDBManager *man = AliCDBManager::Instance();
1999 man->Put(fRunParams, id, md);
2000 AliDebug(2,Form("RunParams written on CDB with run range [%i, %i] ",minrun ,maxrun));
2004 //----------------------------------------------------------------------------
2007 AliTOFcalib::ReadDeltaBCOffsetFromCDB(const Char_t *sel , Int_t nrun)
2010 * read deltaBC offset from CDB
2013 AliCDBManager *man = AliCDBManager::Instance();
2014 AliCDBEntry *entry = man->Get(Form("%s/DeltaBCOffset", sel),nrun);
2016 AliFatal("No DeltaBCOffset entry found in CDB");
2019 fDeltaBCOffset =(AliTOFDeltaBCOffset *)entry->GetObject();
2020 if(!fDeltaBCOffset){
2021 AliFatal("No DeltaBCOffset object found in CDB entry");
2027 //----------------------------------------------------------------------------
2030 AliTOFcalib::ReadCTPLatencyFromCDB(const Char_t *sel , Int_t nrun)
2033 * read CTP latency from CDB
2036 AliCDBManager *man = AliCDBManager::Instance();
2037 AliCDBEntry *entry = man->Get(Form("%s/CTPLatency", sel),nrun);
2039 AliFatal("No CTPLatency entry found in CDB");
2042 fCTPLatency =(AliTOFCTPLatency *)entry->GetObject();
2044 AliFatal("No CTPLatency object found in CDB entry");
2050 //----------------------------------------------------------------------------
2053 AliTOFcalib::ReadT0FillFromCDB(const Char_t *sel , Int_t nrun)
2056 * read event-time from CDB
2059 AliCDBManager *man = AliCDBManager::Instance();
2060 AliCDBEntry *entry = man->Get(Form("%s/T0Fill", sel),nrun);
2062 AliFatal("No T0Fill entry found in CDB");
2065 fT0Fill =(AliTOFT0Fill *)entry->GetObject();
2067 AliFatal("No T0Fill object found in CDB entry");
2073 //----------------------------------------------------------------------------
2076 AliTOFcalib::ReadRunParamsFromCDB(const Char_t *sel , Int_t nrun)
2079 * read run params from CDB
2082 AliCDBManager *man = AliCDBManager::Instance();
2083 AliCDBEntry *entry = man->Get(Form("%s/RunParams", sel),nrun);
2085 AliFatal("No RunParams entry found in CDB");
2088 fRunParams =(AliTOFRunParams *)entry->GetObject();
2090 AliFatal("No RunParams object found in CDB entry");
2096 //----------------------------------------------------------------------------
2099 AliTOFcalib::Init(Int_t run)
2106 AliWarning("the class was already initialized, re-initialize it");
2110 /* read channel status array */
2111 if (!ReadParOnlineStatusFromCDB("TOF/Calib", run)) {
2112 AliError("cannot get \"Status\" object from OCDB");
2115 /* get par offline array */
2116 if (!ReadParOfflineFromCDB("TOF/Calib", run)) {
2117 AliError("cannot get \"ParOffline\" object from OCDB");
2120 /* get deltaBC offset obj */
2121 if (!ReadDeltaBCOffsetFromCDB("TOF/Calib", run)) {
2122 AliError("cannot get \"DeltaBCOffset\" object from OCDB");
2125 /* get CTP latency obj */
2126 if (!ReadCTPLatencyFromCDB("TOF/Calib", run)) {
2127 AliError("cannot get \"CTPLatency\" object from OCDB");
2130 /* get run params obj */
2131 if (!ReadRunParamsFromCDB("TOF/Calib", run)) {
2132 AliError("cannot get \"RunParams\" object from OCDB");
2135 /* get response params */
2137 TFile *responseFile = TFile::Open("$ALICE_ROOT/TOF/data/AliTOFresponsePar.root");
2138 if (!responseFile || !responseFile->IsOpen()) {
2139 AliError("cannot open \"ResponseParams\" local file");
2142 fResponseParams = (AliTOFResponseParams *)responseFile->Get("ResponseParams");
2143 if (!fResponseParams) {
2144 AliError("cannot get \"ResponseParams\" object from local file");
2147 responseFile->Close();
2156 //----------------------------------------------------------------------------
2159 AliTOFcalib::GetTimeCorrection(Int_t index, Double_t tot, Int_t deltaBC, Int_t l0l1, UInt_t timestamp)
2162 * get time correction
2166 AliError("class not yet initialized. Initialize it before.");
2170 /* get calibration params */
2171 AliTOFChannelOffline *parOffline = (AliTOFChannelOffline *)fTOFCalOffline->At(index);
2172 Int_t deltaBCOffset = fDeltaBCOffset->GetDeltaBCOffset();
2173 Float_t ctpLatency = fCTPLatency->GetCTPLatency();
2174 Float_t tdcLatencyWindow = fStatus->GetLatencyWindow(index) * 1.e3;
2175 Float_t timezero = fRunParams->EvalT0(timestamp);
2176 /* check whether to remove mean T0.
2177 * useful when one wants to compute mean T0 */
2178 if (!fRemoveMeanT0) timezero = 0.;
2180 /* compute correction */
2182 /* deltaBC correction */
2183 deltaBC = deltaBCOffset; /* inhibit deltaBC correction for the time being */
2184 corr += (deltaBC - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth();
2185 /* L0-L1 latency correction */
2186 corr -= l0l1 * AliTOFGeometry::BunchCrossingBinWidth();
2187 /* CTP latency correction */
2189 /* TDC latency window correction */
2190 corr += tdcLatencyWindow;
2191 /* time-zero correction */
2193 /* time calibration correction */
2194 if (tot < AliTOFGeometry::SlewTOTMin())
2195 tot = AliTOFGeometry::SlewTOTMin();
2196 if (tot > AliTOFGeometry::SlewTOTMax())
2197 tot = AliTOFGeometry::SlewTOTMax();
2198 for (Int_t islew = 0; islew < 6; islew++)
2199 corr += parOffline->GetSlewPar(islew) * TMath::Power(tot, islew) * 1.e3;
2201 /* return correction */
2205 //----------------------------------------------------------------------------
2208 AliTOFcalib::CalibrateESD(AliESDEvent *event)
2215 AliError("class not yet initialized. Initialize it before.");
2219 /* loop over tracks */
2220 AliESDtrack *track = NULL;
2221 Int_t index, l0l1, deltaBC;
2222 Double_t time, tot, corr, texp[AliPID::kSPECIES];
2223 UInt_t timestamp = event->GetTimeStamp();
2224 for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
2227 track = event->GetTrack(itrk);
2228 if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) continue;
2230 /* calibrate TOF signal */
2231 if (fCalibrateTOFsignal) {
2233 index = track->GetTOFCalChannel();
2234 time = track->GetTOFsignalRaw();
2235 tot = track->GetTOFsignalToT();
2236 l0l1 = track->GetTOFL0L1();
2237 deltaBC = track->GetTOFDeltaBC();
2238 /* get correction */
2239 corr = GetTimeCorrection(index, tot, deltaBC, l0l1, timestamp);
2240 /* apply correction */
2242 /* set new TOF signal */
2243 track->SetTOFsignal(time);
2246 /* correct expected time */
2248 /* get integrated times */
2249 track->GetIntegratedTimes(texp);
2250 /* loop over particle types and correct expected time */
2251 for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++)
2252 texp[ipart] += fResponseParams->EvalTExpCorr(ipart, track->P());
2253 /* set integrated times */
2254 track->SetIntegratedTimes(texp);
2261 //----------------------------------------------------------------------------
2264 AliTOFcalib::IsChannelEnabled(Int_t index)
2267 * is channel enabled
2271 AliError("class not yet initialized. Initialize it before.");
2275 /* check bad status */
2276 if (fStatus->GetPulserStatus(index) == AliTOFChannelOnlineStatusArray::kTOFPulserBad) return kFALSE;
2277 if (fStatus->GetNoiseStatus(index) == AliTOFChannelOnlineStatusArray::kTOFNoiseBad) return kFALSE;
2278 if (fStatus->GetHWStatus(index) == AliTOFChannelOnlineStatusArray::kTOFHWBad) return kFALSE;