]>
Commit | Line | Data |
---|---|---|
d08a92dd | 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 | /* | |
15ec34b9 | 17 | $Log$ |
3432ebfa | 18 | Revision 1.18 2007/03/06 16:31:20 arcelli |
19 | Add Uncorrected TOF Time signal | |
20 | ||
aa5476d8 | 21 | Revision 1.17 2007/02/28 18:09:11 arcelli |
22 | Add protection against failed retrieval of the CDB cal object, now Reconstruction exits with AliFatal | |
23 | ||
a1cab04c | 24 | Revision 1.16 2007/02/20 15:57:00 decaro |
25 | Raw data update: to read the TOF raw data defined in UNPACKED mode | |
26 | ||
d08a92dd | 27 | |
28 | Revision 0.03 2005/07/28 A. De Caro | |
29 | Implement public method | |
30 | Raw2Digits(Int_t, AliRawReader *) | |
31 | to convert digits from raw data in MC digits | |
32 | (temporary solution) | |
33 | ||
34 | Revision 0.02 2005/07/27 A. De Caro | |
35 | Implement public method | |
36 | Digits2RecPoint(Int_t) | |
37 | to convert digits in clusters | |
38 | ||
39 | Revision 0.02 2005/07/26 A. De Caro | |
40 | Implement private methods | |
41 | InsertCluster(AliTOFcluster *) | |
42 | FindClusterIndex(Double_t) | |
43 | originally implemented in AliTOFtracker | |
44 | by S. Arcelli and C. Zampolli | |
45 | ||
46 | Revision 0.01 2005/07/25 A. De Caro | |
47 | Implement public methods | |
48 | Digits2RecPoint(AliRawReader *, TTree *) | |
49 | Digits2RecPoint(Int_t, AliRawReader *) | |
50 | to convert raw data in clusters | |
51 | */ | |
52 | ||
53 | //////////////////////////////////////////////////////////////// | |
54 | // // | |
55 | // Class for TOF cluster finder // | |
56 | // // | |
57 | // Starting from Raw Data, create rec points, // | |
58 | // fill TreeR for TOF, // | |
59 | // write TOF.RecPoints.root file // | |
60 | // // | |
61 | //////////////////////////////////////////////////////////////// | |
62 | ||
15ec34b9 | 63 | #include "Riostream.h" |
64 | ||
0e46b9ae | 65 | #include "TClonesArray.h" |
15ec34b9 | 66 | //#include "TFile.h" |
0e46b9ae | 67 | #include "TTree.h" |
d08a92dd | 68 | |
d0eb8f39 | 69 | #include "AliDAQ.h" |
0e46b9ae | 70 | #include "AliLoader.h" |
d08a92dd | 71 | #include "AliLog.h" |
0e46b9ae | 72 | #include "AliRawReader.h" |
d08a92dd | 73 | #include "AliRunLoader.h" |
d08a92dd | 74 | |
37879eed | 75 | #include "AliTOFCal.h" |
15ec34b9 | 76 | #include "AliTOFcalib.h" |
37879eed | 77 | #include "AliTOFChannel.h" |
d08a92dd | 78 | #include "AliTOFClusterFinder.h" |
0e46b9ae | 79 | #include "AliTOFcluster.h" |
80 | #include "AliTOFdigit.h" | |
0e46b9ae | 81 | #include "AliTOFGeometry.h" |
15ec34b9 | 82 | #include "AliTOFGeometryV5.h" |
83 | #include "AliTOFrawData.h" | |
0e46b9ae | 84 | #include "AliTOFRawStream.h" |
3432ebfa | 85 | #include "Riostream.h" |
0e46b9ae | 86 | |
15ec34b9 | 87 | //extern TFile *gFile; |
d08a92dd | 88 | |
89 | ClassImp(AliTOFClusterFinder) | |
90 | ||
91 | AliTOFClusterFinder::AliTOFClusterFinder(): | |
92 | fRunLoader(0), | |
93 | fTOFLoader(0), | |
94 | fTreeD(0), | |
95 | fTreeR(0), | |
58d8d9a3 | 96 | fTOFGeometry(new AliTOFGeometryV5()), |
d08a92dd | 97 | fDigits(new TClonesArray("AliTOFdigit", 4000)), |
98 | fRecPoints(new TClonesArray("AliTOFcluster", 4000)), | |
15ec34b9 | 99 | fNumberOfTofClusters(0), |
100 | fVerbose(0) | |
d08a92dd | 101 | { |
102 | // | |
103 | // Constructor | |
104 | // | |
105 | ||
3bbdf45d | 106 | AliInfo("V5 TOF Geometry is taken as the default"); |
37879eed | 107 | |
d08a92dd | 108 | } |
109 | //______________________________________________________________________________ | |
110 | ||
111 | AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader): | |
112 | fRunLoader(runLoader), | |
113 | fTOFLoader(runLoader->GetLoader("TOFLoader")), | |
114 | fTreeD(0), | |
115 | fTreeR(0), | |
58d8d9a3 | 116 | fTOFGeometry(new AliTOFGeometryV5()), |
d08a92dd | 117 | fDigits(new TClonesArray("AliTOFdigit", 4000)), |
118 | fRecPoints(new TClonesArray("AliTOFcluster", 4000)), | |
15ec34b9 | 119 | fNumberOfTofClusters(0), |
120 | fVerbose(0) | |
d08a92dd | 121 | { |
122 | // | |
123 | // Constructor | |
124 | // | |
125 | ||
0f49d1bc | 126 | // runLoader->CdGAFile(); |
127 | // TFile *in=(TFile*)gFile; | |
128 | // in->cd(); | |
129 | // fTOFGeometry = (AliTOFGeometry*)in->Get("TOFgeometry"); | |
d08a92dd | 130 | |
7aeeaf38 | 131 | } |
132 | ||
133 | //------------------------------------------------------------------------ | |
134 | AliTOFClusterFinder::AliTOFClusterFinder(const AliTOFClusterFinder &source) | |
58d8d9a3 | 135 | :TObject(), |
136 | fRunLoader(0), | |
137 | fTOFLoader(0), | |
138 | fTreeD(0), | |
139 | fTreeR(0), | |
140 | fTOFGeometry(new AliTOFGeometryV5()), | |
141 | fDigits(new TClonesArray("AliTOFdigit", 4000)), | |
142 | fRecPoints(new TClonesArray("AliTOFcluster", 4000)), | |
15ec34b9 | 143 | fNumberOfTofClusters(0), |
144 | fVerbose(0) | |
7aeeaf38 | 145 | { |
146 | // copy constructor | |
147 | this->fDigits=source.fDigits; | |
148 | this->fRecPoints=source.fRecPoints; | |
149 | this->fTOFGeometry=source.fTOFGeometry; | |
150 | ||
151 | } | |
152 | ||
153 | //------------------------------------------------------------------------ | |
d0eb8f39 | 154 | AliTOFClusterFinder& AliTOFClusterFinder::operator=(const AliTOFClusterFinder &source) |
7aeeaf38 | 155 | { |
156 | // ass. op. | |
157 | this->fDigits=source.fDigits; | |
158 | this->fRecPoints=source.fRecPoints; | |
159 | this->fTOFGeometry=source.fTOFGeometry; | |
15ec34b9 | 160 | this->fVerbose=source.fVerbose; |
7aeeaf38 | 161 | return *this; |
162 | ||
d08a92dd | 163 | } |
164 | //______________________________________________________________________________ | |
165 | ||
166 | AliTOFClusterFinder::~AliTOFClusterFinder() | |
167 | { | |
168 | ||
169 | // | |
170 | // Destructor | |
171 | // | |
172 | ||
173 | if (fDigits) | |
174 | { | |
175 | fDigits->Delete(); | |
176 | delete fDigits; | |
177 | fDigits=0; | |
178 | } | |
179 | if (fRecPoints) | |
180 | { | |
181 | fRecPoints->Delete(); | |
182 | delete fRecPoints; | |
183 | fRecPoints=0; | |
184 | } | |
185 | ||
186 | delete fTOFGeometry; | |
187 | ||
188 | } | |
189 | //______________________________________________________________________________ | |
190 | ||
191 | void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent) | |
192 | { | |
193 | // | |
194 | // Converts digits to recpoints for TOF | |
195 | // | |
196 | ||
197 | fRunLoader->GetEvent(iEvent); | |
198 | ||
199 | fTreeD = fTOFLoader->TreeD(); | |
200 | if (fTreeD == 0x0) | |
201 | { | |
202 | AliFatal("AliTOFClusterFinder: Can not get TreeD"); | |
203 | } | |
204 | ||
205 | TBranch *branch = fTreeD->GetBranch("TOF"); | |
206 | if (!branch) { | |
207 | AliError("can't get the branch with the TOF digits !"); | |
208 | return; | |
209 | } | |
210 | ||
15ec34b9 | 211 | TClonesArray *digits = new TClonesArray("AliTOFdigit",10000); |
d08a92dd | 212 | branch->SetAddress(&digits); |
213 | ||
214 | ResetRecpoint(); | |
215 | ||
216 | fTreeR = fTOFLoader->TreeR(); | |
217 | if (fTreeR == 0x0) | |
218 | { | |
219 | fTOFLoader->MakeTree("R"); | |
220 | fTreeR = fTOFLoader->TreeR(); | |
221 | } | |
222 | ||
223 | Int_t bufsize = 32000; | |
224 | fTreeR->Branch("TOF", &fRecPoints, bufsize); | |
225 | ||
226 | fTreeD->GetEvent(0); | |
227 | Int_t nDigits = digits->GetEntriesFast(); | |
228 | AliDebug(2,Form("Number of TOF digits: %d",nDigits)); | |
229 | ||
230 | Int_t ii, jj; | |
231 | Int_t dig[5]; | |
232 | Float_t g[3]; | |
233 | Double_t h[5]; | |
340693af | 234 | Float_t tToT; |
235 | Double_t tTdcND; | |
d08a92dd | 236 | for (ii=0; ii<nDigits; ii++) { |
237 | AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii); | |
238 | dig[0]=d->GetSector(); | |
239 | dig[1]=d->GetPlate(); | |
240 | dig[2]=d->GetStrip(); | |
241 | dig[3]=d->GetPadz(); | |
242 | dig[4]=d->GetPadx(); | |
243 | ||
d0eb8f39 | 244 | //AliInfo(Form(" %2i %1i %2i %1i %2i ",dig[0],dig[1],dig[2],dig[3],dig[4])); |
245 | ||
d08a92dd | 246 | for (jj=0; jj<3; jj++) g[jj] = 0.; |
247 | fTOFGeometry->GetPos(dig,g); | |
248 | ||
249 | h[0] = TMath::Sqrt(g[0]*g[0]+g[1]*g[1]); | |
250 | h[1] = TMath::ATan2(g[1],g[0]); | |
251 | h[2] = g[2]; | |
252 | h[3] = d->GetTdc(); | |
253 | h[4] = d->GetAdc(); | |
340693af | 254 | tToT = d->GetToT(); |
255 | tTdcND = d->GetTdcND(); | |
d08a92dd | 256 | |
340693af | 257 | AliTOFcluster *tofCluster = new AliTOFcluster(h,d->GetTracks(),dig,ii,tToT, tTdcND); |
aa5476d8 | 258 | tofCluster->SetTDCRAW(d->GetTdc()); |
d08a92dd | 259 | InsertCluster(tofCluster); |
260 | ||
261 | } | |
262 | ||
263 | AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters)); | |
264 | ||
37879eed | 265 | CalibrateRecPoint(); |
d08a92dd | 266 | FillRecPoint(); |
267 | ||
268 | fTreeR->Fill(); | |
269 | ResetRecpoint(); | |
270 | ||
271 | fTOFLoader = fRunLoader->GetLoader("TOFLoader"); | |
272 | fTOFLoader->WriteRecPoints("OVERWRITE"); | |
273 | ||
274 | } | |
275 | //______________________________________________________________________________ | |
276 | ||
277 | void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader, | |
278 | TTree *clustersTree) | |
279 | { | |
280 | // | |
281 | // Converts RAW data to recpoints for TOF | |
282 | // | |
283 | ||
d0eb8f39 | 284 | //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors(); |
285 | const Int_t kDDL = AliDAQ::NumberOfDdls("TOF"); | |
d08a92dd | 286 | |
287 | ResetRecpoint(); | |
288 | ||
289 | Int_t bufsize = 32000; | |
290 | clustersTree->Branch("TOF", &fRecPoints, bufsize); | |
291 | ||
15ec34b9 | 292 | TClonesArray * clonesRawData; |
293 | ||
d08a92dd | 294 | Int_t ii = 0; |
15ec34b9 | 295 | Int_t dummy = -1; |
d08a92dd | 296 | |
297 | Int_t detectorIndex[5]; | |
298 | Float_t position[3]; | |
299 | Double_t cylindricalPosition[5]; | |
340693af | 300 | Float_t tToT; |
301 | Double_t tTdcND; | |
d08a92dd | 302 | |
15ec34b9 | 303 | ofstream ftxt; |
304 | if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app); | |
305 | ||
306 | Int_t indexDDL = 0; | |
307 | for (indexDDL = 0; indexDDL < kDDL; indexDDL++) { | |
308 | ||
309 | rawReader->Reset(); | |
310 | AliTOFRawStream tofInput(rawReader); | |
311 | tofInput.LoadRawData(indexDDL); | |
312 | ||
313 | clonesRawData = (TClonesArray*)tofInput.GetRawData(); | |
314 | ||
315 | for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) { | |
316 | ||
317 | AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData); | |
318 | ||
319 | if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue; | |
320 | ||
321 | if (fVerbose==2) { | |
322 | if (indexDDL<10) ftxt << " " << indexDDL; | |
323 | else ftxt << " " << indexDDL; | |
324 | if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM(); | |
325 | else ftxt << " " << tofRawDatum->GetTRM(); | |
326 | ftxt << " " << tofRawDatum->GetTRMchain(); | |
327 | if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC(); | |
328 | else ftxt << " " << tofRawDatum->GetTDC(); | |
329 | ftxt << " " << tofRawDatum->GetTDCchannel(); | |
330 | } | |
331 | ||
332 | tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(), | |
333 | tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex); | |
334 | dummy = detectorIndex[3]; | |
335 | detectorIndex[3] = detectorIndex[4]; | |
336 | detectorIndex[4] = dummy; | |
337 | ||
338 | if (fVerbose==2) { | |
339 | if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0]; | |
340 | else ftxt << " -> " << detectorIndex[0]; | |
341 | ftxt << " " << detectorIndex[1]; | |
342 | if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2]; | |
343 | else ftxt << " " << detectorIndex[2]; | |
344 | ftxt << " " << detectorIndex[3]; | |
345 | if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4]; | |
346 | else ftxt << " " << detectorIndex[4]; | |
347 | } | |
348 | ||
349 | for (ii=0; ii<3; ii++) position[ii] = 0.; | |
350 | fTOFGeometry->GetPos(detectorIndex, position); | |
351 | ||
352 | cylindricalPosition[0] = TMath::Sqrt(position[0]*position[0] + position[1]*position[1]); | |
353 | cylindricalPosition[1] = TMath::ATan2(position[1], position[0]); | |
354 | cylindricalPosition[2] = position[2]; | |
355 | cylindricalPosition[3] = tofRawDatum->GetTOF(); | |
356 | cylindricalPosition[4] = tofRawDatum->GetTOT(); | |
357 | tToT = tofRawDatum->GetTOT(); | |
358 | tTdcND = -1.; | |
359 | AliTOFcluster *tofCluster = new AliTOFcluster(cylindricalPosition, detectorIndex); | |
360 | tofCluster->SetToT(tToT); | |
361 | tofCluster->SetTDCND(tTdcND); | |
aa5476d8 | 362 | tofCluster->SetTDCRAW(tofRawDatum->GetTOF()); |
15ec34b9 | 363 | InsertCluster(tofCluster); |
364 | ||
365 | if (fVerbose==2) { | |
366 | if (cylindricalPosition[4]<10) ftxt << " " << cylindricalPosition[4]; | |
367 | else if (cylindricalPosition[4]>=10 && cylindricalPosition[4]<100) ftxt << " " << cylindricalPosition[4]; | |
368 | else ftxt << " " << cylindricalPosition[4]; | |
369 | if (cylindricalPosition[3]<10) ftxt << " " << cylindricalPosition[3] << endl; | |
370 | else if (cylindricalPosition[3]>=10 && cylindricalPosition[3]<100) ftxt << " " << cylindricalPosition[3] << endl; | |
371 | else if (cylindricalPosition[3]>=100 && cylindricalPosition[3]<1000) ftxt << " " << cylindricalPosition[3] << endl; | |
372 | else ftxt << " " << cylindricalPosition[3] << endl; | |
373 | } | |
374 | ||
375 | } // closed loop on TOF raw data per current DDL file | |
376 | ||
377 | clonesRawData->Clear(); | |
378 | ||
379 | } // closed loop on DDL index | |
380 | ||
381 | /* | |
382 | Int_t indexDDL = 0; | |
d08a92dd | 383 | for (indexDDL = 0; indexDDL < kDDL; indexDDL++) { |
384 | ||
385 | rawReader->Reset(); | |
386 | AliTOFRawStream tofInput(rawReader); | |
362c9d61 | 387 | rawReader->Select("TOF", indexDDL, indexDDL); |
d08a92dd | 388 | |
389 | while(tofInput.Next()) { | |
390 | ||
d0eb8f39 | 391 | for (ii=0; ii<5; ii++) detectorIndex[ii] = -1; |
392 | ||
d08a92dd | 393 | detectorIndex[0] = tofInput.GetSector(); |
394 | detectorIndex[1] = tofInput.GetPlate(); | |
395 | detectorIndex[2] = tofInput.GetStrip(); | |
396 | detectorIndex[3] = tofInput.GetPadZ(); | |
397 | detectorIndex[4] = tofInput.GetPadX(); | |
398 | ||
d0eb8f39 | 399 | //AliInfo(Form(" %2i %1i %2i %1i %2i ",detectorIndex[0],detectorIndex[1],detectorIndex[2],detectorIndex[3],detectorIndex[4])); |
400 | ||
401 | if (detectorIndex[0]==-1 || | |
402 | detectorIndex[1]==-1 || | |
403 | detectorIndex[2]==-1 || | |
404 | detectorIndex[3]==-1 || | |
405 | detectorIndex[4]==-1) continue; | |
406 | ||
d08a92dd | 407 | for (ii=0; ii<3; ii++) position[ii] = 0.; |
408 | ||
409 | fTOFGeometry->GetPos(detectorIndex, position); | |
410 | ||
411 | cylindricalPosition[0] = TMath::Sqrt(position[0]*position[0] + position[1]*position[1]); | |
412 | cylindricalPosition[1] = TMath::ATan2(position[1], position[0]); | |
413 | cylindricalPosition[2] = position[2]; | |
414 | cylindricalPosition[3] = tofInput.GetTofBin(); | |
d0eb8f39 | 415 | cylindricalPosition[4] = tofInput.GetToTbin(); |
416 | tToT = tofInput.GetToTbin(); | |
340693af | 417 | tTdcND = -1.; |
d08a92dd | 418 | AliTOFcluster *tofCluster = new AliTOFcluster(cylindricalPosition, detectorIndex); |
340693af | 419 | tofCluster->SetToT(tToT); |
420 | tofCluster->SetTDCND(tTdcND); | |
d08a92dd | 421 | InsertCluster(tofCluster); |
422 | ||
423 | } // while loop | |
424 | ||
425 | } // loop on DDL files | |
15ec34b9 | 426 | */ |
427 | ||
428 | if (fVerbose==2) ftxt.close(); | |
d08a92dd | 429 | |
430 | AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters)); | |
431 | ||
37879eed | 432 | CalibrateRecPoint(); |
d08a92dd | 433 | FillRecPoint(); |
434 | ||
435 | clustersTree->Fill(); | |
37879eed | 436 | |
d08a92dd | 437 | ResetRecpoint(); |
438 | ||
439 | } | |
440 | //______________________________________________________________________________ | |
441 | ||
442 | void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader) | |
443 | { | |
444 | // | |
445 | // Converts RAW data to recpoints for TOF | |
446 | // | |
447 | ||
d0eb8f39 | 448 | //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors(); |
449 | const Int_t kDDL = AliDAQ::NumberOfDdls("TOF"); | |
d08a92dd | 450 | |
451 | fRunLoader->GetEvent(iEvent); | |
452 | ||
453 | AliDebug(2,Form(" Event number %2i ", iEvent)); | |
454 | ||
455 | fTreeR = fTOFLoader->TreeR(); | |
456 | ||
457 | if (fTreeR == 0x0){ | |
458 | fTOFLoader->MakeTree("R"); | |
459 | fTreeR = fTOFLoader->TreeR(); | |
460 | } | |
461 | ||
462 | Int_t bufsize = 32000; | |
463 | fTreeR->Branch("TOF", &fRecPoints, bufsize); | |
464 | ||
15ec34b9 | 465 | TClonesArray * clonesRawData; |
466 | ||
d08a92dd | 467 | Int_t ii = 0; |
15ec34b9 | 468 | Int_t dummy = -1; |
d08a92dd | 469 | |
d0eb8f39 | 470 | Int_t detectorIndex[5] = {-1, -1, -1, -1, -1}; |
d08a92dd | 471 | Float_t position[3]; |
472 | Double_t cylindricalPosition[5]; | |
340693af | 473 | Float_t tToT; |
474 | Double_t tTdcND; | |
d08a92dd | 475 | |
15ec34b9 | 476 | ofstream ftxt; |
477 | if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app); | |
478 | ||
479 | Int_t indexDDL = 0; | |
d08a92dd | 480 | for (indexDDL = 0; indexDDL < kDDL; indexDDL++) { |
481 | ||
482 | rawReader->Reset(); | |
483 | AliTOFRawStream tofInput(rawReader); | |
15ec34b9 | 484 | tofInput.LoadRawData(indexDDL); |
485 | ||
486 | clonesRawData = (TClonesArray*)tofInput.GetRawData(); | |
487 | ||
488 | for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) { | |
489 | ||
490 | AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData); | |
491 | ||
492 | if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue; | |
493 | ||
494 | if (fVerbose==2) { | |
495 | if (indexDDL<10) ftxt << " " << indexDDL; | |
496 | else ftxt << " " << indexDDL; | |
497 | if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM(); | |
498 | else ftxt << " " << tofRawDatum->GetTRM(); | |
499 | ftxt << " " << tofRawDatum->GetTRMchain(); | |
500 | if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC(); | |
501 | else ftxt << " " << tofRawDatum->GetTDC(); | |
502 | ftxt << " " << tofRawDatum->GetTDCchannel(); | |
503 | } | |
504 | ||
505 | tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(), | |
506 | tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex); | |
507 | dummy = detectorIndex[3]; | |
508 | detectorIndex[3] = detectorIndex[4]; | |
509 | detectorIndex[4] = dummy; | |
510 | ||
511 | if (fVerbose==2) { | |
512 | if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0]; | |
513 | else ftxt << " -> " << detectorIndex[0]; | |
514 | ftxt << " " << detectorIndex[1]; | |
515 | if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2]; | |
516 | else ftxt << " " << detectorIndex[2]; | |
517 | ftxt << " " << detectorIndex[3]; | |
518 | if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4]; | |
519 | else ftxt << " " << detectorIndex[4]; | |
520 | } | |
d0eb8f39 | 521 | |
d08a92dd | 522 | for (ii=0; ii<3; ii++) position[ii] = 0.; |
d08a92dd | 523 | fTOFGeometry->GetPos(detectorIndex, position); |
15ec34b9 | 524 | |
525 | cylindricalPosition[0] = TMath::Sqrt(position[0]*position[0] + position[1]*position[1]); | |
526 | cylindricalPosition[1] = TMath::ATan2(position[1], position[0]); | |
527 | cylindricalPosition[2] = position[2]; | |
528 | cylindricalPosition[3] = tofRawDatum->GetTOF(); | |
529 | cylindricalPosition[4] = tofRawDatum->GetTOT(); | |
530 | tToT = tofRawDatum->GetTOT(); | |
340693af | 531 | tTdcND = -1.; |
d08a92dd | 532 | AliTOFcluster *tofCluster = new AliTOFcluster(cylindricalPosition, detectorIndex); |
340693af | 533 | tofCluster->SetToT(tToT); |
534 | tofCluster->SetTDCND(tTdcND); | |
aa5476d8 | 535 | tofCluster->SetTDCRAW(tofRawDatum->GetTOF()); |
d08a92dd | 536 | InsertCluster(tofCluster); |
537 | ||
15ec34b9 | 538 | if (fVerbose==2) { |
539 | if (cylindricalPosition[4]<10) ftxt << " " << cylindricalPosition[4]; | |
540 | else if (cylindricalPosition[4]>=10 && cylindricalPosition[4]<100) ftxt << " " << cylindricalPosition[4]; | |
541 | else ftxt << " " << cylindricalPosition[4]; | |
542 | if (cylindricalPosition[3]<10) ftxt << " " << cylindricalPosition[3] << endl; | |
543 | else if (cylindricalPosition[3]>=10 && cylindricalPosition[3]<100) ftxt << " " << cylindricalPosition[3] << endl; | |
544 | else if (cylindricalPosition[3]>=100 && cylindricalPosition[3]<1000) ftxt << " " << cylindricalPosition[3] << endl; | |
545 | else ftxt << " " << cylindricalPosition[3] << endl; | |
546 | } | |
d08a92dd | 547 | |
15ec34b9 | 548 | } // closed loop on TOF raw data per current DDL file |
549 | ||
550 | clonesRawData->Clear(); | |
551 | ||
552 | } // closed loop on DDL index | |
553 | ||
554 | if (fVerbose==2) ftxt.close(); | |
d08a92dd | 555 | |
556 | AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters)); | |
557 | ||
37879eed | 558 | CalibrateRecPoint(); |
d08a92dd | 559 | FillRecPoint(); |
560 | ||
561 | fTreeR->Fill(); | |
562 | ResetRecpoint(); | |
563 | ||
564 | fTOFLoader = fRunLoader->GetLoader("TOFLoader"); | |
565 | fTOFLoader->WriteRecPoints("OVERWRITE"); | |
566 | ||
567 | } | |
568 | //______________________________________________________________________________ | |
569 | ||
570 | void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader) | |
571 | { | |
572 | // | |
573 | // Converts RAW data to MC digits for TOF | |
574 | // | |
575 | // (temporary solution) | |
576 | // | |
577 | ||
15ec34b9 | 578 | //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors(); |
579 | const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors(); | |
580 | ||
d08a92dd | 581 | fRunLoader->GetEvent(iEvent); |
582 | ||
583 | fTreeD = fTOFLoader->TreeD(); | |
584 | if (fTreeD) | |
585 | { | |
d0eb8f39 | 586 | AliInfo("TreeD re-creation"); |
d08a92dd | 587 | fTreeD = 0x0; |
588 | fTOFLoader->MakeTree("D"); | |
589 | fTreeD = fTOFLoader->TreeD(); | |
590 | } | |
591 | ||
15ec34b9 | 592 | TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000); |
d08a92dd | 593 | Int_t bufsize = 32000; |
594 | fTreeD->Branch("TOF", &tofDigits, bufsize); | |
595 | ||
d08a92dd | 596 | fRunLoader->GetEvent(iEvent); |
597 | ||
598 | AliDebug(2,Form(" Event number %2i ", iEvent)); | |
599 | ||
15ec34b9 | 600 | TClonesArray * clonesRawData; |
601 | ||
602 | Int_t dummy = -1; | |
d08a92dd | 603 | |
604 | Int_t detectorIndex[5]; | |
d0eb8f39 | 605 | Float_t digit[4]; |
d08a92dd | 606 | |
15ec34b9 | 607 | Int_t indexDDL = 0; |
d08a92dd | 608 | for (indexDDL = 0; indexDDL < kDDL; indexDDL++) { |
609 | ||
610 | rawReader->Reset(); | |
611 | AliTOFRawStream tofInput(rawReader); | |
15ec34b9 | 612 | tofInput.LoadRawData(indexDDL); |
d08a92dd | 613 | |
15ec34b9 | 614 | clonesRawData = (TClonesArray*)tofInput.GetRawData(); |
d08a92dd | 615 | |
15ec34b9 | 616 | for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) { |
d0eb8f39 | 617 | |
15ec34b9 | 618 | AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData); |
d0eb8f39 | 619 | |
15ec34b9 | 620 | if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue; |
621 | ||
622 | tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(), | |
623 | tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex); | |
624 | dummy = detectorIndex[3]; | |
625 | detectorIndex[3] = detectorIndex[4]; | |
626 | detectorIndex[4] = dummy; | |
d0eb8f39 | 627 | |
d08a92dd | 628 | digit[0] = (Float_t)tofInput.GetTofBin(); |
d0eb8f39 | 629 | digit[1] = (Float_t)tofInput.GetToTbin(); |
630 | digit[2] = (Float_t)tofInput.GetToTbin(); | |
631 | digit[3] = -1.; | |
d08a92dd | 632 | |
633 | Int_t tracknum[3]={-1,-1,-1}; | |
634 | ||
635 | TClonesArray &aDigits = *tofDigits; | |
636 | Int_t last=tofDigits->GetEntriesFast(); | |
637 | new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit); | |
638 | ||
639 | } // while loop | |
640 | ||
15ec34b9 | 641 | clonesRawData->Clear(); |
642 | ||
d08a92dd | 643 | } // DDL Loop |
644 | ||
645 | fTreeD->Fill(); | |
646 | ||
647 | fTOFLoader = fRunLoader->GetLoader("TOFLoader"); | |
648 | fTOFLoader->WriteDigits("OVERWRITE"); | |
649 | ||
650 | } | |
651 | //______________________________________________________________________________ | |
652 | ||
653 | Int_t AliTOFClusterFinder::InsertCluster(AliTOFcluster *tofCluster) { | |
654 | //---------------------------------------------------------------------------// | |
655 | // This function adds a TOF cluster to the array of TOF clusters sorted in Z // | |
656 | //---------------------------------------------------------------------------// | |
657 | if (fNumberOfTofClusters==kTofMaxCluster) { | |
658 | AliError("Too many clusters !"); | |
659 | return 1; | |
660 | } | |
661 | ||
662 | if (fNumberOfTofClusters==0) { | |
663 | fTofClusters[fNumberOfTofClusters++] = tofCluster; | |
664 | return 0; | |
665 | } | |
666 | ||
667 | Int_t ii = FindClusterIndex(tofCluster->GetZ()); | |
668 | memmove(fTofClusters+ii+1 ,fTofClusters+ii,(fNumberOfTofClusters-ii)*sizeof(AliTOFcluster*)); | |
669 | fTofClusters[ii] = tofCluster; | |
670 | fNumberOfTofClusters++; | |
671 | ||
672 | return 0; | |
673 | ||
674 | } | |
675 | //_________________________________________________________________________ | |
676 | ||
677 | Int_t AliTOFClusterFinder::FindClusterIndex(Double_t z) const { | |
678 | //-------------------------------------------------------------------- | |
679 | // This function returns the index of the nearest cluster | |
680 | //-------------------------------------------------------------------- | |
681 | if (fNumberOfTofClusters==0) return 0; | |
682 | if (z <= fTofClusters[0]->GetZ()) return 0; | |
683 | if (z > fTofClusters[fNumberOfTofClusters-1]->GetZ()) return fNumberOfTofClusters; | |
684 | Int_t b = 0, e = fNumberOfTofClusters-1, m = (b+e)/2; | |
685 | for (; b<e; m=(b+e)/2) { | |
686 | if (z > fTofClusters[m]->GetZ()) b=m+1; | |
687 | else e=m; | |
688 | } | |
689 | ||
690 | return m; | |
691 | ||
692 | } | |
693 | //_________________________________________________________________________ | |
694 | ||
695 | void AliTOFClusterFinder::FillRecPoint() | |
696 | { | |
697 | // | |
698 | // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted | |
699 | // in Z) in the global TClonesArray of AliTOFcluster, | |
700 | // i.e. fRecPoints. | |
701 | // | |
702 | ||
703 | Int_t ii, jj; | |
704 | ||
705 | Int_t detectorIndex[5]; | |
706 | Double_t cylindricalPosition[5]; | |
707 | Int_t trackLabels[3]; | |
708 | Int_t digitIndex = -1; | |
58d8d9a3 | 709 | Float_t tToT=0.; |
710 | Double_t tTdcND=0.; | |
3432ebfa | 711 | Double_t tTdcRAW=0.; |
58d8d9a3 | 712 | Bool_t cStatus = kTRUE; |
d08a92dd | 713 | |
714 | TClonesArray &lRecPoints = *fRecPoints; | |
715 | ||
716 | for (ii=0; ii<fNumberOfTofClusters; ii++) { | |
717 | ||
718 | digitIndex = fTofClusters[ii]->GetIndex(); | |
719 | for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj); | |
720 | for(jj=0; jj<3; jj++) trackLabels[jj] = fTofClusters[ii]->GetLabel(jj); | |
721 | cylindricalPosition[0] = fTofClusters[ii]->GetR(); | |
722 | cylindricalPosition[1] = fTofClusters[ii]->GetPhi(); | |
723 | cylindricalPosition[2] = fTofClusters[ii]->GetZ(); | |
724 | cylindricalPosition[3] = fTofClusters[ii]->GetTDC(); | |
725 | cylindricalPosition[4] = fTofClusters[ii]->GetADC(); | |
340693af | 726 | tToT = fTofClusters[ii]->GetToT(); |
727 | tTdcND = fTofClusters[ii]->GetTDCND(); | |
58d8d9a3 | 728 | cStatus=fTofClusters[ii]->GetStatus(); |
3432ebfa | 729 | tTdcRAW=fTofClusters[ii]->GetTDCRAW(); |
730 | new(lRecPoints[ii]) AliTOFcluster(cylindricalPosition, trackLabels, detectorIndex, digitIndex, tToT, tTdcND, tTdcRAW,cStatus); | |
d08a92dd | 731 | |
732 | //AliInfo(Form("%3i %3i %f %f %f %f %f %2i %2i %2i %1i %2i",ii,digitIndex, cylindricalPosition[2],cylindricalPosition[0],cylindricalPosition[1],cylindricalPosition[3],cylindricalPosition[4],detectorIndex[0],detectorIndex[1],detectorIndex[2],detectorIndex[3],detectorIndex[4])); | |
733 | ||
734 | } // loop on clusters | |
735 | ||
736 | } | |
37879eed | 737 | |
738 | //_________________________________________________________________________ | |
739 | void AliTOFClusterFinder::CalibrateRecPoint() | |
740 | { | |
741 | // | |
742 | // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted | |
743 | // in Z) in the global TClonesArray of AliTOFcluster, | |
744 | // i.e. fRecPoints. | |
745 | // | |
746 | ||
747 | Int_t ii, jj; | |
748 | ||
749 | Int_t detectorIndex[5]; | |
750 | Int_t digitIndex = -1; | |
340693af | 751 | Float_t tToT; |
752 | Float_t tdcCorr; | |
37879eed | 753 | AliInfo(" Calibrating TOF Clusters: ") |
754 | AliTOFcalib *calib = new AliTOFcalib(fTOFGeometry); | |
3f2bddfa | 755 | // calib->ReadParFromCDB("TOF/Calib",0); // original |
a1cab04c | 756 | // Use AliCDBManager's run number |
757 | if(!calib->ReadParFromCDB("TOF/Calib",-1)) {AliFatal("Exiting, no CDB object found!!!");exit(0);} | |
758 | ||
340693af | 759 | AliTOFCal *calTOFArray = calib->GetTOFCalArray(); |
37879eed | 760 | |
761 | for (ii=0; ii<fNumberOfTofClusters; ii++) { | |
762 | digitIndex = fTofClusters[ii]->GetIndex(); | |
763 | for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj); | |
764 | ||
765 | Int_t index = calib->GetIndex(detectorIndex); | |
766 | ||
340693af | 767 | AliTOFChannel * calChannel = calTOFArray->GetChannel(index); |
58d8d9a3 | 768 | |
769 | // Get channel status | |
770 | Bool_t status=calChannel->GetStatus(); | |
771 | if(status)fTofClusters[ii]->SetStatus(!status); //odd convention, to avoid conflict with calibration objects currently in the db (temporary solution). | |
772 | ||
773 | // Get Rough channel online equalization | |
774 | Float_t roughDelay=calChannel->GetDelay(); | |
775 | ||
776 | // Get Refined channel offline calibration parameters | |
37879eed | 777 | Float_t par[6]; |
778 | for (Int_t j = 0; j<6; j++){ | |
340693af | 779 | par[j]=calChannel->GetSlewPar(j); |
37879eed | 780 | } |
340693af | 781 | tToT = fTofClusters[ii]->GetToT(); |
58d8d9a3 | 782 | Float_t timeCorr=par[0]+par[1]*tToT+par[2]*tToT*tToT+par[3]*tToT*tToT*tToT+par[4]*tToT*tToT*tToT*tToT+par[5]*tToT*tToT*tToT*tToT*tToT+roughDelay; |
340693af | 783 | tdcCorr=(fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()+32)*1.E-3-timeCorr; |
784 | tdcCorr=(tdcCorr*1E3-32)/AliTOFGeometry::TdcBinWidth(); | |
785 | fTofClusters[ii]->SetTDC(tdcCorr); | |
37879eed | 786 | |
787 | } // loop on clusters | |
788 | ||
789 | delete calib; | |
790 | } | |
d08a92dd | 791 | //______________________________________________________________________________ |
792 | ||
793 | void AliTOFClusterFinder::ResetRecpoint() | |
794 | { | |
795 | // | |
796 | // Clear the list of reconstructed points | |
797 | // | |
798 | ||
799 | fNumberOfTofClusters = 0; | |
800 | if (fRecPoints) fRecPoints->Clear(); | |
801 | ||
802 | } | |
803 | //______________________________________________________________________________ | |
804 | ||
805 | void AliTOFClusterFinder::Load() | |
806 | { | |
807 | // | |
808 | // Load TOF.Digits.root and TOF.RecPoints.root files | |
809 | // | |
810 | ||
811 | fTOFLoader->LoadDigits("READ"); | |
812 | fTOFLoader->LoadRecPoints("recreate"); | |
813 | ||
814 | } | |
815 | //______________________________________________________________________________ | |
816 | ||
817 | void AliTOFClusterFinder::LoadClusters() | |
818 | { | |
819 | // | |
820 | // Load TOF.RecPoints.root file | |
821 | // | |
822 | ||
823 | fTOFLoader->LoadRecPoints("recreate"); | |
824 | ||
825 | } | |
826 | //______________________________________________________________________________ | |
827 | ||
828 | void AliTOFClusterFinder::UnLoad() | |
829 | { | |
830 | // | |
831 | // Unload TOF.Digits.root and TOF.RecPoints.root files | |
832 | // | |
833 | ||
834 | fTOFLoader->UnloadDigits(); | |
835 | fTOFLoader->UnloadRecPoints(); | |
836 | ||
837 | } | |
838 | //______________________________________________________________________________ | |
839 | ||
840 | void AliTOFClusterFinder::UnLoadClusters() | |
841 | { | |
842 | // | |
843 | // Unload TOF.RecPoints.root file | |
844 | // | |
845 | ||
846 | fTOFLoader->UnloadRecPoints(); | |
847 | ||
848 | } | |
849 | //______________________________________________________________________________ |