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)
194 //TOF Calibration Class copy ctor
195 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
196 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
197 AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
198 AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
199 AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
200 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
201 fTOFCalOnline->AddAt(calChOnline,iarray);
202 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
203 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
204 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
205 fTOFCalOffline->AddAt(calChOffline,iarray);
208 if (calib.fDeltaBCOffset) fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset);
209 if (calib.fCTPLatency) fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency);
210 if (calib.fT0Fill) fT0Fill = new AliTOFT0Fill(*calib.fT0Fill);
211 if (calib.fRunParams) fRunParams = new AliTOFRunParams(*calib.fRunParams);
212 if (calib.fResponseParams) fResponseParams = new AliTOFResponseParams(*calib.fResponseParams);
215 //____________________________________________________________________________
217 AliTOFcalib& AliTOFcalib::operator=(const AliTOFcalib &calib)
219 //TOF Calibration Class assignment operator
224 TTask::operator=(calib);
225 fNChannels = calib.fNChannels;
227 fStatus = calib.fStatus;
228 fTOFSimToT = calib.fTOFSimToT;
229 fkValidity = calib.fkValidity;
231 fChain = calib.fChain;
232 fNruns = calib.fNruns;
233 fFirstRun = calib.fFirstRun;
234 fLastRun = calib.fLastRun;
235 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
236 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
237 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
238 AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
239 AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
240 AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
241 fTOFCalOnline->AddAt(calChOnline,iarray);
242 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
243 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
244 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
245 fTOFCalOffline->AddAt(calChOffline,iarray);
248 if (calib.fDeltaBCOffset) {
249 if (fDeltaBCOffset) *fDeltaBCOffset = *calib.fDeltaBCOffset;
250 else fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset);
253 if (calib.fCTPLatency) {
254 if (fCTPLatency) *fCTPLatency = *calib.fCTPLatency;
255 else fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency);
259 if (fT0Fill) *fT0Fill = *calib.fT0Fill;
260 else fT0Fill = new AliTOFT0Fill(*calib.fT0Fill);
262 if (calib.fRunParams) {
263 if (fRunParams) *fRunParams = *calib.fRunParams;
264 else fRunParams = new AliTOFRunParams(*calib.fRunParams);
266 if (calib.fResponseParams) {
267 if (fResponseParams) *fResponseParams = *calib.fResponseParams;
268 else fResponseParams = new AliTOFResponseParams(*calib.fResponseParams);
270 fInitFlag = calib.fInitFlag;
271 fRemoveMeanT0 = calib.fRemoveMeanT0;
272 fCalibrateTOFsignal = calib.fCalibrateTOFsignal;
273 fCorrectTExp = calib.fCorrectTExp;
278 //____________________________________________________________________________
280 AliTOFcalib::~AliTOFcalib()
282 //TOF Calibration Class dtor
283 if(!(AliCDBManager::Instance()->GetCacheFlag())){ // CDB objects must NOT be deleted if cache is active!
285 delete fTOFCalOnline;
287 if (fTOFCalOnlinePulser){
288 delete fTOFCalOnlinePulser;
290 if (fTOFCalOnlineNoise){
291 delete fTOFCalOnlineNoise;
293 if (fTOFCalOnlineHW){
294 delete fTOFCalOnlineHW;
297 delete fTOFCalOffline;
308 if (fDeltaBCOffset) delete fDeltaBCOffset;
309 if (fCTPLatency) delete fCTPLatency;
310 if (fT0Fill) delete fT0Fill;
311 if (fRunParams) delete fRunParams;
313 if (fTree!=0x0) delete fTree;
314 if (fChain!=0x0) delete fChain;
317 //_____________________________________________________________________________
318 void AliTOFcalib::CreateCalArrays(){
320 // creating arrays for online/offline calibration objs
322 fTOFCalOnline = new TObjArray(fNChannels);
323 fTOFCalOnlinePulser = new TObjArray(fNChannels);
324 fTOFCalOnlineNoise = new TObjArray(fNChannels);
325 fTOFCalOnlineHW = new TObjArray(fNChannels);
326 fTOFCalOffline = new TObjArray(fNChannels);
327 fTOFCalOnline->SetOwner();
328 fTOFCalOnlinePulser->SetOwner();
329 fTOFCalOnlineNoise->SetOwner();
330 fTOFCalOnlineHW->SetOwner();
331 fTOFCalOffline->SetOwner();
332 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
333 AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline();
334 AliTOFChannelOnlineStatus * calChOnlineStPulser = new AliTOFChannelOnlineStatus();
335 AliTOFChannelOnlineStatus * calChOnlineStNoise = new AliTOFChannelOnlineStatus();
336 AliTOFChannelOnlineStatus * calChOnlineStHW = new AliTOFChannelOnlineStatus();
337 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
338 fTOFCalOnline->AddAt(calChOnline,iarray);
339 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
340 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
341 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
342 fTOFCalOffline->AddAt(calChOffline,iarray);
344 fCal = new AliTOFChannelOnlineArray(fNChannels);
345 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
347 //_____________________________________________________________________________
348 void AliTOFcalib::CreateCalObjects(){
350 // creating arrays for online/offline calibration objs
352 fTOFCalOffline = new TObjArray(fNChannels);
353 fTOFCalOffline->SetOwner();
354 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
355 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
356 fTOFCalOffline->AddAt(calChOffline,iarray);
358 fCal = new AliTOFChannelOnlineArray(fNChannels);
359 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
361 //_____________________________________________________________________________
362 void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
364 //Write calibration parameters to the CDB
367 AliCDBManager *man = AliCDBManager::Instance();
368 const Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
370 sprintf(out,"%s/%s",sel,sel1);
371 AliDebug(2,Form("Writing TOF configuration map for online calib on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
372 AliCDBId id(out,fFirstRun,fLastRun);
373 AliCDBMetaData *md = new AliCDBMetaData();
374 md->SetResponsible("Chiara Zampolli");
378 man->Put(fConfigMap,id,md);
381 //_____________________________________________________________________________
383 void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel)
385 //Write calibration parameters to the CDB with infinite validity
386 AliCDBManager *man = AliCDBManager::Instance();
387 const Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
389 sprintf(out,"%s/%s",sel,sel1);
390 AliCDBRunRange runrange(fFirstRun,fLastRun);
391 AliDebug(2,Form("Writing TOF config map for online calib on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
392 AliCDBId id(out,runrange);
393 AliCDBMetaData *md = new AliCDBMetaData();
394 md->SetResponsible("Chiara Zampolli");
398 man->Put(fConfigMap,id,md);
401 //_____________________________________________________________________________
402 void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
404 //Write calibration parameters to the CDB -------> new calib objs!!!!!
407 AliCDBManager *man = AliCDBManager::Instance();
408 const Char_t *sel1 = "ParOnlineDelay" ; // to be consistent with TOFPreprocessor
410 sprintf(out,"%s/%s",sel,sel1);
411 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
412 AliCDBId id(out,fFirstRun,fLastRun);
413 AliCDBMetaData *md = new AliCDBMetaData();
414 md->SetResponsible("Chiara Zampolli");
418 man->Put(fCal,id,md);
421 //_____________________________________________________________________________
422 void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
424 //Write calibration parameters to the CDB -------> new calib objs!!!!!
427 AliCDBManager *man = AliCDBManager::Instance();
428 const Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
430 sprintf(out,"%s/%s",sel,sel1);
431 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
432 AliCDBId id(out,fFirstRun,fLastRun);
433 AliCDBMetaData *md = new AliCDBMetaData();
434 md->SetResponsible("Chiara Zampolli");
438 man->Put(fStatus,id,md);
441 //_____________________________________________________________________________
443 void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel)
445 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
446 AliCDBManager *man = AliCDBManager::Instance();
447 const Char_t *sel1 = "ParOnlineDelay" ; // to be consistent with TOFPreprocessor
449 sprintf(out,"%s/%s",sel,sel1);
450 AliCDBRunRange runrange(fFirstRun,fLastRun);
451 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
452 AliCDBId id(out,runrange);
453 AliCDBMetaData *md = new AliCDBMetaData();
454 md->SetResponsible("Chiara Zampolli");
458 man->Put(fCal,id,md);
461 //_____________________________________________________________________________
463 void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel)
465 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
466 AliCDBManager *man = AliCDBManager::Instance();
467 const Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
469 sprintf(out,"%s/%s",sel,sel1);
470 AliCDBRunRange runrange(fFirstRun,fLastRun);
471 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
472 AliCDBId id(out,runrange);
473 AliCDBMetaData *md = new AliCDBMetaData();
474 md->SetResponsible("Chiara Zampolli");
478 man->Put(fStatus,id,md);
481 //_____________________________________________________________________________
482 void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
484 //Write calibration parameters to the CDB
487 AliCDBManager *man = AliCDBManager::Instance();
488 const Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
490 sprintf(out,"%s/%s",sel,sel1);
491 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
492 AliCDBId id(out,fFirstRun,fLastRun);
493 AliCDBMetaData *md = new AliCDBMetaData();
494 md->SetResponsible("Chiara Zampolli");
495 if (!fTOFCalOnline) {
498 man->Put(fTOFCalOnline,id,md);
501 //_____________________________________________________________________________
502 void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
504 //Write calibration parameters from pulser to the CDB
507 AliCDBManager *man = AliCDBManager::Instance();
508 const Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
510 sprintf(out,"%s/%s",sel,sel1);
511 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
512 AliCDBId id(out,fFirstRun,fLastRun);
513 AliCDBMetaData *md = new AliCDBMetaData();
514 md->SetResponsible("Chiara Zampolli");
515 if (!fTOFCalOnlinePulser) {
518 man->Put(fTOFCalOnlinePulser,id,md);
521 //_____________________________________________________________________________
522 void AliTOFcalib::WriteParOnlineNoiseOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
524 //Write calibration parameters from noise to the CDB
527 AliCDBManager *man = AliCDBManager::Instance();
528 const Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
530 sprintf(out,"%s/%s",sel,sel1);
531 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
532 AliCDBId id(out,fFirstRun,fLastRun);
533 AliCDBMetaData *md = new AliCDBMetaData();
534 md->SetResponsible("Chiara Zampolli");
535 if (!fTOFCalOnlineNoise) {
538 man->Put(fTOFCalOnlineNoise,id,md);
541 //_____________________________________________________________________________
542 void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
544 //Write calibration parameters from hardware to the CDB
547 AliCDBManager *man = AliCDBManager::Instance();
548 const Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
550 sprintf(out,"%s/%s",sel,sel1);
551 AliDebug(2,Form("Writing TOF online calib obj from hardware on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
552 AliCDBId id(out,fFirstRun,fLastRun);
553 AliCDBMetaData *md = new AliCDBMetaData();
554 md->SetResponsible("Chiara Zampolli");
555 if (!fTOFCalOnlineHW) {
558 man->Put(fTOFCalOnlineHW,id,md);
561 //_____________________________________________________________________________
563 void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel)
565 //Write calibration parameters to the CDB with infinite validity
566 AliCDBManager *man = AliCDBManager::Instance();
567 const Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
569 sprintf(out,"%s/%s",sel,sel1);
570 AliCDBRunRange runrange(fFirstRun,fLastRun);
571 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
572 AliCDBId id(out,runrange);
573 AliCDBMetaData *md = new AliCDBMetaData();
574 md->SetResponsible("Chiara Zampolli");
575 if (!fTOFCalOnline) {
578 man->Put(fTOFCalOnline,id,md);
581 //_____________________________________________________________________________
583 void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel)
585 //Write calibration parameters from pulser to the CDB with infinite validity
586 AliCDBManager *man = AliCDBManager::Instance();
587 const Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
589 sprintf(out,"%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
609 sprintf(out,"%s/%s",sel,sel1);
610 AliCDBRunRange runrange(fFirstRun,fLastRun);
611 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
612 AliCDBId id(out,runrange);
613 AliCDBMetaData *md = new AliCDBMetaData();
614 md->SetResponsible("Chiara Zampolli");
615 if (!fTOFCalOnlineNoise) {
618 man->Put(fTOFCalOnlineNoise,id,md);
621 //_____________________________________________________________________________
623 void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel)
625 //Write calibration parameters from hardware to the CDB with infinite validity
626 AliCDBManager *man = AliCDBManager::Instance();
627 const Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
629 sprintf(out,"%s/%s",sel,sel1);
630 AliCDBRunRange runrange(fFirstRun,fLastRun);
631 AliDebug(2,Form("Writing TOF online calib obj from harware on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
632 AliCDBId id(out,runrange);
633 AliCDBMetaData *md = new AliCDBMetaData();
634 md->SetResponsible("Chiara Zampolli");
635 if (!fTOFCalOnlineHW) {
638 man->Put(fTOFCalOnlineHW,id,md);
641 //_____________________________________________________________________________
643 void AliTOFcalib::WriteParOfflineOnCDB(const Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun)
645 //Write calibration parameters to the CDB
648 AliCDBManager *man = AliCDBManager::Instance();
649 const Char_t *sel1 = "ParOffline" ;
651 sprintf(out,"%s/%s",sel,sel1);
652 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
653 AliCDBId id(out,fFirstRun,fLastRun);
654 AliCDBMetaData *md = new AliCDBMetaData();
655 md->SetResponsible("Chiara Zampolli");
656 md->SetComment(validity);
657 man->Put(fTOFCalOffline,id,md);
660 //_____________________________________________________________________________
662 void AliTOFcalib::WriteParOfflineOnCDB(const Char_t *sel, const Char_t *validity)
664 //Write calibration parameters to the CDB with infinite validity
665 AliCDBManager *man = AliCDBManager::Instance();
666 const Char_t *sel1 = "ParOffline" ;
668 sprintf(out,"%s/%s",sel,sel1);
669 AliCDBRunRange runrange(fFirstRun,fLastRun);
670 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
671 AliCDBId id(out,runrange);
672 AliCDBMetaData *md = new AliCDBMetaData();
673 md->SetResponsible("Chiara Zampolli");
674 md->SetComment(validity);
675 man->Put(fTOFCalOffline,id,md);
678 //_____________________________________________________________________________
680 Bool_t AliTOFcalib::ReadConfigMapFromCDB(const Char_t *sel, Int_t nrun)
682 //Read calibration parameters from the CDB
683 AliCDBManager *man = AliCDBManager::Instance();
684 const Char_t *sel1 = "Config" ;
686 sprintf(out,"%s/%s",sel,sel1);
687 AliCDBEntry *entry = man->Get(out,nrun);
689 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
692 if(!entry->GetObject()){
693 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
697 fConfigMap =(TMap*)entry->GetObject();
702 //_____________________________________________________________________________
704 Bool_t AliTOFcalib::ReadParOnlineDelayFromCDB(const Char_t *sel, Int_t nrun)
706 //Read calibration parameters from the CDB -------> new calib objs!!!!!
707 AliCDBManager *man = AliCDBManager::Instance();
708 const Char_t *sel1 = "ParOnlineDelay" ;
710 sprintf(out,"%s/%s",sel,sel1);
711 AliCDBEntry *entry = man->Get(out,nrun);
713 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
716 if(!entry->GetObject()){
717 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
721 fCal =(AliTOFChannelOnlineArray*)entry->GetObject();
726 //_____________________________________________________________________________
728 Bool_t AliTOFcalib::ReadParOnlineStatusFromCDB(const Char_t *sel, Int_t nrun)
730 //Read calibration parameters from the CDB -------> new calib objs!!!!!
731 AliCDBManager *man = AliCDBManager::Instance();
732 const Char_t *sel1 = "Status" ;
734 sprintf(out,"%s/%s",sel,sel1);
735 AliCDBEntry *entry = man->Get(out,nrun);
737 AliFatal("Exiting, no CDB object (Status) found!!!");
740 if(!entry->GetObject()){
741 AliFatal("Exiting, no CDB object (Status) found!!!");
745 fStatus =(AliTOFChannelOnlineStatusArray*)entry->GetObject();
750 //_____________________________________________________________________________
752 Bool_t AliTOFcalib::ReadParOnlineFromCDB(const Char_t *sel, Int_t nrun)
754 //Read calibration parameters from the CDB
755 AliCDBManager *man = AliCDBManager::Instance();
756 const Char_t *sel1 = "ParOnline" ;
758 sprintf(out,"%s/%s",sel,sel1);
759 AliCDBEntry *entry = man->Get(out,nrun);
761 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
764 if(!entry->GetObject()){
765 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
769 fTOFCalOnline =(TObjArray*)entry->GetObject();
774 //_____________________________________________________________________________
776 Bool_t AliTOFcalib::ReadParOnlinePulserFromCDB(const Char_t *sel, Int_t nrun)
778 //Read calibration parameters from pulser from the CDB
779 AliCDBManager *man = AliCDBManager::Instance();
780 const Char_t *sel1 = "Pulser" ;
782 sprintf(out,"%s/%s",sel,sel1);
783 AliCDBEntry *entry = man->Get(out,nrun);
785 AliFatal("Exiting, no CDB object (Pulser) found!!!");
788 if(!entry->GetObject()){
789 AliFatal("Exiting, no CDB object (Pulser) found!!!");
793 fTOFCalOnlinePulser =(TObjArray*)entry->GetObject();
798 //_____________________________________________________________________________
800 Bool_t AliTOFcalib::ReadParOnlineNoiseFromCDB(const Char_t *sel, Int_t nrun)
802 //Read calibration parameters from noise from the CDB
803 AliCDBManager *man = AliCDBManager::Instance();
804 const Char_t *sel1 = "Noise" ;
806 sprintf(out,"%s/%s",sel,sel1);
807 AliCDBEntry *entry = man->Get(out,nrun);
809 AliFatal("Exiting, no CDB object (Noise) found!!!");
812 if(!entry->GetObject()){
813 AliFatal("Exiting, no CDB object (Noise) found!!!");
817 fTOFCalOnlineNoise =(TObjArray*)entry->GetObject();
822 //_____________________________________________________________________________
824 Bool_t AliTOFcalib::ReadParOnlineHWFromCDB(const Char_t *sel, Int_t nrun)
826 //Read calibration parameters from hardware from the CDB
827 AliCDBManager *man = AliCDBManager::Instance();
828 const Char_t *sel1 = "HW" ;
830 sprintf(out,"%s/%s",sel,sel1);
831 AliCDBEntry *entry = man->Get(out,nrun);
833 AliFatal("Exiting, no CDB object (HW map) found!!!");
836 if(!entry->GetObject()){
837 AliFatal("Exiting, no CDB object (HW map) found!!!");
841 fTOFCalOnlineHW =(TObjArray*)entry->GetObject();
846 //_____________________________________________________________________________
848 Bool_t AliTOFcalib::ReadParOfflineFromCDB(const Char_t *sel, Int_t nrun)
850 //Read calibration parameters from the CDB
851 AliCDBManager *man = AliCDBManager::Instance();
852 const Char_t *sel1 = "ParOffline" ;
854 sprintf(out,"%s/%s",sel,sel1);
855 AliCDBEntry *entry = man->Get(out,nrun);
857 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
860 if(!entry->GetObject()){
861 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
864 AliCDBMetaData * md = entry->GetMetaData();
865 fkValidity = md->GetComment();
866 fTOFCalOffline =(TObjArray*)entry->GetObject();
871 //_____________________________________________________________________________
872 void AliTOFcalib::WriteSimHistoOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, TH1F *histo){
873 //Write Sim miscalibration parameters to the CDB
876 AliCDBManager *man = AliCDBManager::Instance();
877 const Char_t *sel1 = "SimHisto" ;
879 sprintf(out,"%s/%s",sel,sel1);
880 AliCDBMetaData *mdhisto = new AliCDBMetaData();
881 mdhisto->SetResponsible("Chiara Zampolli");
882 AliCDBId id(out,minrun,maxrun);
883 man->Put(fTOFSimToT,id,mdhisto);
886 //_____________________________________________________________________________
887 Bool_t AliTOFcalib::ReadSimHistoFromCDB(const Char_t *sel, Int_t nrun)
889 //Read miscalibration parameters from the CDB
890 AliCDBManager *man = AliCDBManager::Instance();
894 const Char_t *sel1 = "SimHisto" ;
896 sprintf(out,"%s/%s",sel,sel1);
897 AliCDBEntry *entry = man->Get(out,nrun);
899 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
902 if(!entry->GetObject()){
903 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
906 TH1F *histo =(TH1F*)entry->GetObject();
910 //_____________________________________________________________________________
911 void AliTOFcalib::WriteRecParOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){
912 //Write reconstruction parameters to the CDB
914 AliCDBManager *man = AliCDBManager::Instance();
915 AliCDBMetaData *md = new AliCDBMetaData();
916 md->SetResponsible("Silvia Arcelli");
917 const Char_t *sel1 = "RecoParam" ;
919 sprintf(out,"%s/%s",sel,sel1);
920 AliCDBId id(out,minrun,maxrun);
921 man->Put(param,id,md);
924 //_____________________________________________________________________________
925 AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(const Char_t *sel, Int_t nrun)
927 //Read reconstruction parameters from the CDB
928 AliCDBManager *man = AliCDBManager::Instance();
929 const Char_t *sel1 = "RecoParam" ;
931 sprintf(out,"%s/%s",sel,sel1);
932 AliCDBEntry *entry = man->Get(out,nrun);
934 AliFatal("Exiting, no CDB object (RecoParam) found!!!");
937 if(!entry->GetObject()){
938 AliFatal("Exiting, no CDB object (RecoParam) found!!!");
942 AliTOFRecoParam *param=(AliTOFRecoParam*)entry->GetObject();
945 //-----------------------------------------------------------------------------
946 // Calibration methods
947 //-----------------------------------------------------------------------------
948 void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
950 // creating the chain with the trees for calibration
951 // collecting them from reference data
952 // from minrun to maxrun
954 Float_t p[CHENTRIESSMALL];
956 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
957 fTree->Branch("nentries",&nentries,"nentries/I");
958 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
959 AliCDBManager *man = AliCDBManager::Instance();
960 AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT/OCDB");
961 for (Int_t irun = minrun;irun<=maxrun;irun++){
962 AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
964 AliInfo(Form("No entry found for run %i",irun));
967 TTree *tree = new TTree();
968 tree = (TTree*)entry->GetObject();
969 tree->SetBranchAddress("nentries",&nentries);
970 tree->SetBranchAddress("TOFentries",p);
971 fTree->CopyEntries(tree);
976 AliInfo(Form("Number of runs being analyzed %i",fNruns));
978 //-----------------------------------------------------------------------------
979 void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
981 // creating the chain with the trees for calibration
982 // collecting them from the Grid
983 // from minrun to maxrun
985 Float_t p[CHENTRIESSMALL];
987 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
988 fTree->SetDirectory(0);
989 fTree->Branch("nentries",&nentries,"nentries/I");
990 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
991 AliInfo("connected to alien");
992 TGrid::Connect("alien://");
994 Char_t filename[100];
995 for (Int_t irun = minrun;irun<=maxrun;irun++){
996 sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
997 TFile *filegrid = TFile::Open(filename,"READ");
998 TTree *tree = (TTree*)filegrid->Get("T");
999 tree->SetBranchAddress("nentries",&nentries);
1000 tree->SetBranchAddress("TOFentries",p);
1001 fTree->CopyEntries(tree);
1006 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1008 //-----------------------------------------------------------------------------
1009 void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
1011 // creating the tree with the trees for calibration
1012 // collecting them from reference data (from file)
1013 // from minrun to maxrun
1015 Float_t p[CHENTRIESSMALL];
1017 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
1018 fTree->SetDirectory(0);
1019 fTree->Branch("nentries",&nentries,"nentries/I");
1020 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
1021 Char_t filename[100];
1022 for (Int_t irun = minrun;irun<=maxrun;irun++){
1023 sprintf(filename,"$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
1024 TFile *file = new TFile(filename,"READ");
1025 TTree *tree = (TTree*)file->Get("T");
1026 tree->SetBranchAddress("nentries",&nentries);
1027 tree->SetBranchAddress("TOFentries",p);
1028 fTree->CopyEntries(tree);
1035 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1037 //-----------------------------------------------------------------------------
1038 void AliTOFcalib::CreateChainFromGrid(Int_t minrun, Int_t maxrun){
1040 // creating the chain with the trees for calibration
1041 // collecting them from the Grid
1042 // from minrun to maxrun
1044 fChain = new TChain("T");
1045 AliInfo("connected to alien");
1046 TGrid::Connect("alien://");
1048 Char_t filename[100];
1049 for (Int_t irun = minrun;irun<=maxrun;irun++){
1050 sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
1051 fChain->Add(filename);
1055 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1057 //-----------------------------------------------------------------------------
1058 Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
1060 // calibrating summing more than one channels
1061 // computing calibration parameters
1063 // 0 -> everything was ok
1064 // 1 -> no tree for calibration found
1065 // 2 -> not enough statistics to perform calibration
1066 // 3 -> problems with arrays
1068 TH1::AddDirectory(0);
1070 AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ;
1071 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1072 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1074 Float_t p[CHENTRIESSMALL];
1076 //fTree->SetBranchAddress("nentries",&nentries);
1077 //fTree->SetBranchAddress("TOFentries",p);
1078 fChain->SetBranchAddress("nentries",&nentries);
1079 fChain->SetBranchAddress("TOFentries",p);
1081 Float_t ntracksTotalmean =0;
1082 for (Int_t i=ichmin; i<ichmax; i++){
1084 for (Int_t irun=0;irun<fNruns;irun++){
1085 ientry = i+irun*fNChannels;
1086 //fTree->GetEntry(ientry);
1087 fChain->GetEntry(ientry);
1088 Int_t ntracksRun=nentries/3;
1089 ntracksTotalmean+=ntracksRun;
1093 if (ntracksTotalmean < MEANENTRIES) {
1094 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1098 //filling ToT and Time arrays
1100 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1101 Float_t minToT = 0; // ns
1102 Float_t maxToT = 4.88; // ns
1104 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1105 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1106 Int_t ntracksTotal = 0;
1107 Int_t ntracksRun = 0;
1108 Double_t binsProfile[101]; // sized larger than necessary, the correct
1109 // dim being set in the booking of the profile
1110 Int_t nusefulbins=0;
1112 for (Int_t i = ichmin;i<ichmax;i++){
1114 for (Int_t irun=0;irun<fNruns;irun++){
1115 ientry = i+irun*fNChannels;
1116 //fTree->GetEntry(ientry);
1117 fChain->GetEntry(ientry);
1118 ntracksTotal+=nentries/3;
1119 ntracksRun=nentries/3;
1120 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun));
1121 for (Int_t j=0;j<ntracksRun;j++){
1122 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1123 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1124 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1125 Float_t tot = p[idxexToT];
1126 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1127 meantime+=p[idxexTime]-p[idxexExTime];
1132 nusefulbins = FindBins(hToT,&binsProfile[0]);
1133 meantime/=ntracksTotal;
1134 AliDebug(2, Form("meantime = %f",meantime));
1136 for (Int_t j=1;j<=nusefulbins;j++) {
1137 AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j]));
1140 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1141 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1143 for (Int_t irun=0;irun<fNruns;irun++){
1145 for (Int_t i=ichmin; i<ichmax; i++){
1146 ientry = i+irun*fNChannels;
1147 //fTree->GetEntry(ientry);
1148 fChain->GetEntry(ientry);
1149 ntracksRun=nentries/3;
1150 for (Int_t j=0;j<ntracksRun;j++){
1151 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1152 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1153 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1154 Float_t tot = p[idxexToT];
1155 Float_t time = p[idxexTime]-p[idxexExTime];
1156 AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1157 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1158 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1163 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1164 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1166 for(Int_t kk=0;kk<6;kk++){
1167 par[kk]=calibfunc->GetParameter(kk);
1168 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1171 if(strstr(optionSave,"save")){
1172 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1174 TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
1175 TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
1176 TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
1177 TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
1178 hSlewingProf->Write(profName);
1179 htimetot->Write(timeTotName);
1180 hToT->Write(totName);
1181 hdeltaTime->Write(deltaName);
1189 delete hSlewingProf;
1196 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin);
1197 calChannel->SetSlewPar(par);
1198 WriteParOfflineOnCDB("TOF/Calib","valid");
1201 //----------------------------------------------------------------------------
1202 Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
1204 // computing calibration parameters for channel i
1206 // 0 -> everything was ok
1207 // 1 -> no tree for calibration found
1208 // 2 -> not enough statistics to perform calibration
1209 // 3 -> problems with arrays
1211 TH1::AddDirectory(0);
1213 AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ;
1214 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1215 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1217 Float_t p[MAXCHENTRIESSMALL];
1219 //fTree->SetBranchAddress("nentries",&nentries);
1220 //fTree->SetBranchAddress("TOFentries",p);
1221 fChain->SetBranchAddress("nentries",&nentries);
1222 fChain->SetBranchAddress("TOFentries",p);
1224 Float_t ntracksTotal =0;
1225 for (Int_t irun=0;irun<fNruns;irun++){
1227 ientry = i+irun*fNChannels;
1228 //fTree->GetEntry(ientry);
1229 fChain->GetEntry(ientry);
1230 ntracksTotal+=nentries/3;
1233 if (ntracksTotal < MEANENTRIES) {
1234 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1238 //filling ToT and Time arrays
1240 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1241 Float_t minToT = 0; // ns
1242 Float_t maxToT = 4.88; // ns
1244 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1245 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1246 Int_t ntracksRun = 0;
1247 Double_t binsProfile[101]; // sized larger than necessary, the correct
1248 // dim being set in the booking of the profile
1249 Int_t nusefulbins=0;
1251 for (Int_t irun=0;irun<fNruns;irun++){
1253 ientry = i+irun*fNChannels;
1254 //fTree->GetEntry(ientry);
1255 fChain->GetEntry(ientry);
1256 ntracksRun=nentries/3;
1257 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun));
1258 for (Int_t j=0;j<ntracksRun;j++){
1259 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1260 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1261 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1262 Float_t tot = p[idxexToT];
1263 meantime+=p[idxexTime]-p[idxexExTime];
1264 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1269 nusefulbins = FindBins(hToT,&binsProfile[0]);
1270 meantime/=ntracksTotal;
1271 AliDebug(2,Form("meantime = %f",meantime));
1273 for (Int_t j=1;j<=nusefulbins;j++) {
1274 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1277 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1278 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1279 for (Int_t irun=0;irun<fNruns;irun++){
1281 ientry = i+irun*fNChannels;
1282 //fTree->GetEntry(ientry);
1283 fChain->GetEntry(ientry);
1284 ntracksRun=nentries/3;
1285 for (Int_t j=0;j<ntracksRun;j++){
1286 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1287 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1288 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1289 Float_t tot = p[idxexToT];
1290 Float_t time = p[idxexTime]-p[idxexExTime];
1291 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1292 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1293 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1297 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1298 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1300 for(Int_t kk=0;kk<6;kk++){
1301 par[kk]=calibfunc->GetParameter(kk);
1302 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1306 if(strstr(optionSave,"save")){
1307 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1309 TString profName=Form("Profile%06i",i);
1310 TString timeTotName=Form("TimeTot%06i",i);
1311 TString totName=Form("Tot%06i",i);
1312 TString deltaName=Form("Delta%06i",i);
1313 hSlewingProf->Write(profName);
1314 htimetot->Write(timeTotName);
1315 hToT->Write(totName);
1316 hdeltaTime->Write(deltaName);
1324 delete hSlewingProf;
1331 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1332 calChannel->SetSlewPar(par);
1333 WriteParOfflineOnCDB("TOF/Calib","valid");
1336 //----------------------------------------------------------------------------
1337 Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
1339 // calibrating an array of channels
1340 // computing calibration parameters
1342 // 0 -> everything was ok
1343 // 1 -> no tree for calibration found
1344 // 2 -> not enough statistics to perform calibration
1345 // 3 -> problems with arrays
1347 TH1::AddDirectory(0);
1349 AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ;
1350 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1351 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1352 for (Int_t ich=0; ich<nch; ich++){
1354 AliInfo(Form("Calibrating channel = %i",i )) ;
1356 Float_t p[MAXCHENTRIESSMALL];
1358 //fTree->SetBranchAddress("nentries",&nentries);
1359 //fTree->SetBranchAddress("TOFentries",p);
1360 fChain->SetBranchAddress("nentries",&nentries);
1361 fChain->SetBranchAddress("TOFentries",p);
1363 Float_t ntracksTotalmean =0;
1364 for (Int_t ich=0; ich<nch; ich++){
1367 for (Int_t irun=0;irun<fNruns;irun++){
1368 ientry = i+irun*fNChannels;
1369 //fTree->GetEntry(ientry);
1370 fChain->GetEntry(ientry);
1371 ntracksTotalmean+=nentries/3;
1375 ntracksTotalmean/=nch;
1376 if (ntracksTotalmean < MEANENTRIES) {
1377 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1381 //filling ToT and Time arrays
1383 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1384 Float_t minToT = 0; // ns
1385 Float_t maxToT = 4.88; // ns
1386 TFile * fileProf=0x0;
1387 if(strstr(optionSave,"save")){
1388 fileProf = new TFile("TOFCalibSave.root","recreate");
1390 for (Int_t ich=0; ich<nch; ich++) {
1391 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1392 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1393 Double_t binsProfile[101]; // sized larger than necessary, the correct
1394 // dim being set in the booking of the profile
1395 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1396 Int_t ntracksTotal = 0;
1397 Int_t ntracksRun = 0;
1398 Int_t nusefulbins=0;
1401 for (Int_t irun=0;irun<fNruns;irun++){
1402 i = ch[ich]+irun*fNChannels;
1403 AliDebug(2,Form("Calibrating channel %i",i));
1404 //fTree->GetEntry(i);
1405 fChain->GetEntry(i);
1406 ntracksTotal+=nentries/3;
1408 if (ntracksTotal < MEANENTRIES) {
1409 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",i,ntracksTotal));
1413 for (Int_t irun=0;irun<fNruns;irun++){
1414 i = ch[ich]+irun*fNChannels;
1415 //fTree->GetEntry(i);
1416 fChain->GetEntry(i);
1417 ntracksRun=nentries/3;
1418 for (Int_t j=0;j<ntracksRun;j++){
1419 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1420 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1421 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1422 Float_t tot = p[idxexToT];
1423 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1424 meantime+=p[idxexTime]-p[idxexExTime];
1429 nusefulbins = FindBins(hToT,&binsProfile[0]);
1430 meantime/=ntracksTotal;
1431 for (Int_t j=1;j<=nusefulbins;j++) {
1432 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1435 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1436 for (Int_t irun=0;irun<fNruns;irun++){
1437 i = ch[ich]+irun*fNChannels;
1438 //fTree->GetEntry(i);
1439 fChain->GetEntry(i);
1440 ntracksRun=nentries/3;
1441 for (Int_t j=0;j<ntracksRun;j++){
1442 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1443 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1444 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1445 Float_t tot = p[idxexToT];
1446 Float_t time = p[idxexTime]-p[idxexExTime];
1447 AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1448 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1449 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1453 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1454 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1456 for(Int_t kk=0;kk<6;kk++){
1457 par[kk]=calibfunc->GetParameter(kk);
1458 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1461 if(strstr(optionSave,"save") && fileProf){
1462 TString profName=Form("Profile%06i",i);
1463 TString timeTotName=Form("TimeTot%06i",i);
1464 TString totName=Form("Tot%06i",i);
1465 TString deltaName=Form("Delta%06i",i);
1467 hSlewingProf->Write(profName);
1468 htimetot->Write(timeTotName);
1469 hToT->Write(totName);
1470 hdeltaTime->Write(deltaName);
1473 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1474 calChannel->SetSlewPar(par);
1477 delete hSlewingProf;
1485 if(strstr(optionSave,"save") && fileProf){
1490 WriteParOfflineOnCDB("TOF/Calib","valid");
1494 //----------------------------------------------------------------------------
1495 Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){
1497 // computing calibration parameters using the old profiling algo
1499 // 0 -> everything was ok
1500 // 1 -> no tree for calibration found
1501 // 2 -> not enough statistics to perform calibration
1502 // 3 -> problems with arrays
1504 TH1::AddDirectory(0);
1506 AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ;
1507 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1508 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1509 Float_t p[MAXCHENTRIESSMALL];
1511 Int_t ntracksTotal=0;
1512 //fTree->SetBranchAddress("nentries",&nentries);
1513 //fTree->SetBranchAddress("TOFentries",p);
1514 fChain->SetBranchAddress("nentries",&nentries);
1515 fChain->SetBranchAddress("TOFentries",p);
1517 for (Int_t irun=0;irun<fNruns;irun++){
1518 Int_t i = ich+irun*fNChannels;
1519 //fTree->GetEntry(i);
1520 fChain->GetEntry(i);
1521 ntracksTotal+=nentries/3;
1524 if (ntracksTotal < MEANENTRIES) {
1525 AliInfo(Form(" Too small mean number of entires per channel (mean number = %d) not calibrating and exiting.....",ntracksTotal));
1529 TH1F * hProf = new TH1F();
1530 hProf = Profile(ich);
1531 hProf->Fit("pol5",optionFit,"",0,4);
1532 TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
1534 for(Int_t kk=0;kk<6;kk++){
1535 par[kk]=calibfunc->GetParameter(kk);
1536 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1539 if(strstr(optionSave,"save")){
1540 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1542 TString profName=Form("Profile%06i",ich);
1543 hProf->Write(profName);
1551 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich);
1552 calChannel->SetSlewPar(par);
1553 WriteParOfflineOnCDB("TOF/Calib","valid");
1556 //----------------------------------------------------------------------------
1557 Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
1559 // calibrating the whole TOF
1560 // computing calibration parameters
1562 // 0 -> everything was ok
1563 // 1 -> no tree for calibration found
1564 // 2 -> not enough statistics to perform calibration
1565 // 3 -> problems with arrays
1567 TH1::AddDirectory(0);
1569 AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ;
1570 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1571 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1573 TFile * fileProf=0x0;
1574 if(strstr(optionSave,"save")){
1575 fileProf = new TFile("TOFCalibSave.root","recreate");
1578 Float_t p[MAXCHENTRIESSMALL];
1580 //fTree->SetBranchAddress("nentries",&nentries);
1581 //fTree->SetBranchAddress("TOFentries",p);
1582 fChain->SetBranchAddress("nentries",&nentries);
1583 fChain->SetBranchAddress("TOFentries",p);
1585 Float_t ntracksTotalmean =0;
1586 for (Int_t ii=0; ii<fNChannels; ii++){
1587 for (Int_t irun=0;irun<fNruns;irun++){
1588 Int_t i = ii+irun*fNChannels;
1589 //fTree->GetEntry(i);
1590 fChain->GetEntry(i);
1591 ntracksTotalmean+=nentries/3;
1595 ntracksTotalmean/=fNChannels;
1596 if (ntracksTotalmean < MEANENTRIES) {
1597 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1601 //filling ToT and Time arrays
1603 Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps
1604 Float_t minToT = 0; // ns
1605 Float_t maxToT = 4.88;// ns
1606 for (Int_t ii=0; ii<fNChannels; ii++) {
1607 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1608 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1609 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1610 if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
1612 Int_t nusefulbins=0;
1613 Double_t binsProfile[101]; // sized larger than necessary, the correct
1614 // dim being set in the booking of the profile
1615 Int_t ntracksRun = 0;
1616 Int_t ntracksTotal = 0;
1617 for (Int_t irun=0;irun<fNruns;irun++){
1618 Int_t i = ii+irun*fNChannels;
1619 //fTree->GetEntry(i);
1620 fChain->GetEntry(i);
1621 ntracksTotal+=nentries/3;
1623 if (ntracksTotal < MEANENTRIES) {
1624 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",ii,ntracksTotal));
1628 for (Int_t irun=0;irun<fNruns;irun++){
1629 Int_t i = ii+irun*fNChannels;
1630 //fTree->GetEntry(i);
1631 fChain->GetEntry(i);
1632 ntracksRun=nentries/3;
1633 for (Int_t j=0;j<ntracksRun;j++){
1634 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1635 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1636 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1637 Float_t tot = p[idxexToT];
1638 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1639 meantime+=p[idxexTime]-p[idxexExTime];
1643 nusefulbins = FindBins(hToT,&binsProfile[0]);
1644 meantime/=ntracksTotal;
1645 for (Int_t j=0;j<nusefulbins;j++) {
1646 AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j]));
1648 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1649 for (Int_t irun=0;irun<fNruns;irun++){
1650 Int_t i = ii+irun*fNChannels;
1651 //fTree->GetEntry(i);
1652 fChain->GetEntry(i);
1653 ntracksRun=nentries/3;
1654 for (Int_t j=0;j<ntracksRun;j++){
1655 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1656 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1657 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1658 Float_t tot = p[idxexToT];
1659 Float_t time = p[idxexTime]-p[idxexExTime];
1660 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1661 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1662 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1665 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1666 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1668 for(Int_t kk=0;kk<6;kk++){
1669 par[kk]=calibfunc->GetParameter(kk);
1670 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1673 if(strstr(optionSave,"save") && fileProf){
1674 TString profName=Form("Profile%06i",ii);
1675 TString timeTotName=Form("TimeTot%06i",ii);
1676 TString totName=Form("Tot%06i",ii);
1677 TString deltaName=Form("Delta%06i",ii);
1679 hSlewingProf->Write(profName);
1680 htimetot->Write(timeTotName);
1681 hToT->Write(totName);
1682 hdeltaTime->Write(deltaName);
1684 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii);
1685 calChannel->SetSlewPar(par);
1689 delete hSlewingProf;
1697 if(strstr(optionSave,"save")){
1702 WriteParOfflineOnCDB("TOF/Calib","valid");
1706 //-----------------------------------------------------------------------
1707 TH1F* AliTOFcalib::Profile(Int_t ich)
1711 Float_t p[MAXCHENTRIESSMALL];
1713 //fTree->SetBranchAddress("nentries",&nentries);
1714 //fTree->SetBranchAddress("TOFentries",p);
1715 fChain->SetBranchAddress("nentries",&nentries);
1716 fChain->SetBranchAddress("TOFentries",p);
1718 //Prepare histograms for Slewing Correction
1719 const Int_t knbinToT = 100;
1720 Int_t nbinTime = 200;
1721 Float_t minTime = -5.5; //ns
1722 Float_t maxTime = 5.5; //ns
1723 Float_t minToT = 0; //ns
1724 Float_t maxToT = 5.; //ns
1725 Float_t deltaToT = (maxToT-minToT)/knbinToT;
1726 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];
1727 Int_t n[knbinToT+1], nentrx[knbinToT+1];
1728 Double_t sigmaToT[knbinToT+1];
1729 for (Int_t i = 0; i < knbinToT+1 ; i++){
1747 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
1748 Int_t ntracksRun = 0;
1749 TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
1750 for (Int_t irun=0;irun<fNruns;irun++){
1751 Int_t i = ich+irun*fNChannels;
1752 //fTree->GetEntry(i);
1753 fChain->GetEntry(i);
1754 ntracksRun=nentries/3;
1755 for (Int_t j=0;j<ntracksRun;j++){
1756 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1757 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1758 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1759 Float_t tot = p[idxexToT];
1760 Float_t time = p[idxexTime]-p[idxexExTime];
1761 Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
1762 if ((tot != 0) && ( time!= 0)){
1764 vTime2[nx]+=time*time;
1768 hSlewing->Fill(tot,time);
1772 Int_t nbinsToT=hSlewing->GetNbinsX();
1773 if (nbinsToT != knbinToT) {
1774 AliError("Profile :: incompatible numbers of bins");
1779 for (Int_t i=1;i<=nbinsToT;i++){
1781 n[usefulBins]+=nentrx[i];
1782 if (n[usefulBins]==0 && i == nbinsToT) {
1785 meanTime[usefulBins]+=vTime[i];
1786 meanTime2[usefulBins]+=vTime2[i];
1787 meanToT[usefulBins]+=vToT[i];
1788 meanToT2[usefulBins]+=vToT2[i];
1789 if (n[usefulBins]<10 && i!=nbinsToT) continue;
1790 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
1791 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
1792 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1793 *(meanTime2[usefulBins]-meanTime[usefulBins]
1794 *meanTime[usefulBins]/n[usefulBins]));
1795 if ((1./n[usefulBins]/n[usefulBins]
1796 *(meanToT2[usefulBins]-meanToT[usefulBins]
1797 *meanToT[usefulBins]/n[usefulBins]))< 0) {
1798 AliError(" too small radical" );
1799 sigmaToT[usefulBins]=0;
1802 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1803 *(meanToT2[usefulBins]-meanToT[usefulBins]
1804 *meanToT[usefulBins]/n[usefulBins]));
1809 for (Int_t i=0;i<usefulBins;i++){
1810 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
1811 histo->Fill(mToT[i],mTime[i]);
1812 histo->SetBinError(binN,sigmaTime[i]);
1819 //----------------------------------------------------------------------------
1820 Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
1822 // to determine the bins for ToT histo
1826 Int_t nbin = h->GetNbinsX();
1827 Int_t nentries = (Int_t)h->GetEntries();
1828 Float_t max = h->GetBinLowEdge(nbin);
1829 Int_t nusefulbins=0;
1831 // setting maxvalue of entries per bin
1832 if (nentries <= 60) maxcont = 2;
1833 else if (nentries <= 100) maxcont = 5;
1834 else if (nentries <= 500) maxcont = 10;
1836 for (Int_t j=1;j<=nbin;j++) {
1837 cont += (Int_t)h->GetBinContent(j);
1841 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1850 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1851 binsProfile[nusefulbins]=max;
1854 binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);
1862 //----------------------------------------------------------------------------
1865 AliTOFcalib::CreateDeltaBCOffset()
1868 * create deltaBC offset
1871 if (fDeltaBCOffset) {
1872 AliWarning("DeltaBCOffset object already defined, cannot create a new one");
1875 fDeltaBCOffset = new AliTOFDeltaBCOffset();
1878 //----------------------------------------------------------------------------
1881 AliTOFcalib::CreateCTPLatency()
1884 * create CTP latency
1888 AliWarning("CTPLatency object already defined, cannot create a new one");
1891 fCTPLatency = new AliTOFCTPLatency();
1894 //----------------------------------------------------------------------------
1897 AliTOFcalib::CreateT0Fill()
1904 AliWarning("T0Fill object already defined, cannot create a new one");
1907 fT0Fill = new AliTOFT0Fill();
1910 //----------------------------------------------------------------------------
1913 AliTOFcalib::CreateRunParams()
1920 AliWarning("RunParams object already defined, cannot create a new one");
1923 fRunParams = new AliTOFRunParams();
1926 //----------------------------------------------------------------------------
1929 AliTOFcalib::WriteDeltaBCOffsetOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1932 * deltaBC offset on CDB
1935 if (!fDeltaBCOffset) return;
1936 AliCDBId id(Form("%s/DeltaBCOffset", sel), minrun, maxrun);
1937 AliCDBMetaData *md = new AliCDBMetaData();
1938 md->SetResponsible("Roberto Preghenella");
1939 AliCDBManager *man = AliCDBManager::Instance();
1940 man->Put(fDeltaBCOffset, id, md);
1941 AliDebug(2,Form("DeltaBCOffset written on CDB with run range [%i, %i] ",minrun ,maxrun));
1945 //----------------------------------------------------------------------------
1948 AliTOFcalib::WriteCTPLatencyOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1951 * write CTP latency on CDB
1954 if (!fCTPLatency) return;
1955 AliCDBId id(Form("%s/CTPLatency", sel), minrun, maxrun);
1956 AliCDBMetaData *md = new AliCDBMetaData();
1957 md->SetResponsible("Roberto Preghenella");
1958 AliCDBManager *man = AliCDBManager::Instance();
1959 man->Put(fCTPLatency, id, md);
1960 AliDebug(2,Form("CTPLatency written on CDB with run range [%i, %i] ",minrun ,maxrun));
1964 //----------------------------------------------------------------------------
1967 AliTOFcalib::WriteT0FillOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1970 * write event-time on CDB
1973 if (!fT0Fill) return;
1974 AliCDBId id(Form("%s/T0Fill", sel), minrun, maxrun);
1975 AliCDBMetaData *md = new AliCDBMetaData();
1976 md->SetResponsible("Roberto Preghenella");
1977 AliCDBManager *man = AliCDBManager::Instance();
1978 man->Put(fT0Fill, id, md);
1979 AliDebug(2,Form("T0Fill written on CDB with run range [%i, %i] ",minrun ,maxrun));
1983 //----------------------------------------------------------------------------
1986 AliTOFcalib::WriteRunParamsOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1989 * write run params on CDB
1992 if (!fRunParams) return;
1993 AliCDBId id(Form("%s/RunParams", sel), minrun, maxrun);
1994 AliCDBMetaData *md = new AliCDBMetaData();
1995 md->SetResponsible("Roberto Preghenella");
1996 AliCDBManager *man = AliCDBManager::Instance();
1997 man->Put(fRunParams, id, md);
1998 AliDebug(2,Form("RunParams written on CDB with run range [%i, %i] ",minrun ,maxrun));
2002 //----------------------------------------------------------------------------
2005 AliTOFcalib::ReadDeltaBCOffsetFromCDB(const Char_t *sel , Int_t nrun)
2008 * read deltaBC offset from CDB
2011 AliCDBManager *man = AliCDBManager::Instance();
2012 AliCDBEntry *entry = man->Get(Form("%s/DeltaBCOffset", sel),nrun);
2014 AliFatal("No DeltaBCOffset entry found in CDB");
2017 fDeltaBCOffset =(AliTOFDeltaBCOffset *)entry->GetObject();
2018 if(!fDeltaBCOffset){
2019 AliFatal("No DeltaBCOffset object found in CDB entry");
2025 //----------------------------------------------------------------------------
2028 AliTOFcalib::ReadCTPLatencyFromCDB(const Char_t *sel , Int_t nrun)
2031 * read CTP latency from CDB
2034 AliCDBManager *man = AliCDBManager::Instance();
2035 AliCDBEntry *entry = man->Get(Form("%s/CTPLatency", sel),nrun);
2037 AliFatal("No CTPLatency entry found in CDB");
2040 fCTPLatency =(AliTOFCTPLatency *)entry->GetObject();
2042 AliFatal("No CTPLatency object found in CDB entry");
2048 //----------------------------------------------------------------------------
2051 AliTOFcalib::ReadT0FillFromCDB(const Char_t *sel , Int_t nrun)
2054 * read event-time from CDB
2057 AliCDBManager *man = AliCDBManager::Instance();
2058 AliCDBEntry *entry = man->Get(Form("%s/T0Fill", sel),nrun);
2060 AliFatal("No T0Fill entry found in CDB");
2063 fT0Fill =(AliTOFT0Fill *)entry->GetObject();
2065 AliFatal("No T0Fill object found in CDB entry");
2071 //----------------------------------------------------------------------------
2074 AliTOFcalib::ReadRunParamsFromCDB(const Char_t *sel , Int_t nrun)
2077 * read run params from CDB
2080 AliCDBManager *man = AliCDBManager::Instance();
2081 AliCDBEntry *entry = man->Get(Form("%s/RunParams", sel),nrun);
2083 AliFatal("No RunParams entry found in CDB");
2086 fRunParams =(AliTOFRunParams *)entry->GetObject();
2088 AliFatal("No RunParams object found in CDB entry");
2094 //----------------------------------------------------------------------------
2097 AliTOFcalib::Init(Int_t run)
2104 AliWarning("the class was already initialized, re-initialize it");
2108 /* read channel status array */
2109 if (!ReadParOnlineStatusFromCDB("TOF/Calib", run)) {
2110 AliError("cannot get \"Status\" object from OCDB");
2113 /* get par offline array */
2114 if (!ReadParOfflineFromCDB("TOF/Calib", run)) {
2115 AliError("cannot get \"ParOffline\" object from OCDB");
2118 /* get deltaBC offset obj */
2119 if (!ReadDeltaBCOffsetFromCDB("TOF/Calib", run)) {
2120 AliError("cannot get \"DeltaBCOffset\" object from OCDB");
2123 /* get CTP latency obj */
2124 if (!ReadCTPLatencyFromCDB("TOF/Calib", run)) {
2125 AliError("cannot get \"CTPLatency\" object from OCDB");
2128 /* get run params obj */
2129 if (!ReadRunParamsFromCDB("TOF/Calib", run)) {
2130 AliError("cannot get \"RunParams\" object from OCDB");
2133 /* get response params */
2135 TFile *responseFile = TFile::Open("$ALICE_ROOT/TOF/data/AliTOFresponsePar.root");
2136 if (!responseFile || !responseFile->IsOpen()) {
2137 AliError("cannot open \"ResponseParams\" local file");
2140 fResponseParams = (AliTOFResponseParams *)responseFile->Get("ResponseParams");
2141 if (!fResponseParams) {
2142 AliError("cannot get \"ResponseParams\" object from local file");
2145 responseFile->Close();
2154 //----------------------------------------------------------------------------
2157 AliTOFcalib::GetTimeCorrection(Int_t index, Double_t tot, Int_t deltaBC, Int_t l0l1, UInt_t timestamp)
2160 * get time correction
2164 AliError("class not yet initialized. Initialize it before.");
2168 /* get calibration params */
2169 AliTOFChannelOffline *parOffline = (AliTOFChannelOffline *)fTOFCalOffline->At(index);
2170 Int_t deltaBCOffset = fDeltaBCOffset->GetDeltaBCOffset();
2171 Float_t ctpLatency = fCTPLatency->GetCTPLatency();
2172 Float_t tdcLatencyWindow = fStatus->GetLatencyWindow(index) * 1.e3;
2173 Float_t timezero = fRunParams->EvalT0(timestamp);
2174 /* check whether to remove mean T0.
2175 * useful when one wants to compute mean T0 */
2176 if (!fRemoveMeanT0) timezero = 0.;
2178 /* compute correction */
2180 /* deltaBC correction */
2181 deltaBC = deltaBCOffset; /* inhibit deltaBC correction for the time being */
2182 corr += (deltaBC - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth();
2183 /* L0-L1 latency correction */
2184 corr -= l0l1 * AliTOFGeometry::BunchCrossingBinWidth();
2185 /* CTP latency correction */
2187 /* TDC latency window correction */
2188 corr += tdcLatencyWindow;
2189 /* time-zero correction */
2191 /* time calibration correction */
2192 if (tot < AliTOFGeometry::SlewTOTMin())
2193 tot = AliTOFGeometry::SlewTOTMin();
2194 if (tot > AliTOFGeometry::SlewTOTMax())
2195 tot = AliTOFGeometry::SlewTOTMax();
2196 for (Int_t islew = 0; islew < 6; islew++)
2197 corr += parOffline->GetSlewPar(islew) * TMath::Power(tot, islew) * 1.e3;
2199 /* return correction */
2203 //----------------------------------------------------------------------------
2206 AliTOFcalib::CalibrateESD(AliESDEvent *event)
2213 AliError("class not yet initialized. Initialize it before.");
2217 /* loop over tracks */
2218 AliESDtrack *track = NULL;
2219 Int_t index, l0l1, deltaBC;
2220 Double_t time, tot, corr, texp[AliPID::kSPECIES];
2221 UInt_t timestamp = event->GetTimeStamp();
2222 for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
2225 track = event->GetTrack(itrk);
2226 if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) continue;
2228 /* calibrate TOF signal */
2229 if (fCalibrateTOFsignal) {
2231 index = track->GetTOFCalChannel();
2232 time = track->GetTOFsignalRaw();
2233 tot = track->GetTOFsignalToT();
2234 l0l1 = track->GetTOFL0L1();
2235 deltaBC = track->GetTOFDeltaBC();
2236 /* get correction */
2237 corr = GetTimeCorrection(index, tot, deltaBC, l0l1, timestamp);
2238 /* apply correction */
2240 /* set new TOF signal */
2241 track->SetTOFsignal(time);
2244 /* correct expected time */
2246 /* get integrated times */
2247 track->GetIntegratedTimes(texp);
2248 /* loop over particle types and correct expected time */
2249 for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++)
2250 texp[ipart] += fResponseParams->EvalTExpCorr(ipart, track->P());
2251 /* set integrated times */
2252 track->SetIntegratedTimes(texp);
2259 //----------------------------------------------------------------------------
2262 AliTOFcalib::IsChannelEnabled(Int_t index)
2265 * is channel enabled
2269 AliError("class not yet initialized. Initialize it before.");
2273 /* check bad status */
2274 if (fStatus->GetPulserStatus(index) == AliTOFChannelOnlineStatusArray::kTOFPulserBad) return kFALSE;
2275 if (fStatus->GetNoiseStatus(index) == AliTOFChannelOnlineStatusArray::kTOFNoiseBad) return kFALSE;
2276 if (fStatus->GetHWStatus(index) == AliTOFChannelOnlineStatusArray::kTOFHWBad) return kFALSE;