for pass0 AliT0PreprocessorOffline.cxx
[u/mrichter/AliRoot.git] / T0 / AliT0CalibTimeEq.cxx
CommitLineData
a2ad8166 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
59b8a5fc 20// class for T0 calibration TM-AC-AM_6-02-2006
21// equalize time shift for each time CFD channel
a2ad8166 22// //
23///////////////////////////////////////////////////////////////////////////////
24
25#include "AliT0CalibTimeEq.h"
e47b556f 26#include "AliLog.h"
a2ad8166 27#include <TFile.h>
28#include <TMath.h>
29#include <TF1.h>
a2ad8166 30#include <TSpectrum.h>
a2ad8166 31#include <TProfile.h>
c61a7285 32#include <iostream>
a2ad8166 33
34ClassImp(AliT0CalibTimeEq)
35
36//________________________________________________________________
eef60a6a 37 AliT0CalibTimeEq::AliT0CalibTimeEq():TNamed(),
38 fMeanVertex(0),
39 fRmsVertex(0)
a2ad8166 40{
41 //
b95e8d87 42
a2ad8166 43}
44
45//________________________________________________________________
eef60a6a 46AliT0CalibTimeEq::AliT0CalibTimeEq(const char* name):TNamed(),
47 fMeanVertex(0),
48 fRmsVertex(0)
a2ad8166 49{
59b8a5fc 50 //constructor
51
a2ad8166 52 TString namst = "Calib_";
53 namst += name;
54 SetName(namst.Data());
55 SetTitle(namst.Data());
56}
57
58//________________________________________________________________
eef60a6a 59AliT0CalibTimeEq::AliT0CalibTimeEq(const AliT0CalibTimeEq& calibda):TNamed(calibda),
60 fMeanVertex(0),
61 fRmsVertex(0)
a2ad8166 62{
63// copy constructor
64 SetName(calibda.GetName());
65 SetTitle(calibda.GetName());
66
67
68}
69
70//________________________________________________________________
71AliT0CalibTimeEq &AliT0CalibTimeEq::operator =(const AliT0CalibTimeEq& calibda)
72{
73// assignment operator
74 SetName(calibda.GetName());
75 SetTitle(calibda.GetName());
76
77 return *this;
78}
79
80//________________________________________________________________
81AliT0CalibTimeEq::~AliT0CalibTimeEq()
82{
83 //
59b8a5fc 84 // destrictor
a2ad8166 85}
86//________________________________________________________________
87void AliT0CalibTimeEq::Reset()
88{
59b8a5fc 89 //reset values
90
a2ad8166 91 memset(fCFDvalue,0,120*sizeof(Float_t));
92 memset(fTimeEq,1,24*sizeof(Float_t));
93}
94
95
96//________________________________________________________________
97void AliT0CalibTimeEq::Print(Option_t*) const
98{
59b8a5fc 99 // print time values
a2ad8166 100
101 printf("\n ---- PM Arrays ----\n\n");
102 printf(" Time delay CFD \n");
103 for (Int_t i=0; i<24; i++) printf(" CFD %f ",fTimeEq[i]);
b95e8d87 104 printf("\n Mean Vertex %f \n", fMeanVertex);
a2ad8166 105}
106
107
108//________________________________________________________________
02888358 109Bool_t AliT0CalibTimeEq::ComputeOnlineParams(const char* filePhys)
a2ad8166 110{
59b8a5fc 111 // compute online equalized time
1e7108ce 112 Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
c4ba15c3 113 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
c4ba15c3 114 Double_t rmsver=0;
b5e0299c 115 Int_t nent=0;
02888358 116 Bool_t ok=false;
c2337900 117 gFile = TFile::Open(filePhys);
370867d2 118 if(!gFile) {
6318dd46 119 AliError("No input PHYS data found ");
120 }
121 else
122 {
02888358 123 ok=true;
6318dd46 124 for (Int_t i=0; i<24; i++)
125 {
e691fec9 126 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
1e7108ce 127 TH1F *cfd = (TH1F*) gFile->Get(Form("CFD1minCFD%d",i+1));
128 TH1F *cfdtime = (TH1F*) gFile->Get(Form("CFD%d",i+1));
e691fec9 129 if(!cfd) AliWarning(Form("no Diff histograms collected by PHYS DA for channel %i", i));
eef60a6a 130 if(cfd) {
e691fec9 131 nent = Int_t(cfd->GetEntries());
132 if(nent>500 ) {
133 if(cfd->GetRMS()>1.5 && cfd->GetRMS()<20)
134 GetMeanAndSigma(cfd, meandiff, sigmadiff);
135 if(cfd->GetRMS()<=1.5)
136 {
137 meandiff = cfd->GetMean();
138 sigmadiff=cfd->GetRMS();
139 }
1e7108ce 140
e691fec9 141 if(cfd->GetRMS()>20)
142 {
143 ok=false;
144 AliWarning(Form("Data is not good in PMT %i - mean %f rsm %f nentries %i", i,meandiff,sigmadiff , nent));
145 }
1e7108ce 146 }
147 else
148 {
f824d160 149 ok=false;
e691fec9 150 AliWarning(Form(" Not enouph data in PMT %i- PMT1: %i ", i, nent));
1e7108ce 151 }
e691fec9 152 if(!cfd) AliWarning(Form("no CFD histograms collected by PHYS DA for channel %i", i));
1e7108ce 153 }
154 // printf(" i = %d buf1 = %s\n", i, buf1);
155 if(cfdtime) {
e691fec9 156 nent = Int_t(cfdtime->GetEntries());
157 if(nent>500 ) {
b5e0299c 158 if(cfdtime->GetRMS()>1.5 )
e691fec9 159 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
160 if(cfdtime->GetRMS()<=1.5)
161 {
162 meancfdtime = cfdtime->GetMean();
163 sigmacfdtime = cfdtime->GetRMS();
164 }
b5e0299c 165 if(sigmacfdtime>50 )
e691fec9 166 {
b5e0299c 167 ok=false;
168 AliWarning(Form("Data is not good enouph in PMT %i - meancfdtime %f rsm %f nentries %i", i,meancfdtime, sigmacfdtime, nent));
e691fec9 169 }
1e7108ce 170 }
171 }
172 else
173 {
e691fec9 174 ok=false;
175 AliWarning(Form(" Not enouph data in PMT in CFD peak %i - %i ", i, nent));
176 }
177 // printf(" %i %f %f %f %f \n",i, meandiff, sigmadiff, meancfdtime, sigmacfdtime);
1e7108ce 178 SetTimeEq(i,meandiff);
179 SetTimeEqRms(i,sigmadiff);
180 SetCFDvalue(i,0,meancfdtime);
181 SetCFDvalue(i,0,sigmacfdtime);
182 if (cfd) delete cfd;
183 if (cfdtime) delete cfdtime;
184
185 }
186 TH1F *ver = (TH1F*) gFile->Get("hVertex");
187 if(!ver) AliWarning("no T0 histogram collected by PHYS DA ");
188 if(ver) {
189 meanver = ver->GetMean();
190 rmsver = ver->GetRMS();
191 }
192 SetMeanVertex(meanver);
193 SetRmsVertex(rmsver);
194
195 gFile->Close();
196 delete gFile;
197
198 }
199 return ok;
200}
201
202//________________________________________________________________
b5e0299c 203Bool_t AliT0CalibTimeEq::ComputeOfflineParams(const char* filePhys, Float_t *timecdb, Int_t badpmt)
1e7108ce 204{
205 // compute online equalized time
206 Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
c4ba15c3 207 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
c4ba15c3 208 Double_t rmsver=0;
1e7108ce 209 Int_t nent=0;
210 Bool_t ok=false;
c4ba15c3 211 gFile = TFile::Open(filePhys);
1e7108ce 212 if(!gFile) {
213 AliError("No input PHYS data found ");
214 }
215 else
216 {
e691fec9 217 meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
1e7108ce 218 ok=true;
b5e0299c 219 TDirectory *dr = (TDirectory*) gFile->Get("T0Calib");
220 TObjArray * TzeroObj = (TObjArray*) dr->Get("fTzeroObject");
221 for (Int_t i=0; i<24; i++)
1e7108ce 222 {
b5e0299c 223 if (i != badpmt) {
1e7108ce 224 TH1F *cfddiff = (TH1F*)TzeroObj->At(i);
225 TH1F *cfdtime = (TH1F*)TzeroObj->At(i+24);
e691fec9 226 if(!cfddiff) AliWarning(Form("no Diff histograms collected by PHYS DA for channel %i", i));
1e7108ce 227 // printf(" i = %d buf1 = %s\n", i, buf1);
228 if(cfddiff) {
e691fec9 229 nent = Int_t(cfddiff->GetEntries());
b5e0299c 230 if(nent>10 ) {
231 if(cfddiff->GetRMS()>1.5 && cfddiff->GetRMS()<30)
e691fec9 232 GetMeanAndSigma(cfddiff, meandiff, sigmadiff);
233 if(cfddiff->GetRMS()<=1.5)
234 {
235 meandiff = cfddiff->GetMean();
236 sigmadiff = cfddiff->GetRMS();
237 }
b5e0299c 238 // printf(" ipmt %i meandiff %f sigmadiff %f mean %f rms %f\n", i, meandiff,sigmadiff,cfddiff->GetMean(), cfddiff->GetRMS() );
e691fec9 239
b5e0299c 240 if(sigmadiff > 30)
e691fec9 241 {
242 ok=false;
243 AliWarning(Form("Data is not good in PMT %i - mean %f rsm %f nentries %i", i,meandiff,sigmadiff , nent));
244 }
b5e0299c 245
370867d2 246 }
247 else
f824d160 248 {
249 ok=false;
e691fec9 250 AliWarning(Form(" Not enouph data in PMT %i- PMT1: %i ", i, nent));
f824d160 251 }
e691fec9 252 }
1e7108ce 253 if(cfdtime) {
e691fec9 254 nent = Int_t(cfdtime->GetEntries());
b5e0299c 255 if(nent>10 ) {
256 if(cfdtime->GetRMS()>1.5 )
e691fec9 257 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
258 if(cfdtime->GetRMS()<=1.5)
259 {
260 meancfdtime = cfdtime->GetMean();
261 sigmacfdtime=cfdtime->GetRMS();
262 }
b5e0299c 263 if(sigmacfdtime>50)
e691fec9 264 {
265 ok=false;
266 AliWarning(Form("Data is not good enouph in PMT %i - meancfdtime %f rsm %f nentries %i", i,meancfdtime, sigmacfdtime, nent));
267 }
1e7108ce 268 }
e691fec9 269 else
270 {
1e7108ce 271 ok=false;
e691fec9 272 AliWarning(Form(" Not enouph data in PMT in CFD peak %i - %i ", i, nent));
1e7108ce 273 }
eef60a6a 274 }
b5e0299c 275 SetTimeEq(i,timecdb[i] + meandiff);
1e7108ce 276 SetTimeEqRms(i,sigmadiff);
277 SetCFDvalue(i,0,meancfdtime);
278 SetCFDvalue(i,0,sigmacfdtime);
279 if (cfddiff) delete cfddiff;
280 if (cfdtime) delete cfdtime;
b5e0299c 281 } //bad pmt
6318dd46 282 }
b95e8d87 283 TH1F *ver = (TH1F*) gFile->Get("hVertex");
f824d160 284 if(!ver) AliWarning("no T0 histogram collected by PHYS DA ");
eef60a6a 285 if(ver) {
286 meanver = ver->GetMean();
287 rmsver = ver->GetRMS();
288 }
b95e8d87 289 SetMeanVertex(meanver);
eef60a6a 290 SetRmsVertex(rmsver);
6318dd46 291
292 gFile->Close();
293 delete gFile;
02888358 294
6318dd46 295 }
02888358 296 return ok;
e691fec9 297 }
a2ad8166 298
1e7108ce 299//________________________________________________________________________
300void AliT0CalibTimeEq::GetMeanAndSigma(TH1F* hist, Float_t &mean, Float_t &sigma) {
301
1e7108ce 302 const double window = 5.; //fit window
1e7108ce 303
304 double meanEstimate, sigmaEstimate;
305 int maxBin;
306 maxBin = hist->GetMaximumBin(); //position of maximum
307 meanEstimate = hist->GetBinCenter( maxBin); // mean of gaussian sitting in maximum
308 sigmaEstimate = hist->GetRMS();
309 TF1* fit= new TF1("fit","gaus", meanEstimate - window*sigmaEstimate, meanEstimate + window*sigmaEstimate);
310 fit->SetParameters(hist->GetBinContent(maxBin), meanEstimate, sigmaEstimate);
b5e0299c 311 hist->Fit("fit","RQ","Q");
1e7108ce 312
313 mean = (Float_t) fit->GetParameter(1);
314 sigma = (Float_t) fit->GetParameter(2);
315
316 delete fit;
317}
318
8bfd9a3e 319