]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/AliT0CalibTimeEq.cxx
Method: TObjString::GetString() replaced with TObjString::String() in GetFile method...
[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");
104 for (Int_t i=0; i<24; i++) printf(" CFD %f ",fTimeEq[i]);
b95e8d87 105 printf("\n Mean Vertex %f \n", fMeanVertex);
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());
32d3e409 154 if( nent<=50 || cfd->GetRMS() == 0 || cfd->GetMean() ) {
155 okdiff++;
156 if(okdiff<4) {
157 meandiff = 0;
158 sigmadiff = 0;
159 }
160 else
161 {
162 AliWarning(Form(" Not enouph data in PMT %i- PMT1: %i ", i, nent));
163 ok = false;
164 }
165 }
18086258 166 if(nent>50) {
612737bb 167 if(cfd->GetRMS()>1.5 )
e691fec9 168 GetMeanAndSigma(cfd, meandiff, sigmadiff);
169 if(cfd->GetRMS()<=1.5)
170 {
171 meandiff = cfd->GetMean();
172 sigmadiff=cfd->GetRMS();
173 }
dd92f5b8 174 Int_t maxBin = cfd->GetMaximumBin();
175 Double_t meanEstimate = cfd->GetBinCenter( maxBin);
176 if(TMath::Abs(meanEstimate - meandiff) > 20 ) meandiff = meanEstimate;
1e7108ce 177 }
1e7108ce 178 }
32d3e409 179
1e7108ce 180 if(cfdtime) {
e691fec9 181 nent = Int_t(cfdtime->GetEntries());
391e1406 182 if( nent<=50 || cfdtime->GetRMS() == 0 || cfdtime->GetMean() ) {
32d3e409 183 oktime++;
184 if(oktime<4) {
185 meancfdtime = 0;
186 }
187 else
188 {
189 AliWarning(Form(" Not enouph data in PMT %i: %i ", i, nent));
190 ok = false;
191 }
192 }
18086258 193 if(nent > 50 ) { //!!!!!!!!!!
b5e0299c 194 if(cfdtime->GetRMS()>1.5 )
e691fec9 195 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
196 if(cfdtime->GetRMS()<=1.5)
197 {
198 meancfdtime = cfdtime->GetMean();
199 sigmacfdtime = cfdtime->GetRMS();
200 }
dd92f5b8 201 Int_t maxBin = cfdtime->GetMaximumBin();
202 Double_t meanEstimate = cfdtime->GetBinCenter( maxBin);
203 if(TMath::Abs(meanEstimate - meancfdtime) > 20 ) meancfdtime = meanEstimate;
1e7108ce 204 }
205 }
1e7108ce 206 SetTimeEq(i,meandiff);
207 SetTimeEqRms(i,sigmadiff);
208 SetCFDvalue(i,0,meancfdtime);
1e7108ce 209 if (cfd) delete cfd;
210 if (cfdtime) delete cfdtime;
1e7108ce 211 }
212 TH1F *ver = (TH1F*) gFile->Get("hVertex");
1e7108ce 213 if(ver) {
214 meanver = ver->GetMean();
215 rmsver = ver->GetRMS();
216 }
217 SetMeanVertex(meanver);
218 SetRmsVertex(rmsver);
219
220 gFile->Close();
221 delete gFile;
dd92f5b8 222
1e7108ce 223 }
224 return ok;
225}
226
227//________________________________________________________________
32d3e409 228 Int_t AliT0CalibTimeEq::ComputeOfflineParams(const char* filePhys, Float_t *timecdb, Float_t *cfdvalue, Int_t badpmt)
1e7108ce 229{
32d3e409 230 // fStatus implementation:
231 //ok means
232 // 1000 - can not open file
233 // for timediff
234 // 1-24 no histograms with time diff for more than okdiff channenls
235 // 100 >3 histos are empty
236 // - 1 if less 3 channels are empty ;for these channels OCDB value will be written back WARNING
237 // -2 low statistics in few channels; for these channels OCDB value will be written back WARNING
238 // for cfd
239 // 200 >3 histos are empty
240 // -11 if less 3 channels are empty ;for these channels OCDB value will be written back WARNING
241 // -22 low statistics in few channels; for these channels OCDB value will be written back WARNING
242 //
dd92f5b8 243 // compute offline equalized time
1e7108ce 244 Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
c4ba15c3 245 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
1e7108ce 246 Int_t nent=0;
32d3e409 247 Int_t ok = 0;
248 Int_t okdiff=0;
249 Int_t okcfd=0;
bb54f817 250 TH1F *cfddiff = NULL;
251 TH1F *cfdtime = NULL;
dd92f5b8 252 TObjArray * TzeroObj = NULL;
bb54f817 253
c4ba15c3 254 gFile = TFile::Open(filePhys);
1e7108ce 255 if(!gFile) {
256 AliError("No input PHYS data found ");
32d3e409 257 ok = 1000;
612737bb 258 return ok;
1e7108ce 259 }
260 else
261 {
e691fec9 262 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
612737bb 263 TDirectory *dr = (TDirectory*) gFile->Get("T0Calib");
dd92f5b8 264 if (dr) TzeroObj = (TObjArray*) dr->Get("T0Calib");
612737bb 265 for (Int_t i=0; i<24; i++)
1e7108ce 266 {
b5e0299c 267 if (i != badpmt) {
bb54f817 268 if(TzeroObj) {
269 cfddiff = (TH1F*)TzeroObj->FindObject(Form("CFD1minCFD%d",i+1));
18086258 270 cfdtime = (TH1F*)TzeroObj->FindObject(Form("CFD%d",i+1));
bb54f817 271 }
272 else
273 {
dd92f5b8 274 cfddiff = (TH1F*)gFile->Get(Form("CFD1minCFD%d",i+1));
18086258 275 cfdtime = (TH1F*)gFile->Get(Form("CFD%d",i+1));
276
bb54f817 277 }
18086258 278 if(!cfddiff ) {
32d3e409 279 AliWarning(Form("no histograms collected by pass0 for diff channel %i", i));
280 okdiff++;
281 if(okdiff<4) {
282 meandiff = timecdb[i];
283 sigmadiff = 0;
284 ok = -1;
285 }
286 else
287 return 100+okdiff;
dd92f5b8 288 }
289 if(cfddiff) {
18086258 290 nent = Int_t(cfddiff->GetEntries());
32d3e409 291 if ( nent == 0) {
292 okdiff++;
293 if(okdiff<4) {
294 meandiff = timecdb[i];
295 sigmadiff = 0;
296 ok = - 1;
297 }
298 else
299 return 100;
300 }
301 if(nent<100 && nent>0) { //!!!!!
302 AliWarning(Form(" Not enouph data in PMT %i- PMT1: %i ", i, nent));
303 ok=-2;
304 meandiff = timecdb[i];
305 sigmadiff = 0;
f824d160 306 }
32d3e409 307 if(nent>100 ) { //!!!!!
e691fec9 308 {
32d3e409 309 if(cfddiff->GetRMS()>1.5 )
310 GetMeanAndSigma(cfddiff, meandiff, sigmadiff);
311 if(cfddiff->GetRMS()<=1.5)
312 {
313 meandiff = cfddiff->GetMean();
314 sigmadiff = cfddiff->GetRMS();
315 }
316 Int_t maxBin = cfddiff->GetMaximumBin();
317 Double_t meanEstimate = cfddiff->GetBinCenter( maxBin);
318 if(TMath::Abs(meanEstimate - meandiff) > 20 ) meandiff = meanEstimate;
18086258 319 }
32d3e409 320 }
321 }
18086258 322 if(!cfdtime ) {
323 AliWarning(Form("no histograms collected by pass0 for time channel %i", i));
db082d76 324 meancfdtime = cfdvalue[i];
32d3e409 325 okcfd++;
326 if(okcfd<4) {
327 meancfdtime = cfdvalue[i];
328 ok = -11;
329 }
330 else {
331 AliError(Form("no histograms collected by pass0 for time %i channels ", okcfd));
332 return 200;
333 }
18086258 334 }
335 if(cfdtime) {
336 nent = Int_t(cfdtime->GetEntries());
32d3e409 337 if (nent == 0 ||
338 (cfdtime->GetRMS() == 0 || cfdtime->GetMean() ==0 ) )
339 {
340 okcfd++;
341 if(okcfd<4) {
342 meancfdtime = cfdvalue[i];
343 ok = -11;
344 printf("!!!!bad data:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
345 i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), fCFDvalue[i][0]);
346 }
347 else
348 {
349 printf("!!!!fatal data:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
350 i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), fCFDvalue[i][0]);
351 AliError(Form(" histograms collected by pass0 for time %i channels are empty", okcfd));
352 return 200;
353 }
354 }
355
356
357 if(nent<100 && nent>0 )
358 {
359 AliWarning(Form(" Not enouph data in PMT in CFD peak %i - %i ", i, nent));
360 if(okcfd<4) {
361 meancfdtime = cfdvalue[i];
362 ok = -22;
363 printf("!!!!low statstics:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
364 i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), fCFDvalue[i][0]);
365 }
366 else {
367 printf("!!!!low fatal statstics:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
368 i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), fCFDvalue[i][0]);
369
370 AliError(Form(" Not enouph data in PMT in CFD peak %i in channels ", okcfd));
371 return 200;
372 }
373
374 }
375
376 if( nent>100 && cfdtime->GetRMS() != 0 ) { //!!!!!
18086258 377 if(cfdtime->GetRMS()>1.5 )
378 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
379 if(cfdtime->GetRMS()<=1.5)
380 {
381 meancfdtime = cfdtime->GetMean();
382 sigmacfdtime=cfdtime->GetRMS();
32d3e409 383 }
657abde7 384 Int_t maxBin = cfdtime->GetMaximumBin();
385 Double_t meanEstimate = cfdtime->GetBinCenter( maxBin);
386 if(TMath::Abs(meanEstimate - meancfdtime) > 20 ) meancfdtime = meanEstimate;
1e7108ce 387 }
eef60a6a 388 }
bb54f817 389
b9dd81a7 390 SetTimeEq(i,meandiff);
1e7108ce 391 SetTimeEqRms(i,sigmadiff);
18086258 392 SetCFDvalue(i,0, meancfdtime );
32d3e409 393 printf(" pmt %i diff %f sigma %f meancfdtime %f cdbtime %f \n",i, meandiff, sigmadiff, meancfdtime, fCFDvalue[i][0]);
bb54f817 394 if (cfddiff) cfddiff->Reset();
395 if (cfdtime) cfdtime->Reset();
b5e0299c 396 } //bad pmt
6318dd46 397 }
6318dd46 398
399 gFile->Close();
400 delete gFile;
02888358 401
6318dd46 402 }
02888358 403 return ok;
e691fec9 404 }
a2ad8166 405
1e7108ce 406//________________________________________________________________________
407void AliT0CalibTimeEq::GetMeanAndSigma(TH1F* hist, Float_t &mean, Float_t &sigma) {
612737bb 408
409 const double window = 2.; //fit window
410
1e7108ce 411 double meanEstimate, sigmaEstimate;
412 int maxBin;
413 maxBin = hist->GetMaximumBin(); //position of maximum
414 meanEstimate = hist->GetBinCenter( maxBin); // mean of gaussian sitting in maximum
18086258 415 // sigmaEstimate = hist->GetRMS();
416 sigmaEstimate = 10;
1e7108ce 417 TF1* fit= new TF1("fit","gaus", meanEstimate - window*sigmaEstimate, meanEstimate + window*sigmaEstimate);
418 fit->SetParameters(hist->GetBinContent(maxBin), meanEstimate, sigmaEstimate);
b5e0299c 419 hist->Fit("fit","RQ","Q");
1e7108ce 420
421 mean = (Float_t) fit->GetParameter(1);
422 sigma = (Float_t) fit->GetParameter(2);
423
424 delete fit;
425}
426
8bfd9a3e 427