Handle friend chain name in GetChainForTestMode
[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;
61bd03f6 120 //
c2337900 121 gFile = TFile::Open(filePhys);
370867d2 122 if(!gFile) {
6318dd46 123 AliError("No input PHYS data found ");
124 }
125 else
126 {
02888358 127 ok=true;
6318dd46 128 for (Int_t i=0; i<24; i++)
129 {
e691fec9 130 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
61bd03f6 131 TH1F *cfd = (TH1F*) gFile->Get(Form("CFD1minCFD%d",i+1));
1e7108ce 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 }
61bd03f6 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);
1e7108ce 226 gFile->Close();
227 delete gFile;
1e7108ce 228 }
229 return ok;
230}
231
232//________________________________________________________________
61bd03f6 233Int_t AliT0CalibTimeEq::ComputeOfflineParams(const char* filePhys, Float_t *timecdb, Float_t *cfdvalue, Int_t badpmt)
1e7108ce 234{
32d3e409 235 // fStatus implementation:
236 //ok means
237 // 1000 - can not open file
238 // for timediff
239 // 1-24 no histograms with time diff for more than okdiff channenls
240 // 100 >3 histos are empty
241 // - 1 if less 3 channels are empty ;for these channels OCDB value will be written back WARNING
242 // -2 low statistics in few channels; for these channels OCDB value will be written back WARNING
243 // for cfd
244 // 200 >3 histos are empty
245 // -11 if less 3 channels are empty ;for these channels OCDB value will be written back WARNING
246 // -22 low statistics in few channels; for these channels OCDB value will be written back WARNING
247 //
dd92f5b8 248 // compute offline equalized time
1e7108ce 249 Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
c4ba15c3 250 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
1e7108ce 251 Int_t nent=0;
32d3e409 252 Int_t ok = 0;
253 Int_t okdiff=0;
254 Int_t okcfd=0;
bb54f817 255 TH1F *cfddiff = NULL;
256 TH1F *cfdtime = NULL;
61bd03f6 257 TObjArray * tzeroObj = NULL;
bb54f817 258
c4ba15c3 259 gFile = TFile::Open(filePhys);
1e7108ce 260 if(!gFile) {
261 AliError("No input PHYS data found ");
32d3e409 262 ok = 1000;
612737bb 263 return ok;
1e7108ce 264 }
265 else
266 {
e691fec9 267 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
61bd03f6 268 // TDirectory *dr = (TDirectory*) gFile->Get("T0Calib");
269 tzeroObj = dynamic_cast<TObjArray*>(gFile->Get("T0Calib"));
612737bb 270 for (Int_t i=0; i<24; i++)
1e7108ce 271 {
61bd03f6 272 if (i != badpmt) {
273 if(tzeroObj) {
274 cfddiff = (TH1F*) tzeroObj->FindObject(Form("CFD1minCFD%d",i+1));
275 cfdtime = (TH1F*)tzeroObj->FindObject(Form("CFD%d",i+1));
bb54f817 276 }
277 else
278 {
dd92f5b8 279 cfddiff = (TH1F*)gFile->Get(Form("CFD1minCFD%d",i+1));
18086258 280 cfdtime = (TH1F*)gFile->Get(Form("CFD%d",i+1));
281
bb54f817 282 }
18086258 283 if(!cfddiff ) {
32d3e409 284 AliWarning(Form("no histograms collected by pass0 for diff channel %i", i));
285 okdiff++;
286 if(okdiff<4) {
287 meandiff = timecdb[i];
288 sigmadiff = 0;
289 ok = -1;
290 }
291 else
292 return 100+okdiff;
dd92f5b8 293 }
294 if(cfddiff) {
18086258 295 nent = Int_t(cfddiff->GetEntries());
32d3e409 296 if ( nent == 0) {
297 okdiff++;
298 if(okdiff<4) {
299 meandiff = timecdb[i];
300 sigmadiff = 0;
301 ok = - 1;
302 }
303 else
304 return 100;
305 }
306 if(nent<100 && nent>0) { //!!!!!
307 AliWarning(Form(" Not enouph data in PMT %i- PMT1: %i ", i, nent));
308 ok=-2;
309 meandiff = timecdb[i];
310 sigmadiff = 0;
f824d160 311 }
32d3e409 312 if(nent>100 ) { //!!!!!
e691fec9 313 {
32d3e409 314 if(cfddiff->GetRMS()>1.5 )
315 GetMeanAndSigma(cfddiff, meandiff, sigmadiff);
316 if(cfddiff->GetRMS()<=1.5)
317 {
318 meandiff = cfddiff->GetMean();
319 sigmadiff = cfddiff->GetRMS();
320 }
321 Int_t maxBin = cfddiff->GetMaximumBin();
322 Double_t meanEstimate = cfddiff->GetBinCenter( maxBin);
323 if(TMath::Abs(meanEstimate - meandiff) > 20 ) meandiff = meanEstimate;
18086258 324 }
32d3e409 325 }
326 }
18086258 327 if(!cfdtime ) {
328 AliWarning(Form("no histograms collected by pass0 for time channel %i", i));
db082d76 329 meancfdtime = cfdvalue[i];
32d3e409 330 okcfd++;
331 if(okcfd<4) {
332 meancfdtime = cfdvalue[i];
333 ok = -11;
334 }
335 else {
336 AliError(Form("no histograms collected by pass0 for time %i channels ", okcfd));
337 return 200;
338 }
18086258 339 }
340 if(cfdtime) {
341 nent = Int_t(cfdtime->GetEntries());
32d3e409 342 if (nent == 0 ||
343 (cfdtime->GetRMS() == 0 || cfdtime->GetMean() ==0 ) )
344 {
345 okcfd++;
346 if(okcfd<4) {
347 meancfdtime = cfdvalue[i];
348 ok = -11;
349 printf("!!!!bad data:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
350 i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), fCFDvalue[i][0]);
351 }
352 else
353 {
354 printf("!!!!fatal data:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
355 i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), fCFDvalue[i][0]);
356 AliError(Form(" histograms collected by pass0 for time %i channels are empty", okcfd));
357 return 200;
358 }
359 }
360
361
362 if(nent<100 && nent>0 )
363 {
364 AliWarning(Form(" Not enouph data in PMT in CFD peak %i - %i ", i, nent));
365 if(okcfd<4) {
366 meancfdtime = cfdvalue[i];
367 ok = -22;
368 printf("!!!!low statstics:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
369 i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), fCFDvalue[i][0]);
370 }
371 else {
372 printf("!!!!low fatal statstics:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
373 i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), fCFDvalue[i][0]);
374
375 AliError(Form(" Not enouph data in PMT in CFD peak %i in channels ", okcfd));
376 return 200;
377 }
378
379 }
380
381 if( nent>100 && cfdtime->GetRMS() != 0 ) { //!!!!!
18086258 382 if(cfdtime->GetRMS()>1.5 )
383 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
384 if(cfdtime->GetRMS()<=1.5)
385 {
386 meancfdtime = cfdtime->GetMean();
387 sigmacfdtime=cfdtime->GetRMS();
32d3e409 388 }
657abde7 389 Int_t maxBin = cfdtime->GetMaximumBin();
390 Double_t meanEstimate = cfdtime->GetBinCenter( maxBin);
391 if(TMath::Abs(meanEstimate - meancfdtime) > 20 ) meancfdtime = meanEstimate;
1e7108ce 392 }
eef60a6a 393 }
bb54f817 394
b9dd81a7 395 SetTimeEq(i,meandiff);
1e7108ce 396 SetTimeEqRms(i,sigmadiff);
18086258 397 SetCFDvalue(i,0, meancfdtime );
32d3e409 398 printf(" pmt %i diff %f sigma %f meancfdtime %f cdbtime %f \n",i, meandiff, sigmadiff, meancfdtime, fCFDvalue[i][0]);
bb54f817 399 if (cfddiff) cfddiff->Reset();
400 if (cfdtime) cfdtime->Reset();
b5e0299c 401 } //bad pmt
61bd03f6 402 }
6318dd46 403 gFile->Close();
404 delete gFile;
6318dd46 405 }
02888358 406 return ok;
e691fec9 407 }
a2ad8166 408
1e7108ce 409//________________________________________________________________________
410void AliT0CalibTimeEq::GetMeanAndSigma(TH1F* hist, Float_t &mean, Float_t &sigma) {
612737bb 411
412 const double window = 2.; //fit window
413
1e7108ce 414 double meanEstimate, sigmaEstimate;
415 int maxBin;
416 maxBin = hist->GetMaximumBin(); //position of maximum
417 meanEstimate = hist->GetBinCenter( maxBin); // mean of gaussian sitting in maximum
18086258 418 // sigmaEstimate = hist->GetRMS();
419 sigmaEstimate = 10;
1e7108ce 420 TF1* fit= new TF1("fit","gaus", meanEstimate - window*sigmaEstimate, meanEstimate + window*sigmaEstimate);
421 fit->SetParameters(hist->GetBinContent(maxBin), meanEstimate, sigmaEstimate);
b5e0299c 422 hist->Fit("fit","RQ","Q");
1e7108ce 423
424 mean = (Float_t) fit->GetParameter(1);
425 sigma = (Float_t) fit->GetParameter(2);
426
427 delete fit;
428}
429
8bfd9a3e 430