]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/AliT0CalibTimeEq.cxx
Fix for coverity 17562
[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;
02888358 117 Bool_t ok=false;
c2337900 118 gFile = TFile::Open(filePhys);
370867d2 119 if(!gFile) {
6318dd46 120 AliError("No input PHYS data found ");
121 }
122 else
123 {
02888358 124 ok=true;
6318dd46 125 for (Int_t i=0; i<24; i++)
126 {
18086258 127
e691fec9 128 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
1e7108ce 129 TH1F *cfd = (TH1F*) gFile->Get(Form("CFD1minCFD%d",i+1));
130 TH1F *cfdtime = (TH1F*) gFile->Get(Form("CFD%d",i+1));
dd92f5b8 131 if(!cfd) {
132 AliWarning(Form("no Diff histograms collected by PHYS DA for channel %i", i));
dd92f5b8 133 }
134 if(!cfdtime) {
135 AliWarning(Form("no CFD histograms collected by PHYS DA for channel %i", i));
dd92f5b8 136 }
eef60a6a 137 if(cfd) {
e691fec9 138 nent = Int_t(cfd->GetEntries());
18086258 139 if(nent>50) {
612737bb 140 if(cfd->GetRMS()>1.5 )
e691fec9 141 GetMeanAndSigma(cfd, meandiff, sigmadiff);
142 if(cfd->GetRMS()<=1.5)
143 {
144 meandiff = cfd->GetMean();
145 sigmadiff=cfd->GetRMS();
146 }
dd92f5b8 147 Int_t maxBin = cfd->GetMaximumBin();
148 Double_t meanEstimate = cfd->GetBinCenter( maxBin);
149 if(TMath::Abs(meanEstimate - meandiff) > 20 ) meandiff = meanEstimate;
1e7108ce 150 }
151 else
152 {
18086258 153 // ok=false;
e691fec9 154 AliWarning(Form(" Not enouph data in PMT %i- PMT1: %i ", i, nent));
1e7108ce 155 }
1e7108ce 156 }
1e7108ce 157 if(cfdtime) {
e691fec9 158 nent = Int_t(cfdtime->GetEntries());
18086258 159 if(nent > 50 ) { //!!!!!!!!!!
b5e0299c 160 if(cfdtime->GetRMS()>1.5 )
e691fec9 161 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
162 if(cfdtime->GetRMS()<=1.5)
163 {
164 meancfdtime = cfdtime->GetMean();
165 sigmacfdtime = cfdtime->GetRMS();
166 }
dd92f5b8 167 Int_t maxBin = cfdtime->GetMaximumBin();
168 Double_t meanEstimate = cfdtime->GetBinCenter( maxBin);
169 if(TMath::Abs(meanEstimate - meancfdtime) > 20 ) meancfdtime = meanEstimate;
1e7108ce 170 }
dd92f5b8 171 else
172 {
18086258 173 // ok=false;
dd92f5b8 174 AliWarning(Form(" Not enouph data in PMT in CFD peak %i - %i ", i, nent));
175 }
1e7108ce 176 }
1e7108ce 177 SetTimeEq(i,meandiff);
178 SetTimeEqRms(i,sigmadiff);
179 SetCFDvalue(i,0,meancfdtime);
1e7108ce 180 if (cfd) delete cfd;
181 if (cfdtime) delete cfdtime;
dd92f5b8 182
1e7108ce 183 }
184 TH1F *ver = (TH1F*) gFile->Get("hVertex");
1e7108ce 185 if(ver) {
186 meanver = ver->GetMean();
187 rmsver = ver->GetRMS();
188 }
189 SetMeanVertex(meanver);
190 SetRmsVertex(rmsver);
191
192 gFile->Close();
193 delete gFile;
dd92f5b8 194
1e7108ce 195 }
196 return ok;
197}
198
199//________________________________________________________________
dd92f5b8 200 Bool_t AliT0CalibTimeEq::ComputeOfflineParams(const char* filePhys, Float_t *timecdb, Float_t *cfdvalue, Int_t badpmt)
1e7108ce 201{
dd92f5b8 202 // compute offline equalized time
1e7108ce 203 Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
c4ba15c3 204 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
1e7108ce 205 Int_t nent=0;
206 Bool_t ok=false;
bb54f817 207 TH1F *cfddiff = NULL;
208 TH1F *cfdtime = NULL;
dd92f5b8 209 TObjArray * TzeroObj = NULL;
bb54f817 210
c4ba15c3 211 gFile = TFile::Open(filePhys);
1e7108ce 212 if(!gFile) {
213 AliError("No input PHYS data found ");
612737bb 214 return ok;
1e7108ce 215 }
216 else
217 {
e691fec9 218 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
1e7108ce 219 ok=true;
612737bb 220 TDirectory *dr = (TDirectory*) gFile->Get("T0Calib");
dd92f5b8 221 if (dr) TzeroObj = (TObjArray*) dr->Get("T0Calib");
18086258 222
612737bb 223 for (Int_t i=0; i<24; i++)
1e7108ce 224 {
b5e0299c 225 if (i != badpmt) {
bb54f817 226 if(TzeroObj) {
227 cfddiff = (TH1F*)TzeroObj->FindObject(Form("CFD1minCFD%d",i+1));
18086258 228 cfdtime = (TH1F*)TzeroObj->FindObject(Form("CFD%d",i+1));
bb54f817 229 }
230 else
231 {
dd92f5b8 232 cfddiff = (TH1F*)gFile->Get(Form("CFD1minCFD%d",i+1));
18086258 233 cfdtime = (TH1F*)gFile->Get(Form("CFD%d",i+1));
234
bb54f817 235 }
18086258 236 if(!cfddiff ) {
237 AliWarning(Form("no histograms collected by pass0 for diff channel %i", i));
238 SetTimeEq(i,timecdb[i]);
239 SetTimeEqRms(i,0);
dd92f5b8 240 }
241 if(cfddiff) {
18086258 242 nent = Int_t(cfddiff->GetEntries());
b9dd81a7 243 if(nent>500 ) { //!!!!!
18086258 244 if(cfddiff->GetRMS()>1.5 )
245 GetMeanAndSigma(cfddiff, meandiff, sigmadiff);
246 if(cfddiff->GetRMS()<=1.5)
247 {
248 meandiff = cfddiff->GetMean();
249 sigmadiff = cfddiff->GetRMS();
250 }
657abde7 251 Int_t maxBin = cfddiff->GetMaximumBin();
252 Double_t meanEstimate = cfddiff->GetBinCenter( maxBin);
18086258 253 if(TMath::Abs(meanEstimate - meandiff) > 20 ) meandiff = meanEstimate;
f824d160 254 }
18086258 255 else
e691fec9 256 {
18086258 257 AliWarning(Form(" Not enouph data in PMT %i- PMT1: %i ", i, nent));
258 SetTimeEq(i,timecdb[i]);
259 SetTimeEqRms(i,0);
260
261 }
262 }
263
264 if(!cfdtime ) {
265 AliWarning(Form("no histograms collected by pass0 for time channel %i", i));
266 SetTimeEq(i, cfdvalue[i]);
267 SetTimeEqRms(i, 0);
268 }
269 if(cfdtime) {
270 nent = Int_t(cfdtime->GetEntries());
b9dd81a7 271 if(nent>500 ) { //!!!!!
18086258 272 if(cfdtime->GetRMS()>1.5 )
273 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
274 if(cfdtime->GetRMS()<=1.5)
275 {
276 meancfdtime = cfdtime->GetMean();
277 sigmacfdtime=cfdtime->GetRMS();
e691fec9 278 }
657abde7 279 Int_t maxBin = cfdtime->GetMaximumBin();
280 Double_t meanEstimate = cfdtime->GetBinCenter( maxBin);
281 if(TMath::Abs(meanEstimate - meancfdtime) > 20 ) meancfdtime = meanEstimate;
1e7108ce 282 }
e691fec9 283 else
284 {
e691fec9 285 AliWarning(Form(" Not enouph data in PMT in CFD peak %i - %i ", i, nent));
18086258 286 SetTimeEq(i, cfdvalue[i]);
287 SetTimeEqRms(i, 0);
1e7108ce 288 }
eef60a6a 289 }
bb54f817 290
b9dd81a7 291 SetTimeEq(i,meandiff);
1e7108ce 292 SetTimeEqRms(i,sigmadiff);
18086258 293 SetCFDvalue(i,0, meancfdtime );
bb54f817 294 if (cfddiff) cfddiff->Reset();
295 if (cfdtime) cfdtime->Reset();
b5e0299c 296 } //bad pmt
6318dd46 297 }
6318dd46 298
299 gFile->Close();
300 delete gFile;
02888358 301
6318dd46 302 }
02888358 303 return ok;
e691fec9 304 }
a2ad8166 305
1e7108ce 306//________________________________________________________________________
307void AliT0CalibTimeEq::GetMeanAndSigma(TH1F* hist, Float_t &mean, Float_t &sigma) {
612737bb 308
309 const double window = 2.; //fit window
310
1e7108ce 311 double meanEstimate, sigmaEstimate;
312 int maxBin;
313 maxBin = hist->GetMaximumBin(); //position of maximum
314 meanEstimate = hist->GetBinCenter( maxBin); // mean of gaussian sitting in maximum
18086258 315 // sigmaEstimate = hist->GetRMS();
316 sigmaEstimate = 10;
1e7108ce 317 TF1* fit= new TF1("fit","gaus", meanEstimate - window*sigmaEstimate, meanEstimate + window*sigmaEstimate);
318 fit->SetParameters(hist->GetBinContent(maxBin), meanEstimate, sigmaEstimate);
b5e0299c 319 hist->Fit("fit","RQ","Q");
1e7108ce 320
321 mean = (Float_t) fit->GetParameter(1);
322 sigma = (Float_t) fit->GetParameter(2);
323
324 delete fit;
325}
326
8bfd9a3e 327