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