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