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