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