dc7ca31d |
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 | #include <Riostream.h> |
19 | |
20 | #include <TDirectory.h> |
21 | |
22 | #include "AliRunLoader.h" |
af885e0f |
23 | #include <AliESDEvent.h> |
dc7ca31d |
24 | #include "AliLog.h" |
c41ceaac |
25 | #include "AliT0Loader.h" |
dc7ca31d |
26 | #include "AliT0RecPoint.h" |
27 | #include "AliRawReader.h" |
28 | #include "AliT0RawReader.h" |
dc7ca31d |
29 | #include "AliT0digit.h" |
30 | #include "AliT0Reconstructor.h" |
31 | #include "AliT0Parameters.h" |
c41ceaac |
32 | #include "AliT0Calibrator.h" |
dc7ca31d |
33 | #include "AliCDBLocal.h" |
34 | #include "AliCDBStorage.h" |
35 | #include "AliCDBManager.h" |
36 | #include "AliCDBEntry.h" |
37 | |
38 | #include <TArrayI.h> |
39 | #include <TGraph.h> |
aad72f45 |
40 | #include <TMath.h> |
dc7ca31d |
41 | |
42 | ClassImp(AliT0Reconstructor) |
43 | |
c41ceaac |
44 | AliT0Reconstructor:: AliT0Reconstructor(): AliReconstructor(), |
f16935f7 |
45 | fdZonA(0), |
46 | fdZonC(0), |
47 | fZposition(0), |
48 | fParam(NULL), |
49 | fAmpLEDrec() |
e0bba6cc |
50 | { |
c41ceaac |
51 | AliDebug(1,"Start reconstructor "); |
74adb36a |
52 | |
53 | fParam = AliT0Parameters::Instance(); |
54 | fParam->Init(); |
74adb36a |
55 | for (Int_t i=0; i<24; i++){ |
56 | TGraph* gr = fParam ->GetAmpLEDRec(i); |
57 | fAmpLEDrec.AddAtAndExpand(gr,i) ; |
c32fcee0 |
58 | // fTime0vertex[i]= fParam->GetTimeV0(i); |
74adb36a |
59 | } |
f16935f7 |
60 | fdZonC = TMath::Abs(fParam->GetZPositionShift("T0/C/PMT1")); |
61 | fdZonA = TMath::Abs(fParam->GetZPositionShift("T0/A/PMT15")); |
74adb36a |
62 | |
c41ceaac |
63 | } |
64 | //____________________________________________________________________ |
e0bba6cc |
65 | |
c41ceaac |
66 | AliT0Reconstructor::AliT0Reconstructor(const AliT0Reconstructor &r): |
d76c31f4 |
67 | AliReconstructor(r), |
f16935f7 |
68 | fdZonA(0), |
69 | fdZonC(0), |
70 | fZposition(0), |
71 | fParam(NULL), |
72 | fAmpLEDrec() |
73 | { |
c41ceaac |
74 | // |
75 | // AliT0Reconstructor copy constructor |
76 | // |
e0bba6cc |
77 | |
c41ceaac |
78 | ((AliT0Reconstructor &) r).Copy(*this); |
e0bba6cc |
79 | |
80 | } |
81 | |
c41ceaac |
82 | //_____________________________________________________________________________ |
83 | AliT0Reconstructor &AliT0Reconstructor::operator=(const AliT0Reconstructor &r) |
dc7ca31d |
84 | { |
c41ceaac |
85 | // |
86 | // Assignment operator |
87 | // |
88 | |
89 | if (this != &r) ((AliT0Reconstructor &) r).Copy(*this); |
90 | return *this; |
e0bba6cc |
91 | |
dc7ca31d |
92 | } |
c41ceaac |
93 | |
94 | //_____________________________________________________________________________ |
95 | |
dc7ca31d |
96 | void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const |
94c27e4f |
97 | |
dc7ca31d |
98 | { |
94c27e4f |
99 | // T0 digits reconstruction |
100 | // T0RecPoint writing |
c41ceaac |
101 | |
74adb36a |
102 | |
c41ceaac |
103 | TArrayI * timeCFD = new TArrayI(24); |
104 | TArrayI * timeLED = new TArrayI(24); |
105 | TArrayI * chargeQT0 = new TArrayI(24); |
106 | TArrayI * chargeQT1 = new TArrayI(24); |
74adb36a |
107 | |
c41ceaac |
108 | AliT0Calibrator *calib=new AliT0Calibrator(); |
dc7ca31d |
109 | |
94c27e4f |
110 | // Int_t mV2Mip = param->GetmV2Mip(); |
dc7ca31d |
111 | //mV2Mip = param->GetmV2Mip(); |
8955c6b4 |
112 | Float_t channelWidth = fParam->GetChannelWidth() ; |
74adb36a |
113 | Int_t meanT0 = fParam->GetMeanT0(); |
94c27e4f |
114 | |
dc7ca31d |
115 | AliDebug(1,Form("Start DIGITS reconstruction ")); |
94c27e4f |
116 | |
dc7ca31d |
117 | TBranch *brDigits=digitsTree->GetBranch("T0"); |
e0bba6cc |
118 | AliT0digit *fDigits = new AliT0digit() ; |
dc7ca31d |
119 | if (brDigits) { |
120 | brDigits->SetAddress(&fDigits); |
121 | }else{ |
f16935f7 |
122 | AliError(Form("EXEC Branch T0 digits not found")); |
123 | return; |
dc7ca31d |
124 | } |
e0bba6cc |
125 | |
c41ceaac |
126 | digitsTree->GetEvent(0); |
127 | digitsTree->GetEntry(0); |
128 | brDigits->GetEntry(0); |
129 | fDigits->GetTimeCFD(*timeCFD); |
130 | fDigits->GetTimeLED(*timeLED); |
131 | fDigits->GetQT0(*chargeQT0); |
132 | fDigits->GetQT1(*chargeQT1); |
c32fcee0 |
133 | |
134 | cout<<"!!!! AliT0Reconstructor::Reconstruct RefPoint "<<fDigits->RefPoint()<<endl; |
c41ceaac |
135 | |
136 | Float_t besttimeA=999999; |
137 | Float_t besttimeC=999999; |
138 | Int_t pmtBestA=99999; |
139 | Int_t pmtBestC=99999; |
dc7ca31d |
140 | Float_t timeDiff=999999, meanTime=0; |
141 | |
e0bba6cc |
142 | |
143 | |
94c27e4f |
144 | AliT0RecPoint* frecpoints= new AliT0RecPoint (); |
145 | clustersTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1); |
146 | |
dc7ca31d |
147 | Float_t time[24], adc[24]; |
148 | for (Int_t ipmt=0; ipmt<24; ipmt++) { |
c41ceaac |
149 | if(timeCFD->At(ipmt)>0 ){ |
29d3e0eb |
150 | Double_t qt0 = Double_t(chargeQT0->At(ipmt)); |
151 | Double_t qt1 = Double_t(chargeQT1->At(ipmt)); |
c41ceaac |
152 | if((qt1-qt0)>0) adc[ipmt] = TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000)); |
29d3e0eb |
153 | time[ipmt] = calib-> WalkCorrection( ipmt,Int_t(qt1) , timeCFD->At(ipmt) ) ; |
c41ceaac |
154 | |
155 | //LED |
29d3e0eb |
156 | Double_t sl = (timeLED->At(ipmt) - time[ipmt])*channelWidth; |
74adb36a |
157 | Double_t qt=((TGraph*)fAmpLEDrec.At(ipmt))->Eval(sl/1000.); |
29d3e0eb |
158 | frecpoints->SetTime(ipmt,time[ipmt]); |
dc7ca31d |
159 | frecpoints->SetAmp(ipmt,adc[ipmt]); |
c41ceaac |
160 | frecpoints->SetAmpLED(ipmt,qt); |
dc7ca31d |
161 | } |
162 | else { |
163 | time[ipmt] = 0; |
164 | adc[ipmt] = 0; |
165 | } |
166 | } |
94c27e4f |
167 | |
dc7ca31d |
168 | for (Int_t ipmt=0; ipmt<12; ipmt++){ |
169 | if(time[ipmt] > 1 ) { |
c41ceaac |
170 | if(time[ipmt]<besttimeC){ |
171 | besttimeC=time[ipmt]; //timeC |
172 | pmtBestC=ipmt; |
dc7ca31d |
173 | } |
174 | } |
175 | } |
176 | for ( Int_t ipmt=12; ipmt<24; ipmt++){ |
177 | if(time[ipmt] > 1) { |
c41ceaac |
178 | if(time[ipmt]<besttimeA) { |
179 | besttimeA=time[ipmt]; //timeA |
180 | pmtBestA=ipmt;} |
dc7ca31d |
181 | } |
182 | } |
c41ceaac |
183 | if(besttimeA !=999999) frecpoints->SetTimeBestA(Int_t(besttimeA)); |
184 | if( besttimeC != 999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC)); |
185 | AliDebug(1,Form(" besttimeA %f ps, besttimeC %f ps",besttimeA, besttimeC)); |
dc7ca31d |
186 | Float_t c = 0.0299792; // cm/ps |
187 | Float_t vertex = 0; |
c41ceaac |
188 | if(besttimeA !=999999 && besttimeC != 999999 ){ |
94c27e4f |
189 | timeDiff =(besttimeC - besttimeA)*channelWidth; |
190 | meanTime = (meanT0 - (besttimeA + besttimeC)/2) * channelWidth; |
f16935f7 |
191 | vertex = c*(timeDiff)/2. + (fdZonA - fdZonC)/2; //-(lenr-lenl))/2; |
dc7ca31d |
192 | AliDebug(1,Form(" timeDiff %f ps, meanTime %f ps, vertex %f cm",timeDiff, meanTime,vertex )); |
193 | frecpoints->SetVertex(vertex); |
194 | frecpoints->SetMeanTime(Int_t(meanTime)); |
195 | |
196 | } |
94c27e4f |
197 | //time in each channel as time[ipmt]-MeanTimeinThisChannel(with vertex=0) |
198 | for (Int_t ipmt=0; ipmt<24; ipmt++) { |
199 | if(time[ipmt]>1) { |
c32fcee0 |
200 | // time[ipmt] = (time[ipmt] - fTime0vertex[ipmt])*channelWidth; |
201 | time[ipmt] = time[ipmt] * channelWidth; |
94c27e4f |
202 | frecpoints->SetTime(ipmt,time[ipmt]); |
203 | } |
204 | } |
dc7ca31d |
205 | clustersTree->Fill(); |
bd375212 |
206 | |
207 | delete timeCFD; |
208 | delete timeLED; |
209 | delete chargeQT0; |
210 | delete chargeQT1; |
dc7ca31d |
211 | } |
212 | |
213 | |
c41ceaac |
214 | //_______________________________________________________________________ |
215 | |
216 | void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) const |
217 | { |
94c27e4f |
218 | // T0 raw -> |
219 | // T0RecPoint writing |
220 | |
221 | //Q->T-> coefficients !!!! should be measured!!! |
5325480c |
222 | Int_t allData[110][5]; |
94c27e4f |
223 | |
c41ceaac |
224 | TArrayI * timeCFD = new TArrayI(24); |
225 | TArrayI * timeLED = new TArrayI(24); |
226 | TArrayI * chargeQT0 = new TArrayI(24); |
227 | TArrayI * chargeQT1 = new TArrayI(24); |
228 | |
5325480c |
229 | for (Int_t i=0; i<110; i++) { |
230 | allData[i][0]=0; |
231 | } |
232 | |
c41ceaac |
233 | AliT0RawReader myrawreader(rawReader); |
234 | if (!myrawreader.Next()) |
235 | AliDebug(1,Form(" no raw data found!! %i", myrawreader.Next())); |
c41ceaac |
236 | for (Int_t i=0; i<110; i++) { |
237 | allData[i][0]=myrawreader.GetData(i,0); |
238 | } |
74adb36a |
239 | AliT0Calibrator *calib = new AliT0Calibrator(); |
c41ceaac |
240 | |
74adb36a |
241 | // Int_t mV2Mip = param->GetmV2Mip(); |
c41ceaac |
242 | //mV2Mip = param->GetmV2Mip(); |
8955c6b4 |
243 | Float_t channelWidth = fParam->GetChannelWidth() ; |
244 | |
74adb36a |
245 | Int_t meanT0 = fParam->GetMeanT0(); |
246 | |
5325480c |
247 | for (Int_t in=0; in<24; in++) |
c41ceaac |
248 | { |
249 | timeLED->AddAt(allData[in+1][0],in); |
250 | timeCFD->AddAt(allData[in+25][0],in); |
29d3e0eb |
251 | chargeQT1->AddAt(allData[in+57][0],in); |
252 | chargeQT0->AddAt(allData[in+80][0],in); |
c41ceaac |
253 | AliDebug(10, Form(" readed Raw %i %i %i %i %i", in, timeLED->At(in),timeCFD->At(in),chargeQT0->At(in),chargeQT1->At(in))); |
254 | } |
255 | |
256 | Float_t besttimeA=999999; |
257 | Float_t besttimeC=999999; |
258 | Int_t pmtBestA=99999; |
259 | Int_t pmtBestC=99999; |
260 | Float_t timeDiff=999999, meanTime=0; |
261 | |
262 | |
263 | AliT0RecPoint* frecpoints= new AliT0RecPoint (); |
264 | |
265 | recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1); |
266 | |
267 | |
268 | Float_t time[24], adc[24]; |
269 | for (Int_t ipmt=0; ipmt<24; ipmt++) { |
270 | if(timeCFD->At(ipmt)>0 ){ |
29d3e0eb |
271 | Double_t qt0 = Double_t(chargeQT0->At(ipmt)); |
272 | Double_t qt1 = Double_t(chargeQT1->At(ipmt)); |
c41ceaac |
273 | if((qt1-qt0)>0) adc[ipmt] = TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000)); |
94c27e4f |
274 | // time[ipmt] = channelWidth * (calib-> WalkCorrection( ipmt,qt1 , timeCFD->At(ipmt) ) ) ; |
29d3e0eb |
275 | time[ipmt] = calib-> WalkCorrection( ipmt,Int_t(qt1) , timeCFD->At(ipmt) ) ; |
276 | Double_t sl = (timeLED->At(ipmt) - time[ipmt])*channelWidth; |
74adb36a |
277 | Double_t qt=((TGraph*)fAmpLEDrec.At(ipmt))->Eval(sl/1000.); |
c41ceaac |
278 | frecpoints->SetTime(ipmt,time[ipmt]); |
279 | frecpoints->SetAmp(ipmt,adc[ipmt]); |
280 | frecpoints->SetAmpLED(ipmt,qt); |
8955c6b4 |
281 | AliDebug(1,Form(" QTC %f mv, QTC %f MIPS time in chann %f time %f ",adc[ipmt], adc[ipmt]/50.,time[ipmt], time[ipmt]*channelWidth)); |
282 | |
c41ceaac |
283 | } |
284 | else { |
285 | time[ipmt] = 0; |
286 | adc[ipmt] = 0; |
287 | } |
288 | } |
289 | |
290 | for (Int_t ipmt=0; ipmt<12; ipmt++){ |
291 | if(time[ipmt] > 1 ) { |
292 | if(time[ipmt]<besttimeC){ |
293 | besttimeC=time[ipmt]; //timeC |
294 | pmtBestC=ipmt; |
295 | } |
296 | } |
297 | } |
298 | for ( Int_t ipmt=12; ipmt<24; ipmt++){ |
299 | if(time[ipmt] > 1) { |
300 | if(time[ipmt]<besttimeA) { |
301 | besttimeA=time[ipmt]; //timeA |
302 | pmtBestA=ipmt;} |
303 | } |
304 | } |
305 | if(besttimeA !=999999) frecpoints->SetTimeBestA(Int_t(besttimeA)); |
306 | if( besttimeC != 999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC)); |
307 | AliDebug(1,Form(" besttimeA %f ps, besttimeC %f ps",besttimeA, besttimeC)); |
308 | Float_t c = 0.0299792; // cm/ps |
309 | Float_t vertex = 0; |
310 | if(besttimeA !=999999 && besttimeC != 999999 ){ |
94c27e4f |
311 | timeDiff = (besttimeC - besttimeA)*channelWidth; |
8955c6b4 |
312 | meanTime = (meanT0 - (besttimeA + besttimeC)/2) * channelWidth; |
f16935f7 |
313 | vertex = c*(timeDiff)/2. + (fdZonA - fdZonC)/2; //-(lenr-lenl))/2; |
c41ceaac |
314 | AliDebug(1,Form(" timeDiff %f ps, meanTime %f ps, vertex %f cm",timeDiff, meanTime,vertex )); |
315 | frecpoints->SetVertex(vertex); |
316 | frecpoints->SetMeanTime(Int_t(meanTime)); |
317 | |
318 | } |
94c27e4f |
319 | //time in each channel as time[ipmt]-MeanTimeinThisChannel(with vertex=0) |
8955c6b4 |
320 | /* |
94c27e4f |
321 | for (Int_t ipmt=0; ipmt<24; ipmt++) { |
322 | if(time[ipmt]>1) { |
74adb36a |
323 | time[ipmt] = (time[ipmt] - fTime0vertex[ipmt])*channelWidth; |
94c27e4f |
324 | frecpoints->SetTime(ipmt,time[ipmt]); |
325 | } |
8955c6b4 |
326 | } |
327 | */ |
c41ceaac |
328 | recTree->Fill(); |
94c27e4f |
329 | |
bd375212 |
330 | |
331 | delete timeCFD; |
332 | delete timeLED; |
333 | delete chargeQT0; |
334 | delete chargeQT1; |
335 | |
c41ceaac |
336 | } |
337 | //____________________________________________________________ |
338 | |
d76c31f4 |
339 | void AliT0Reconstructor::FillESD(TTree */*digitsTree*/, TTree *clustersTree, AliESDEvent *pESD) const |
dc7ca31d |
340 | { |
341 | |
342 | /*************************************************** |
343 | Resonstruct digits to vertex position |
344 | ****************************************************/ |
345 | |
dc7ca31d |
346 | AliDebug(1,Form("Start FillESD T0")); |
347 | |
d76c31f4 |
348 | TTree *treeR = clustersTree; |
dc7ca31d |
349 | |
350 | AliT0RecPoint* frecpoints= new AliT0RecPoint (); |
351 | if (!frecpoints) { |
352 | AliError("Reconstruct Fill ESD >> no recpoints found"); |
353 | return; |
354 | } |
355 | |
356 | AliDebug(1,Form("Start FillESD T0")); |
357 | TBranch *brRec = treeR->GetBranch("T0"); |
358 | if (brRec) { |
359 | brRec->SetAddress(&frecpoints); |
360 | }else{ |
f16935f7 |
361 | AliError(Form("EXEC Branch T0 rec not found")); |
dc7ca31d |
362 | return; |
363 | } |
364 | |
365 | brRec->GetEntry(0); |
f16935f7 |
366 | Float_t amp[24], time[24]; |
367 | Float_t zPosition = frecpoints -> GetVertex(); |
368 | Float_t timeStart = frecpoints -> GetMeanTime() ; |
369 | for ( Int_t i=0; i<24; i++) { |
94c27e4f |
370 | time[i] = Float_t (frecpoints -> GetTime(i)); // ps to ns |
dc7ca31d |
371 | amp[i] = frecpoints -> GetAmp(i); |
372 | } |
f16935f7 |
373 | pESD->SetT0zVertex(zPosition); //vertex Z position |
dc7ca31d |
374 | pESD->SetT0(timeStart); // interaction time |
375 | pESD->SetT0time(time); // best TOF on each PMT |
376 | pESD->SetT0amplitude(amp); // number of particles(MIPs) on each PMT |
5325480c |
377 | |
f16935f7 |
378 | AliDebug(1,Form(" Z position %f cm, T0 %f ps",zPosition , timeStart)); |
dc7ca31d |
379 | |
dc7ca31d |
380 | } // vertex in 3 sigma |
381 | |
382 | |
383 | |
384 | |
385 | |
386 | |