]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFcalib.cxx
added method for fine tuning of TOF in Monte Carlo simulation
[u/mrichter/AliRoot.git] / TOF / AliTOFcalib.cxx
CommitLineData
6dc9348d 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
762446e0 16/*
7fffa85b 17$Log: AliTOFcalib.cxx,v $
18Revision 1.21 2007/11/02 15:41:49 hristov
19Provide return value if the function is not void
20
52be7fb0 21Revision 1.20 2007/10/26 15:13:50 zampolli
22Using a TChain instead of a TTree
23
296591ad 24Revision 1.19 2007/10/23 15:27:38 zampolli
25Rearrangement of Calibration objects for simulation
26
a7e9db2a 27Revision 1.16 2007/10/08 10:13:26 zampolli
28First Run and Last Run members added, infinite validity of calib obj implemented.
29
0cb9d099 30Revision 1.15 2007/10/04 13:23:28 zampolli
31Updates to handle functionalities in TOF online/offline calibration according to the latest schema
32
0a749fa5 33Revision 1.14 2007/06/06 16:26:30 arcelli
34remove fall-back call to local CDB storage
35
03705065 36Revision 1.13 2007/04/20 13:59:40 arcelli
37make protections agains failed retrieval of the CDB object in a proper way
38
7a4f634e 39Revision 1.12 2007/03/23 11:31:16 arcelli
40CDB Entry for TOF Reconstruction Parameters
41
7037bd93 42Revision 1.11 2007/02/28 18:08:26 arcelli
43Add protection against failed retrieval of the CDB cal object
44
1b20c168 45Revision 1.10 2006/08/22 13:30:49 arcelli
46removal of effective c++ warnings (C.Zampolli)
47
655e379f 48Revision 1.9 2006/04/20 22:30:50 hristov
49Coding conventions (Annalisa)
50
0e46b9ae 51Revision 1.8 2006/04/16 22:29:05 hristov
52Coding conventions (Annalisa)
53
7aeeaf38 54Revision 1.7 2006/04/16 20:12:46 hristov
55Removing memory leak in case of cached CDB entries
56
85fc78e3 57Revision 1.6 2006/04/11 15:28:32 hristov
58Checks on cache status before deleting calibration objects (A.Colla)
59
5eaae242 60Revision 1.5 2006/04/05 08:35:38 hristov
61Coding conventions (S.Arcelli, C.Zampolli)
62
340693af 63Revision 1.4 2006/03/31 11:26:46 arcelli
64 changing CDB Ids according to standard convention
65
28dd10b6 66Revision 1.3 2006/03/28 14:57:02 arcelli
67updates to handle new V5 geometry & some re-arrangements
68
d4ad0d6b 69Revision 1.2 2006/02/13 17:22:26 arcelli
70just Fixing Log info
71
762446e0 72Revision 1.1 2006/02/13 16:10:48 arcelli
73Add classes for TOF Calibration (C.Zampolli)
74
6dc9348d 75author: Chiara Zampolli, zampolli@bo.infn.it
762446e0 76*/
6dc9348d 77
78///////////////////////////////////////////////////////////////////////////////
79// //
80// class for TOF calibration //
81// //
82///////////////////////////////////////////////////////////////////////////////
83
6dc9348d 84#include "TF1.h"
0e46b9ae 85#include "TFile.h"
6dc9348d 86#include "TH1F.h"
87#include "TH2F.h"
5c7c93fa 88//#include "TList.h"
89//#include "TROOT.h"
90//#include "TStyle.h"
0a749fa5 91#include "TTree.h"
296591ad 92#include "TChain.h"
0a749fa5 93#include "TProfile.h"
94#include "TGrid.h"
5c7c93fa 95#include "TMath.h"
17149e6b 96#include "TMap.h"
0e46b9ae 97
98#include "AliCDBEntry.h"
0cb9d099 99#include "AliCDBRunRange.h"
0e46b9ae 100#include "AliCDBId.h"
6dc9348d 101#include "AliCDBManager.h"
0a749fa5 102#include "AliCDBStorage.h"
6dc9348d 103#include "AliCDBMetaData.h"
5c7c93fa 104//#include "AliESDtrack.h"
105//#include "AliESD.h"
0e46b9ae 106#include "AliLog.h"
107
0e46b9ae 108#include "AliTOFcalib.h"
17149e6b 109#include "AliTOFChannelOnlineArray.h"
0a749fa5 110#include "AliTOFChannelOnline.h"
7fffa85b 111#include "AliTOFChannelOnlineStatus.h"
17149e6b 112#include "AliTOFChannelOnlineStatusArray.h"
0a749fa5 113#include "AliTOFChannelOffline.h"
0e46b9ae 114#include "AliTOFGeometry.h"
7037bd93 115#include "AliTOFRecoParam.h"
2bf4d9d6 116#include "AliTOFDeltaBCOffset.h"
117#include "AliTOFCTPLatency.h"
118#include "AliTOFT0Fill.h"
f04b3a69 119#include "AliTOFRunParams.h"
5b4ed716 120#include "AliTOFResponseParams.h"
121#include "AliESDEvent.h"
122#include "AliESDtrack.h"
899d8839 123#include "TRandom.h"
6dc9348d 124
5c7c93fa 125class TROOT;
126class TStyle;
127
6dc9348d 128extern TROOT *gROOT;
129extern TStyle *gStyle;
130
131ClassImp(AliTOFcalib)
132
6dc9348d 133//_______________________________________________________________________
655e379f 134AliTOFcalib::AliTOFcalib():
135 TTask("AliTOFcalib",""),
136 fNChannels(-1),
0a749fa5 137 fTOFCalOnline(0x0),
7fffa85b 138 fTOFCalOnlinePulser(0x0),
139 fTOFCalOnlineNoise(0x0),
140 fTOFCalOnlineHW(0x0),
0a749fa5 141 fTOFCalOffline(0x0),
17149e6b 142 fCal(0x0),
143 fStatus(0x0),
0a749fa5 144 fTOFSimToT(0x0),
145 fkValidity(0x0),
146 fTree(0x0),
296591ad 147 fChain(0x0),
0cb9d099 148 fNruns(0),
149 fFirstRun(0),
17149e6b 150 fLastRun(AliCDBRunRange::Infinity()),
2bf4d9d6 151 fConfigMap(new TMap),
152 fDeltaBCOffset(NULL),
153 fCTPLatency(NULL),
f04b3a69 154 fT0Fill(NULL),
5b4ed716 155 fRunParams(NULL),
156 fResponseParams(NULL),
dad2868f 157 fReadoutEfficiency(NULL),
5b4ed716 158 fInitFlag(kFALSE),
159 fRemoveMeanT0(kTRUE),
8bb89c94 160 fCalibrateTOFsignal(kTRUE),
5b4ed716 161 fCorrectTExp(kFALSE)
655e379f 162{
340693af 163 //TOF Calibration Class ctor
0a749fa5 164 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
899d8839 165
166 gRandom->SetSeed(123456789);
6dc9348d 167}
168//____________________________________________________________________________
169
655e379f 170AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib):
8a190ba2 171 TTask(calib),
0a749fa5 172 fNChannels(calib.fNChannels),
173 fTOFCalOnline(0x0),
7fffa85b 174 fTOFCalOnlinePulser(0x0),
175 fTOFCalOnlineNoise(0x0),
176 fTOFCalOnlineHW(0x0),
0a749fa5 177 fTOFCalOffline(0x0),
17149e6b 178 fCal(calib.fCal),
179 fStatus(calib.fStatus),
0a749fa5 180 fTOFSimToT(calib.fTOFSimToT),
181 fkValidity(calib.fkValidity),
182 fTree(calib.fTree),
296591ad 183 fChain(calib.fChain),
0cb9d099 184 fNruns(calib.fNruns),
185 fFirstRun(calib.fFirstRun),
17149e6b 186 fLastRun(calib.fLastRun),
2bf4d9d6 187 fConfigMap(calib.fConfigMap),
188 fDeltaBCOffset(NULL),
189 fCTPLatency(NULL),
f04b3a69 190 fT0Fill(NULL),
5b4ed716 191 fRunParams(NULL),
192 fResponseParams(NULL),
dad2868f 193 fReadoutEfficiency(NULL),
5b4ed716 194 fInitFlag(calib.fInitFlag),
195 fRemoveMeanT0(calib.fRemoveMeanT0),
8bb89c94 196 fCalibrateTOFsignal(calib.fCalibrateTOFsignal),
5b4ed716 197 fCorrectTExp(calib.fCorrectTExp)
6dc9348d 198{
955f2093 199
200 fTOFCalOnline = new TObjArray(fNChannels);
201 fTOFCalOnlinePulser = new TObjArray(fNChannels);
202 fTOFCalOnlineNoise = new TObjArray(fNChannels);
203 fTOFCalOnlineHW = new TObjArray(fNChannels);
204 fTOFCalOffline = new TObjArray(fNChannels);
205 fTOFCalOnline->SetOwner();
206 fTOFCalOnlinePulser->SetOwner();
207 fTOFCalOnlineNoise->SetOwner();
208 fTOFCalOnlineHW->SetOwner();
209 fTOFCalOffline->SetOwner();
210
340693af 211 //TOF Calibration Class copy ctor
0a749fa5 212 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
213 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
7fffa85b 214 AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
215 AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
216 AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
0a749fa5 217 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
218 fTOFCalOnline->AddAt(calChOnline,iarray);
7fffa85b 219 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
220 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
221 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
0a749fa5 222 fTOFCalOffline->AddAt(calChOffline,iarray);
0a749fa5 223 }
2bf4d9d6 224
225 if (calib.fDeltaBCOffset) fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset);
226 if (calib.fCTPLatency) fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency);
227 if (calib.fT0Fill) fT0Fill = new AliTOFT0Fill(*calib.fT0Fill);
f04b3a69 228 if (calib.fRunParams) fRunParams = new AliTOFRunParams(*calib.fRunParams);
5b4ed716 229 if (calib.fResponseParams) fResponseParams = new AliTOFResponseParams(*calib.fResponseParams);
dad2868f 230 if (calib.fReadoutEfficiency) fReadoutEfficiency = new TH1F(*calib.fReadoutEfficiency);
899d8839 231
232 gRandom->SetSeed(123456789);
6dc9348d 233}
234
235//____________________________________________________________________________
7aeeaf38 236
237AliTOFcalib& AliTOFcalib::operator=(const AliTOFcalib &calib)
238{
239 //TOF Calibration Class assignment operator
8a190ba2 240
241 if (this == &calib)
242 return *this;
243
244 TTask::operator=(calib);
245 fNChannels = calib.fNChannels;
246 fCal = calib.fCal;
247 fStatus = calib.fStatus;
248 fTOFSimToT = calib.fTOFSimToT;
249 fkValidity = calib.fkValidity;
250 fTree = calib.fTree;
251 fChain = calib.fChain;
252 fNruns = calib.fNruns;
253 fFirstRun = calib.fFirstRun;
254 fLastRun = calib.fLastRun;
0a749fa5 255 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
256 AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
257 AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
7fffa85b 258 AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
259 AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
260 AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
8a190ba2 261 fTOFCalOnline->AddAt(calChOnline,iarray);
262 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
263 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
264 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
265 fTOFCalOffline->AddAt(calChOffline,iarray);
0a749fa5 266 }
2bf4d9d6 267
268 if (calib.fDeltaBCOffset) {
269 if (fDeltaBCOffset) *fDeltaBCOffset = *calib.fDeltaBCOffset;
270 else fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset);
271 }
272
273 if (calib.fCTPLatency) {
274 if (fCTPLatency) *fCTPLatency = *calib.fCTPLatency;
275 else fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency);
276 }
277
278 if (calib.fT0Fill) {
279 if (fT0Fill) *fT0Fill = *calib.fT0Fill;
280 else fT0Fill = new AliTOFT0Fill(*calib.fT0Fill);
281 }
f04b3a69 282 if (calib.fRunParams) {
283 if (fRunParams) *fRunParams = *calib.fRunParams;
284 else fRunParams = new AliTOFRunParams(*calib.fRunParams);
285 }
5b4ed716 286 if (calib.fResponseParams) {
287 if (fResponseParams) *fResponseParams = *calib.fResponseParams;
288 else fResponseParams = new AliTOFResponseParams(*calib.fResponseParams);
289 }
dad2868f 290 if (calib.fReadoutEfficiency) {
291 if (fReadoutEfficiency) *fReadoutEfficiency = *calib.fReadoutEfficiency;
292 else fReadoutEfficiency = new TH1F(*calib.fReadoutEfficiency);
293 }
5b4ed716 294 fInitFlag = calib.fInitFlag;
295 fRemoveMeanT0 = calib.fRemoveMeanT0;
8bb89c94 296 fCalibrateTOFsignal = calib.fCalibrateTOFsignal;
5b4ed716 297 fCorrectTExp = calib.fCorrectTExp;
2bf4d9d6 298
7aeeaf38 299 return *this;
300}
301
302//____________________________________________________________________________
6dc9348d 303
304AliTOFcalib::~AliTOFcalib()
305{
340693af 306 //TOF Calibration Class dtor
5eaae242 307 if(!(AliCDBManager::Instance()->GetCacheFlag())){ // CDB objects must NOT be deleted if cache is active!
0a749fa5 308 if (fTOFCalOnline){
0a749fa5 309 delete fTOFCalOnline;
6dc9348d 310 }
7fffa85b 311 if (fTOFCalOnlinePulser){
312 delete fTOFCalOnlinePulser;
313 }
314 if (fTOFCalOnlineNoise){
315 delete fTOFCalOnlineNoise;
316 }
317 if (fTOFCalOnlineHW){
318 delete fTOFCalOnlineHW;
319 }
0a749fa5 320 if (fTOFCalOffline){
0a749fa5 321 delete fTOFCalOffline;
6dc9348d 322 }
17149e6b 323 if (fCal){
324 delete fCal;
325 }
326 if (fStatus){
327 delete fStatus;
328 }
329 if (fConfigMap){
330 delete fConfigMap;
331 }
2bf4d9d6 332 if (fDeltaBCOffset) delete fDeltaBCOffset;
333 if (fCTPLatency) delete fCTPLatency;
334 if (fT0Fill) delete fT0Fill;
f04b3a69 335 if (fRunParams) delete fRunParams;
dad2868f 336 if (fResponseParams) delete fResponseParams;
337 if (fReadoutEfficiency) delete fReadoutEfficiency;
6dc9348d 338 }
0a749fa5 339 if (fTree!=0x0) delete fTree;
296591ad 340 if (fChain!=0x0) delete fChain;
2bf4d9d6 341
6dc9348d 342}
343//_____________________________________________________________________________
0a749fa5 344void AliTOFcalib::CreateCalArrays(){
6dc9348d 345
0a749fa5 346 // creating arrays for online/offline calibration objs
6dc9348d 347
0a749fa5 348 fTOFCalOnline = new TObjArray(fNChannels);
7fffa85b 349 fTOFCalOnlinePulser = new TObjArray(fNChannels);
350 fTOFCalOnlineNoise = new TObjArray(fNChannels);
351 fTOFCalOnlineHW = new TObjArray(fNChannels);
0a749fa5 352 fTOFCalOffline = new TObjArray(fNChannels);
353 fTOFCalOnline->SetOwner();
7fffa85b 354 fTOFCalOnlinePulser->SetOwner();
355 fTOFCalOnlineNoise->SetOwner();
356 fTOFCalOnlineHW->SetOwner();
0a749fa5 357 fTOFCalOffline->SetOwner();
358 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
359 AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline();
7fffa85b 360 AliTOFChannelOnlineStatus * calChOnlineStPulser = new AliTOFChannelOnlineStatus();
361 AliTOFChannelOnlineStatus * calChOnlineStNoise = new AliTOFChannelOnlineStatus();
362 AliTOFChannelOnlineStatus * calChOnlineStHW = new AliTOFChannelOnlineStatus();
0a749fa5 363 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
364 fTOFCalOnline->AddAt(calChOnline,iarray);
7fffa85b 365 fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
366 fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
367 fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
0a749fa5 368 fTOFCalOffline->AddAt(calChOffline,iarray);
6dc9348d 369 }
17149e6b 370 fCal = new AliTOFChannelOnlineArray(fNChannels);
371 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
372}
373//_____________________________________________________________________________
24d1e16e 374void AliTOFcalib::CreateCalObjects(){
375
376 // creating arrays for online/offline calibration objs
377
378 fTOFCalOffline = new TObjArray(fNChannels);
379 fTOFCalOffline->SetOwner();
380 for (Int_t iarray = 0; iarray<fNChannels; iarray++){
381 AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
382 fTOFCalOffline->AddAt(calChOffline,iarray);
383 }
384 fCal = new AliTOFChannelOnlineArray(fNChannels);
385 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
386}
387//_____________________________________________________________________________
a6e0ebfe 388void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
17149e6b 389{
390 //Write calibration parameters to the CDB
391 SetFirstRun(minrun);
392 SetLastRun(maxrun);
393 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 394 const Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
955f2093 395 TString out(Form("%s/%s",sel,sel1));
17149e6b 396 AliDebug(2,Form("Writing TOF configuration map for online calib on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
397 AliCDBId id(out,fFirstRun,fLastRun);
398 AliCDBMetaData *md = new AliCDBMetaData();
399 md->SetResponsible("Chiara Zampolli");
400 if (!fConfigMap) {
401 // deve uscire!!
402 }
403 man->Put(fConfigMap,id,md);
404 delete md;
405}
406//_____________________________________________________________________________
407
a6e0ebfe 408void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel)
17149e6b 409{
410 //Write calibration parameters to the CDB with infinite validity
411 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 412 const Char_t *sel1 = "Config" ; // to be consistent with TOFPreprocessor
955f2093 413 TString out(Form("%s/%s",sel,sel1));
17149e6b 414 AliCDBRunRange runrange(fFirstRun,fLastRun);
415 AliDebug(2,Form("Writing TOF config map for online calib on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
416 AliCDBId id(out,runrange);
417 AliCDBMetaData *md = new AliCDBMetaData();
418 md->SetResponsible("Chiara Zampolli");
419 if (!fConfigMap) {
420 // deve uscire!!
421 }
422 man->Put(fConfigMap,id,md);
423 delete md;
424}
425//_____________________________________________________________________________
a6e0ebfe 426void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
17149e6b 427{
428 //Write calibration parameters to the CDB -------> new calib objs!!!!!
429 SetFirstRun(minrun);
430 SetLastRun(maxrun);
431 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 432 const Char_t *sel1 = "ParOnlineDelay" ; // to be consistent with TOFPreprocessor
955f2093 433 TString out(Form("%s/%s",sel,sel1));
17149e6b 434 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
435 AliCDBId id(out,fFirstRun,fLastRun);
436 AliCDBMetaData *md = new AliCDBMetaData();
437 md->SetResponsible("Chiara Zampolli");
438 if (!fCal) {
439 // deve uscire!!
440 }
441 man->Put(fCal,id,md);
442 delete md;
443}
444//_____________________________________________________________________________
a6e0ebfe 445void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
17149e6b 446{
447 //Write calibration parameters to the CDB -------> new calib objs!!!!!
448 SetFirstRun(minrun);
449 SetLastRun(maxrun);
450 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 451 const Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
955f2093 452 TString out(Form("%s/%s",sel,sel1));
17149e6b 453 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
454 AliCDBId id(out,fFirstRun,fLastRun);
455 AliCDBMetaData *md = new AliCDBMetaData();
456 md->SetResponsible("Chiara Zampolli");
457 if (!fStatus) {
458 // deve uscire!!
459 }
460 man->Put(fStatus,id,md);
461 delete md;
462}
463//_____________________________________________________________________________
464
a6e0ebfe 465void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel)
17149e6b 466{
467 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
468 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 469 const Char_t *sel1 = "ParOnlineDelay" ; // to be consistent with TOFPreprocessor
955f2093 470 TString out(Form("%s/%s",sel,sel1));
17149e6b 471 AliCDBRunRange runrange(fFirstRun,fLastRun);
472 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
473 AliCDBId id(out,runrange);
474 AliCDBMetaData *md = new AliCDBMetaData();
475 md->SetResponsible("Chiara Zampolli");
476 if (!fCal) {
477 // deve uscire!!
478 }
479 man->Put(fCal,id,md);
480 delete md;
481}
482//_____________________________________________________________________________
483
a6e0ebfe 484void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel)
17149e6b 485{
486 //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
487 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 488 const Char_t *sel1 = "Status" ; // to be consistent with TOFPreprocessor
955f2093 489 TString out(Form("%s/%s",sel,sel1));
17149e6b 490 AliCDBRunRange runrange(fFirstRun,fLastRun);
491 AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
492 AliCDBId id(out,runrange);
493 AliCDBMetaData *md = new AliCDBMetaData();
494 md->SetResponsible("Chiara Zampolli");
495 if (!fStatus) {
496 // deve uscire!!
497 }
498 man->Put(fStatus,id,md);
499 delete md;
6dc9348d 500}
501//_____________________________________________________________________________
a6e0ebfe 502void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
340693af 503{
504 //Write calibration parameters to the CDB
0cb9d099 505 SetFirstRun(minrun);
506 SetLastRun(maxrun);
6dc9348d 507 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 508 const Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
955f2093 509 TString out(Form("%s/%s",sel,sel1));
0cb9d099 510 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
511 AliCDBId id(out,fFirstRun,fLastRun);
512 AliCDBMetaData *md = new AliCDBMetaData();
513 md->SetResponsible("Chiara Zampolli");
514 if (!fTOFCalOnline) {
515 // deve uscire!!
516 }
517 man->Put(fTOFCalOnline,id,md);
518 delete md;
519}
520//_____________________________________________________________________________
a6e0ebfe 521void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
7fffa85b 522{
523 //Write calibration parameters from pulser to the CDB
524 SetFirstRun(minrun);
525 SetLastRun(maxrun);
526 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 527 const Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
955f2093 528 TString out(Form("%s/%s",sel,sel1));
7fffa85b 529 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
530 AliCDBId id(out,fFirstRun,fLastRun);
531 AliCDBMetaData *md = new AliCDBMetaData();
532 md->SetResponsible("Chiara Zampolli");
533 if (!fTOFCalOnlinePulser) {
534 // deve uscire!!
535 }
536 man->Put(fTOFCalOnlinePulser,id,md);
537 delete md;
538}
539//_____________________________________________________________________________
a6e0ebfe 540void AliTOFcalib::WriteParOnlineNoiseOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
7fffa85b 541{
542 //Write calibration parameters from noise to the CDB
543 SetFirstRun(minrun);
544 SetLastRun(maxrun);
545 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 546 const Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
955f2093 547 TString out(Form("%s/%s",sel,sel1));
7fffa85b 548 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
549 AliCDBId id(out,fFirstRun,fLastRun);
550 AliCDBMetaData *md = new AliCDBMetaData();
551 md->SetResponsible("Chiara Zampolli");
552 if (!fTOFCalOnlineNoise) {
553 // deve uscire!!
554 }
555 man->Put(fTOFCalOnlineNoise,id,md);
556 delete md;
557}
558//_____________________________________________________________________________
a6e0ebfe 559void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
7fffa85b 560{
561 //Write calibration parameters from hardware to the CDB
562 SetFirstRun(minrun);
563 SetLastRun(maxrun);
564 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 565 const Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
955f2093 566 TString out(Form("%s/%s",sel,sel1));
7fffa85b 567 AliDebug(2,Form("Writing TOF online calib obj from hardware on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
568 AliCDBId id(out,fFirstRun,fLastRun);
569 AliCDBMetaData *md = new AliCDBMetaData();
570 md->SetResponsible("Chiara Zampolli");
571 if (!fTOFCalOnlineHW) {
572 // deve uscire!!
573 }
574 man->Put(fTOFCalOnlineHW,id,md);
575 delete md;
576}
577//_____________________________________________________________________________
0cb9d099 578
a6e0ebfe 579void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel)
0cb9d099 580{
581 //Write calibration parameters to the CDB with infinite validity
582 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 583 const Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor
955f2093 584 TString out(Form("%s/%s",sel,sel1));
0cb9d099 585 AliCDBRunRange runrange(fFirstRun,fLastRun);
586 AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
587 AliCDBId id(out,runrange);
6dc9348d 588 AliCDBMetaData *md = new AliCDBMetaData();
d4ad0d6b 589 md->SetResponsible("Chiara Zampolli");
0a749fa5 590 if (!fTOFCalOnline) {
591 // deve uscire!!
85fc78e3 592 }
0a749fa5 593 man->Put(fTOFCalOnline,id,md);
5eaae242 594 delete md;
6dc9348d 595}
596//_____________________________________________________________________________
597
a6e0ebfe 598void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel)
7fffa85b 599{
600 //Write calibration parameters from pulser to the CDB with infinite validity
601 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 602 const Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor
955f2093 603 TString out(Form("%s/%s",sel,sel1));
7fffa85b 604 AliCDBRunRange runrange(fFirstRun,fLastRun);
605 AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
606 AliCDBId id(out,runrange);
607 AliCDBMetaData *md = new AliCDBMetaData();
608 md->SetResponsible("Chiara Zampolli");
609 if (!fTOFCalOnlinePulser) {
610 // deve uscire!!
611 }
612 man->Put(fTOFCalOnlinePulser,id,md);
613 delete md;
614}
615//_____________________________________________________________________________
616
a6e0ebfe 617void AliTOFcalib::WriteParOnlineNoiseOnCDB(const Char_t *sel)
7fffa85b 618{
619 //Write calibration parameters from noise to the CDB with infinite validity
620 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 621 const Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor
955f2093 622 TString out(Form("%s/%s",sel,sel1));
7fffa85b 623 AliCDBRunRange runrange(fFirstRun,fLastRun);
624 AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
625 AliCDBId id(out,runrange);
626 AliCDBMetaData *md = new AliCDBMetaData();
627 md->SetResponsible("Chiara Zampolli");
628 if (!fTOFCalOnlineNoise) {
629 // deve uscire!!
630 }
631 man->Put(fTOFCalOnlineNoise,id,md);
632 delete md;
633}
634//_____________________________________________________________________________
635
a6e0ebfe 636void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel)
7fffa85b 637{
638 //Write calibration parameters from hardware to the CDB with infinite validity
639 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 640 const Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor
955f2093 641 TString out(Form("%s/%s",sel,sel1));
7fffa85b 642 AliCDBRunRange runrange(fFirstRun,fLastRun);
643 AliDebug(2,Form("Writing TOF online calib obj from harware on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
644 AliCDBId id(out,runrange);
645 AliCDBMetaData *md = new AliCDBMetaData();
646 md->SetResponsible("Chiara Zampolli");
647 if (!fTOFCalOnlineHW) {
648 // deve uscire!!
649 }
650 man->Put(fTOFCalOnlineHW,id,md);
651 delete md;
652}
653//_____________________________________________________________________________
654
a6e0ebfe 655void AliTOFcalib::WriteParOfflineOnCDB(const Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun)
0a749fa5 656{
340693af 657 //Write calibration parameters to the CDB
0cb9d099 658 SetFirstRun(minrun);
659 SetLastRun(maxrun);
6dc9348d 660 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 661 const Char_t *sel1 = "ParOffline" ;
955f2093 662 TString out(Form("%s/%s",sel,sel1));
0cb9d099 663 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
664 AliCDBId id(out,fFirstRun,fLastRun);
665 AliCDBMetaData *md = new AliCDBMetaData();
666 md->SetResponsible("Chiara Zampolli");
667 md->SetComment(validity);
668 man->Put(fTOFCalOffline,id,md);
669 delete md;
670}
671//_____________________________________________________________________________
672
a6e0ebfe 673void AliTOFcalib::WriteParOfflineOnCDB(const Char_t *sel, const Char_t *validity)
0cb9d099 674{
675 //Write calibration parameters to the CDB with infinite validity
676 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 677 const Char_t *sel1 = "ParOffline" ;
955f2093 678 TString out(Form("%s/%s",sel,sel1));
0cb9d099 679 AliCDBRunRange runrange(fFirstRun,fLastRun);
680 AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
681 AliCDBId id(out,runrange);
d4ad0d6b 682 AliCDBMetaData *md = new AliCDBMetaData();
683 md->SetResponsible("Chiara Zampolli");
0a749fa5 684 md->SetComment(validity);
685 man->Put(fTOFCalOffline,id,md);
5eaae242 686 delete md;
d4ad0d6b 687}
688//_____________________________________________________________________________
689
a6e0ebfe 690Bool_t AliTOFcalib::ReadConfigMapFromCDB(const Char_t *sel, Int_t nrun)
17149e6b 691{
692 //Read calibration parameters from the CDB
693 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 694 const Char_t *sel1 = "Config" ;
955f2093 695 TString out(Form("%s/%s",sel,sel1));
17149e6b 696 AliCDBEntry *entry = man->Get(out,nrun);
697 if (!entry) {
698 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
699 exit(0);
700 }
701 if(!entry->GetObject()){
702 AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
703 exit(0);
704 }
705
706 fConfigMap =(TMap*)entry->GetObject();
707
708 return kTRUE;
709
710}
711//_____________________________________________________________________________
712
a6e0ebfe 713Bool_t AliTOFcalib::ReadParOnlineDelayFromCDB(const Char_t *sel, Int_t nrun)
17149e6b 714{
715 //Read calibration parameters from the CDB -------> new calib objs!!!!!
716 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 717 const Char_t *sel1 = "ParOnlineDelay" ;
955f2093 718 TString out(Form("%s/%s",sel,sel1));
17149e6b 719 AliCDBEntry *entry = man->Get(out,nrun);
720 if (!entry) {
721 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
722 exit(0);
723 }
724 if(!entry->GetObject()){
725 AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
726 exit(0);
727 }
728
729 fCal =(AliTOFChannelOnlineArray*)entry->GetObject();
730
731 return kTRUE;
732
733}
734//_____________________________________________________________________________
735
a6e0ebfe 736Bool_t AliTOFcalib::ReadParOnlineStatusFromCDB(const Char_t *sel, Int_t nrun)
17149e6b 737{
738 //Read calibration parameters from the CDB -------> new calib objs!!!!!
739 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 740 const Char_t *sel1 = "Status" ;
955f2093 741 TString out(Form("%s/%s",sel,sel1));
17149e6b 742 AliCDBEntry *entry = man->Get(out,nrun);
743 if (!entry) {
744 AliFatal("Exiting, no CDB object (Status) found!!!");
745 exit(0);
746 }
747 if(!entry->GetObject()){
748 AliFatal("Exiting, no CDB object (Status) found!!!");
749 exit(0);
750 }
751
752 fStatus =(AliTOFChannelOnlineStatusArray*)entry->GetObject();
753
754 return kTRUE;
755
756}
757//_____________________________________________________________________________
758
a6e0ebfe 759Bool_t AliTOFcalib::ReadParOnlineFromCDB(const Char_t *sel, Int_t nrun)
340693af 760{
761 //Read calibration parameters from the CDB
d4ad0d6b 762 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 763 const Char_t *sel1 = "ParOnline" ;
955f2093 764 TString out(Form("%s/%s",sel,sel1));
7a4f634e 765 AliCDBEntry *entry = man->Get(out,nrun);
c30c0a38 766 if (!entry) {
767 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
768 exit(0);
769 }
7a4f634e 770 if(!entry->GetObject()){
c30c0a38 771 AliFatal("Exiting, no CDB object (ParOnline) found!!!");
772 exit(0);
7a4f634e 773 }
774
0a749fa5 775 fTOFCalOnline =(TObjArray*)entry->GetObject();
7fffa85b 776
777 return kTRUE;
778
779}
780//_____________________________________________________________________________
781
a6e0ebfe 782Bool_t AliTOFcalib::ReadParOnlinePulserFromCDB(const Char_t *sel, Int_t nrun)
7fffa85b 783{
784 //Read calibration parameters from pulser from the CDB
785 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 786 const Char_t *sel1 = "Pulser" ;
955f2093 787 TString out(Form("%s/%s",sel,sel1));
7fffa85b 788 AliCDBEntry *entry = man->Get(out,nrun);
c30c0a38 789 if (!entry) {
790 AliFatal("Exiting, no CDB object (Pulser) found!!!");
791 exit(0);
792 }
7fffa85b 793 if(!entry->GetObject()){
c30c0a38 794 AliFatal("Exiting, no CDB object (Pulser) found!!!");
795 exit(0);
7fffa85b 796 }
797
798 fTOFCalOnlinePulser =(TObjArray*)entry->GetObject();
799
800 return kTRUE;
801
802}
803//_____________________________________________________________________________
804
a6e0ebfe 805Bool_t AliTOFcalib::ReadParOnlineNoiseFromCDB(const Char_t *sel, Int_t nrun)
7fffa85b 806{
807 //Read calibration parameters from noise from the CDB
808 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 809 const Char_t *sel1 = "Noise" ;
955f2093 810 TString out(Form("%s/%s",sel,sel1));
7fffa85b 811 AliCDBEntry *entry = man->Get(out,nrun);
c30c0a38 812 if (!entry) {
813 AliFatal("Exiting, no CDB object (Noise) found!!!");
814 exit(0);
815 }
7fffa85b 816 if(!entry->GetObject()){
c30c0a38 817 AliFatal("Exiting, no CDB object (Noise) found!!!");
818 exit(0);
7fffa85b 819 }
820
821 fTOFCalOnlineNoise =(TObjArray*)entry->GetObject();
822
823 return kTRUE;
824
825}
826//_____________________________________________________________________________
827
a6e0ebfe 828Bool_t AliTOFcalib::ReadParOnlineHWFromCDB(const Char_t *sel, Int_t nrun)
7fffa85b 829{
830 //Read calibration parameters from hardware from the CDB
831 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 832 const Char_t *sel1 = "HW" ;
955f2093 833 TString out(Form("%s/%s",sel,sel1));
7fffa85b 834 AliCDBEntry *entry = man->Get(out,nrun);
c30c0a38 835 if (!entry) {
836 AliFatal("Exiting, no CDB object (HW map) found!!!");
837 exit(0);
838 }
7fffa85b 839 if(!entry->GetObject()){
c30c0a38 840 AliFatal("Exiting, no CDB object (HW map) found!!!");
841 exit(0);
7fffa85b 842 }
843
844 fTOFCalOnlineHW =(TObjArray*)entry->GetObject();
0a749fa5 845
1b20c168 846 return kTRUE;
7a4f634e 847
6dc9348d 848}
849//_____________________________________________________________________________
d4ad0d6b 850
a6e0ebfe 851Bool_t AliTOFcalib::ReadParOfflineFromCDB(const Char_t *sel, Int_t nrun)
0a749fa5 852{
853 //Read calibration parameters from the CDB
854 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 855 const Char_t *sel1 = "ParOffline" ;
955f2093 856 TString out(Form("%s/%s",sel,sel1));
0a749fa5 857 AliCDBEntry *entry = man->Get(out,nrun);
c30c0a38 858 if (!entry) {
859 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
860 exit(0);
861 }
0a749fa5 862 if(!entry->GetObject()){
c30c0a38 863 AliFatal("Exiting, no CDB object (ParOffline) found!!!");
864 exit(0);
0a749fa5 865 }
866 AliCDBMetaData * md = entry->GetMetaData();
867 fkValidity = md->GetComment();
868 fTOFCalOffline =(TObjArray*)entry->GetObject();
d4ad0d6b 869
0a749fa5 870 return kTRUE;
871
872}
873//_____________________________________________________________________________
a6e0ebfe 874void AliTOFcalib::WriteSimHistoOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, TH1F *histo){
340693af 875 //Write Sim miscalibration parameters to the CDB
d4ad0d6b 876
d4ad0d6b 877 fTOFSimToT=histo;
d4ad0d6b 878 AliCDBManager *man = AliCDBManager::Instance();
a6e0ebfe 879 const Char_t *sel1 = "SimHisto" ;
955f2093 880 TString out(Form("%s/%s",sel,sel1));
0a749fa5 881 AliCDBMetaData *mdhisto = new AliCDBMetaData();
882 mdhisto->SetResponsible("Chiara Zampolli");
40212801 883 AliCDBId id(out,minrun,maxrun);
884 man->Put(fTOFSimToT,id,mdhisto);
0a749fa5 885 delete mdhisto;
886}
887//_____________________________________________________________________________
a6e0ebfe 888Bool_t AliTOFcalib::ReadSimHistoFromCDB(const Char_t *sel, Int_t nrun)
0a749fa5 889{
890 //Read miscalibration parameters from the CDB
891 AliCDBManager *man = AliCDBManager::Instance();
892
40212801 893 // The Tot Histo
7a4f634e 894
a6e0ebfe 895 const Char_t *sel1 = "SimHisto" ;
955f2093 896 TString out(Form("%s/%s",sel,sel1));
c30c0a38 897 AliCDBEntry *entry = man->Get(out,nrun);
898 if (!entry) {
7a4f634e 899 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
900 exit(0);
901 }
40212801 902 if(!entry->GetObject()){
7a4f634e 903 AliFatal("Exiting, no CDB object (SimHisto) found!!!");
904 exit(0);
905 }
40212801 906 TH1F *histo =(TH1F*)entry->GetObject();
d4ad0d6b 907 fTOFSimToT=histo;
52be7fb0 908 return kTRUE;
d4ad0d6b 909}
7037bd93 910//_____________________________________________________________________________
a6e0ebfe 911void AliTOFcalib::WriteRecParOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){
7037bd93 912 //Write reconstruction parameters to the CDB
913
914 AliCDBManager *man = AliCDBManager::Instance();
7037bd93 915 AliCDBMetaData *md = new AliCDBMetaData();
916 md->SetResponsible("Silvia Arcelli");
641168d2 917 const Char_t *sel1 = "RecoParam" ;
955f2093 918 TString out(Form("%s/%s",sel,sel1));
7037bd93 919 AliCDBId id(out,minrun,maxrun);
f858b00e 920
921 TObjArray *arr=new TObjArray(1);
922 arr->AddLast(param);
923 man->Put(arr,id,md);
924 //man->Put(param,id,md);
925 delete md;
926}
927//_____________________________________________________________________________
928void AliTOFcalib::WriteRecParOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, TObjArray *arr){
929 //Write reconstruction parameters to the CDB
930
931 AliCDBManager *man = AliCDBManager::Instance();
932 AliCDBMetaData *md = new AliCDBMetaData();
933 md->SetResponsible("Silvia Arcelli");
934 const Char_t *sel1 = "RecoParam" ;
935 TString out(Form("%s/%s",sel,sel1));
936 AliCDBId id(out,minrun,maxrun);
937 man->Put(arr,id,md);
7037bd93 938 delete md;
939}
940//_____________________________________________________________________________
d6888ae2 941AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(const Char_t *sel, Int_t nrun, Int_t eventType)
7037bd93 942{
943 //Read reconstruction parameters from the CDB
944 AliCDBManager *man = AliCDBManager::Instance();
641168d2 945 const Char_t *sel1 = "RecoParam" ;
955f2093 946 TString out(Form("%s/%s",sel,sel1));
c30c0a38 947 AliCDBEntry *entry = man->Get(out,nrun);
948 if (!entry) {
641168d2 949 AliFatal("Exiting, no CDB object (RecoParam) found!!!");
7a4f634e 950 exit(0);
951 }
7a4f634e 952 if(!entry->GetObject()){
641168d2 953 AliFatal("Exiting, no CDB object (RecoParam) found!!!");
7a4f634e 954 exit(0);
955 }
956
d6888ae2 957 TObjArray *array = (TObjArray*)entry->GetObject();
958 AliTOFRecoParam *param=0x0;
959 if (eventType>=0 || eventType<array->GetEntries())
960 param=(AliTOFRecoParam*)array->At(eventType);
7037bd93 961 return param;
d6888ae2 962
7037bd93 963}
0a749fa5 964//-----------------------------------------------------------------------------
965// Calibration methods
966//-----------------------------------------------------------------------------
967void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
968
969 // creating the chain with the trees for calibration
970 // collecting them from reference data
971 // from minrun to maxrun
972
973 Float_t p[CHENTRIESSMALL];
974 Int_t nentries;
975 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
976 fTree->Branch("nentries",&nentries,"nentries/I");
977 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
978 AliCDBManager *man = AliCDBManager::Instance();
162637e4 979 AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT/OCDB");
0a749fa5 980 for (Int_t irun = minrun;irun<=maxrun;irun++){
981 AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
982 if (!entry){
983 AliInfo(Form("No entry found for run %i",irun));
984 }
985 else{
af6e05be 986 TTree *tree = (TTree*)entry->GetObject();
0a749fa5 987 tree->SetBranchAddress("nentries",&nentries);
988 tree->SetBranchAddress("TOFentries",p);
989 fTree->CopyEntries(tree);
0a749fa5 990 fNruns++;
991 }
992 }
993 AliInfo(Form("Number of runs being analyzed %i",fNruns));
994}
995//-----------------------------------------------------------------------------
996void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
997
998 // creating the chain with the trees for calibration
999 // collecting them from the Grid
1000 // from minrun to maxrun
1001
1002 Float_t p[CHENTRIESSMALL];
1003 Int_t nentries;
1004 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
1005 fTree->SetDirectory(0);
1006 fTree->Branch("nentries",&nentries,"nentries/I");
1007 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
1008 AliInfo("connected to alien");
1009 TGrid::Connect("alien://");
1010
955f2093 1011 TString filename;
0a749fa5 1012 for (Int_t irun = minrun;irun<=maxrun;irun++){
955f2093 1013 filename = Form("alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
1014 TFile *filegrid = TFile::Open(filename.Data(),"READ");
0a749fa5 1015 TTree *tree = (TTree*)filegrid->Get("T");
1016 tree->SetBranchAddress("nentries",&nentries);
1017 tree->SetBranchAddress("TOFentries",p);
1018 fTree->CopyEntries(tree);
1019 delete tree;
1020 fNruns++;
1021 }
1022
1023 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1024}
1025//-----------------------------------------------------------------------------
1026void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
1027
1028 // creating the tree with the trees for calibration
1029 // collecting them from reference data (from file)
1030 // from minrun to maxrun
1031
1032 Float_t p[CHENTRIESSMALL];
1033 Int_t nentries;
1034 fTree = new TTree("TOFCalib","Tree for TOF Calibration");
1035 fTree->SetDirectory(0);
1036 fTree->Branch("nentries",&nentries,"nentries/I");
1037 fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
955f2093 1038 TString filename;
0a749fa5 1039 for (Int_t irun = minrun;irun<=maxrun;irun++){
955f2093 1040 filename = Form("$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
1041 TFile *file = new TFile(filename.Data(),"READ");
0a749fa5 1042 TTree *tree = (TTree*)file->Get("T");
1043 tree->SetBranchAddress("nentries",&nentries);
1044 tree->SetBranchAddress("TOFentries",p);
1045 fTree->CopyEntries(tree);
1046 delete tree;
1047 delete file;
1048 file = 0x0;
1049 fNruns++;
1050 }
1051
1052 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1053}
1054//-----------------------------------------------------------------------------
296591ad 1055void AliTOFcalib::CreateChainFromGrid(Int_t minrun, Int_t maxrun){
1056
1057 // creating the chain with the trees for calibration
1058 // collecting them from the Grid
1059 // from minrun to maxrun
1060
1061 fChain = new TChain("T");
1062 AliInfo("connected to alien");
1063 TGrid::Connect("alien://");
1064
955f2093 1065 TString filename;
296591ad 1066 for (Int_t irun = minrun;irun<=maxrun;irun++){
955f2093 1067 filename = Form("alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
1068 fChain->Add(filename.Data());
296591ad 1069 fNruns++;
1070 }
1071
1072 AliInfo(Form("Number of runs being analyzed %i",fNruns));
1073}
1074//-----------------------------------------------------------------------------
0a749fa5 1075Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
7037bd93 1076
0a749fa5 1077 // calibrating summing more than one channels
1078 // computing calibration parameters
1079 // Returning codes:
1080 // 0 -> everything was ok
1081 // 1 -> no tree for calibration found
1082 // 2 -> not enough statistics to perform calibration
1083 // 3 -> problems with arrays
1084
1085 TH1::AddDirectory(0);
1086
1087 AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ;
1088 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1089 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1090
1091 Float_t p[CHENTRIESSMALL];
1092 Int_t nentries;
296591ad 1093 //fTree->SetBranchAddress("nentries",&nentries);
1094 //fTree->SetBranchAddress("TOFentries",p);
1095 fChain->SetBranchAddress("nentries",&nentries);
1096 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1097
1098 Float_t ntracksTotalmean =0;
1099 for (Int_t i=ichmin; i<ichmax; i++){
1100 Int_t ientry = -1;
1101 for (Int_t irun=0;irun<fNruns;irun++){
1102 ientry = i+irun*fNChannels;
296591ad 1103 //fTree->GetEntry(ientry);
1104 fChain->GetEntry(ientry);
0a749fa5 1105 Int_t ntracksRun=nentries/3;
1106 ntracksTotalmean+=ntracksRun;
1107 }
1108 }
1109
1110 if (ntracksTotalmean < MEANENTRIES) {
1111 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1112 return 2;
1113 }
1114
1115 //filling ToT and Time arrays
1116
1117 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1118 Float_t minToT = 0; // ns
1119 Float_t maxToT = 4.88; // ns
1120
1121 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1122 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1123 Int_t ntracksTotal = 0;
1124 Int_t ntracksRun = 0;
1125 Double_t binsProfile[101]; // sized larger than necessary, the correct
1126 // dim being set in the booking of the profile
1127 Int_t nusefulbins=0;
1128 Float_t meantime=0;
1129 for (Int_t i = ichmin;i<ichmax;i++){
1130 Int_t ientry = -1;
1131 for (Int_t irun=0;irun<fNruns;irun++){
1132 ientry = i+irun*fNChannels;
296591ad 1133 //fTree->GetEntry(ientry);
1134 fChain->GetEntry(ientry);
0a749fa5 1135 ntracksTotal+=nentries/3;
1136 ntracksRun=nentries/3;
1137 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun));
1138 for (Int_t j=0;j<ntracksRun;j++){
1139 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1140 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1141 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1142 Float_t tot = p[idxexToT];
1143 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1144 meantime+=p[idxexTime]-p[idxexExTime];
1145 hToT->Fill(tot);
1146 }
1147 }
1148 }
1149 nusefulbins = FindBins(hToT,&binsProfile[0]);
1150 meantime/=ntracksTotal;
1151 AliDebug(2, Form("meantime = %f",meantime));
1152
1153 for (Int_t j=1;j<=nusefulbins;j++) {
1154 AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j]));
1155 }
1156
1157 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1158 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1159
1160 for (Int_t irun=0;irun<fNruns;irun++){
1161 Int_t ientry = -1;
1162 for (Int_t i=ichmin; i<ichmax; i++){
1163 ientry = i+irun*fNChannels;
296591ad 1164 //fTree->GetEntry(ientry);
1165 fChain->GetEntry(ientry);
0a749fa5 1166 ntracksRun=nentries/3;
1167 for (Int_t j=0;j<ntracksRun;j++){
1168 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1169 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1170 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1171 Float_t tot = p[idxexToT];
1172 Float_t time = p[idxexTime]-p[idxexExTime];
1173 AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1174 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1175 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1176 }
1177 }
1178 }
1179
1180 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1181 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1182 Float_t par[6];
1183 for(Int_t kk=0;kk<6;kk++){
1184 par[kk]=calibfunc->GetParameter(kk);
1185 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1186 }
1187
1188 if(strstr(optionSave,"save")){
1189 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1190 fileProf->cd();
1191 TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
1192 TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
1193 TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
1194 TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
1195 hSlewingProf->Write(profName);
1196 htimetot->Write(timeTotName);
1197 hToT->Write(totName);
1198 hdeltaTime->Write(deltaName);
1199 fileProf->Close();
1200 delete fileProf;
1201 fileProf=0x0;
1202 }
1203
1204 delete hToT;
1205 hToT=0x0;
1206 delete hSlewingProf;
1207 hSlewingProf=0x0;
1208 delete htimetot;
1209 htimetot=0x0;
1210 delete hdeltaTime;
1211 hdeltaTime=0x0;
1212
1213 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin);
1214 calChannel->SetSlewPar(par);
0cb9d099 1215 WriteParOfflineOnCDB("TOF/Calib","valid");
0a749fa5 1216 return 0;
1217}
1218//----------------------------------------------------------------------------
1219Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
1220
1221 // computing calibration parameters for channel i
1222 // Returning codes:
1223 // 0 -> everything was ok
1224 // 1 -> no tree for calibration found
1225 // 2 -> not enough statistics to perform calibration
1226 // 3 -> problems with arrays
1227
1228 TH1::AddDirectory(0);
1229
1230 AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ;
1231 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1232 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1233
1234 Float_t p[MAXCHENTRIESSMALL];
1235 Int_t nentries;
296591ad 1236 //fTree->SetBranchAddress("nentries",&nentries);
1237 //fTree->SetBranchAddress("TOFentries",p);
1238 fChain->SetBranchAddress("nentries",&nentries);
1239 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1240
1241 Float_t ntracksTotal =0;
1242 for (Int_t irun=0;irun<fNruns;irun++){
1243 Int_t ientry = -1;
1244 ientry = i+irun*fNChannels;
296591ad 1245 //fTree->GetEntry(ientry);
1246 fChain->GetEntry(ientry);
0a749fa5 1247 ntracksTotal+=nentries/3;
1248 }
1249
1250 if (ntracksTotal < MEANENTRIES) {
1251 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
1252 return 2;
1253 }
1254
1255 //filling ToT and Time arrays
1256
1257 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1258 Float_t minToT = 0; // ns
1259 Float_t maxToT = 4.88; // ns
1260
1261 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1262 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1263 Int_t ntracksRun = 0;
1264 Double_t binsProfile[101]; // sized larger than necessary, the correct
1265 // dim being set in the booking of the profile
1266 Int_t nusefulbins=0;
1267 Float_t meantime=0;
1268 for (Int_t irun=0;irun<fNruns;irun++){
1269 Int_t ientry = -1;
1270 ientry = i+irun*fNChannels;
296591ad 1271 //fTree->GetEntry(ientry);
1272 fChain->GetEntry(ientry);
0a749fa5 1273 ntracksRun=nentries/3;
1274 AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun));
1275 for (Int_t j=0;j<ntracksRun;j++){
1276 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1277 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1278 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1279 Float_t tot = p[idxexToT];
1280 meantime+=p[idxexTime]-p[idxexExTime];
1281 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1282 hToT->Fill(tot);
1283 }
1284 }
1285
1286 nusefulbins = FindBins(hToT,&binsProfile[0]);
1287 meantime/=ntracksTotal;
1288 AliDebug(2,Form("meantime = %f",meantime));
1289
1290 for (Int_t j=1;j<=nusefulbins;j++) {
1291 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1292 }
1293
1294 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1295 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1296 for (Int_t irun=0;irun<fNruns;irun++){
1297 Int_t ientry = -1;
1298 ientry = i+irun*fNChannels;
296591ad 1299 //fTree->GetEntry(ientry);
1300 fChain->GetEntry(ientry);
0a749fa5 1301 ntracksRun=nentries/3;
1302 for (Int_t j=0;j<ntracksRun;j++){
1303 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1304 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1305 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1306 Float_t tot = p[idxexToT];
1307 Float_t time = p[idxexTime]-p[idxexExTime];
1308 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1309 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1310 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1311 }
1312 }
1313
1314 hSlewingProf->Fit("pol5",optionFit,"",0,4);
1315 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1316 Float_t par[6];
1317 for(Int_t kk=0;kk<6;kk++){
1318 par[kk]=calibfunc->GetParameter(kk);
1319 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1320 }
1321
1322
1323 if(strstr(optionSave,"save")){
1324 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1325 fileProf->cd();
1326 TString profName=Form("Profile%06i",i);
1327 TString timeTotName=Form("TimeTot%06i",i);
1328 TString totName=Form("Tot%06i",i);
1329 TString deltaName=Form("Delta%06i",i);
1330 hSlewingProf->Write(profName);
1331 htimetot->Write(timeTotName);
1332 hToT->Write(totName);
1333 hdeltaTime->Write(deltaName);
1334 fileProf->Close();
1335 delete fileProf;
1336 fileProf=0x0;
1337 }
1338
1339 delete hToT;
1340 hToT=0x0;
1341 delete hSlewingProf;
1342 hSlewingProf=0x0;
1343 delete htimetot;
1344 htimetot=0x0;
1345 delete hdeltaTime;
1346 hdeltaTime=0x0;
1347
1348 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1349 calChannel->SetSlewPar(par);
0cb9d099 1350 WriteParOfflineOnCDB("TOF/Calib","valid");
0a749fa5 1351 return 0;
1352}
1353//----------------------------------------------------------------------------
1354Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
1355
1356 // calibrating an array of channels
1357 // computing calibration parameters
1358 // Returning codes:
1359 // 0 -> everything was ok
1360 // 1 -> no tree for calibration found
1361 // 2 -> not enough statistics to perform calibration
1362 // 3 -> problems with arrays
1363
1364 TH1::AddDirectory(0);
1365
1366 AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ;
1367 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1368 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1369 for (Int_t ich=0; ich<nch; ich++){
1370 Int_t i = ch[ich];
1371 AliInfo(Form("Calibrating channel = %i",i )) ;
1372 }
1373 Float_t p[MAXCHENTRIESSMALL];
1374 Int_t nentries;
296591ad 1375 //fTree->SetBranchAddress("nentries",&nentries);
1376 //fTree->SetBranchAddress("TOFentries",p);
1377 fChain->SetBranchAddress("nentries",&nentries);
1378 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1379
1380 Float_t ntracksTotalmean =0;
1381 for (Int_t ich=0; ich<nch; ich++){
1382 Int_t ientry = -1;
1383 Int_t i = ch[ich];
1384 for (Int_t irun=0;irun<fNruns;irun++){
1385 ientry = i+irun*fNChannels;
296591ad 1386 //fTree->GetEntry(ientry);
1387 fChain->GetEntry(ientry);
0a749fa5 1388 ntracksTotalmean+=nentries/3;
1389 }
1390 }
1391
1392 ntracksTotalmean/=nch;
1393 if (ntracksTotalmean < MEANENTRIES) {
1394 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1395 return 2;
1396 }
1397
1398 //filling ToT and Time arrays
1399
1400 Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps
1401 Float_t minToT = 0; // ns
1402 Float_t maxToT = 4.88; // ns
1403 TFile * fileProf=0x0;
1404 if(strstr(optionSave,"save")){
1405 fileProf = new TFile("TOFCalibSave.root","recreate");
1406 }
1407 for (Int_t ich=0; ich<nch; ich++) {
1408 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1409 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1410 Double_t binsProfile[101]; // sized larger than necessary, the correct
1411 // dim being set in the booking of the profile
1412 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1413 Int_t ntracksTotal = 0;
1414 Int_t ntracksRun = 0;
1415 Int_t nusefulbins=0;
1416 Float_t meantime=0;
1417 Int_t i=-1;
1418 for (Int_t irun=0;irun<fNruns;irun++){
1419 i = ch[ich]+irun*fNChannels;
1420 AliDebug(2,Form("Calibrating channel %i",i));
296591ad 1421 //fTree->GetEntry(i);
1422 fChain->GetEntry(i);
0a749fa5 1423 ntracksTotal+=nentries/3;
1424 }
1425 if (ntracksTotal < MEANENTRIES) {
4682c56e 1426 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",i,ntracksTotal));
0a749fa5 1427 continue;
1428 }
1429
1430 for (Int_t irun=0;irun<fNruns;irun++){
3c609b5c 1431 i = ch[ich]+irun*fNChannels;
296591ad 1432 //fTree->GetEntry(i);
1433 fChain->GetEntry(i);
0a749fa5 1434 ntracksRun=nentries/3;
1435 for (Int_t j=0;j<ntracksRun;j++){
1436 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1437 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1438 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1439 Float_t tot = p[idxexToT];
1440 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1441 meantime+=p[idxexTime]-p[idxexExTime];
1442 hToT->Fill(tot);
1443 }
1444 }
1445
1446 nusefulbins = FindBins(hToT,&binsProfile[0]);
1447 meantime/=ntracksTotal;
1448 for (Int_t j=1;j<=nusefulbins;j++) {
1449 AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j]));
1450 }
1451
1452 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1453 for (Int_t irun=0;irun<fNruns;irun++){
3c609b5c 1454 i = ch[ich]+irun*fNChannels;
296591ad 1455 //fTree->GetEntry(i);
1456 fChain->GetEntry(i);
0a749fa5 1457 ntracksRun=nentries/3;
1458 for (Int_t j=0;j<ntracksRun;j++){
1459 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1460 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1461 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1462 Float_t tot = p[idxexToT];
1463 Float_t time = p[idxexTime]-p[idxexExTime];
1464 AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1465 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1466 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1467 }
1468 }
1469
1470 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1471 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1472 Float_t par[6];
1473 for(Int_t kk=0;kk<6;kk++){
1474 par[kk]=calibfunc->GetParameter(kk);
1475 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1476 }
1477
1478 if(strstr(optionSave,"save") && fileProf){
1479 TString profName=Form("Profile%06i",i);
1480 TString timeTotName=Form("TimeTot%06i",i);
1481 TString totName=Form("Tot%06i",i);
1482 TString deltaName=Form("Delta%06i",i);
1483 fileProf->cd();
1484 hSlewingProf->Write(profName);
1485 htimetot->Write(timeTotName);
1486 hToT->Write(totName);
1487 hdeltaTime->Write(deltaName);
1488 }
1489
1490 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
1491 calChannel->SetSlewPar(par);
1492 delete hToT;
1493 hToT=0x0;
1494 delete hSlewingProf;
1495 hSlewingProf=0x0;
1496 delete htimetot;
1497 htimetot=0x0;
1498 delete hdeltaTime;
1499 hdeltaTime=0x0;
1500 }
1501
1502 if(strstr(optionSave,"save") && fileProf){
1503 fileProf->Close();
1504 delete fileProf;
1505 fileProf=0x0;
1506 }
0cb9d099 1507 WriteParOfflineOnCDB("TOF/Calib","valid");
0a749fa5 1508
1509 return 0;
1510}
1511//----------------------------------------------------------------------------
1512Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){
1513
1514 // computing calibration parameters using the old profiling algo
1515 // Returning codes:
1516 // 0 -> everything was ok
1517 // 1 -> no tree for calibration found
1518 // 2 -> not enough statistics to perform calibration
1519 // 3 -> problems with arrays
1520
1521 TH1::AddDirectory(0);
1522
1523 AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ;
1524 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1525 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1526 Float_t p[MAXCHENTRIESSMALL];
1527 Int_t nentries;
1528 Int_t ntracksTotal=0;
296591ad 1529 //fTree->SetBranchAddress("nentries",&nentries);
1530 //fTree->SetBranchAddress("TOFentries",p);
1531 fChain->SetBranchAddress("nentries",&nentries);
1532 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1533
1534 for (Int_t irun=0;irun<fNruns;irun++){
1535 Int_t i = ich+irun*fNChannels;
296591ad 1536 //fTree->GetEntry(i);
1537 fChain->GetEntry(i);
0a749fa5 1538 ntracksTotal+=nentries/3;
1539 }
1540
1541 if (ntracksTotal < MEANENTRIES) {
4682c56e 1542 AliInfo(Form(" Too small mean number of entires per channel (mean number = %d) not calibrating and exiting.....",ntracksTotal));
0a749fa5 1543 return 2;
1544 }
1545
af6e05be 1546 TH1F * hProf = Profile(ich);
0a749fa5 1547 hProf->Fit("pol5",optionFit,"",0,4);
1548 TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
1549 Float_t par[6];
1550 for(Int_t kk=0;kk<6;kk++){
1551 par[kk]=calibfunc->GetParameter(kk);
1552 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1553 }
1554
1555 if(strstr(optionSave,"save")){
1556 TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
1557 fileProf->cd();
1558 TString profName=Form("Profile%06i",ich);
1559 hProf->Write(profName);
1560 fileProf->Close();
1561 delete fileProf;
1562 fileProf=0x0;
1563 }
1564
1565 delete hProf;
1566 hProf=0x0;
1567 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich);
1568 calChannel->SetSlewPar(par);
0cb9d099 1569 WriteParOfflineOnCDB("TOF/Calib","valid");
0a749fa5 1570 return 0;
1571}
1572//----------------------------------------------------------------------------
1573Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
1574
1575 // calibrating the whole TOF
1576 // computing calibration parameters
1577 // Returning codes:
1578 // 0 -> everything was ok
1579 // 1 -> no tree for calibration found
1580 // 2 -> not enough statistics to perform calibration
1581 // 3 -> problems with arrays
1582
1583 TH1::AddDirectory(0);
1584
1585 AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ;
1586 AliInfo(Form("Option for Saving histos = %s",optionSave )) ;
1587 AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ;
1588
1589 TFile * fileProf=0x0;
1590 if(strstr(optionSave,"save")){
1591 fileProf = new TFile("TOFCalibSave.root","recreate");
1592 }
1593
1594 Float_t p[MAXCHENTRIESSMALL];
1595 Int_t nentries;
296591ad 1596 //fTree->SetBranchAddress("nentries",&nentries);
1597 //fTree->SetBranchAddress("TOFentries",p);
1598 fChain->SetBranchAddress("nentries",&nentries);
1599 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1600
1601 Float_t ntracksTotalmean =0;
1602 for (Int_t ii=0; ii<fNChannels; ii++){
1603 for (Int_t irun=0;irun<fNruns;irun++){
1604 Int_t i = ii+irun*fNChannels;
296591ad 1605 //fTree->GetEntry(i);
1606 fChain->GetEntry(i);
0a749fa5 1607 ntracksTotalmean+=nentries/3;
1608 }
1609 }
1610
1611 ntracksTotalmean/=fNChannels;
1612 if (ntracksTotalmean < MEANENTRIES) {
1613 AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
1614 return 2;
1615 }
1616
1617 //filling ToT and Time arrays
1618
1619 Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps
1620 Float_t minToT = 0; // ns
1621 Float_t maxToT = 4.88;// ns
1622 for (Int_t ii=0; ii<fNChannels; ii++) {
1623 TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
1624 TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
1625 TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
1626 if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
1627 //Int_t i = 3;
1628 Int_t nusefulbins=0;
1629 Double_t binsProfile[101]; // sized larger than necessary, the correct
1630 // dim being set in the booking of the profile
1631 Int_t ntracksRun = 0;
1632 Int_t ntracksTotal = 0;
1633 for (Int_t irun=0;irun<fNruns;irun++){
1634 Int_t i = ii+irun*fNChannels;
296591ad 1635 //fTree->GetEntry(i);
1636 fChain->GetEntry(i);
0a749fa5 1637 ntracksTotal+=nentries/3;
1638 }
1639 if (ntracksTotal < MEANENTRIES) {
4682c56e 1640 AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",ii,ntracksTotal));
0a749fa5 1641 continue;
1642 }
1643 Float_t meantime=0;
1644 for (Int_t irun=0;irun<fNruns;irun++){
1645 Int_t i = ii+irun*fNChannels;
296591ad 1646 //fTree->GetEntry(i);
1647 fChain->GetEntry(i);
0a749fa5 1648 ntracksRun=nentries/3;
1649 for (Int_t j=0;j<ntracksRun;j++){
1650 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1651 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1652 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1653 Float_t tot = p[idxexToT];
1654 hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
1655 meantime+=p[idxexTime]-p[idxexExTime];
1656 hToT->Fill(tot);
1657 }
1658 }
1659 nusefulbins = FindBins(hToT,&binsProfile[0]);
1660 meantime/=ntracksTotal;
1661 for (Int_t j=0;j<nusefulbins;j++) {
1662 AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j]));
1663 }
1664 TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!!
1665 for (Int_t irun=0;irun<fNruns;irun++){
1666 Int_t i = ii+irun*fNChannels;
296591ad 1667 //fTree->GetEntry(i);
1668 fChain->GetEntry(i);
0a749fa5 1669 ntracksRun=nentries/3;
1670 for (Int_t j=0;j<ntracksRun;j++){
1671 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1672 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1673 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1674 Float_t tot = p[idxexToT];
1675 Float_t time = p[idxexTime]-p[idxexExTime];
1676 AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
1677 hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above
1678 htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above
1679 }
1680 }
1681 hSlewingProf->Fit("pol5",optionFit,"",1,4);
1682 TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
1683 Float_t par[6];
1684 for(Int_t kk=0;kk<6;kk++){
1685 par[kk]=calibfunc->GetParameter(kk);
1686 AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
1687 }
1688
1689 if(strstr(optionSave,"save") && fileProf){
1690 TString profName=Form("Profile%06i",ii);
1691 TString timeTotName=Form("TimeTot%06i",ii);
1692 TString totName=Form("Tot%06i",ii);
1693 TString deltaName=Form("Delta%06i",ii);
1694 fileProf->cd();
1695 hSlewingProf->Write(profName);
1696 htimetot->Write(timeTotName);
1697 hToT->Write(totName);
1698 hdeltaTime->Write(deltaName);
1699 }
1700 AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii);
1701 calChannel->SetSlewPar(par);
1702
1703 delete hToT;
1704 hToT=0x0;
1705 delete hSlewingProf;
1706 hSlewingProf=0x0;
1707 delete htimetot;
1708 htimetot=0x0;
1709 delete hdeltaTime;
1710 hdeltaTime=0x0;
1711 }
1712
1713 if(strstr(optionSave,"save")){
1714 fileProf->Close();
1715 delete fileProf;
1716 fileProf=0x0;
1717 }
0cb9d099 1718 WriteParOfflineOnCDB("TOF/Calib","valid");
0a749fa5 1719 return 0;
1720}
1721
1722//-----------------------------------------------------------------------
1723TH1F* AliTOFcalib::Profile(Int_t ich)
340693af 1724{
0a749fa5 1725 // profiling algo
1726
1727 Float_t p[MAXCHENTRIESSMALL];
1728 Int_t nentries;
296591ad 1729 //fTree->SetBranchAddress("nentries",&nentries);
1730 //fTree->SetBranchAddress("TOFentries",p);
1731 fChain->SetBranchAddress("nentries",&nentries);
1732 fChain->SetBranchAddress("TOFentries",p);
0a749fa5 1733
1734 //Prepare histograms for Slewing Correction
1735 const Int_t knbinToT = 100;
1736 Int_t nbinTime = 200;
1737 Float_t minTime = -5.5; //ns
1738 Float_t maxTime = 5.5; //ns
1739 Float_t minToT = 0; //ns
1740 Float_t maxToT = 5.; //ns
1741 Float_t deltaToT = (maxToT-minToT)/knbinToT;
1742 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];
1743 Int_t n[knbinToT+1], nentrx[knbinToT+1];
1744 Double_t sigmaToT[knbinToT+1];
1745 for (Int_t i = 0; i < knbinToT+1 ; i++){
1746 mTime[i]=0;
1747 mToT[i]=0;
1748 n[i]=0;
1749 meanTime[i]=0;
1750 meanTime2[i]=0;
1751 vToT[i]=0;
1752 vToT2[i]=0;
1753 meanToT[i]=0;
1754 meanToT2[i]=0;
1755 vTime[i]=0;
1756 vTime2[i]=0;
1757 xlow[i]=0;
1758 sigmaTime[i]=0;
1759 sigmaToT[i]=0;
1760 n[i]=0;
1761 nentrx[i]=0;
1762 }
1763 TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
1764 Int_t ntracksRun = 0;
1765 TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
1766 for (Int_t irun=0;irun<fNruns;irun++){
1767 Int_t i = ich+irun*fNChannels;
296591ad 1768 //fTree->GetEntry(i);
1769 fChain->GetEntry(i);
0a749fa5 1770 ntracksRun=nentries/3;
1771 for (Int_t j=0;j<ntracksRun;j++){
1772 Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT;
1773 Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME;
1774 Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID;
1775 Float_t tot = p[idxexToT];
1776 Float_t time = p[idxexTime]-p[idxexExTime];
1777 Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
1778 if ((tot != 0) && ( time!= 0)){
1779 vTime[nx]+=time;
1780 vTime2[nx]+=time*time;
1781 vToT[nx]+=tot;
1782 vToT2[nx]+=tot*tot;
1783 nentrx[nx]++;
1784 hSlewing->Fill(tot,time);
1785 }
1786 }
1787 }
1788 Int_t nbinsToT=hSlewing->GetNbinsX();
1789 if (nbinsToT != knbinToT) {
1790 AliError("Profile :: incompatible numbers of bins");
1791 return 0x0;
1792 }
1793
1794 Int_t usefulBins=0;
1795 for (Int_t i=1;i<=nbinsToT;i++){
1796 if (nentrx[i]!=0){
1797 n[usefulBins]+=nentrx[i];
1798 if (n[usefulBins]==0 && i == nbinsToT) {
1799 break;
1800 }
1801 meanTime[usefulBins]+=vTime[i];
1802 meanTime2[usefulBins]+=vTime2[i];
1803 meanToT[usefulBins]+=vToT[i];
1804 meanToT2[usefulBins]+=vToT2[i];
1805 if (n[usefulBins]<10 && i!=nbinsToT) continue;
1806 mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
1807 mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
1808 sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1809 *(meanTime2[usefulBins]-meanTime[usefulBins]
1810 *meanTime[usefulBins]/n[usefulBins]));
1811 if ((1./n[usefulBins]/n[usefulBins]
1812 *(meanToT2[usefulBins]-meanToT[usefulBins]
1813 *meanToT[usefulBins]/n[usefulBins]))< 0) {
1814 AliError(" too small radical" );
1815 sigmaToT[usefulBins]=0;
1816 }
1817 else{
1818 sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
1819 *(meanToT2[usefulBins]-meanToT[usefulBins]
1820 *meanToT[usefulBins]/n[usefulBins]));
1821 }
1822 usefulBins++;
1823 }
1824 }
1825 for (Int_t i=0;i<usefulBins;i++){
1826 Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
1827 histo->Fill(mToT[i],mTime[i]);
1828 histo->SetBinError(binN,sigmaTime[i]);
1829 }
1830 delete hSlewing;
1831 hSlewing=0x0;
1832
1833 return histo;
6dc9348d 1834}
0a749fa5 1835//----------------------------------------------------------------------------
1836Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
6dc9348d 1837
0a749fa5 1838 // to determine the bins for ToT histo
1839
1840 Int_t cont = 0;
1841 Int_t startBin = 1;
1842 Int_t nbin = h->GetNbinsX();
1843 Int_t nentries = (Int_t)h->GetEntries();
1844 Float_t max = h->GetBinLowEdge(nbin);
1845 Int_t nusefulbins=0;
1846 Int_t maxcont=0;
1847 // setting maxvalue of entries per bin
1848 if (nentries <= 60) maxcont = 2;
1849 else if (nentries <= 100) maxcont = 5;
1850 else if (nentries <= 500) maxcont = 10;
1851 else maxcont = 20;
1852 for (Int_t j=1;j<=nbin;j++) {
1853 cont += (Int_t)h->GetBinContent(j);
1854 if (j<nbin){
1855 if (cont>=maxcont){
1856 nusefulbins++;
1857 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1858 cont=0;
1859 startBin=j+1;
1860 continue;
1861 }
1862 }
1863 else{
1864 if (cont>=maxcont){
1865 nusefulbins++;
1866 binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
1867 binsProfile[nusefulbins]=max;
1868 }
1869 else {
1870 binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);
1871 }
1872 }
1873 }
1874 return nusefulbins;
1875}
2bf4d9d6 1876
1877
1878//----------------------------------------------------------------------------
1879
1880void
1881AliTOFcalib::CreateDeltaBCOffset()
1882{
1883 /*
1884 * create deltaBC offset
1885 */
1886
1887 if (fDeltaBCOffset) {
1888 AliWarning("DeltaBCOffset object already defined, cannot create a new one");
1889 return;
1890 }
1891 fDeltaBCOffset = new AliTOFDeltaBCOffset();
1892}
1893
1894//----------------------------------------------------------------------------
1895
1896void
1897AliTOFcalib::CreateCTPLatency()
1898{
1899 /*
1900 * create CTP latency
1901 */
1902
1903 if (fCTPLatency) {
1904 AliWarning("CTPLatency object already defined, cannot create a new one");
1905 return;
1906 }
1907 fCTPLatency = new AliTOFCTPLatency();
1908}
1909
1910//----------------------------------------------------------------------------
1911
1912void
1913AliTOFcalib::CreateT0Fill()
1914{
1915 /*
1916 * create event-time
1917 */
1918
1919 if (fT0Fill) {
1920 AliWarning("T0Fill object already defined, cannot create a new one");
1921 return;
1922 }
1923 fT0Fill = new AliTOFT0Fill();
1924}
1925
1926//----------------------------------------------------------------------------
1927
f04b3a69 1928void
1929AliTOFcalib::CreateRunParams()
1930{
1931 /*
1932 * create run params
1933 */
1934
1935 if (fRunParams) {
1936 AliWarning("RunParams object already defined, cannot create a new one");
1937 return;
1938 }
1939 fRunParams = new AliTOFRunParams();
1940}
1941
1942//----------------------------------------------------------------------------
1943
2bf4d9d6 1944void
1945AliTOFcalib::WriteDeltaBCOffsetOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1946{
1947 /*
1948 * deltaBC offset on CDB
1949 */
1950
1951 if (!fDeltaBCOffset) return;
1952 AliCDBId id(Form("%s/DeltaBCOffset", sel), minrun, maxrun);
1953 AliCDBMetaData *md = new AliCDBMetaData();
1954 md->SetResponsible("Roberto Preghenella");
1955 AliCDBManager *man = AliCDBManager::Instance();
1956 man->Put(fDeltaBCOffset, id, md);
1957 AliDebug(2,Form("DeltaBCOffset written on CDB with run range [%i, %i] ",minrun ,maxrun));
1958 delete md;
1959}
1960
1961//----------------------------------------------------------------------------
1962
1963void
1964AliTOFcalib::WriteCTPLatencyOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1965{
1966 /*
1967 * write CTP latency on CDB
1968 */
1969
1970 if (!fCTPLatency) return;
1971 AliCDBId id(Form("%s/CTPLatency", sel), minrun, maxrun);
1972 AliCDBMetaData *md = new AliCDBMetaData();
1973 md->SetResponsible("Roberto Preghenella");
1974 AliCDBManager *man = AliCDBManager::Instance();
1975 man->Put(fCTPLatency, id, md);
1976 AliDebug(2,Form("CTPLatency written on CDB with run range [%i, %i] ",minrun ,maxrun));
1977 delete md;
1978}
1979
1980//----------------------------------------------------------------------------
1981
1982void
1983AliTOFcalib::WriteT0FillOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
1984{
1985 /*
1986 * write event-time on CDB
1987 */
1988
1989 if (!fT0Fill) return;
1990 AliCDBId id(Form("%s/T0Fill", sel), minrun, maxrun);
1991 AliCDBMetaData *md = new AliCDBMetaData();
1992 md->SetResponsible("Roberto Preghenella");
1993 AliCDBManager *man = AliCDBManager::Instance();
1994 man->Put(fT0Fill, id, md);
1995 AliDebug(2,Form("T0Fill written on CDB with run range [%i, %i] ",minrun ,maxrun));
1996 delete md;
1997}
1998
1999//----------------------------------------------------------------------------
2000
f04b3a69 2001void
2002AliTOFcalib::WriteRunParamsOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
2003{
2004 /*
2005 * write run params on CDB
2006 */
2007
2008 if (!fRunParams) return;
2009 AliCDBId id(Form("%s/RunParams", sel), minrun, maxrun);
2010 AliCDBMetaData *md = new AliCDBMetaData();
2011 md->SetResponsible("Roberto Preghenella");
2012 AliCDBManager *man = AliCDBManager::Instance();
2013 man->Put(fRunParams, id, md);
2014 AliDebug(2,Form("RunParams written on CDB with run range [%i, %i] ",minrun ,maxrun));
2015 delete md;
2016}
2017
2018//----------------------------------------------------------------------------
2019
dad2868f 2020void
2021AliTOFcalib::WriteReadoutEfficiencyOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
2022{
2023 /*
2024 * write readout efficiency on CDB
2025 */
2026
2027 if (!fReadoutEfficiency) return;
2028 AliCDBId id(Form("%s/ReadoutEfficiency", sel), minrun, maxrun);
2029 AliCDBMetaData *md = new AliCDBMetaData();
2030 md->SetResponsible("Roberto Preghenella");
2031 AliCDBManager *man = AliCDBManager::Instance();
2032 man->Put(fReadoutEfficiency, id, md);
2033 AliDebug(2,Form("ReadoutEfficiency written on CDB with run range [%i, %i] ",minrun ,maxrun));
2034 delete md;
2035}
2036
2037//----------------------------------------------------------------------------
2038
2bf4d9d6 2039Bool_t
2040AliTOFcalib::ReadDeltaBCOffsetFromCDB(const Char_t *sel , Int_t nrun)
2041{
2042 /*
2043 * read deltaBC offset from CDB
2044 */
2045
2046 AliCDBManager *man = AliCDBManager::Instance();
2047 AliCDBEntry *entry = man->Get(Form("%s/DeltaBCOffset", sel),nrun);
2048 if (!entry) {
2049 AliFatal("No DeltaBCOffset entry found in CDB");
2050 exit(0);
2051 }
2052 fDeltaBCOffset =(AliTOFDeltaBCOffset *)entry->GetObject();
2053 if(!fDeltaBCOffset){
2054 AliFatal("No DeltaBCOffset object found in CDB entry");
2055 exit(0);
2056 }
2057 return kTRUE;
2058}
2059
2060//----------------------------------------------------------------------------
2061
2062Bool_t
2063AliTOFcalib::ReadCTPLatencyFromCDB(const Char_t *sel , Int_t nrun)
2064{
2065 /*
2066 * read CTP latency from CDB
2067 */
2068
2069 AliCDBManager *man = AliCDBManager::Instance();
2070 AliCDBEntry *entry = man->Get(Form("%s/CTPLatency", sel),nrun);
2071 if (!entry) {
2072 AliFatal("No CTPLatency entry found in CDB");
2073 exit(0);
2074 }
2075 fCTPLatency =(AliTOFCTPLatency *)entry->GetObject();
2076 if(!fCTPLatency){
2077 AliFatal("No CTPLatency object found in CDB entry");
2078 exit(0);
2079 }
2080 return kTRUE;
2081}
2082
2083//----------------------------------------------------------------------------
2084
2085Bool_t
2086AliTOFcalib::ReadT0FillFromCDB(const Char_t *sel , Int_t nrun)
2087{
2088 /*
2089 * read event-time from CDB
2090 */
2091
2092 AliCDBManager *man = AliCDBManager::Instance();
2093 AliCDBEntry *entry = man->Get(Form("%s/T0Fill", sel),nrun);
2094 if (!entry) {
2095 AliFatal("No T0Fill entry found in CDB");
2096 exit(0);
2097 }
2098 fT0Fill =(AliTOFT0Fill *)entry->GetObject();
2099 if(!fT0Fill){
2100 AliFatal("No T0Fill object found in CDB entry");
2101 exit(0);
2102 }
2103 return kTRUE;
2104}
2105
f04b3a69 2106//----------------------------------------------------------------------------
2107
2108Bool_t
2109AliTOFcalib::ReadRunParamsFromCDB(const Char_t *sel , Int_t nrun)
2110{
2111 /*
2112 * read run params from CDB
2113 */
2114
2115 AliCDBManager *man = AliCDBManager::Instance();
2116 AliCDBEntry *entry = man->Get(Form("%s/RunParams", sel),nrun);
2117 if (!entry) {
2118 AliFatal("No RunParams entry found in CDB");
2119 exit(0);
2120 }
2121 fRunParams =(AliTOFRunParams *)entry->GetObject();
2122 if(!fRunParams){
2123 AliFatal("No RunParams object found in CDB entry");
2124 exit(0);
2125 }
2126 return kTRUE;
2127}
2128
5b4ed716 2129//----------------------------------------------------------------------------
2130
dad2868f 2131Bool_t
2132AliTOFcalib::ReadReadoutEfficiencyFromCDB(const Char_t *sel , Int_t nrun)
2133{
2134 /*
2135 * read readout efficiency from CDB
2136 */
2137
2138 AliCDBManager *man = AliCDBManager::Instance();
2139 AliCDBEntry *entry = man->Get(Form("%s/ReadoutEfficiency", sel),nrun);
2140 if (!entry) {
2141 AliFatal("No ReadoutEfficiency entry found in CDB");
2142 exit(0);
2143 }
2144 fReadoutEfficiency = (TH1F *)entry->GetObject();
2145 if(!fReadoutEfficiency){
2146 AliFatal("No ReadoutEfficiency object found in CDB entry");
2147 exit(0);
2148 }
2149 return kTRUE;
2150}
2151
2152//----------------------------------------------------------------------------
2153
5b4ed716 2154Bool_t
2155AliTOFcalib::Init(Int_t run)
2156{
2157 /*
2158 * init
2159 */
2160
2161 if (fInitFlag) {
2162 AliWarning("the class was already initialized, re-initialize it");
2163 fInitFlag = kFALSE;
2164 }
2165
2166 /* read channel status array */
2167 if (!ReadParOnlineStatusFromCDB("TOF/Calib", run)) {
2168 AliError("cannot get \"Status\" object from OCDB");
2169 return kFALSE;
2170 }
2171 /* get par offline array */
2172 if (!ReadParOfflineFromCDB("TOF/Calib", run)) {
2173 AliError("cannot get \"ParOffline\" object from OCDB");
2174 return kFALSE;
2175 }
2176 /* get deltaBC offset obj */
2177 if (!ReadDeltaBCOffsetFromCDB("TOF/Calib", run)) {
2178 AliError("cannot get \"DeltaBCOffset\" object from OCDB");
2179 return kFALSE;
2180 }
2181 /* get CTP latency obj */
2182 if (!ReadCTPLatencyFromCDB("TOF/Calib", run)) {
2183 AliError("cannot get \"CTPLatency\" object from OCDB");
2184 return kFALSE;
2185 }
2186 /* get run params obj */
2187 if (!ReadRunParamsFromCDB("TOF/Calib", run)) {
2188 AliError("cannot get \"RunParams\" object from OCDB");
2189 return kFALSE;
2190 }
dad2868f 2191 /* get readout efficiency obj */
2192 if (!ReadReadoutEfficiencyFromCDB("TOF/Calib", run)) {
2193 AliError("cannot get \"ReadoutEfficiency\" object from OCDB");
2194 return kFALSE;
2195 }
5b4ed716 2196 /* get response params */
c2fb5b09 2197 TFile *responseFile = TFile::Open("$ALICE_ROOT/TOF/data/AliTOFresponsePar.root");
2198 if (!responseFile || !responseFile->IsOpen()) {
2199 AliError("cannot open \"ResponseParams\" local file");
2200 return kFALSE;
2201 }
2202 fResponseParams = (AliTOFResponseParams *)responseFile->Get("ResponseParams");
2203 if (!fResponseParams) {
2204 AliError("cannot get \"ResponseParams\" object from local file");
2205 return kFALSE;
5b4ed716 2206 }
c2fb5b09 2207 responseFile->Close();
5b4ed716 2208
2209 /* all done */
2210 fInitFlag = kTRUE;
2211 return kTRUE;
2212
2213}
2214
2215//----------------------------------------------------------------------------
2216
2217Double_t
2218AliTOFcalib::GetTimeCorrection(Int_t index, Double_t tot, Int_t deltaBC, Int_t l0l1, UInt_t timestamp)
2219{
2220 /*
2221 * get time correction
2222 */
2223
2224 if (!fInitFlag) {
2225 AliError("class not yet initialized. Initialize it before.");
2226 return 0.;
2227 }
2228
2229 /* get calibration params */
2230 AliTOFChannelOffline *parOffline = (AliTOFChannelOffline *)fTOFCalOffline->At(index);
2231 Int_t deltaBCOffset = fDeltaBCOffset->GetDeltaBCOffset();
2232 Float_t ctpLatency = fCTPLatency->GetCTPLatency();
2233 Float_t tdcLatencyWindow = fStatus->GetLatencyWindow(index) * 1.e3;
2234 Float_t timezero = fRunParams->EvalT0(timestamp);
2235 /* check whether to remove mean T0.
2236 * useful when one wants to compute mean T0 */
2237 if (!fRemoveMeanT0) timezero = 0.;
2238
2239 /* compute correction */
2240 Double_t corr = 0.;
2241 /* deltaBC correction */
2242 deltaBC = deltaBCOffset; /* inhibit deltaBC correction for the time being */
2243 corr += (deltaBC - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth();
2244 /* L0-L1 latency correction */
2245 corr -= l0l1 * AliTOFGeometry::BunchCrossingBinWidth();
2246 /* CTP latency correction */
2247 corr -= ctpLatency;
2248 /* TDC latency window correction */
2249 corr += tdcLatencyWindow;
2250 /* time-zero correction */
2251 corr += timezero;
2252 /* time calibration correction */
2253 if (tot < AliTOFGeometry::SlewTOTMin())
2254 tot = AliTOFGeometry::SlewTOTMin();
2255 if (tot > AliTOFGeometry::SlewTOTMax())
2256 tot = AliTOFGeometry::SlewTOTMax();
2257 for (Int_t islew = 0; islew < 6; islew++)
2258 corr += parOffline->GetSlewPar(islew) * TMath::Power(tot, islew) * 1.e3;
2259
2260 /* return correction */
2261 return corr;
2262}
2263
2264//----------------------------------------------------------------------------
2265
2266void
2267AliTOFcalib::CalibrateESD(AliESDEvent *event)
2268{
2269 /*
2270 * calibrate ESD
2271 */
2272
2273 if (!fInitFlag) {
2274 AliError("class not yet initialized. Initialize it before.");
2275 return;
2276 }
2277
2278 /* loop over tracks */
2279 AliESDtrack *track = NULL;
2280 Int_t index, l0l1, deltaBC;
2281 Double_t time, tot, corr, texp[AliPID::kSPECIES];
2282 UInt_t timestamp = event->GetTimeStamp();
2283 for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
2284
2285 /* get track */
2286 track = event->GetTrack(itrk);
2287 if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) continue;
8bb89c94 2288
2289 /* calibrate TOF signal */
2290 if (fCalibrateTOFsignal) {
2291 /* get info */
2292 index = track->GetTOFCalChannel();
2293 time = track->GetTOFsignalRaw();
2294 tot = track->GetTOFsignalToT();
2295 l0l1 = track->GetTOFL0L1();
2296 deltaBC = track->GetTOFDeltaBC();
2297 /* get correction */
2298 corr = GetTimeCorrection(index, tot, deltaBC, l0l1, timestamp);
2299 /* apply correction */
2300 time -= corr;
2301 /* set new TOF signal */
2302 track->SetTOFsignal(time);
2303 }
5b4ed716 2304
2305 /* correct expected time */
2306 if (fCorrectTExp) {
2307 /* get integrated times */
2308 track->GetIntegratedTimes(texp);
2309 /* loop over particle types and correct expected time */
2310 for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++)
2311 texp[ipart] += fResponseParams->EvalTExpCorr(ipart, track->P());
2312 /* set integrated times */
2313 track->SetIntegratedTimes(texp);
2314 }
2315
2316 }
2317
2318}
2319
2320//----------------------------------------------------------------------------
2321
2322Bool_t
dad2868f 2323AliTOFcalib::IsChannelEnabled(Int_t index, Bool_t checkEfficiency)
5b4ed716 2324{
2325 /*
2326 * is channel enabled
2327 */
2328
2329 if (!fInitFlag) {
2330 AliError("class not yet initialized. Initialize it before.");
2331 return kTRUE;
2332 }
2333
2334 /* check bad status */
2335 if (fStatus->GetPulserStatus(index) == AliTOFChannelOnlineStatusArray::kTOFPulserBad) return kFALSE;
2336 if (fStatus->GetNoiseStatus(index) == AliTOFChannelOnlineStatusArray::kTOFNoiseBad) return kFALSE;
2337 if (fStatus->GetHWStatus(index) == AliTOFChannelOnlineStatusArray::kTOFHWBad) return kFALSE;
dad2868f 2338 if (checkEfficiency && !IsChannelEfficient(index)) return kFALSE;
5b4ed716 2339
2340 /* good status */
2341 return kTRUE;
2342
2343}
c2fb5b09 2344
2345//----------------------------------------------------------------------------
2346
dad2868f 2347Bool_t
2348AliTOFcalib::IsChannelEfficient(Int_t index)
2349{
2350 /*
2351 * is channel efficient
2352 */
2353
2354 if (!fInitFlag) {
2355 AliError("class not yet initialized. Initialize it before.");
2356 return kTRUE;
2357 }
2358
2359 /* check efficiency */
2360 if (fReadoutEfficiency->GetBinContent(index + 1) < 0.95) return kFALSE;
2361 return kTRUE;
2362
2363}
2364
2365//----------------------------------------------------------------------------
2366
c2fb5b09 2367void
2368AliTOFcalib::CalibrateTExp(AliESDEvent *event) const
2369{
2370 /*
2371 * calibrate TExp
2372 */
2373
2374 if (!fInitFlag) {
2375 AliError("class not yet initialized. Initialize it before.");
2376 return;
2377 }
2378
2379 /* loop over tracks */
2380 AliESDtrack *track = NULL;
2381 Double_t texp[AliPID::kSPECIES];
2382 for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
2383
2384 /* get track */
2385 track = event->GetTrack(itrk);
2386 if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) continue;
2387
2388 /* get integrated times */
2389 track->GetIntegratedTimes(texp);
2390 /* loop over particle types and correct expected time */
2391 for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++)
2392 texp[ipart] += fResponseParams->EvalTExpCorr(ipart, track->P());
2393 /* set integrated times */
2394 track->SetIntegratedTimes(texp);
2395
2396 }
2397
2398}
2399
899d8839 2400//----------------------------------------------------------------------------
2401
2402Double_t
2403AliTOFcalib::TuneForMC(AliESDEvent *event, Double_t resolution)
2404{
2405 /*
2406 * tune for MC
2407 */
2408
2409 /* get vertex spread and define T0-spread */
2410 Double_t diamond2 = TMath::Abs(event->GetSigma2DiamondZ());
2411 Double_t t0spread = TMath::Sqrt(diamond2) / 2.99792457999999984e-02;
2412 /* generate random startTime */
2413 Double_t startTime = gRandom->Gaus(0., t0spread);
2414 /* define extra smearing for resolution */
2415 Double_t defaultResolution = 80.;
2416 Double_t extraSmearing = 0.;
2417 if (resolution > defaultResolution)
2418 extraSmearing = TMath::Sqrt(resolution * resolution - defaultResolution * defaultResolution);
2419
2420 /* loop over tracks */
2421 AliESDtrack *track = NULL;
2422 Double_t time;
2423 for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
2424 /* get track */
2425 track = event->GetTrack(itrk);
2426 if (!track) continue;
2427 /* check TOF match */
2428 if (!track->IsOn(AliESDtrack::kTOFout)) continue;
2429 /* check if channel is enabled */
2430 if (!IsChannelEnabled(track->GetTOFCalChannel())) {
2431 /* reset TOF status */
2432 track->ResetStatus(AliESDtrack::kTOFin);
2433 track->ResetStatus(AliESDtrack::kTOFout);
2434 track->ResetStatus(AliESDtrack::kTOFmismatch);
2435 track->ResetStatus(AliESDtrack::kTOFpid);
2436 }
2437 /* get original time and manipulate it */
2438 time = track->GetTOFsignal();
2439 time += startTime; /* add start time */
2440 time += gRandom->Gaus(0., extraSmearing); /* extra smearing */
2441 time -= 25.; /* remove 25 ps to center the signal */
2442 track->SetTOFsignal(time);
2443 }
2444
2445 return startTime;
2446}