]>
Commit | Line | Data |
---|---|---|
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 $ |
18 | Revision 1.21 2007/11/02 15:41:49 hristov | |
19 | Provide return value if the function is not void | |
20 | ||
52be7fb0 | 21 | Revision 1.20 2007/10/26 15:13:50 zampolli |
22 | Using a TChain instead of a TTree | |
23 | ||
296591ad | 24 | Revision 1.19 2007/10/23 15:27:38 zampolli |
25 | Rearrangement of Calibration objects for simulation | |
26 | ||
a7e9db2a | 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. | |
29 | ||
0cb9d099 | 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 | |
32 | ||
0a749fa5 | 33 | Revision 1.14 2007/06/06 16:26:30 arcelli |
34 | remove fall-back call to local CDB storage | |
35 | ||
03705065 | 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 | |
38 | ||
7a4f634e | 39 | Revision 1.12 2007/03/23 11:31:16 arcelli |
40 | CDB Entry for TOF Reconstruction Parameters | |
41 | ||
7037bd93 | 42 | Revision 1.11 2007/02/28 18:08:26 arcelli |
43 | Add protection against failed retrieval of the CDB cal object | |
44 | ||
1b20c168 | 45 | Revision 1.10 2006/08/22 13:30:49 arcelli |
46 | removal of effective c++ warnings (C.Zampolli) | |
47 | ||
655e379f | 48 | Revision 1.9 2006/04/20 22:30:50 hristov |
49 | Coding conventions (Annalisa) | |
50 | ||
0e46b9ae | 51 | Revision 1.8 2006/04/16 22:29:05 hristov |
52 | Coding conventions (Annalisa) | |
53 | ||
7aeeaf38 | 54 | Revision 1.7 2006/04/16 20:12:46 hristov |
55 | Removing memory leak in case of cached CDB entries | |
56 | ||
85fc78e3 | 57 | Revision 1.6 2006/04/11 15:28:32 hristov |
58 | Checks on cache status before deleting calibration objects (A.Colla) | |
59 | ||
5eaae242 | 60 | Revision 1.5 2006/04/05 08:35:38 hristov |
61 | Coding conventions (S.Arcelli, C.Zampolli) | |
62 | ||
340693af | 63 | Revision 1.4 2006/03/31 11:26:46 arcelli |
64 | changing CDB Ids according to standard convention | |
65 | ||
28dd10b6 | 66 | Revision 1.3 2006/03/28 14:57:02 arcelli |
67 | updates to handle new V5 geometry & some re-arrangements | |
68 | ||
d4ad0d6b | 69 | Revision 1.2 2006/02/13 17:22:26 arcelli |
70 | just Fixing Log info | |
71 | ||
762446e0 | 72 | Revision 1.1 2006/02/13 16:10:48 arcelli |
73 | Add classes for TOF Calibration (C.Zampolli) | |
74 | ||
6dc9348d | 75 | author: 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" | |
6dc9348d | 88 | #include "TList.h" |
0e46b9ae | 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" | |
0e46b9ae | 95 | |
96 | #include "AliCDBEntry.h" | |
0cb9d099 | 97 | #include "AliCDBRunRange.h" |
0e46b9ae | 98 | #include "AliCDBId.h" |
6dc9348d | 99 | #include "AliCDBManager.h" |
0a749fa5 | 100 | #include "AliCDBStorage.h" |
6dc9348d | 101 | #include "AliCDBMetaData.h" |
0e46b9ae | 102 | #include "AliESDtrack.h" |
103 | #include "AliESD.h" | |
104 | #include "AliLog.h" | |
105 | ||
0e46b9ae | 106 | #include "AliTOFcalib.h" |
0a749fa5 | 107 | #include "AliTOFChannelOnline.h" |
7fffa85b | 108 | #include "AliTOFChannelOnlineStatus.h" |
0a749fa5 | 109 | #include "AliTOFChannelOffline.h" |
0e46b9ae | 110 | #include "AliTOFGeometry.h" |
7037bd93 | 111 | #include "AliTOFRecoParam.h" |
6dc9348d | 112 | |
113 | extern TROOT *gROOT; | |
114 | extern TStyle *gStyle; | |
115 | ||
116 | ClassImp(AliTOFcalib) | |
117 | ||
6dc9348d | 118 | //_______________________________________________________________________ |
655e379f | 119 | AliTOFcalib::AliTOFcalib(): |
120 | TTask("AliTOFcalib",""), | |
121 | fNChannels(-1), | |
0a749fa5 | 122 | fTOFCalOnline(0x0), |
7fffa85b | 123 | fTOFCalOnlinePulser(0x0), |
124 | fTOFCalOnlineNoise(0x0), | |
125 | fTOFCalOnlineHW(0x0), | |
0a749fa5 | 126 | fTOFCalOffline(0x0), |
0a749fa5 | 127 | fTOFSimToT(0x0), |
128 | fkValidity(0x0), | |
129 | fTree(0x0), | |
296591ad | 130 | fChain(0x0), |
0cb9d099 | 131 | fNruns(0), |
132 | fFirstRun(0), | |
133 | fLastRun(AliCDBRunRange::Infinity()) | |
655e379f | 134 | { |
340693af | 135 | //TOF Calibration Class ctor |
0a749fa5 | 136 | fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX(); |
6dc9348d | 137 | } |
138 | //____________________________________________________________________________ | |
139 | ||
655e379f | 140 | AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib): |
141 | TTask("AliTOFcalib",""), | |
0a749fa5 | 142 | fNChannels(calib.fNChannels), |
143 | fTOFCalOnline(0x0), | |
7fffa85b | 144 | fTOFCalOnlinePulser(0x0), |
145 | fTOFCalOnlineNoise(0x0), | |
146 | fTOFCalOnlineHW(0x0), | |
0a749fa5 | 147 | fTOFCalOffline(0x0), |
0a749fa5 | 148 | fTOFSimToT(calib.fTOFSimToT), |
149 | fkValidity(calib.fkValidity), | |
150 | fTree(calib.fTree), | |
296591ad | 151 | fChain(calib.fChain), |
0cb9d099 | 152 | fNruns(calib.fNruns), |
153 | fFirstRun(calib.fFirstRun), | |
154 | fLastRun(calib.fLastRun) | |
6dc9348d | 155 | { |
340693af | 156 | //TOF Calibration Class copy ctor |
0a749fa5 | 157 | for (Int_t iarray = 0; iarray<fNChannels; iarray++){ |
158 | AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray); | |
7fffa85b | 159 | AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray); |
160 | AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray); | |
161 | AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray); | |
0a749fa5 | 162 | AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray); |
163 | fTOFCalOnline->AddAt(calChOnline,iarray); | |
7fffa85b | 164 | fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray); |
165 | fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray); | |
166 | fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray); | |
0a749fa5 | 167 | fTOFCalOffline->AddAt(calChOffline,iarray); |
168 | ||
0a749fa5 | 169 | } |
6dc9348d | 170 | } |
171 | ||
172 | //____________________________________________________________________________ | |
7aeeaf38 | 173 | |
174 | AliTOFcalib& AliTOFcalib::operator=(const AliTOFcalib &calib) | |
175 | { | |
176 | //TOF Calibration Class assignment operator | |
7aeeaf38 | 177 | this->fNChannels = calib.fNChannels; |
0a749fa5 | 178 | this->fTOFSimToT = calib.fTOFSimToT; |
179 | this->fkValidity = calib.fkValidity; | |
180 | this->fTree = calib.fTree; | |
296591ad | 181 | this->fChain = calib.fChain; |
0a749fa5 | 182 | this->fNruns = calib.fNruns; |
0cb9d099 | 183 | this->fFirstRun = calib.fFirstRun; |
184 | this->fLastRun = calib.fLastRun; | |
0a749fa5 | 185 | for (Int_t iarray = 0; iarray<fNChannels; iarray++){ |
186 | AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray); | |
187 | AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray); | |
7fffa85b | 188 | AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray); |
189 | AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray); | |
190 | AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray); | |
0a749fa5 | 191 | this->fTOFCalOnline->AddAt(calChOnline,iarray); |
7fffa85b | 192 | this->fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray); |
193 | this->fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray); | |
194 | this->fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray); | |
0a749fa5 | 195 | this->fTOFCalOffline->AddAt(calChOffline,iarray); |
0a749fa5 | 196 | } |
7aeeaf38 | 197 | return *this; |
198 | } | |
199 | ||
200 | //____________________________________________________________________________ | |
6dc9348d | 201 | |
202 | AliTOFcalib::~AliTOFcalib() | |
203 | { | |
340693af | 204 | //TOF Calibration Class dtor |
5eaae242 | 205 | if(!(AliCDBManager::Instance()->GetCacheFlag())){ // CDB objects must NOT be deleted if cache is active! |
0a749fa5 | 206 | if (fTOFCalOnline){ |
0a749fa5 | 207 | delete fTOFCalOnline; |
6dc9348d | 208 | } |
7fffa85b | 209 | if (fTOFCalOnlinePulser){ |
210 | delete fTOFCalOnlinePulser; | |
211 | } | |
212 | if (fTOFCalOnlineNoise){ | |
213 | delete fTOFCalOnlineNoise; | |
214 | } | |
215 | if (fTOFCalOnlineHW){ | |
216 | delete fTOFCalOnlineHW; | |
217 | } | |
0a749fa5 | 218 | if (fTOFCalOffline){ |
0a749fa5 | 219 | delete fTOFCalOffline; |
6dc9348d | 220 | } |
6dc9348d | 221 | } |
0a749fa5 | 222 | if (fTree!=0x0) delete fTree; |
296591ad | 223 | if (fChain!=0x0) delete fChain; |
6dc9348d | 224 | } |
225 | //_____________________________________________________________________________ | |
0a749fa5 | 226 | void AliTOFcalib::CreateCalArrays(){ |
6dc9348d | 227 | |
0a749fa5 | 228 | // creating arrays for online/offline calibration objs |
6dc9348d | 229 | |
0a749fa5 | 230 | fTOFCalOnline = new TObjArray(fNChannels); |
7fffa85b | 231 | fTOFCalOnlinePulser = new TObjArray(fNChannels); |
232 | fTOFCalOnlineNoise = new TObjArray(fNChannels); | |
233 | fTOFCalOnlineHW = new TObjArray(fNChannels); | |
0a749fa5 | 234 | fTOFCalOffline = new TObjArray(fNChannels); |
235 | fTOFCalOnline->SetOwner(); | |
7fffa85b | 236 | fTOFCalOnlinePulser->SetOwner(); |
237 | fTOFCalOnlineNoise->SetOwner(); | |
238 | fTOFCalOnlineHW->SetOwner(); | |
0a749fa5 | 239 | fTOFCalOffline->SetOwner(); |
240 | for (Int_t iarray = 0; iarray<fNChannels; iarray++){ | |
241 | AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline(); | |
7fffa85b | 242 | AliTOFChannelOnlineStatus * calChOnlineStPulser = new AliTOFChannelOnlineStatus(); |
243 | AliTOFChannelOnlineStatus * calChOnlineStNoise = new AliTOFChannelOnlineStatus(); | |
244 | AliTOFChannelOnlineStatus * calChOnlineStHW = new AliTOFChannelOnlineStatus(); | |
0a749fa5 | 245 | AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline(); |
246 | fTOFCalOnline->AddAt(calChOnline,iarray); | |
7fffa85b | 247 | fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray); |
248 | fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray); | |
249 | fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray); | |
0a749fa5 | 250 | fTOFCalOffline->AddAt(calChOffline,iarray); |
6dc9348d | 251 | } |
252 | } | |
253 | //_____________________________________________________________________________ | |
0a749fa5 | 254 | void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun) |
340693af | 255 | { |
256 | //Write calibration parameters to the CDB | |
0cb9d099 | 257 | SetFirstRun(minrun); |
258 | SetLastRun(maxrun); | |
6dc9348d | 259 | AliCDBManager *man = AliCDBManager::Instance(); |
a7e9db2a | 260 | Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor |
d4ad0d6b | 261 | Char_t out[100]; |
262 | sprintf(out,"%s/%s",sel,sel1); | |
0cb9d099 | 263 | AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun)); |
264 | AliCDBId id(out,fFirstRun,fLastRun); | |
265 | AliCDBMetaData *md = new AliCDBMetaData(); | |
266 | md->SetResponsible("Chiara Zampolli"); | |
267 | if (!fTOFCalOnline) { | |
268 | // deve uscire!! | |
269 | } | |
270 | man->Put(fTOFCalOnline,id,md); | |
271 | delete md; | |
272 | } | |
273 | //_____________________________________________________________________________ | |
7fffa85b | 274 | void AliTOFcalib::WriteParOnlinePulserOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun) |
275 | { | |
276 | //Write calibration parameters from pulser to the CDB | |
277 | SetFirstRun(minrun); | |
278 | SetLastRun(maxrun); | |
279 | AliCDBManager *man = AliCDBManager::Instance(); | |
280 | Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor | |
281 | Char_t out[100]; | |
282 | sprintf(out,"%s/%s",sel,sel1); | |
283 | AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",fFirstRun,fLastRun)); | |
284 | AliCDBId id(out,fFirstRun,fLastRun); | |
285 | AliCDBMetaData *md = new AliCDBMetaData(); | |
286 | md->SetResponsible("Chiara Zampolli"); | |
287 | if (!fTOFCalOnlinePulser) { | |
288 | // deve uscire!! | |
289 | } | |
290 | man->Put(fTOFCalOnlinePulser,id,md); | |
291 | delete md; | |
292 | } | |
293 | //_____________________________________________________________________________ | |
294 | void AliTOFcalib::WriteParOnlineNoiseOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun) | |
295 | { | |
296 | //Write calibration parameters from noise to the CDB | |
297 | SetFirstRun(minrun); | |
298 | SetLastRun(maxrun); | |
299 | AliCDBManager *man = AliCDBManager::Instance(); | |
300 | Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor | |
301 | Char_t out[100]; | |
302 | sprintf(out,"%s/%s",sel,sel1); | |
303 | AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",fFirstRun,fLastRun)); | |
304 | AliCDBId id(out,fFirstRun,fLastRun); | |
305 | AliCDBMetaData *md = new AliCDBMetaData(); | |
306 | md->SetResponsible("Chiara Zampolli"); | |
307 | if (!fTOFCalOnlineNoise) { | |
308 | // deve uscire!! | |
309 | } | |
310 | man->Put(fTOFCalOnlineNoise,id,md); | |
311 | delete md; | |
312 | } | |
313 | //_____________________________________________________________________________ | |
314 | void AliTOFcalib::WriteParOnlineHWOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun) | |
315 | { | |
316 | //Write calibration parameters from hardware to the CDB | |
317 | SetFirstRun(minrun); | |
318 | SetLastRun(maxrun); | |
319 | AliCDBManager *man = AliCDBManager::Instance(); | |
320 | Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor | |
321 | Char_t out[100]; | |
322 | sprintf(out,"%s/%s",sel,sel1); | |
323 | AliDebug(2,Form("Writing TOF online calib obj from hardware on CDB with run range [%i, %i] ",fFirstRun,fLastRun)); | |
324 | AliCDBId id(out,fFirstRun,fLastRun); | |
325 | AliCDBMetaData *md = new AliCDBMetaData(); | |
326 | md->SetResponsible("Chiara Zampolli"); | |
327 | if (!fTOFCalOnlineHW) { | |
328 | // deve uscire!! | |
329 | } | |
330 | man->Put(fTOFCalOnlineHW,id,md); | |
331 | delete md; | |
332 | } | |
333 | //_____________________________________________________________________________ | |
0cb9d099 | 334 | |
335 | void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel) | |
336 | { | |
337 | //Write calibration parameters to the CDB with infinite validity | |
338 | AliCDBManager *man = AliCDBManager::Instance(); | |
a7e9db2a | 339 | Char_t *sel1 = "ParOnline" ; // to be consistent with TOFPreprocessor |
0cb9d099 | 340 | Char_t out[100]; |
341 | sprintf(out,"%s/%s",sel,sel1); | |
342 | AliCDBRunRange runrange(fFirstRun,fLastRun); | |
343 | AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun())); | |
344 | AliCDBId id(out,runrange); | |
6dc9348d | 345 | AliCDBMetaData *md = new AliCDBMetaData(); |
d4ad0d6b | 346 | md->SetResponsible("Chiara Zampolli"); |
0a749fa5 | 347 | if (!fTOFCalOnline) { |
348 | // deve uscire!! | |
85fc78e3 | 349 | } |
0a749fa5 | 350 | man->Put(fTOFCalOnline,id,md); |
5eaae242 | 351 | delete md; |
6dc9348d | 352 | } |
353 | //_____________________________________________________________________________ | |
354 | ||
7fffa85b | 355 | void AliTOFcalib::WriteParOnlinePulserOnCDB(Char_t *sel) |
356 | { | |
357 | //Write calibration parameters from pulser to the CDB with infinite validity | |
358 | AliCDBManager *man = AliCDBManager::Instance(); | |
359 | Char_t *sel1 = "Pulser" ; // to be consistent with TOFPreprocessor | |
360 | Char_t out[100]; | |
361 | sprintf(out,"%s/%s",sel,sel1); | |
362 | AliCDBRunRange runrange(fFirstRun,fLastRun); | |
363 | AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun())); | |
364 | AliCDBId id(out,runrange); | |
365 | AliCDBMetaData *md = new AliCDBMetaData(); | |
366 | md->SetResponsible("Chiara Zampolli"); | |
367 | if (!fTOFCalOnlinePulser) { | |
368 | // deve uscire!! | |
369 | } | |
370 | man->Put(fTOFCalOnlinePulser,id,md); | |
371 | delete md; | |
372 | } | |
373 | //_____________________________________________________________________________ | |
374 | ||
375 | void AliTOFcalib::WriteParOnlineNoiseOnCDB(Char_t *sel) | |
376 | { | |
377 | //Write calibration parameters from noise to the CDB with infinite validity | |
378 | AliCDBManager *man = AliCDBManager::Instance(); | |
379 | Char_t *sel1 = "Noise" ; // to be consistent with TOFPreprocessor | |
380 | Char_t out[100]; | |
381 | sprintf(out,"%s/%s",sel,sel1); | |
382 | AliCDBRunRange runrange(fFirstRun,fLastRun); | |
383 | AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun())); | |
384 | AliCDBId id(out,runrange); | |
385 | AliCDBMetaData *md = new AliCDBMetaData(); | |
386 | md->SetResponsible("Chiara Zampolli"); | |
387 | if (!fTOFCalOnlineNoise) { | |
388 | // deve uscire!! | |
389 | } | |
390 | man->Put(fTOFCalOnlineNoise,id,md); | |
391 | delete md; | |
392 | } | |
393 | //_____________________________________________________________________________ | |
394 | ||
395 | void AliTOFcalib::WriteParOnlineHWOnCDB(Char_t *sel) | |
396 | { | |
397 | //Write calibration parameters from hardware to the CDB with infinite validity | |
398 | AliCDBManager *man = AliCDBManager::Instance(); | |
399 | Char_t *sel1 = "HW" ; // to be consistent with TOFPreprocessor | |
400 | Char_t out[100]; | |
401 | sprintf(out,"%s/%s",sel,sel1); | |
402 | AliCDBRunRange runrange(fFirstRun,fLastRun); | |
403 | AliDebug(2,Form("Writing TOF online calib obj from harware on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun())); | |
404 | AliCDBId id(out,runrange); | |
405 | AliCDBMetaData *md = new AliCDBMetaData(); | |
406 | md->SetResponsible("Chiara Zampolli"); | |
407 | if (!fTOFCalOnlineHW) { | |
408 | // deve uscire!! | |
409 | } | |
410 | man->Put(fTOFCalOnlineHW,id,md); | |
411 | delete md; | |
412 | } | |
413 | //_____________________________________________________________________________ | |
414 | ||
0a749fa5 | 415 | void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun) |
416 | { | |
340693af | 417 | //Write calibration parameters to the CDB |
0cb9d099 | 418 | SetFirstRun(minrun); |
419 | SetLastRun(maxrun); | |
6dc9348d | 420 | AliCDBManager *man = AliCDBManager::Instance(); |
0a749fa5 | 421 | Char_t *sel1 = "ParOffline" ; |
d4ad0d6b | 422 | Char_t out[100]; |
423 | sprintf(out,"%s/%s",sel,sel1); | |
0cb9d099 | 424 | AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun)); |
425 | AliCDBId id(out,fFirstRun,fLastRun); | |
426 | AliCDBMetaData *md = new AliCDBMetaData(); | |
427 | md->SetResponsible("Chiara Zampolli"); | |
428 | md->SetComment(validity); | |
429 | man->Put(fTOFCalOffline,id,md); | |
430 | delete md; | |
431 | } | |
432 | //_____________________________________________________________________________ | |
433 | ||
434 | void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity) | |
435 | { | |
436 | //Write calibration parameters to the CDB with infinite validity | |
437 | AliCDBManager *man = AliCDBManager::Instance(); | |
438 | Char_t *sel1 = "ParOffline" ; | |
439 | Char_t out[100]; | |
440 | sprintf(out,"%s/%s",sel,sel1); | |
441 | AliCDBRunRange runrange(fFirstRun,fLastRun); | |
442 | AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun())); | |
443 | AliCDBId id(out,runrange); | |
d4ad0d6b | 444 | AliCDBMetaData *md = new AliCDBMetaData(); |
445 | md->SetResponsible("Chiara Zampolli"); | |
0a749fa5 | 446 | md->SetComment(validity); |
447 | man->Put(fTOFCalOffline,id,md); | |
5eaae242 | 448 | delete md; |
d4ad0d6b | 449 | } |
450 | //_____________________________________________________________________________ | |
451 | ||
0a749fa5 | 452 | Bool_t AliTOFcalib::ReadParOnlineFromCDB(Char_t *sel, Int_t nrun) |
340693af | 453 | { |
454 | //Read calibration parameters from the CDB | |
d4ad0d6b | 455 | AliCDBManager *man = AliCDBManager::Instance(); |
a7e9db2a | 456 | Char_t *sel1 = "ParOnline" ; |
d4ad0d6b | 457 | Char_t out[100]; |
458 | sprintf(out,"%s/%s",sel,sel1); | |
7a4f634e | 459 | if (!man->Get(out,nrun)) { |
460 | return kFALSE; | |
1b20c168 | 461 | } |
7a4f634e | 462 | AliCDBEntry *entry = man->Get(out,nrun); |
463 | if(!entry->GetObject()){ | |
464 | return kFALSE; | |
465 | } | |
466 | ||
0a749fa5 | 467 | fTOFCalOnline =(TObjArray*)entry->GetObject(); |
7fffa85b | 468 | |
469 | return kTRUE; | |
470 | ||
471 | } | |
472 | //_____________________________________________________________________________ | |
473 | ||
474 | Bool_t AliTOFcalib::ReadParOnlinePulserFromCDB(Char_t *sel, Int_t nrun) | |
475 | { | |
476 | //Read calibration parameters from pulser from the CDB | |
477 | AliCDBManager *man = AliCDBManager::Instance(); | |
478 | Char_t *sel1 = "Pulser" ; | |
479 | Char_t out[100]; | |
480 | sprintf(out,"%s/%s",sel,sel1); | |
481 | if (!man->Get(out,nrun)) { | |
482 | return kFALSE; | |
483 | } | |
484 | AliCDBEntry *entry = man->Get(out,nrun); | |
485 | if(!entry->GetObject()){ | |
486 | return kFALSE; | |
487 | } | |
488 | ||
489 | fTOFCalOnlinePulser =(TObjArray*)entry->GetObject(); | |
490 | ||
491 | return kTRUE; | |
492 | ||
493 | } | |
494 | //_____________________________________________________________________________ | |
495 | ||
496 | Bool_t AliTOFcalib::ReadParOnlineNoiseFromCDB(Char_t *sel, Int_t nrun) | |
497 | { | |
498 | //Read calibration parameters from noise from the CDB | |
499 | AliCDBManager *man = AliCDBManager::Instance(); | |
500 | Char_t *sel1 = "Noise" ; | |
501 | Char_t out[100]; | |
502 | sprintf(out,"%s/%s",sel,sel1); | |
503 | if (!man->Get(out,nrun)) { | |
504 | return kFALSE; | |
505 | } | |
506 | AliCDBEntry *entry = man->Get(out,nrun); | |
507 | if(!entry->GetObject()){ | |
508 | return kFALSE; | |
509 | } | |
510 | ||
511 | fTOFCalOnlineNoise =(TObjArray*)entry->GetObject(); | |
512 | ||
513 | return kTRUE; | |
514 | ||
515 | } | |
516 | //_____________________________________________________________________________ | |
517 | ||
518 | Bool_t AliTOFcalib::ReadParOnlineHWFromCDB(Char_t *sel, Int_t nrun) | |
519 | { | |
520 | //Read calibration parameters from hardware from the CDB | |
521 | AliCDBManager *man = AliCDBManager::Instance(); | |
522 | Char_t *sel1 = "HW" ; | |
523 | Char_t out[100]; | |
524 | sprintf(out,"%s/%s",sel,sel1); | |
525 | if (!man->Get(out,nrun)) { | |
526 | return kFALSE; | |
527 | } | |
528 | AliCDBEntry *entry = man->Get(out,nrun); | |
529 | if(!entry->GetObject()){ | |
530 | return kFALSE; | |
531 | } | |
532 | ||
533 | fTOFCalOnlineHW =(TObjArray*)entry->GetObject(); | |
0a749fa5 | 534 | |
1b20c168 | 535 | return kTRUE; |
7a4f634e | 536 | |
6dc9348d | 537 | } |
538 | //_____________________________________________________________________________ | |
d4ad0d6b | 539 | |
0a749fa5 | 540 | Bool_t AliTOFcalib::ReadParOfflineFromCDB(Char_t *sel, Int_t nrun) |
541 | { | |
542 | //Read calibration parameters from the CDB | |
543 | AliCDBManager *man = AliCDBManager::Instance(); | |
544 | Char_t *sel1 = "ParOffline" ; | |
545 | Char_t out[100]; | |
546 | sprintf(out,"%s/%s",sel,sel1); | |
547 | if (!man->Get(out,nrun)) { | |
548 | return kFALSE; | |
d4ad0d6b | 549 | } |
0a749fa5 | 550 | AliCDBEntry *entry = man->Get(out,nrun); |
551 | if(!entry->GetObject()){ | |
552 | return kFALSE; | |
553 | } | |
554 | AliCDBMetaData * md = entry->GetMetaData(); | |
555 | fkValidity = md->GetComment(); | |
556 | fTOFCalOffline =(TObjArray*)entry->GetObject(); | |
d4ad0d6b | 557 | |
0a749fa5 | 558 | return kTRUE; |
559 | ||
560 | } | |
561 | //_____________________________________________________________________________ | |
40212801 | 562 | void AliTOFcalib::WriteSimHistoOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, TH1F *histo){ |
340693af | 563 | //Write Sim miscalibration parameters to the CDB |
d4ad0d6b | 564 | |
d4ad0d6b | 565 | fTOFSimToT=histo; |
d4ad0d6b | 566 | AliCDBManager *man = AliCDBManager::Instance(); |
40212801 | 567 | Char_t *sel1 = "SimHisto" ; |
d4ad0d6b | 568 | Char_t out[100]; |
569 | sprintf(out,"%s/%s",sel,sel1); | |
0a749fa5 | 570 | AliCDBMetaData *mdhisto = new AliCDBMetaData(); |
571 | mdhisto->SetResponsible("Chiara Zampolli"); | |
40212801 | 572 | AliCDBId id(out,minrun,maxrun); |
573 | man->Put(fTOFSimToT,id,mdhisto); | |
0a749fa5 | 574 | delete mdhisto; |
575 | } | |
576 | //_____________________________________________________________________________ | |
40212801 | 577 | Bool_t AliTOFcalib::ReadSimHistoFromCDB(Char_t *sel, Int_t nrun) |
0a749fa5 | 578 | { |
579 | //Read miscalibration parameters from the CDB | |
580 | AliCDBManager *man = AliCDBManager::Instance(); | |
581 | ||
40212801 | 582 | // The Tot Histo |
7a4f634e | 583 | |
40212801 | 584 | Char_t *sel1 = "SimHisto" ; |
d4ad0d6b | 585 | Char_t out[100]; |
586 | sprintf(out,"%s/%s",sel,sel1); | |
7a4f634e | 587 | if (!man->Get(out,nrun)) { |
588 | AliFatal("Exiting, no CDB object (SimHisto) found!!!"); | |
589 | exit(0); | |
590 | } | |
40212801 | 591 | AliCDBEntry *entry = man->Get(out,nrun); |
592 | if(!entry->GetObject()){ | |
7a4f634e | 593 | AliFatal("Exiting, no CDB object (SimHisto) found!!!"); |
594 | exit(0); | |
595 | } | |
40212801 | 596 | TH1F *histo =(TH1F*)entry->GetObject(); |
d4ad0d6b | 597 | fTOFSimToT=histo; |
52be7fb0 | 598 | return kTRUE; |
d4ad0d6b | 599 | } |
7037bd93 | 600 | //_____________________________________________________________________________ |
601 | void AliTOFcalib::WriteRecParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){ | |
602 | //Write reconstruction parameters to the CDB | |
603 | ||
604 | AliCDBManager *man = AliCDBManager::Instance(); | |
7037bd93 | 605 | AliCDBMetaData *md = new AliCDBMetaData(); |
606 | md->SetResponsible("Silvia Arcelli"); | |
607 | Char_t *sel1 = "RecPar" ; | |
608 | Char_t out[100]; | |
609 | sprintf(out,"%s/%s",sel,sel1); | |
610 | AliCDBId id(out,minrun,maxrun); | |
611 | man->Put(param,id,md); | |
612 | delete md; | |
613 | } | |
614 | //_____________________________________________________________________________ | |
615 | AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(Char_t *sel, Int_t nrun) | |
616 | { | |
617 | //Read reconstruction parameters from the CDB | |
618 | AliCDBManager *man = AliCDBManager::Instance(); | |
7037bd93 | 619 | Char_t *sel1 = "RecPar" ; |
620 | Char_t out[100]; | |
621 | sprintf(out,"%s/%s",sel,sel1); | |
7a4f634e | 622 | if (!man->Get(out,nrun)) { |
623 | AliFatal("Exiting, no CDB object (RecPar) found!!!"); | |
624 | exit(0); | |
625 | } | |
7037bd93 | 626 | AliCDBEntry *entry = man->Get(out,nrun); |
7a4f634e | 627 | if(!entry->GetObject()){ |
628 | AliFatal("Exiting, no CDB object (RecPar) found!!!"); | |
629 | exit(0); | |
630 | } | |
631 | ||
7037bd93 | 632 | AliTOFRecoParam *param=(AliTOFRecoParam*)entry->GetObject(); |
633 | return param; | |
634 | } | |
0a749fa5 | 635 | //----------------------------------------------------------------------------- |
636 | // Calibration methods | |
637 | //----------------------------------------------------------------------------- | |
638 | void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){ | |
639 | ||
640 | // creating the chain with the trees for calibration | |
641 | // collecting them from reference data | |
642 | // from minrun to maxrun | |
643 | ||
644 | Float_t p[CHENTRIESSMALL]; | |
645 | Int_t nentries; | |
646 | fTree = new TTree("TOFCalib","Tree for TOF Calibration"); | |
647 | fTree->Branch("nentries",&nentries,"nentries/I"); | |
648 | fTree->Branch("TOFentries",p,"TOFentries[nentries]/F"); | |
649 | AliCDBManager *man = AliCDBManager::Instance(); | |
650 | AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT"); | |
651 | for (Int_t irun = minrun;irun<=maxrun;irun++){ | |
652 | AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun); | |
653 | if (!entry){ | |
654 | AliInfo(Form("No entry found for run %i",irun)); | |
655 | } | |
656 | else{ | |
657 | TTree *tree = new TTree(); | |
658 | tree = (TTree*)entry->GetObject(); | |
659 | tree->SetBranchAddress("nentries",&nentries); | |
660 | tree->SetBranchAddress("TOFentries",p); | |
661 | fTree->CopyEntries(tree); | |
662 | delete tree; | |
663 | fNruns++; | |
664 | } | |
665 | } | |
666 | AliInfo(Form("Number of runs being analyzed %i",fNruns)); | |
667 | } | |
668 | //----------------------------------------------------------------------------- | |
669 | void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){ | |
670 | ||
671 | // creating the chain with the trees for calibration | |
672 | // collecting them from the Grid | |
673 | // from minrun to maxrun | |
674 | ||
675 | Float_t p[CHENTRIESSMALL]; | |
676 | Int_t nentries; | |
677 | fTree = new TTree("TOFCalib","Tree for TOF Calibration"); | |
678 | fTree->SetDirectory(0); | |
679 | fTree->Branch("nentries",&nentries,"nentries/I"); | |
680 | fTree->Branch("TOFentries",p,"TOFentries[nentries]/F"); | |
681 | AliInfo("connected to alien"); | |
682 | TGrid::Connect("alien://"); | |
683 | ||
684 | Char_t filename[100]; | |
685 | for (Int_t irun = minrun;irun<=maxrun;irun++){ | |
686 | sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun); | |
687 | TFile *filegrid = TFile::Open(filename,"READ"); | |
688 | TTree *tree = (TTree*)filegrid->Get("T"); | |
689 | tree->SetBranchAddress("nentries",&nentries); | |
690 | tree->SetBranchAddress("TOFentries",p); | |
691 | fTree->CopyEntries(tree); | |
692 | delete tree; | |
693 | fNruns++; | |
694 | } | |
695 | ||
696 | AliInfo(Form("Number of runs being analyzed %i",fNruns)); | |
697 | } | |
698 | //----------------------------------------------------------------------------- | |
699 | void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){ | |
700 | ||
701 | // creating the tree with the trees for calibration | |
702 | // collecting them from reference data (from file) | |
703 | // from minrun to maxrun | |
704 | ||
705 | Float_t p[CHENTRIESSMALL]; | |
706 | Int_t nentries; | |
707 | fTree = new TTree("TOFCalib","Tree for TOF Calibration"); | |
708 | fTree->SetDirectory(0); | |
709 | fTree->Branch("nentries",&nentries,"nentries/I"); | |
710 | fTree->Branch("TOFentries",p,"TOFentries[nentries]/F"); | |
711 | Char_t filename[100]; | |
712 | for (Int_t irun = minrun;irun<=maxrun;irun++){ | |
713 | sprintf(filename,"$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun); | |
714 | TFile *file = new TFile(filename,"READ"); | |
715 | TTree *tree = (TTree*)file->Get("T"); | |
716 | tree->SetBranchAddress("nentries",&nentries); | |
717 | tree->SetBranchAddress("TOFentries",p); | |
718 | fTree->CopyEntries(tree); | |
719 | delete tree; | |
720 | delete file; | |
721 | file = 0x0; | |
722 | fNruns++; | |
723 | } | |
724 | ||
725 | AliInfo(Form("Number of runs being analyzed %i",fNruns)); | |
726 | } | |
727 | //----------------------------------------------------------------------------- | |
296591ad | 728 | void AliTOFcalib::CreateChainFromGrid(Int_t minrun, Int_t maxrun){ |
729 | ||
730 | // creating the chain with the trees for calibration | |
731 | // collecting them from the Grid | |
732 | // from minrun to maxrun | |
733 | ||
734 | fChain = new TChain("T"); | |
735 | AliInfo("connected to alien"); | |
736 | TGrid::Connect("alien://"); | |
737 | ||
738 | Char_t filename[100]; | |
739 | for (Int_t irun = minrun;irun<=maxrun;irun++){ | |
740 | sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun); | |
741 | fChain->Add(filename); | |
742 | fNruns++; | |
743 | } | |
744 | ||
745 | AliInfo(Form("Number of runs being analyzed %i",fNruns)); | |
746 | } | |
747 | //----------------------------------------------------------------------------- | |
0a749fa5 | 748 | Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){ |
7037bd93 | 749 | |
0a749fa5 | 750 | // calibrating summing more than one channels |
751 | // computing calibration parameters | |
752 | // Returning codes: | |
753 | // 0 -> everything was ok | |
754 | // 1 -> no tree for calibration found | |
755 | // 2 -> not enough statistics to perform calibration | |
756 | // 3 -> problems with arrays | |
757 | ||
758 | TH1::AddDirectory(0); | |
759 | ||
760 | AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ; | |
761 | AliInfo(Form("Option for Saving histos = %s",optionSave )) ; | |
762 | AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ; | |
763 | ||
764 | Float_t p[CHENTRIESSMALL]; | |
765 | Int_t nentries; | |
296591ad | 766 | //fTree->SetBranchAddress("nentries",&nentries); |
767 | //fTree->SetBranchAddress("TOFentries",p); | |
768 | fChain->SetBranchAddress("nentries",&nentries); | |
769 | fChain->SetBranchAddress("TOFentries",p); | |
0a749fa5 | 770 | |
771 | Float_t ntracksTotalmean =0; | |
772 | for (Int_t i=ichmin; i<ichmax; i++){ | |
773 | Int_t ientry = -1; | |
774 | for (Int_t irun=0;irun<fNruns;irun++){ | |
775 | ientry = i+irun*fNChannels; | |
296591ad | 776 | //fTree->GetEntry(ientry); |
777 | fChain->GetEntry(ientry); | |
0a749fa5 | 778 | Int_t ntracksRun=nentries/3; |
779 | ntracksTotalmean+=ntracksRun; | |
780 | } | |
781 | } | |
782 | ||
783 | if (ntracksTotalmean < MEANENTRIES) { | |
784 | AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean)); | |
785 | return 2; | |
786 | } | |
787 | ||
788 | //filling ToT and Time arrays | |
789 | ||
790 | Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps | |
791 | Float_t minToT = 0; // ns | |
792 | Float_t maxToT = 4.88; // ns | |
793 | ||
794 | TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT); | |
795 | TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4); | |
796 | Int_t ntracksTotal = 0; | |
797 | Int_t ntracksRun = 0; | |
798 | Double_t binsProfile[101]; // sized larger than necessary, the correct | |
799 | // dim being set in the booking of the profile | |
800 | Int_t nusefulbins=0; | |
801 | Float_t meantime=0; | |
802 | for (Int_t i = ichmin;i<ichmax;i++){ | |
803 | Int_t ientry = -1; | |
804 | for (Int_t irun=0;irun<fNruns;irun++){ | |
805 | ientry = i+irun*fNChannels; | |
296591ad | 806 | //fTree->GetEntry(ientry); |
807 | fChain->GetEntry(ientry); | |
0a749fa5 | 808 | ntracksTotal+=nentries/3; |
809 | ntracksRun=nentries/3; | |
810 | AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun)); | |
811 | for (Int_t j=0;j<ntracksRun;j++){ | |
812 | Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; | |
813 | Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; | |
814 | Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; | |
815 | Float_t tot = p[idxexToT]; | |
816 | hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]); | |
817 | meantime+=p[idxexTime]-p[idxexExTime]; | |
818 | hToT->Fill(tot); | |
819 | } | |
820 | } | |
821 | } | |
822 | nusefulbins = FindBins(hToT,&binsProfile[0]); | |
823 | meantime/=ntracksTotal; | |
824 | AliDebug(2, Form("meantime = %f",meantime)); | |
825 | ||
826 | for (Int_t j=1;j<=nusefulbins;j++) { | |
827 | AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j])); | |
828 | } | |
829 | ||
830 | TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!! | |
831 | TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10); | |
832 | ||
833 | for (Int_t irun=0;irun<fNruns;irun++){ | |
834 | Int_t ientry = -1; | |
835 | for (Int_t i=ichmin; i<ichmax; i++){ | |
836 | ientry = i+irun*fNChannels; | |
296591ad | 837 | //fTree->GetEntry(ientry); |
838 | fChain->GetEntry(ientry); | |
0a749fa5 | 839 | ntracksRun=nentries/3; |
840 | for (Int_t j=0;j<ntracksRun;j++){ | |
841 | Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; | |
842 | Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; | |
843 | Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; | |
844 | Float_t tot = p[idxexToT]; | |
845 | Float_t time = p[idxexTime]-p[idxexExTime]; | |
846 | AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime)); | |
847 | hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above | |
848 | htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above | |
849 | } | |
850 | } | |
851 | } | |
852 | ||
853 | hSlewingProf->Fit("pol5",optionFit,"",0,4); | |
854 | TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5"); | |
855 | Float_t par[6]; | |
856 | for(Int_t kk=0;kk<6;kk++){ | |
857 | par[kk]=calibfunc->GetParameter(kk); | |
858 | AliDebug(2,Form("parameter %i = %f",kk,par[kk])); | |
859 | } | |
860 | ||
861 | if(strstr(optionSave,"save")){ | |
862 | TFile * fileProf = new TFile("TOFCalibSave.root","recreate"); | |
863 | fileProf->cd(); | |
864 | TString profName=Form("Profile%06i_%06i",ichmin,ichmax); | |
865 | TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax); | |
866 | TString totName=Form("Tot%06i_%06i",ichmin,ichmax); | |
867 | TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax); | |
868 | hSlewingProf->Write(profName); | |
869 | htimetot->Write(timeTotName); | |
870 | hToT->Write(totName); | |
871 | hdeltaTime->Write(deltaName); | |
872 | fileProf->Close(); | |
873 | delete fileProf; | |
874 | fileProf=0x0; | |
875 | } | |
876 | ||
877 | delete hToT; | |
878 | hToT=0x0; | |
879 | delete hSlewingProf; | |
880 | hSlewingProf=0x0; | |
881 | delete htimetot; | |
882 | htimetot=0x0; | |
883 | delete hdeltaTime; | |
884 | hdeltaTime=0x0; | |
885 | ||
886 | AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin); | |
887 | calChannel->SetSlewPar(par); | |
0cb9d099 | 888 | WriteParOfflineOnCDB("TOF/Calib","valid"); |
0a749fa5 | 889 | return 0; |
890 | } | |
891 | //---------------------------------------------------------------------------- | |
892 | Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){ | |
893 | ||
894 | // computing calibration parameters for channel i | |
895 | // Returning codes: | |
896 | // 0 -> everything was ok | |
897 | // 1 -> no tree for calibration found | |
898 | // 2 -> not enough statistics to perform calibration | |
899 | // 3 -> problems with arrays | |
900 | ||
901 | TH1::AddDirectory(0); | |
902 | ||
903 | AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ; | |
904 | AliInfo(Form("Option for Saving histos = %s",optionSave )) ; | |
905 | AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ; | |
906 | ||
907 | Float_t p[MAXCHENTRIESSMALL]; | |
908 | Int_t nentries; | |
296591ad | 909 | //fTree->SetBranchAddress("nentries",&nentries); |
910 | //fTree->SetBranchAddress("TOFentries",p); | |
911 | fChain->SetBranchAddress("nentries",&nentries); | |
912 | fChain->SetBranchAddress("TOFentries",p); | |
0a749fa5 | 913 | |
914 | Float_t ntracksTotal =0; | |
915 | for (Int_t irun=0;irun<fNruns;irun++){ | |
916 | Int_t ientry = -1; | |
917 | ientry = i+irun*fNChannels; | |
296591ad | 918 | //fTree->GetEntry(ientry); |
919 | fChain->GetEntry(ientry); | |
0a749fa5 | 920 | ntracksTotal+=nentries/3; |
921 | } | |
922 | ||
923 | if (ntracksTotal < MEANENTRIES) { | |
924 | AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal)); | |
925 | return 2; | |
926 | } | |
927 | ||
928 | //filling ToT and Time arrays | |
929 | ||
930 | Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps | |
931 | Float_t minToT = 0; // ns | |
932 | Float_t maxToT = 4.88; // ns | |
933 | ||
934 | TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT); | |
935 | TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4); | |
936 | Int_t ntracksRun = 0; | |
937 | Double_t binsProfile[101]; // sized larger than necessary, the correct | |
938 | // dim being set in the booking of the profile | |
939 | Int_t nusefulbins=0; | |
940 | Float_t meantime=0; | |
941 | for (Int_t irun=0;irun<fNruns;irun++){ | |
942 | Int_t ientry = -1; | |
943 | ientry = i+irun*fNChannels; | |
296591ad | 944 | //fTree->GetEntry(ientry); |
945 | fChain->GetEntry(ientry); | |
0a749fa5 | 946 | ntracksRun=nentries/3; |
947 | AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun)); | |
948 | for (Int_t j=0;j<ntracksRun;j++){ | |
949 | Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; | |
950 | Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; | |
951 | Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; | |
952 | Float_t tot = p[idxexToT]; | |
953 | meantime+=p[idxexTime]-p[idxexExTime]; | |
954 | hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]); | |
955 | hToT->Fill(tot); | |
956 | } | |
957 | } | |
958 | ||
959 | nusefulbins = FindBins(hToT,&binsProfile[0]); | |
960 | meantime/=ntracksTotal; | |
961 | AliDebug(2,Form("meantime = %f",meantime)); | |
962 | ||
963 | for (Int_t j=1;j<=nusefulbins;j++) { | |
964 | AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j])); | |
965 | } | |
966 | ||
967 | TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!! | |
968 | TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10); | |
969 | for (Int_t irun=0;irun<fNruns;irun++){ | |
970 | Int_t ientry = -1; | |
971 | ientry = i+irun*fNChannels; | |
296591ad | 972 | //fTree->GetEntry(ientry); |
973 | fChain->GetEntry(ientry); | |
0a749fa5 | 974 | ntracksRun=nentries/3; |
975 | for (Int_t j=0;j<ntracksRun;j++){ | |
976 | Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; | |
977 | Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; | |
978 | Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; | |
979 | Float_t tot = p[idxexToT]; | |
980 | Float_t time = p[idxexTime]-p[idxexExTime]; | |
981 | AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime)); | |
982 | hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above | |
983 | htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above | |
984 | } | |
985 | } | |
986 | ||
987 | hSlewingProf->Fit("pol5",optionFit,"",0,4); | |
988 | TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5"); | |
989 | Float_t par[6]; | |
990 | for(Int_t kk=0;kk<6;kk++){ | |
991 | par[kk]=calibfunc->GetParameter(kk); | |
992 | AliDebug(2,Form("parameter %i = %f",kk,par[kk])); | |
993 | } | |
994 | ||
995 | ||
996 | if(strstr(optionSave,"save")){ | |
997 | TFile * fileProf = new TFile("TOFCalibSave.root","recreate"); | |
998 | fileProf->cd(); | |
999 | TString profName=Form("Profile%06i",i); | |
1000 | TString timeTotName=Form("TimeTot%06i",i); | |
1001 | TString totName=Form("Tot%06i",i); | |
1002 | TString deltaName=Form("Delta%06i",i); | |
1003 | hSlewingProf->Write(profName); | |
1004 | htimetot->Write(timeTotName); | |
1005 | hToT->Write(totName); | |
1006 | hdeltaTime->Write(deltaName); | |
1007 | fileProf->Close(); | |
1008 | delete fileProf; | |
1009 | fileProf=0x0; | |
1010 | } | |
1011 | ||
1012 | delete hToT; | |
1013 | hToT=0x0; | |
1014 | delete hSlewingProf; | |
1015 | hSlewingProf=0x0; | |
1016 | delete htimetot; | |
1017 | htimetot=0x0; | |
1018 | delete hdeltaTime; | |
1019 | hdeltaTime=0x0; | |
1020 | ||
1021 | AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i); | |
1022 | calChannel->SetSlewPar(par); | |
0cb9d099 | 1023 | WriteParOfflineOnCDB("TOF/Calib","valid"); |
0a749fa5 | 1024 | return 0; |
1025 | } | |
1026 | //---------------------------------------------------------------------------- | |
1027 | Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){ | |
1028 | ||
1029 | // calibrating an array of channels | |
1030 | // computing calibration parameters | |
1031 | // Returning codes: | |
1032 | // 0 -> everything was ok | |
1033 | // 1 -> no tree for calibration found | |
1034 | // 2 -> not enough statistics to perform calibration | |
1035 | // 3 -> problems with arrays | |
1036 | ||
1037 | TH1::AddDirectory(0); | |
1038 | ||
1039 | AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ; | |
1040 | AliInfo(Form("Option for Saving histos = %s",optionSave )) ; | |
1041 | AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ; | |
1042 | for (Int_t ich=0; ich<nch; ich++){ | |
1043 | Int_t i = ch[ich]; | |
1044 | AliInfo(Form("Calibrating channel = %i",i )) ; | |
1045 | } | |
1046 | Float_t p[MAXCHENTRIESSMALL]; | |
1047 | Int_t nentries; | |
296591ad | 1048 | //fTree->SetBranchAddress("nentries",&nentries); |
1049 | //fTree->SetBranchAddress("TOFentries",p); | |
1050 | fChain->SetBranchAddress("nentries",&nentries); | |
1051 | fChain->SetBranchAddress("TOFentries",p); | |
0a749fa5 | 1052 | |
1053 | Float_t ntracksTotalmean =0; | |
1054 | for (Int_t ich=0; ich<nch; ich++){ | |
1055 | Int_t ientry = -1; | |
1056 | Int_t i = ch[ich]; | |
1057 | for (Int_t irun=0;irun<fNruns;irun++){ | |
1058 | ientry = i+irun*fNChannels; | |
296591ad | 1059 | //fTree->GetEntry(ientry); |
1060 | fChain->GetEntry(ientry); | |
0a749fa5 | 1061 | ntracksTotalmean+=nentries/3; |
1062 | } | |
1063 | } | |
1064 | ||
1065 | ntracksTotalmean/=nch; | |
1066 | if (ntracksTotalmean < MEANENTRIES) { | |
1067 | AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean)); | |
1068 | return 2; | |
1069 | } | |
1070 | ||
1071 | //filling ToT and Time arrays | |
1072 | ||
1073 | Int_t nbinToT = 100; // ToT bin width in Profile = 48.8 ps | |
1074 | Float_t minToT = 0; // ns | |
1075 | Float_t maxToT = 4.88; // ns | |
1076 | TFile * fileProf=0x0; | |
1077 | if(strstr(optionSave,"save")){ | |
1078 | fileProf = new TFile("TOFCalibSave.root","recreate"); | |
1079 | } | |
1080 | for (Int_t ich=0; ich<nch; ich++) { | |
1081 | TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT); | |
1082 | TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4); | |
1083 | Double_t binsProfile[101]; // sized larger than necessary, the correct | |
1084 | // dim being set in the booking of the profile | |
1085 | TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10); | |
1086 | Int_t ntracksTotal = 0; | |
1087 | Int_t ntracksRun = 0; | |
1088 | Int_t nusefulbins=0; | |
1089 | Float_t meantime=0; | |
1090 | Int_t i=-1; | |
1091 | for (Int_t irun=0;irun<fNruns;irun++){ | |
1092 | i = ch[ich]+irun*fNChannels; | |
1093 | AliDebug(2,Form("Calibrating channel %i",i)); | |
296591ad | 1094 | //fTree->GetEntry(i); |
1095 | fChain->GetEntry(i); | |
0a749fa5 | 1096 | ntracksTotal+=nentries/3; |
1097 | } | |
1098 | if (ntracksTotal < MEANENTRIES) { | |
1099 | AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",i,ntracksTotal)); | |
1100 | continue; | |
1101 | } | |
1102 | ||
1103 | for (Int_t irun=0;irun<fNruns;irun++){ | |
1104 | Int_t i = ch[ich]+irun*fNChannels; | |
296591ad | 1105 | //fTree->GetEntry(i); |
1106 | fChain->GetEntry(i); | |
0a749fa5 | 1107 | ntracksRun=nentries/3; |
1108 | for (Int_t j=0;j<ntracksRun;j++){ | |
1109 | Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; | |
1110 | Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; | |
1111 | Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; | |
1112 | Float_t tot = p[idxexToT]; | |
1113 | hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]); | |
1114 | meantime+=p[idxexTime]-p[idxexExTime]; | |
1115 | hToT->Fill(tot); | |
1116 | } | |
1117 | } | |
1118 | ||
1119 | nusefulbins = FindBins(hToT,&binsProfile[0]); | |
1120 | meantime/=ntracksTotal; | |
1121 | for (Int_t j=1;j<=nusefulbins;j++) { | |
1122 | AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j])); | |
1123 | } | |
1124 | ||
1125 | TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!! | |
1126 | for (Int_t irun=0;irun<fNruns;irun++){ | |
1127 | Int_t i = ch[ich]+irun*fNChannels; | |
296591ad | 1128 | //fTree->GetEntry(i); |
1129 | fChain->GetEntry(i); | |
0a749fa5 | 1130 | ntracksRun=nentries/3; |
1131 | for (Int_t j=0;j<ntracksRun;j++){ | |
1132 | Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; | |
1133 | Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; | |
1134 | Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; | |
1135 | Float_t tot = p[idxexToT]; | |
1136 | Float_t time = p[idxexTime]-p[idxexExTime]; | |
1137 | AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime)); | |
1138 | hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above | |
1139 | htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above | |
1140 | } | |
1141 | } | |
1142 | ||
1143 | hSlewingProf->Fit("pol5",optionFit,"",1,4); | |
1144 | TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5"); | |
1145 | Float_t par[6]; | |
1146 | for(Int_t kk=0;kk<6;kk++){ | |
1147 | par[kk]=calibfunc->GetParameter(kk); | |
1148 | AliDebug(2,Form("parameter %i = %f",kk,par[kk])); | |
1149 | } | |
1150 | ||
1151 | if(strstr(optionSave,"save") && fileProf){ | |
1152 | TString profName=Form("Profile%06i",i); | |
1153 | TString timeTotName=Form("TimeTot%06i",i); | |
1154 | TString totName=Form("Tot%06i",i); | |
1155 | TString deltaName=Form("Delta%06i",i); | |
1156 | fileProf->cd(); | |
1157 | hSlewingProf->Write(profName); | |
1158 | htimetot->Write(timeTotName); | |
1159 | hToT->Write(totName); | |
1160 | hdeltaTime->Write(deltaName); | |
1161 | } | |
1162 | ||
1163 | AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i); | |
1164 | calChannel->SetSlewPar(par); | |
1165 | delete hToT; | |
1166 | hToT=0x0; | |
1167 | delete hSlewingProf; | |
1168 | hSlewingProf=0x0; | |
1169 | delete htimetot; | |
1170 | htimetot=0x0; | |
1171 | delete hdeltaTime; | |
1172 | hdeltaTime=0x0; | |
1173 | } | |
1174 | ||
1175 | if(strstr(optionSave,"save") && fileProf){ | |
1176 | fileProf->Close(); | |
1177 | delete fileProf; | |
1178 | fileProf=0x0; | |
1179 | } | |
0cb9d099 | 1180 | WriteParOfflineOnCDB("TOF/Calib","valid"); |
0a749fa5 | 1181 | |
1182 | return 0; | |
1183 | } | |
1184 | //---------------------------------------------------------------------------- | |
1185 | Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){ | |
1186 | ||
1187 | // computing calibration parameters using the old profiling algo | |
1188 | // Returning codes: | |
1189 | // 0 -> everything was ok | |
1190 | // 1 -> no tree for calibration found | |
1191 | // 2 -> not enough statistics to perform calibration | |
1192 | // 3 -> problems with arrays | |
1193 | ||
1194 | TH1::AddDirectory(0); | |
1195 | ||
1196 | AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ; | |
1197 | AliInfo(Form("Option for Saving histos = %s",optionSave )) ; | |
1198 | AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ; | |
1199 | Float_t p[MAXCHENTRIESSMALL]; | |
1200 | Int_t nentries; | |
1201 | Int_t ntracksTotal=0; | |
296591ad | 1202 | //fTree->SetBranchAddress("nentries",&nentries); |
1203 | //fTree->SetBranchAddress("TOFentries",p); | |
1204 | fChain->SetBranchAddress("nentries",&nentries); | |
1205 | fChain->SetBranchAddress("TOFentries",p); | |
0a749fa5 | 1206 | |
1207 | for (Int_t irun=0;irun<fNruns;irun++){ | |
1208 | Int_t i = ich+irun*fNChannels; | |
296591ad | 1209 | //fTree->GetEntry(i); |
1210 | fChain->GetEntry(i); | |
0a749fa5 | 1211 | ntracksTotal+=nentries/3; |
1212 | } | |
1213 | ||
1214 | if (ntracksTotal < MEANENTRIES) { | |
1215 | AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal)); | |
1216 | return 2; | |
1217 | } | |
1218 | ||
1219 | TH1F * hProf = new TH1F(); | |
1220 | hProf = Profile(ich); | |
1221 | hProf->Fit("pol5",optionFit,"",0,4); | |
1222 | TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5"); | |
1223 | Float_t par[6]; | |
1224 | for(Int_t kk=0;kk<6;kk++){ | |
1225 | par[kk]=calibfunc->GetParameter(kk); | |
1226 | AliDebug(2,Form("parameter %i = %f",kk,par[kk])); | |
1227 | } | |
1228 | ||
1229 | if(strstr(optionSave,"save")){ | |
1230 | TFile * fileProf = new TFile("TOFCalibSave.root","recreate"); | |
1231 | fileProf->cd(); | |
1232 | TString profName=Form("Profile%06i",ich); | |
1233 | hProf->Write(profName); | |
1234 | fileProf->Close(); | |
1235 | delete fileProf; | |
1236 | fileProf=0x0; | |
1237 | } | |
1238 | ||
1239 | delete hProf; | |
1240 | hProf=0x0; | |
1241 | AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich); | |
1242 | calChannel->SetSlewPar(par); | |
0cb9d099 | 1243 | WriteParOfflineOnCDB("TOF/Calib","valid"); |
0a749fa5 | 1244 | return 0; |
1245 | } | |
1246 | //---------------------------------------------------------------------------- | |
1247 | Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){ | |
1248 | ||
1249 | // calibrating the whole TOF | |
1250 | // computing calibration parameters | |
1251 | // Returning codes: | |
1252 | // 0 -> everything was ok | |
1253 | // 1 -> no tree for calibration found | |
1254 | // 2 -> not enough statistics to perform calibration | |
1255 | // 3 -> problems with arrays | |
1256 | ||
1257 | TH1::AddDirectory(0); | |
1258 | ||
1259 | AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ; | |
1260 | AliInfo(Form("Option for Saving histos = %s",optionSave )) ; | |
1261 | AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ; | |
1262 | ||
1263 | TFile * fileProf=0x0; | |
1264 | if(strstr(optionSave,"save")){ | |
1265 | fileProf = new TFile("TOFCalibSave.root","recreate"); | |
1266 | } | |
1267 | ||
1268 | Float_t p[MAXCHENTRIESSMALL]; | |
1269 | Int_t nentries; | |
296591ad | 1270 | //fTree->SetBranchAddress("nentries",&nentries); |
1271 | //fTree->SetBranchAddress("TOFentries",p); | |
1272 | fChain->SetBranchAddress("nentries",&nentries); | |
1273 | fChain->SetBranchAddress("TOFentries",p); | |
0a749fa5 | 1274 | |
1275 | Float_t ntracksTotalmean =0; | |
1276 | for (Int_t ii=0; ii<fNChannels; ii++){ | |
1277 | for (Int_t irun=0;irun<fNruns;irun++){ | |
1278 | Int_t i = ii+irun*fNChannels; | |
296591ad | 1279 | //fTree->GetEntry(i); |
1280 | fChain->GetEntry(i); | |
0a749fa5 | 1281 | ntracksTotalmean+=nentries/3; |
1282 | } | |
1283 | } | |
1284 | ||
1285 | ntracksTotalmean/=fNChannels; | |
1286 | if (ntracksTotalmean < MEANENTRIES) { | |
1287 | AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean)); | |
1288 | return 2; | |
1289 | } | |
1290 | ||
1291 | //filling ToT and Time arrays | |
1292 | ||
1293 | Int_t nbinToT = 100; // ToT bin width in Profile = 50.0 ps | |
1294 | Float_t minToT = 0; // ns | |
1295 | Float_t maxToT = 4.88;// ns | |
1296 | for (Int_t ii=0; ii<fNChannels; ii++) { | |
1297 | TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT); | |
1298 | TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4); | |
1299 | TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10); | |
1300 | if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii)); | |
1301 | //Int_t i = 3; | |
1302 | Int_t nusefulbins=0; | |
1303 | Double_t binsProfile[101]; // sized larger than necessary, the correct | |
1304 | // dim being set in the booking of the profile | |
1305 | Int_t ntracksRun = 0; | |
1306 | Int_t ntracksTotal = 0; | |
1307 | for (Int_t irun=0;irun<fNruns;irun++){ | |
1308 | Int_t i = ii+irun*fNChannels; | |
296591ad | 1309 | //fTree->GetEntry(i); |
1310 | fChain->GetEntry(i); | |
0a749fa5 | 1311 | ntracksTotal+=nentries/3; |
1312 | } | |
1313 | if (ntracksTotal < MEANENTRIES) { | |
1314 | AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",ii,ntracksTotal)); | |
1315 | continue; | |
1316 | } | |
1317 | Float_t meantime=0; | |
1318 | for (Int_t irun=0;irun<fNruns;irun++){ | |
1319 | Int_t i = ii+irun*fNChannels; | |
296591ad | 1320 | //fTree->GetEntry(i); |
1321 | fChain->GetEntry(i); | |
0a749fa5 | 1322 | ntracksRun=nentries/3; |
1323 | for (Int_t j=0;j<ntracksRun;j++){ | |
1324 | Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; | |
1325 | Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; | |
1326 | Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; | |
1327 | Float_t tot = p[idxexToT]; | |
1328 | hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]); | |
1329 | meantime+=p[idxexTime]-p[idxexExTime]; | |
1330 | hToT->Fill(tot); | |
1331 | } | |
1332 | } | |
1333 | nusefulbins = FindBins(hToT,&binsProfile[0]); | |
1334 | meantime/=ntracksTotal; | |
1335 | for (Int_t j=0;j<nusefulbins;j++) { | |
1336 | AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j])); | |
1337 | } | |
1338 | TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G"); // CHECK THE BUILD OPTION, PLEASE!!!!!! | |
1339 | for (Int_t irun=0;irun<fNruns;irun++){ | |
1340 | Int_t i = ii+irun*fNChannels; | |
296591ad | 1341 | //fTree->GetEntry(i); |
1342 | fChain->GetEntry(i); | |
0a749fa5 | 1343 | ntracksRun=nentries/3; |
1344 | for (Int_t j=0;j<ntracksRun;j++){ | |
1345 | Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; | |
1346 | Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; | |
1347 | Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; | |
1348 | Float_t tot = p[idxexToT]; | |
1349 | Float_t time = p[idxexTime]-p[idxexExTime]; | |
1350 | AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime)); | |
1351 | hSlewingProf->Fill(tot,time); // if meantime is not used, the fill may be moved in the loop above | |
1352 | htimetot->Fill(tot,time-meantime); // if meantime is not used, the fill may be moved in the loop above | |
1353 | } | |
1354 | } | |
1355 | hSlewingProf->Fit("pol5",optionFit,"",1,4); | |
1356 | TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5"); | |
1357 | Float_t par[6]; | |
1358 | for(Int_t kk=0;kk<6;kk++){ | |
1359 | par[kk]=calibfunc->GetParameter(kk); | |
1360 | AliDebug(2,Form("parameter %i = %f",kk,par[kk])); | |
1361 | } | |
1362 | ||
1363 | if(strstr(optionSave,"save") && fileProf){ | |
1364 | TString profName=Form("Profile%06i",ii); | |
1365 | TString timeTotName=Form("TimeTot%06i",ii); | |
1366 | TString totName=Form("Tot%06i",ii); | |
1367 | TString deltaName=Form("Delta%06i",ii); | |
1368 | fileProf->cd(); | |
1369 | hSlewingProf->Write(profName); | |
1370 | htimetot->Write(timeTotName); | |
1371 | hToT->Write(totName); | |
1372 | hdeltaTime->Write(deltaName); | |
1373 | } | |
1374 | AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii); | |
1375 | calChannel->SetSlewPar(par); | |
1376 | ||
1377 | delete hToT; | |
1378 | hToT=0x0; | |
1379 | delete hSlewingProf; | |
1380 | hSlewingProf=0x0; | |
1381 | delete htimetot; | |
1382 | htimetot=0x0; | |
1383 | delete hdeltaTime; | |
1384 | hdeltaTime=0x0; | |
1385 | } | |
1386 | ||
1387 | if(strstr(optionSave,"save")){ | |
1388 | fileProf->Close(); | |
1389 | delete fileProf; | |
1390 | fileProf=0x0; | |
1391 | } | |
0cb9d099 | 1392 | WriteParOfflineOnCDB("TOF/Calib","valid"); |
0a749fa5 | 1393 | return 0; |
1394 | } | |
1395 | ||
1396 | //----------------------------------------------------------------------- | |
1397 | TH1F* AliTOFcalib::Profile(Int_t ich) | |
340693af | 1398 | { |
0a749fa5 | 1399 | // profiling algo |
1400 | ||
1401 | Float_t p[MAXCHENTRIESSMALL]; | |
1402 | Int_t nentries; | |
296591ad | 1403 | //fTree->SetBranchAddress("nentries",&nentries); |
1404 | //fTree->SetBranchAddress("TOFentries",p); | |
1405 | fChain->SetBranchAddress("nentries",&nentries); | |
1406 | fChain->SetBranchAddress("TOFentries",p); | |
0a749fa5 | 1407 | |
1408 | //Prepare histograms for Slewing Correction | |
1409 | const Int_t knbinToT = 100; | |
1410 | Int_t nbinTime = 200; | |
1411 | Float_t minTime = -5.5; //ns | |
1412 | Float_t maxTime = 5.5; //ns | |
1413 | Float_t minToT = 0; //ns | |
1414 | Float_t maxToT = 5.; //ns | |
1415 | Float_t deltaToT = (maxToT-minToT)/knbinToT; | |
1416 | 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]; | |
1417 | Int_t n[knbinToT+1], nentrx[knbinToT+1]; | |
1418 | Double_t sigmaToT[knbinToT+1]; | |
1419 | for (Int_t i = 0; i < knbinToT+1 ; i++){ | |
1420 | mTime[i]=0; | |
1421 | mToT[i]=0; | |
1422 | n[i]=0; | |
1423 | meanTime[i]=0; | |
1424 | meanTime2[i]=0; | |
1425 | vToT[i]=0; | |
1426 | vToT2[i]=0; | |
1427 | meanToT[i]=0; | |
1428 | meanToT2[i]=0; | |
1429 | vTime[i]=0; | |
1430 | vTime2[i]=0; | |
1431 | xlow[i]=0; | |
1432 | sigmaTime[i]=0; | |
1433 | sigmaToT[i]=0; | |
1434 | n[i]=0; | |
1435 | nentrx[i]=0; | |
1436 | } | |
1437 | TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime); | |
1438 | Int_t ntracksRun = 0; | |
1439 | TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT); | |
1440 | for (Int_t irun=0;irun<fNruns;irun++){ | |
1441 | Int_t i = ich+irun*fNChannels; | |
296591ad | 1442 | //fTree->GetEntry(i); |
1443 | fChain->GetEntry(i); | |
0a749fa5 | 1444 | ntracksRun=nentries/3; |
1445 | for (Int_t j=0;j<ntracksRun;j++){ | |
1446 | Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; | |
1447 | Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; | |
1448 | Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; | |
1449 | Float_t tot = p[idxexToT]; | |
1450 | Float_t time = p[idxexTime]-p[idxexExTime]; | |
1451 | Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1; | |
1452 | if ((tot != 0) && ( time!= 0)){ | |
1453 | vTime[nx]+=time; | |
1454 | vTime2[nx]+=time*time; | |
1455 | vToT[nx]+=tot; | |
1456 | vToT2[nx]+=tot*tot; | |
1457 | nentrx[nx]++; | |
1458 | hSlewing->Fill(tot,time); | |
1459 | } | |
1460 | } | |
1461 | } | |
1462 | Int_t nbinsToT=hSlewing->GetNbinsX(); | |
1463 | if (nbinsToT != knbinToT) { | |
1464 | AliError("Profile :: incompatible numbers of bins"); | |
1465 | return 0x0; | |
1466 | } | |
1467 | ||
1468 | Int_t usefulBins=0; | |
1469 | for (Int_t i=1;i<=nbinsToT;i++){ | |
1470 | if (nentrx[i]!=0){ | |
1471 | n[usefulBins]+=nentrx[i]; | |
1472 | if (n[usefulBins]==0 && i == nbinsToT) { | |
1473 | break; | |
1474 | } | |
1475 | meanTime[usefulBins]+=vTime[i]; | |
1476 | meanTime2[usefulBins]+=vTime2[i]; | |
1477 | meanToT[usefulBins]+=vToT[i]; | |
1478 | meanToT2[usefulBins]+=vToT2[i]; | |
1479 | if (n[usefulBins]<10 && i!=nbinsToT) continue; | |
1480 | mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins]; | |
1481 | mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins]; | |
1482 | sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins] | |
1483 | *(meanTime2[usefulBins]-meanTime[usefulBins] | |
1484 | *meanTime[usefulBins]/n[usefulBins])); | |
1485 | if ((1./n[usefulBins]/n[usefulBins] | |
1486 | *(meanToT2[usefulBins]-meanToT[usefulBins] | |
1487 | *meanToT[usefulBins]/n[usefulBins]))< 0) { | |
1488 | AliError(" too small radical" ); | |
1489 | sigmaToT[usefulBins]=0; | |
1490 | } | |
1491 | else{ | |
1492 | sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins] | |
1493 | *(meanToT2[usefulBins]-meanToT[usefulBins] | |
1494 | *meanToT[usefulBins]/n[usefulBins])); | |
1495 | } | |
1496 | usefulBins++; | |
1497 | } | |
1498 | } | |
1499 | for (Int_t i=0;i<usefulBins;i++){ | |
1500 | Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1; | |
1501 | histo->Fill(mToT[i],mTime[i]); | |
1502 | histo->SetBinError(binN,sigmaTime[i]); | |
1503 | } | |
1504 | delete hSlewing; | |
1505 | hSlewing=0x0; | |
1506 | ||
1507 | return histo; | |
6dc9348d | 1508 | } |
0a749fa5 | 1509 | //---------------------------------------------------------------------------- |
1510 | Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{ | |
6dc9348d | 1511 | |
0a749fa5 | 1512 | // to determine the bins for ToT histo |
1513 | ||
1514 | Int_t cont = 0; | |
1515 | Int_t startBin = 1; | |
1516 | Int_t nbin = h->GetNbinsX(); | |
1517 | Int_t nentries = (Int_t)h->GetEntries(); | |
1518 | Float_t max = h->GetBinLowEdge(nbin); | |
1519 | Int_t nusefulbins=0; | |
1520 | Int_t maxcont=0; | |
1521 | // setting maxvalue of entries per bin | |
1522 | if (nentries <= 60) maxcont = 2; | |
1523 | else if (nentries <= 100) maxcont = 5; | |
1524 | else if (nentries <= 500) maxcont = 10; | |
1525 | else maxcont = 20; | |
1526 | for (Int_t j=1;j<=nbin;j++) { | |
1527 | cont += (Int_t)h->GetBinContent(j); | |
1528 | if (j<nbin){ | |
1529 | if (cont>=maxcont){ | |
1530 | nusefulbins++; | |
1531 | binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin); | |
1532 | cont=0; | |
1533 | startBin=j+1; | |
1534 | continue; | |
1535 | } | |
1536 | } | |
1537 | else{ | |
1538 | if (cont>=maxcont){ | |
1539 | nusefulbins++; | |
1540 | binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin); | |
1541 | binsProfile[nusefulbins]=max; | |
1542 | } | |
1543 | else { | |
1544 | binsProfile[nusefulbins]=h->GetBinLowEdge(startBin); | |
1545 | } | |
1546 | } | |
1547 | } | |
1548 | return nusefulbins; | |
1549 | } |