Line data Source code
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 : /*
17 : $Log: AliTOFClusterFinder.cxx,v $
18 : Revision 1.31 2007/11/24 14:53:19 zampolli
19 : Status flag implemented as UChar_t
20 :
21 : Revision 1.30 2007/10/04 13:08:52 arcelli
22 : updates to comply with AliTOFGeometryV5 becoming AliTOFGeometry
23 :
24 : Revision 1.29 2007/10/03 10:42:33 arcelli
25 : updates to handle new AliTOFcluster, inheriting form AliCluster3D
26 :
27 : Revision 1.28 2007/05/31 16:06:05 arcelli
28 : move instance of AliRawStream outside loop on DDL
29 :
30 : Revision 1.27 2007/05/02 16:31:49 arcelli
31 : Add methods to handle single event reconstruction. retrieval of Calib
32 : info moved to AliTOFReconstructor ctor, and passed via a pointer to
33 : AliTOFcalib
34 :
35 : Revision 1.26 2007/04/30 19:02:24 arcelli
36 : hopefully the last refinements for correct type conversion in calibration
37 :
38 : Revision 1.25 2007/04/30 15:22:17 arcelli
39 : Change TOF digit Time, Tot etc to int type
40 :
41 : Revision 1.24 2007/04/27 11:19:31 arcelli
42 : updates for the new decoder
43 :
44 : Revision 1.23 2007/04/23 16:51:39 decaro
45 : Digits-to-raw_data conversion: correction for a more real description
46 : (A.De Caro, R.Preghenella)
47 :
48 : Revision 1.22 2007/04/19 17:26:32 arcelli
49 : Fix a bug (add some debug printout
50 :
51 : Revision 1.21 2007/04/18 17:28:12 arcelli
52 : Set the ToT bin width to the one actually used...
53 :
54 : Revision 1.20 2007/03/09 09:57:23 arcelli
55 : Remove a forgotten include of Riostrem
56 :
57 : Revision 1.19 2007/03/08 15:41:20 arcelli
58 : set uncorrected times when filling RecPoints
59 :
60 : Revision 1.18 2007/03/06 16:31:20 arcelli
61 : Add Uncorrected TOF Time signal
62 :
63 : Revision 1.17 2007/02/28 18:09:11 arcelli
64 : Add protection against failed retrieval of the CDB cal object,
65 : now Reconstruction exits with AliFatal
66 :
67 : Revision 1.16 2007/02/20 15:57:00 decaro
68 : Raw data update: to read the TOF raw data defined in UNPACKED mode
69 :
70 :
71 : Revision 0.03 2005/07/28 A. De Caro
72 : Implement public method
73 : Raw2Digits(Int_t, AliRawReader *)
74 : to convert digits from raw data in MC digits
75 : (temporary solution)
76 :
77 : Revision 0.02 2005/07/27 A. De Caro
78 : Implement public method
79 : Digits2RecPoint(Int_t)
80 : to convert digits in clusters
81 :
82 : Revision 0.02 2005/07/26 A. De Caro
83 : Implement private methods
84 : InsertCluster(AliTOFcluster *)
85 : FindClusterIndex(Double_t)
86 : originally implemented in AliTOFtracker
87 : by S. Arcelli and C. Zampolli
88 :
89 : Revision 0.01 2005/07/25 A. De Caro
90 : Implement public methods
91 : Digits2RecPoint(AliRawReader *, TTree *)
92 : Digits2RecPoint(Int_t, AliRawReader *)
93 : to convert raw data in clusters
94 : */
95 :
96 : ////////////////////////////////////////////////////////////////
97 : // //
98 : // Class for TOF cluster finder //
99 : // //
100 : // Starting from Raw Data, create rec points, //
101 : // fill TreeR for TOF, //
102 : // write TOF.RecPoints.root file //
103 : // //
104 : ////////////////////////////////////////////////////////////////
105 :
106 : #include "Riostream.h"
107 :
108 : #include "TClonesArray.h"
109 : #include "TStopwatch.h"
110 : #include "TTree.h"
111 : //#include <TGeoManager.h>
112 : #include <TGeoMatrix.h>
113 : //#include <TGeoPhysicalNode.h>
114 :
115 : #include "AliDAQ.h"
116 : #include "AliLoader.h"
117 : #include "AliLog.h"
118 : #include "AliRawReader.h"
119 : #include "AliRunLoader.h"
120 : //#include "AliAlignObj.h"
121 : #include <AliGeomManager.h>
122 :
123 : #include "AliTOFcalib.h"
124 : #include "AliTOFChannelOnlineArray.h"
125 : #include "AliTOFChannelOnlineStatusArray.h"
126 : #include "AliTOFChannelOffline.h"
127 : #include "AliTOFClusterFinder.h"
128 : #include "AliTOFcluster.h"
129 : #include "AliTOFdigit.h"
130 : #include "AliTOFGeometry.h"
131 : #include "AliTOFrawData.h"
132 :
133 : #include "AliTOFDeltaBCOffset.h"
134 : #include "AliTOFCTPLatency.h"
135 : #include "AliTOFRunParams.h"
136 :
137 : //extern TFile *gFile;
138 :
139 : using std::cout;
140 : using std::endl;
141 : using std::ofstream;
142 : using std::ios;
143 26 : ClassImp(AliTOFClusterFinder)
144 :
145 : AliTOFClusterFinder::AliTOFClusterFinder(AliTOFcalib *calib):
146 2 : TTask("AliTOFClusterFinder",""),
147 2 : fRunLoader(0),
148 2 : fTOFLoader(0),
149 2 : fTreeD(0),
150 2 : fTreeR(0),
151 6 : fDigits(new TClonesArray("AliTOFdigit", 4000)),
152 6 : fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
153 2 : fNumberOfTofClusters(0),
154 2 : fNumberOfTofTrgPads(0),
155 2 : fVerbose(0),
156 2 : fDecoderVersion(0),
157 2 : fTOFcalib(calib),
158 2 : fTOFRawStream(AliTOFRawStream())
159 10 : {
160 : //
161 : // Constructor
162 : //
163 :
164 311112 : for (Int_t ii=0; ii<kTofMaxCluster; ii++) fTofClusters[ii]=0x0;
165 :
166 2 : TString validity = (TString)fTOFcalib->GetOfflineValidity();
167 4 : if (validity.CompareTo("valid")==0) {
168 0 : AliInfo(Form(" validity = %s - Using offline calibration parameters",validity.Data()));
169 : } else {
170 8 : AliInfo(Form(" validity = %s - Using online calibration parameters",validity.Data()));
171 : }
172 :
173 4 : }
174 :
175 : //______________________________________________________________________________
176 :
177 : AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader, AliTOFcalib *calib):
178 0 : TTask("AliTOFClusterFinder",""),
179 0 : fRunLoader(runLoader),
180 0 : fTOFLoader(runLoader->GetLoader("TOFLoader")),
181 0 : fTreeD(0),
182 0 : fTreeR(0),
183 0 : fDigits(new TClonesArray("AliTOFdigit", 4000)),
184 0 : fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
185 0 : fNumberOfTofClusters(0),
186 0 : fNumberOfTofTrgPads(0),
187 0 : fVerbose(0),
188 0 : fDecoderVersion(0),
189 0 : fTOFcalib(calib),
190 0 : fTOFRawStream(AliTOFRawStream())
191 0 : {
192 : //
193 : // Constructor
194 : //
195 :
196 0 : for (Int_t ii=0; ii<kTofMaxCluster; ii++) fTofClusters[ii]=0x0;
197 :
198 0 : TString validity = (TString)fTOFcalib->GetOfflineValidity();
199 0 : if (validity.CompareTo("valid")==0) {
200 0 : AliInfo(Form(" validity = %s - Using offline calibration parameters",validity.Data()));
201 : } else {
202 0 : AliInfo(Form(" validity = %s - Using online calibration parameters",validity.Data()));
203 : }
204 :
205 0 : }
206 :
207 : //------------------------------------------------------------------------
208 : AliTOFClusterFinder::AliTOFClusterFinder(const AliTOFClusterFinder &source) :
209 0 : TTask(source),
210 0 : fRunLoader(0),
211 0 : fTOFLoader(0),
212 0 : fTreeD(0),
213 0 : fTreeR(0),
214 0 : fDigits(source.fDigits),
215 0 : fRecPoints(source.fRecPoints),
216 0 : fNumberOfTofClusters(0),
217 0 : fNumberOfTofTrgPads(0),
218 0 : fVerbose(0),
219 0 : fDecoderVersion(source.fDecoderVersion),
220 0 : fTOFcalib(source.fTOFcalib),
221 0 : fTOFRawStream(source.fTOFRawStream)
222 0 : {
223 : // copy constructor
224 :
225 0 : for (Int_t ii=0; ii<kTofMaxCluster; ii++) fTofClusters[ii]=source.fTofClusters[ii];
226 :
227 0 : }
228 :
229 : //------------------------------------------------------------------------
230 : AliTOFClusterFinder& AliTOFClusterFinder::operator=(const AliTOFClusterFinder &source)
231 : {
232 : // ass. op.
233 :
234 0 : if (this == &source)
235 0 : return *this;
236 :
237 0 : TTask::operator=(source);
238 0 : fDigits=source.fDigits;
239 0 : fRecPoints=source.fRecPoints;
240 0 : fVerbose=source.fVerbose;
241 0 : fDecoderVersion=source.fDecoderVersion;
242 0 : fTOFcalib=source.fTOFcalib;
243 0 : fTOFRawStream=source.fTOFRawStream;
244 0 : for (Int_t ii=0; ii<kTofMaxCluster; ii++) fTofClusters[ii]=source.fTofClusters[ii];
245 :
246 0 : return *this;
247 :
248 0 : }
249 : //______________________________________________________________________________
250 :
251 : AliTOFClusterFinder::~AliTOFClusterFinder()
252 12 : {
253 :
254 : //
255 : // Destructor
256 : //
257 :
258 2 : if (fDigits)
259 : {
260 2 : fDigits->Delete();
261 4 : delete fDigits;
262 2 : fDigits=0;
263 2 : }
264 2 : if (fRecPoints)
265 : {
266 2 : fRecPoints->Delete();
267 4 : delete fRecPoints;
268 2 : fRecPoints=0;
269 2 : }
270 :
271 : //if (fTofClusters || fNumberOfTofClusters) {
272 2 : if (fNumberOfTofClusters) {
273 0 : for (Int_t ii=0; ii<kTofMaxCluster; ii++) {
274 0 : if (fTofClusters[ii]) fTofClusters[ii]->Delete();
275 0 : delete fTofClusters[ii];
276 : }
277 0 : fNumberOfTofClusters=0;
278 0 : }
279 :
280 2 : fNumberOfTofTrgPads=0;
281 :
282 6 : }
283 : //______________________________________________________________________________
284 :
285 : void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
286 : {
287 : //
288 : // Converts digits to recpoints for TOF
289 : //
290 :
291 0 : TStopwatch stopwatch;
292 0 : stopwatch.Start();
293 :
294 : Int_t inholes = 0;
295 :
296 0 : fRunLoader->GetEvent(iEvent);
297 :
298 0 : fTreeD = fTOFLoader->TreeD();
299 0 : if (fTreeD == 0x0) {
300 0 : AliFatal("AliTOFClusterFinder: Can not get TreeD");
301 0 : return;
302 : }
303 :
304 0 : fDigits->Clear();
305 0 : fTreeD->GetBranch("TOF")->SetAutoDelete(kFALSE);
306 0 : fTreeD->SetBranchAddress("TOF",&fDigits);
307 :
308 0 : ResetRecpoint();
309 :
310 0 : fTreeR = fTOFLoader->TreeR();
311 0 : if (fTreeR == 0x0)
312 : {
313 0 : fTOFLoader->MakeTree("R");
314 0 : fTreeR = fTOFLoader->TreeR();
315 0 : }
316 :
317 : Int_t bufsize = 32000;
318 0 : fTreeR->Branch("TOF", &fRecPoints, bufsize);
319 :
320 0 : fTreeD->GetEvent(0);
321 0 : Int_t nDigits = fDigits->GetEntriesFast();
322 0 : AliDebug(2,Form("Number of TOF digits: %d",nDigits));
323 :
324 : Int_t ii;
325 0 : Int_t dig[5]={-1,-1,-1,-1,-1}; //cluster detector indeces
326 0 : Int_t parTOF[7]={0,0,0,0,0,0,0}; //The TOF signal parameters
327 : Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
328 0 : for (ii=0; ii<nDigits; ii++) {
329 0 : AliTOFdigit *d = (AliTOFdigit*)fDigits->UncheckedAt(ii);
330 0 : dig[0]=d->GetSector();
331 0 : dig[1]=d->GetPlate();
332 0 : dig[2]=d->GetStrip();
333 0 : dig[3]=d->GetPadz();
334 0 : dig[4]=d->GetPadx();
335 :
336 : /* check valid index */
337 0 : if (dig[0]==-1||dig[1]==-1||dig[2]==-1||dig[3]==-1||dig[4]==-1) continue;
338 :
339 : // Do not reconstruct anything in the holes
340 0 : if (dig[0]==13 || dig[0]==14 || dig[0]==15 ) { // sectors with holes
341 0 : if (dig[1]==2) { // plate with holes
342 0 : inholes++;
343 0 : continue;
344 : }
345 : }
346 :
347 0 : AliDebug(2,Form(" %2d %1d %2d %1d %2d ",dig[0],dig[1],dig[2],dig[3],dig[4]));
348 :
349 0 : parTOF[0] = d->GetTdc(); //the TDC signal
350 0 : parTOF[1] = d->GetToT(); //the ToT signal
351 0 : parTOF[2] = d->GetAdc(); // the adc charge
352 0 : parTOF[3] = d->GetTdcND(); // non decalibrated sim time
353 0 : parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
354 0 : parTOF[5] = 0; // deltaBC
355 0 : parTOF[6] = 0; // L0-L1 latency
356 0 : Double_t posClus[3];
357 0 : Double_t covClus[6];
358 0 : UShort_t volIdClus=GetClusterVolIndex(dig);
359 0 : GetClusterPars(dig, posClus,covClus);
360 0 : AliTOFcluster *tofCluster = new AliTOFcluster(volIdClus,posClus[0],posClus[1],posClus[2],covClus[0],covClus[1],covClus[2],covClus[3],covClus[4],covClus[5],d->GetTracks(),dig,parTOF,status,ii);
361 0 : InsertCluster(tofCluster);
362 :
363 0 : }
364 :
365 0 : AliDebug(1,Form("Number of found clusters: %d for event: %d", fNumberOfTofClusters, iEvent));
366 :
367 0 : CalibrateRecPoint();
368 0 : FillRecPoint();
369 :
370 0 : fTreeR->Fill();
371 : // ResetRecpoint();
372 :
373 0 : fTOFLoader = fRunLoader->GetLoader("TOFLoader");
374 0 : fTOFLoader->WriteRecPoints("OVERWRITE");
375 :
376 0 : AliDebug(1,Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
377 : stopwatch.RealTime(),stopwatch.CpuTime()));
378 0 : if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
379 :
380 0 : }
381 :
382 : //______________________________________________________________________________
383 :
384 : void AliTOFClusterFinder::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree)
385 : {
386 : //
387 : // Converts digits to recpoints for TOF
388 : //
389 :
390 8 : TStopwatch stopwatch;
391 4 : stopwatch.Start();
392 :
393 : Int_t inholes = 0;
394 :
395 4 : if (digitsTree == 0x0) {
396 0 : AliFatal("AliTOFClusterFinder: Can not get TreeD");
397 0 : return;
398 : }
399 :
400 4 : fDigits->Clear();
401 8 : digitsTree->GetBranch("TOF")->SetAutoDelete(kFALSE);
402 4 : digitsTree->SetBranchAddress("TOF",&fDigits);
403 :
404 4 : ResetRecpoint();
405 : Int_t bufsize = 32000;
406 4 : clusterTree->Branch("TOF", &fRecPoints, bufsize);
407 :
408 4 : digitsTree->GetEvent(0);
409 4 : Int_t nDigits = fDigits->GetEntriesFast();
410 20 : AliDebug(2,Form("Number of TOF digits: %d",nDigits));
411 :
412 : Int_t ii;
413 4 : Int_t dig[5]={-1,-1,-1,-1,-1}; //cluster detector indeces
414 4 : Int_t parTOF[7]={0,0,0,0,0,0,0}; //The TOF signal parameters
415 : Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
416 208 : for (ii=0; ii<nDigits; ii++) {
417 100 : AliTOFdigit *d = (AliTOFdigit*)fDigits->UncheckedAt(ii);
418 100 : dig[0]=d->GetSector();
419 100 : dig[1]=d->GetPlate();
420 100 : dig[2]=d->GetStrip();
421 100 : dig[3]=d->GetPadz();
422 100 : dig[4]=d->GetPadx();
423 :
424 : /* check valid index */
425 500 : if (dig[0]==-1||dig[1]==-1||dig[2]==-1||dig[3]==-1||dig[4]==-1) continue;
426 :
427 : // Do not reconstruct anything in the holes
428 296 : if (dig[0]==13 || dig[0]==14 || dig[0]==15 ) { // sectors with holes
429 2 : if (dig[1]==2) { // plate with holes
430 0 : inholes++;
431 0 : continue;
432 : }
433 : }
434 :
435 : // AliDebug(2,Form(" %2d %1d %2d %1d %2d ",dig[0],dig[1],dig[2],dig[3],dig[4]));
436 :
437 100 : parTOF[0] = d->GetTdc(); //the TDC signal
438 100 : parTOF[1] = d->GetToT(); //the ToT signal
439 100 : parTOF[2] = d->GetAdc(); // the adc charge
440 100 : parTOF[3] = d->GetTdcND(); // non decalibrated sim time
441 100 : parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
442 100 : parTOF[5] = 0; // deltaBC
443 100 : parTOF[6] = 0; // L0-L1 latency
444 :
445 100 : Double_t posClus[3];
446 100 : Double_t covClus[6];
447 100 : UShort_t volIdClus=GetClusterVolIndex(dig);
448 100 : GetClusterPars(dig,posClus,covClus);
449 300 : AliTOFcluster *tofCluster = new AliTOFcluster(volIdClus,posClus[0],posClus[1],posClus[2],covClus[0],covClus[1],covClus[2],covClus[3],covClus[4],covClus[5],d->GetTracks(),dig,parTOF,status,ii);
450 100 : InsertCluster(tofCluster);
451 :
452 100 : }
453 :
454 20 : AliDebug(1,Form("Number of found clusters: %d", fNumberOfTofClusters));
455 :
456 4 : CalibrateRecPoint();
457 4 : FillRecPoint();
458 :
459 4 : clusterTree->Fill();
460 : // ResetRecpoint();
461 :
462 20 : AliDebug(1,Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
463 : stopwatch.RealTime(),stopwatch.CpuTime()));
464 4 : if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
465 :
466 8 : }
467 : //______________________________________________________________________________
468 :
469 : void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
470 : TTree *clustersTree)
471 : {
472 : //
473 : // Converts RAW data to recpoints for TOF
474 : //
475 :
476 8 : TStopwatch stopwatch;
477 4 : stopwatch.Start();
478 :
479 : Int_t inholes = 0;
480 :
481 4 : const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
482 :
483 4 : ResetRecpoint();
484 :
485 : Int_t bufsize = 32000;
486 4 : clustersTree->Branch("TOF", &fRecPoints, bufsize);
487 :
488 : TClonesArray * clonesRawData;
489 : Int_t dummy = -1;
490 :
491 4 : Int_t detectorIndex[5]={-1,-1,-1,-1,-1};
492 4 : Int_t parTOF[7]={-1,-1,-1,-1,-1,-1,-1};
493 :
494 4 : ofstream ftxt;
495 4 : if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
496 :
497 4 : fTOFRawStream.Clear();
498 4 : fTOFRawStream.SetRawReader(rawReader);
499 :
500 4 : if (fDecoderVersion == 1) {
501 0 : AliInfo("Using New Decoder");
502 : }
503 8 : else if (fDecoderVersion == 2) {
504 12 : AliInfo("Using Enhanced Decoder");
505 : }
506 : else {
507 0 : AliInfo("Using Old Decoder");
508 : }
509 :
510 : Int_t indexDDL = 0;
511 584 : for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
512 :
513 288 : rawReader->Reset();
514 288 : if (fDecoderVersion == 1) {
515 0 : fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
516 : }
517 288 : else if (fDecoderVersion == 2) {
518 288 : fTOFRawStream.LoadRawDataBuffersV2(indexDDL,fVerbose);
519 : }
520 : else {
521 0 : fTOFRawStream.LoadRawData(indexDDL);
522 : }
523 :
524 288 : clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
525 :
526 1164 : for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
527 :
528 100 : AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
529 :
530 : //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
531 100 : if (tofRawDatum->GetTOF()==-1) continue;
532 :
533 100 : if (fVerbose==2) {
534 0 : if (indexDDL<10) ftxt << " " << indexDDL;
535 0 : else ftxt << " " << indexDDL;
536 0 : if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
537 0 : else ftxt << " " << tofRawDatum->GetTRM();
538 0 : ftxt << " " << tofRawDatum->GetTRMchain();
539 0 : if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
540 0 : else ftxt << " " << tofRawDatum->GetTDC();
541 0 : ftxt << " " << tofRawDatum->GetTDCchannel();
542 : }
543 :
544 100 : if ( tofRawDatum->GetTRM()==3 &&
545 1 : (tofRawDatum->GetTDC()> 11 && tofRawDatum->GetTDC()< 15) ) FillTOFtriggerMap(indexDDL, tofRawDatum);
546 :
547 1200 : for (Int_t aa=0; aa<5; aa++) detectorIndex[aa] = -1;
548 :
549 200 : fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
550 100 : tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
551 100 : dummy = detectorIndex[3];
552 100 : detectorIndex[3] = detectorIndex[4];
553 100 : detectorIndex[4] = dummy;
554 :
555 100 : if (fVerbose==2) {
556 0 : if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
557 0 : else ftxt << " -> " << detectorIndex[0];
558 0 : ftxt << " " << detectorIndex[1];
559 0 : if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
560 0 : else ftxt << " " << detectorIndex[2];
561 0 : ftxt << " " << detectorIndex[3];
562 0 : if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4];
563 0 : else ftxt << " " << detectorIndex[4];
564 : }
565 :
566 : /* check valid index */
567 500 : if (detectorIndex[0]==-1||detectorIndex[1]==-1||detectorIndex[2]==-1||detectorIndex[3]==-1||detectorIndex[4]==-1) continue;
568 :
569 : // Do not reconstruct anything in the holes
570 296 : if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
571 2 : if (detectorIndex[1]==2) { // plate with holes
572 0 : inholes++;
573 0 : continue;
574 : }
575 : }
576 :
577 100 : parTOF[0] = tofRawDatum->GetTOF(); //TDC
578 200 : parTOF[1] = tofRawDatum->GetTOT(); // TOT
579 200 : parTOF[2] = tofRawDatum->GetTOT(); //ADC==TOF
580 100 : parTOF[3] = 0;//raw data: no track of undecalib sim time
581 100 : parTOF[4] = tofRawDatum->GetTOF(); // RAW time
582 100 : parTOF[5] = tofRawDatum->GetDeltaBC(); // deltaBC
583 100 : parTOF[6] = tofRawDatum->GetL0L1Latency(); // L0-L1 latency
584 100 : Double_t posClus[3];
585 100 : Double_t covClus[6];
586 100 : UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
587 100 : Int_t lab[3]={-1,-1,-1};
588 : Bool_t status=kTRUE;
589 100 : GetClusterPars(detectorIndex,posClus,covClus);
590 200 : AliTOFcluster *tofCluster = new AliTOFcluster(volIdClus,posClus[0],posClus[1],posClus[2],covClus[0],covClus[1],covClus[2],covClus[3],covClus[4],covClus[5],lab,detectorIndex,parTOF,status,-1);
591 100 : InsertCluster(tofCluster);
592 :
593 100 : if (fVerbose==2) {
594 0 : if (parTOF[1]<10)ftxt << " " << parTOF[1];
595 0 : else if (parTOF[1]>=10 && parTOF[1]<100) ftxt << " " << parTOF[1];
596 0 : else ftxt << " " << parTOF[1];
597 0 : if (parTOF[0]<10) ftxt << " " << parTOF[0] << endl;
598 0 : else if (parTOF[0]>=10 && parTOF[0]<100) ftxt << " " << parTOF[0] << endl;
599 0 : else if (parTOF[0]>=100 && parTOF[0]<1000) ftxt << " " << parTOF[0] << endl;
600 0 : else ftxt << " " << parTOF[0] << endl;
601 : }
602 :
603 100 : } // closed loop on TOF raw data per current DDL file
604 :
605 288 : clonesRawData->Clear("C");
606 :
607 : } // closed loop on DDL index
608 :
609 4 : if (fVerbose==2) ftxt.close();
610 :
611 20 : AliDebug(1,Form("Number of found clusters: %d", fNumberOfTofClusters));
612 :
613 8 : CalibrateRecPoint(rawReader->GetTimestamp());
614 4 : FillRecPoint();
615 :
616 4 : clustersTree->Fill();
617 :
618 : // ResetRecpoint();
619 :
620 20 : AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
621 : stopwatch.RealTime(),stopwatch.CpuTime()));
622 4 : if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
623 :
624 4 : }
625 : //______________________________________________________________________________
626 :
627 : void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader)
628 : {
629 : //
630 : // Converts RAW data to recpoints for TOF
631 : //
632 :
633 0 : TStopwatch stopwatch;
634 0 : stopwatch.Start();
635 :
636 : Int_t inholes = 0;
637 :
638 0 : const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
639 :
640 0 : fRunLoader->GetEvent(iEvent);
641 :
642 0 : AliDebug(2,Form(" Event number %2d ", iEvent));
643 :
644 0 : fTreeR = fTOFLoader->TreeR();
645 :
646 0 : if (fTreeR == 0x0){
647 0 : fTOFLoader->MakeTree("R");
648 0 : fTreeR = fTOFLoader->TreeR();
649 0 : }
650 :
651 : Int_t bufsize = 32000;
652 0 : fTreeR->Branch("TOF", &fRecPoints, bufsize);
653 :
654 : TClonesArray * clonesRawData;
655 :
656 : Int_t dummy = -1;
657 :
658 0 : Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
659 0 : Int_t parTOF[7];
660 0 : ofstream ftxt;
661 0 : if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
662 :
663 0 : fTOFRawStream.Clear();
664 0 : fTOFRawStream.SetRawReader(rawReader);
665 :
666 0 : if (fDecoderVersion == 1) {
667 0 : AliInfo("Using New Decoder");
668 : }
669 0 : else if (fDecoderVersion == 2) {
670 0 : AliInfo("Using Enhanced Decoder");
671 : }
672 : else {
673 0 : AliInfo("Using Old Decoder");
674 : }
675 :
676 : Int_t indexDDL = 0;
677 0 : for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
678 :
679 0 : rawReader->Reset();
680 0 : if (fDecoderVersion == 1) {
681 0 : fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
682 : }
683 0 : else if (fDecoderVersion == 2) {
684 0 : fTOFRawStream.LoadRawDataBuffersV2(indexDDL,fVerbose);
685 : }
686 : else {
687 0 : fTOFRawStream.LoadRawData(indexDDL);
688 : }
689 :
690 0 : clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
691 :
692 0 : for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
693 :
694 0 : AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
695 :
696 : //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
697 0 : if (tofRawDatum->GetTOF()==-1) continue;
698 :
699 0 : if (fVerbose==2) {
700 0 : if (indexDDL<10) ftxt << " " << indexDDL;
701 0 : else ftxt << " " << indexDDL;
702 0 : if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
703 0 : else ftxt << " " << tofRawDatum->GetTRM();
704 0 : ftxt << " " << tofRawDatum->GetTRMchain();
705 0 : if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
706 0 : else ftxt << " " << tofRawDatum->GetTDC();
707 0 : ftxt << " " << tofRawDatum->GetTDCchannel();
708 : }
709 :
710 0 : fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
711 0 : tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
712 0 : dummy = detectorIndex[3];
713 0 : detectorIndex[3] = detectorIndex[4];
714 0 : detectorIndex[4] = dummy;
715 :
716 0 : if (fVerbose==2) {
717 0 : if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
718 0 : else ftxt << " -> " << detectorIndex[0];
719 0 : ftxt << " " << detectorIndex[1];
720 0 : if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
721 0 : else ftxt << " " << detectorIndex[2];
722 0 : ftxt << " " << detectorIndex[3];
723 0 : if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4];
724 0 : else ftxt << " " << detectorIndex[4];
725 : }
726 :
727 : /* check valid index */
728 0 : if (detectorIndex[0]==-1||detectorIndex[1]==-1||detectorIndex[2]==-1||detectorIndex[3]==-1||detectorIndex[4]==-1) continue;
729 :
730 : // Do not reconstruct anything in the holes
731 0 : if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
732 0 : if (detectorIndex[1]==2) { // plate with holes
733 0 : inholes++;
734 0 : continue;
735 : }
736 : }
737 :
738 0 : parTOF[0] = tofRawDatum->GetTOF(); // TDC
739 0 : parTOF[1] = tofRawDatum->GetTOT(); // TOT
740 0 : parTOF[2] = tofRawDatum->GetTOT(); // raw data have ADC=TOT
741 0 : parTOF[3] = 0; //raw data: no track of the undecalib sim time
742 0 : parTOF[4] = tofRawDatum->GetTOF(); // Raw time == TDC
743 0 : parTOF[5] = tofRawDatum->GetDeltaBC(); // deltaBC
744 0 : parTOF[6] = tofRawDatum->GetL0L1Latency(); // L0-L1 latency
745 0 : Double_t posClus[3];
746 0 : Double_t covClus[6];
747 0 : UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
748 0 : Int_t lab[3]={-1,-1,-1};
749 : Bool_t status=kTRUE;
750 0 : GetClusterPars(detectorIndex,posClus,covClus);
751 0 : AliTOFcluster *tofCluster = new AliTOFcluster(volIdClus,posClus[0],posClus[1],posClus[2],covClus[0],covClus[1],covClus[2],covClus[3],covClus[4],covClus[5],lab,detectorIndex,parTOF,status,-1);
752 0 : InsertCluster(tofCluster);
753 :
754 0 : if (fVerbose==2) {
755 0 : if (parTOF[1]<10)ftxt << " " << parTOF[1];
756 0 : else if (parTOF[1]>=10 && parTOF[1]<100) ftxt << " " << parTOF[1];
757 0 : else ftxt << " " << parTOF[1];
758 0 : if (parTOF[0]<10) ftxt << " " << parTOF[0] << endl;
759 0 : else if (parTOF[0]>=10 && parTOF[0]<100) ftxt << " " << parTOF[0] << endl;
760 0 : else if (parTOF[0]>=100 && parTOF[0]<1000) ftxt << " " << parTOF[0] << endl;
761 0 : else ftxt << " " << parTOF[0] << endl;
762 : }
763 :
764 0 : } // closed loop on TOF raw data per current DDL file
765 :
766 0 : clonesRawData->Clear("C");
767 :
768 : } // closed loop on DDL index
769 :
770 0 : if (fVerbose==2) ftxt.close();
771 :
772 0 : AliDebug(1,Form("Number of found clusters: %d for event: %d", fNumberOfTofClusters, iEvent));
773 :
774 0 : CalibrateRecPoint(rawReader->GetTimestamp());
775 0 : FillRecPoint();
776 :
777 0 : fTreeR->Fill();
778 : // ResetRecpoint();
779 :
780 0 : fTOFLoader = fRunLoader->GetLoader("TOFLoader");
781 0 : fTOFLoader->WriteRecPoints("OVERWRITE");
782 :
783 0 : AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
784 : stopwatch.RealTime(),stopwatch.CpuTime()));
785 0 : if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
786 :
787 0 : }
788 : //______________________________________________________________________________
789 :
790 : void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
791 : {
792 : //
793 : // Converts RAW data to MC digits for TOF
794 : //
795 : // (temporary solution)
796 : //
797 :
798 0 : TStopwatch stopwatch;
799 0 : stopwatch.Start();
800 :
801 0 : const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
802 :
803 0 : fRunLoader->GetEvent(iEvent);
804 :
805 0 : fTreeD = fTOFLoader->TreeD();
806 0 : if (fTreeD)
807 : {
808 0 : AliInfo("TreeD re-creation");
809 0 : fTreeD = 0x0;
810 0 : fTOFLoader->MakeTree("D");
811 0 : fTreeD = fTOFLoader->TreeD();
812 : }
813 : else {
814 0 : AliFatal("Can not get TreeD");
815 0 : return;
816 : }
817 :
818 : Int_t bufsize = 32000;
819 0 : fDigits->Clear();
820 0 : fTreeD->Branch("TOF", &fDigits, bufsize);
821 :
822 0 : fRunLoader->GetEvent(iEvent);
823 :
824 0 : AliDebug(2,Form(" Event number %2d ", iEvent));
825 :
826 : TClonesArray * clonesRawData;
827 :
828 : Int_t dummy = -1;
829 :
830 0 : Int_t detectorIndex[5];
831 0 : Int_t digit[4];
832 :
833 0 : fTOFRawStream.Clear();
834 0 : fTOFRawStream.SetRawReader(rawReader);
835 :
836 0 : if (fDecoderVersion == 1) {
837 0 : AliInfo("Using New Decoder");
838 : }
839 0 : else if (fDecoderVersion == 2) {
840 0 : AliInfo("Using Enhanced Decoder");
841 : }
842 : else {
843 0 : AliInfo("Using Old Decoder");
844 : }
845 :
846 : Int_t indexDDL = 0;
847 0 : for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
848 :
849 0 : rawReader->Reset();
850 0 : if (fDecoderVersion == 1) {
851 0 : fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
852 : }
853 0 : else if (fDecoderVersion == 2) {
854 0 : fTOFRawStream.LoadRawDataBuffersV2(indexDDL,fVerbose);
855 : }
856 : else {
857 0 : fTOFRawStream.LoadRawData(indexDDL);
858 : }
859 :
860 0 : clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
861 :
862 0 : for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
863 :
864 0 : AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
865 :
866 : //if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
867 0 : if (tofRawDatum->GetTOF()==-1) continue;
868 :
869 0 : fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
870 0 : tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
871 0 : dummy = detectorIndex[3];
872 0 : detectorIndex[3] = detectorIndex[4];
873 0 : detectorIndex[4] = dummy;
874 :
875 0 : digit[0] = fTOFRawStream.GetTofBin();
876 0 : digit[1] = fTOFRawStream.GetToTbin();
877 0 : digit[2] = fTOFRawStream.GetToTbin();
878 0 : digit[3] = 0;
879 :
880 0 : Int_t tracknum[3]={-1,-1,-1};
881 :
882 0 : TClonesArray &aDigits = *fDigits;
883 0 : Int_t last=fDigits->GetEntriesFast();
884 0 : new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
885 :
886 0 : } // while loop
887 :
888 0 : clonesRawData->Clear("C");
889 :
890 : } // DDL Loop
891 :
892 0 : fTreeD->Fill();
893 :
894 0 : fTOFLoader = fRunLoader->GetLoader("TOFLoader");
895 0 : fTOFLoader->WriteDigits("OVERWRITE");
896 :
897 0 : AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.2fs C:%.2fs",
898 : stopwatch.RealTime(),stopwatch.CpuTime()));
899 :
900 0 : }
901 :
902 : //______________________________________________________________________________
903 :
904 : void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
905 : {
906 : //
907 : // Converts RAW data to MC digits for TOF for the current event
908 : //
909 : //
910 :
911 0 : TStopwatch stopwatch;
912 0 : stopwatch.Start();
913 :
914 0 : const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
915 :
916 0 : if (!digitsTree)
917 : {
918 0 : AliError("No input digits Tree");
919 0 : return;
920 : }
921 :
922 : Int_t bufsize = 32000;
923 0 : digitsTree->Branch("TOF", &fDigits, bufsize);
924 :
925 : TClonesArray * clonesRawData;
926 : Int_t dummy = -1;
927 :
928 0 : Int_t detectorIndex[5];
929 0 : Int_t digit[4];
930 :
931 0 : fTOFRawStream.Clear();
932 0 : fTOFRawStream.SetRawReader(rawReader);
933 :
934 0 : if (fDecoderVersion == 1) {
935 0 : AliInfo("Using New Decoder");
936 : }
937 0 : else if (fDecoderVersion == 2) {
938 0 : AliInfo("Using Enhanced Decoder");
939 : }
940 : else {
941 0 : AliInfo("Using Old Decoder");
942 : }
943 :
944 : Int_t indexDDL = 0;
945 0 : for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
946 :
947 0 : rawReader->Reset();
948 0 : if (fDecoderVersion == 1) {
949 0 : fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
950 : }
951 0 : else if (fDecoderVersion == 2) {
952 0 : fTOFRawStream.LoadRawDataBuffersV2(indexDDL,fVerbose);
953 : }
954 : else {
955 0 : fTOFRawStream.LoadRawData(indexDDL);
956 : }
957 :
958 0 : clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
959 :
960 0 : for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
961 :
962 0 : AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
963 :
964 : //if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
965 0 : if (tofRawDatum->GetTOF()==-1) continue;
966 :
967 0 : fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
968 0 : tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
969 0 : dummy = detectorIndex[3];
970 0 : detectorIndex[3] = detectorIndex[4];
971 0 : detectorIndex[4] = dummy;
972 :
973 0 : digit[0] = fTOFRawStream.GetTofBin();
974 0 : digit[1] = fTOFRawStream.GetToTbin();
975 0 : digit[2] = fTOFRawStream.GetToTbin();
976 0 : digit[3] = 0;
977 :
978 0 : Int_t tracknum[3]={-1,-1,-1};
979 :
980 0 : TClonesArray &aDigits = *fDigits;
981 0 : Int_t last=fDigits->GetEntriesFast();
982 0 : new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
983 :
984 0 : } // while loop
985 :
986 0 : clonesRawData->Clear("C");
987 :
988 : } // DDL Loop
989 :
990 0 : digitsTree->Fill();
991 :
992 0 : AliDebug(1, Form("Got %d digits: ", fDigits->GetEntries()));
993 0 : AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
994 : stopwatch.RealTime(),stopwatch.CpuTime()));
995 :
996 0 : }
997 : //______________________________________________________________________________
998 :
999 : Int_t AliTOFClusterFinder::InsertCluster(AliTOFcluster *tofCluster) {
1000 : //---------------------------------------------------------------------------//
1001 : // This function adds a TOF cluster to the array of TOF clusters sorted in Z //
1002 : //---------------------------------------------------------------------------//
1003 400 : if (fNumberOfTofClusters==kTofMaxCluster) {
1004 0 : AliError("Too many clusters !");
1005 0 : return 1;
1006 : }
1007 :
1008 200 : if (fNumberOfTofClusters==0) {
1009 8 : fTofClusters[fNumberOfTofClusters++] = tofCluster;
1010 8 : return 0;
1011 : }
1012 :
1013 192 : Int_t ii = FindClusterIndex(tofCluster->GetZ());
1014 192 : memmove(fTofClusters+ii+1 ,fTofClusters+ii,(fNumberOfTofClusters-ii)*sizeof(AliTOFcluster*));
1015 192 : fTofClusters[ii] = tofCluster;
1016 192 : fNumberOfTofClusters++;
1017 :
1018 : return 0;
1019 :
1020 200 : }
1021 : //_________________________________________________________________________
1022 :
1023 : Int_t AliTOFClusterFinder::FindClusterIndex(Double_t z) const {
1024 : //--------------------------------------------------------------------
1025 : // This function returns the index of the nearest cluster in z
1026 : //--------------------------------------------------------------------
1027 384 : if (fNumberOfTofClusters==0) return 0;
1028 226 : if (z <= fTofClusters[0]->GetZ()) return 0;
1029 170 : if (z > fTofClusters[fNumberOfTofClusters-1]->GetZ()) return fNumberOfTofClusters;
1030 146 : Int_t b = 0, e = fNumberOfTofClusters-1, m = (b+e)/2;
1031 1338 : for (; b<e; m=(b+e)/2) {
1032 774 : if (z > fTofClusters[m]->GetZ()) b=m+1;
1033 : else e=m;
1034 : }
1035 :
1036 : return m;
1037 :
1038 192 : }
1039 : //_________________________________________________________________________
1040 :
1041 : void AliTOFClusterFinder::FillRecPoint()
1042 : {
1043 : //
1044 : // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
1045 : // in Z) in the global TClonesArray of AliTOFcluster,
1046 : // i.e. fRecPoints.
1047 : //
1048 :
1049 : Int_t ii, jj;
1050 :
1051 16 : Int_t detectorIndex[5];
1052 8 : Int_t parTOF[7];
1053 8 : Int_t trackLabels[3];
1054 : Int_t digitIndex = -1;
1055 : Bool_t status=kTRUE;
1056 :
1057 8 : TClonesArray &lRecPoints = *fRecPoints;
1058 :
1059 416 : for (ii=0; ii<fNumberOfTofClusters; ii++) {
1060 200 : AliTOFcluster* clOr = fTofClusters[ii];
1061 200 : fTofClusters[ii] = 0;
1062 200 : digitIndex = clOr->GetIndex();
1063 2400 : for(jj=0; jj<5; jj++) detectorIndex[jj] = clOr->GetDetInd(jj);
1064 1600 : for(jj=0; jj<3; jj++) trackLabels[jj] = clOr->GetLabel(jj);
1065 200 : parTOF[0] = clOr->GetTDC(); // TDC
1066 200 : parTOF[1] = clOr->GetToT(); // TOT
1067 200 : parTOF[2] = clOr->GetADC(); // ADC=TOT
1068 200 : parTOF[3] = clOr->GetTDCND(); // TDCND
1069 200 : parTOF[4] = clOr->GetTDCRAW();//RAW
1070 200 : parTOF[5] = clOr->GetDeltaBC();//deltaBC
1071 200 : parTOF[6] = clOr->GetL0L1Latency();//L0-L1 latency
1072 200 : status=clOr->GetStatus();
1073 200 : Double_t posClus[3];
1074 200 : Double_t covClus[6];
1075 200 : UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
1076 200 : GetClusterPars(detectorIndex,posClus,covClus);
1077 200 : new(lRecPoints[ii]) AliTOFcluster(volIdClus,posClus[0],posClus[1],posClus[2],covClus[0],covClus[1],covClus[2],covClus[3],covClus[4],covClus[5],trackLabels,detectorIndex, parTOF,status,digitIndex);
1078 :
1079 600 : AliDebug(2, Form(" %4d %4d %f %f %f %f %f %f %f %f %f %3d %3d %3d %2d %1d %2d %1d %2d %4d %3d %3d %4d %4d %1d %4d",
1080 : ii, volIdClus, posClus[0], posClus[1], posClus[2],
1081 : clOr->GetSigmaX2(),
1082 : clOr->GetSigmaXY(),
1083 : clOr->GetSigmaXZ(),
1084 : clOr->GetSigmaY2(),
1085 : clOr->GetSigmaYZ(),
1086 : clOr->GetSigmaZ2(),
1087 : trackLabels[0], trackLabels[1], trackLabels[2],
1088 : detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[3], detectorIndex[4],
1089 : parTOF[0], parTOF[1], parTOF[2], parTOF[3], parTOF[4],
1090 : status, digitIndex));
1091 :
1092 400 : delete clOr;
1093 200 : } // loop on clusters
1094 :
1095 8 : }
1096 :
1097 : //_________________________________________________________________________
1098 :
1099 : /*
1100 : * OLD CALIBRATE REC POINTS FUNCTION
1101 : */
1102 :
1103 : #if 0
1104 : void AliTOFClusterFinder::CalibrateRecPoint(UInt_t timestamp)
1105 : {
1106 : //
1107 : // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
1108 : // in Z) in the global TClonesArray of AliTOFcluster,
1109 : // i.e. fRecPoints.
1110 : //
1111 :
1112 : Int_t ii, jj;
1113 :
1114 : Int_t detectorIndex[5];
1115 : Int_t digitIndex = -1;
1116 : Double_t tToT;
1117 : Double_t timeCorr;
1118 : Int_t tdcCorr;
1119 : Float_t tdcLatencyWindow;
1120 : AliDebug(1," Calibrating TOF Clusters");
1121 :
1122 : AliTOFChannelOnlineArray *calDelay = fTOFcalib->GetTOFOnlineDelay();
1123 : AliTOFChannelOnlineStatusArray *calStatus = fTOFcalib->GetTOFOnlineStatus();
1124 : TObjArray *calTOFArrayOffline = fTOFcalib->GetTOFCalArrayOffline();
1125 :
1126 : AliTOFDeltaBCOffset *deltaBCOffsetObj = fTOFcalib->GetDeltaBCOffset();
1127 : Int_t deltaBCOffset = deltaBCOffsetObj->GetDeltaBCOffset();
1128 : AliTOFCTPLatency *ctpLatencyObj = fTOFcalib->GetCTPLatency();
1129 : Float_t ctpLatency = ctpLatencyObj->GetCTPLatency();
1130 : AliTOFRunParams *runParamsObj = fTOFcalib->GetRunParams();
1131 : Float_t t0 = runParamsObj->EvalT0(timestamp);
1132 :
1133 : TString validity = (TString)fTOFcalib->GetOfflineValidity();
1134 : Int_t calibration = -1;
1135 : if (validity.CompareTo("valid")==0) {
1136 : //AliInfo(Form(" validity = %s - Using offline calibration parameters",validity.Data()));
1137 : calibration = 1;
1138 : } else {
1139 : //AliInfo(Form(" validity = %s - Using online calibration parameters",validity.Data()));
1140 : calibration = 0 ;
1141 : }
1142 :
1143 : for (ii=0; ii<fNumberOfTofClusters; ii++) {
1144 : digitIndex = fTofClusters[ii]->GetIndex();
1145 : for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
1146 :
1147 : Int_t index = AliTOFGeometry::GetIndex(detectorIndex);
1148 :
1149 : UChar_t statusPulser=calStatus->GetPulserStatus(index);
1150 : UChar_t statusNoise=calStatus->GetNoiseStatus(index);
1151 : UChar_t statusHW=calStatus->GetHWStatus(index);
1152 : UChar_t status=calStatus->GetStatus(index);
1153 : tdcLatencyWindow = calStatus->GetLatencyWindow(index) * 1.e3; /* ns -> ps */
1154 :
1155 : //check the status, also unknown is fine!!!!!!!
1156 :
1157 : AliDebug(2, Form(" Status for channel %d = %d",index, (Int_t)status));
1158 : if((statusPulser & AliTOFChannelOnlineStatusArray::kTOFPulserBad)==(AliTOFChannelOnlineStatusArray::kTOFPulserBad)||(statusNoise & AliTOFChannelOnlineStatusArray::kTOFNoiseBad)==(AliTOFChannelOnlineStatusArray::kTOFNoiseBad)||(statusHW & AliTOFChannelOnlineStatusArray::kTOFHWBad)==(AliTOFChannelOnlineStatusArray::kTOFHWBad)){
1159 : AliDebug(2, Form(" Bad Status for channel %d",index));
1160 : fTofClusters[ii]->SetStatus(kFALSE); //odd convention, to avoid conflict with calibration objects currently in the db (temporary solution).
1161 : }
1162 : else {
1163 : AliDebug(2, Form(" Good Status for channel %d",index));
1164 : }
1165 : // Get Rough channel online equalization
1166 : Double_t roughDelay=(Double_t)calDelay->GetDelay(index); // in ns
1167 : AliDebug(2,Form(" channel delay (ns) = %f", roughDelay));
1168 : // Get Refined channel offline calibration parameters
1169 : if (calibration ==1){
1170 : AliTOFChannelOffline * calChannelOffline = (AliTOFChannelOffline*)calTOFArrayOffline->At(index);
1171 : Double_t par[6];
1172 : for (Int_t j = 0; j<6; j++){
1173 : par[j]=(Double_t)calChannelOffline->GetSlewPar(j);
1174 : }
1175 : AliDebug(2,Form(" Calib Pars = %f, %f, %f, %f, %f, %f ",par[0],par[1],par[2],par[3],par[4],par[5]));
1176 : AliDebug(2,Form(" The ToT and Time, uncorr (counts) = %d , %d", fTofClusters[ii]->GetToT(),fTofClusters[ii]->GetTDC()));
1177 : tToT = (Double_t)(fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth());
1178 : tToT*=1.E-3; //ToT in ns
1179 :
1180 : /* check TOT limits and set new TOT in case */
1181 : if (tToT < AliTOFGeometry::SlewTOTMin()) tToT = AliTOFGeometry::SlewTOTMin();
1182 : if (tToT > AliTOFGeometry::SlewTOTMax()) tToT = AliTOFGeometry::SlewTOTMax();
1183 :
1184 : AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,tToT));
1185 : 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; // the time correction (ns)
1186 : }
1187 : else {
1188 : timeCorr = roughDelay; // correction in ns
1189 : }
1190 : AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth()));
1191 : AliDebug(2,Form(" The time correction (ns) = %f", timeCorr));
1192 : timeCorr=(Double_t)(fTofClusters[ii]->GetTDC())*AliTOFGeometry::TdcBinWidth()*1.E-3-timeCorr;//redefine the time
1193 : timeCorr*=1.E3;
1194 : AliDebug(2,Form(" The channel time, corr (ps)= %e",timeCorr ));
1195 :
1196 : /* here timeCorr should be already corrected for calibration.
1197 : * we now go into further corrections keeping in mind that timeCorr
1198 : * is in ps.
1199 : *
1200 : * the following corrections are performed in this way:
1201 : *
1202 : * time = timeRaw - deltaBC + L0L1Latency + CTPLatency - TDCLatencyWindow - T0
1203 : *
1204 : */
1205 :
1206 : AliDebug(2, Form("applying further corrections (DeltaBC): DeltaBC=%d (BC bins), DeltaBCoffset=%d (BC bins)", fTofClusters[ii]->GetDeltaBC(), deltaBCOffset));
1207 : AliDebug(2, Form("applying further corrections (L0L1Latency): L0L1Latency=%d (BC bins)", fTofClusters[ii]->GetL0L1Latency()));
1208 : AliDebug(2, Form("applying further corrections (CTPLatency): CTPLatency=%f (ps)", ctpLatency));
1209 : AliDebug(2, Form("applying further corrections (TDCLatencyWindow): TDCLatencyWindow=%f (ps)", tdcLatencyWindow));
1210 : AliDebug(2, Form("applying further corrections (T0): T0=%f (ps)", t0));
1211 :
1212 : /* deltaBC correction (inhibited for the time being) */
1213 : // timeCorr -= (fTofClusters[ii]->GetDeltaBC() - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth();
1214 : /* L0L1-latency correction */
1215 : timeCorr += fTofClusters[ii]->GetL0L1Latency() * AliTOFGeometry::BunchCrossingBinWidth();
1216 : /* CTP-latency correction (from OCDB) */
1217 : timeCorr += ctpLatency;
1218 : /* TDC latency-window correction (from OCDB) */
1219 : timeCorr -= tdcLatencyWindow;
1220 : /* T0 correction (from OCDB) */
1221 : timeCorr -= t0;
1222 :
1223 : /*
1224 : * end of furhter corrections
1225 : */
1226 :
1227 : tdcCorr=(Int_t)(timeCorr/AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
1228 : fTofClusters[ii]->SetTDC(tdcCorr);
1229 :
1230 : } // loop on clusters
1231 :
1232 : }
1233 : #endif
1234 :
1235 : //_________________________________________________________________________
1236 :
1237 : void AliTOFClusterFinder::CalibrateRecPoint(UInt_t timestamp)
1238 : {
1239 : //
1240 : // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
1241 : // in Z) in the global TClonesArray of AliTOFcluster,
1242 : // i.e. fRecPoints.
1243 : //
1244 :
1245 16 : Int_t detectorIndex[5];
1246 : Double_t time, tot, corr;
1247 : Int_t deltaBC, l0l1, tdcBin;
1248 416 : for (Int_t ii = 0; ii < fNumberOfTofClusters; ii++) {
1249 2400 : for(Int_t jj = 0; jj < 5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
1250 :
1251 200 : Int_t index = AliTOFGeometry::GetIndex(detectorIndex);
1252 :
1253 : /* check channel enabled */
1254 200 : if (!fTOFcalib->IsChannelEnabled(index)) fTofClusters[ii]->SetStatus(kFALSE);
1255 :
1256 : /* get cluster info */
1257 200 : time = fTofClusters[ii]->GetTDC() * AliTOFGeometry::TdcBinWidth(); /* ps */
1258 200 : tot = fTofClusters[ii]->GetToT() * AliTOFGeometry::ToTBinWidth() * 1.e-3; /* ns */
1259 200 : deltaBC = fTofClusters[ii]->GetDeltaBC();
1260 200 : l0l1 = fTofClusters[ii]->GetL0L1Latency();
1261 :
1262 : /* get correction */
1263 200 : corr = fTOFcalib->GetTimeCorrection(index, tot, deltaBC, l0l1, timestamp); /* ps */
1264 600 : AliDebug(2, Form("calibrate index %d: time=%f (ps) tot=%f (ns) deltaBC=%d l0l1=%d timestamp=%d corr=%f (ps)", index, time, tot, deltaBC, l0l1, timestamp, corr));
1265 :
1266 : /* apply time correction */
1267 200 : time -= corr;
1268 :
1269 : /* convert in TDC bins and set cluster */
1270 : //tdcBin = (Int_t)(time / AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
1271 200 : tdcBin = TMath::Nint(time / AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
1272 200 : fTofClusters[ii]->SetTDC(tdcBin);
1273 :
1274 : // noferini
1275 200 : Float_t pos[3];
1276 200 : AliTOFGeometry::GetPosPar(detectorIndex, pos);
1277 : Float_t length = 0.;
1278 1600 : for (Int_t ic = 0; ic < 3; ic++) length += pos[ic] * pos[ic];
1279 200 : length = TMath::Sqrt(length);
1280 200 : Float_t timealligned = tdcBin*24.4 - length * 0.0333564095198152043; // subtract the minimal time in
1281 :
1282 378 : if(timealligned > -1000 && timealligned < 24000 && fTOFcalib->IsChannelEnabled(index)){
1283 178 : fNumberOfTofTrgPads++;
1284 178 : }
1285 :
1286 200 : } // loop on clusters
1287 :
1288 8 : }
1289 :
1290 : //______________________________________________________________________________
1291 :
1292 : void AliTOFClusterFinder::ResetRecpoint()
1293 : {
1294 : //
1295 : // Clear the list of reconstructed points
1296 : //
1297 :
1298 32 : fNumberOfTofClusters = 0;
1299 16 : fNumberOfTofTrgPads = 0;
1300 32 : if (fRecPoints) fRecPoints->Clear();
1301 :
1302 16 : }
1303 : //______________________________________________________________________________
1304 :
1305 : void AliTOFClusterFinder::Load()
1306 : {
1307 : //
1308 : // Load TOF.Digits.root and TOF.RecPoints.root files
1309 : //
1310 :
1311 0 : fTOFLoader->LoadDigits("READ");
1312 0 : fTOFLoader->LoadRecPoints("recreate");
1313 :
1314 0 : }
1315 : //______________________________________________________________________________
1316 :
1317 : void AliTOFClusterFinder::LoadClusters()
1318 : {
1319 : //
1320 : // Load TOF.RecPoints.root file
1321 : //
1322 :
1323 0 : fTOFLoader->LoadRecPoints("recreate");
1324 :
1325 0 : }
1326 : //______________________________________________________________________________
1327 :
1328 : void AliTOFClusterFinder::UnLoad()
1329 : {
1330 : //
1331 : // Unload TOF.Digits.root and TOF.RecPoints.root files
1332 : //
1333 :
1334 0 : fTOFLoader->UnloadDigits();
1335 0 : fTOFLoader->UnloadRecPoints();
1336 :
1337 0 : }
1338 : //______________________________________________________________________________
1339 :
1340 : void AliTOFClusterFinder::UnLoadClusters()
1341 : {
1342 : //
1343 : // Unload TOF.RecPoints.root file
1344 : //
1345 :
1346 0 : fTOFLoader->UnloadRecPoints();
1347 :
1348 0 : }
1349 : //-------------------------------------------------------------------------
1350 : UShort_t AliTOFClusterFinder::GetClusterVolIndex(const Int_t * const ind) const {
1351 :
1352 : //First of all get the volume ID to retrieve the l2t transformation...
1353 : //
1354 : // Detector numbering scheme
1355 : Int_t nSector = 18;
1356 : Int_t nPlate = 5;
1357 : Int_t nStripA = 15;
1358 : Int_t nStripB = 19;
1359 : Int_t nStripC = 19;
1360 :
1361 1600 : Int_t isector =ind[0];
1362 800 : if (isector >= nSector)
1363 0 : AliError(Form("Wrong sector number in TOF (%d) !",isector));
1364 800 : Int_t iplate = ind[1];
1365 800 : if (iplate >= nPlate)
1366 0 : AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1367 800 : Int_t istrip = ind[2];
1368 :
1369 : Int_t stripOffset = 0;
1370 800 : switch (iplate) {
1371 : case 0:
1372 : stripOffset = 0;
1373 72 : break;
1374 : case 1:
1375 : stripOffset = nStripC;
1376 104 : break;
1377 : case 2:
1378 : stripOffset = nStripC+nStripB;
1379 552 : break;
1380 : case 3:
1381 : stripOffset = nStripC+nStripB+nStripA;
1382 72 : break;
1383 : case 4:
1384 : stripOffset = nStripC+nStripB+nStripA+nStripB;
1385 0 : break;
1386 : default:
1387 0 : AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1388 0 : break;
1389 : };
1390 :
1391 800 : Int_t index= (2*(nStripC+nStripB)+nStripA)*isector +
1392 800 : stripOffset +
1393 : istrip;
1394 :
1395 800 : UShort_t volIndex = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,index);
1396 800 : return volIndex;
1397 : }
1398 : //
1399 : //-------------------------------------------------------------------------
1400 : void AliTOFClusterFinder::GetClusterPars(Int_t *ind, Double_t* pos,Double_t* cov) const {
1401 :
1402 : //First of all get the volume ID to retrieve the l2t transformation...
1403 : //
1404 800 : UShort_t volIndex = GetClusterVolIndex(ind);
1405 : //
1406 : //
1407 : //we now go in the system of the strip: determine the local coordinates
1408 : //
1409 : //
1410 : // 47---------------------------------------------------0 ^ z
1411 : // | | | | | | | | | | | | | | | | | | | | | | | | | | | 1 |
1412 : // ----------------------------------------------------- | y going outwards
1413 : // | | | | | | | | | | | | | | | | | | | | | | | | | | | 0 | par[0]=0;
1414 :
1415 : // ----------------------------------------------------- |
1416 : // x <-----------------------------------------------------
1417 :
1418 : /*
1419 : Float_t localX = (ind[4]-23.5)*AliTOFGeometry::XPad();
1420 : Float_t localY = 0;
1421 : Float_t localZ = (ind[3]- 0.5)*AliTOFGeometry::ZPad();
1422 : */
1423 400 : Float_t localX = (ind[4]-AliTOFGeometry::NpadX()/2)*AliTOFGeometry::XPad()+AliTOFGeometry::XPad()/2.;
1424 : Float_t localY = 0;
1425 400 : Float_t localZ = (ind[3]-AliTOFGeometry::NpadZ()/2)*AliTOFGeometry::ZPad()+AliTOFGeometry::ZPad()/2.;
1426 : //move to the tracking ref system
1427 :
1428 400 : Double_t lpos[3];
1429 400 : lpos[0] = localX;
1430 400 : lpos[1] = localY;
1431 400 : lpos[2] = localZ;
1432 :
1433 400 : const TGeoHMatrix *l2t= AliGeomManager::GetTracking2LocalMatrix(volIndex);
1434 : // Get The position in the track ref system
1435 400 : Double_t tpos[3];
1436 400 : l2t->MasterToLocal(lpos,tpos);
1437 400 : pos[0] = tpos[0];
1438 400 : pos[1] = tpos[1];
1439 400 : pos[2] = tpos[2];
1440 :
1441 : //Get The cluster covariance in the track ref system
1442 400 : Double_t lcov[9];
1443 :
1444 : //cluster covariance in the local system:
1445 : // sx2 0 0
1446 : // 0 0 0
1447 : // 0 0 sz2
1448 :
1449 400 : lcov[0] = AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
1450 400 : lcov[1] = 0;
1451 400 : lcov[2] = 0;
1452 400 : lcov[3] = 0;
1453 400 : lcov[4] = 0;
1454 400 : lcov[5] = 0;
1455 400 : lcov[6] = 0;
1456 400 : lcov[7] = 0;
1457 400 : lcov[8] = AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
1458 :
1459 : //cluster covariance in the tracking system:
1460 400 : TGeoHMatrix m;
1461 400 : m.SetRotation(lcov);
1462 400 : m.Multiply(l2t);
1463 800 : m.MultiplyLeft(&l2t->Inverse());
1464 400 : Double_t *tcov = m.GetRotationMatrix();
1465 400 : cov[0] = tcov[0]; cov[1] = tcov[1]; cov[2] = tcov[2];
1466 400 : cov[3] = tcov[4]; cov[4] = tcov[5];
1467 400 : cov[5] = tcov[8];
1468 :
1469 : return;
1470 :
1471 400 : }
1472 : //-------------------------------------------------------------------------
1473 : void AliTOFClusterFinder::FillTOFtriggerMap(Int_t iDDL, AliTOFrawData *tofRawDatum)
1474 : {
1475 :
1476 : /* get cluster info */
1477 : //Int_t trm = tofRawDatum->GetTRM();
1478 : // Int_t tdc = tofRawDatum->GetTDC();
1479 : // Int_t tdc_ch = tofRawDatum->GetTDCchannel();
1480 0 : Int_t chain = tofRawDatum->GetTRMchain();
1481 0 : Int_t l0l1 = tofRawDatum->GetL0L1Latency();
1482 0 : Double_t corr = l0l1 * AliTOFGeometry::BunchCrossingBinWidth();
1483 0 : AliTOFCTPLatency *ctpLatencyObj = fTOFcalib->GetCTPLatency();
1484 0 : Float_t ctpLatency = ctpLatencyObj->GetCTPLatency();
1485 0 : corr += ctpLatency;
1486 :
1487 0 : Double_t timeTOF=tofRawDatum->GetTOF()*AliTOFGeometry::TdcBinWidth();
1488 : timeTOF-=corr;
1489 : //Int_t timeRaw_bc = Int_t(timeTOF/1000/24.4); // per ora non usata
1490 :
1491 : //Int_t timeRaw_bc = Int_t((tofRawDatum->GetTOF()*AliTOFGeometry::TdcBinWidth())/1000/24.4); // per ora non usata
1492 :
1493 : /*
1494 : const Int_t crate_CTTM[72] = { 0, 1, 37, 36, 2, 3, 39, 38, 4, 5,
1495 : 41, 40, 6, 7, 43, 42, 8, 9, 45, 44,
1496 : 10, 11, 47, 46, 12, 13, 49, 48, 14, 15,
1497 : 51, 50, 16, 17, 53, 52, 18, 19, 55, 54,
1498 : 20, 21, 57, 56, 22, 23, 59, 58, 24, 25,
1499 : 61, 60, 26, 27, 63, 62, 28, 29, 65, 64,
1500 : 30, 31, 67, 66, 32, 33, 69, 68, 34, 35,
1501 : 71, 70};
1502 : */
1503 :
1504 : Int_t cttmCrate=-1;
1505 : // Int_t cttmBit = tdc_ch + (tdc-12)*AliTOFGeometry::NCh();
1506 0 : switch(iDDL%AliTOFGeometry::NDDL()){
1507 : case 1:
1508 : cttmCrate=1;
1509 0 : break;
1510 : case 3:
1511 : cttmCrate=36;
1512 0 : break;
1513 : default:
1514 : break;
1515 : }
1516 0 : cttmCrate+=2*(Int_t)(iDDL/AliTOFGeometry::NDDL());
1517 0 : if(chain==0) {
1518 0 : if (iDDL<36) cttmCrate--;
1519 : else cttmCrate++;
1520 : }
1521 :
1522 :
1523 :
1524 :
1525 0 : }
1526 :
|