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(),
46 //________________________________________________________________
47 AliT0CalibTimeEq::AliT0CalibTimeEq(const char* name):TNamed(),
53 TString namst = "Calib_";
55 SetName(namst.Data());
56 SetTitle(namst.Data());
59 //________________________________________________________________
60 AliT0CalibTimeEq::AliT0CalibTimeEq(const AliT0CalibTimeEq& calibda):TNamed(calibda),
65 SetName(calibda.GetName());
66 SetTitle(calibda.GetName());
71 //________________________________________________________________
72 AliT0CalibTimeEq &AliT0CalibTimeEq::operator =(const AliT0CalibTimeEq& calibda)
74 // assignment operator
75 SetName(calibda.GetName());
76 SetTitle(calibda.GetName());
81 //________________________________________________________________
82 AliT0CalibTimeEq::~AliT0CalibTimeEq()
87 //________________________________________________________________
88 void AliT0CalibTimeEq::Reset()
92 memset(fCFDvalue,0,120*sizeof(Float_t));
93 memset(fTimeEq,1,24*sizeof(Float_t));
97 //________________________________________________________________
98 void AliT0CalibTimeEq::Print(Option_t*) const
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]);
105 printf("\n Mean Vertex %f \n", fMeanVertex);
109 //________________________________________________________________
110 Bool_t AliT0CalibTimeEq::ComputeOnlineParams(const char* filePhys)
112 // compute online equalized time
113 Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
114 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
120 gFile = TFile::Open(filePhys);
122 AliError("No input PHYS data found ");
127 for (Int_t i=0; i<24; i++)
130 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
131 TH1F *cfd = (TH1F*) gFile->Get(Form("CFD1minCFD%d",i+1));
132 TH1F *cfdtime = (TH1F*) gFile->Get(Form("CFD%d",i+1));
134 AliWarning(Form("no Diff histograms collected by PHYS DA for channel %i", i));
144 AliWarning(Form("no CFD histograms collected by PHYS DA for channel %i", i));
153 nent = Int_t(cfd->GetEntries());
154 if( nent<=50 || cfd->GetRMS() == 0 || cfd->GetMean() ) {
162 AliWarning(Form(" Not enouph data in PMT %i- PMT1: %i ", i, nent));
167 if(cfd->GetRMS()>1.5 )
168 GetMeanAndSigma(cfd, meandiff, sigmadiff);
169 if(cfd->GetRMS()<=1.5)
171 meandiff = cfd->GetMean();
172 sigmadiff=cfd->GetRMS();
174 Int_t maxBin = cfd->GetMaximumBin();
175 Double_t meanEstimate = cfd->GetBinCenter( maxBin);
176 if(TMath::Abs(meanEstimate - meandiff) > 20 ) meandiff = meanEstimate;
181 nent = Int_t(cfdtime->GetEntries());
182 if( nent<=50 || cfdtime->GetRMS() == 0 || cfdtime->GetMean() ) {
189 AliWarning(Form(" Not enouph data in PMT %i: %i ", i, nent));
193 if(nent > 50 ) { //!!!!!!!!!!
194 if(cfdtime->GetRMS()>1.5 )
195 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
196 if(cfdtime->GetRMS()<=1.5)
198 meancfdtime = cfdtime->GetMean();
199 sigmacfdtime = cfdtime->GetRMS();
201 Int_t maxBin = cfdtime->GetMaximumBin();
202 Double_t meanEstimate = cfdtime->GetBinCenter( maxBin);
203 if(TMath::Abs(meanEstimate - meancfdtime) > 20 ) meancfdtime = meanEstimate;
206 SetTimeEq(i,meandiff);
207 SetTimeEqRms(i,sigmadiff);
208 SetCFDvalue(i,0,meancfdtime);
210 if (cfdtime) delete cfdtime;
212 TH1F *ver = (TH1F*) gFile->Get("hVertex");
214 meanver = ver->GetMean();
215 rmsver = ver->GetRMS();
217 SetMeanVertex(meanver);
218 SetRmsVertex(rmsver);
227 //________________________________________________________________
228 Int_t AliT0CalibTimeEq::ComputeOfflineParams(const char* filePhys, Float_t *timecdb, Float_t *cfdvalue, Int_t badpmt)
230 // fStatus implementation:
232 // 1000 - can not open file
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
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
243 // compute offline equalized time
244 Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
245 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
250 TH1F *cfddiff = NULL;
251 TH1F *cfdtime = NULL;
252 TObjArray * TzeroObj = NULL;
254 gFile = TFile::Open(filePhys);
256 AliError("No input PHYS data found ");
262 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
263 TDirectory *dr = (TDirectory*) gFile->Get("T0Calib");
264 if (dr) TzeroObj = (TObjArray*) dr->Get("T0Calib");
265 for (Int_t i=0; i<24; i++)
269 cfddiff = (TH1F*)TzeroObj->FindObject(Form("CFD1minCFD%d",i+1));
270 cfdtime = (TH1F*)TzeroObj->FindObject(Form("CFD%d",i+1));
274 cfddiff = (TH1F*)gFile->Get(Form("CFD1minCFD%d",i+1));
275 cfdtime = (TH1F*)gFile->Get(Form("CFD%d",i+1));
279 AliWarning(Form("no histograms collected by pass0 for diff channel %i", i));
282 meandiff = timecdb[i];
290 nent = Int_t(cfddiff->GetEntries());
294 meandiff = timecdb[i];
301 if(nent<100 && nent>0) { //!!!!!
302 AliWarning(Form(" Not enouph data in PMT %i- PMT1: %i ", i, nent));
304 meandiff = timecdb[i];
307 if(nent>100 ) { //!!!!!
309 if(cfddiff->GetRMS()>1.5 )
310 GetMeanAndSigma(cfddiff, meandiff, sigmadiff);
311 if(cfddiff->GetRMS()<=1.5)
313 meandiff = cfddiff->GetMean();
314 sigmadiff = cfddiff->GetRMS();
316 Int_t maxBin = cfddiff->GetMaximumBin();
317 Double_t meanEstimate = cfddiff->GetBinCenter( maxBin);
318 if(TMath::Abs(meanEstimate - meandiff) > 20 ) meandiff = meanEstimate;
323 AliWarning(Form("no histograms collected by pass0 for time channel %i", i));
324 meancfdtime = cfdvalue[i];
327 meancfdtime = cfdvalue[i];
331 AliError(Form("no histograms collected by pass0 for time %i channels ", okcfd));
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(), fCFDvalue[i][0]);
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));
357 if(nent<100 && nent>0 )
359 AliWarning(Form(" Not enouph data in PMT in CFD peak %i - %i ", i, nent));
361 meancfdtime = cfdvalue[i];
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]);
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]);
370 AliError(Form(" Not enouph data in PMT in CFD peak %i in channels ", okcfd));
376 if( nent>100 && cfdtime->GetRMS() != 0 ) { //!!!!!
377 if(cfdtime->GetRMS()>1.5 )
378 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
379 if(cfdtime->GetRMS()<=1.5)
381 meancfdtime = cfdtime->GetMean();
382 sigmacfdtime=cfdtime->GetRMS();
384 Int_t maxBin = cfdtime->GetMaximumBin();
385 Double_t meanEstimate = cfdtime->GetBinCenter( maxBin);
386 if(TMath::Abs(meanEstimate - meancfdtime) > 20 ) meancfdtime = meanEstimate;
390 SetTimeEq(i,meandiff);
391 SetTimeEqRms(i,sigmadiff);
392 SetCFDvalue(i,0, meancfdtime );
393 printf(" pmt %i diff %f sigma %f meancfdtime %f cdbtime %f \n",i, meandiff, sigmadiff, meancfdtime, fCFDvalue[i][0]);
394 if (cfddiff) cfddiff->Reset();
395 if (cfdtime) cfdtime->Reset();
406 //________________________________________________________________________
407 void AliT0CalibTimeEq::GetMeanAndSigma(TH1F* hist, Float_t &mean, Float_t &sigma) {
409 const double window = 2.; //fit window
411 double meanEstimate, sigmaEstimate;
413 maxBin = hist->GetMaximumBin(); //position of maximum
414 meanEstimate = hist->GetBinCenter( maxBin); // mean of gaussian sitting in maximum
415 // sigmaEstimate = hist->GetRMS();
417 TF1* fit= new TF1("fit","gaus", meanEstimate - window*sigmaEstimate, meanEstimate + window*sigmaEstimate);
418 fit->SetParameters(hist->GetBinContent(maxBin), meanEstimate, sigmaEstimate);
419 hist->Fit("fit","RQ","Q");
421 mean = (Float_t) fit->GetParameter(1);
422 sigma = (Float_t) fit->GetParameter(2);