]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/AliT0CalibWalk.cxx
Clean-up compile-time warnings
[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 **************************************************************************/
15
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>
36
a2ad8166 37
38ClassImp(AliT0CalibWalk)
39
40//________________________________________________________________
41 AliT0CalibWalk::AliT0CalibWalk(): TNamed(),
42 fWalk(0),
43 fAmpLEDRec(0)
44{
45 //
46}
47
48//________________________________________________________________
49AliT0CalibWalk::AliT0CalibWalk(const char* name):TNamed(),
50 fWalk(0),
51 fAmpLEDRec(0)
52{
53 TString namst = "Calib_";
54 namst += name;
55 SetName(namst.Data());
56 SetTitle(namst.Data());
57
58}
59
60//________________________________________________________________
61AliT0CalibWalk::AliT0CalibWalk(const AliT0CalibWalk& calibda) :
62 TNamed(calibda),
63 fWalk(0),
64 fAmpLEDRec(0)
65
66{
67// copy constructor
68 SetName(calibda.GetName());
69 SetTitle(calibda.GetName());
70
71
72}
73
74//________________________________________________________________
75AliT0CalibWalk &AliT0CalibWalk::operator =(const AliT0CalibWalk& calibda)
76{
77// assignment operator
78 SetName(calibda.GetName());
79 SetTitle(calibda.GetName());
80
81 return *this;
82}
83
84//________________________________________________________________
85AliT0CalibWalk::~AliT0CalibWalk()
86{
87 //
88}
89//________________________________________________________________
90void AliT0CalibWalk::SetWalk(Int_t ipmt)
91{
7576945f 92 //read QTC walk graph from external file
a2ad8166 93
94 Int_t mv, ps;
95 Int_t x[70000], y[70000], index[70000];
96 Float_t time[10000],amplitude[10000];
97 string buffer;
98 Bool_t down=false;
99
100 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-Amp.txt");
101 ifstream inFile(filename);
102 if(!inFile) AliError(Form("Cannot open file %s !",filename));
103
104 Int_t i=0;
105 while(getline(inFile,buffer)){
106 inFile >> ps >> mv;
107
108 x[i]=ps; y[i]=mv;
109 i++;
110 }
111 inFile.close();
112 cout<<" number of data "<<i<<endl;
113
114 TMath::Sort(i, y, index,down);
115 Int_t amp=0, iin=0, isum=0, sum=0;
116 Int_t ind=0;
117 for (Int_t ii=0; ii<i; ii++)
118 {
119 ind=index[ii];
120 if(y[ind] == amp)
121 {
122 sum +=x[ind];
123 iin++;
124 }
125 else
126 {
127 if(iin>0)
128 time[isum] = Float_t (sum/(iin));
129 else
130 time[isum] =Float_t (x[ind]);
131 amplitude[isum] = Float_t (amp);
132 amp=y[ind];
133 iin=0;
134 isum++;
135 sum=0;
136 }
137 }
138
139 inFile.close();
140
141 TGraph* gr = new TGraph(isum, amplitude, time);
142 fWalk.AddAtAndExpand(gr,ipmt);
143}
144
145//________________________________________________________________
146
147void AliT0CalibWalk::SetAmpLEDRec(Int_t ipmt)
148{
7576945f 149 // read LED walk from external file
a2ad8166 150 Float_t mv, ps;
151 Float_t x[100], y[100];
152 string buffer;
153
154 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-LED.txt");
155 ifstream inFile(filename);
156 if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
157
158 inFile >> mv>>ps;
159 Int_t i=0;
160
161 while(getline(inFile,buffer)){
162 x[i]=mv; y[i]=ps;
163 inFile >> mv >> ps;
164 i++;
165 }
166 inFile.close();
167 Float_t y1[100], x1[100];
168 for (Int_t ir=0; ir<i; ir++){
169 y1[ir]=y[i-ir]; x1[ir]=x[i-ir];}
170 TGraph* gr = new TGraph(i,y1,x1);
171 fAmpLEDRec.AddAtAndExpand(gr,ipmt);
172
173}
174
175//________________________________________________________________
176
177void AliT0CalibWalk::MakeWalkCorrGraph(const char *laserFile)
178{
7576945f 179 //make walk corerction for preprocessor
180
a2ad8166 181 TFile *gFile = TFile::Open(laserFile);
a8d3b391 182 //gSystem->Load("libSpectrum");
a2ad8166 183 TGraph *gr[24];
f35a2c6c 184 TGraph *grLED[24];
a2ad8166 185 Int_t npeaks = 20;
186 Int_t sigma=3;
187 Bool_t down=false;
188
189 Int_t index[20];
f35a2c6c 190 Char_t buf1[10], buf2[10], buf3[10], title[10], title2[10], titleLED[10], title2LED[10];
5ce9c64b 191 TSpectrum *s = new TSpectrum(2*npeaks,1.);
a2ad8166 192
f35a2c6c 193 for (Int_t d=0; d<2; d++)
a2ad8166 194 {
f35a2c6c 195 for (Int_t i=0; i<12; i++)
a2ad8166 196 {
f35a2c6c 197 sprintf(buf1,"T0_C_%i_CFD",i+1);
198 if (d==0)
199 {
200 sprintf(buf2,"CFD_QTC%i",i+1);
201 }
202 else
203 {
204 sprintf(buf3,"CFD_LED%i",i+1);
205 }
7576945f 206 TH2F *qtccfd = (TH2F*) gFile->Get(buf2);
207 TH2F *ledcfd = (TH2F*) gFile->Get(buf3);
f35a2c6c 208 // cout<<buf1<<" "<<buf2<<endl;
209 TH1F *cfd = (TH1F*) gFile->Get(buf1);
f35a2c6c 210 Int_t nfound = s->Search(cfd,sigma,"goff",0.05);
211 // cout<<"Found "<<nfound<<" peaks sigma "<<sigma<<endl;
212 if(nfound!=0)
a2ad8166 213 {
f35a2c6c 214 Float_t *xpeak = s->GetPositionX();
215 TMath::Sort(nfound, xpeak, index,down);
216 Float_t xp = xpeak[index[0]];
217 Float_t hmax = xp+10*sigma;
218 Float_t hmin = xp-10*sigma;
219 if (d==0)
220 {
7576945f 221 Int_t nbins= qtccfd->GetXaxis()->GetNbins();
222 TProfile *prY = qtccfd->ProfileX();
223 prY->SetMaximum(hmax);
224 prY->SetMinimum(hmin);
f35a2c6c 225 Int_t np=nbins/20;
226 Double_t *xx = new Double_t[np];
227 Double_t *yy = new Double_t[np];
228 Int_t ng=0;
229 Double_t yg=0;
230 for (Int_t ip=1; ip<nbins; ip++)
a2ad8166 231 {
f35a2c6c 232 if(ip%20 != 0 )
233 {
7576945f 234 if (prY->GetBinContent(ip) !=0)
f35a2c6c 235 {
7576945f 236 yg +=prY->GetBinContent(ip);
f35a2c6c 237 }
238 ng++;
239 }
240 else
241 {
7576945f 242 xx[ip/20] = Float_t (prY->GetBinCenter(ip));
f35a2c6c 243 yy[ip/20] = yg/ng;
244 yg=0;
245 ng=0;
246 }
a2ad8166 247 }
f35a2c6c 248 sprintf(title,"Walk %i",i+1);
249 gr[i] = new TGraph(np,xx,yy);
250 gr[i]->SetTitle(title);
251 gr[i]->SetMinimum(hmin);
252 gr[i]->SetMaximum(hmax);
253 gr[i]->SetMarkerStyle(7);
254 sprintf(title2,"Walk %i",i+13);
255 gr[i+12] = new TGraph(np,xx,yy);
256 gr[i+12]->SetTitle(title2);
257 gr[i+12]->SetMinimum(hmin);
258 gr[i+12]->SetMaximum(hmax);
259 gr[i+12]->SetMarkerStyle(7);
6b7d32f7 260
f35a2c6c 261 fWalk.AddAtAndExpand(gr[i],i);
262 fWalk.AddAtAndExpand(gr[i+12],i+12);
263 delete [] xx;
264 delete [] yy;
7576945f 265 delete prY;
f35a2c6c 266 }
267 else
268 {
7576945f 269 Int_t nbinsLED= ledcfd->GetXaxis()->GetNbins();
270 TProfile *prYLED = ledcfd->ProfileX();
271 prYLED->SetMaximum(hmax);
272 prYLED->SetMinimum(hmin);
f35a2c6c 273 Int_t npLED=nbinsLED/20;
274 Double_t *xxLED = new Double_t[npLED];
275 Double_t *yyLED = new Double_t[npLED];
276 Int_t ngLED=0;
277 Double_t ygLED=0;
278 for (Int_t ip=1; ip<nbinsLED; ip++)
279 {
280 if(ip%20 != 0 )
281 {
7576945f 282 if (prYLED->GetBinContent(ip) !=0)
f35a2c6c 283 {
7576945f 284 ygLED +=prYLED->GetBinContent(ip);
f35a2c6c 285 }
286 ngLED++;
287 }
288 else
289 {
7576945f 290 xxLED[ip/20] = Float_t (prYLED->GetBinCenter(ip));
f35a2c6c 291 yyLED[ip/20] = ygLED/ngLED;
292 ygLED=0;
293 ngLED=0;
294 }
295 }
296 sprintf(titleLED,"Walk LED %i",i+1);
297 grLED[i] = new TGraph(npLED,xxLED,yyLED);
298 grLED[i]->SetTitle(titleLED);
299 grLED[i]->SetMinimum(hmin);
300 grLED[i]->SetMaximum(hmax);
301 grLED[i]->SetMarkerStyle(7);
302 sprintf(title2LED,"Walk LED%i",i+13);
303 grLED[i+12] = new TGraph(npLED,xxLED,yyLED);
304 grLED[i+12]->SetTitle(title2LED);
305 grLED[i+12]->SetMinimum(hmin);
306 grLED[i+12]->SetMaximum(hmax);
307 grLED[i+12]->SetMarkerStyle(7);
308
309 fAmpLEDRec.AddAtAndExpand(grLED[i],i);
310 fAmpLEDRec.AddAtAndExpand(grLED[i+12],i+12);
311 delete [] xxLED;
312 delete [] yyLED;
7576945f 313 delete prYLED;
f35a2c6c 314 }
315 }
5ce9c64b 316 delete cfd;
7576945f 317 delete qtccfd;
318 delete ledcfd;
a2ad8166 319 }
320 }
321
a2ad8166 322}
323