Added another recoParam to the TOF recoParam object, i.e. time window to discriminate...
[u/mrichter/AliRoot.git] / TOF / AliTOFClusterFinderV1.cxx
CommitLineData
e3bd5504 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: AliTOFClusterFinderV1.cxx,v $
e885fb81 18Revision 2009/04/20 A. De Caro
19 - added two new global variables, called fTOFGeometry and fTOFdigits;
20 - added a new method, called FindClustersWithoutTOT,
21 to transform TOF digits with fTOT=0 in one pad clusters;
22 - update of the covariance matrix elements for the TOF clusters
23
e3bd5504 24Revision 0.01 2008/05/10 A. De Caro
25 */
26
27/////////////////////////////////////////
28// //
29// Class for TOF cluster finder (V1) //
30// //
31// Input data: Raw Data or Digits; //
32// Output data: Digits or Rec Points //
33// //
34/////////////////////////////////////////
35
36#include "Riostream.h"
37
38#include "TClonesArray.h"
39#include "TStopwatch.h"
40#include "TTree.h"
41#include "TGeoMatrix.h"
42#include "TString.h"
43
44#include "AliDAQ.h"
45#include "AliLog.h"
46#include "AliRawReader.h"
47#include "AliRunLoader.h"
48#include "AliGeomManager.h"
49
50#include "AliTOFcalib.h"
51#include "AliTOFChannelOnlineArray.h"
52#include "AliTOFChannelOnlineStatusArray.h"
53#include "AliTOFChannelOffline.h"
54#include "AliTOFClusterFinderV1.h"
55#include "AliTOFcluster.h"
56#include "AliTOFdigit.h"
e3bd5504 57#include "AliTOFDigitMap.h"
e3bd5504 58#include "AliTOFrawData.h"
45a69ca6 59#include "AliTOFReconstructor.h"
60#include "AliTOFRecoParam.h"
e3bd5504 61
62ClassImp(AliTOFClusterFinderV1)
63
e885fb81 64//_____________________________________________________________________________
e3bd5504 65AliTOFClusterFinderV1::AliTOFClusterFinderV1(AliTOFcalib *calib):
66 fRunLoader(0),
67 fDigits(new TClonesArray("AliTOFdigit", 4000)),
68 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
69 fNumberOfTofClusters(0),
70 fNumberOfTofDigits(0),
45a69ca6 71 fMaxDeltaTime(0),
e3bd5504 72 fVerbose(0),
73 fDecoderVersion(0),
74 fTOFcalib(calib),
0275b7df 75 fTOFdigitMap(new AliTOFDigitMap()),
e885fb81 76 fTOFGeometry(new AliTOFGeometry()),
77 fTOFdigits(0),
0275b7df 78 fTOFRawStream(AliTOFRawStream())
e3bd5504 79{
80//
81// Constructor
82//
45a69ca6 83 const AliTOFRecoParam *recoParam = AliTOFReconstructor::GetRecoParam(); // instantiate reco param from STEER...
84 fMaxDeltaTime = recoParam->GetMaxDeltaTime();
e3bd5504 85}
e3bd5504 86
e885fb81 87//_____________________________________________________________________________
e3bd5504 88AliTOFClusterFinderV1::AliTOFClusterFinderV1(AliRunLoader* runLoader, AliTOFcalib *calib):
89 fRunLoader(runLoader),
90 fDigits(new TClonesArray("AliTOFdigit", 4000)),
91 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
92 fNumberOfTofClusters(0),
93 fNumberOfTofDigits(0),
45a69ca6 94 fMaxDeltaTime(0),
e3bd5504 95 fVerbose(0),
96 fDecoderVersion(0),
97 fTOFcalib(calib),
0275b7df 98 fTOFdigitMap(new AliTOFDigitMap()),
e885fb81 99 fTOFGeometry(new AliTOFGeometry()),
100 fTOFdigits(0),
0275b7df 101 fTOFRawStream(AliTOFRawStream())
e3bd5504 102{
103//
104// Constructor
105//
45a69ca6 106 const AliTOFRecoParam *recoParam = AliTOFReconstructor::GetRecoParam(); // instantiate reco param from STEER...
107 fMaxDeltaTime = recoParam->GetMaxDeltaTime();
e3bd5504 108
109}
110//_____________________________________________________________________________
111
112AliTOFClusterFinderV1::AliTOFClusterFinderV1(const AliTOFClusterFinderV1 &source)
8a190ba2 113 :TObject(source),
114 fRunLoader(0),
115 fDigits(source.fDigits),
116 fRecPoints(source.fRecPoints),
c0f9ecc7 117 fNumberOfTofClusters(0),
118 fNumberOfTofDigits(0),
e885fb81 119 fMaxDeltaTime(2),
c0f9ecc7 120 fVerbose(0),
121 fDecoderVersion(source.fDecoderVersion),
122 fTOFcalib(source.fTOFcalib),
0275b7df 123 fTOFdigitMap(new AliTOFDigitMap()),
e885fb81 124 fTOFGeometry(new AliTOFGeometry()),
125 fTOFdigits(source.fTOFdigits),
0275b7df 126 fTOFRawStream(source.fTOFRawStream)
e885fb81 127
e3bd5504 128{
129 // copy constructor
e3bd5504 130}
131//_____________________________________________________________________________
132
133AliTOFClusterFinderV1& AliTOFClusterFinderV1::operator=(const AliTOFClusterFinderV1 &source)
134{
135 // ass. op.
8a190ba2 136
137 if (this == &source)
138 return *this;
139
140 TObject::operator=(source);
141 fDigits=source.fDigits;
142 fRecPoints=source.fRecPoints;
143 fVerbose=source.fVerbose;
144 fDecoderVersion=source.fDecoderVersion;
145 fTOFcalib=source.fTOFcalib;
146 fTOFdigitMap=source.fTOFdigitMap;
e885fb81 147 fTOFGeometry=source.fTOFGeometry;
148 fTOFdigits=source.fTOFdigits;
0275b7df 149 fTOFRawStream=source.fTOFRawStream;
e3bd5504 150 return *this;
151
152}
153//_____________________________________________________________________________
154
155AliTOFClusterFinderV1::~AliTOFClusterFinderV1()
156{
157
158 //
159 // Destructor
160 //
161
162 if (fDigits)
163 {
164 fDigits->Delete();
165 delete fDigits;
166 fDigits=0;
167 }
168 if (fRecPoints)
169 {
170 fRecPoints->Delete();
171 delete fRecPoints;
172 fRecPoints=0;
173 }
174
175 delete fTOFdigitMap;
176
e885fb81 177 delete fTOFGeometry;
178
179 delete fTOFdigits;
180
e3bd5504 181}
182//_____________________________________________________________________________
183
184void AliTOFClusterFinderV1::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree)
185{
186 //
187 // Converts digits to recPoints for TOF
188 //
189
190 TStopwatch stopwatch;
191 stopwatch.Start();
192
193 Int_t inholes = 0;
194
195 TClonesArray &aDigits = *fDigits;
196
197 if (digitsTree == 0x0)
198 AliFatal("Can not get TreeD for TOF");
199
200 TBranch *branch = digitsTree->GetBranch("TOF");
201 if (!branch) {
202 AliError("Can not get branch with the TOF digits !");
203 return;
204 }
205
206 TClonesArray staticDigits("AliTOFdigit",10000);
207 staticDigits.Clear();
208 TClonesArray *digits = &staticDigits;
209 branch->SetAddress(&digits);
210 digitsTree->GetEvent(0);
211 AliInfo(Form("Number of TOF digits: %d", digits->GetEntriesFast()));
212
213 AliTOFdigit *tofDigit;
214
215 Int_t jj = 0;
216 Int_t detectorIndex[5];
217 for (jj=0; jj<5; jj++) detectorIndex[jj] = -1;
218 Int_t info[4];
219 for (jj=0; jj<4; jj++) info[jj] = -1;
220 Int_t *tracks;
221 Int_t tdcCorr;
222 Int_t dummy = -1;
223 Int_t last = -1;
224
225 Bool_t status = kTRUE;
226
227 AliInfo(" Calibrating TOF Digits: ");
228 TString validity = (TString)fTOFcalib->GetOfflineValidity();
229 AliInfo(Form(" validity = %s", validity.Data()));
230 if (validity.CompareTo("valid")==0) {
231 AliInfo(" ...using offline calibration parameters");
232 }
233 else {
234 AliInfo(" ...using online calibration parameters");
235 }
236
237 Int_t ii = 0;
238 for (ii=0; ii<digits->GetEntriesFast(); ii++) {
239 tofDigit = (AliTOFdigit*)digits->UncheckedAt(ii);
240 detectorIndex[0] = tofDigit->GetSector();
241 detectorIndex[1] = tofDigit->GetPlate();
242 detectorIndex[2] = tofDigit->GetStrip();
243 detectorIndex[3] = tofDigit->GetPadz();
244 detectorIndex[4] = tofDigit->GetPadx();
245
246 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
247 if (detectorIndex[1]==2) { // plate with holes
248 inholes++;
249 continue;
250 }
251 }
252
253 status = MakeSlewingCorrection(detectorIndex, tofDigit->GetToT(), tofDigit->GetTdc(), tdcCorr);
254
255 for (jj=0; jj<4; jj++) info[jj] = -1;
256 info[0] = tdcCorr;//tofDigit->GetTdc();
257 info[1] = tofDigit->GetAdc();
258 info[2] = tofDigit->GetToT();
90b234fe 259 info[3] = tofDigit->GetTdcND();//tofDigit->GetTdc();//
e3bd5504 260 tracks = tofDigit->GetTracks();
261
262 dummy = detectorIndex[3];
263 detectorIndex[3] = detectorIndex[4];//padx
264 detectorIndex[4] = dummy;//padz
265 last = fDigits->GetEntriesFast();
266 new (aDigits[last]) AliTOFdigit(tracks, detectorIndex, info);
267 if (status) fTOFdigitMap->AddDigit(detectorIndex, last);
268
e885fb81 269 AliDebug(2, Form(" Digits reading %2d -> %2d %1d %2d %1d %2d (%d, %d, %d)",
e3bd5504 270 last,
271 detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[3], detectorIndex[4],
272 info[0], info[1], info[3]));
273
274 }
275
276 fNumberOfTofDigits = fDigits->GetEntriesFast();
277
278 ResetRecpoint();
279
280 Int_t bufsize = 32000;
281 clusterTree->Branch("TOF", &fRecPoints, bufsize);
282
283 FillRecPoint();
284 clusterTree->Fill();
285
45a69ca6 286 AliInfo(Form("Number of found clusters: %d", fNumberOfTofClusters));
e3bd5504 287
288 ResetRecpoint();
289
290 fTOFdigitMap->Clear();
291
292 ResetDigits();
293
294 AliInfo(Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
295 stopwatch.RealTime(),stopwatch.CpuTime()));
296
297 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
298
299}
300//_____________________________________________________________________________
301
302void AliTOFClusterFinderV1::Digits2RecPoints(AliRawReader *rawReader, TTree *clustersTree)
303{
304 //
305 // Converts raw data to recPoints for TOF
306 //
307
308 TStopwatch stopwatch;
309 stopwatch.Start();
310
311
312 AliDebug(2, "TreeD re-creation");
e885fb81 313 //TTree *digitsTree = new TTree();
314 //Raw2Digits(rawReader, digitsTree);
e3bd5504 315
e885fb81 316 Raw2Digits(rawReader, fTOFdigits);
e3bd5504 317
318 AliDebug(2,Form("Number of TOF digits: %d", fNumberOfTofDigits));
319 ResetRecpoint();
320
321 Int_t bufsize = 32000;
322 clustersTree->Branch("TOF", &fRecPoints, bufsize);
323 FillRecPoint();
324
325 clustersTree->Fill();
326
e885fb81 327 AliInfo(Form("Number of found clusters: %d", fNumberOfTofClusters));
e3bd5504 328
329 ResetRecpoint();
330
331 fTOFdigitMap->Clear();
332
333 ResetDigits();
334
335 AliInfo(Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
336 stopwatch.RealTime(),stopwatch.CpuTime()));
337
338}
339
340//_____________________________________________________________________________
341
342void AliTOFClusterFinderV1::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
343{
344 //
345 // Converts raw data to digits for TOF
346 //
347
348 TStopwatch stopwatch;
349 stopwatch.Start();
350
351 Int_t inholes = 0;
352
353 const Int_t kMaxNumberOfTracksPerDigit = 3;
354 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
355
356 digitsTree->Branch("TOF", &fDigits);
357 TClonesArray &aDigits = *fDigits;
358
0275b7df 359 fTOFRawStream.Clear();
360 fTOFRawStream.SetRawReader(rawReader);
e3bd5504 361
362 ofstream ftxt;
363 if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
364
365 TClonesArray staticRawData("AliTOFrawData",10000);
366 staticRawData.Clear();
367 TClonesArray * clonesRawData = &staticRawData;
368
369 Int_t dummy = -1;
370 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
371 Int_t digit[4];
372 Int_t tracks[kMaxNumberOfTracksPerDigit];
373 for (Int_t ii=0; ii<kMaxNumberOfTracksPerDigit; ii++)
374 tracks[ii] = -1;
375 Int_t last = -1;
376 Int_t tdcCorr = 0;
377
378 Bool_t status = kTRUE;
379
380 AliInfo(" Calibrating TOF Digits: ");
381 TString validity = (TString)fTOFcalib->GetOfflineValidity();
382 AliInfo(Form(" validity = %s", validity.Data()));
383 if (validity.CompareTo("valid")==0) {
384 AliInfo(" ...using offline calibration parameters");
385 }
386 else {
387 AliInfo(" ...using online calibration parameters");
388 }
389
390 Int_t indexDDL = 0;
391 Int_t iRawData = 0;
392 for (indexDDL=0; indexDDL<kDDL; indexDDL++) {
393
394 rawReader->Reset();
395 if (fDecoderVersion) {
396 AliInfo("Using New Decoder \n");
0275b7df 397 fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
e3bd5504 398 }
0275b7df 399 else fTOFRawStream.LoadRawData(indexDDL);
e3bd5504 400
0275b7df 401 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
e885fb81 402 if (clonesRawData->GetEntriesFast()!=0) AliInfo(Form(" TOF raw data number = %3d", clonesRawData->GetEntriesFast()));
e3bd5504 403 for (iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
404
405 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
406
407 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
408 if (tofRawDatum->GetTOF()==-1) continue;
409
0275b7df 410 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
411 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
e3bd5504 412
413 tdcCorr = 0;
414 dummy = detectorIndex[3];
415 detectorIndex[3] = detectorIndex[4];//padz
416 detectorIndex[4] = dummy;//padx
417 status = MakeSlewingCorrection(detectorIndex, tofRawDatum->GetTOT(), tofRawDatum->GetTOF(), tdcCorr);
418
419 digit[0] = tdcCorr;
420 digit[1] = tofRawDatum->GetTOT();
421 digit[2] = tofRawDatum->GetTOT();
e885fb81 422 digit[3] = -1;//tofRawDatum->GetTOF(); //tofND
e3bd5504 423
424 dummy = detectorIndex[3];
425 detectorIndex[3] = detectorIndex[4];//padx
426 detectorIndex[4] = dummy;//padz
427
428 // Do not reconstruct anything in the holes
429 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
430 if (detectorIndex[1]==2) { // plate with holes
431 inholes++;
432 continue;
433 }
434 }
435
436 last = fDigits->GetEntriesFast();
437 new (aDigits[last]) AliTOFdigit(tracks, detectorIndex, digit);
438 if (status) fTOFdigitMap->AddDigit(detectorIndex, last);
439
440 if (fVerbose==2) {
441 if (indexDDL<10) ftxt << " " << indexDDL;
442 else ftxt << " " << indexDDL;
443 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
444 else ftxt << " " << tofRawDatum->GetTRM();
445 ftxt << " " << tofRawDatum->GetTRMchain();
446 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
447 else ftxt << " " << tofRawDatum->GetTDC();
448 ftxt << " " << tofRawDatum->GetTDCchannel();
449
450 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
451 else ftxt << " -> " << detectorIndex[0];
452 ftxt << " " << detectorIndex[1];
453 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
454 else ftxt << " " << detectorIndex[2];
455 ftxt << " " << detectorIndex[4];
456 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[3];
457 else ftxt << " " << detectorIndex[3];
458
459 if (digit[1]<10)ftxt << " " << digit[1];
460 else if (digit[1]>=10 && digit[1]<100) ftxt << " " << digit[1];
461 else ftxt << " " << digit[1];
462 if (digit[0]<10) ftxt << " " << digit[0] << endl;
463 else if (digit[0]>=10 && digit[0]<100) ftxt << " " << digit[0] << endl;
464 else if (digit[0]>=100 && digit[0]<1000) ftxt << " " << digit[0] << endl;
465 else ftxt << " " << digit[3] << endl;
466 }
467
e885fb81 468 AliDebug(2, Form(" Raw data reading %2d -> %2d %1d %2d %1d %2d (%d, %d, %d)",
e3bd5504 469 last,
470 detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[4], detectorIndex[3],
471 digit[0], digit[1], digit[3]));
472
473 } // while loop
474
475 clonesRawData->Clear();
476
477 } // DDL Loop
478
479 if (fVerbose==2) ftxt.close();
480
481 digitsTree->Fill();
482
483 fNumberOfTofDigits = fDigits->GetEntries();
484
485 AliDebug(1, Form("Got %d TOF digits", fNumberOfTofDigits));
486 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
487 stopwatch.RealTime(),stopwatch.CpuTime()));
488
489 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
490
491}
492//_____________________________________________________________________________
493
494void AliTOFClusterFinderV1::FillRecPoint()
495{
496 //
497 // Fill the global TClonesArray of AliTOFcluster objects,
498 // i.e. fRecPoints
499 //
500
e885fb81 501 Int_t dummy4_1 = -1;
502 Int_t dummy3_1 = -1;
503 Int_t dummy2_1 = -1;
e3bd5504 504 Int_t dummy = -1;
505
e885fb81 506 for(Int_t iPlate=AliTOFGeometry::NPlates()-1; iPlate>=0; iPlate--) {
507 for(Int_t iStrip=AliTOFGeometry::NStrip(iPlate)-1; iStrip>=0; iStrip--) {
508 //for (Int_t iSector=AliTOFGeometry::NSectors()-1; iSector>=0; iSector--) {
e3bd5504 509 for (Int_t iSector=0; iSector<AliTOFGeometry::NSectors(); iSector++) {
e885fb81 510
511 if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
512 FindClustersWithoutTOT(iSector, iPlate, iStrip); // clusters coming from digits without TOT measurement
513
514
e3bd5504 515 if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
516 FindClustersPerStrip(iSector, iPlate, iStrip, 4); // 4 pads clusters
e3bd5504 517 if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
e885fb81 518
519 dummy4_1 = fNumberOfTofClusters;
e3bd5504 520 FindClustersPerStrip(iSector, iPlate, iStrip, 4); // 4 pads clusters
521 if (fNumberOfTofClusters!=dummy4_1)
e885fb81 522 AliDebug(2, Form(" (4): n1= %5d, n2 = %5", dummy4_1, fNumberOfTofClusters));
523
524
e3bd5504 525 if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
526 FindClustersPerStrip(iSector, iPlate, iStrip, 3); // 3 pads clusters
e3bd5504 527 if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
e885fb81 528
529 dummy3_1 = fNumberOfTofClusters;
e3bd5504 530 FindClustersPerStrip(iSector, iPlate, iStrip, 3); // 3 pads clusters
531 if (fNumberOfTofClusters!=dummy3_1)
e885fb81 532 AliDebug(2, Form(" (3): n1= %5d, n2 = %5", dummy3_1, fNumberOfTofClusters));
533
534
e3bd5504 535 if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
536 FindClustersPerStrip(iSector, iPlate, iStrip, 2); // 2 pads clusters
e3bd5504 537 if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
e885fb81 538
539 dummy2_1 = fNumberOfTofClusters;
e3bd5504 540 FindClustersPerStrip(iSector, iPlate, iStrip, 2); // 2 pads clusters
541 if (fNumberOfTofClusters!=dummy2_1)
e885fb81 542 AliDebug(2, Form(" (2): n1= %5d, n2 =%5", dummy2_1, fNumberOfTofClusters));
543
544
e3bd5504 545 if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
546 dummy = fNumberOfTofClusters;
547 FindClusters34(iSector, iPlate, iStrip); // 3 pads clusters between 4 hit pads
548 if (fNumberOfTofClusters!=dummy)
e885fb81 549 AliDebug(2, Form(" (3 between 4): n1 = %5d, n2 = %5d", fNumberOfTofClusters, dummy));
550
551
e3bd5504 552 if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
553 dummy = fNumberOfTofClusters;
554 FindClusters23(iSector, iPlate, iStrip); // 2 pads clusters between 3 hit pads
555 if (fNumberOfTofClusters!=dummy)
e885fb81 556 AliDebug(2, Form(" (2 between 3): n1 = %5d, n2 = %5d", fNumberOfTofClusters, dummy));
e3bd5504 557
558 if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
559 dummy = fNumberOfTofClusters;
560 FindClusters24(iSector, iPlate, iStrip); // 2 pads clusters between 4 hit pads
561 if (fNumberOfTofClusters!=dummy)
e885fb81 562 AliDebug(2, Form(" (2 between 4): n1 = %5d, n2 = %5d", fNumberOfTofClusters, dummy));
e3bd5504 563
564
565 if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
566 dummy = fNumberOfTofClusters;
567 FindOnePadClusterPerStrip(iSector, iPlate, iStrip); // 1 pad clusters
568 if (fNumberOfTofClusters!=dummy)
e885fb81 569 AliDebug(2,Form(" (1): n1 = %5d, n2 = %5d", fNumberOfTofClusters, dummy));
e3bd5504 570
571 if (fTOFdigitMap->DigitInStrip(iSector,iPlate,iStrip)>0)
e885fb81 572 AliDebug(2, Form(" (1): number of clusters = %5d (remaining digit %2d), -%2d %1d %2d-",
573 fNumberOfTofClusters, fTOFdigitMap->DigitInStrip(iSector,iPlate,iStrip),
574 iSector, iPlate, iStrip));
e3bd5504 575
576 }
577 }
578 }
579
580
581 TClonesArray &lRecPoints = *fRecPoints;
582
583 Int_t ii, jj;
584
585 Int_t detectorIndex[5];
e885fb81 586 for (jj=0; jj<5; jj++) detectorIndex[jj] = -1;
e3bd5504 587 Int_t parTOF[5];
e885fb81 588 for (jj=0; jj<5; jj++) parTOF[jj] = -1;
e3bd5504 589 Int_t trackLabels[3];
e885fb81 590 for (jj=0; jj<3; jj++) trackLabels[jj] = -1;
e3bd5504 591 Int_t digitIndex = -1;
592 Bool_t status = kTRUE;
593 Float_t posClus[3];
594 for (ii=0; ii<3; ii++) posClus[ii] = 0.;
595 //Float_t covClus[6];
596 //for (ii=0; ii<6; ii++) covClus[ii] = 0.;
597 UShort_t volIdClus;
598
599 for (ii=0; ii<fNumberOfTofClusters; ii++) {
600
601 digitIndex = fTofClusters[ii]->GetIndex();
602 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
e885fb81 603 volIdClus = fTOFGeometry->GetAliSensVolIndex(detectorIndex[0],detectorIndex[1],detectorIndex[2]);
604 //volIdClus = GetClusterVolIndex(detectorIndex);
e3bd5504 605 for(jj=0; jj<3; jj++) trackLabels[jj] = fTofClusters[ii]->GetLabel(jj);
606 parTOF[0] = fTofClusters[ii]->GetTDC(); // TDC
607 parTOF[1] = fTofClusters[ii]->GetToT(); // TOT
608 parTOF[2] = fTofClusters[ii]->GetADC(); // ADC=TOT
609 parTOF[3] = fTofClusters[ii]->GetTDCND(); // TDCND
610 parTOF[4] = fTofClusters[ii]->GetTDCRAW();//RAW
611 status = fTofClusters[ii]->GetStatus();
612
613 posClus[0] = fTofClusters[ii]->GetX();
614 posClus[1] = fTofClusters[ii]->GetY();
615 posClus[2] = fTofClusters[ii]->GetZ();
616
617 //for (jj=0; jj<6; jj++) covClus[jj] = 0.;
618 //((AliCluster*)fTofClusters[ii])->GetGlobalCov(covClus);
619
620 new(lRecPoints[ii]) AliTOFcluster(volIdClus, (Double_t)posClus[0], (Double_t)posClus[1], (Double_t)posClus[2],
621 (Double_t)(fTofClusters[ii]->GetSigmaX2()),
622 (Double_t)(fTofClusters[ii]->GetSigmaXY()),
623 (Double_t)(fTofClusters[ii]->GetSigmaXZ()),
624 (Double_t)(fTofClusters[ii]->GetSigmaY2()),
625 (Double_t)(fTofClusters[ii]->GetSigmaYZ()),
626 (Double_t)(fTofClusters[ii]->GetSigmaZ2()),
627 //(Double_t)covClus[0], (Double_t)covClus[1], (Double_t)covClus[2],
628 //(Double_t)covClus[3], (Double_t)covClus[4], (Double_t)covClus[5],
629 trackLabels, detectorIndex, parTOF, status, digitIndex);
630
e885fb81 631 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",
e3bd5504 632 ii, volIdClus, posClus[0], posClus[1], posClus[2],
633 fTofClusters[ii]->GetSigmaX2(),
634 fTofClusters[ii]->GetSigmaXY(),
635 fTofClusters[ii]->GetSigmaXZ(),
636 fTofClusters[ii]->GetSigmaY2(),
637 fTofClusters[ii]->GetSigmaYZ(),
638 fTofClusters[ii]->GetSigmaZ2(),
639 trackLabels[0], trackLabels[1], trackLabels[2],
640 detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[3], detectorIndex[4],
641 parTOF[0], parTOF[1], parTOF[2], parTOF[3], parTOF[4],
642 status, digitIndex));
643
644
645 }
646
647 for (Int_t iSector=0; iSector<AliTOFGeometry::NSectors(); iSector++)
648 for(Int_t iPlate=0; iPlate<AliTOFGeometry::NPlates(); iPlate++) {
649 for(Int_t iStrip=0; iStrip<AliTOFGeometry::NStrip(iPlate); iStrip++) {
650 if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
e885fb81 651 AliDebug(2, Form(" END %2d %1d %2d %5d",
e3bd5504 652 iSector, iPlate, iStrip, fTOFdigitMap->DigitInStrip(iSector,iPlate,iStrip)));
653 }
654 }
655
656}
657//_____________________________________________________________________________
658
659void AliTOFClusterFinderV1::FindOnePadClusterPerStrip(Int_t nSector,
660 Int_t nPlate,
661 Int_t nStrip)
662{
663 //
664 // This function searches the isolated digits (stored in the fDigits object),
665 // to perform clusters (stored in the fTofClusters array).
666 // This research has been made by checking the fTOFdigitMap object,
667 // filled at digits/raw-data reading time.
668 //
669
670 const Int_t kMaxNumberOfTracksPerDigit = 3;
671 const Int_t kMaxNumberOfDigitsPerVolume = 3;
672
673 Int_t jj = 0;
674
e3bd5504 675 Int_t det[5] = {nSector,nPlate,nStrip,-1,-1};//sector,plate,strip,padZ,padX
676 Int_t vol[5] = {nSector,nPlate,nStrip,-1,-1};//sector,plate,strip,padX,padZ
677 UShort_t volIdClus = 0;
678
679 Float_t pos[3];
680 for (jj=0; jj<3; jj++) pos[jj] = 0.;
681 Double_t posClus[3];
682 for (jj=0; jj<3; jj++) posClus[jj] = 0.;
683
684 Double_t covClus[6];
685 for (jj=0; jj<6; jj++) covClus[jj] = 0.;
686
687 Int_t parTOF[5];
688 for (jj=0; jj<5; jj++) parTOF[jj] = 0;
689
690 Bool_t status = kTRUE; //assume all sim channels ok in the beginning...
691
692 Int_t tracks[kMaxNumberOfTracksPerDigit];
693 for (jj=0; jj<3; jj++) tracks[jj] = -1;
694
695 Int_t dummyCounter=-1;
e3bd5504 696
697 AliTOFdigit *digitInteresting;
698
699 Int_t iPadX = -1;
700 Int_t iPadZ = -1;
701 for (iPadX=0; iPadX<AliTOFGeometry::NpadX(); iPadX++) {
702 for (iPadZ=0; iPadZ<AliTOFGeometry::NpadZ(); iPadZ++) {
703 vol[4] = iPadZ , vol[3] = iPadX;
704
e885fb81 705 AliDebug(3, Form(" %1d %2d\n", iPadZ, iPadX));
e3bd5504 706
707 if (fTOFdigitMap->GetNumberOfDigits(vol)==0) continue;
708
709 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
710 if (fTOFdigitMap->GetDigitIndex(vol,digIndex)<0) continue;
711 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(fTOFdigitMap->GetDigitIndex(vol,digIndex));
712
e885fb81 713 AliDebug(2, Form(" %3d %5d %2d %1d %2d %1d %2d %d %d %d %5d %5d %5d %5d",
714 fTOFdigitMap->GetNumberOfDigits(vol), digIndex,
e3bd5504 715 vol[0], vol[1], vol[2] ,vol[4], vol[3],
716 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
717 digitInteresting->GetToT(),
718 fTOFdigitMap->GetDigitIndex(vol,digIndex),
719 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
720
e885fb81 721 det[3] = vol[4]; // padz
722 det[4] = vol[3]; // padx
723 fTOFGeometry->GetPosPar(det,pos);
e3bd5504 724 AliDebug(1,Form(" %f %f %f", pos[0], pos[1], pos[2]));
725
726 //insert cluster
727 for (jj=0; jj<3; jj++) posClus[jj] = pos[jj];
728
729 parTOF[0] = Int_t(digitInteresting->GetTdc());
e885fb81 730 parTOF[1] = Int_t(digitInteresting->GetToT());
731 parTOF[2] = Int_t(digitInteresting->GetAdc());
732 parTOF[3] = Int_t(digitInteresting->GetTdcND());
e3bd5504 733 parTOF[4] = Int_t(digitInteresting->GetTdc());
734
e885fb81 735 volIdClus = fTOFGeometry->GetAliSensVolIndex(det[0],det[1],det[2]);
736 //volIdClus = GetClusterVolIndex(det);
e3bd5504 737
738 for (jj=0; jj<6; jj++) covClus[jj] = 0.;
739 GetClusterPars(det, posClus, covClus);
740
741 // To fill the track index array
742 dummyCounter=-1;
743 for (jj=0; jj<kMaxNumberOfTracksPerDigit; jj++) tracks[jj] = -1;
744 for (jj=0; jj<kMaxNumberOfTracksPerDigit; jj++) { // three is the max number of tracks associated to one digit
745 if (digitInteresting->GetTrack(jj)==-1) continue;
746 else {
747 dummyCounter++;
748 tracks[dummyCounter] = digitInteresting->GetTrack(jj);
749 }
750 }
751
752 AliTOFcluster *tofCluster =
753 new AliTOFcluster(volIdClus, posClus[0], posClus[1], posClus[2],
754 covClus[0], covClus[1], covClus[2], covClus[3], covClus[4], covClus[5],
755 tracks, det, parTOF, status, fTOFdigitMap->GetDigitIndex(vol,digIndex));
756 InsertCluster(tofCluster);
757
e885fb81 758 AliDebug(2, Form(" %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",
e3bd5504 759 volIdClus, posClus[0], posClus[1], posClus[2],
760 covClus[0], covClus[1], covClus[2], covClus[3], covClus[4], covClus[5],
761 tracks[0], tracks[1], tracks[2],
762 det[0], det[1], det[2], det[3], det[4],
763 parTOF[0], parTOF[1], parTOF[2], parTOF[3], parTOF[4],
764 status, fTOFdigitMap->GetDigitIndex(vol,digIndex)));
765
766 AliDebug(2, Form(" %f %f %f", pos[0], pos[1], pos[2]));
e885fb81 767 AliDebug(2, Form(" %d %d", parTOF[0], parTOF[2]));
768
769 fTOFdigitMap->ResetDigit(vol, digIndex);
770
771 }
772
773 }
774 }
775
776}
777//_____________________________________________________________________________
778
779void AliTOFClusterFinderV1::FindClustersWithoutTOT(Int_t nSector,
780 Int_t nPlate,
781 Int_t nStrip)
782{
783 //
784 // This function searches the isolated digits without TOT
785 // measurement (stored in the fDigits object), to perform clusters
786 // (stored in the fTofClusters array). This research has been made
787 // by checking the fTOFdigitMap object, filled at digits/raw-data
788 // reading time.
789 //
790
791 const Int_t kMaxNumberOfTracksPerDigit = 3;
792 const Int_t kMaxNumberOfDigitsPerVolume = 3;
793
794 Int_t jj = 0;
795
796 Int_t det[5] = {nSector,nPlate,nStrip,-1,-1};//sector,plate,strip,padZ,padX
797 Int_t vol[5] = {nSector,nPlate,nStrip,-1,-1};//sector,plate,strip,padX,padZ
798 UShort_t volIdClus = 0;
799
800 Float_t pos[3];
801 for (jj=0; jj<3; jj++) pos[jj] = 0.;
802 Double_t posClus[3];
803 for (jj=0; jj<3; jj++) posClus[jj] = 0.;
804
805 Double_t covClus[6];
806 for (jj=0; jj<6; jj++) covClus[jj] = 0.;
807
808 Int_t parTOF[5];
809 for (jj=0; jj<5; jj++) parTOF[jj] = 0;
810
811 Bool_t status = kTRUE; //assume all sim channels ok in the beginning...
812 Int_t tracks[kMaxNumberOfTracksPerDigit];
813 for (jj=0; jj<3; jj++) tracks[jj] = -1;
814
815 Int_t dummyCounter=-1;
816
817 AliTOFdigit *digitInteresting;
818
819 Int_t iPadX = -1;
820 Int_t iPadZ = -1;
821 for (iPadX=0; iPadX<AliTOFGeometry::NpadX(); iPadX++) {
822 for (iPadZ=0; iPadZ<AliTOFGeometry::NpadZ(); iPadZ++) {
823 vol[4] = iPadZ , vol[3] = iPadX;
824
825 AliDebug(3, Form(" %1d %2d\n", iPadZ, iPadX));
826
827 if (fTOFdigitMap->GetNumberOfDigits(vol)==0) continue;
828
829 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
830 if (fTOFdigitMap->GetDigitIndex(vol,digIndex)<0) continue;
831 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(fTOFdigitMap->GetDigitIndex(vol,digIndex));
832 if (digitInteresting->GetToT()>0) continue; // AdC
833
834 AliDebug(2, Form(" %3d %5d %2d %1d %2d %1d %2d %d %d %d %5d %5d %5d %5d",
835 fTOFdigitMap->GetNumberOfDigits(vol), digIndex,
836 vol[0], vol[1], vol[2] ,vol[4], vol[3],
837 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
838 digitInteresting->GetToT(),
839 fTOFdigitMap->GetDigitIndex(vol,digIndex),
840 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
841
842 det[3] = vol[4]; // padz
843 det[4] = vol[3]; // padx
844 fTOFGeometry->GetPosPar(det,pos);
845 AliDebug(1,Form(" %f %f %f", pos[0], pos[1], pos[2]));
846
847 //insert cluster
848 for (jj=0; jj<3; jj++) posClus[jj] = pos[jj];
849
850 parTOF[0] = Int_t(digitInteresting->GetTdc());
851 parTOF[1] = Int_t(digitInteresting->GetToT());
852 parTOF[2] = Int_t(digitInteresting->GetAdc());
853 parTOF[3] = Int_t(digitInteresting->GetTdcND());
854 parTOF[4] = Int_t(digitInteresting->GetTdc());
855
856 volIdClus = fTOFGeometry->GetAliSensVolIndex(det[0],det[1],det[2]);
857 //volIdClus = GetClusterVolIndex(det);
858
859 for (jj=0; jj<6; jj++) covClus[jj] = 0.;
860 GetClusterPars(det, posClus, covClus);
861
862 // To fill the track index array
863 dummyCounter=-1;
864 for (jj=0; jj<kMaxNumberOfTracksPerDigit; jj++) tracks[jj] = -1;
865 for (jj=0; jj<kMaxNumberOfTracksPerDigit; jj++) { // three is the max number of tracks associated to one digit
866 if (digitInteresting->GetTrack(jj)==-1) continue;
867 else {
868 dummyCounter++;
869 tracks[dummyCounter] = digitInteresting->GetTrack(jj);
870 }
871 }
872
873 AliTOFcluster *tofCluster =
874 new AliTOFcluster(volIdClus, posClus[0], posClus[1], posClus[2],
875 covClus[0], covClus[1], covClus[2], covClus[3], covClus[4], covClus[5],
876 tracks, det, parTOF, status, fTOFdigitMap->GetDigitIndex(vol,digIndex));
877 InsertCluster(tofCluster);
878
879 AliDebug(2, Form(" %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",
880 volIdClus, posClus[0], posClus[1], posClus[2],
881 covClus[0], covClus[1], covClus[2], covClus[3], covClus[4], covClus[5],
882 tracks[0], tracks[1], tracks[2],
883 det[0], det[1], det[2], det[3], det[4],
884 parTOF[0], parTOF[1], parTOF[2], parTOF[3], parTOF[4],
885 status, fTOFdigitMap->GetDigitIndex(vol,digIndex)));
886
887 AliDebug(2, Form(" %f %f %f", pos[0], pos[1], pos[2]));
888 AliDebug(2, Form(" %d %d", parTOF[0], parTOF[2]));
e3bd5504 889
e3bd5504 890 fTOFdigitMap->ResetDigit(vol, digIndex);
891
892 }
893
894 }
895 }
896
897}
898//_____________________________________________________________________________
899
900void AliTOFClusterFinderV1::FindClusters34(Int_t nSector,
901 Int_t nPlate,
902 Int_t nStrip)
903{
904 //
905 // This function searches the neighbouring digits (stored in the fDigits object),
906 // to perform clusters (stored in the fTofClusters array).
907 //
908 // This research has been made by checking the fTOFdigitMap object,
909 // filled at digits/raw-data reading time.
910 //
911
912 const Int_t kMaxNumberOfInterestingPads = 4;
913 const Int_t kMaxNumberOfTracksPerDigit = 3;
914 const Int_t kMaxNumberOfDigitsPerVolume = 3;
915
916 Int_t ii = 0;
917
918 Int_t digitsInVolumeIndices[kMaxNumberOfDigitsPerVolume];
919 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
920 digitsInVolumeIndices[ii] = -1;
921
e3bd5504 922 Int_t vol[5] = {nSector,nPlate,nStrip,-1,-1};
923
924 Float_t pos[3] = {0.,0.,0.};
925
926 Int_t jj = 0;
927 Int_t interestingPadX[kMaxNumberOfInterestingPads];
928 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingPadX[jj] = -1;
929 Int_t interestingPadZ[kMaxNumberOfInterestingPads];
930 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingPadZ[jj] = -1;
931 Double_t interestingTOT[kMaxNumberOfInterestingPads];
932 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingTOT[jj] = 0;
933 Double_t interestingADC[kMaxNumberOfInterestingPads];
934 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingADC[jj] = 0;
935 Double_t interestingTOF[kMaxNumberOfInterestingPads];
936 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingTOF[jj] = 0;
937 Double_t interestingWeight[kMaxNumberOfInterestingPads];
938 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingWeight[jj] = 0;
939
940 Float_t interestingX[kMaxNumberOfInterestingPads];
941 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingX[jj] = 0;
942 Float_t interestingY[kMaxNumberOfInterestingPads];
943 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingY[jj] = 0;
944 Float_t interestingZ[kMaxNumberOfInterestingPads];
945 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingZ[jj] = 0;
946
947 Float_t interDigit[kMaxNumberOfInterestingPads];
948 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interDigit[jj] = 0;
949
950 Int_t padsCluster[11];
951 padsCluster[0] = nSector;
952 padsCluster[1] = nPlate;
953 padsCluster[2] = nStrip;
954 for (jj=3; jj<11; jj++) padsCluster[jj] = -1;
955
956 Int_t interestingCounter=-1;
e885fb81 957 Int_t digitIndexLocal=-1; // AdC
e3bd5504 958 Int_t iPad = -1;
959 Int_t iPadX = -1;
960 Int_t iPadZ = -1;
961
962 Int_t parTOF[5];
963 for (jj=0; jj<5; jj++) parTOF[jj] = 0;
964 Double_t posClus[3];
965 for (jj=0; jj<3; jj++) posClus[jj] = 0.;
966 Int_t det[5];
967 for (jj=0; jj<5; jj++) det[jj] = -1;
968 Float_t posF[3];
969 for (jj=0; jj<3; jj++) posF[jj] = 0.;
970 UShort_t volIdClus = 0;
971 Bool_t check = kFALSE;
972 Bool_t status = kTRUE; //assume all sim channels ok in the beginning...
973 Double_t covClus[6];
974 for (jj=0; jj<6; jj++) covClus[jj] = 0.;
975 Int_t tracks[kMaxNumberOfTracksPerDigit];
976 for (jj=0; jj<3; jj++) tracks[jj] = -1;
977 Int_t dummyCounter=-1;
978 Bool_t alreadyStored = kFALSE;
979
980 AliTOFselectedDigit ***selectedDigit = new AliTOFselectedDigit**[kMaxNumberOfInterestingPads];
981 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
982 selectedDigit[ii] = new AliTOFselectedDigit*[kMaxNumberOfDigitsPerVolume];
983
984 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
985 for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++) selectedDigit[ii][jj] = 0x0;
986
987 AliTOFdigit *digitInteresting;
988
989 for (iPad=0; iPad<AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX()-3; iPad+=2) {
990
991 iPadZ = iPad%AliTOFGeometry::NpadZ(); //iPad%2;
992 iPadX = iPad/AliTOFGeometry::NpadZ(); //iPad/2;
993
e885fb81 994 AliDebug(3, Form("%2d %1d %2d\n", iPad, iPadZ, iPadX));
e3bd5504 995
996
997
998
999
1000
1001 interestingCounter=-1;
1002
1003 vol[4] = iPadZ , vol[3] = iPadX;
1004 if (fTOFdigitMap->GetNumberOfDigits(vol)>0)
1005 interestingCounter++;
1006
1007 vol[4] = iPadZ, vol[3] = iPadX+1;
1008 if (fTOFdigitMap->GetNumberOfDigits(vol)>0)
1009 interestingCounter++;
1010
1011 vol[4] = AliTOFGeometry::NpadZ()-(iPadZ+1), vol[3] = iPadX;
1012 if (fTOFdigitMap->GetNumberOfDigits(vol)>0)
1013 interestingCounter++;
1014
1015 vol[4] = AliTOFGeometry::NpadZ()-(iPadZ+1), vol[3] = iPadX+1;
1016 if (fTOFdigitMap->GetNumberOfDigits(vol)>0)
1017 interestingCounter++;
1018
1019 if (interestingCounter+1!=4) continue; // the hit pads have to be 4
1020 else interestingCounter=-1;
1021
1022
1023 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
1024 for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++)
1025 selectedDigit[ii][jj] = 0x0;
1026
1027
1028 vol[4] = iPadZ, vol[3] = iPadX;
1029
1030 if (fTOFdigitMap->GetNumberOfDigits(vol)>0) {
1031 interestingCounter++;
1032 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
1033 digitsInVolumeIndices[ii] = -1;
1034 fTOFdigitMap->GetDigitIndex(vol, digitsInVolumeIndices);
e885fb81 1035 digitIndexLocal=-1; // AdC
e3bd5504 1036 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
1037 if (digitsInVolumeIndices[digIndex]<0) continue;
1038 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(digitsInVolumeIndices[digIndex]);
e885fb81 1039 if (digitInteresting->GetToT()<=0) continue; // AdC
1040 digitIndexLocal++; // AdC
e3bd5504 1041
e885fb81 1042 AliDebug(1,Form(" %2d %1d %2d %1d %2d %f %f %f %f %5d %5d %5d %5d",
e3bd5504 1043 vol[0], vol[1], vol[2] ,vol[4], vol[3],
1044 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
1045 digitInteresting->GetToT(), digitInteresting->GetToT()*digitInteresting->GetToT(),
1046 digitsInVolumeIndices[digIndex],
1047 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
1048
1049
e885fb81 1050 selectedDigit[interestingCounter][digitIndexLocal] = new // AdC
e3bd5504 1051 AliTOFselectedDigit(vol, digitInteresting->GetTdc(),
1052 digitInteresting->GetAdc(), digitInteresting->GetToT(),
1053 digitInteresting->GetToT()*digitInteresting->GetToT(),
1054 digitsInVolumeIndices[digIndex],
1055 digitInteresting->GetTracks());
1056 }
e885fb81 1057 if (digitIndexLocal==-1) interestingCounter--; // AdC
e3bd5504 1058 }
1059
1060
1061 vol[4] = iPadZ, vol[3] = iPadX+1;
1062
1063 if (fTOFdigitMap->GetNumberOfDigits(vol)>0) {
1064 interestingCounter++;
1065 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
1066 digitsInVolumeIndices[ii] = -1;
1067 fTOFdigitMap->GetDigitIndex(vol, digitsInVolumeIndices);
e885fb81 1068 digitIndexLocal=-1; // AdC
e3bd5504 1069 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
1070 if (digitsInVolumeIndices[digIndex]<0) continue;
1071 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(digitsInVolumeIndices[digIndex]);
e885fb81 1072 if (digitInteresting->GetToT()<=0) continue; // AdC
1073 digitIndexLocal++; // AdC
e3bd5504 1074
e885fb81 1075 AliDebug(1,Form(" %2d %1d %2d %1d %2d %f %f %f %f %5d %5d %5d %5d",
e3bd5504 1076 vol[0], vol[1], vol[2] ,vol[4], vol[3],
1077 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
1078 digitInteresting->GetToT(), digitInteresting->GetToT()*digitInteresting->GetToT(),
1079 digitsInVolumeIndices[digIndex],
1080 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
1081
1082
e885fb81 1083 selectedDigit[interestingCounter][digitIndexLocal] = new // AdC
e3bd5504 1084 AliTOFselectedDigit(vol, digitInteresting->GetTdc(),
1085 digitInteresting->GetAdc(), digitInteresting->GetToT(),
1086 digitInteresting->GetToT()*digitInteresting->GetToT(),
1087 digitsInVolumeIndices[digIndex],
1088 digitInteresting->GetTracks());
1089 }
e885fb81 1090 if (digitIndexLocal==-1) interestingCounter--; // AdC
e3bd5504 1091 }
1092
1093
1094 vol[4] = AliTOFGeometry::NpadZ()-(iPadZ+1), vol[3] = iPadX;
1095
1096 if (fTOFdigitMap->GetNumberOfDigits(vol)>0) {
1097 interestingCounter++;
1098 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
1099 digitsInVolumeIndices[ii] = -1;
1100 fTOFdigitMap->GetDigitIndex(vol, digitsInVolumeIndices);
e885fb81 1101 digitIndexLocal=-1; // AdC
e3bd5504 1102 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
1103 if (digitsInVolumeIndices[digIndex]<0) continue;
1104 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(digitsInVolumeIndices[digIndex]);
e885fb81 1105 if (digitInteresting->GetToT()<=0) continue; // AdC
1106 digitIndexLocal++; // AdC
e3bd5504 1107
e885fb81 1108 AliDebug(1,Form(" %2d %1d %2d %1d %2d %f %f %f %f %5d %5d %5d %5d",
e3bd5504 1109 vol[0], vol[1], vol[2] ,vol[4], vol[3],
1110 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
1111 digitInteresting->GetToT(), digitInteresting->GetToT()*digitInteresting->GetToT(),
1112 digitsInVolumeIndices[digIndex],
1113 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
1114
1115
e885fb81 1116 selectedDigit[interestingCounter][digitIndexLocal] = new // AdC
e3bd5504 1117 AliTOFselectedDigit(vol, digitInteresting->GetTdc(),
1118 digitInteresting->GetAdc(), digitInteresting->GetToT(),
1119 digitInteresting->GetToT()*digitInteresting->GetToT(),
1120 digitsInVolumeIndices[digIndex],
1121 digitInteresting->GetTracks());
1122 }
e885fb81 1123 if (digitIndexLocal==-1) interestingCounter--; // AdC
e3bd5504 1124 }
1125
1126
1127 vol[4] = AliTOFGeometry::NpadZ()-(iPadZ+1), vol[3] = iPadX+1;
1128
1129 if (fTOFdigitMap->GetNumberOfDigits(vol)>0) {
1130 interestingCounter++;
1131 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
1132 digitsInVolumeIndices[ii] = -1;
1133 fTOFdigitMap->GetDigitIndex(vol, digitsInVolumeIndices);
e885fb81 1134 digitIndexLocal=-1;
e3bd5504 1135 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
1136 if (digitsInVolumeIndices[digIndex]<0) continue;
1137 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(digitsInVolumeIndices[digIndex]);
e885fb81 1138 if (digitInteresting->GetToT()<=0) continue; // AdC
1139 digitIndexLocal++; // AdC
e3bd5504 1140
e885fb81 1141 AliDebug(1,Form(" %2d %1d %2d %1d %2d %f %f %f %f %5d %5d %5d %5d",
e3bd5504 1142 vol[0], vol[1], vol[2] ,vol[4], vol[3],
1143 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
1144 digitInteresting->GetToT(), digitInteresting->GetToT()*digitInteresting->GetToT(),
1145 digitsInVolumeIndices[digIndex],
1146 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
1147
e885fb81 1148 selectedDigit[interestingCounter][digitIndexLocal] = new // AdC
e3bd5504 1149 AliTOFselectedDigit(vol, digitInteresting->GetTdc(),
1150 digitInteresting->GetAdc(), digitInteresting->GetToT(),
1151 digitInteresting->GetToT()*digitInteresting->GetToT(),
1152 digitsInVolumeIndices[digIndex],
1153 digitInteresting->GetTracks());
1154 }
e885fb81 1155 if (digitIndexLocal==-1) interestingCounter--; // AdC
e3bd5504 1156 }
1157
e885fb81 1158 AliDebug(1,Form(" e adesso %1d", interestingCounter+1));
e3bd5504 1159
1160 for (Int_t adesso1=0; adesso1<interestingCounter+1; adesso1++) {
1161 for (Int_t firstIndex=0; firstIndex<kMaxNumberOfDigitsPerVolume; firstIndex++) {
1162 if (selectedDigit[adesso1][firstIndex]==0x0) continue;
1163
1164 for (Int_t adesso2=adesso1+1; adesso2<interestingCounter+1; adesso2++) {
1165 for (Int_t secondIndex=0; secondIndex<kMaxNumberOfDigitsPerVolume; secondIndex++) {
1166 if (selectedDigit[adesso2][secondIndex]==0x0) continue;
1167
1168 for (Int_t adesso3=adesso2+1; adesso3<interestingCounter+1; adesso3++) {
1169 for (Int_t thirdIndex=0; thirdIndex<kMaxNumberOfDigitsPerVolume; thirdIndex++) {
1170 if (selectedDigit[adesso3][thirdIndex]==0x0) continue;
1171
1172
1173 if (TMath::Abs(selectedDigit[adesso1][firstIndex]->GetTDC()-selectedDigit[adesso2][secondIndex]->GetTDC())>fMaxDeltaTime
1174 ||
1175 TMath::Abs(selectedDigit[adesso1][firstIndex]->GetTDC()-selectedDigit[adesso3][thirdIndex]->GetTDC())>fMaxDeltaTime
1176 ||
1177 TMath::Abs(selectedDigit[adesso2][secondIndex]->GetTDC()-selectedDigit[adesso3][thirdIndex]->GetTDC())>fMaxDeltaTime) continue;
1178
1179 interestingTOF[0] = selectedDigit[adesso1][firstIndex]->GetTDC();
1180 interestingTOT[0] = selectedDigit[adesso1][firstIndex]->GetTOT();
1181 interestingADC[0] = selectedDigit[adesso1][firstIndex]->GetADC();
1182 interestingWeight[0] = selectedDigit[adesso1][firstIndex]->GetWeight();
1183 Int_t vol1[5]; for(jj=0; jj<5; jj++) vol1[jj] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(jj);
e885fb81 1184 AliDebug(1,Form(" %2d %1d %2d %1d %2d", vol1[0], vol1[1], vol1[2], vol1[4], vol1[3]));
e3bd5504 1185 Int_t volDum = vol1[3];
1186 vol1[3] = vol1[4];
1187 vol1[4] = volDum;
e885fb81 1188 fTOFGeometry->GetPosPar(vol1,pos);
e3bd5504 1189 interestingX[0] = pos[0];
1190 interestingY[0] = pos[1];
1191 interestingZ[0] = pos[2];
1192
1193 interestingTOF[1] = selectedDigit[adesso2][secondIndex]->GetTDC();
1194 interestingTOT[1] = selectedDigit[adesso2][secondIndex]->GetTOT();
1195 interestingADC[1] = selectedDigit[adesso2][secondIndex]->GetADC();
1196 interestingWeight[1] = selectedDigit[adesso2][secondIndex]->GetWeight();
1197 Int_t vol2[5]; for(jj=0; jj<5; jj++) vol2[jj] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(jj);
e885fb81 1198 AliDebug(1,Form(" %2d %1d %2d %1d %2d", vol2[0], vol2[1], vol2[2], vol2[4], vol2[3]));
e3bd5504 1199 volDum = vol2[3];
1200 vol2[3] = vol2[4];
1201 vol2[4] = volDum;
e885fb81 1202 fTOFGeometry->GetPosPar(vol2,pos);
e3bd5504 1203 interestingX[1] = pos[0];
1204 interestingY[1] = pos[1];
1205 interestingZ[1] = pos[2];
1206
1207 interestingTOF[2] = selectedDigit[adesso3][thirdIndex]->GetTDC();
1208 interestingTOT[2] = selectedDigit[adesso3][thirdIndex]->GetTOT();
1209 interestingADC[2] = selectedDigit[adesso3][thirdIndex]->GetADC();
1210 interestingWeight[2] = selectedDigit[adesso3][thirdIndex]->GetWeight();
1211 Int_t vol3[5]; for(jj=0; jj<5; jj++) vol3[jj] = selectedDigit[adesso3][thirdIndex]->GetDetectorIndex(jj);
e885fb81 1212 AliDebug(1,Form(" %2d %1d %2d %1d %2d", vol3[0], vol3[1], vol3[2], vol3[4], vol3[3]));
e3bd5504 1213 volDum = vol3[3];
1214 vol3[3] = vol3[4];
1215 vol3[4] = volDum;
e885fb81 1216 fTOFGeometry->GetPosPar(vol3,pos);
e3bd5504 1217 interestingX[2] = pos[0];
1218 interestingY[2] = pos[1];
1219 interestingZ[2] = pos[2];
1220
1221
1222 AverageCalculations(3, interestingX, interestingY, interestingZ,
1223 interestingTOF, interestingTOT, interestingADC,
1224 interestingWeight,
1225 parTOF, posClus, check);
1226
1227
1228 for (jj=0; jj<5; jj++) det[jj] = -1;
1229 for (jj=0; jj<3; jj++) posF[jj] = posClus[jj];
e885fb81 1230 fTOFGeometry->GetDetID(posF, det);
e3bd5504 1231
e885fb81 1232 volIdClus = fTOFGeometry->GetAliSensVolIndex(det[0],det[1],det[2]);
1233 //volIdClus = GetClusterVolIndex(det);
e3bd5504 1234
1235 for (jj=3; jj<11; jj++) padsCluster[jj] = -1;
1236 padsCluster[3] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(4);
1237 padsCluster[4] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(3);
1238 padsCluster[5] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(4);
1239 padsCluster[6] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(3);
1240 padsCluster[7] = selectedDigit[adesso3][thirdIndex]->GetDetectorIndex(4);
1241 padsCluster[8] = selectedDigit[adesso3][thirdIndex]->GetDetectorIndex(3);
1242
1243 for (jj=0; jj<6; jj++) covClus[jj] = 0.;
1244 Int_t ** indDet = new Int_t*[3];
1245 for (jj=0; jj<3; jj++) indDet[jj] = new Int_t [5];
1246 for (jj=0; jj<3; jj++) indDet[jj][0] = nSector;
1247 for (jj=0; jj<3; jj++) indDet[jj][1] = nPlate;
1248 for (jj=0; jj<3; jj++) indDet[jj][2] = nStrip;
1249 for (jj=0; jj<3; jj++) indDet[jj][3] = padsCluster[2*jj+3];
1250 for (jj=0; jj<3; jj++) indDet[jj][4] = padsCluster[2*jj+1+3];
e885fb81 1251 GetClusterPars(/*check,*/ 3, indDet, interestingWeight, posClus, covClus);
e3bd5504 1252 for (jj=0; jj<3; jj++) delete [] indDet[jj];
1253
1254 // To fill the track index array
1255 dummyCounter=-1;
1256 for (jj=0; jj<kMaxNumberOfTracksPerDigit; jj++) tracks[jj] = -1;
1257 for (Int_t kk=0; kk<kMaxNumberOfTracksPerDigit; kk++) { // three is the max number of tracks associated to one digit
1258 if (selectedDigit[adesso1][firstIndex]->GetTrackLabel(kk)==-1) continue;
1259 else {
1260 dummyCounter++;
1261 tracks[dummyCounter] = selectedDigit[adesso1][firstIndex]->GetTrackLabel(kk);
1262 }
1263 }
1264 for (Int_t kk=0; kk<kMaxNumberOfTracksPerDigit; kk++) { // three is the max number of tracks associated to one digit
1265 if (selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk)==-1) continue;
1266 else {
1267
1268 alreadyStored = kFALSE;
1269 for (jj=0; jj<dummyCounter+1; jj++)
1270 alreadyStored = alreadyStored || (tracks[jj]!=-1 && tracks[jj]==selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk));
1271
1272 if (alreadyStored) continue;
1273 if (dummyCounter==2) { // three is the max number of tracks associated to one cluster
1274 AliWarning(" Siamo al limite!");
1275 continue;
1276 }
1277
1278 dummyCounter++;
1279 tracks[dummyCounter] = selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk);
1280
1281 }
1282
1283 }
1284 for (Int_t kk=0; kk<kMaxNumberOfTracksPerDigit; kk++) { // three is the max number of tracks associated to one digit
1285 if (selectedDigit[adesso3][thirdIndex]->GetTrackLabel(kk)==-1) continue;
1286 else {
1287
1288 alreadyStored = kFALSE;
1289 for (jj=0; jj<dummyCounter+1; jj++)
1290 alreadyStored = alreadyStored || (tracks[jj]!=-1 && tracks[jj]==selectedDigit[adesso3][thirdIndex]->GetTrackLabel(kk));
1291
1292 if (alreadyStored) continue;
1293 if (dummyCounter==2) { // three is the max number of tracks associated to one cluster
1294 AliWarning(" Siamo al limite!");
1295 continue;
1296 }
1297
1298 dummyCounter++;
1299 tracks[dummyCounter] = selectedDigit[adesso3][thirdIndex]->GetTrackLabel(kk);
1300
1301 }
1302
1303 }
1304
1305
1306 AliTOFcluster *tofCluster =
1307 new AliTOFcluster(volIdClus, posClus[0], posClus[1], posClus[2],
1308 covClus[0], covClus[1], covClus[2], covClus[3], covClus[4], covClus[5],
1309 tracks, det, parTOF, status, selectedDigit[adesso1][firstIndex]->GetIndex()); // to be updated
1310 InsertCluster(tofCluster);
1311
e885fb81 1312 AliDebug(2, Form(" %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",
e3bd5504 1313 volIdClus, posClus[0], posClus[1], posClus[2],
1314 covClus[0], covClus[1], covClus[2], covClus[3], covClus[4], covClus[5],
1315 tracks[0], tracks[1], tracks[2],
1316 det[0], det[1], det[2], det[3], det[4],
1317 parTOF[0], parTOF[1], parTOF[2], parTOF[3], parTOF[4],
1318 status, selectedDigit[adesso1][firstIndex]->GetIndex()));
1319
1320
1321 volDum = vol1[3];
1322 vol1[3] = vol1[4];
1323 vol1[4] = volDum;
1324 fTOFdigitMap->ResetDigitNumber(vol1,selectedDigit[adesso1][firstIndex]->GetIndex());
1325 volDum = vol2[3];
1326 vol2[3] = vol2[4];
1327 vol2[4] = volDum;
1328 fTOFdigitMap->ResetDigitNumber(vol2,selectedDigit[adesso2][secondIndex]->GetIndex());
1329 volDum = vol3[3];
1330 vol3[3] = vol3[4];
1331 vol3[4] = volDum;
1332 fTOFdigitMap->ResetDigitNumber(vol3,selectedDigit[adesso3][thirdIndex]->GetIndex());
1333
1334
1335 } // close loop on third digit
1336 } // close loop on adesso3
1337
1338 } // close loop on second digit
1339 } // close loop on adesso2
1340
1341 } // close loop on first digit
1342 } // close loop on adesso1
1343
1344 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
1345 for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++)
1346 selectedDigit[ii][jj] = 0x0;
1347
1348 } // loop on iPad
1349
1350 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
1351 for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++) {
1352 delete selectedDigit[ii][jj];
1353 selectedDigit[ii][jj] = 0x0;
1354 }
1355
1356
1357}
1358//_____________________________________________________________________________
1359
1360void AliTOFClusterFinderV1::FindClusters23(Int_t nSector,
1361 Int_t nPlate,
1362 Int_t nStrip)
1363{
1364 //
1365 // This function searches the neighbouring digits (stored in the fDigits object),
1366 // to perform clusters (stored in the fTofClusters array).
1367 //
1368 // This research has been made by checking the fTOFdigitMap object,
1369 // filled at digits/raw-data reading time.
1370 //
1371
1372 const Int_t kMaxNumberOfInterestingPads = 4;
1373 const Int_t kMaxNumberOfTracksPerDigit = 3;
1374 const Int_t kMaxNumberOfDigitsPerVolume = 3;
1375
1376 Int_t ii = 0;
1377
1378 Int_t digitsInVolumeIndices[kMaxNumberOfDigitsPerVolume];
1379 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
1380 digitsInVolumeIndices[ii] = -1;
1381
e3bd5504 1382 Int_t vol[5] = {nSector,nPlate,nStrip,-1,-1};
1383
1384 Float_t pos[3] = {0.,0.,0.};
1385
1386 Int_t jj = 0;
1387 Int_t interestingPadX[kMaxNumberOfInterestingPads];
1388 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingPadX[jj] = -1;
1389 Int_t interestingPadZ[kMaxNumberOfInterestingPads];
1390 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingPadZ[jj] = -1;
1391 Double_t interestingTOT[kMaxNumberOfInterestingPads];
1392 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingTOT[jj] = 0;
1393 Double_t interestingADC[kMaxNumberOfInterestingPads];
1394 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingADC[jj] = 0;
1395 Double_t interestingTOF[kMaxNumberOfInterestingPads];
1396 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingTOF[jj] = 0;
1397 Double_t interestingWeight[kMaxNumberOfInterestingPads];
1398 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingWeight[jj] = 0;
1399
1400 Float_t interestingX[kMaxNumberOfInterestingPads];
1401 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingX[jj] = 0;
1402 Float_t interestingY[kMaxNumberOfInterestingPads];
1403 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingY[jj] = 0;
1404 Float_t interestingZ[kMaxNumberOfInterestingPads];
1405 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingZ[jj] = 0;
1406
1407 Float_t interDigit[kMaxNumberOfInterestingPads];
1408 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interDigit[jj] = 0;
1409
1410 Int_t padsCluster[11];
1411 padsCluster[0] = nSector;
1412 padsCluster[1] = nPlate;
1413 padsCluster[2] = nStrip;
1414 for (jj=3; jj<11; jj++) padsCluster[jj] = -1;
1415
1416 Int_t interestingCounter=-1;
e885fb81 1417 Int_t digitIndexLocal = -1;
e3bd5504 1418 Int_t iPad = -1;
1419 Int_t iPadX = -1;
1420 Int_t iPadZ = -1;
1421
1422 Bool_t check = kFALSE;
1423 Int_t parTOF[5];
1424 for (jj=0; jj<5; jj++) parTOF[jj] = 0;
1425 Double_t posClus[3];
1426 for (jj=0; jj<3; jj++) posClus[jj] = 0.;
1427 Int_t det[5];
1428 for (jj=0; jj<5; jj++) det[jj] = -1;
1429 Float_t posF[3];
1430 for (jj=0; jj<3; jj++) posF[jj] = 0.;
1431 UShort_t volIdClus = 0;
1432 Bool_t status = kTRUE; //assume all sim channels ok in the beginning...
1433 Double_t covClus[6];
1434 for (jj=0; jj<6; jj++) covClus[jj] = 0.;
1435 Int_t tracks[kMaxNumberOfTracksPerDigit];
1436 for (jj=0; jj<3; jj++) tracks[jj] = -1;
1437 Int_t dummyCounter=-1;
1438 Bool_t alreadyStored = kFALSE;
1439
1440 AliTOFselectedDigit ***selectedDigit = new AliTOFselectedDigit**[kMaxNumberOfInterestingPads];
1441 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
1442 selectedDigit[ii] = new AliTOFselectedDigit*[kMaxNumberOfDigitsPerVolume];
1443
1444 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
1445 for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++) selectedDigit[ii][jj] = 0x0;
1446
1447 AliTOFdigit *digitInteresting;
1448
1449 for (iPad=0; iPad<AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX()-3; iPad+=2) {
1450
1451 iPadZ = iPad%AliTOFGeometry::NpadZ(); //iPad%2;
1452 iPadX = iPad/AliTOFGeometry::NpadZ(); //iPad/2;
1453
e885fb81 1454 AliDebug(3, Form("%2d %1d %2d\n", iPad, iPadZ, iPadX));
e3bd5504 1455
1456
1457
1458
1459
1460
1461 interestingCounter=-1;
1462
1463 vol[4] = iPadZ , vol[3] = iPadX;
1464 if (fTOFdigitMap->GetNumberOfDigits(vol)>0)
1465 interestingCounter++;
1466
1467 vol[4] = iPadZ, vol[3] = iPadX+1;
1468 if (fTOFdigitMap->GetNumberOfDigits(vol)>0)
1469 interestingCounter++;
1470
1471 vol[4] = AliTOFGeometry::NpadZ()-(iPadZ+1), vol[3] = iPadX;
1472 if (fTOFdigitMap->GetNumberOfDigits(vol)>0)
1473 interestingCounter++;
1474
1475 vol[4] = AliTOFGeometry::NpadZ()-(iPadZ+1), vol[3] = iPadX+1;
1476 if (fTOFdigitMap->GetNumberOfDigits(vol)>0)
1477 interestingCounter++;
1478
1479 if (interestingCounter+1!=3) continue; // the hit pads have to be 3
1480 else interestingCounter=-1;
1481
1482
1483 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
1484 for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++)
1485 selectedDigit[ii][jj] = 0x0;
1486
1487
1488 vol[4] = iPadZ, vol[3] = iPadX;
1489
1490 if (fTOFdigitMap->GetNumberOfDigits(vol)>0) {
1491 interestingCounter++;
1492 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
1493 digitsInVolumeIndices[ii] = -1;
1494 fTOFdigitMap->GetDigitIndex(vol, digitsInVolumeIndices);
e885fb81 1495 digitIndexLocal=-1;
e3bd5504 1496 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
1497 if (digitsInVolumeIndices[digIndex]<0) continue;
1498 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(digitsInVolumeIndices[digIndex]);
e885fb81 1499 if (digitInteresting->GetToT()<=0) continue; // AdC
1500 digitIndexLocal++; // AdC
e3bd5504 1501
e885fb81 1502 AliDebug(1,Form(" %2d %1d %2d %1d %2d %f %f %f %f %5d %5d %5d %5d",
e3bd5504 1503 vol[0], vol[1], vol[2] ,vol[4], vol[3],
1504 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
1505 digitInteresting->GetToT(), digitInteresting->GetToT()*digitInteresting->GetToT(),
1506 digitsInVolumeIndices[digIndex],
1507 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
1508
e885fb81 1509 selectedDigit[interestingCounter][digitIndexLocal] = new // AdC
e3bd5504 1510 AliTOFselectedDigit(vol, digitInteresting->GetTdc(),
1511 digitInteresting->GetAdc(), digitInteresting->GetToT(),
1512 digitInteresting->GetToT()*digitInteresting->GetToT(),
1513 digitsInVolumeIndices[digIndex],
1514 digitInteresting->GetTracks());
1515 }
e885fb81 1516 if (digitIndexLocal==-1) interestingCounter--; // AdC
e3bd5504 1517 }
1518
1519
1520 vol[4] = iPadZ, vol[3] = iPadX+1;
1521
1522 if (fTOFdigitMap->GetNumberOfDigits(vol)>0) {
1523 interestingCounter++;
1524 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
1525 digitsInVolumeIndices[ii] = -1;
1526 fTOFdigitMap->GetDigitIndex(vol, digitsInVolumeIndices);
e885fb81 1527 digitIndexLocal=-1; // AdC
e3bd5504 1528 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
1529 if (digitsInVolumeIndices[digIndex]<0) continue;
1530 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(digitsInVolumeIndices[digIndex]);
e885fb81 1531 if (digitInteresting->GetToT()<=0) continue; // AdC
1532 digitIndexLocal++; // AdC
e3bd5504 1533
e885fb81 1534 AliDebug(1,Form(" %2d %1d %2d %1d %2d %f %f %f %f %5d %5d %5d %5d",
e3bd5504 1535 vol[0], vol[1], vol[2] ,vol[4], vol[3],
1536 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
1537 digitInteresting->GetToT(), digitInteresting->GetToT()*digitInteresting->GetToT(),
1538 digitsInVolumeIndices[digIndex],
1539 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
1540
e885fb81 1541 selectedDigit[interestingCounter][digitIndexLocal] = new // AdC
e3bd5504 1542 AliTOFselectedDigit(vol, digitInteresting->GetTdc(),
1543 digitInteresting->GetAdc(), digitInteresting->GetToT(),
1544 digitInteresting->GetToT()*digitInteresting->GetToT(),
1545 digitsInVolumeIndices[digIndex],
1546 digitInteresting->GetTracks());
1547 }
e885fb81 1548 if (digitIndexLocal==-1) interestingCounter--; // AdC
e3bd5504 1549 }
1550
1551
1552 vol[4] = AliTOFGeometry::NpadZ()-(iPadZ+1), vol[3] = iPadX;
1553
1554 if (fTOFdigitMap->GetNumberOfDigits(vol)>0) {
1555 interestingCounter++;
1556 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
1557 digitsInVolumeIndices[ii] = -1;
1558 fTOFdigitMap->GetDigitIndex(vol, digitsInVolumeIndices);
e885fb81 1559 digitIndexLocal=-1; // AdC
e3bd5504 1560 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
1561 if (digitsInVolumeIndices[digIndex]<0) continue;
1562 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(digitsInVolumeIndices[digIndex]);
e885fb81 1563 if (digitInteresting->GetToT()<=0) continue; // AdC
1564 digitIndexLocal++; // AdC
e3bd5504 1565
e885fb81 1566 AliDebug(1,Form(" %2d %1d %2d %1d %2d %f %f %f %f %5d %5d %5d %5d",
e3bd5504 1567 vol[0], vol[1], vol[2] ,vol[4], vol[3],
1568 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
1569 digitInteresting->GetToT(), digitInteresting->GetToT()*digitInteresting->GetToT(),
1570 digitsInVolumeIndices[digIndex],
1571 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
1572
e885fb81 1573 selectedDigit[interestingCounter][digitIndexLocal] = new // AdC
e3bd5504 1574 AliTOFselectedDigit(vol, digitInteresting->GetTdc(),
1575 digitInteresting->GetAdc(), digitInteresting->GetToT(),
1576 digitInteresting->GetToT()*digitInteresting->GetToT(),
1577 digitsInVolumeIndices[digIndex],
1578 digitInteresting->GetTracks());
1579 }
e885fb81 1580 if (digitIndexLocal==-1) interestingCounter--; // AdC
e3bd5504 1581 }
1582
1583
1584 vol[4] = AliTOFGeometry::NpadZ()-(iPadZ+1), vol[3] = iPadX+1;
1585
1586 if (fTOFdigitMap->GetNumberOfDigits(vol)>0) {
1587 interestingCounter++;
1588 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
1589 digitsInVolumeIndices[ii] = -1;
1590 fTOFdigitMap->GetDigitIndex(vol, digitsInVolumeIndices);
e885fb81 1591 digitIndexLocal=-1; // AdC
e3bd5504 1592 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
1593 if (digitsInVolumeIndices[digIndex]<0) continue;
1594 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(digitsInVolumeIndices[digIndex]);
e885fb81 1595 if (digitInteresting->GetToT()<=0) continue; // AdC
1596 digitIndexLocal++; // AdC
e3bd5504 1597
e885fb81 1598 AliDebug(1,Form(" %2d %1d %2d %1d %2d %f %f %f %f %5d %5d %5d %5d",
e3bd5504 1599 vol[0], vol[1], vol[2] ,vol[4], vol[3],
1600 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
1601 digitInteresting->GetToT(), digitInteresting->GetToT()*digitInteresting->GetToT(),
1602 digitsInVolumeIndices[digIndex],
1603 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
1604
e885fb81 1605 selectedDigit[interestingCounter][digitIndexLocal] = new // AdC
e3bd5504 1606 AliTOFselectedDigit(vol, digitInteresting->GetTdc(),
1607 digitInteresting->GetAdc(), digitInteresting->GetToT(),
1608 digitInteresting->GetToT()*digitInteresting->GetToT(),
1609 digitsInVolumeIndices[digIndex],
1610 digitInteresting->GetTracks());
1611 }
e885fb81 1612 if (digitIndexLocal==-1) interestingCounter--; // AdC
e3bd5504 1613 }
1614
e885fb81 1615 AliDebug(1,Form(" e adesso %1d", interestingCounter+1));
e3bd5504 1616
1617 for (Int_t adesso1=0; adesso1<interestingCounter+1; adesso1++) {
1618 for (Int_t firstIndex=0; firstIndex<kMaxNumberOfDigitsPerVolume; firstIndex++) {
1619 if (selectedDigit[adesso1][firstIndex]==0x0) continue;
1620
1621 for (Int_t adesso2=adesso1+1; adesso2<interestingCounter+1; adesso2++) {
1622 for (Int_t secondIndex=0; secondIndex<kMaxNumberOfDigitsPerVolume; secondIndex++) {
1623 if (selectedDigit[adesso2][secondIndex]==0x0) continue;
1624
1625 if (TMath::Abs(selectedDigit[adesso1][firstIndex]->GetTDC()-selectedDigit[adesso2][secondIndex]->GetTDC())>fMaxDeltaTime) continue;
1626
1627 interestingTOF[0] = selectedDigit[adesso1][firstIndex]->GetTDC();
1628 interestingTOT[0] = selectedDigit[adesso1][firstIndex]->GetTOT();
1629 interestingADC[0] = selectedDigit[adesso1][firstIndex]->GetADC();
1630 interestingWeight[0] = selectedDigit[adesso1][firstIndex]->GetWeight();
1631 Int_t vol1[5]; for(jj=0; jj<5; jj++) vol1[jj] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(jj);
e885fb81 1632 AliDebug(1,Form(" %2d %1d %2d %1d %2d", vol1[0], vol1[1], vol1[2], vol1[4], vol1[3]));
e3bd5504 1633 Int_t volDum = vol1[3];
1634 vol1[3] = vol1[4];
1635 vol1[4] = volDum;
e885fb81 1636 fTOFGeometry->GetPosPar(vol1,pos);
e3bd5504 1637 interestingX[0] = pos[0];
1638 interestingY[0] = pos[1];
1639 interestingZ[0] = pos[2];
1640
1641 interestingTOF[1] = selectedDigit[adesso2][secondIndex]->GetTDC();
1642 interestingTOT[1] = selectedDigit[adesso2][secondIndex]->GetTOT();
1643 interestingADC[1] = selectedDigit[adesso2][secondIndex]->GetADC();
1644 interestingWeight[1] = selectedDigit[adesso2][secondIndex]->GetWeight();
1645 Int_t vol2[5]; for(jj=0; jj<5; jj++) vol2[jj] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(jj);
e885fb81 1646 AliDebug(1,Form(" %2d %1d %2d %1d %2d", vol2[0], vol2[1], vol2[2], vol2[4], vol2[3]));
e3bd5504 1647 volDum = vol2[3];
1648 vol2[3] = vol2[4];
1649 vol2[4] = volDum;
e885fb81 1650 fTOFGeometry->GetPosPar(vol2,pos);
e3bd5504 1651 interestingX[1] = pos[0];
1652 interestingY[1] = pos[1];
1653 interestingZ[1] = pos[2];
1654
1655 AverageCalculations(2, interestingX, interestingY, interestingZ,
1656 interestingTOF, interestingTOT, interestingADC,
1657 interestingWeight,
1658 parTOF, posClus, check);
1659
1660 for (jj=0; jj<5; jj++) det[jj] = -1;
1661 for (jj=0; jj<3; jj++) posF[jj] = posClus[jj];
e885fb81 1662 fTOFGeometry->GetDetID(posF, det);
e3bd5504 1663
e885fb81 1664 volIdClus = fTOFGeometry->GetAliSensVolIndex(det[0],det[1],det[2]);
1665 //volIdClus = GetClusterVolIndex(det);
e3bd5504 1666
1667 for (jj=3; jj<11; jj++) padsCluster[jj] = -1;
1668 padsCluster[3] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(4);
1669 padsCluster[4] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(3);
1670 padsCluster[5] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(4);
1671 padsCluster[6] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(3);
1672
1673 for (jj=0; jj<6; jj++) covClus[jj] = 0.;
1674 Int_t ** indDet = new Int_t*[2];
1675 for (jj=0; jj<2; jj++) indDet[jj] = new Int_t [5];
1676 for (jj=0; jj<2; jj++) indDet[jj][0] = nSector;
1677 for (jj=0; jj<2; jj++) indDet[jj][1] = nPlate;
1678 for (jj=0; jj<2; jj++) indDet[jj][2] = nStrip;
1679 for (jj=0; jj<2; jj++) indDet[jj][3] = padsCluster[2*jj+3];
1680 for (jj=0; jj<2; jj++) indDet[jj][4] = padsCluster[2*jj+1+3];
e885fb81 1681 GetClusterPars(/*check,*/ 2, indDet, interestingWeight, posClus, covClus);
e3bd5504 1682 for (jj=0; jj<2; jj++) delete [] indDet[jj];
1683
1684 // To fill the track index array
1685 dummyCounter=-1;
1686 for (jj=0; jj<kMaxNumberOfTracksPerDigit; jj++) tracks[jj] = -1;
1687 for (Int_t kk=0; kk<kMaxNumberOfTracksPerDigit; kk++) { // three is the max number of tracks associated to one digit
1688 if (selectedDigit[adesso1][firstIndex]->GetTrackLabel(kk)==-1) continue;
1689 else {
1690 dummyCounter++;
1691 tracks[dummyCounter] = selectedDigit[adesso1][firstIndex]->GetTrackLabel(kk);
1692 }
1693 }
1694 for (Int_t kk=0; kk<kMaxNumberOfTracksPerDigit; kk++) { // three is the max number of tracks associated to one digit
1695 if (selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk)==-1) continue;
1696 else {
1697
1698 alreadyStored = kFALSE;
1699 for (jj=0; jj<dummyCounter+1; jj++)
1700 alreadyStored = alreadyStored || (tracks[jj]!=-1 && tracks[jj]==selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk));
1701
1702 if (alreadyStored) continue;
1703 if (dummyCounter==2) { // three is the max number of tracks associated to one cluster
1704 AliWarning(" Siamo al limite!");
1705 continue;
1706 }
1707
1708 dummyCounter++;
1709 tracks[dummyCounter] = selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk);
1710
1711 }
1712
1713 }
1714
1715
1716 AliTOFcluster *tofCluster =
1717 new AliTOFcluster(volIdClus, posClus[0], posClus[1], posClus[2],
1718 covClus[0], covClus[1], covClus[2], covClus[3], covClus[4], covClus[5],
1719 tracks, det, parTOF, status, selectedDigit[adesso1][firstIndex]->GetIndex()); // to be updated
1720 InsertCluster(tofCluster);
1721
e885fb81 1722 AliDebug(2, Form(" %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",
e3bd5504 1723 volIdClus, posClus[0], posClus[1], posClus[2],
1724 covClus[0], covClus[1], covClus[2], covClus[3], covClus[4], covClus[5],
1725 tracks[0], tracks[1], tracks[2],
1726 det[0], det[1], det[2], det[3], det[4],
1727 parTOF[0], parTOF[1], parTOF[2], parTOF[3], parTOF[4],
1728 status, selectedDigit[adesso1][firstIndex]->GetIndex()));
1729
1730 volDum = vol1[3];
1731 vol1[3] = vol1[4];
1732 vol1[4] = volDum;
1733 fTOFdigitMap->ResetDigitNumber(vol1,selectedDigit[adesso1][firstIndex]->GetIndex());
1734 volDum = vol2[3];
1735 vol2[3] = vol2[4];
1736 vol2[4] = volDum;
1737 fTOFdigitMap->ResetDigitNumber(vol2,selectedDigit[adesso2][secondIndex]->GetIndex());
1738
1739
1740 } // close loop on second digit
1741 } // close loop on adesso2
1742
1743 } // close loop on first digit
1744 } // close loop on adesso1
1745
1746 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
1747 for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++)
1748 selectedDigit[ii][jj] = 0x0;
1749
1750 } // loop on iPad
1751
1752 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
1753 for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++) {
1754 delete selectedDigit[ii][jj];
1755 selectedDigit[ii][jj] = 0x0;
1756 }
1757
1758
1759}
1760//_____________________________________________________________________________
1761
1762void AliTOFClusterFinderV1::FindClusters24(Int_t nSector,
1763 Int_t nPlate,
1764 Int_t nStrip)
1765{
1766 //
1767 // This function searches the neighbouring digits (stored in the fDigits object),
1768 // to perform clusters (stored in the fTofClusters array).
1769 //
1770 // This research has been made by checking the fTOFdigitMap object,
1771 // filled at digits/raw-data reading time.
1772 //
1773
1774 const Int_t kMaxNumberOfInterestingPads = 4;
1775 const Int_t kMaxNumberOfTracksPerDigit = 3;
1776 const Int_t kMaxNumberOfDigitsPerVolume = 3;
1777
1778 Int_t ii = 0;
1779
1780 Int_t digitsInVolumeIndices[kMaxNumberOfDigitsPerVolume];
1781 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
1782 digitsInVolumeIndices[ii] = -1;
1783
e3bd5504 1784 Int_t vol[5] = {nSector,nPlate,nStrip,-1,-1};
1785
1786 Float_t pos[3] = {0.,0.,0.};
1787
1788 Int_t jj = 0;
1789 Int_t interestingPadX[kMaxNumberOfInterestingPads];
1790 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingPadX[jj] = -1;
1791 Int_t interestingPadZ[kMaxNumberOfInterestingPads];
1792 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingPadZ[jj] = -1;
1793 Double_t interestingTOT[kMaxNumberOfInterestingPads];
1794 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingTOT[jj] = 0;
1795 Double_t interestingADC[kMaxNumberOfInterestingPads];
1796 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingADC[jj] = 0;
1797 Double_t interestingTOF[kMaxNumberOfInterestingPads];
1798 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingTOF[jj] = 0;
1799 Double_t interestingWeight[kMaxNumberOfInterestingPads];
1800 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingWeight[jj] = 0;
1801
1802 Float_t interestingX[kMaxNumberOfInterestingPads];
1803 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingX[jj] = 0;
1804 Float_t interestingY[kMaxNumberOfInterestingPads];
1805 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingY[jj] = 0;
1806 Float_t interestingZ[kMaxNumberOfInterestingPads];
1807 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingZ[jj] = 0;
1808
1809 Float_t interDigit[kMaxNumberOfInterestingPads];
1810 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interDigit[jj] = 0;
1811
1812 Int_t padsCluster[11];
1813 padsCluster[0] = nSector;
1814 padsCluster[1] = nPlate;
1815 padsCluster[2] = nStrip;
1816 for (jj=3; jj<11; jj++) padsCluster[jj] = -1;
1817
1818 Int_t interestingCounter=-1;
e885fb81 1819 Int_t digitIndexLocal = -1;
e3bd5504 1820 Int_t iPad = -1;
1821 Int_t iPadX = -1;
1822 Int_t iPadZ = -1;
1823
1824 Bool_t check = kFALSE;
1825 Int_t parTOF[5];
1826 for (jj=0; jj<5; jj++) parTOF[jj] = 0;
1827 Double_t posClus[3];
1828 for (jj=0; jj<3; jj++) posClus[jj] = 0.;
1829 Int_t det[5];
1830 for (jj=0; jj<5; jj++) det[jj] = -1;
1831 Float_t posF[3];
1832 for (jj=0; jj<3; jj++) posF[jj] = 0.;
1833 UShort_t volIdClus = 0;
1834 Bool_t status = kTRUE; //assume all sim channels ok in the beginning...
1835 Double_t covClus[6];
1836 for (jj=0; jj<6; jj++) covClus[jj] = 0.;
1837 Int_t tracks[kMaxNumberOfTracksPerDigit];
1838 for (jj=0; jj<3; jj++) tracks[jj] = -1;
1839 Int_t dummyCounter=-1;
1840 Bool_t alreadyStored = kFALSE;
1841
1842 AliTOFselectedDigit ***selectedDigit = new AliTOFselectedDigit**[kMaxNumberOfInterestingPads];
1843 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
1844 selectedDigit[ii] = new AliTOFselectedDigit*[kMaxNumberOfDigitsPerVolume];
1845
1846 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
1847 for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++) selectedDigit[ii][jj] = 0x0;
1848
1849 AliTOFdigit *digitInteresting;
1850
1851 for (iPad=0; iPad<AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX()-3; iPad+=2) {
1852
1853 iPadZ = iPad%AliTOFGeometry::NpadZ(); //iPad%2;
1854 iPadX = iPad/AliTOFGeometry::NpadZ(); //iPad/2;
1855
e885fb81 1856 AliDebug(3, Form("%2d %1d %2d\n", iPad, iPadZ, iPadX));
e3bd5504 1857
1858
1859
1860
1861
1862
1863 interestingCounter=-1;
1864
1865 vol[4] = iPadZ , vol[3] = iPadX;
1866 if (fTOFdigitMap->GetNumberOfDigits(vol)>0)
1867 interestingCounter++;
1868
1869 vol[4] = iPadZ, vol[3] = iPadX+1;
1870 if (fTOFdigitMap->GetNumberOfDigits(vol)>0)
1871 interestingCounter++;
1872
1873 vol[4] = AliTOFGeometry::NpadZ()-(iPadZ+1), vol[3] = iPadX;
1874 if (fTOFdigitMap->GetNumberOfDigits(vol)>0)
1875 interestingCounter++;
1876
1877 vol[4] = AliTOFGeometry::NpadZ()-(iPadZ+1), vol[3] = iPadX+1;
1878 if (fTOFdigitMap->GetNumberOfDigits(vol)>0)
1879 interestingCounter++;
1880
1881 if (interestingCounter+1!=4) continue; // the hit pads have to be 4
1882 else interestingCounter=-1;
1883
1884
1885 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
1886 for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++)
1887 selectedDigit[ii][jj] = 0x0;
1888
1889
1890 vol[4] = iPadZ, vol[3] = iPadX;
1891
1892 if (fTOFdigitMap->GetNumberOfDigits(vol)>0) {
1893 interestingCounter++;
1894 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
1895 digitsInVolumeIndices[ii] = -1;
1896 fTOFdigitMap->GetDigitIndex(vol, digitsInVolumeIndices);
e885fb81 1897 digitIndexLocal=-1; // AdC
e3bd5504 1898 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
1899 if (digitsInVolumeIndices[digIndex]<0) continue;
1900 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(digitsInVolumeIndices[digIndex]);
e885fb81 1901 if (digitInteresting->GetToT()<=0) continue; // AdC
1902 digitIndexLocal++; // AdC
e3bd5504 1903
e885fb81 1904 AliDebug(1,Form(" %2d %1d %2d %1d %2d %f %f %f %f %5d %5d %5d %5d",
e3bd5504 1905 vol[0], vol[1], vol[2] ,vol[4], vol[3],
1906 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
1907 digitInteresting->GetToT(), digitInteresting->GetToT()*digitInteresting->GetToT(),
1908 digitsInVolumeIndices[digIndex],
1909 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
1910
e885fb81 1911 selectedDigit[interestingCounter][digitIndexLocal] = new // AdC
e3bd5504 1912 AliTOFselectedDigit(vol, digitInteresting->GetTdc(),
1913 digitInteresting->GetAdc(), digitInteresting->GetToT(),
1914 digitInteresting->GetToT()*digitInteresting->GetToT(),
1915 digitsInVolumeIndices[digIndex],
1916 digitInteresting->GetTracks());
1917 }
e885fb81 1918 if (digitIndexLocal==-1) interestingCounter--; // AdC
e3bd5504 1919 }
1920
1921
1922 vol[4] = iPadZ, vol[3] = iPadX+1;
1923
1924 if (fTOFdigitMap->GetNumberOfDigits(vol)>0) {
1925 interestingCounter++;
1926 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
1927 digitsInVolumeIndices[ii] = -1;
1928 fTOFdigitMap->GetDigitIndex(vol, digitsInVolumeIndices);
e885fb81 1929 digitIndexLocal=-1; // AdC
e3bd5504 1930 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
1931 if (digitsInVolumeIndices[digIndex]<0) continue;
1932 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(digitsInVolumeIndices[digIndex]);
e885fb81 1933 if (digitInteresting->GetToT()<=0) continue; // AdC
1934 digitIndexLocal++; // AdC
e3bd5504 1935
e885fb81 1936 AliDebug(1,Form(" %2d %1d %2d %1d %2d %f %f %f %f %5d %5d %5d %5d",
e3bd5504 1937 vol[0], vol[1], vol[2] ,vol[4], vol[3],
1938 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
1939 digitInteresting->GetToT(), digitInteresting->GetToT()*digitInteresting->GetToT(),
1940 digitsInVolumeIndices[digIndex],
1941 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
1942
e885fb81 1943 selectedDigit[interestingCounter][digitIndexLocal] = new // AdC
e3bd5504 1944 AliTOFselectedDigit(vol, digitInteresting->GetTdc(),
1945 digitInteresting->GetAdc(), digitInteresting->GetToT(),
1946 digitInteresting->GetToT()*digitInteresting->GetToT(),
1947 digitsInVolumeIndices[digIndex],
1948 digitInteresting->GetTracks());
1949 }
e885fb81 1950 if (digitIndexLocal==-1) interestingCounter--; // AdC
e3bd5504 1951 }
1952
1953
1954 vol[4] = AliTOFGeometry::NpadZ()-(iPadZ+1), vol[3] = iPadX;
1955
1956 if (fTOFdigitMap->GetNumberOfDigits(vol)>0) {
1957 interestingCounter++;
1958 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
1959 digitsInVolumeIndices[ii] = -1;
1960 fTOFdigitMap->GetDigitIndex(vol, digitsInVolumeIndices);
e885fb81 1961 digitIndexLocal=-1; // AdC
e3bd5504 1962 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
1963 if (digitsInVolumeIndices[digIndex]<0) continue;
1964 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(digitsInVolumeIndices[digIndex]);
e885fb81 1965 if (digitInteresting->GetToT()<=0) continue; // AdC
1966 digitIndexLocal++; // AdC
e3bd5504 1967
e885fb81 1968 AliDebug(1,Form(" %2d %1d %2d %1d %2d %f %f %f %f %5d %5d %5d %5d",
e3bd5504 1969 vol[0], vol[1], vol[2] ,vol[4], vol[3],
1970 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
1971 digitInteresting->GetToT(), digitInteresting->GetToT()*digitInteresting->GetToT(),
1972 digitsInVolumeIndices[digIndex],
1973 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
1974
e885fb81 1975 selectedDigit[interestingCounter][digitIndexLocal] = new // AdC
e3bd5504 1976 AliTOFselectedDigit(vol, digitInteresting->GetTdc(),
1977 digitInteresting->GetAdc(), digitInteresting->GetToT(),
1978 digitInteresting->GetToT()*digitInteresting->GetToT(),
1979 digitsInVolumeIndices[digIndex],
1980 digitInteresting->GetTracks());
1981 }
e885fb81 1982 if (digitIndexLocal==-1) interestingCounter--; // AdC
e3bd5504 1983 }
1984
1985
1986 vol[4] = AliTOFGeometry::NpadZ()-(iPadZ+1), vol[3] = iPadX+1;
1987
1988 if (fTOFdigitMap->GetNumberOfDigits(vol)>0) {
1989 interestingCounter++;
1990 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
1991 digitsInVolumeIndices[ii] = -1;
1992 fTOFdigitMap->GetDigitIndex(vol, digitsInVolumeIndices);
e885fb81 1993 digitIndexLocal=-1; // AdC
e3bd5504 1994 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
1995 if (digitsInVolumeIndices[digIndex]<0) continue;
1996 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(digitsInVolumeIndices[digIndex]);
e885fb81 1997 if (digitInteresting->GetToT()<=0) continue; // AdC
1998 digitIndexLocal++; // AdC
e3bd5504 1999
e885fb81 2000 AliDebug(1,Form(" %2d %1d %2d %1d %2d %f %f %f %f %5d %5d %5d %5d",
e3bd5504 2001 vol[0], vol[1], vol[2] ,vol[4], vol[3],
2002 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
2003 digitInteresting->GetToT(), digitInteresting->GetToT()*digitInteresting->GetToT(),
2004 digitsInVolumeIndices[digIndex],
2005 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
2006
e885fb81 2007 selectedDigit[interestingCounter][digitIndexLocal] = new // AdC
e3bd5504 2008 AliTOFselectedDigit(vol, digitInteresting->GetTdc(),
2009 digitInteresting->GetAdc(), digitInteresting->GetToT(),
2010 digitInteresting->GetToT()*digitInteresting->GetToT(),
2011 digitsInVolumeIndices[digIndex],
2012 digitInteresting->GetTracks());
2013 }
e885fb81 2014 if (digitIndexLocal==-1) interestingCounter--; // AdC
e3bd5504 2015 }
2016
e885fb81 2017 AliDebug(1,Form(" e adesso %1d", interestingCounter+1));
e3bd5504 2018
2019 for (Int_t adesso1=0; adesso1<interestingCounter+1; adesso1++) {
2020 for (Int_t firstIndex=0; firstIndex<kMaxNumberOfDigitsPerVolume; firstIndex++) {
2021 if (selectedDigit[adesso1][firstIndex]==0x0) continue;
2022
2023 for (Int_t adesso2=adesso1+1; adesso2<interestingCounter+1; adesso2++) {
2024 for (Int_t secondIndex=0; secondIndex<kMaxNumberOfDigitsPerVolume; secondIndex++) {
2025 if (selectedDigit[adesso2][secondIndex]==0x0) continue;
2026
2027 if (TMath::Abs(selectedDigit[adesso1][firstIndex]->GetTDC()-selectedDigit[adesso2][secondIndex]->GetTDC())>fMaxDeltaTime) continue;
2028
2029 interestingTOF[0] = selectedDigit[adesso1][firstIndex]->GetTDC();
2030 interestingTOT[0] = selectedDigit[adesso1][firstIndex]->GetTOT();
2031 interestingADC[0] = selectedDigit[adesso1][firstIndex]->GetADC();
2032 interestingWeight[0] = selectedDigit[adesso1][firstIndex]->GetWeight();
2033 Int_t vol1[5]; for(jj=0; jj<5; jj++) vol1[jj] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(jj);
e885fb81 2034 AliDebug(1,Form(" %2d %1d %2d %1d %2d", vol1[0], vol1[1], vol1[2], vol1[4], vol1[3]));
e3bd5504 2035 Int_t volDum = vol1[3];
2036 vol1[3] = vol1[4];
2037 vol1[4] = volDum;
e885fb81 2038 fTOFGeometry->GetPosPar(vol1,pos);
e3bd5504 2039 interestingX[0] = pos[0];
2040 interestingY[0] = pos[1];
2041 interestingZ[0] = pos[2];
2042
2043 interestingTOF[1] = selectedDigit[adesso2][secondIndex]->GetTDC();
2044 interestingTOT[1] = selectedDigit[adesso2][secondIndex]->GetTOT();
2045 interestingADC[1] = selectedDigit[adesso2][secondIndex]->GetADC();
2046 interestingWeight[1] = selectedDigit[adesso2][secondIndex]->GetWeight();
2047 Int_t vol2[5]; for(jj=0; jj<5; jj++) vol2[jj] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(jj);
e885fb81 2048 AliDebug(1,Form(" %2d %1d %2d %1d %2d", vol2[0], vol2[1], vol2[2], vol2[4], vol2[3]));
e3bd5504 2049 volDum = vol2[3];
2050 vol2[3] = vol2[4];
2051 vol2[4] = volDum;
e885fb81 2052 fTOFGeometry->GetPosPar(vol2,pos);
e3bd5504 2053 interestingX[1] = pos[0];
2054 interestingY[1] = pos[1];
2055 interestingZ[1] = pos[2];
2056
2057
2058 AverageCalculations(2, interestingX, interestingY, interestingZ,
2059 interestingTOF, interestingTOT, interestingADC,
2060 interestingWeight,
2061 parTOF, posClus, check);
2062
2063 for (jj=0; jj<5; jj++) det[jj] = -1;
2064 for (jj=0; jj<3; jj++) posF[jj] = posClus[jj];
e885fb81 2065 fTOFGeometry->GetDetID(posF, det);
e3bd5504 2066
e885fb81 2067 volIdClus = fTOFGeometry->GetAliSensVolIndex(det[0],det[1],det[2]);
2068 //volIdClus = GetClusterVolIndex(det);
e3bd5504 2069
2070 for (jj=3; jj<11; jj++) padsCluster[jj] = -1;
2071 padsCluster[3] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(4);
2072 padsCluster[4] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(3);
2073 padsCluster[5] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(4);
2074 padsCluster[6] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(3);
2075
2076 for (jj=0; jj<6; jj++) covClus[jj] = 0.;
2077 Int_t ** indDet = new Int_t*[2];
2078 for (jj=0; jj<2; jj++) indDet[jj] = new Int_t [5];
2079 for (jj=0; jj<2; jj++) indDet[jj][0] = nSector;
2080 for (jj=0; jj<2; jj++) indDet[jj][1] = nPlate;
2081 for (jj=0; jj<2; jj++) indDet[jj][2] = nStrip;
2082 for (jj=0; jj<2; jj++) indDet[jj][3] = padsCluster[2*jj+3];
2083 for (jj=0; jj<2; jj++) indDet[jj][4] = padsCluster[2*jj+1+3];
e885fb81 2084 GetClusterPars(/*check,*/ 2, indDet, interestingWeight, posClus, covClus);
e3bd5504 2085 for (jj=0; jj<2; jj++) delete [] indDet[jj];
2086
2087 // To fill the track index array
2088 dummyCounter=-1;
2089 for (jj=0; jj<kMaxNumberOfTracksPerDigit; jj++) tracks[jj] = -1;
2090 for (Int_t kk=0; kk<kMaxNumberOfTracksPerDigit; kk++) { // three is the max number of tracks associated to one digit
2091 if (selectedDigit[adesso1][firstIndex]->GetTrackLabel(kk)==-1) continue;
2092 else {
2093 dummyCounter++;
2094 tracks[dummyCounter] = selectedDigit[adesso1][firstIndex]->GetTrackLabel(kk);
2095 }
2096 }
2097 for (Int_t kk=0; kk<kMaxNumberOfTracksPerDigit; kk++) { // three is the max number of tracks associated to one digit
2098 if (selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk)==-1) continue;
2099 else {
2100
2101 alreadyStored = kFALSE;
2102 for (jj=0; jj<dummyCounter+1; jj++)
2103 alreadyStored = alreadyStored || (tracks[jj]!=-1 && tracks[jj]==selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk));
2104
2105 if (alreadyStored) continue;
2106 if (dummyCounter==2) { // three is the max number of tracks associated to one cluster
2107 AliWarning(" Siamo al limite!");
2108 continue;
2109 }
2110
2111 dummyCounter++;
2112 tracks[dummyCounter] = selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk);
2113
2114 }
2115
2116 }
2117
2118
2119 AliTOFcluster *tofCluster =
2120 new AliTOFcluster(volIdClus, posClus[0], posClus[1], posClus[2],
2121 covClus[0], covClus[1], covClus[2], covClus[3], covClus[4], covClus[5],
2122 tracks, det, parTOF, status, selectedDigit[adesso1][firstIndex]->GetIndex()); // to be updated
2123 InsertCluster(tofCluster);
2124
e885fb81 2125 AliDebug(2, Form(" %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",
e3bd5504 2126 volIdClus, posClus[0], posClus[1], posClus[2],
2127 covClus[0], covClus[1], covClus[2], covClus[3], covClus[4], covClus[5],
2128 tracks[0], tracks[1], tracks[2],
2129 det[0], det[1], det[2], det[3], det[4],
2130 parTOF[0], parTOF[1], parTOF[2], parTOF[3], parTOF[4],
2131 status, selectedDigit[adesso1][firstIndex]->GetIndex()));
2132
2133 volDum = vol1[3];
2134 vol1[3] = vol1[4];
2135 vol1[4] = volDum;
2136 fTOFdigitMap->ResetDigitNumber(vol1,selectedDigit[adesso1][firstIndex]->GetIndex());
2137 volDum = vol2[3];
2138 vol2[3] = vol2[4];
2139 vol2[4] = volDum;
2140 fTOFdigitMap->ResetDigitNumber(vol2,selectedDigit[adesso2][secondIndex]->GetIndex());
2141
2142
2143 } // close loop on second digit
2144 } // close loop on adesso2
2145
2146 } // close loop on first digit
2147 } // close loop on adesso1
2148
2149 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
2150 for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++)
2151 selectedDigit[ii][jj] = 0x0;
2152
2153 } // loop on iPad
2154
2155 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
2156 for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++) {
2157 delete selectedDigit[ii][jj];
2158 selectedDigit[ii][jj] = 0x0;
2159 }
2160
2161
2162}
2163//_____________________________________________________________________________
2164
2165void AliTOFClusterFinderV1::FindClustersPerStrip(Int_t nSector,
2166 Int_t nPlate,
2167 Int_t nStrip,
2168 Int_t group)
2169{
2170 //
2171 // This function searches the neighbouring digits (stored in the fDigits object),
2172 // to perform clusters (stored in the fTofClusters array).
2173 //
2174 // Each strip is read four times:
2175 // - 1st time: it searches possible clusters formed by four
2176 // neighbouring digits;
2177 // - 2nd time: it searches possible clusters formed by three
2178 // neighbouring digits;
2179 // - 3rd time: it searches possible clusters formed by two
2180 // neighbouring digits;
2181 // - 4th time: the remaining isolated digits have been transformed
2182 // in clusters.
2183 // This research has been made by checking the fTOFdigitMap object,
2184 // filled at digits/raw-data reading time.
2185 //
2186
2187 const Int_t kMaxNumberOfInterestingPads = 4;
2188 const Int_t kMaxNumberOfTracksPerDigit = 3;
2189 const Int_t kMaxNumberOfDigitsPerVolume = 3;
2190
2191 Int_t ii = 0;
2192
2193 Int_t digitsInVolumeIndices[kMaxNumberOfDigitsPerVolume];
2194 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
2195 digitsInVolumeIndices[ii] = -1;
2196
e3bd5504 2197 Int_t vol[5] = {nSector,nPlate,nStrip,-1,-1};
2198
2199 Float_t pos[3] = {0.,0.,0.};
2200
2201 Int_t jj = 0;
2202 Int_t interestingPadX[kMaxNumberOfInterestingPads];
2203 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingPadX[jj] = -1;
2204 Int_t interestingPadZ[kMaxNumberOfInterestingPads];
2205 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingPadZ[jj] = -1;
2206 Double_t interestingTOT[kMaxNumberOfInterestingPads];
2207 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingTOT[jj] = 0;
2208 Double_t interestingADC[kMaxNumberOfInterestingPads];
2209 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingADC[jj] = 0;
2210 Double_t interestingTOF[kMaxNumberOfInterestingPads];
2211 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingTOF[jj] = 0;
2212 Double_t interestingWeight[kMaxNumberOfInterestingPads];
2213 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingWeight[jj] = 0;
2214
2215 Float_t interestingX[kMaxNumberOfInterestingPads];
2216 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingX[jj] = 0;
2217 Float_t interestingY[kMaxNumberOfInterestingPads];
2218 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingY[jj] = 0;
2219 Float_t interestingZ[kMaxNumberOfInterestingPads];
2220 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interestingZ[jj] = 0;
2221
2222 Float_t interDigit[kMaxNumberOfInterestingPads];
2223 for (jj=0; jj<kMaxNumberOfInterestingPads; jj++) interDigit[jj] = 0;
2224
2225 Int_t padsCluster[11];
2226 padsCluster[0] = nSector;
2227 padsCluster[1] = nPlate;
2228 padsCluster[2] = nStrip;
2229 for (jj=3; jj<11; jj++) padsCluster[jj] = -1;
2230
2231 Int_t interestingCounter=-1;
e885fb81 2232 Int_t digitIndexLocal = -1;
e3bd5504 2233 Int_t iPad = -1;
2234 Int_t iPadX = -1;
2235 Int_t iPadZ = -1;
2236
2237 Bool_t check = kFALSE;
2238 Int_t parTOF[5];
2239 for (jj=0; jj<5; jj++) parTOF[jj] = 0;
2240 Double_t posClus[3];
2241 for (jj=0; jj<3; jj++) posClus[jj] = 0.;
2242 Int_t det[5];
2243 for (jj=0; jj<5; jj++) det[jj] = -1;
2244 Float_t posF[3];
2245 for (jj=0; jj<3; jj++) posF[jj] = 0.;
2246 UShort_t volIdClus = 0;
2247 Bool_t status = kTRUE; //assume all sim channels ok in the beginning...
2248 Double_t covClus[6];
2249 for (jj=0; jj<6; jj++) covClus[jj] = 0.;
2250 Int_t tracks[kMaxNumberOfTracksPerDigit];
2251 for (jj=0; jj<3; jj++) tracks[jj] = -1;
2252 Int_t dummyCounter=-1;
2253 Bool_t alreadyStored = kFALSE;
2254
2255 AliTOFselectedDigit ***selectedDigit = new AliTOFselectedDigit**[kMaxNumberOfInterestingPads];
2256 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
2257 selectedDigit[ii] = new AliTOFselectedDigit*[kMaxNumberOfDigitsPerVolume];
2258
2259 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
2260 for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++) selectedDigit[ii][jj] = 0x0;
2261
2262 AliTOFdigit *digitInteresting;
2263
2264 group = group-1;
2265
2266 for (iPad=0; iPad<AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX()-3; iPad+=2) {
2267
2268 iPadZ = iPad%AliTOFGeometry::NpadZ(); //iPad%2;
2269 iPadX = iPad/AliTOFGeometry::NpadZ(); //iPad/2;
2270
e885fb81 2271 AliDebug(3, Form("%2d %1d %2d\n", iPad, iPadZ, iPadX));
e3bd5504 2272
2273
2274
2275
2276
2277
2278 interestingCounter=-1;
2279
2280 vol[4] = iPadZ , vol[3] = iPadX;
2281 if (fTOFdigitMap->GetNumberOfDigits(vol)>0)
2282 interestingCounter++;
2283
2284 vol[4] = iPadZ, vol[3] = iPadX+1;
2285 if (fTOFdigitMap->GetNumberOfDigits(vol)>0)
2286 interestingCounter++;
2287
2288 vol[4] = AliTOFGeometry::NpadZ()-(iPadZ+1), vol[3] = iPadX;
2289 if (fTOFdigitMap->GetNumberOfDigits(vol)>0)
2290 interestingCounter++;
2291
2292 vol[4] = AliTOFGeometry::NpadZ()-(iPadZ+1), vol[3] = iPadX+1;
2293 if (fTOFdigitMap->GetNumberOfDigits(vol)>0)
2294 interestingCounter++;
2295
2296 if (interestingCounter!=group) continue;
2297 else interestingCounter=-1;
2298
2299
2300 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
2301 for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++)
2302 selectedDigit[ii][jj] = 0x0;
2303
2304
2305 vol[4] = iPadZ, vol[3] = iPadX;
2306
2307 if (fTOFdigitMap->GetNumberOfDigits(vol)>0) {
2308 interestingCounter++;
2309 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
2310 digitsInVolumeIndices[ii] = -1;
2311 fTOFdigitMap->GetDigitIndex(vol, digitsInVolumeIndices);
e885fb81 2312 digitIndexLocal=-1; // AdC
e3bd5504 2313 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
2314 if (digitsInVolumeIndices[digIndex]<0) continue;
2315 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(digitsInVolumeIndices[digIndex]);
e885fb81 2316 if (digitInteresting->GetToT()<=0) continue; // AdC
2317 digitIndexLocal++; // AdC
e3bd5504 2318
e885fb81 2319 AliDebug(1,Form(" %2d %1d %2d %1d %2d %d %d %d %d %5d %5d %5d %5d",
e3bd5504 2320 vol[0], vol[1], vol[2] ,vol[4], vol[3],
2321 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
2322 digitInteresting->GetToT(), digitInteresting->GetToT()*digitInteresting->GetToT(),
2323 digitsInVolumeIndices[digIndex],
2324 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
e885fb81 2325 AliDebug(1,Form(" to try %d %d ",digIndex, interestingCounter));
e3bd5504 2326
e885fb81 2327 selectedDigit[interestingCounter][digitIndexLocal] = new // AdC
e3bd5504 2328 AliTOFselectedDigit(vol, digitInteresting->GetTdc(),
2329 digitInteresting->GetAdc(), digitInteresting->GetToT(),
2330 digitInteresting->GetToT()*digitInteresting->GetToT(),
2331 digitsInVolumeIndices[digIndex],
2332 digitInteresting->GetTracks());
2333 }
e885fb81 2334 if (digitIndexLocal==-1) interestingCounter--; // AdC
e3bd5504 2335 }
2336
2337
2338 vol[4] = iPadZ, vol[3] = iPadX+1;
2339
2340 if (fTOFdigitMap->GetNumberOfDigits(vol)>0) {
2341 interestingCounter++;
2342 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
2343 digitsInVolumeIndices[ii] = -1;
2344 fTOFdigitMap->GetDigitIndex(vol, digitsInVolumeIndices);
e885fb81 2345 digitIndexLocal=-1; // AdC
e3bd5504 2346 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
2347 if (digitsInVolumeIndices[digIndex]<0) continue;
2348 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(digitsInVolumeIndices[digIndex]);
e885fb81 2349 if (digitInteresting->GetToT()<=0) continue; // AdC
2350 digitIndexLocal++; // AdC
e3bd5504 2351
e885fb81 2352 AliDebug(1,Form(" %2d %1d %2d %1d %2d %d %d %d %d %5d %5d %5d %5d",
e3bd5504 2353 vol[0], vol[1], vol[2] ,vol[4], vol[3],
2354 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
2355 digitInteresting->GetToT(), digitInteresting->GetToT()*digitInteresting->GetToT(),
2356 digitsInVolumeIndices[digIndex],
2357 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
e885fb81 2358 AliDebug(1,Form(" to try %d %d ",digIndex, interestingCounter));
e3bd5504 2359
e885fb81 2360 selectedDigit[interestingCounter][digitIndexLocal] = new // AdC
e3bd5504 2361 AliTOFselectedDigit(vol, digitInteresting->GetTdc(),
2362 digitInteresting->GetAdc(), digitInteresting->GetToT(),
2363 digitInteresting->GetToT()*digitInteresting->GetToT(),
2364 digitsInVolumeIndices[digIndex],
2365 digitInteresting->GetTracks());
2366 }
e885fb81 2367 if (digitIndexLocal==-1) interestingCounter--; // AdC
e3bd5504 2368 }
2369
2370
2371 vol[4] = AliTOFGeometry::NpadZ()-(iPadZ+1), vol[3] = iPadX;
2372
2373 if (fTOFdigitMap->GetNumberOfDigits(vol)>0) {
2374 interestingCounter++;
2375 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
2376 digitsInVolumeIndices[ii] = -1;
2377 fTOFdigitMap->GetDigitIndex(vol, digitsInVolumeIndices);
e885fb81 2378 digitIndexLocal=-1; // AdC
e3bd5504 2379 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
2380 if (digitsInVolumeIndices[digIndex]<0) continue;
2381 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(digitsInVolumeIndices[digIndex]);
e885fb81 2382 if (digitInteresting->GetToT()<=0) continue; // AdC
2383 digitIndexLocal++; // AdC
e3bd5504 2384
e885fb81 2385 AliDebug(1,Form(" %2d %1d %2d %1d %2d %d %d %d %d %5d %5d %5d %5d",
e3bd5504 2386 vol[0], vol[1], vol[2] ,vol[4], vol[3],
2387 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
2388 digitInteresting->GetToT(), digitInteresting->GetToT()*digitInteresting->GetToT(),
2389 digitsInVolumeIndices[digIndex],
2390 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
e885fb81 2391 AliDebug(1,Form(" to try %d %d ",digIndex, interestingCounter));
e3bd5504 2392
e885fb81 2393 selectedDigit[interestingCounter][digitIndexLocal] = new // AdC
e3bd5504 2394 AliTOFselectedDigit(vol, digitInteresting->GetTdc(),
2395 digitInteresting->GetAdc(), digitInteresting->GetToT(),
2396 digitInteresting->GetToT()*digitInteresting->GetToT(),
2397 digitsInVolumeIndices[digIndex],
2398 digitInteresting->GetTracks());
2399 }
e885fb81 2400 if (digitIndexLocal==-1) interestingCounter--; // AdC
e3bd5504 2401 }
2402
2403
2404 vol[4] = AliTOFGeometry::NpadZ()-(iPadZ+1), vol[3] = iPadX+1;
2405
2406 if (fTOFdigitMap->GetNumberOfDigits(vol)>0) {
2407 interestingCounter++;
2408 for (ii=0; ii<kMaxNumberOfDigitsPerVolume; ii++)
2409 digitsInVolumeIndices[ii] = -1;
2410 fTOFdigitMap->GetDigitIndex(vol, digitsInVolumeIndices);
e885fb81 2411 digitIndexLocal=-1; // AdC
e3bd5504 2412 for(Int_t digIndex=0; digIndex<kMaxNumberOfDigitsPerVolume; digIndex++) {
2413 if (digitsInVolumeIndices[digIndex]<0) continue;
2414 digitInteresting = (AliTOFdigit*)fDigits->UncheckedAt(digitsInVolumeIndices[digIndex]);
e885fb81 2415 if (digitInteresting->GetToT()<=0) continue; // AdC
2416 digitIndexLocal++; // AdC
e3bd5504 2417
e885fb81 2418 AliDebug(1,Form(" %2d %1d %2d %1d %2d %d %d %d %d %5d %5d %5d %5d",
e3bd5504 2419 vol[0], vol[1], vol[2] ,vol[4], vol[3],
2420 digitInteresting->GetTdc(), digitInteresting->GetAdc(),
2421 digitInteresting->GetToT(), digitInteresting->GetToT()*digitInteresting->GetToT(),
2422 digitsInVolumeIndices[digIndex],
2423 digitInteresting->GetTrack(0), digitInteresting->GetTrack(1), digitInteresting->GetTrack(2)));
e885fb81 2424 AliDebug(1,Form(" to try %d %d ",digIndex, interestingCounter));
e3bd5504 2425
e885fb81 2426 selectedDigit[interestingCounter][digitIndexLocal] = new // AdC
e3bd5504 2427 AliTOFselectedDigit(vol, digitInteresting->GetTdc(),
2428 digitInteresting->GetAdc(), digitInteresting->GetToT(),
2429 digitInteresting->GetToT()*digitInteresting->GetToT(),
2430 digitsInVolumeIndices[digIndex],
2431 digitInteresting->GetTracks());
2432 }
e885fb81 2433 if (digitIndexLocal==-1) interestingCounter--; // AdC
e3bd5504 2434 }
2435
e885fb81 2436 AliDebug(1,Form(" e adesso %1d", interestingCounter+1));
e3bd5504 2437
2438 switch(interestingCounter+1) {
2439
2440 case 2:
2441
2442 for (Int_t adesso1=0; adesso1<interestingCounter+1; adesso1++) {
2443 for (Int_t firstIndex=0; firstIndex<kMaxNumberOfDigitsPerVolume; firstIndex++) {
2444 if (selectedDigit[adesso1][firstIndex]==0x0) continue;
2445
2446 for (Int_t adesso2=adesso1+1; adesso2<interestingCounter+1; adesso2++) {
2447 for (Int_t secondIndex=0; secondIndex<kMaxNumberOfDigitsPerVolume; secondIndex++) {
2448 if (selectedDigit[adesso2][secondIndex]==0x0) continue;
2449
2450 if (TMath::Abs(selectedDigit[adesso1][firstIndex]->GetTDC()-selectedDigit[adesso2][secondIndex]->GetTDC())>fMaxDeltaTime) continue;
2451
e885fb81 2452 AliDebug(1, Form(" %1d %1d (0x%x) %1d %1d (0x%x)", adesso1, firstIndex,selectedDigit[adesso1][firstIndex],
e3bd5504 2453 adesso2, secondIndex,selectedDigit[adesso2][secondIndex]));
2454
2455 interestingTOF[0] = selectedDigit[adesso1][firstIndex]->GetTDC();
2456 interestingTOT[0] = selectedDigit[adesso1][firstIndex]->GetTOT();
2457 interestingADC[0] = selectedDigit[adesso1][firstIndex]->GetADC();
2458 interestingWeight[0] = selectedDigit[adesso1][firstIndex]->GetWeight();
2459 Int_t vol1[5]; for(jj=0; jj<5; jj++) vol1[jj] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(jj);
e885fb81 2460 AliDebug(1,Form(" %2d %1d %2d %1d %2d", vol1[0], vol1[1], vol1[2], vol1[4], vol1[3]));
e3bd5504 2461 Int_t volDum = vol1[3];
2462 vol1[3] = vol1[4];
2463 vol1[4] = volDum;
e885fb81 2464 fTOFGeometry->GetPosPar(vol1,pos);
e3bd5504 2465 AliDebug(1,Form(" %f %f %f", pos[0], pos[1], pos[2]));
2466 interestingX[0] = pos[0];
2467 interestingY[0] = pos[1];
2468 interestingZ[0] = pos[2];
2469
2470 interestingTOF[1] = selectedDigit[adesso2][secondIndex]->GetTDC();
2471 interestingTOT[1] = selectedDigit[adesso2][secondIndex]->GetTOT();
2472 interestingADC[1] = selectedDigit[adesso2][secondIndex]->GetADC();
2473 interestingWeight[1] = selectedDigit[adesso2][secondIndex]->GetWeight();
2474 Int_t vol2[5]; for(jj=0; jj<5; jj++) vol2[jj] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(jj);
e885fb81 2475 AliDebug(1,Form(" %2d %1d %2d %1d %2d", vol2[0], vol2[1], vol2[2], vol2[4], vol2[3]));
e3bd5504 2476 volDum = vol2[3];
2477 vol2[3] = vol2[4];
2478 vol2[4] = volDum;
e885fb81 2479 fTOFGeometry->GetPosPar(vol2,pos);
e3bd5504 2480 AliDebug(1,Form(" %f %f %f", pos[0], pos[1], pos[2]));
2481 interestingX[1] = pos[0];
2482 interestingY[1] = pos[1];
2483 interestingZ[1] = pos[2];
2484
2485
2486 AverageCalculations(interestingCounter+1,
2487 interestingX, interestingY, interestingZ,
2488 interestingTOF, interestingTOT, interestingADC,
2489 interestingWeight,
2490 parTOF, posClus, check);
2491
2492 for (jj=0; jj<5; jj++) det[jj] = -1;
2493 for (jj=0; jj<3; jj++) posF[jj] = posClus[jj];
2494
2495 AliDebug(1,Form(" %f %f %f", posF[0], posF[1], posF[2]));
e885fb81 2496 fTOFGeometry->GetDetID(posF, det);
2497 AliDebug(1,Form(" %2d %1d %2d %1d %2d", det[0], det[1], det[2], det[3], det[4]));
e3bd5504 2498
e885fb81 2499 volIdClus = fTOFGeometry->GetAliSensVolIndex(det[0],det[1],det[2]);
2500 //volIdClus = GetClusterVolIndex(det);
e3bd5504 2501
2502 for (jj=3; jj<11; jj++) padsCluster[jj] = -1;
2503 padsCluster[3] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(4);
2504 padsCluster[4] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(3);
2505 padsCluster[5] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(4);
2506 padsCluster[6] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(3);
2507
2508 for (jj=0; jj<6; jj++) covClus[jj] = 0.;
2509 Int_t ** indDet = new Int_t*[interestingCounter+1];
2510 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj] = new Int_t [5];
2511 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj][0] = nSector;
2512 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj][1] = nPlate;
2513 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj][2] = nStrip;
2514 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj][3] = padsCluster[2*jj+3];
2515 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj][4] = padsCluster[2*jj+1+3];
e885fb81 2516 GetClusterPars(/*check,*/ interestingCounter+1, indDet, interestingWeight, posClus, covClus);
e3bd5504 2517 for (jj=0; jj<interestingCounter+1; jj++) delete [] indDet[jj];
2518
2519 // To fill the track index array
2520 dummyCounter=-1;
2521 for (jj=0; jj<kMaxNumberOfTracksPerDigit; jj++) tracks[jj] = -1;
2522 for (Int_t kk=0; kk<kMaxNumberOfTracksPerDigit; kk++) { // three is the max number of tracks associated to one digit
2523 if (selectedDigit[adesso1][firstIndex]->GetTrackLabel(kk)==-1) continue;
2524 else {
2525 dummyCounter++;
2526 tracks[dummyCounter] = selectedDigit[adesso1][firstIndex]->GetTrackLabel(kk);
2527 }
2528 }
2529 for (Int_t kk=0; kk<kMaxNumberOfTracksPerDigit; kk++) { // three is the max number of tracks associated to one digit
2530 if (selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk)==-1) continue;
2531 else {
2532
2533 alreadyStored = kFALSE;
2534 for (jj=0; jj<dummyCounter+1; jj++)
2535 alreadyStored = alreadyStored || (tracks[jj]!=-1 && tracks[jj]==selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk));
2536
2537 if (alreadyStored) continue;
2538 if (dummyCounter==2) { // three is the max number of tracks associated to one cluster
2539 AliWarning(" Siamo al limite!");
2540 continue;
2541 }
2542
2543 dummyCounter++;
2544 tracks[dummyCounter] = selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk);
2545
2546 }
2547
2548 }
2549
2550
2551 AliTOFcluster *tofCluster =
2552 new AliTOFcluster(volIdClus, posClus[0], posClus[1], posClus[2],
2553 covClus[0], covClus[1], covClus[2], covClus[3], covClus[4], covClus[5],
2554 tracks, det, parTOF, status, selectedDigit[adesso1][firstIndex]->GetIndex()); //to updated
2555 InsertCluster(tofCluster);
2556
e885fb81 2557 AliDebug(2, Form(" %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",
e3bd5504 2558 volIdClus, posClus[0], posClus[1], posClus[2],
2559 covClus[0], covClus[1], covClus[2], covClus[3], covClus[4], covClus[5],
2560 tracks[0], tracks[1], tracks[2],
2561 det[0], det[1], det[2], det[3], det[4],
2562 parTOF[0], parTOF[1], parTOF[2], parTOF[3], parTOF[4],
2563 status, selectedDigit[adesso1][firstIndex]->GetIndex()));
2564
2565 volDum = vol1[3];
2566 vol1[3] = vol1[4];
2567 vol1[4] = volDum;
2568 fTOFdigitMap->ResetDigitNumber(vol1,selectedDigit[adesso1][firstIndex]->GetIndex());
2569 volDum = vol2[3];
2570 vol2[3] = vol2[4];
2571 vol2[4] = volDum;
2572 fTOFdigitMap->ResetDigitNumber(vol2,selectedDigit[adesso2][secondIndex]->GetIndex());
2573
2574
2575 } // close loop on second digit
2576 } // close loop on adesso2
2577
2578 } // close loop on first digit
2579 } // close loop on adesso1
2580
2581
2582 break;
2583
2584 case 3:
2585
2586 for (Int_t adesso1=0; adesso1<interestingCounter+1; adesso1++) {
2587 for (Int_t firstIndex=0; firstIndex<kMaxNumberOfDigitsPerVolume; firstIndex++) {
2588 if (selectedDigit[adesso1][firstIndex]==0x0) continue;
2589
2590 for (Int_t adesso2=adesso1+1; adesso2<interestingCounter+1; adesso2++) {
2591 for (Int_t secondIndex=0; secondIndex<kMaxNumberOfDigitsPerVolume; secondIndex++) {
2592 if (selectedDigit[adesso2][secondIndex]==0x0) continue;
2593
2594 for (Int_t adesso3=adesso2+1; adesso3<interestingCounter+1; adesso3++) {
2595 for (Int_t thirdIndex=0; thirdIndex<kMaxNumberOfDigitsPerVolume; thirdIndex++) {
2596 if (selectedDigit[adesso3][thirdIndex]==0x0) continue;
2597
2598
2599 if (TMath::Abs(selectedDigit[adesso1][firstIndex]->GetTDC()-selectedDigit[adesso2][secondIndex]->GetTDC())>fMaxDeltaTime
2600 ||
2601 TMath::Abs(selectedDigit[adesso1][firstIndex]->GetTDC()-selectedDigit[adesso3][thirdIndex]->GetTDC())>fMaxDeltaTime
2602 ||
2603 TMath::Abs(selectedDigit[adesso2][secondIndex]->GetTDC()-selectedDigit[adesso3][thirdIndex]->GetTDC())>fMaxDeltaTime) continue;
2604
2605 interestingTOF[0] = selectedDigit[adesso1][firstIndex]->GetTDC();
2606 interestingTOT[0] = selectedDigit[adesso1][firstIndex]->GetTOT();
2607 interestingADC[0] = selectedDigit[adesso1][firstIndex]->GetADC();
2608 interestingWeight[0] = selectedDigit[adesso1][firstIndex]->GetWeight();
2609 Int_t vol1[5]; for(jj=0; jj<5; jj++) vol1[jj] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(jj);
e885fb81 2610 AliDebug(1,Form(" %2d %1d %2d %1d %2d", vol1[0], vol1[1], vol1[2], vol1[4], vol1[3]));
e3bd5504 2611 Int_t volDum = vol1[3];
2612 vol1[3] = vol1[4];
2613 vol1[4] = volDum;
e885fb81 2614 fTOFGeometry->GetPosPar(vol1,pos);
e3bd5504 2615 interestingX[0] = pos[0];
2616 interestingY[0] = pos[1];
2617 interestingZ[0] = pos[2];
2618
2619 interestingTOF[1] = selectedDigit[adesso2][secondIndex]->GetTDC();
2620 interestingTOT[1] = selectedDigit[adesso2][secondIndex]->GetTOT();
2621 interestingADC[1] = selectedDigit[adesso2][secondIndex]->GetADC();
2622 interestingWeight[1] = selectedDigit[adesso2][secondIndex]->GetWeight();
2623 Int_t vol2[5]; for(jj=0; jj<5; jj++) vol2[jj] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(jj);
e885fb81 2624 AliDebug(1,Form(" %2d %1d %2d %1d %2d", vol2[0], vol2[1], vol2[2], vol2[4], vol2[3]));
e3bd5504 2625 volDum = vol2[3];
2626 vol2[3] = vol2[4];
2627 vol2[4] = volDum;
e885fb81 2628 fTOFGeometry->GetPosPar(vol2,pos);
e3bd5504 2629 interestingX[1] = pos[0];
2630 interestingY[1] = pos[1];
2631 interestingZ[1] = pos[2];
2632
2633 interestingTOF[2] = selectedDigit[adesso3][thirdIndex]->GetTDC();
2634 interestingTOT[2] = selectedDigit[adesso3][thirdIndex]->GetTOT();
2635 interestingADC[2] = selectedDigit[adesso3][thirdIndex]->GetADC();
2636 interestingWeight[2] = selectedDigit[adesso3][thirdIndex]->GetWeight();
2637 Int_t vol3[5]; for(jj=0; jj<5; jj++) vol3[jj] = selectedDigit[adesso3][thirdIndex]->GetDetectorIndex(jj);
e885fb81 2638 AliDebug(1,Form(" %2d %1d %2d %1d %2d", vol3[0], vol3[1], vol3[2], vol3[4], vol3[3]));
e3bd5504 2639 volDum = vol3[3];
2640 vol3[3] = vol3[4];
2641 vol3[4] = volDum;
e885fb81 2642 fTOFGeometry->GetPosPar(vol3,pos);
e3bd5504 2643 interestingX[2] = pos[0];
2644 interestingY[2] = pos[1];
2645 interestingZ[2] = pos[2];
2646
2647
2648 AverageCalculations(interestingCounter+1,
2649 interestingX, interestingY, interestingZ,
2650 interestingTOF, interestingTOT, interestingADC,
2651 interestingWeight,
2652 parTOF, posClus, check);
2653
2654 for (jj=0; jj<5; jj++) det[jj] = -1;
2655 for (jj=0; jj<3; jj++) posF[jj] = posClus[jj];
e885fb81 2656 fTOFGeometry->GetDetID(posF, det);
e3bd5504 2657
e885fb81 2658 volIdClus = fTOFGeometry->GetAliSensVolIndex(det[0],det[1],det[2]);
2659 //volIdClus = GetClusterVolIndex(det);
e3bd5504 2660
2661 for (jj=3; jj<11; jj++) padsCluster[jj] = -1;
2662 padsCluster[3] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(4);
2663 padsCluster[4] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(3);
2664 padsCluster[5] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(4);
2665 padsCluster[6] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(3);
2666 padsCluster[7] = selectedDigit[adesso3][thirdIndex]->GetDetectorIndex(4);
2667 padsCluster[8] = selectedDigit[adesso3][thirdIndex]->GetDetectorIndex(3);
2668
2669 for (jj=0; jj<6; jj++) covClus[jj] = 0.;
2670 Int_t ** indDet = new Int_t*[interestingCounter+1];
2671 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj] = new Int_t [5];
2672 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj][0] = nSector;
2673 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj][1] = nPlate;
2674 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj][2] = nStrip;
2675 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj][3] = padsCluster[2*jj+3];
2676 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj][4] = padsCluster[2*jj+1+3];
e885fb81 2677 GetClusterPars(/*check,*/ interestingCounter+1, indDet, interestingWeight, posClus, covClus);
e3bd5504 2678 for (jj=0; jj<interestingCounter+1; jj++) delete [] indDet[jj];
2679
2680 // To fill the track index array
2681 dummyCounter=-1;
2682 for (jj=0; jj<kMaxNumberOfTracksPerDigit; jj++) tracks[jj] = -1;
2683 for (Int_t kk=0; kk<kMaxNumberOfTracksPerDigit; kk++) { // three is the max number of tracks associated to one digit
2684 if (selectedDigit[adesso1][firstIndex]->GetTrackLabel(kk)==-1) continue;
2685 else {
2686 dummyCounter++;
2687 tracks[dummyCounter] = selectedDigit[adesso1][firstIndex]->GetTrackLabel(kk);
2688 }
2689 }
2690 for (Int_t kk=0; kk<kMaxNumberOfTracksPerDigit; kk++) { // three is the max number of tracks associated to one digit
2691 if (selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk)==-1) continue;
2692 else {
2693
2694 alreadyStored = kFALSE;
2695 for (jj=0; jj<dummyCounter+1; jj++)
2696 alreadyStored = alreadyStored || (tracks[jj]!=-1 && tracks[jj]==selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk));
2697
2698 if (alreadyStored) continue;
2699 if (dummyCounter==2) { // three is the max number of tracks associated to one cluster
2700 AliWarning(" Siamo al limite!");
2701 continue;
2702 }
2703
2704 dummyCounter++;
2705 tracks[dummyCounter] = selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk);
2706
2707 }
2708
2709 }
2710 for (Int_t kk=0; kk<kMaxNumberOfTracksPerDigit; kk++) { // three is the max number of tracks associated to one digit
2711 if (selectedDigit[adesso3][thirdIndex]->GetTrackLabel(kk)==-1) continue;
2712 else {
2713
2714 alreadyStored = kFALSE;
2715 for (jj=0; jj<dummyCounter+1; jj++)
2716 alreadyStored = alreadyStored || (tracks[jj]!=-1 && tracks[jj]==selectedDigit[adesso3][thirdIndex]->GetTrackLabel(kk));
2717
2718 if (alreadyStored) continue;
2719 if (dummyCounter==2) { // three is the max number of tracks associated to one cluster
2720 AliWarning(" Siamo al limite!");
2721 continue;
2722 }
2723
2724 dummyCounter++;
2725 tracks[dummyCounter] = selectedDigit[adesso3][thirdIndex]->GetTrackLabel(kk);
2726
2727 }
2728
2729 }
2730
2731
2732 AliTOFcluster *tofCluster =
2733 new AliTOFcluster(volIdClus, posClus[0], posClus[1], posClus[2],
2734 covClus[0], covClus[1], covClus[2], covClus[3], covClus[4], covClus[5],
2735 tracks, det, parTOF, status, selectedDigit[adesso1][firstIndex]->GetIndex()); // to be updated
2736 InsertCluster(tofCluster);
2737
e885fb81 2738 AliDebug(2, Form(" %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",
e3bd5504 2739 volIdClus, posClus[0], posClus[1], posClus[2],
2740 covClus[0], covClus[1], covClus[2], covClus[3], covClus[4], covClus[5],
2741 tracks[0], tracks[1], tracks[2],
2742 det[0], det[1], det[2], det[3], det[4],
2743 parTOF[0], parTOF[1], parTOF[2], parTOF[3], parTOF[4],
2744 status, selectedDigit[adesso1][firstIndex]->GetIndex()));
2745
2746 volDum = vol1[3];
2747 vol1[3] = vol1[4];
2748 vol1[4] = volDum;
2749 fTOFdigitMap->ResetDigitNumber(vol1,selectedDigit[adesso1][firstIndex]->GetIndex());
2750 volDum = vol2[3];
2751 vol2[3] = vol2[4];
2752 vol2[4] = volDum;
2753 fTOFdigitMap->ResetDigitNumber(vol2,selectedDigit[adesso2][secondIndex]->GetIndex());
2754 volDum = vol3[3];
2755 vol3[3] = vol3[4];
2756 vol3[4] = volDum;
2757 fTOFdigitMap->ResetDigitNumber(vol3,selectedDigit[adesso3][thirdIndex]->GetIndex());
2758
2759
2760 } // close loop on third digit
2761 } // close loop on adesso3
2762
2763 } // close loop on second digit
2764 } // close loop on adesso2
2765
2766 } // close loop on first digit
2767 } // close loop on adesso1
2768
2769
2770 break;
2771
2772 case 4:
2773
2774 Int_t adesso1 = 0;
2775 for (Int_t firstIndex=0; firstIndex<kMaxNumberOfDigitsPerVolume; firstIndex++) {
2776 if (selectedDigit[adesso1][firstIndex]==0x0) continue;
2777
2778 Int_t adesso2 = 1;
2779 for (Int_t secondIndex=0; secondIndex<kMaxNumberOfDigitsPerVolume; secondIndex++) {
2780 if (selectedDigit[adesso2][secondIndex]==0x0) continue;
2781
2782 Int_t adesso3 = 2;
2783 for (Int_t thirdIndex=0; thirdIndex<kMaxNumberOfDigitsPerVolume; thirdIndex++) {
2784 if (selectedDigit[adesso3][thirdIndex]==0x0) continue;
2785
2786 Int_t adesso4 = 3;
2787 for (Int_t fourthIndex=0; fourthIndex<kMaxNumberOfDigitsPerVolume; fourthIndex++) {
2788 if (selectedDigit[adesso4][fourthIndex]==0x0) continue;
2789
2790
2791 if (TMath::Abs(selectedDigit[adesso1][firstIndex]->GetTDC()-selectedDigit[adesso2][secondIndex]->GetTDC())>fMaxDeltaTime
2792 ||
2793 TMath::Abs(selectedDigit[adesso1][firstIndex]->GetTDC()-selectedDigit[adesso3][thirdIndex]->GetTDC())>fMaxDeltaTime
2794 ||
2795 TMath::Abs(selectedDigit[adesso1][firstIndex]->GetTDC()-selectedDigit[adesso4][fourthIndex]->GetTDC())>fMaxDeltaTime
2796 ||
2797 TMath::Abs(selectedDigit[adesso2][secondIndex]->GetTDC()-selectedDigit[adesso3][thirdIndex]->GetTDC())>fMaxDeltaTime
2798 ||
2799 TMath::Abs(selectedDigit[adesso2][secondIndex]->GetTDC()-selectedDigit[adesso4][fourthIndex]->GetTDC())>fMaxDeltaTime
2800 ||
2801 TMath::Abs(selectedDigit[adesso3][thirdIndex]->GetTDC()-selectedDigit[adesso4][fourthIndex]->GetTDC())>fMaxDeltaTime) continue;
2802
2803 interestingTOF[0] = selectedDigit[adesso1][firstIndex]->GetTDC();
2804 interestingTOT[0] = selectedDigit[adesso1][firstIndex]->GetTOT();
2805 interestingADC[0] = selectedDigit[adesso1][firstIndex]->GetADC();
2806 interestingWeight[0] = selectedDigit[adesso1][firstIndex]->GetWeight();
2807 Int_t vol1[5]; for(jj=0; jj<5; jj++) vol1[jj] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(jj);
e885fb81 2808 AliDebug(1,Form(" %2d %1d %2d %1d %2d", vol1[0], vol1[1], vol1[2], vol1[4], vol1[3]));
e3bd5504 2809 Int_t volDum = vol1[3];
2810 vol1[3] = vol1[4];
2811 vol1[4] = volDum;
e885fb81 2812 fTOFGeometry->GetPosPar(vol1,pos);
e3bd5504 2813 interestingX[0] = pos[0];
2814 interestingY[0] = pos[1];
2815 interestingZ[0] = pos[2];
2816
2817 interestingTOF[1] = selectedDigit[adesso2][secondIndex]->GetTDC();
2818 interestingTOT[1] = selectedDigit[adesso2][secondIndex]->GetTOT();
2819 interestingADC[1] = selectedDigit[adesso2][secondIndex]->GetADC();
2820 interestingWeight[1] = selectedDigit[adesso2][secondIndex]->GetWeight();
2821 Int_t vol2[5]; for(jj=0; jj<5; jj++) vol2[jj] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(jj);
e885fb81 2822 AliDebug(1,Form(" %2d %1d %2d %1d %2d", vol2[0], vol2[1], vol2[2], vol2[4], vol2[3]));
e3bd5504 2823 volDum = vol2[3];
2824 vol2[3] = vol2[4];
2825 vol2[4] = volDum;
e885fb81 2826 fTOFGeometry->GetPosPar(vol2,pos);
e3bd5504 2827 interestingX[1] = pos[0];
2828 interestingY[1] = pos[1];
2829 interestingZ[1] = pos[2];
2830
2831 interestingTOF[2] = selectedDigit[adesso3][thirdIndex]->GetTDC();
2832 interestingTOT[2] = selectedDigit[adesso3][thirdIndex]->GetTOT();
2833 interestingADC[2] = selectedDigit[adesso3][thirdIndex]->GetADC();
2834 interestingWeight[2] = selectedDigit[adesso3][thirdIndex]->GetWeight();
2835 Int_t vol3[5]; for(jj=0; jj<5; jj++) vol3[jj] = selectedDigit[adesso3][thirdIndex]->GetDetectorIndex(jj);
e885fb81 2836 AliDebug(1,Form(" %2d %1d %2d %1d %2d", vol3[0], vol3[1], vol3[2], vol3[4], vol3[3]));
e3bd5504 2837 volDum = vol3[3];
2838 vol3[3] = vol3[4];
2839 vol3[4] = volDum;
e885fb81 2840 fTOFGeometry->GetPosPar(vol3,pos);
e3bd5504 2841 interestingX[2] = pos[0];
2842 interestingY[2] = pos[1];
2843 interestingZ[2] = pos[2];
2844
2845 interestingTOF[3] = selectedDigit[adesso4][fourthIndex]->GetTDC();
2846 interestingTOT[3] = selectedDigit[adesso4][fourthIndex]->GetTOT();
2847 interestingADC[3] = selectedDigit[adesso4][fourthIndex]->GetADC();
2848 interestingWeight[3] = selectedDigit[adesso4][fourthIndex]->GetWeight();
2849 Int_t vol4[5]; for(jj=0; jj<5; jj++) vol4[jj] = selectedDigit[adesso4][fourthIndex]->GetDetectorIndex(jj);
e885fb81 2850 AliDebug(1,Form(" %2d %1d %2d %1d %2d", vol4[0], vol4[1], vol4[2], vol4[4], vol4[3]));
e3bd5504 2851 volDum = vol4[3];
2852 vol4[3] = vol4[4];
2853 vol4[4] = volDum;
e885fb81 2854 fTOFGeometry->GetPosPar(vol4,pos);
e3bd5504 2855 interestingX[3] = pos[0];
2856 interestingY[3] = pos[1];
2857 interestingZ[3] = pos[2];
2858
2859
2860 AverageCalculations(interestingCounter+1,
2861 interestingX, interestingY, interestingZ,
2862 interestingTOF, interestingTOT, interestingADC,
2863 interestingWeight,
2864 parTOF, posClus, check);
2865
2866 for (jj=0; jj<5; jj++) det[jj] = -1;
2867 for (jj=0; jj<3; jj++) posF[jj] = posClus[jj];
e885fb81 2868 fTOFGeometry->GetDetID(posF, det);
e3bd5504 2869
e885fb81 2870 volIdClus = fTOFGeometry->GetAliSensVolIndex(det[0],det[1],det[2]);
2871 //volIdClus = GetClusterVolIndex(det);
e3bd5504 2872
2873 for (jj=3; jj<11; jj++) padsCluster[jj] = -1;
2874 padsCluster[3] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(4);
2875 padsCluster[4] = selectedDigit[adesso1][firstIndex]->GetDetectorIndex(3);
2876 padsCluster[5] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(4);
2877 padsCluster[6] = selectedDigit[adesso2][secondIndex]->GetDetectorIndex(3);
2878 padsCluster[7] = selectedDigit[adesso3][thirdIndex]->GetDetectorIndex(4);
2879 padsCluster[8] = selectedDigit[adesso3][thirdIndex]->GetDetectorIndex(3);
2880 padsCluster[9] = selectedDigit[adesso4][fourthIndex]->GetDetectorIndex(4);
2881 padsCluster[10] = selectedDigit[adesso4][fourthIndex]->GetDetectorIndex(3);
2882
2883 for (jj=0; jj<6; jj++) covClus[jj] = 0.;
2884 Int_t ** indDet = new Int_t*[interestingCounter+1];
2885 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj] = new Int_t [5];
2886 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj][0] = nSector;
2887 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj][1] = nPlate;
2888 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj][2] = nStrip;
2889 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj][3] = padsCluster[2*jj+3];
2890 for (jj=0; jj<interestingCounter+1; jj++) indDet[jj][4] = padsCluster[2*jj+1+3];
e885fb81 2891 GetClusterPars(/*check,*/ interestingCounter+1, indDet, interestingWeight, posClus, covClus);
e3bd5504 2892 for (jj=0; jj<interestingCounter+1; jj++) delete [] indDet[jj];
2893
2894 // To fill the track index array
2895 dummyCounter=-1;
2896 for (jj=0; jj<kMaxNumberOfTracksPerDigit; jj++) tracks[jj] = -1;
2897 for (Int_t kk=0; kk<kMaxNumberOfTracksPerDigit; kk++) { // three is the max number of tracks associated to one digit
2898 if (selectedDigit[adesso1][firstIndex]->GetTrackLabel(kk)==-1) continue;
2899 else {
2900 dummyCounter++;
2901 tracks[dummyCounter] = selectedDigit[adesso1][firstIndex]->GetTrackLabel(kk);
2902 }
2903 }
2904 for (Int_t kk=0; kk<kMaxNumberOfTracksPerDigit; kk++) { // three is the max number of tracks associated to one digit
2905 if (selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk)==-1) continue;
2906 else {
2907
2908 alreadyStored = kFALSE;
2909 for (jj=0; jj<dummyCounter+1; jj++)
2910 alreadyStored = alreadyStored || (tracks[jj]!=-1 && tracks[jj]==selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk));
2911
2912 if (alreadyStored) continue;
2913 if (dummyCounter==2) { // three is the max number of tracks associated to one cluster
2914 AliWarning(" Siamo al limite!");
2915 continue;
2916 }
2917
2918 dummyCounter++;
2919 tracks[dummyCounter] = selectedDigit[adesso2][secondIndex]->GetTrackLabel(kk);
2920
2921 }
2922
2923 }
2924 for (Int_t kk=0; kk<kMaxNumberOfTracksPerDigit; kk++) { // three is the max number of tracks associated to one digit
2925 if (selectedDigit[adesso3][thirdIndex]->GetTrackLabel(kk)==-1) continue;
2926 else {
2927
2928 alreadyStored = kFALSE;
2929 for (jj=0; jj<dummyCounter+1; jj++)
2930 alreadyStored = alreadyStored || (tracks[jj]!=-1 && tracks[jj]==selectedDigit[adesso3][thirdIndex]->GetTrackLabel(kk));
2931
2932 if (alreadyStored) continue;
2933 if (dummyCounter==2) { // three is the max number of tracks associated to one cluster
2934 AliWarning(" Siamo al limite!");
2935 continue;
2936 }
2937
2938 dummyCounter++;
2939 tracks[dummyCounter] = selectedDigit[adesso3][thirdIndex]->GetTrackLabel(kk);
2940
2941 }
2942
2943 }
2944 for (Int_t kk=0; kk<kMaxNumberOfTracksPerDigit; kk++) { // three is the max number of tracks associated to one digit
2945 if (selectedDigit[adesso4][fourthIndex]->GetTrackLabel(kk)==-1) continue;
2946 else {
2947
2948 alreadyStored = kFALSE;
2949 for (jj=0; jj<dummyCounter+1; jj++)
2950 alreadyStored = alreadyStored || (tracks[jj]!=-1 && tracks[jj]==selectedDigit[adesso4][fourthIndex]->GetTrackLabel(kk));
2951
2952 if (alreadyStored) continue;
2953 if (dummyCounter==2) { // three is the max number of tracks associated to one cluster
2954 AliWarning(" Siamo al limite!");
2955 continue;
2956 }
2957
2958 dummyCounter++;
2959 tracks[dummyCounter] = selectedDigit[adesso4][fourthIndex]->GetTrackLabel(kk);
2960
2961 }
2962
2963 }
2964
2965
2966 AliTOFcluster *tofCluster =
2967 new AliTOFcluster(volIdClus, posClus[0], posClus[1], posClus[2],
2968 covClus[0], covClus[1], covClus[2], covClus[3], covClus[4], covClus[5],
2969 tracks, det, parTOF, status, selectedDigit[adesso1][firstIndex]->GetIndex()); // to be updated
2970 InsertCluster(tofCluster);
2971
e885fb81 2972 AliDebug(2, Form(" %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",
e3bd5504 2973 volIdClus, posClus[0], posClus[1], posClus[2],
2974 covClus[0], covClus[1], covClus[2], covClus[3], covClus[4], covClus[5],
2975 tracks[0], tracks[1], tracks[2],
2976 det[0], det[1], det[2], det[3], det[4],
2977 parTOF[0], parTOF[1], parTOF[2], parTOF[3], parTOF[4],
2978 status, selectedDigit[adesso1][firstIndex]->GetIndex()));
2979
2980 volDum = vol1[3];
2981 vol1[3] = vol1[4];
2982 vol1[4] = volDum;
2983 fTOFdigitMap->ResetDigitNumber(vol1,selectedDigit[adesso1][firstIndex]->GetIndex());
2984 volDum = vol2[3];
2985 vol2[3] = vol2[4];
2986 vol2[4] = volDum;
2987 fTOFdigitMap->ResetDigitNumber(vol2,selectedDigit[adesso2][secondIndex]->GetIndex());
2988 volDum = vol3[3];
2989 vol3[3] = vol3[4];
2990 vol3[4] = volDum;
2991 fTOFdigitMap->ResetDigitNumber(vol3,selectedDigit[adesso3][thirdIndex]->GetIndex());
2992 volDum = vol4[3];
2993 vol4[3] = vol4[4];
2994 vol4[4] = volDum;
2995 fTOFdigitMap->ResetDigitNumber(vol4,selectedDigit[adesso4][fourthIndex]->GetIndex());
2996
2997
2998 } // close loop on fourth digit
2999
3000 } // close loop on third digit
3001
3002 } // close loop on second digit
3003
3004 } // close loop on first digit
3005
3006 break;
3007
3008 }
3009
3010 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
3011 for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++)
3012 selectedDigit[ii][jj] = 0x0;
3013
3014 } // loop on iPad
3015
3016 for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
3017 for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++) {
3018 delete selectedDigit[ii][jj];
3019 selectedDigit[ii][jj] = 0x0;
3020 }
3021
3022}
3023//_____________________________________________________________________________
3024
3025Int_t AliTOFClusterFinderV1::InsertCluster(AliTOFcluster *tofCluster)
3026{
3027 //
3028 // This function adds a TOF cluster to the array of TOF clusters
3029 // sorted in Z, i.e. fTofClusters
3030 //
3031
3032 if (fNumberOfTofClusters==kTofMaxCluster) {
3033 AliError("Too many clusters !");
3034 return 1;
3035 }
3036
3037 if (fNumberOfTofClusters==0) {
3038 fTofClusters[fNumberOfTofClusters++] = tofCluster;
3039 return 0;
3040 }
3041
3042 Int_t ii = FindClusterIndex(tofCluster->GetZ());
3043 memmove(fTofClusters+ii+1 ,fTofClusters+ii,(fNumberOfTofClusters-ii)*sizeof(AliTOFcluster*));
3044 fTofClusters[ii] = tofCluster;
3045 fNumberOfTofClusters++;
3046
3047 return 0;
3048
3049}
3050//_____________________________________________________________________________
3051
3052Int_t AliTOFClusterFinderV1::FindClusterIndex(Double_t z) const
3053{
3054 //
3055 // This function returns the index of the nearest cluster in z
3056 //
3057
3058 if (fNumberOfTofClusters==0) return 0;
3059 if (z <= fTofClusters[0]->GetZ()) return 0;
3060 if (z > fTofClusters[fNumberOfTofClusters-1]->GetZ()) return fNumberOfTofClusters;
3061 Int_t b = 0, e = fNumberOfTofClusters-1, m = (b+e)/2;
3062 for (; b<e; m=(b+e)/2) {
3063 if (z > fTofClusters[m]->GetZ()) b=m+1;
3064 else e=m;
3065 }
3066
3067 return m;
3068
3069}
3070//_____________________________________________________________________________
3071
3072void AliTOFClusterFinderV1::ResetRecpoint()
3073{
3074 //
3075 // Clear the list of reconstructed points
3076 //
3077
3078 fNumberOfTofClusters = 0;
3079 if (fRecPoints) fRecPoints->Clear();
3080
3081}
3082//_____________________________________________________________________________
3083
3084void AliTOFClusterFinderV1::ResetDigits()
3085{
3086 //
3087 // Clear the list of digits
3088 //
3089
3090 fNumberOfTofDigits = 0;
3091 if (fDigits) fDigits->Clear();
3092
3093}
3094//_____________________________________________________________________________
e885fb81 3095//UShort_t AliTOFClusterFinderV1::GetClusterVolIndex(Int_t *ind) const
3096//{
e3bd5504 3097 //
3098 // Get the volume ID to retrieve the l2t transformation
3099 //
3100
3101 // Detector numbering scheme
e885fb81 3102/*
e3bd5504 3103 Int_t nSector = AliTOFGeometry::NSectors();
3104 Int_t nPlate = AliTOFGeometry::NPlates();
3105 Int_t nStripA = AliTOFGeometry::NStripA();
3106 Int_t nStripB = AliTOFGeometry::NStripB();
3107 Int_t nStripC = AliTOFGeometry::NStripC();
3108
3109 Int_t isector =ind[0];
3110 if (isector >= nSector)
3111 AliError(Form("Wrong sector number in TOF (%d) !", isector));
3112 Int_t iplate = ind[1];
3113 if (iplate >= nPlate)
3114 AliError(Form("Wrong plate number in TOF (%d) !", iplate));
3115 Int_t istrip = ind[2];
3116
3117 Int_t stripOffset = 0;
3118 switch (iplate) {
3119 case 0:
3120 stripOffset = 0;
3121 break;
3122 case 1:
3123 stripOffset = nStripC;
3124 break;
3125 case 2:
3126 stripOffset = nStripC+nStripB;
3127 break;
3128 case 3:
3129 stripOffset = nStripC+nStripB+nStripA;
3130 break;
3131 case 4:
3132 stripOffset = nStripC+nStripB+nStripA+nStripB;
3133 break;
3134 default:
3135 AliError(Form("Wrong plate number in TOF (%d) !", iplate));
3136 break;
3137 };
3138
3139 Int_t index= (2*(nStripC+nStripB)+nStripA)*isector +
3140 stripOffset +
3141 istrip;
3142
3143 UShort_t volIndex = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF, index);
3144 return volIndex;
3145
3146}
e885fb81 3147*/
e3bd5504 3148//_____________________________________________________________________________
3149
3150void AliTOFClusterFinderV1::GetClusterPars(Int_t *ind, Double_t* pos, Double_t* cov) const
3151{
3152 //
3153 // Starting from the volume indices (ind[5]), for a cluster coming from
3154 // a isolated digits, this function returns:
3155 // the cluster position (pos),
3156 // the cluster covariance matrix elements (cov)
3157 //
3158
3159 //
3160 //we now go in the system of the strip: determine the local coordinates
3161 //
3162 //
3163 // 47---------------------------------------------------0 ^ z
3164 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 1 |
3165 // ----------------------------------------------------- | y going outwards
3166 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 0 | par[0]=0;
3167
3168 // ----------------------------------------------------- |
3169 // x <-----------------------------------------------------
3170
3171 //move to the tracking ref system
3172 Double_t lpos[3] = { (ind[4]-23.5)*AliTOFGeometry::XPad(),
3173 0.,
3174 (ind[3]- 0.5)*AliTOFGeometry::ZPad() };
3175 AliDebug(1, Form(" %f %f %f", lpos[0], lpos[1], lpos[2]));
3176
3177 // Volume ID
e885fb81 3178 UShort_t volIndex = fTOFGeometry->GetAliSensVolIndex(ind[0],ind[1],ind[2]);
3179 //UShort_t volIndex = GetClusterVolIndex(ind);
e3bd5504 3180 const TGeoHMatrix *l2t = AliGeomManager::GetTracking2LocalMatrix(volIndex);
3181
3182 // Get the position in the track ref system
3183 Double_t tpos[3];
3184 l2t->MasterToLocal(lpos,tpos);
3185 pos[0] = tpos[0];
3186 pos[1] = tpos[1];
3187 pos[2] = tpos[2];
3188
3189 //Get the cluster covariance in the track ref system
3190 Double_t lcov[9];
3191 for (Int_t ii=0; ii<9; ii++) lcov[ii] = 0.;
3192
3193 //cluster covariance in the local system:
3194 // sx2 0 0
3195 // 0 0 0
3196 // 0 0 sz2
3197 /*
3198 lcov[4] = 0.42*0.42/3.;
3199 // = ( 5*0.025 (gas gaps thikness)
3200 // + 4*0.040 (internal glasses thickness)
3201 // + 0.5*0.160 (internl PCB)
3202 // + 1*0.055 (external red glass))
3203 */
e885fb81 3204
e3bd5504 3205 lcov[0] = 0.499678;//AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
3206 lcov[8] = 0.992429;//AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
3207
3208 //cluster covariance in the tracking system:
3209 TGeoHMatrix m;
3210 m.SetRotation(lcov);
3211 m.Multiply(l2t);
3212 m.MultiplyLeft(&l2t->Inverse());
3213 Double_t *tcov = m.GetRotationMatrix();
3214 cov[0] = tcov[0]; cov[1] = tcov[1]; cov[2] = tcov[2];
3215 cov[3] = tcov[4]; cov[4] = tcov[5]; cov[5] = tcov[8];
3216
3217 return;
3218
3219}
3220//_____________________________________________________________________________
3221
e885fb81 3222void AliTOFClusterFinderV1::GetClusterPars(/*Bool_t check,*/ Int_t counter,
e3bd5504 3223 Int_t **ind, Double_t *weight,
3224 Double_t *pos, Double_t *cov) const
3225{
3226 //
3227 // Starting from:
3228 // the volumes indices (ind[counter][5]), for a
3229 // cluster coming from a collection of 'counter'
3230 // digits,
3231 // the volumes weights (weight[counter]), -controlled
3232 // by the 'check' variable control-, for a cluster
3233 // coming from a collection of 'counter' digits,
3234 // the cluster position (pos),
3235 // this function returns:
3236 // the covariance matrix elements (cov) for the found cluster
3237 //
3238
3239 //
3240 // we now go in the system of the strip: determine the local coordinates
3241 //
3242 // 47---------------------------------------------------0 ^ z
3243 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 1 |
3244 // ----------------------------------------------------- | y going outwards
3245 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 0 | par[0]=0;
3246
3247 // ----------------------------------------------------- |
3248 // x <-----------------------------------------------------
3249
3250 for (Int_t ii=0; ii<counter; ii++)
e885fb81 3251 AliDebug(1, Form(" %2d %2d %1d %2d %1d %2d ",
e3bd5504 3252 ii, ind[ii][0], ind[ii][1], ind[ii][2], ind[ii][3], ind[ii][4]));
3253
3254 Float_t posF[3]; for (Int_t ii=0; ii<3; ii++) posF[ii] = (Float_t)pos[ii];
3255 AliDebug(1, Form(" %f %f %f", pos[0], pos[1], pos[2]));
e885fb81 3256
e3bd5504 3257 Int_t detClus[5] = {-1, -1, -1, -1, -1};
e885fb81 3258 fTOFGeometry->GetDetID(posF, detClus);
e3bd5504 3259
3260 // Volume ID
e885fb81 3261 UShort_t volIndex = fTOFGeometry->GetAliSensVolIndex(detClus[0],detClus[1],detClus[2]);
3262 //UShort_t volIndex = GetClusterVolIndex(detClus);
3263 AliDebug(1, Form(" %2d %1d %2d %1d %2d %7i",
e3bd5504 3264 detClus[0], detClus[1], detClus[2], detClus[3], detClus[4], volIndex));
3265
3266 // Get the position in the TOF strip ref system
3267 const TGeoHMatrix *alice2strip = AliGeomManager::GetOrigGlobalMatrix(volIndex);
3268 Double_t ppos[3] = {-1, -1, -1};
3269 alice2strip->MasterToLocal(pos,ppos);
3270 AliDebug(1, Form(" %f %f %f", ppos[0], ppos[1], ppos[2]));
3271
3272
3273 // Get the position in the tracking ref system
3274 const TGeoHMatrix *g2l = AliGeomManager::GetTracking2LocalMatrix(volIndex);
3275 Double_t lpos[3] = {-1, -1, -1};
3276 g2l->MasterToLocal(ppos,lpos);
3277 AliDebug(1, Form(" %f %f %f", lpos[0], lpos[1], lpos[2]));
3278 for (Int_t ii=0; ii<3; ii++) pos[ii] = lpos[ii];
3279
3280 //Get the cluster covariance in the track ref system
3281 Double_t lcov[9];
3282 for (Int_t ii=0; ii<9; ii++) lcov[ii] = 0.;
3283
3284 //cluster covariance in the local system:
3285 // sx2 0 0
3286 // 0 0 0
3287 // 0 0 sz2
3288
3289 // Evaluation of the ovariance matrix elements
e885fb81 3290 TOFclusterError(/*check,*/ counter, ind, weight, ppos, lcov);
e3bd5504 3291
3292 AliDebug(1, Form("lcov[0] = %f, lcov[8] = %f", lcov[0], lcov[8]));
3293
3294 //cluster covariance in the tracking system:
3295 TGeoHMatrix m;
3296 m.SetRotation(lcov);
3297 m.Multiply(g2l);
3298 m.MultiplyLeft(&g2l->Inverse());
3299 Double_t *tcov = m.GetRotationMatrix();
3300 cov[0] = tcov[0]; cov[1] = tcov[1]; cov[2] = tcov[2];
3301 cov[3] = tcov[4]; cov[4] = tcov[5]; cov[5] = tcov[8];
3302
3303 return;
3304
3305}
3306//_____________________________________________________________________________
3307
e885fb81 3308void AliTOFClusterFinderV1::TOFclusterError(/*Bool_t check,*/ Int_t counter,
e3bd5504 3309 Int_t **ind, Double_t *weight,
3310 Double_t ppos[], Double_t lcov[]) const
3311{
3312 //
3313 //
3314 //
3315
e885fb81 3316 //lcov[4] = 0.42*0.42/3.; // cm2
e3bd5504 3317 // = ( 5*0.025 (gas gaps thikness)
3318 // + 4*0.040 (internal glasses thickness)
3319 // + 0.5*0.160 (internl PCB)
3320 // + 1*0.055 (external red glass))
3321
3322
3323 Float_t *delta2X = new Float_t[counter];
3324 for (Int_t ii=0; ii<counter; ii++)
3325 delta2X[ii] =
3326 ((ind[ii][4]-23.5)*AliTOFGeometry::XPad() - ppos[0])*((ind[ii][4]-23.5)*AliTOFGeometry::XPad() - ppos[0]);
3327
3328 Float_t *delta2Z = new Float_t[counter];
3329 for (Int_t ii=0; ii<counter; ii++)
3330 delta2Z[ii] =
3331 ((ind[ii][3]- 0.5)*AliTOFGeometry::ZPad() - ppos[2])*((ind[ii][3]- 0.5)*AliTOFGeometry::ZPad() - ppos[2]);
3332
3333 for (Int_t ii=0; ii<counter; ii++)