]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/AliT0CalibTimeEq.cxx
Method HasBadDaughters() to check that all ITS+TPC daughters have BIT(4) (Francesco)
[u/mrichter/AliRoot.git] / T0 / AliT0CalibTimeEq.cxx
CommitLineData
18086258 1
a2ad8166 2/**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
7 * *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
16
17/* $Id$ */
18
19///////////////////////////////////////////////////////////////////////////////
20// //
59b8a5fc 21// class for T0 calibration TM-AC-AM_6-02-2006
22// equalize time shift for each time CFD channel
a2ad8166 23// //
24///////////////////////////////////////////////////////////////////////////////
25
26#include "AliT0CalibTimeEq.h"
e47b556f 27#include "AliLog.h"
a2ad8166 28#include <TFile.h>
29#include <TMath.h>
30#include <TF1.h>
a2ad8166 31#include <TSpectrum.h>
a2ad8166 32#include <TProfile.h>
c61a7285 33#include <iostream>
a2ad8166 34
35ClassImp(AliT0CalibTimeEq)
36
37//________________________________________________________________
eef60a6a 38 AliT0CalibTimeEq::AliT0CalibTimeEq():TNamed(),
39 fMeanVertex(0),
40 fRmsVertex(0)
a2ad8166 41{
42 //
b95e8d87 43
a2ad8166 44}
45
46//________________________________________________________________
eef60a6a 47AliT0CalibTimeEq::AliT0CalibTimeEq(const char* name):TNamed(),
48 fMeanVertex(0),
49 fRmsVertex(0)
a2ad8166 50{
59b8a5fc 51 //constructor
52
a2ad8166 53 TString namst = "Calib_";
54 namst += name;
55 SetName(namst.Data());
56 SetTitle(namst.Data());
57}
58
59//________________________________________________________________
eef60a6a 60AliT0CalibTimeEq::AliT0CalibTimeEq(const AliT0CalibTimeEq& calibda):TNamed(calibda),
61 fMeanVertex(0),
62 fRmsVertex(0)
a2ad8166 63{
64// copy constructor
65 SetName(calibda.GetName());
66 SetTitle(calibda.GetName());
67
68
69}
70
71//________________________________________________________________
72AliT0CalibTimeEq &AliT0CalibTimeEq::operator =(const AliT0CalibTimeEq& calibda)
73{
74// assignment operator
75 SetName(calibda.GetName());
76 SetTitle(calibda.GetName());
77
78 return *this;
79}
80
81//________________________________________________________________
82AliT0CalibTimeEq::~AliT0CalibTimeEq()
83{
84 //
59b8a5fc 85 // destrictor
a2ad8166 86}
87//________________________________________________________________
88void AliT0CalibTimeEq::Reset()
89{
59b8a5fc 90 //reset values
91
a2ad8166 92 memset(fCFDvalue,0,120*sizeof(Float_t));
93 memset(fTimeEq,1,24*sizeof(Float_t));
94}
95
96
97//________________________________________________________________
98void AliT0CalibTimeEq::Print(Option_t*) const
99{
59b8a5fc 100 // print time values
a2ad8166 101
102 printf("\n ---- PM Arrays ----\n\n");
103 printf(" Time delay CFD \n");
2a1ccb90 104 for (Int_t i=0; i<24; i++)
105 printf(" CFD %f diff %f \n",fCFDvalue[i][0],fTimeEq[i]);
a2ad8166 106}
107
108
109//________________________________________________________________
02888358 110Bool_t AliT0CalibTimeEq::ComputeOnlineParams(const char* filePhys)
a2ad8166 111{
59b8a5fc 112 // compute online equalized time
1e7108ce 113 Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
c4ba15c3 114 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
c4ba15c3 115 Double_t rmsver=0;
b5e0299c 116 Int_t nent=0;
32d3e409 117 Int_t okdiff=0;
118 Int_t oktime=0;
02888358 119 Bool_t ok=false;
c2337900 120 gFile = TFile::Open(filePhys);
370867d2 121 if(!gFile) {
6318dd46 122 AliError("No input PHYS data found ");
123 }
124 else
125 {
02888358 126 ok=true;
6318dd46 127 for (Int_t i=0; i<24; i++)
128 {
18086258 129
e691fec9 130 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
1e7108ce 131 TH1F *cfd = (TH1F*) gFile->Get(Form("CFD1minCFD%d",i+1));
132 TH1F *cfdtime = (TH1F*) gFile->Get(Form("CFD%d",i+1));
dd92f5b8 133 if(!cfd) {
134 AliWarning(Form("no Diff histograms collected by PHYS DA for channel %i", i));
32d3e409 135 okdiff++;
136 if(okdiff<4) {
137 meandiff = 0;
138 sigmadiff = 0;
139 }
140 else
141 ok = false;
dd92f5b8 142 }
143 if(!cfdtime) {
144 AliWarning(Form("no CFD histograms collected by PHYS DA for channel %i", i));
32d3e409 145 oktime++;
146 if(oktime<4) {
147 meancfdtime = 0;
148 }
149 else
150 ok = false;
dd92f5b8 151 }
eef60a6a 152 if(cfd) {
e691fec9 153 nent = Int_t(cfd->GetEntries());
2a1ccb90 154 if( nent<=50) {
32d3e409 155 okdiff++;
2a1ccb90 156 // printf(" pmt %i nent %i cfd->GetRMS() %f cfd->GetMean() %f \n",
157 // i, nent, cfd->GetRMS(), cfd->GetMean() );
32d3e409 158 if(okdiff<4) {
159 meandiff = 0;
160 sigmadiff = 0;
161 }
162 else
163 {
2a1ccb90 164 // printf(" OK fsle:: pmt %i nent %i cfd->GetRMS() %f cfd->GetMean() %f \n",
165 // i, nent, cfd->GetRMS(), cfd->GetMean() );
32d3e409 166 AliWarning(Form(" Not enouph data in PMT %i- PMT1: %i ", i, nent));
167 ok = false;
168 }
169 }
18086258 170 if(nent>50) {
612737bb 171 if(cfd->GetRMS()>1.5 )
e691fec9 172 GetMeanAndSigma(cfd, meandiff, sigmadiff);
173 if(cfd->GetRMS()<=1.5)
174 {
175 meandiff = cfd->GetMean();
176 sigmadiff=cfd->GetRMS();
177 }
dd92f5b8 178 Int_t maxBin = cfd->GetMaximumBin();
179 Double_t meanEstimate = cfd->GetBinCenter( maxBin);
180 if(TMath::Abs(meanEstimate - meandiff) > 20 ) meandiff = meanEstimate;
1e7108ce 181 }
1e7108ce 182 }
32d3e409 183
1e7108ce 184 if(cfdtime) {
e691fec9 185 nent = Int_t(cfdtime->GetEntries());
2a1ccb90 186 if( nent<=50 ) {
32d3e409 187 oktime++;
188 if(oktime<4) {
189 meancfdtime = 0;
190 }
191 else
192 {
193 AliWarning(Form(" Not enouph data in PMT %i: %i ", i, nent));
194 ok = false;
195 }
196 }
2a1ccb90 197 if(nent > 50 ) { //!!!!!!!!!!
b5e0299c 198 if(cfdtime->GetRMS()>1.5 )
e691fec9 199 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
200 if(cfdtime->GetRMS()<=1.5)
201 {
2a1ccb90 202 if(cfdtime->GetRMS()==0 ||cfdtime->GetMean()==0 ) {
203 ok = false;
204 }
e691fec9 205 meancfdtime = cfdtime->GetMean();
206 sigmacfdtime = cfdtime->GetRMS();
207 }
dd92f5b8 208 Int_t maxBin = cfdtime->GetMaximumBin();
209 Double_t meanEstimate = cfdtime->GetBinCenter( maxBin);
210 if(TMath::Abs(meanEstimate - meancfdtime) > 20 ) meancfdtime = meanEstimate;
1e7108ce 211 }
212 }
1e7108ce 213 SetTimeEq(i,meandiff);
214 SetTimeEqRms(i,sigmadiff);
215 SetCFDvalue(i,0,meancfdtime);
1e7108ce 216 if (cfd) delete cfd;
217 if (cfdtime) delete cfdtime;
1e7108ce 218 }
219 TH1F *ver = (TH1F*) gFile->Get("hVertex");
1e7108ce 220 if(ver) {
221 meanver = ver->GetMean();
222 rmsver = ver->GetRMS();
223 }
224 SetMeanVertex(meanver);
225 SetRmsVertex(rmsver);
226
227 gFile->Close();
228 delete gFile;
dd92f5b8 229
1e7108ce 230 }
231 return ok;
232}
233
234//________________________________________________________________
32d3e409 235 Int_t AliT0CalibTimeEq::ComputeOfflineParams(const char* filePhys, Float_t *timecdb, Float_t *cfdvalue, Int_t badpmt)
1e7108ce 236{
32d3e409 237 // fStatus implementation:
238 //ok means
239 // 1000 - can not open file
240 // for timediff
241 // 1-24 no histograms with time diff for more than okdiff channenls
242 // 100 >3 histos are empty
243 // - 1 if less 3 channels are empty ;for these channels OCDB value will be written back WARNING
244 // -2 low statistics in few channels; for these channels OCDB value will be written back WARNING
245 // for cfd
246 // 200 >3 histos are empty
247 // -11 if less 3 channels are empty ;for these channels OCDB value will be written back WARNING
248 // -22 low statistics in few channels; for these channels OCDB value will be written back WARNING
249 //
dd92f5b8 250 // compute offline equalized time
1e7108ce 251 Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
c4ba15c3 252 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
1e7108ce 253 Int_t nent=0;
32d3e409 254 Int_t ok = 0;
255 Int_t okdiff=0;
256 Int_t okcfd=0;
bb54f817 257 TH1F *cfddiff = NULL;
258 TH1F *cfdtime = NULL;
dd92f5b8 259 TObjArray * TzeroObj = NULL;
bb54f817 260
c4ba15c3 261 gFile = TFile::Open(filePhys);
1e7108ce 262 if(!gFile) {
263 AliError("No input PHYS data found ");
32d3e409 264 ok = 1000;
612737bb 265 return ok;
1e7108ce 266 }
267 else
268 {
e691fec9 269 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
612737bb 270 TDirectory *dr = (TDirectory*) gFile->Get("T0Calib");
dd92f5b8 271 if (dr) TzeroObj = (TObjArray*) dr->Get("T0Calib");
612737bb 272 for (Int_t i=0; i<24; i++)
1e7108ce 273 {
b5e0299c 274 if (i != badpmt) {
bb54f817 275 if(TzeroObj) {
276 cfddiff = (TH1F*)TzeroObj->FindObject(Form("CFD1minCFD%d",i+1));
18086258 277 cfdtime = (TH1F*)TzeroObj->FindObject(Form("CFD%d",i+1));
bb54f817 278 }
279 else
280 {
dd92f5b8 281 cfddiff = (TH1F*)gFile->Get(Form("CFD1minCFD%d",i+1));
18086258 282 cfdtime = (TH1F*)gFile->Get(Form("CFD%d",i+1));
283
bb54f817 284 }
18086258 285 if(!cfddiff ) {
32d3e409 286 AliWarning(Form("no histograms collected by pass0 for diff channel %i", i));
287 okdiff++;
288 if(okdiff<4) {
289 meandiff = timecdb[i];
290 sigmadiff = 0;
291 ok = -1;
292 }
293 else
294 return 100+okdiff;
dd92f5b8 295 }
296 if(cfddiff) {
18086258 297 nent = Int_t(cfddiff->GetEntries());
32d3e409 298 if ( nent == 0) {
299 okdiff++;
300 if(okdiff<4) {
301 meandiff = timecdb[i];
302 sigmadiff = 0;
303 ok = - 1;
304 }
305 else
306 return 100;
307 }
308 if(nent<100 && nent>0) { //!!!!!
309 AliWarning(Form(" Not enouph data in PMT %i- PMT1: %i ", i, nent));
310 ok=-2;
311 meandiff = timecdb[i];
312 sigmadiff = 0;
f824d160 313 }
32d3e409 314 if(nent>100 ) { //!!!!!
e691fec9 315 {
32d3e409 316 if(cfddiff->GetRMS()>1.5 )
317 GetMeanAndSigma(cfddiff, meandiff, sigmadiff);
318 if(cfddiff->GetRMS()<=1.5)
319 {
320 meandiff = cfddiff->GetMean();
321 sigmadiff = cfddiff->GetRMS();
322 }
323 Int_t maxBin = cfddiff->GetMaximumBin();
324 Double_t meanEstimate = cfddiff->GetBinCenter( maxBin);
325 if(TMath::Abs(meanEstimate - meandiff) > 20 ) meandiff = meanEstimate;
18086258 326 }
32d3e409 327 }
328 }
18086258 329 if(!cfdtime ) {
330 AliWarning(Form("no histograms collected by pass0 for time channel %i", i));
db082d76 331 meancfdtime = cfdvalue[i];
32d3e409 332 okcfd++;
333 if(okcfd<4) {
334 meancfdtime = cfdvalue[i];
335 ok = -11;
336 }
337 else {
338 AliError(Form("no histograms collected by pass0 for time %i channels ", okcfd));
339 return 200;
340 }
18086258 341 }
342 if(cfdtime) {
343 nent = Int_t(cfdtime->GetEntries());
32d3e409 344 if (nent == 0 ||
345 (cfdtime->GetRMS() == 0 || cfdtime->GetMean() ==0 ) )
346 {
347 okcfd++;
348 if(okcfd<4) {
349 meancfdtime = cfdvalue[i];
350 ok = -11;
351 printf("!!!!bad data:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
352 i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), fCFDvalue[i][0]);
353 }
354 else
355 {
356 printf("!!!!fatal data:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
357 i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), fCFDvalue[i][0]);
358 AliError(Form(" histograms collected by pass0 for time %i channels are empty", okcfd));
359 return 200;
360 }
361 }
362
363
364 if(nent<100 && nent>0 )
365 {
366 AliWarning(Form(" Not enouph data in PMT in CFD peak %i - %i ", i, nent));
367 if(okcfd<4) {
368 meancfdtime = cfdvalue[i];
369 ok = -22;
370 printf("!!!!low statstics:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
371 i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), fCFDvalue[i][0]);
372 }
373 else {
374 printf("!!!!low fatal statstics:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
375 i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), fCFDvalue[i][0]);
376
377 AliError(Form(" Not enouph data in PMT in CFD peak %i in channels ", okcfd));
378 return 200;
379 }
380
381 }
382
383 if( nent>100 && cfdtime->GetRMS() != 0 ) { //!!!!!
18086258 384 if(cfdtime->GetRMS()>1.5 )
385 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
386 if(cfdtime->GetRMS()<=1.5)
387 {
388 meancfdtime = cfdtime->GetMean();
389 sigmacfdtime=cfdtime->GetRMS();
32d3e409 390 }
657abde7 391 Int_t maxBin = cfdtime->GetMaximumBin();
392 Double_t meanEstimate = cfdtime->GetBinCenter( maxBin);
393 if(TMath::Abs(meanEstimate - meancfdtime) > 20 ) meancfdtime = meanEstimate;
1e7108ce 394 }
eef60a6a 395 }
bb54f817 396
b9dd81a7 397 SetTimeEq(i,meandiff);
1e7108ce 398 SetTimeEqRms(i,sigmadiff);
18086258 399 SetCFDvalue(i,0, meancfdtime );
32d3e409 400 printf(" pmt %i diff %f sigma %f meancfdtime %f cdbtime %f \n",i, meandiff, sigmadiff, meancfdtime, fCFDvalue[i][0]);
bb54f817 401 if (cfddiff) cfddiff->Reset();
402 if (cfdtime) cfdtime->Reset();
b5e0299c 403 } //bad pmt
6318dd46 404 }
6318dd46 405
406 gFile->Close();
407 delete gFile;
02888358 408
6318dd46 409 }
02888358 410 return ok;
e691fec9 411 }
a2ad8166 412
1e7108ce 413//________________________________________________________________________
414void AliT0CalibTimeEq::GetMeanAndSigma(TH1F* hist, Float_t &mean, Float_t &sigma) {
612737bb 415
416 const double window = 2.; //fit window
417
1e7108ce 418 double meanEstimate, sigmaEstimate;
419 int maxBin;
420 maxBin = hist->GetMaximumBin(); //position of maximum
421 meanEstimate = hist->GetBinCenter( maxBin); // mean of gaussian sitting in maximum
18086258 422 // sigmaEstimate = hist->GetRMS();
423 sigmaEstimate = 10;
1e7108ce 424 TF1* fit= new TF1("fit","gaus", meanEstimate - window*sigmaEstimate, meanEstimate + window*sigmaEstimate);
425 fit->SetParameters(hist->GetBinContent(maxBin), meanEstimate, sigmaEstimate);
b5e0299c 426 hist->Fit("fit","RQ","Q");
1e7108ce 427
428 mean = (Float_t) fit->GetParameter(1);
429 sigma = (Float_t) fit->GetParameter(2);
430
431 delete fit;
432}
433
8bfd9a3e 434