1st draft for pass0
[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;
113 Double_t rms=0, rmsver=0, rmscfd=0;
02888358 114 Int_t nent=0;
115 Bool_t ok=false;
c2337900 116 gFile = TFile::Open(filePhys);
370867d2 117 if(!gFile) {
6318dd46 118 AliError("No input PHYS data found ");
119 }
120 else
121 {
f824d160 122 // gFile->ls();
02888358 123 ok=true;
6318dd46 124 for (Int_t i=0; i<24; i++)
125 {
1e7108ce 126 TH1F *cfd = (TH1F*) gFile->Get(Form("CFD1minCFD%d",i+1));
127 TH1F *cfdtime = (TH1F*) gFile->Get(Form("CFD%d",i+1));
b95e8d87 128 if(!cfd) AliWarning(Form("no histograms collected by PHYS DA for channel %i", i));
6318dd46 129 // printf(" i = %d buf1 = %s\n", i, buf1);
eef60a6a 130 if(cfd) {
1e7108ce 131 GetMeanAndSigma(cfd, meandiff, sigmadiff);
132 nent=cfd->GetEntries();
133 if(nent<500 || cfd->GetRMS()>20. ) {
134 ok=false;
135 AliWarning(Form("Data is not good enouph in PMT %i - mean %f rsm %f nentries %i", i,meandiff,sigmadiff , nent));
136
137 }
138 else
139 {
f824d160 140 ok=false;
1e7108ce 141 AliWarning(Form("Data is not good enouph in PMT %i , no clean peak", i));
142 }
143 if(!cfd) AliWarning(Form("no histograms collected by PHYS DA for channel %i", i));
144 }
145 // printf(" i = %d buf1 = %s\n", i, buf1);
146 if(cfdtime) {
147 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
148 nent=cfdtime->GetEntries();
149 if(nent<500 || sigmacfdtime>30. ) {
150 ok=false;
151 AliWarning(Form("Data is not good enouph in PMT %i CFD data - meancfdtime %f rsm %f nentries %i", i,meancfdtime, sigmacfdtime, nent));
f824d160 152
1e7108ce 153 }
154 }
155 else
156 {
157 ok=false;
158 AliWarning(Form("Data is not good enouph in PMT %i , no clean peak", i));
f824d160 159 }
1e7108ce 160
161
162
163 SetTimeEq(i,meandiff);
164 SetTimeEqRms(i,sigmadiff);
165 SetCFDvalue(i,0,meancfdtime);
166 SetCFDvalue(i,0,sigmacfdtime);
167 if (cfd) delete cfd;
168 if (cfdtime) delete cfdtime;
169
170 }
171 TH1F *ver = (TH1F*) gFile->Get("hVertex");
172 if(!ver) AliWarning("no T0 histogram collected by PHYS DA ");
173 if(ver) {
174 meanver = ver->GetMean();
175 rmsver = ver->GetRMS();
176 }
177 SetMeanVertex(meanver);
178 SetRmsVertex(rmsver);
179
180 gFile->Close();
181 delete gFile;
182
183 }
184 return ok;
185}
186
187//________________________________________________________________
188Bool_t AliT0CalibTimeEq::ComputeOfflineParams(const char* filePhys)
189{
190 // compute online equalized time
191 Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
192 Double_t rms=0, rmsver=0, rmscfd=0;
193 Int_t nent=0;
194 Bool_t ok=false;
195 gFile = TFile::Open(filePhys);
196 if(!gFile) {
197 AliError("No input PHYS data found ");
198 }
199 else
200 {
201 // gFile->ls();
202 ok=true;
203 TObjArray * TzeroObj = (TObjArray*) gFile->Get("fTzeroObject");
204 for (Int_t i=0; i<24; i++)
205 {
206 TH1F *cfddiff = (TH1F*)TzeroObj->At(i);
207 TH1F *cfdtime = (TH1F*)TzeroObj->At(i+24);
208 if(!cfddiff) AliWarning(Form("no histograms collected by PHYS DA for channel %i", i));
209 // printf(" i = %d buf1 = %s\n", i, buf1);
210 if(cfddiff) {
211 GetMeanAndSigma(cfddiff,meandiff, sigmadiff);
212 nent=cfddiff->GetEntries();
213 if(nent<500 || cfddiff->GetRMS()>20. ) {
214 ok=false;
215 AliWarning(Form("Data is not good enouph in PMT %i - mean %f rsm %f nentries %i", i,meandiff,sigmadiff, nent));
216
370867d2 217 }
218 else
f824d160 219 {
220 ok=false;
221 AliWarning(Form("Data is not good enouph in PMT %i , no clean peak", i));
222 }
1e7108ce 223 if(!cfdtime) AliWarning(Form("no histograms collected by PHYS DA for channel %i", i));
224 // printf(" i = %d buf1 = %s\n", i, buf1);
225 if(cfdtime) {
226 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
227 nent=cfdtime->GetEntries();
228 if(nent<500 || cfdtime->GetRMS()>30. ) {
229 ok=false;
230 AliWarning(Form("Data is not good enouph in PMT %i CFD data - mean %f rsm %f nentries %i", i,meancfdtime, sigmacfdtime, nent));
231
232 }
233 }
234 else
235 {
236 ok=false;
237 AliWarning(Form("Data is not good enouph in PMT %i , no clean peak", i));
238 }
eef60a6a 239 }
370867d2 240
241
1e7108ce 242 SetTimeEq(i,meandiff);
243 SetTimeEqRms(i,sigmadiff);
244 SetCFDvalue(i,0,meancfdtime);
245 SetCFDvalue(i,0,sigmacfdtime);
246 if (cfddiff) delete cfddiff;
247 if (cfdtime) delete cfdtime;
248
6318dd46 249 }
b95e8d87 250 TH1F *ver = (TH1F*) gFile->Get("hVertex");
f824d160 251 if(!ver) AliWarning("no T0 histogram collected by PHYS DA ");
eef60a6a 252 if(ver) {
253 meanver = ver->GetMean();
254 rmsver = ver->GetRMS();
255 }
b95e8d87 256 SetMeanVertex(meanver);
eef60a6a 257 SetRmsVertex(rmsver);
6318dd46 258
259 gFile->Close();
260 delete gFile;
02888358 261
6318dd46 262 }
02888358 263 return ok;
264}
a2ad8166 265
1e7108ce 266//________________________________________________________________________
267void AliT0CalibTimeEq::GetMeanAndSigma(TH1F* hist, Float_t &mean, Float_t &sigma) {
268
269 const double threshold = 0.5; // threshold level with respect to maximum bin
270 const double window = 5.; //fit window
271 double norm = hist->Integral(); // normalize to one count
272 hist->Scale(1./norm);
273
274 double meanEstimate, sigmaEstimate;
275 int maxBin;
276 maxBin = hist->GetMaximumBin(); //position of maximum
277 meanEstimate = hist->GetBinCenter( maxBin); // mean of gaussian sitting in maximum
278 sigmaEstimate = hist->GetRMS();
279 TF1* fit= new TF1("fit","gaus", meanEstimate - window*sigmaEstimate, meanEstimate + window*sigmaEstimate);
280 fit->SetParameters(hist->GetBinContent(maxBin), meanEstimate, sigmaEstimate);
281 hist->Fit("fit","R");
282
283 mean = (Float_t) fit->GetParameter(1);
284 sigma = (Float_t) fit->GetParameter(2);
285
286 delete fit;
287}
288
8bfd9a3e 289