2 /**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 ///////////////////////////////////////////////////////////////////////////////
21 // class for T0 calibration TM-AC-AM_6-02-2006
22 // equalize time shift for each time CFD channel
24 ///////////////////////////////////////////////////////////////////////////////
26 #include "AliT0CalibTimeEq.h"
31 #include <TSpectrum.h>
35 ClassImp(AliT0CalibTimeEq)
37 //________________________________________________________________
38 AliT0CalibTimeEq::AliT0CalibTimeEq():TNamed(),
43 for(Int_t i=0; i<24; i++) {
44 fTimeEq[i] = 0; // Time Equalized for OCDB
45 fTimeEqRms[i] = -1; // RMS of Time Equalized for OCDB
46 for (Int_t ih=0; ih<5; ih++) fCFDvalue[i][ih] = 0;
50 //________________________________________________________________
51 AliT0CalibTimeEq::AliT0CalibTimeEq(const char* name):TNamed(),
57 TString namst = "Calib_";
59 SetName(namst.Data());
60 SetTitle(namst.Data());
61 for(Int_t i=0; i<24; i++) {
62 fTimeEq[i] = 0; // Time Equalized for OCDB
63 fTimeEqRms[i] = -1; // RMS of Time Equalized for OCDB
64 for (Int_t ih=0; ih<5; ih++) fCFDvalue[i][ih] = 0;
68 //________________________________________________________________
69 AliT0CalibTimeEq::AliT0CalibTimeEq(const AliT0CalibTimeEq& calibda):TNamed(calibda),
74 SetName(calibda.GetName());
75 SetTitle(calibda.GetName());
76 ((AliT0CalibTimeEq &) calibda).Copy(*this);
80 //________________________________________________________________
81 AliT0CalibTimeEq &AliT0CalibTimeEq::operator =(const AliT0CalibTimeEq& calibda)
83 // assignment operator
84 SetName(calibda.GetName());
85 SetTitle(calibda.GetName());
87 if (this != &calibda) (( AliT0CalibTimeEq &) calibda).Copy(*this);
91 //________________________________________________________________
92 AliT0CalibTimeEq::~AliT0CalibTimeEq()
97 //________________________________________________________________
98 void AliT0CalibTimeEq::Reset()
102 memset(fCFDvalue,0,120*sizeof(Float_t));
103 memset(fTimeEq,1,24*sizeof(Float_t));
107 //________________________________________________________________
108 void AliT0CalibTimeEq::Print(Option_t*) const
112 printf("\n ---- PM Arrays ----\n\n");
113 printf(" Time delay CFD \n");
114 for (Int_t i=0; i<24; i++)
115 printf(" CFD %f diff %f \n",fCFDvalue[i][0],fTimeEq[i]);
119 //________________________________________________________________
120 Bool_t AliT0CalibTimeEq::ComputeOnlineParams(const char* filePhys)
122 // compute online equalized time
123 Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
124 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
131 gFile = TFile::Open(filePhys);
133 AliError("No input PHYS data found ");
138 for (Int_t i=0; i<24; i++)
140 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
141 TH1F *cfd = (TH1F*) gFile->Get(Form("CFD1minCFD%d",i+1));
142 TH1F *cfdtime = (TH1F*) gFile->Get(Form("CFD%d",i+1));
144 AliWarning(Form("no Diff histograms collected by PHYS DA for channel %i", i));
154 AliWarning(Form("no CFD histograms collected by PHYS DA for channel %i", i));
163 nent = Int_t(cfd->GetEntries());
166 // printf(" pmt %i nent %i cfd->GetRMS() %f cfd->GetMean() %f \n",
167 // i, nent, cfd->GetRMS(), cfd->GetMean() );
174 // printf(" OK fsle:: pmt %i nent %i cfd->GetRMS() %f cfd->GetMean() %f \n",
175 // i, nent, cfd->GetRMS(), cfd->GetMean() );
176 AliWarning(Form(" Not enouph data in PMT %i- PMT1: %i ", i, nent));
181 if(cfd->GetRMS()>1.5 )
182 GetMeanAndSigma(cfd, meandiff, sigmadiff);
183 if(cfd->GetRMS()<=1.5)
185 meandiff = cfd->GetMean();
186 sigmadiff=cfd->GetRMS();
188 Int_t maxBin = cfd->GetMaximumBin();
189 Double_t meanEstimate = cfd->GetBinCenter( maxBin);
190 if(TMath::Abs(meanEstimate - meandiff) > 20 ) meandiff = meanEstimate;
195 nent = Int_t(cfdtime->GetEntries());
203 AliWarning(Form(" Not enouph data in PMT %i: %i ", i, nent));
207 if(nent > 50 ) { //!!!!!!!!!!
208 if(cfdtime->GetRMS()>1.5 )
209 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
210 if(cfdtime->GetRMS()<=1.5)
212 if(cfdtime->GetRMS()==0 ||cfdtime->GetMean()==0 ) {
215 meancfdtime = cfdtime->GetMean();
216 sigmacfdtime = cfdtime->GetRMS();
218 Int_t maxBin = cfdtime->GetMaximumBin();
219 Double_t meanEstimate = cfdtime->GetBinCenter( maxBin);
220 if(TMath::Abs(meanEstimate - meancfdtime) > 20 ) meancfdtime = meanEstimate;
223 SetTimeEq(i,meandiff);
224 SetTimeEqRms(i,sigmadiff);
225 SetCFDvalue(i,0,meancfdtime);
227 if (cfdtime) delete cfdtime;
229 TH1F *ver = (TH1F*) gFile->Get("hVertex") ;
231 meanver = ver->GetMean();
232 rmsver = ver->GetRMS();
234 SetMeanVertex(meanver);
235 SetRmsVertex(rmsver);
242 //________________________________________________________________
243 Int_t AliT0CalibTimeEq::ComputeOfflineParams(const char* filePhys, Float_t *timecdb, Float_t *cfdvalue, Int_t badpmt)
245 // fStatus implementation:
247 // 1000 - can not open file
249 // 20 >3 histos are empty
250 // -11 low statistics oe empty histos in few channels; for these channels OCDB value will be written back WARNING
252 // 20 >2 histos are empty or with low statistic
253 // -11 if less 3 channels are empty or low statistics in few channels ;for these channels OCDB value will be written back WARNING
255 // compute offline equalized time
256 Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
257 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
261 TH1F *cfddiff = NULL;
262 TH1F *cfdtime = NULL;
263 TObjArray * tzeroObj = NULL;
265 gFile = TFile::Open(filePhys);
267 AliError("No input PHYS data found ");
273 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
274 // TDirectory *dr = (TDirectory*) gFile->Get("T0Calib");
275 tzeroObj = dynamic_cast<TObjArray*>(gFile->Get("T0Calib"));
276 for (Int_t i=0; i<24; i++)
280 cfddiff = (TH1F*) tzeroObj->FindObject(Form("CFD1minCFD%d",i+1));
281 cfdtime = (TH1F*)tzeroObj->FindObject(Form("CFD%d",i+1));
285 cfddiff = (TH1F*)gFile->Get(Form("CFD1minCFD%d",i+1));
286 cfdtime = (TH1F*)gFile->Get(Form("CFD%d",i+1));
290 AliWarning(Form("no histograms collected by pass0 for diff channel %i\n", i));
291 meandiff = timecdb[i];
295 nent = Int_t(cfddiff->GetEntries());
297 AliWarning(Form("no entries in histogram for diff channel %i\n", i));
298 meandiff = timecdb[i];
301 if(nent<=100 && nent>0) { //!!!!!
302 AliWarning(Form(" Not enouph data in PMT %i- PMT1: %i \n", i, nent));
303 meandiff = timecdb[i];
306 if(nent>=100 ) { //!!!!!
308 if(cfddiff->GetRMS()>1.5 )
309 GetMeanAndSigma(cfddiff, meandiff, sigmadiff);
310 if(cfddiff->GetRMS()<=1.5)
312 meandiff = cfddiff->GetMean();
313 sigmadiff = cfddiff->GetRMS();
315 Int_t maxBin = cfddiff->GetMaximumBin();
316 Double_t meanEstimate = cfddiff->GetBinCenter( maxBin);
317 if(TMath::Abs(meanEstimate - meandiff) > 20 ) meandiff = meanEstimate;
322 AliWarning(Form("no histograms collected by pass0 for time channel %i", i));
323 meancfdtime = cfdvalue[i];
326 meancfdtime = cfdvalue[i];
330 AliError(Form("no histograms collected by pass0 for time %i channels ", okcfd));
331 if (tzeroObj) delete tzeroObj;
336 nent = Int_t(cfdtime->GetEntries());
338 (cfdtime->GetRMS() == 0 || cfdtime->GetMean() ==0 ) )
342 meancfdtime = cfdvalue[i];
344 printf("!!!!bad data:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
345 i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), cfdvalue[i] );
349 printf("!!!!fatal data:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
350 i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), cfdvalue[i]);
351 AliError(Form(" histograms collected by pass0 for time %i channels are empty", okcfd));
352 if (tzeroObj) delete tzeroObj;
358 if(nent<=100 && nent>0 )
361 AliWarning(Form(" Not enouph data in PMT in CFD peak %i - %i ", i, nent));
362 meancfdtime = cfdvalue[i];
364 printf("!!!!low statstics:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
365 i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), cfdvalue[i]);
368 if (tzeroObj) delete tzeroObj;
373 if( nent>100 ) { //!!!!!
374 if(cfdtime->GetRMS()>1.5 )
375 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
376 if(cfdtime->GetRMS()<=1.5)
378 meancfdtime = cfdtime->GetMean();
379 sigmacfdtime=cfdtime->GetRMS();
381 Int_t maxBin = cfdtime->GetMaximumBin();
382 Double_t meanEstimate = cfdtime->GetBinCenter( maxBin);
383 if(TMath::Abs(meanEstimate - meancfdtime) > 20 ) meancfdtime = meanEstimate;
387 SetTimeEq(i,meandiff);
388 SetTimeEqRms(i,sigmadiff);
389 SetCFDvalue(i,0, meancfdtime );
390 if (cfddiff) cfddiff->Reset();
391 if (cfdtime) cfdtime->Reset();
397 if (tzeroObj) delete tzeroObj;
401 //________________________________________________________________________
402 void AliT0CalibTimeEq::GetMeanAndSigma(TH1F* hist, Float_t &mean, Float_t &sigma) {
404 const double window = 5.; //fit window
405 double meanEstimate, sigmaEstimate;
407 maxBin = hist->GetMaximumBin(); //position of maximum
408 meanEstimate = hist->GetBinCenter( maxBin); // mean of gaussian sitting in maximum
409 sigmaEstimate = hist->GetRMS();
410 // sigmaEstimate = 10;
411 TF1* fit= new TF1("fit","gaus", meanEstimate - window*sigmaEstimate, meanEstimate + window*sigmaEstimate);
412 fit->SetParameters(hist->GetBinContent(maxBin), meanEstimate, sigmaEstimate);
413 hist->Fit("fit","QR","");
415 mean = (Float_t) fit->GetParameter(1);
416 sigma = (Float_t) fit->GetParameter(2);