discrimination based on PRE-CPV matching
[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"
01709453 38#include "AliPMDcluster.h"
96377d57 39#include "AliPMDrecpoint1.h"
5f55af10 40#include "AliPMDRawStream.h"
01709453 41
7e9508a7 42
43
01709453 44ClassImp(AliPMDClusterFinder)
b208c6a3 45
7e9508a7 46AliPMDClusterFinder::AliPMDClusterFinder():
47 fRunLoader(0),
48 fPMDLoader(0),
49 fTreeD(0),
50 fTreeR(0),
51 fDigits(new TClonesArray("AliPMDdigit", 1000)),
52 fRecpoints(new TClonesArray("AliPMDrecpoint1", 1000)),
53 fNpoint(0),
54 fEcut(0.)
55{
56//
57// Constructor
58//
59}
60// ------------------------------------------------------------------------- //
dfaeee5f 61AliPMDClusterFinder::AliPMDClusterFinder(AliRunLoader* runLoader):
62 fRunLoader(runLoader),
63 fPMDLoader(runLoader->GetLoader("PMDLoader")),
1758e4fe 64 fTreeD(0),
65 fTreeR(0),
ebd83c56 66 fDigits(new TClonesArray("AliPMDdigit", 1000)),
1758e4fe 67 fRecpoints(new TClonesArray("AliPMDrecpoint1", 1000)),
68 fNpoint(0),
1758e4fe 69 fEcut(0.)
01709453 70{
b208c6a3 71//
dfaeee5f 72// Constructor
b208c6a3 73//
01709453 74}
1758e4fe 75// ------------------------------------------------------------------------- //
01709453 76AliPMDClusterFinder::~AliPMDClusterFinder()
77{
b208c6a3 78 // Destructor
ebd83c56 79 if (fDigits)
80 {
81 fDigits->Delete();
82 delete fDigits;
83 fDigits=0;
84 }
1758e4fe 85 if (fRecpoints)
86 {
87 fRecpoints->Delete();
88 delete fRecpoints;
89 fRecpoints=0;
90 }
01709453 91}
1758e4fe 92// ------------------------------------------------------------------------- //
b208c6a3 93
01709453 94void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt)
95{
b208c6a3 96 // Converts digits to recpoints after running clustering
97 // algorithm on CPV plane and PREshower plane
98 //
ed228cbc 99 Int_t det = 0,smn = 0;
01709453 100 Int_t xpos,ypos;
101 Float_t adc;
1758e4fe 102 Int_t ismn;
01709453 103 Int_t idet;
1758e4fe 104 Float_t clusdata[5];
ed228cbc 105
106 TObjArray *pmdcont = new TObjArray();
ed228cbc 107 AliPMDClustering *pmdclust = new AliPMDClustering();
7e9508a7 108
ed228cbc 109 pmdclust->SetEdepCut(fEcut);
01709453 110
111 fRunLoader->GetEvent(ievt);
7e9508a7 112
01b56f5c 113
b208c6a3 114 fTreeD = fPMDLoader->TreeD();
115 if (fTreeD == 0x0)
01709453 116 {
7e9508a7 117 AliFatal("AliPMDClusterFinder: Can not get TreeD");
118
01709453 119 }
120 AliPMDdigit *pmddigit;
b208c6a3 121 TBranch *branch = fTreeD->GetBranch("PMDDigit");
01709453 122 branch->SetAddress(&fDigits);
123
124 ResetRecpoint();
01b56f5c 125
b208c6a3 126 fTreeR = fPMDLoader->TreeR();
127 if (fTreeR == 0x0)
01709453 128 {
b208c6a3 129 fPMDLoader->MakeTree("R");
130 fTreeR = fPMDLoader->TreeR();
01709453 131 }
132
133 Int_t bufsize = 16000;
b208c6a3 134 fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize);
01709453 135
b208c6a3 136 Int_t nmodules = (Int_t) fTreeD->GetEntries();
01b56f5c 137
01709453 138 for (Int_t imodule = 0; imodule < nmodules; imodule++)
139 {
ed228cbc 140 ResetCellADC();
b208c6a3 141 fTreeD->GetEntry(imodule);
01709453 142 Int_t nentries = fDigits->GetLast();
143 for (Int_t ient = 0; ient < nentries+1; ient++)
144 {
145 pmddigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
146
147 det = pmddigit->GetDetector();
148 smn = pmddigit->GetSMNumber();
5e6a9312 149 xpos = pmddigit->GetRow();
150 ypos = pmddigit->GetColumn();
01709453 151 adc = pmddigit->GetADC();
ed228cbc 152 //Int_t trno = pmddigit->GetTrackNumber();
ed228cbc 153 fCellADC[xpos][ypos] = (Double_t) adc;
01709453 154 }
01709453 155
ed228cbc 156 idet = det;
1758e4fe 157 ismn = smn;
8616b098 158 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
ed228cbc 159
160 Int_t nentries1 = pmdcont->GetEntries();
7e9508a7 161
162 AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
163
ed228cbc 164 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
01709453 165 {
ebd83c56 166 AliPMDcluster *pmdcl = (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
1758e4fe 167 idet = pmdcl->GetDetector();
168 ismn = pmdcl->GetSMN();
169 clusdata[0] = pmdcl->GetClusX();
170 clusdata[1] = pmdcl->GetClusY();
171 clusdata[2] = pmdcl->GetClusADC();
172 clusdata[3] = pmdcl->GetClusCells();
173 clusdata[4] = pmdcl->GetClusRadius();
01b56f5c 174
1758e4fe 175 AddRecPoint(idet,ismn,clusdata);
ed228cbc 176 }
177 pmdcont->Clear();
178
b208c6a3 179 fTreeR->Fill();
ed228cbc 180 ResetRecpoint();
181
182 } // modules
183
01709453 184 ResetCellADC();
e1287360 185 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
b208c6a3 186 fPMDLoader->WriteRecPoints("OVERWRITE");
01709453 187
188 // delete the pointers
189 delete pmdclust;
190 delete pmdcont;
191
7e9508a7 192}
193// ------------------------------------------------------------------------- //
194
195void AliPMDClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
196 TTree *clustersTree)
197{
198 // Converts RAW data to recpoints after running clustering
199 // algorithm on CPV and PREshower plane
200 //
201
202 Float_t clusdata[5];
203
204 TObjArray *pmdcont = new TObjArray();
205 AliPMDClustering *pmdclust = new AliPMDClustering();
206
207 pmdclust->SetEdepCut(fEcut);
208
209 ResetRecpoint();
210
211 Int_t bufsize = 16000;
212 clustersTree->Branch("PMDRecpoint", &fRecpoints, bufsize);
213
214 const Int_t kDDL = 6;
215 const Int_t kRow = 48;
216 const Int_t kCol = 96;
217
218 Int_t idet = 0;
219 Int_t iSMN = 0;
220
221 for (Int_t indexDDL = 0; indexDDL < kDDL; indexDDL++)
222 {
223 if (indexDDL < 4)
224 {
225 iSMN = 6;
226 }
227 else if (indexDDL >= 4)
228 {
229 iSMN = 12;
230 }
231 Int_t ***precpvADC;
232 precpvADC = new int **[iSMN];
233 for (Int_t i=0; i<iSMN; i++) precpvADC[i] = new int *[kRow];
234 for (Int_t i=0; i<iSMN;i++)
235 {
236 for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
237 }
238 for (Int_t i = 0; i < iSMN; i++)
239 {
240 for (Int_t j = 0; j < kRow; j++)
241 {
242 for (Int_t k = 0; k < kCol; k++)
243 {
244 precpvADC[i][j][k] = 0;
245 }
246 }
247 }
248 ResetCellADC();
249 rawReader->Reset();
250 AliPMDRawStream pmdinput(rawReader);
251 rawReader->Select(12, indexDDL, indexDDL);
252 while(pmdinput.Next())
253 {
254 Int_t det = pmdinput.GetDetector();
255 Int_t smn = pmdinput.GetSMN();
256 //Int_t mcm = pmdinput.GetMCM();
257 //Int_t chno = pmdinput.GetChannel();
258 Int_t row = pmdinput.GetRow();
259 Int_t col = pmdinput.GetColumn();
260 Int_t sig = pmdinput.GetSignal();
261
262 Int_t indexsmn = 0;
263
264 if (indexDDL < 4)
265 {
266 if (det != 0)
267 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
268 indexDDL, det));
269 indexsmn = smn - indexDDL * 6;
270 }
271 else if (indexDDL == 4)
272 {
273 if (det != 1)
274 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
275 indexDDL, det));
276 if (smn < 6)
277 {
278 indexsmn = smn;
279 }
280 else if (smn >= 12 && smn < 18)
281 {
282 indexsmn = smn - 6;
283 }
284 }
285 else if (indexDDL == 5)
286 {
287 if (det != 1)
288 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
289 indexDDL, det));
290 if (smn >= 6 && smn < 12)
291 {
292 indexsmn = smn - 6;
293 }
294 else if (smn >= 18 && smn < 24)
295 {
296 indexsmn = smn - 12;
297 }
298 }
299 precpvADC[indexsmn][row][col] = sig;
300 } // while loop
301
302 Int_t ismn = 0;
303 for (Int_t indexsmn = 0; indexsmn < iSMN; indexsmn++)
304 {
305 ResetCellADC();
306 for (Int_t irow = 0; irow < kRow; irow++)
307 {
308 for (Int_t icol = 0; icol < kCol; icol++)
309 {
310 fCellADC[irow][icol] =
311 (Double_t) precpvADC[indexsmn][irow][icol];
312 } // row
313 } // col
314 if (indexDDL < 4)
315 {
316 ismn = indexsmn + indexDDL * 6;
317 idet = 0;
318 }
319 else if (indexDDL == 4)
320 {
321 if (indexsmn < 6)
322 {
323 ismn = indexsmn;
324 }
325 else if (indexsmn >= 6 && indexsmn < 12)
326 {
327 ismn = indexsmn + 6;
328 }
329 idet = 1;
330 }
331 else if (indexDDL == 5)
332 {
333 if (indexsmn < 6)
334 {
335 ismn = indexsmn + 6;
336 }
337 else if (indexsmn >= 6 && indexsmn < 12)
338 {
339 ismn = indexsmn + 12;
340 }
341 idet = 1;
342 }
343
344
345 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
346 Int_t nentries1 = pmdcont->GetEntries();
347
348 AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
349
350 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
351 {
352 AliPMDcluster *pmdcl =
353 (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
354 idet = pmdcl->GetDetector();
355 ismn = pmdcl->GetSMN();
356 clusdata[0] = pmdcl->GetClusX();
357 clusdata[1] = pmdcl->GetClusY();
358 clusdata[2] = pmdcl->GetClusADC();
359 clusdata[3] = pmdcl->GetClusCells();
360 clusdata[4] = pmdcl->GetClusRadius();
361
362 AddRecPoint(idet,ismn,clusdata);
363 }
364 pmdcont->Clear();
365
366 //fTreeR->Fill();
367 clustersTree->Fill();
368 ResetRecpoint();
369
370
371 } // smn
372
373 for (Int_t i=0; i<iSMN; i++)
374 {
375 for (Int_t j=0; j<kRow; j++) delete [] precpvADC[i][j];
376 }
377 for (Int_t i=0; i<iSMN; i++) delete [] precpvADC[i];
378 delete precpvADC;
379 } // DDL Loop
380
381 ResetCellADC();
382
383 // delete the pointers
384 delete pmdclust;
385 delete pmdcont;
386
01709453 387}
1758e4fe 388// ------------------------------------------------------------------------- //
5f55af10 389
390void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt, AliRawReader *rawReader)
391{
01b56f5c 392 // Converts RAW data to recpoints after running clustering
393 // algorithm on CPV and PREshower plane
5f55af10 394 //
395
396 Float_t clusdata[5];
397
5f55af10 398 TObjArray *pmdcont = new TObjArray();
399 AliPMDClustering *pmdclust = new AliPMDClustering();
7e9508a7 400
5f55af10 401 pmdclust->SetEdepCut(fEcut);
402
403 fRunLoader->GetEvent(ievt);
404
405 ResetRecpoint();
01b56f5c 406
5f55af10 407 fTreeR = fPMDLoader->TreeR();
408 if (fTreeR == 0x0)
409 {
410 fPMDLoader->MakeTree("R");
411 fTreeR = fPMDLoader->TreeR();
412 }
5f55af10 413 Int_t bufsize = 16000;
414 fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize);
01b56f5c 415
416 const Int_t kDDL = 6;
5f55af10 417 const Int_t kRow = 48;
418 const Int_t kCol = 96;
5f55af10 419
01b56f5c 420 Int_t idet = 0;
421 Int_t iSMN = 0;
422
423 for (Int_t indexDDL = 0; indexDDL < kDDL; indexDDL++)
5f55af10 424 {
01b56f5c 425 if (indexDDL < 4)
5f55af10 426 {
01b56f5c 427 iSMN = 6;
5f55af10 428 }
01b56f5c 429 else if (indexDDL >= 4)
5f55af10 430 {
01b56f5c 431 iSMN = 12;
5f55af10 432 }
01b56f5c 433 Int_t ***precpvADC;
434 precpvADC = new int **[iSMN];
435 for (Int_t i=0; i<iSMN; i++) precpvADC[i] = new int *[kRow];
436 for (Int_t i=0; i<iSMN;i++)
5f55af10 437 {
01b56f5c 438 for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
5f55af10 439 }
01b56f5c 440 for (Int_t i = 0; i < iSMN; i++)
441 {
442 for (Int_t j = 0; j < kRow; j++)
443 {
444 for (Int_t k = 0; k < kCol; k++)
445 {
446 precpvADC[i][j][k] = 0;
447 }
448 }
449 }
450 ResetCellADC();
451 rawReader->Reset();
452 AliPMDRawStream pmdinput(rawReader);
453 rawReader->Select(12, indexDDL, indexDDL);
454 while(pmdinput.Next())
455 {
456 Int_t det = pmdinput.GetDetector();
457 Int_t smn = pmdinput.GetSMN();
458 //Int_t mcm = pmdinput.GetMCM();
459 //Int_t chno = pmdinput.GetChannel();
460 Int_t row = pmdinput.GetRow();
461 Int_t col = pmdinput.GetColumn();
462 Int_t sig = pmdinput.GetSignal();
463
464 Int_t indexsmn = 0;
5f55af10 465
01b56f5c 466 if (indexDDL < 4)
467 {
468 if (det != 0)
7e9508a7 469 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
470 indexDDL, det));
01b56f5c 471 indexsmn = smn - indexDDL * 6;
472 }
473 else if (indexDDL == 4)
474 {
475 if (det != 1)
7e9508a7 476 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
477 indexDDL, det));
01b56f5c 478 if (smn < 6)
479 {
480 indexsmn = smn;
481 }
482 else if (smn >= 12 && smn < 18)
483 {
484 indexsmn = smn - 6;
485 }
486 }
487 else if (indexDDL == 5)
488 {
489 if (det != 1)
7e9508a7 490 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
491 indexDDL, det));
01b56f5c 492 if (smn >= 6 && smn < 12)
493 {
494 indexsmn = smn - 6;
495 }
496 else if (smn >= 18 && smn < 24)
497 {
498 indexsmn = smn - 12;
499 }
500 }
501 precpvADC[indexsmn][row][col] = sig;
502 } // while loop
503
504 Int_t ismn = 0;
505 for (Int_t indexsmn = 0; indexsmn < iSMN; indexsmn++)
5f55af10 506 {
01b56f5c 507 ResetCellADC();
5f55af10 508 for (Int_t irow = 0; irow < kRow; irow++)
509 {
510 for (Int_t icol = 0; icol < kCol; icol++)
511 {
01b56f5c 512 fCellADC[irow][icol] =
513 (Double_t) precpvADC[indexsmn][irow][icol];
5f55af10 514 } // row
515 } // col
01b56f5c 516 if (indexDDL < 4)
517 {
518 ismn = indexsmn + indexDDL * 6;
519 idet = 0;
520 }
521 else if (indexDDL == 4)
522 {
523 if (indexsmn < 6)
524 {
525 ismn = indexsmn;
526 }
527 else if (indexsmn >= 6 && indexsmn < 12)
528 {
529 ismn = indexsmn + 6;
530 }
531 idet = 1;
532 }
533 else if (indexDDL == 5)
534 {
535 if (indexsmn < 6)
536 {
537 ismn = indexsmn + 6;
538 }
539 else if (indexsmn >= 6 && indexsmn < 12)
540 {
541 ismn = indexsmn + 12;
542 }
543 idet = 1;
544 }
545
546
5f55af10 547 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
548 Int_t nentries1 = pmdcont->GetEntries();
7e9508a7 549
550 AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
551
5f55af10 552 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
553 {
554 AliPMDcluster *pmdcl =
555 (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
556 idet = pmdcl->GetDetector();
557 ismn = pmdcl->GetSMN();
558 clusdata[0] = pmdcl->GetClusX();
559 clusdata[1] = pmdcl->GetClusY();
560 clusdata[2] = pmdcl->GetClusADC();
561 clusdata[3] = pmdcl->GetClusCells();
562 clusdata[4] = pmdcl->GetClusRadius();
01b56f5c 563
5f55af10 564 AddRecPoint(idet,ismn,clusdata);
565 }
566 pmdcont->Clear();
567
568 fTreeR->Fill();
569 ResetRecpoint();
01b56f5c 570
571
5f55af10 572 } // smn
5f55af10 573
01b56f5c 574 for (Int_t i=0; i<iSMN; i++)
575 {
576 for (Int_t j=0; j<kRow; j++) delete [] precpvADC[i][j];
577 }
578 for (Int_t i=0; i<iSMN; i++) delete [] precpvADC[i];
579 delete precpvADC;
580 } // DDL Loop
581
5f55af10 582 ResetCellADC();
01b56f5c 583
5f55af10 584 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
585 fPMDLoader->WriteRecPoints("OVERWRITE");
586
587 // delete the pointers
588 delete pmdclust;
589 delete pmdcont;
590
5f55af10 591}
592// ------------------------------------------------------------------------- //
ed228cbc 593void AliPMDClusterFinder::SetCellEdepCut(Float_t ecut)
594{
595 fEcut = ecut;
596}
1758e4fe 597// ------------------------------------------------------------------------- //
1758e4fe 598void AliPMDClusterFinder::AddRecPoint(Int_t idet,Int_t ismn,Float_t *clusdata)
01709453 599{
b208c6a3 600 // Add Reconstructed points
601 //
01709453 602 TClonesArray &lrecpoints = *fRecpoints;
ed228cbc 603 AliPMDrecpoint1 *newrecpoint;
1758e4fe 604 newrecpoint = new AliPMDrecpoint1(idet, ismn, clusdata);
ed228cbc 605 new(lrecpoints[fNpoint++]) AliPMDrecpoint1(newrecpoint);
01709453 606 delete newrecpoint;
607}
1758e4fe 608// ------------------------------------------------------------------------- //
01709453 609void AliPMDClusterFinder::ResetCellADC()
610{
b208c6a3 611 // Reset the individual cell ADC value to zero
612 //
5e6a9312 613 for(Int_t irow = 0; irow < fgkRow; irow++)
01709453 614 {
5e6a9312 615 for(Int_t icol = 0; icol < fgkCol; icol++)
01709453 616 {
ed228cbc 617 fCellADC[irow][icol] = 0.;
01709453 618 }
619 }
620}
1758e4fe 621// ------------------------------------------------------------------------- //
01709453 622
623void AliPMDClusterFinder::ResetRecpoint()
624{
b208c6a3 625 // Clear the list of reconstructed points
01709453 626 fNpoint = 0;
627 if (fRecpoints) fRecpoints->Clear();
628}
1758e4fe 629// ------------------------------------------------------------------------- //
55601d47 630void AliPMDClusterFinder::Load()
631{
ebd83c56 632 // Load all the *.root files
55601d47 633 //
634 fPMDLoader->LoadDigits("READ");
635 fPMDLoader->LoadRecPoints("recreate");
636}
637// ------------------------------------------------------------------------- //
01b56f5c 638void AliPMDClusterFinder::LoadClusters()
639{
640 // Load all the *.root files
641 //
642 fPMDLoader->LoadRecPoints("recreate");
643}
644// ------------------------------------------------------------------------- //
ebd83c56 645void AliPMDClusterFinder::UnLoad()
01709453 646{
b208c6a3 647 // Unload all the *.root files
648 //
ebd83c56 649 fPMDLoader->UnloadDigits();
650 fPMDLoader->UnloadRecPoints();
01709453 651}
1758e4fe 652// ------------------------------------------------------------------------- //
01b56f5c 653void AliPMDClusterFinder::UnLoadClusters()
654{
655 // Unload all the *.root files
656 //
657 fPMDLoader->UnloadRecPoints();
658}
659// ------------------------------------------------------------------------- //