]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/AliT0CalibWalk.cxx
improved time and amplitude calibration
[u/mrichter/AliRoot.git] / T0 / AliT0CalibWalk.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 **************************************************************************/
271b5bd3 15
a2ad8166 16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// class T0 walk correction Alla Maevskaya alla@inr.ru 20.11.2007 //
21// //
22///////////////////////////////////////////////////////////////////////////////
23
24#include "AliT0CalibWalk.h"
a2ad8166 25#include "AliLog.h"
a2ad8166 26
27#include <TObjArray.h>
28#include <TGraph.h>
29#include <TFile.h>
a2ad8166 30#include <TH2F.h>
31#include <TMath.h>
32#include <TSystem.h>
33#include <Riostream.h>
34#include <TSpectrum.h>
a2ad8166 35#include <TProfile.h>
8f1790c4 36#include <TF1.h>
a2ad8166 37
38ClassImp(AliT0CalibWalk)
39
40//________________________________________________________________
41 AliT0CalibWalk::AliT0CalibWalk(): TNamed(),
42 fWalk(0),
c883fdf2 43 fAmpLEDRec(0),
44 fQTC(0),
45 fAmpLED(0)
a2ad8166 46{
47 //
48}
49
50//________________________________________________________________
51AliT0CalibWalk::AliT0CalibWalk(const char* name):TNamed(),
52 fWalk(0),
c883fdf2 53 fAmpLEDRec(0), fQTC(0),
54 fAmpLED(0)
55
a2ad8166 56{
57 TString namst = "Calib_";
58 namst += name;
59 SetName(namst.Data());
60 SetTitle(namst.Data());
61
62}
63
64//________________________________________________________________
65AliT0CalibWalk::AliT0CalibWalk(const AliT0CalibWalk& calibda) :
66 TNamed(calibda),
67 fWalk(0),
c883fdf2 68 fAmpLEDRec(0),
69 fQTC(0),
70 fAmpLED(0)
71
a2ad8166 72{
73// copy constructor
74 SetName(calibda.GetName());
75 SetTitle(calibda.GetName());
76
77
78}
79
80//________________________________________________________________
81AliT0CalibWalk &AliT0CalibWalk::operator =(const AliT0CalibWalk& calibda)
82{
83// assignment operator
84 SetName(calibda.GetName());
85 SetTitle(calibda.GetName());
86
87 return *this;
88}
89
90//________________________________________________________________
91AliT0CalibWalk::~AliT0CalibWalk()
92{
93 //
94}
d95247c3 95//________________________________________________________________
a2ad8166 96
d95247c3 97Bool_t AliT0CalibWalk::MakeWalkCorrGraph(const char *laserFile)
a2ad8166 98{
7576945f 99 //make walk corerction for preprocessor
d95247c3 100 Int_t npeaks = 20;
101 Int_t sigma=3.;
102 Bool_t down=false;
103 Int_t index[20];
104 Bool_t ok=true;
105 Float_t mips[20];
0d96e32b 106 Int_t nfound=0;
d95247c3 107
c2337900 108 gFile = TFile::Open(laserFile);
6318dd46 109 if(!gFile) {
110 AliError("No input laser data found ");
111 }
112 else
113 {
8f1790c4 114 // gFile->ls();
d95247c3 115 TH1F* hAmp = (TH1F*) gFile->Get("hAmpLaser");
116 Int_t nmips=0;
99584f2a 117 for (Int_t ibin=0; ibin<2000; ibin++) {
d95247c3 118 Float_t bincont = hAmp->GetBinContent(ibin);
119 if(bincont>0){
120 mips[nmips] = hAmp->GetXaxis()->GetBinCenter(ibin);
121 cout<<ibin<<" bincont "<<bincont<<" amp "<< mips[nmips]<<endl;
122 nmips++;
123 }
c69fcbc1 124 }
125
126 if (nmips<15) ok=false;
127
128 Float_t x1[50], y1[50];
129 Float_t x2[50], xx2[50],y2[50];
130 Float_t xx1[50],yy1[50], xx[50];
95f63b36 131
d95247c3 132 Float_t cfd0[24];
133 Int_t startim = 0;
95f63b36 134
d95247c3 135 for (Int_t ii=0; ii<nmips; ii++)
136 x1[ii] = y1[ii] = x2[ii] = y2[ii] = 0;
95f63b36 137
138 for (Int_t i=0; i<24; i++)
c883fdf2 139 {
99584f2a 140 for (Int_t im=startim; im<nmips-2; im++)
8f1790c4 141 {
d95247c3 142 TString cfd = Form("hCFD%i_%i",i+1,im+1);
143 TString qtc = Form("hQTC%i_%i",i+1,im+1);
3740a735 144 TString led = Form("hLED%i_%i",i+1,im+1);
95f63b36 145
d95247c3 146 TH1F *hCFD = (TH1F*) gFile->Get(cfd.Data()) ;
147 TH1F *hLED = (TH1F*) gFile->Get(led.Data());
148 TH1F *hQTC = (TH1F*) gFile->Get(qtc.Data()) ;
99584f2a 149 printf(" hist get %d %d\n", i,im);
d95247c3 150 hCFD->SetDirectory(0);
151 hQTC->SetDirectory(0);
152 hLED->SetDirectory(0);
153 if(!hCFD )
154 AliWarning(Form(" no CFD data in LASER DA for channel %i for amplitude %f MIPs",i,mips[im]));
155 if(!hQTC )
156 AliWarning(Form(" no QTC correction data in LASER DA for channel %i for amplitude %f MIPs",i,mips[im]));
157 if(!hLED)
158 AliWarning(Form(" no LED correction data in LASER DA for channel %i for amplitude %f MIPs",i,mips[im]));
159
160 if(hCFD ) {
161 TSpectrum *s = new TSpectrum(2*npeaks,1);
0d96e32b 162 nfound = s->Search(hCFD,sigma," ",0.1);
d95247c3 163 if(nfound!=0){
164 Float_t *xpeak = s->GetPositionX();
165 TMath::Sort(nfound, xpeak, index,down);
166 Float_t xp = xpeak[index[0]];
167 Double_t hmax = xp+3*sigma;
168 Double_t hmin = xp-3*sigma;
99584f2a 169 cout<<i<<" "<<im<<" CFD "<<xp<<endl;
d95247c3 170 hCFD->GetXaxis()->SetRangeUser(hmin-10,hmax+10);
8f1790c4 171 }
d95247c3 172 else
173 {
174 hCFD->Rebin(2);
0d96e32b 175 TSpectrum *s1 = new TSpectrum(2*npeaks,1);
0aa8abc8 176 nfound = s1->Search(hCFD,sigma," ",0.1);
d95247c3 177 if(nfound!=0){
0d96e32b 178 Float_t *xpeak = s1->GetPositionX();
d95247c3 179 TMath::Sort(nfound, xpeak, index,down);
180 Float_t xp = xpeak[index[0]];
181 Double_t hmax = xp+3*sigma;
182 Double_t hmin = xp-3*sigma;
99584f2a 183 cout<<" CFD "<<xpeak<<" "<<xp<<endl;
d95247c3 184 hCFD->GetXaxis()->SetRangeUser(hmin-10,hmax+10);
185 }
186 else
187 ok=false;
188 }
189
190 if (im == 0) cfd0[i] = hCFD->GetMean();
99584f2a 191 cout<<i<<" "<<im<<"CFD ok "<<ok<<endl;
d95247c3 192 y1[im] = hCFD->GetMean() - cfd0[i];
193 }
194 if( hQTC) x1[im] = hQTC->GetMean();
195
196 if( hLED){
197 TSpectrum *s = new TSpectrum(2*npeaks,1);
0d96e32b 198 nfound = s->Search(hLED,sigma," ",0.1);
d95247c3 199 if(nfound!=0){
200 Float_t *xpeak = s->GetPositionX();
201 TMath::Sort(nfound, xpeak, index,down);
202 Float_t xp = xpeak[index[0]];
99584f2a 203 cout<<i<<" "<<im<<" LED "<<xp<<endl;
d95247c3 204 Double_t hmax = xp+10*sigma;
205 Double_t hmin = xp-10*sigma;
206 hLED->GetXaxis()->SetRangeUser(hmin-10,hmax+10);
95f63b36 207 }
d95247c3 208 else
209 ok=false;
210 x2[im] = hLED->GetMean();
99584f2a 211 xx2[im] = x2[nmips-im-1];
212 cout<<"LED ok "<<ok<<endl;
d95247c3 213 }
8f1790c4 214 xx[im]=mips[im];
d95247c3 215
216 if (hQTC) delete hQTC;
217 if (hCFD) delete hCFD;
218 if (hLED) delete hLED;
e47b556f 219 }
d95247c3 220
8f1790c4 221 for (Int_t imi=0; imi<nmips; imi++)
95f63b36 222 {
8f1790c4 223 yy1[imi] = Float_t (mips[nmips-imi-1]);
224 xx1[imi] = x2[nmips-imi-1];
d95247c3 225 // cout<<" LED rev "<<i<<" "<<imi<<" "<<xx1[imi]<<" "<< yy1[imi]<<"nmips-imi-1 = "<< nmips-imi-1<<endl;
95f63b36 226 }
95f63b36 227
d95247c3 228 if(i==0) cout<<"Making graphs..."<<endl;
99584f2a 229
230
231 /*
232
233
234 Float_t x1[50], y1[50];
235 Float_t x2[50], xx2[50],y2[50];
236 Float_t xx1[50],yy1[50], xx[50];
237
238 Int_t nmips=20;
239 for (Int_t i=0; i<24; i++)
240 {
241
242 for (Int_t im=0; im<nmips; im++)
243 {
244 x1[im]=xx[im]=500+im*200;
245 y1[im]=0;
246 x2[im]=xx1[im]=yy1[im]=260+20*im;
247 }
248 */
249 Bool_t ok=true;
250 TGraph *grwalkqtc = new TGraph (nmips-2,x1,y1);
251 grwalkqtc->SetTitle(Form("PMT%i",i));
252 TGraph *grwalkled = new TGraph (nmips-2,x2,y1);
253 grwalkled->SetTitle(Form("PMT%i",i));
254 fWalk.AddAtAndExpand(grwalkqtc,i);
255 fAmpLEDRec.AddAtAndExpand(grwalkled,i);
256 // cout<<" add walk "<<i<<endl;
257
258 //fit amplitude graphs to make comparison wth new one
259 TGraph *grampled = new TGraph (nmips-2,xx1,yy1);
260 TGraph *grqtc = new TGraph (nmips-2,x1,xx);
261 fQTC.AddAtAndExpand(grqtc,i);
262 fAmpLED.AddAtAndExpand(grampled,i);
263 // cout<<" add amp "<<i<<endl;
264
265 if(i==23)
266 cout<<"Graphs created..."<<endl;
271b5bd3 267 }
6318dd46 268 } //if gFile exits
99584f2a 269 ok=true;
d95247c3 270 return ok;
a2ad8166 271}
272
c883fdf2 273
274
275