Unused variable i removed
[u/mrichter/AliRoot.git] / PMD / AliPMDClusterFinder.cxx
CommitLineData
ed228cbc 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
01709453 16//-----------------------------------------------------//
17// //
18// Date : August 05 2003 //
19// This reads the file PMD.digits.root(TreeD), //
20// calls the Clustering algorithm and stores the //
21// clustering output in PMD.RecPoints.root(TreeR) //
22// //
23//-----------------------------------------------------//
24
25#include <Riostream.h>
01709453 26#include <TTree.h>
01709453 27#include <TObjArray.h>
28#include <TClonesArray.h>
01709453 29
7e9508a7 30#include "AliLog.h"
01709453 31#include "AliRunLoader.h"
32#include "AliLoader.h"
5f55af10 33#include "AliRawReader.h"
01709453 34
35#include "AliPMDdigit.h"
36#include "AliPMDClusterFinder.h"
37#include "AliPMDClustering.h"
5c5cadd5 38#include "AliPMDClusteringV1.h"
01709453 39#include "AliPMDcluster.h"
96377d57 40#include "AliPMDrecpoint1.h"
5c5cadd5 41#include "AliPMDrechit.h"
5f55af10 42#include "AliPMDRawStream.h"
09a06455 43#include "AliPMDCalibData.h"
df42ab21 44#include "AliPMDddldata.h"
09a06455 45
2332574a 46#include "AliDAQ.h"
09a06455 47#include "AliCDBManager.h"
48#include "AliCDBEntry.h"
01709453 49
7e9508a7 50
51
01709453 52ClassImp(AliPMDClusterFinder)
b208c6a3 53
7e9508a7 54AliPMDClusterFinder::AliPMDClusterFinder():
55 fRunLoader(0),
56 fPMDLoader(0),
a48edddd 57 fCalibData(GetCalibData()),
7e9508a7 58 fTreeD(0),
59 fTreeR(0),
60 fDigits(new TClonesArray("AliPMDdigit", 1000)),
61 fRecpoints(new TClonesArray("AliPMDrecpoint1", 1000)),
5c5cadd5 62 fRechits(new TClonesArray("AliPMDrechit", 1000)),
7e9508a7 63 fNpoint(0),
5c5cadd5 64 fNhit(0),
a48edddd 65 fDetNo(0),
7e9508a7 66 fEcut(0.)
67{
68//
69// Constructor
70//
71}
72// ------------------------------------------------------------------------- //
dfaeee5f 73AliPMDClusterFinder::AliPMDClusterFinder(AliRunLoader* runLoader):
74 fRunLoader(runLoader),
75 fPMDLoader(runLoader->GetLoader("PMDLoader")),
a48edddd 76 fCalibData(GetCalibData()),
1758e4fe 77 fTreeD(0),
78 fTreeR(0),
ebd83c56 79 fDigits(new TClonesArray("AliPMDdigit", 1000)),
1758e4fe 80 fRecpoints(new TClonesArray("AliPMDrecpoint1", 1000)),
5c5cadd5 81 fRechits(new TClonesArray("AliPMDrechit", 1000)),
1758e4fe 82 fNpoint(0),
5c5cadd5 83 fNhit(0),
a48edddd 84 fDetNo(0),
1758e4fe 85 fEcut(0.)
01709453 86{
b208c6a3 87//
dfaeee5f 88// Constructor
b208c6a3 89//
a48edddd 90}
91// ------------------------------------------------------------------------- //
2332574a 92AliPMDClusterFinder::AliPMDClusterFinder(const AliPMDClusterFinder & finder):
93 TObject(finder),
94 fRunLoader(0),
95 fPMDLoader(0),
96 fCalibData(GetCalibData()),
97 fTreeD(0),
98 fTreeR(0),
99 fDigits(NULL),
100 fRecpoints(NULL),
101 fRechits(NULL),
102 fNpoint(0),
103 fNhit(0),
104 fDetNo(0),
105 fEcut(0.)
a48edddd 106{
107 // copy constructor
108 AliError("Copy constructor not allowed");
109}
110// ------------------------------------------------------------------------- //
111AliPMDClusterFinder &AliPMDClusterFinder::operator=(const AliPMDClusterFinder & /*finder*/)
112{
113 // assignment op
114 AliError("Assignment Operator not allowed");
115 return *this;
01709453 116}
1758e4fe 117// ------------------------------------------------------------------------- //
01709453 118AliPMDClusterFinder::~AliPMDClusterFinder()
119{
b208c6a3 120 // Destructor
ebd83c56 121 if (fDigits)
122 {
123 fDigits->Delete();
124 delete fDigits;
125 fDigits=0;
126 }
1758e4fe 127 if (fRecpoints)
128 {
129 fRecpoints->Delete();
130 delete fRecpoints;
131 fRecpoints=0;
132 }
5c5cadd5 133 if (fRechits)
134 {
135 fRechits->Delete();
136 delete fRechits;
137 fRechits=0;
138 }
01709453 139}
1758e4fe 140// ------------------------------------------------------------------------- //
b208c6a3 141
01709453 142void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt)
143{
b208c6a3 144 // Converts digits to recpoints after running clustering
145 // algorithm on CPV plane and PREshower plane
146 //
2332574a 147
ed228cbc 148 Int_t det = 0,smn = 0;
01709453 149 Int_t xpos,ypos;
150 Float_t adc;
1758e4fe 151 Int_t ismn;
01709453 152 Int_t idet;
5c5cadd5 153 Float_t clusdata[6];
ed228cbc 154
155 TObjArray *pmdcont = new TObjArray();
5c5cadd5 156 AliPMDClustering *pmdclust = new AliPMDClusteringV1();
7e9508a7 157
ed228cbc 158 pmdclust->SetEdepCut(fEcut);
01709453 159
160 fRunLoader->GetEvent(ievt);
7e9508a7 161
01b56f5c 162
b208c6a3 163 fTreeD = fPMDLoader->TreeD();
164 if (fTreeD == 0x0)
01709453 165 {
7e9508a7 166 AliFatal("AliPMDClusterFinder: Can not get TreeD");
167
01709453 168 }
169 AliPMDdigit *pmddigit;
b208c6a3 170 TBranch *branch = fTreeD->GetBranch("PMDDigit");
01709453 171 branch->SetAddress(&fDigits);
172
173 ResetRecpoint();
01b56f5c 174
b208c6a3 175 fTreeR = fPMDLoader->TreeR();
176 if (fTreeR == 0x0)
01709453 177 {
b208c6a3 178 fPMDLoader->MakeTree("R");
179 fTreeR = fPMDLoader->TreeR();
01709453 180 }
181
182 Int_t bufsize = 16000;
5c5cadd5 183 TBranch * branch1 = fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize);
184 TBranch * branch2 = fTreeR->Branch("PMDRechit", &fRechits, bufsize);
01709453 185
b208c6a3 186 Int_t nmodules = (Int_t) fTreeD->GetEntries();
01b56f5c 187
01709453 188 for (Int_t imodule = 0; imodule < nmodules; imodule++)
189 {
ed228cbc 190 ResetCellADC();
b208c6a3 191 fTreeD->GetEntry(imodule);
01709453 192 Int_t nentries = fDigits->GetLast();
193 for (Int_t ient = 0; ient < nentries+1; ient++)
194 {
195 pmddigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
196
197 det = pmddigit->GetDetector();
198 smn = pmddigit->GetSMNumber();
5e6a9312 199 xpos = pmddigit->GetRow();
200 ypos = pmddigit->GetColumn();
01709453 201 adc = pmddigit->GetADC();
09a06455 202
203 // CALIBRATION
204 Float_t gain = fCalibData->GetGainFact(det,smn,xpos,ypos);
2332574a 205 // printf("adc = %d gain = %f\n",adc,gain);
09a06455 206
207 adc = adc*gain;
208
ed228cbc 209 //Int_t trno = pmddigit->GetTrackNumber();
ed228cbc 210 fCellADC[xpos][ypos] = (Double_t) adc;
01709453 211 }
01709453 212
ed228cbc 213 idet = det;
1758e4fe 214 ismn = smn;
8616b098 215 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
ed228cbc 216
217 Int_t nentries1 = pmdcont->GetEntries();
7e9508a7 218
219 AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
220
ed228cbc 221 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
01709453 222 {
ebd83c56 223 AliPMDcluster *pmdcl = (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
1758e4fe 224 idet = pmdcl->GetDetector();
225 ismn = pmdcl->GetSMN();
226 clusdata[0] = pmdcl->GetClusX();
227 clusdata[1] = pmdcl->GetClusY();
228 clusdata[2] = pmdcl->GetClusADC();
229 clusdata[3] = pmdcl->GetClusCells();
5c5cadd5 230 clusdata[4] = pmdcl->GetClusSigmaX();
231 clusdata[5] = pmdcl->GetClusSigmaY();
01b56f5c 232
1758e4fe 233 AddRecPoint(idet,ismn,clusdata);
5c5cadd5 234
5c5cadd5 235 Int_t ncell = (Int_t) clusdata[3];
236 for(Int_t ihit = 0; ihit < ncell; ihit++)
237 {
238 Int_t celldataX = pmdcl->GetClusCellX(ihit);
239 Int_t celldataY = pmdcl->GetClusCellY(ihit);
240 AddRecHit(celldataX, celldataY);
241 }
242 branch2->Fill();
243 ResetRechit();
ed228cbc 244 }
245 pmdcont->Clear();
246
5c5cadd5 247 branch1->Fill();
ed228cbc 248 ResetRecpoint();
249
250 } // modules
251
01709453 252 ResetCellADC();
e1287360 253 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
b208c6a3 254 fPMDLoader->WriteRecPoints("OVERWRITE");
01709453 255
256 // delete the pointers
257 delete pmdclust;
258 delete pmdcont;
259
7e9508a7 260}
261// ------------------------------------------------------------------------- //
262
8fbad6d3 263void AliPMDClusterFinder::Digits2RecPoints(TTree *digitsTree,
264 TTree *clustersTree)
265{
266 // Converts digits to recpoints after running clustering
267 // algorithm on CPV plane and PREshower plane
268 //
269
270 Int_t det = 0,smn = 0;
271 Int_t xpos,ypos;
272 Float_t adc;
273 Int_t ismn;
274 Int_t idet;
275 Float_t clusdata[6];
276
277 TObjArray *pmdcont = new TObjArray();
278 AliPMDClustering *pmdclust = new AliPMDClusteringV1();
279
280 pmdclust->SetEdepCut(fEcut);
281
8fbad6d3 282 AliPMDdigit *pmddigit;
283 TBranch *branch = digitsTree->GetBranch("PMDDigit");
284 branch->SetAddress(&fDigits);
285
286 ResetRecpoint();
287
8fbad6d3 288 Int_t bufsize = 16000;
289 TBranch * branch1 = clustersTree->Branch("PMDRecpoint", &fRecpoints, bufsize);
290 TBranch * branch2 = clustersTree->Branch("PMDRechit", &fRechits, bufsize);
291
292 Int_t nmodules = (Int_t) digitsTree->GetEntries();
293
294 for (Int_t imodule = 0; imodule < nmodules; imodule++)
295 {
296 ResetCellADC();
297 digitsTree->GetEntry(imodule);
298 Int_t nentries = fDigits->GetLast();
299 for (Int_t ient = 0; ient < nentries+1; ient++)
300 {
301 pmddigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
302
303 det = pmddigit->GetDetector();
304 smn = pmddigit->GetSMNumber();
305 xpos = pmddigit->GetRow();
306 ypos = pmddigit->GetColumn();
307 adc = pmddigit->GetADC();
308
309 // CALIBRATION
310 Float_t gain = fCalibData->GetGainFact(det,smn,xpos,ypos);
311 // printf("adc = %d gain = %f\n",adc,gain);
312
313 adc = adc*gain;
314
315 //Int_t trno = pmddigit->GetTrackNumber();
316 fCellADC[xpos][ypos] = (Double_t) adc;
317 }
318
319 idet = det;
320 ismn = smn;
321 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
322
323 Int_t nentries1 = pmdcont->GetEntries();
324
325 AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
326
327 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
328 {
329 AliPMDcluster *pmdcl = (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
330 idet = pmdcl->GetDetector();
331 ismn = pmdcl->GetSMN();
332 clusdata[0] = pmdcl->GetClusX();
333 clusdata[1] = pmdcl->GetClusY();
334 clusdata[2] = pmdcl->GetClusADC();
335 clusdata[3] = pmdcl->GetClusCells();
336 clusdata[4] = pmdcl->GetClusSigmaX();
337 clusdata[5] = pmdcl->GetClusSigmaY();
338
339 AddRecPoint(idet,ismn,clusdata);
340
341 Int_t ncell = (Int_t) clusdata[3];
342 for(Int_t ihit = 0; ihit < ncell; ihit++)
343 {
344 Int_t celldataX = pmdcl->GetClusCellX(ihit);
345 Int_t celldataY = pmdcl->GetClusCellY(ihit);
346 AddRecHit(celldataX, celldataY);
347 }
348 branch2->Fill();
349 ResetRechit();
350 }
351 pmdcont->Clear();
352
353 branch1->Fill();
354 ResetRecpoint();
355
356 } // modules
357
358 ResetCellADC();
8fbad6d3 359
360 // delete the pointers
361 delete pmdclust;
362 delete pmdcont;
363
364}
365// ------------------------------------------------------------------------- //
366
7e9508a7 367void AliPMDClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
368 TTree *clustersTree)
369{
370 // Converts RAW data to recpoints after running clustering
371 // algorithm on CPV and PREshower plane
372 //
2332574a 373 // This method is called at the time of reconstruction
374
7e9508a7 375
5c5cadd5 376 Float_t clusdata[6];
df42ab21 377 TObjArray pmdddlcont;
7e9508a7 378
379 TObjArray *pmdcont = new TObjArray();
5c5cadd5 380 AliPMDClustering *pmdclust = new AliPMDClusteringV1();
7e9508a7 381
382 pmdclust->SetEdepCut(fEcut);
383
384 ResetRecpoint();
385
386 Int_t bufsize = 16000;
5c5cadd5 387 TBranch *branch1 = clustersTree->Branch("PMDRecpoint", &fRecpoints, bufsize);
388
389 TBranch * branch2 = clustersTree->Branch("PMDRechit", &fRechits, bufsize);
7e9508a7 390
2332574a 391 const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
7e9508a7 392 const Int_t kRow = 48;
393 const Int_t kCol = 96;
394
395 Int_t idet = 0;
396 Int_t iSMN = 0;
2332574a 397
8fbad6d3 398
7e9508a7 399 for (Int_t indexDDL = 0; indexDDL < kDDL; indexDDL++)
400 {
401 if (indexDDL < 4)
402 {
403 iSMN = 6;
404 }
405 else if (indexDDL >= 4)
406 {
407 iSMN = 12;
408 }
409 Int_t ***precpvADC;
410 precpvADC = new int **[iSMN];
411 for (Int_t i=0; i<iSMN; i++) precpvADC[i] = new int *[kRow];
412 for (Int_t i=0; i<iSMN;i++)
413 {
414 for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
415 }
416 for (Int_t i = 0; i < iSMN; i++)
417 {
418 for (Int_t j = 0; j < kRow; j++)
419 {
420 for (Int_t k = 0; k < kCol; k++)
421 {
422 precpvADC[i][j][k] = 0;
423 }
424 }
425 }
426 ResetCellADC();
427 rawReader->Reset();
428 AliPMDRawStream pmdinput(rawReader);
2332574a 429
362c9d61 430 rawReader->Select("PMD", indexDDL, indexDDL);
2332574a 431
432 pmdinput.DdlData(indexDDL,&pmdddlcont);
433
df42ab21 434 Int_t indexsmn = 0;
435 Int_t ientries = pmdddlcont.GetEntries();
436 for (Int_t ient = 0; ient < ientries; ient++)
7e9508a7 437 {
df42ab21 438 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
7e9508a7 439
df42ab21 440 Int_t det = pmdddl->GetDetector();
441 Int_t smn = pmdddl->GetSMN();
442 //Int_t mcm = pmdddl->GetMCM();
443 //Int_t chno = pmdddl->GetChannel();
444 Int_t row = pmdddl->GetRow();
445 Int_t col = pmdddl->GetColumn();
446 Int_t sig = pmdddl->GetSignal();
09a06455 447
df42ab21 448 Float_t sig1 = (Float_t) sig;
09a06455 449 // CALIBRATION
450 Float_t gain = fCalibData->GetGainFact(det,smn,row,col);
df42ab21 451 //printf("sig = %d gain = %f\n",sig,gain);
09a06455 452 sig = (Int_t) (sig1*gain);
7e9508a7 453
454 if (indexDDL < 4)
455 {
456 if (det != 0)
457 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
458 indexDDL, det));
459 indexsmn = smn - indexDDL * 6;
460 }
461 else if (indexDDL == 4)
462 {
463 if (det != 1)
464 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
465 indexDDL, det));
466 if (smn < 6)
467 {
468 indexsmn = smn;
469 }
df42ab21 470 else if (smn >= 18 && smn < 24)
7e9508a7 471 {
df42ab21 472 indexsmn = smn - 12;
7e9508a7 473 }
474 }
475 else if (indexDDL == 5)
476 {
477 if (det != 1)
478 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
479 indexDDL, det));
480 if (smn >= 6 && smn < 12)
481 {
482 indexsmn = smn - 6;
483 }
df42ab21 484 else if (smn >= 12 && smn < 18)
7e9508a7 485 {
df42ab21 486 indexsmn = smn - 6;
7e9508a7 487 }
488 }
489 precpvADC[indexsmn][row][col] = sig;
df42ab21 490 }
491
492 pmdddlcont.Clear();
7e9508a7 493
494 Int_t ismn = 0;
495 for (Int_t indexsmn = 0; indexsmn < iSMN; indexsmn++)
496 {
497 ResetCellADC();
498 for (Int_t irow = 0; irow < kRow; irow++)
499 {
500 for (Int_t icol = 0; icol < kCol; icol++)
501 {
502 fCellADC[irow][icol] =
503 (Double_t) precpvADC[indexsmn][irow][icol];
504 } // row
505 } // col
df42ab21 506
7e9508a7 507 if (indexDDL < 4)
508 {
509 ismn = indexsmn + indexDDL * 6;
510 idet = 0;
511 }
512 else if (indexDDL == 4)
513 {
514 if (indexsmn < 6)
515 {
516 ismn = indexsmn;
517 }
518 else if (indexsmn >= 6 && indexsmn < 12)
519 {
df42ab21 520 ismn = indexsmn + 12;
7e9508a7 521 }
522 idet = 1;
523 }
524 else if (indexDDL == 5)
525 {
526 if (indexsmn < 6)
527 {
528 ismn = indexsmn + 6;
529 }
530 else if (indexsmn >= 6 && indexsmn < 12)
531 {
df42ab21 532 ismn = indexsmn + 6;
7e9508a7 533 }
534 idet = 1;
535 }
536
7e9508a7 537 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
538 Int_t nentries1 = pmdcont->GetEntries();
539
540 AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
541
542 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
543 {
544 AliPMDcluster *pmdcl =
545 (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
546 idet = pmdcl->GetDetector();
547 ismn = pmdcl->GetSMN();
548 clusdata[0] = pmdcl->GetClusX();
549 clusdata[1] = pmdcl->GetClusY();
550 clusdata[2] = pmdcl->GetClusADC();
551 clusdata[3] = pmdcl->GetClusCells();
5c5cadd5 552 clusdata[4] = pmdcl->GetClusSigmaX();
553 clusdata[5] = pmdcl->GetClusSigmaY();
7e9508a7 554
555 AddRecPoint(idet,ismn,clusdata);
09a06455 556
5c5cadd5 557 Int_t ncell = (Int_t) clusdata[3];
558 for(Int_t ihit = 0; ihit < ncell; ihit++)
559 {
560 Int_t celldataX = pmdcl->GetClusCellX(ihit);
561 Int_t celldataY = pmdcl->GetClusCellY(ihit);
562 AddRecHit(celldataX, celldataY);
563 }
564 branch2->Fill();
565 ResetRechit();
566
7e9508a7 567 }
568 pmdcont->Clear();
569
5c5cadd5 570 branch1->Fill();
7e9508a7 571 ResetRecpoint();
572
573
574 } // smn
575
576 for (Int_t i=0; i<iSMN; i++)
577 {
578 for (Int_t j=0; j<kRow; j++) delete [] precpvADC[i][j];
579 }
580 for (Int_t i=0; i<iSMN; i++) delete [] precpvADC[i];
581 delete precpvADC;
582 } // DDL Loop
583
584 ResetCellADC();
585
586 // delete the pointers
587 delete pmdclust;
588 delete pmdcont;
589
01709453 590}
1758e4fe 591// ------------------------------------------------------------------------- //
5f55af10 592
593void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt, AliRawReader *rawReader)
594{
01b56f5c 595 // Converts RAW data to recpoints after running clustering
596 // algorithm on CPV and PREshower plane
5f55af10 597 //
598
5c5cadd5 599 Float_t clusdata[6];
df42ab21 600 TObjArray pmdddlcont;
5f55af10 601 TObjArray *pmdcont = new TObjArray();
5c5cadd5 602
603 AliPMDClustering *pmdclust = new AliPMDClusteringV1();
7e9508a7 604
5f55af10 605 pmdclust->SetEdepCut(fEcut);
606
607 fRunLoader->GetEvent(ievt);
608
609 ResetRecpoint();
01b56f5c 610
5f55af10 611 fTreeR = fPMDLoader->TreeR();
612 if (fTreeR == 0x0)
613 {
614 fPMDLoader->MakeTree("R");
615 fTreeR = fPMDLoader->TreeR();
616 }
5f55af10 617 Int_t bufsize = 16000;
5c5cadd5 618 TBranch *branch1 = fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize);
619 TBranch *branch2 = fTreeR->Branch("PMDRechit", &fRechits, bufsize);
01b56f5c 620
2332574a 621 const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
5f55af10 622 const Int_t kRow = 48;
623 const Int_t kCol = 96;
5f55af10 624
01b56f5c 625 Int_t idet = 0;
626 Int_t iSMN = 0;
627
628 for (Int_t indexDDL = 0; indexDDL < kDDL; indexDDL++)
5f55af10 629 {
01b56f5c 630 if (indexDDL < 4)
5f55af10 631 {
01b56f5c 632 iSMN = 6;
5f55af10 633 }
01b56f5c 634 else if (indexDDL >= 4)
5f55af10 635 {
01b56f5c 636 iSMN = 12;
5f55af10 637 }
01b56f5c 638 Int_t ***precpvADC;
639 precpvADC = new int **[iSMN];
640 for (Int_t i=0; i<iSMN; i++) precpvADC[i] = new int *[kRow];
641 for (Int_t i=0; i<iSMN;i++)
5f55af10 642 {
01b56f5c 643 for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
5f55af10 644 }
01b56f5c 645 for (Int_t i = 0; i < iSMN; i++)
646 {
647 for (Int_t j = 0; j < kRow; j++)
648 {
649 for (Int_t k = 0; k < kCol; k++)
650 {
651 precpvADC[i][j][k] = 0;
652 }
653 }
654 }
655 ResetCellADC();
656 rawReader->Reset();
362c9d61 657 rawReader->Select("PMD", indexDDL, indexDDL);
2332574a 658
659 AliPMDRawStream pmdinput(rawReader);
660 pmdinput.DdlData(indexDDL,&pmdddlcont);
df42ab21 661
662 Int_t indexsmn = 0;
663 Int_t ientries = pmdddlcont.GetEntries();
664 for (Int_t ient = 0; ient < ientries; ient++)
01b56f5c 665 {
df42ab21 666 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
667
668 Int_t det = pmdddl->GetDetector();
669 Int_t smn = pmdddl->GetSMN();
670 //Int_t mcm = pmdddl->GetMCM();
671 //Int_t chno = pmdddl->GetChannel();
672 Int_t row = pmdddl->GetRow();
673 Int_t col = pmdddl->GetColumn();
674 Int_t sig = pmdddl->GetSignal();
09a06455 675
676 Float_t sig1 = (Float_t) sig;
677 // CALIBRATION
1f86361b 678 Float_t gain = fCalibData->GetGainFact(det,smn,row,col);
2332574a 679
df42ab21 680 //printf("sig = %d gain = %f\n",sig,gain);
09a06455 681 sig = (Int_t) (sig1*gain);
df42ab21 682
5f55af10 683
01b56f5c 684 if (indexDDL < 4)
685 {
686 if (det != 0)
7e9508a7 687 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
688 indexDDL, det));
01b56f5c 689 indexsmn = smn - indexDDL * 6;
690 }
691 else if (indexDDL == 4)
692 {
693 if (det != 1)
7e9508a7 694 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
695 indexDDL, det));
01b56f5c 696 if (smn < 6)
697 {
698 indexsmn = smn;
699 }
df42ab21 700 else if (smn >= 18 && smn < 24)
01b56f5c 701 {
df42ab21 702 indexsmn = smn - 12;
01b56f5c 703 }
704 }
705 else if (indexDDL == 5)
706 {
707 if (det != 1)
7e9508a7 708 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
709 indexDDL, det));
01b56f5c 710 if (smn >= 6 && smn < 12)
711 {
712 indexsmn = smn - 6;
713 }
df42ab21 714 else if (smn >= 12 && smn < 18)
01b56f5c 715 {
df42ab21 716 indexsmn = smn - 6;
01b56f5c 717 }
718 }
719 precpvADC[indexsmn][row][col] = sig;
df42ab21 720
721 }
722
723 pmdddlcont.Clear();
01b56f5c 724
725 Int_t ismn = 0;
726 for (Int_t indexsmn = 0; indexsmn < iSMN; indexsmn++)
5f55af10 727 {
01b56f5c 728 ResetCellADC();
5f55af10 729 for (Int_t irow = 0; irow < kRow; irow++)
730 {
731 for (Int_t icol = 0; icol < kCol; icol++)
732 {
01b56f5c 733 fCellADC[irow][icol] =
734 (Double_t) precpvADC[indexsmn][irow][icol];
5f55af10 735 } // row
736 } // col
df42ab21 737
738
01b56f5c 739 if (indexDDL < 4)
740 {
741 ismn = indexsmn + indexDDL * 6;
742 idet = 0;
743 }
744 else if (indexDDL == 4)
745 {
746 if (indexsmn < 6)
747 {
748 ismn = indexsmn;
749 }
750 else if (indexsmn >= 6 && indexsmn < 12)
751 {
df42ab21 752 ismn = indexsmn + 12;
01b56f5c 753 }
754 idet = 1;
755 }
756 else if (indexDDL == 5)
757 {
758 if (indexsmn < 6)
759 {
760 ismn = indexsmn + 6;
761 }
762 else if (indexsmn >= 6 && indexsmn < 12)
763 {
df42ab21 764 ismn = indexsmn + 6;
01b56f5c 765 }
766 idet = 1;
767 }
768
5f55af10 769 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
770 Int_t nentries1 = pmdcont->GetEntries();
7e9508a7 771
772 AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
773
5f55af10 774 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
775 {
776 AliPMDcluster *pmdcl =
777 (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
778 idet = pmdcl->GetDetector();
779 ismn = pmdcl->GetSMN();
780 clusdata[0] = pmdcl->GetClusX();
781 clusdata[1] = pmdcl->GetClusY();
782 clusdata[2] = pmdcl->GetClusADC();
783 clusdata[3] = pmdcl->GetClusCells();
5c5cadd5 784 clusdata[4] = pmdcl->GetClusSigmaX();
785 clusdata[5] = pmdcl->GetClusSigmaY();
01b56f5c 786
5f55af10 787 AddRecPoint(idet,ismn,clusdata);
5c5cadd5 788
5c5cadd5 789 Int_t ncell = (Int_t) clusdata[3];
790 for(Int_t ihit = 0; ihit < ncell; ihit++)
791 {
792 Int_t celldataX = pmdcl->GetClusCellX(ihit);
793 Int_t celldataY = pmdcl->GetClusCellY(ihit);
794 AddRecHit(celldataX, celldataY);
795 }
796 branch2->Fill();
797 ResetRechit();
798
5f55af10 799 }
800 pmdcont->Clear();
801
5c5cadd5 802 branch1->Fill();
5f55af10 803 ResetRecpoint();
01b56f5c 804
805
5f55af10 806 } // smn
5f55af10 807
01b56f5c 808 for (Int_t i=0; i<iSMN; i++)
809 {
810 for (Int_t j=0; j<kRow; j++) delete [] precpvADC[i][j];
811 }
812 for (Int_t i=0; i<iSMN; i++) delete [] precpvADC[i];
813 delete precpvADC;
814 } // DDL Loop
815
5f55af10 816 ResetCellADC();
01b56f5c 817
5f55af10 818 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
819 fPMDLoader->WriteRecPoints("OVERWRITE");
820
821 // delete the pointers
822 delete pmdclust;
823 delete pmdcont;
824
5f55af10 825}
826// ------------------------------------------------------------------------- //
ed228cbc 827void AliPMDClusterFinder::SetCellEdepCut(Float_t ecut)
828{
829 fEcut = ecut;
830}
1758e4fe 831// ------------------------------------------------------------------------- //
1758e4fe 832void AliPMDClusterFinder::AddRecPoint(Int_t idet,Int_t ismn,Float_t *clusdata)
01709453 833{
b208c6a3 834 // Add Reconstructed points
835 //
01709453 836 TClonesArray &lrecpoints = *fRecpoints;
ed228cbc 837 AliPMDrecpoint1 *newrecpoint;
1758e4fe 838 newrecpoint = new AliPMDrecpoint1(idet, ismn, clusdata);
ed228cbc 839 new(lrecpoints[fNpoint++]) AliPMDrecpoint1(newrecpoint);
01709453 840 delete newrecpoint;
841}
1758e4fe 842// ------------------------------------------------------------------------- //
5c5cadd5 843void AliPMDClusterFinder::AddRecHit(Int_t celldataX,Int_t celldataY)
844{
845 // Add associated cell hits to the Reconstructed points
846 //
847 TClonesArray &lrechits = *fRechits;
848 AliPMDrechit *newrechit;
849 newrechit = new AliPMDrechit(celldataX, celldataY);
850 new(lrechits[fNhit++]) AliPMDrechit(newrechit);
851 delete newrechit;
852}
853// ------------------------------------------------------------------------- //
01709453 854void AliPMDClusterFinder::ResetCellADC()
855{
b208c6a3 856 // Reset the individual cell ADC value to zero
857 //
5e6a9312 858 for(Int_t irow = 0; irow < fgkRow; irow++)
01709453 859 {
5e6a9312 860 for(Int_t icol = 0; icol < fgkCol; icol++)
01709453 861 {
ed228cbc 862 fCellADC[irow][icol] = 0.;
01709453 863 }
864 }
865}
1758e4fe 866// ------------------------------------------------------------------------- //
01709453 867
868void AliPMDClusterFinder::ResetRecpoint()
869{
b208c6a3 870 // Clear the list of reconstructed points
01709453 871 fNpoint = 0;
872 if (fRecpoints) fRecpoints->Clear();
873}
1758e4fe 874// ------------------------------------------------------------------------- //
5c5cadd5 875void AliPMDClusterFinder::ResetRechit()
876{
877 // Clear the list of reconstructed points
878 fNhit = 0;
879 if (fRechits) fRechits->Clear();
880}
881// ------------------------------------------------------------------------- //
55601d47 882void AliPMDClusterFinder::Load()
883{
ebd83c56 884 // Load all the *.root files
55601d47 885 //
886 fPMDLoader->LoadDigits("READ");
887 fPMDLoader->LoadRecPoints("recreate");
888}
889// ------------------------------------------------------------------------- //
01b56f5c 890void AliPMDClusterFinder::LoadClusters()
891{
892 // Load all the *.root files
893 //
894 fPMDLoader->LoadRecPoints("recreate");
895}
896// ------------------------------------------------------------------------- //
ebd83c56 897void AliPMDClusterFinder::UnLoad()
01709453 898{
b208c6a3 899 // Unload all the *.root files
900 //
ebd83c56 901 fPMDLoader->UnloadDigits();
902 fPMDLoader->UnloadRecPoints();
01709453 903}
1758e4fe 904// ------------------------------------------------------------------------- //
01b56f5c 905void AliPMDClusterFinder::UnLoadClusters()
906{
907 // Unload all the *.root files
908 //
909 fPMDLoader->UnloadRecPoints();
910}
911// ------------------------------------------------------------------------- //
09a06455 912
913AliPMDCalibData* AliPMDClusterFinder::GetCalibData() const
914{
915 // The run number will be centralized in AliCDBManager,
916 // you don't need to set it here!
917 // Added by ZA
918 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Data");
919
0dd3d6f9 920 if(!entry) AliFatal("Calibration object retrieval failed! ");
09a06455 921
922 AliPMDCalibData *calibdata=0;
923 if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
924
0dd3d6f9 925 if (!calibdata) AliFatal("No calibration data from calibration database !");
09a06455 926
927 return calibdata;
928}