Removing obsolete header file
[u/mrichter/AliRoot.git] / PMD / AliPMDDigitizer.cxx
CommitLineData
b9746a9e 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 **************************************************************************/
b2b13ee2 15//-----------------------------------------------------//
16// //
8599803d 17// Source File : PMDDigitizer.cxx, Version 00 //
b2b13ee2 18// //
19// Date : September 20 2002 //
20// //
21//-----------------------------------------------------//
22
36031625 23#include <Riostream.h>
b2b13ee2 24#include <TTree.h>
b2b13ee2 25#include <TObjArray.h>
26#include <TClonesArray.h>
27#include <TFile.h>
28#include <TNtuple.h>
29#include <TParticle.h>
e939a978 30#include <TRandom.h>
b2b13ee2 31
ecee2a1a 32#include "AliLog.h"
b2b13ee2 33#include "AliRun.h"
b2b13ee2 34#include "AliHit.h"
35#include "AliDetector.h"
36#include "AliRunLoader.h"
37#include "AliLoader.h"
38#include "AliConfig.h"
39#include "AliMagF.h"
40#include "AliRunDigitizer.h"
7088dbe9 41#include "AliDigitizer.h"
b2b13ee2 42#include "AliHeader.h"
09a06455 43#include "AliCDBManager.h"
44#include "AliCDBStorage.h"
45#include "AliCDBEntry.h"
46#include "AliMC.h"
b2b13ee2 47
09a06455 48#include "AliPMD.h"
49#include "AliPMDhit.h"
b2b13ee2 50#include "AliPMDcell.h"
51#include "AliPMDsdigit.h"
52#include "AliPMDdigit.h"
09a06455 53#include "AliPMDCalibData.h"
35535af7 54#include "AliPMDPedestal.h"
b2b13ee2 55#include "AliPMDDigitizer.h"
09a06455 56
b2b13ee2 57
58ClassImp(AliPMDDigitizer)
a7d110b8 59
01960205 60AliPMDDigitizer::AliPMDDigitizer() :
61 fRunLoader(0),
62 fPMDHit(0),
63 fPMD(0),
64 fPMDLoader(0),
35535af7 65 fCalibGain(GetCalibGain()),
66 fCalibPed(GetCalibPed()),
ebd83c56 67 fSDigits(0),
68 fDigits(0),
4d59e381 69 fCPVCell(0),
ebd83c56 70 fCell(0),
01960205 71 fNsdigit(0),
72 fNdigit(0),
73 fDetNo(0),
2332574a 74 fZPos(361.5) // in units of cm, default position of PMD
b2b13ee2 75{
36031625 76 // Default Constructor
77 //
36031625 78 for (Int_t i = 0; i < fgkTotUM; i++)
b2b13ee2 79 {
36031625 80 for (Int_t j = 0; j < fgkRow; j++)
b2b13ee2 81 {
36031625 82 for (Int_t k = 0; k < fgkCol; k++)
b2b13ee2 83 {
5e2cc5bc 84 fCPV[i][j][k] = 0.;
85 fPRE[i][j][k] = 0.;
4d59e381 86 fCPVCounter[i][j][k] = 0;
5e2cc5bc 87 fPRECounter[i][j][k] = 0;
5e2cc5bc 88 fCPVTrackNo[i][j][k] = -1;
4d59e381 89 fPRETrackNo[i][j][k] = -1;
b2b13ee2 90 }
91 }
92 }
2332574a 93
b2b13ee2 94}
7088dbe9 95//____________________________________________________________________________
2332574a 96AliPMDDigitizer::AliPMDDigitizer(const AliPMDDigitizer& digitizer):
97 AliDigitizer(digitizer),
98 fRunLoader(0),
99 fPMDHit(0),
100 fPMD(0),
101 fPMDLoader(0),
35535af7 102 fCalibGain(GetCalibGain()),
103 fCalibPed(GetCalibPed()),
2332574a 104 fSDigits(0),
105 fDigits(0),
4d59e381 106 fCPVCell(0),
2332574a 107 fCell(0),
108 fNsdigit(0),
109 fNdigit(0),
110 fDetNo(0),
111 fZPos(361.5) // in units of cm, default position of PMD
a48edddd 112{
113 // copy constructor
114 AliError("Copy constructor not allowed ");
115
116}
117//____________________________________________________________________________
a48edddd 118AliPMDDigitizer & AliPMDDigitizer::operator=(const AliPMDDigitizer& /*digitizer*/)
119{
120 // Assignment operator
121 AliError("Assignement operator not allowed ");
122
123 return *this;
124}
125//____________________________________________________________________________
2332574a 126AliPMDDigitizer::AliPMDDigitizer(AliRunDigitizer* manager):
127 AliDigitizer(manager),
ebd83c56 128 fRunLoader(0),
129 fPMDHit(0),
130 fPMD(0),
131 fPMDLoader(0),
35535af7 132 fCalibGain(GetCalibGain()),
133 fCalibPed(GetCalibPed()),
ebd83c56 134 fSDigits(new TClonesArray("AliPMDsdigit", 1000)),
135 fDigits(new TClonesArray("AliPMDdigit", 1000)),
4d59e381 136 fCPVCell(0),
ebd83c56 137 fCell(0),
ebd83c56 138 fNsdigit(0),
139 fNdigit(0),
140 fDetNo(0),
141 fZPos(361.5)// in units of cm, This is the default position of PMD
7088dbe9 142{
143 // ctor which should be used
144
09a06455 145
ebd83c56 146 for (Int_t i = 0; i < fgkTotUM; i++)
147 {
148 for (Int_t j = 0; j < fgkRow; j++)
149 {
150 for (Int_t k = 0; k < fgkCol; k++)
151 {
5e2cc5bc 152 fCPV[i][j][k] = 0.;
153 fPRE[i][j][k] = 0.;
4d59e381 154 fCPVCounter[i][j][k] = 0;
5e2cc5bc 155 fPRECounter[i][j][k] = 0;
5e2cc5bc 156 fCPVTrackNo[i][j][k] = -1;
4d59e381 157 fPRETrackNo[i][j][k] = -1;
ebd83c56 158 }
159 }
160 }
7088dbe9 161}
2332574a 162
7088dbe9 163//____________________________________________________________________________
b2b13ee2 164AliPMDDigitizer::~AliPMDDigitizer()
165{
36031625 166 // Default Destructor
167 //
01960205 168 if (fSDigits) {
169 fSDigits->Delete();
170 delete fSDigits;
171 fSDigits=0;
172 }
173 if (fDigits) {
174 fDigits->Delete();
175 delete fDigits;
176 fDigits=0;
177 }
4d59e381 178 fCPVCell.Delete();
ebd83c56 179 fCell.Delete();
b2b13ee2 180}
181//
182// Member functions
183//
7088dbe9 184//____________________________________________________________________________
85a5290f 185void AliPMDDigitizer::OpengAliceFile(const char *file, Option_t *option)
b2b13ee2 186{
36031625 187 // Loads galice.root file and corresponding header, kinematics
188 // hits and sdigits or digits depending on the option
189 //
f540341d 190
e191bb57 191 TString evfoldname = AliConfig::GetDefaultEventFolderName();
f540341d 192 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
193 if (!fRunLoader)
5e2cc5bc 194 fRunLoader = AliRunLoader::Open(file,AliConfig::GetDefaultEventFolderName(), "UPDATE");
b2b13ee2 195
196 if (!fRunLoader)
197 {
ecee2a1a 198 AliError(Form("Can not open session for file %s.",file));
b2b13ee2 199 }
b2b13ee2 200
be9188a5 201 const char *cHS = strstr(option,"HS");
202 const char *cHD = strstr(option,"HD");
203 const char *cSD = strstr(option,"SD");
b2b13ee2 204
be9188a5 205 if(cHS || cHD)
ecee2a1a 206 {
be9188a5 207 if (!fRunLoader->GetAliRun()) fRunLoader->LoadgAlice();
208 if (!fRunLoader->TreeE()) fRunLoader->LoadHeader();
209 if (!fRunLoader->TreeK()) fRunLoader->LoadKinematics();
210
211 gAlice = fRunLoader->GetAliRun();
212
213 if (gAlice)
214 {
215 AliDebug(1,"Alirun object found");
216 }
217 else
218 {
219 AliError("Could not found Alirun object");
220 }
f540341d 221
be9188a5 222 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
223 }
224
36031625 225 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
226 if (fPMDLoader == 0x0)
b2b13ee2 227 {
ecee2a1a 228 AliError("Can not find PMDLoader");
b2b13ee2 229 }
230
b2b13ee2 231
232 if (cHS)
233 {
36031625 234 fPMDLoader->LoadHits("READ");
235 fPMDLoader->LoadSDigits("recreate");
b2b13ee2 236 }
237 else if (cHD)
238 {
36031625 239 fPMDLoader->LoadHits("READ");
240 fPMDLoader->LoadDigits("recreate");
b2b13ee2 241 }
242 else if (cSD)
243 {
36031625 244 fPMDLoader->LoadSDigits("READ");
245 fPMDLoader->LoadDigits("recreate");
b2b13ee2 246 }
b2b13ee2 247}
7088dbe9 248//____________________________________________________________________________
b2b13ee2 249void AliPMDDigitizer::Hits2SDigits(Int_t ievt)
250{
36031625 251 // This reads the PMD Hits tree and assigns the right track number
252 // to a cell and stores in the summable digits tree
253 //
b2b13ee2 254
36031625 255 const Int_t kPi0 = 111;
256 const Int_t kGamma = 22;
b2b13ee2 257 Int_t npmd;
258 Int_t trackno;
b2b13ee2 259 Int_t smnumber;
260 Int_t trackpid;
261 Int_t mtrackno;
262 Int_t mtrackpid;
263
264 Float_t xPos, yPos, zPos;
8599803d 265 Int_t xpad = -1, ypad = -1;
b2b13ee2 266 Float_t edep;
267 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
268
a7d110b8 269
ebd83c56 270 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
b2b13ee2 271 ResetSDigit();
272
ecee2a1a 273 AliDebug(1,Form("Event Number = %d",ievt));
b2b13ee2 274 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
ecee2a1a 275 AliDebug(1,Form("Number of Particles = %d",nparticles));
b2b13ee2 276 fRunLoader->GetEvent(ievt);
b2b13ee2 277 // ------------------------------------------------------- //
278 // Pointer to specific detector hits.
279 // Get pointers to Alice detectors and Hits containers
280
ebd83c56 281 TTree* treeH = fPMDLoader->TreeH();
b2b13ee2 282
ebd83c56 283 Int_t ntracks = (Int_t) treeH->GetEntries();
ecee2a1a 284 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
ebd83c56 285 TTree* treeS = fPMDLoader->TreeS();
286 if (treeS == 0x0)
b2b13ee2 287 {
36031625 288 fPMDLoader->MakeTree("S");
ebd83c56 289 treeS = fPMDLoader->TreeS();
b2b13ee2 290 }
291 Int_t bufsize = 16000;
5e2cc5bc 292 treeS->Branch("PMDSDigit", &fSDigits, bufsize);
b2b13ee2 293
ebd83c56 294 TClonesArray* hits = 0;
295 if (fPMD) hits = fPMD->Hits();
b2b13ee2 296
297 // Start loop on tracks in the hits containers
a7d110b8 298
5e2cc5bc 299 for (Int_t track=0; track<ntracks;track++)
b2b13ee2 300 {
3e2e3ece 301 gAlice->GetMCApp()->ResetHits();
ebd83c56 302 treeH->GetEvent(track);
5e2cc5bc 303 if (fPMD)
b2b13ee2 304 {
ebd83c56 305 npmd = hits->GetEntriesFast();
4d59e381 306 for (Int_t ipmd = 0; ipmd < npmd; ipmd++)
b2b13ee2 307 {
ebd83c56 308 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
36031625 309 trackno = fPMDHit->GetTrack();
b2b13ee2 310 // get kinematics of the particles
36031625 311
ebd83c56 312 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
313 trackpid = mparticle->GetPdgCode();
4d59e381 314 Int_t ks = mparticle->GetStatusCode();
b2b13ee2 315 Int_t imo;
36031625 316 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
4d59e381 317
8599803d 318 if (mparticle->GetFirstMother() == -1)
319 {
36031625 320 tracknoOld = trackno;
321 trackpidOld = trackpid;
322 statusOld = -1;
8599803d 323 }
8599803d 324 Int_t igstatus = 0;
4d59e381 325 //------------------modified by Mriganka ----------------------
d934d257 326 Int_t trnotemp = trackno;
327
4d59e381 328 if(ks==1||(imo = mparticle->GetFirstMother())<0 ){
329 vx = mparticle->Vx();
330 vy = mparticle->Vy();
331 vz = mparticle->Vz();
332
333 if(trackpid==kGamma||trackpid==11||trackpid==-11||
334 trackpid==kPi0)igstatus=1;
335 }
4d59e381 336 while(((imo = mparticle->GetFirstMother()) >= 0)&&
337 (ks = mparticle->GetStatusCode() <1) )
5f7ce82b 338 {
b208c6a3 339 mparticle = gAlice->GetMCApp()->Particle(imo);
4d59e381 340 trackpid = mparticle->GetPdgCode();
341 ks = mparticle->GetStatusCode();
b2b13ee2 342 vx = mparticle->Vx();
343 vy = mparticle->Vy();
344 vz = mparticle->Vz();
d934d257 345 trnotemp = trackno;
346 if(trackpid == 111)
347 {
348 trackno = trnotemp;
5f7ce82b 349 }
d934d257 350 if(trackpid != 111)
351 {
352 trackno = imo;
353 }
354 }
355
5f7ce82b 356 if(trackpid==kGamma||trackpid==11||trackpid==-11||
357 trackpid==kPi0)igstatus=1;
358 mtrackpid=trackpid;
359 mtrackno=trackno;
360 trackpid=trackpidOld;
361 trackno=tracknoOld;
4d59e381 362 //-----------------end of modification----------------
d934d257 363
36031625 364 xPos = fPMDHit->X();
365 yPos = fPMDHit->Y();
366 zPos = fPMDHit->Z();
7088dbe9 367
c35544fe 368 edep = fPMDHit->GetEnergy();
369 Int_t vol1 = fPMDHit->GetVolume(1); // Column
370 Int_t vol2 = fPMDHit->GetVolume(2); // Row
f117e3aa 371 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
372 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
373
c35544fe 374
8599803d 375 // -----------------------------------------//
f117e3aa 376 // In new geometry after adding electronics //
8599803d 377 // For Super Module 1 & 2 //
8599803d 378 // nrow = 48, ncol = 96 //
f117e3aa 379 // For Super Module 3 & 4 //
380 // nrow = 96, ncol = 48 //
8599803d 381 // -----------------------------------------//
f117e3aa 382
383
b2b13ee2 384
f117e3aa 385 smnumber = (vol8-1)*6 + vol7;
8599803d 386
f117e3aa 387 if (vol8 == 1 || vol8 == 2)
b2b13ee2 388 {
36031625 389 xpad = vol2;
390 ypad = vol1;
b2b13ee2 391 }
f117e3aa 392 else if (vol8 == 3 || vol8 == 4)
393 {
394 xpad = vol1;
395 ypad = vol2;
396 }
b2b13ee2 397
ecee2a1a 398 AliDebug(2,Form("Zposition = %f Edeposition = %f",zPos,edep));
5f7ce82b 399 //Float_t zposition = TMath::Abs(zPos);
f117e3aa 400 if (zPos < fZPos)
b2b13ee2 401 {
402 // CPV
403 fDetNo = 1;
404 }
f117e3aa 405 else if (zPos > fZPos)
b2b13ee2 406 {
407 // PMD
408 fDetNo = 0;
409 }
8599803d 410 Int_t smn = smnumber - 1;
411 Int_t ixx = xpad - 1;
412 Int_t iyy = ypad - 1;
b2b13ee2 413 if (fDetNo == 0)
414 {
36031625 415 fPRE[smn][ixx][iyy] += edep;
416 fPRECounter[smn][ixx][iyy]++;
b2b13ee2 417
ebd83c56 418 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
ebd83c56 419 fCell.Add(cell);
b2b13ee2 420 }
421 else if(fDetNo == 1)
422 {
8599803d 423 fCPV[smn][ixx][iyy] += edep;
4d59e381 424 fCPVCounter[smn][ixx][iyy]++;
425 AliPMDcell* cpvcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
426 fCPVCell.Add(cpvcell);
b2b13ee2 427 }
428 }
429 }
430 } // Track Loop ended
4d59e381 431 TrackAssignment2CPVCell();
b2b13ee2 432 TrackAssignment2Cell();
b2b13ee2 433 ResetCell();
434
435 Float_t deltaE = 0.;
436 Int_t detno = 0;
b2b13ee2 437 Int_t trno = -1;
b2b13ee2 438
439 for (Int_t idet = 0; idet < 2; idet++)
440 {
36031625 441 for (Int_t ism = 0; ism < fgkTotUM; ism++)
b2b13ee2 442 {
36031625 443 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
b2b13ee2 444 {
36031625 445 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
b2b13ee2 446 {
b2b13ee2 447 if (idet == 0)
448 {
36031625 449 deltaE = fPRE[ism][jrow][kcol];
450 trno = fPRETrackNo[ism][jrow][kcol];
b2b13ee2 451 detno = 0;
452 }
453 else if (idet == 1)
454 {
455 deltaE = fCPV[ism][jrow][kcol];
456 trno = fCPVTrackNo[ism][jrow][kcol];
457 detno = 1;
458 }
459 if (deltaE > 0.)
460 {
7088dbe9 461 AddSDigit(trno,detno,ism,jrow,kcol,deltaE);
b2b13ee2 462 }
463 }
464 }
ebd83c56 465 treeS->Fill();
b2b13ee2 466 ResetSDigit();
467 }
468 }
36031625 469 fPMDLoader->WriteSDigits("OVERWRITE");
b2b13ee2 470 ResetCellADC();
b2b13ee2 471}
7088dbe9 472//____________________________________________________________________________
b2b13ee2 473
474void AliPMDDigitizer::Hits2Digits(Int_t ievt)
475{
36031625 476 // This reads the PMD Hits tree and assigns the right track number
477 // to a cell and stores in the digits tree
478 //
479 const Int_t kPi0 = 111;
480 const Int_t kGamma = 22;
b2b13ee2 481 Int_t npmd;
482 Int_t trackno;
b2b13ee2 483 Int_t smnumber;
484 Int_t trackpid;
485 Int_t mtrackno;
486 Int_t mtrackpid;
487
488 Float_t xPos, yPos, zPos;
8599803d 489 Int_t xpad = -1, ypad = -1;
b2b13ee2 490 Float_t edep;
491 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
492
ebd83c56 493 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
b2b13ee2 494 ResetDigit();
495
5e2cc5bc 496 AliDebug(1,Form("Event Number = %d",ievt));
b2b13ee2 497 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
ecee2a1a 498 AliDebug(1,Form("Number of Particles = %d", nparticles));
b2b13ee2 499 fRunLoader->GetEvent(ievt);
b2b13ee2 500 // ------------------------------------------------------- //
501 // Pointer to specific detector hits.
502 // Get pointers to Alice detectors and Hits containers
503
b208c6a3 504 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
36031625 505 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
b2b13ee2 506
36031625 507 if (fPMDLoader == 0x0)
b2b13ee2 508 {
ecee2a1a 509 AliError("Can not find PMD or PMDLoader");
b2b13ee2 510 }
ebd83c56 511 TTree* treeH = fPMDLoader->TreeH();
512 Int_t ntracks = (Int_t) treeH->GetEntries();
ecee2a1a 513 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
36031625 514 fPMDLoader->LoadDigits("recreate");
ebd83c56 515 TTree* treeD = fPMDLoader->TreeD();
516 if (treeD == 0x0)
b2b13ee2 517 {
36031625 518 fPMDLoader->MakeTree("D");
ebd83c56 519 treeD = fPMDLoader->TreeD();
b2b13ee2 520 }
521 Int_t bufsize = 16000;
5e2cc5bc 522 treeD->Branch("PMDDigit", &fDigits, bufsize);
b2b13ee2 523
ebd83c56 524 TClonesArray* hits = 0;
525 if (fPMD) hits = fPMD->Hits();
b2b13ee2 526
527 // Start loop on tracks in the hits containers
528
5e2cc5bc 529 for (Int_t track=0; track<ntracks;track++)
b2b13ee2 530 {
3e2e3ece 531 gAlice->GetMCApp()->ResetHits();
ebd83c56 532 treeH->GetEvent(track);
b2b13ee2 533
5e2cc5bc 534 if (fPMD)
b2b13ee2 535 {
ebd83c56 536 npmd = hits->GetEntriesFast();
4d59e381 537 for (Int_t ipmd = 0; ipmd < npmd; ipmd++)
b2b13ee2 538 {
ebd83c56 539 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
36031625 540 trackno = fPMDHit->GetTrack();
b2b13ee2 541
542 // get kinematics of the particles
543
ebd83c56 544 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
545 trackpid = mparticle->GetPdgCode();
4d59e381 546 Int_t ks = mparticle->GetStatusCode();
b2b13ee2 547 Int_t imo;
36031625 548 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
8599803d 549 if (mparticle->GetFirstMother() == -1)
550 {
36031625 551 tracknoOld = trackno;
552 trackpidOld = trackpid;
553 statusOld = -1;
8599803d 554 }
555
556 Int_t igstatus = 0;
4d59e381 557 //-----------------------modified by Mriganka ------------------
d934d257 558 Int_t trnotemp = trackno;
4d59e381 559 if(ks==1||(imo = mparticle->GetFirstMother())<0 ){
560 vx = mparticle->Vx();
561 vy = mparticle->Vy();
562 vz = mparticle->Vz();
563
564 if(trackpid==kGamma||trackpid==11||trackpid==-11||trackpid==kPi0)
565 igstatus=1;
566 }
567
568
569 while(((imo = mparticle->GetFirstMother()) >= 0)&&
570 (ks = mparticle->GetStatusCode() <1) )
b2b13ee2 571 {
b208c6a3 572 mparticle = gAlice->GetMCApp()->Particle(imo);
4d59e381 573 trackpid = mparticle->GetPdgCode();
574 ks = mparticle->GetStatusCode();
b2b13ee2 575 vx = mparticle->Vx();
576 vy = mparticle->Vy();
577 vz = mparticle->Vz();
d934d257 578 trnotemp = trackno;
579 if(trackpid == 111)
580 {
581 trackno = trnotemp;
b2b13ee2 582 }
d934d257 583 if(trackpid != 111)
584 {
585 trackno = imo;
586 }
587 }
4d59e381 588
589 if(trackpid==kGamma||trackpid==11||trackpid==-11||trackpid==kPi0)
590 igstatus=1;
591 mtrackpid=trackpid;
592 mtrackno=trackno;
593 trackpid=trackpidOld;
594 trackno=tracknoOld;
b2b13ee2 595
4d59e381 596 //-----------------end of modification----------------
36031625 597 xPos = fPMDHit->X();
598 yPos = fPMDHit->Y();
599 zPos = fPMDHit->Z();
f117e3aa 600 edep = fPMDHit->GetEnergy();
c35544fe 601 Int_t vol1 = fPMDHit->GetVolume(1); // Column
602 Int_t vol2 = fPMDHit->GetVolume(2); // Row
f117e3aa 603 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
604 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
605
8599803d 606
607 // -----------------------------------------//
f117e3aa 608 // In new geometry after adding electronics //
8599803d 609 // For Super Module 1 & 2 //
8599803d 610 // nrow = 48, ncol = 96 //
f117e3aa 611 // For Super Module 3 & 4 //
612 // nrow = 96, ncol = 48 //
8599803d 613 // -----------------------------------------//
b2b13ee2 614
f117e3aa 615 smnumber = (vol8-1)*6 + vol7;
8599803d 616
f117e3aa 617 if (vol8 == 1 || vol8 == 2)
8599803d 618 {
36031625 619 xpad = vol2;
620 ypad = vol1;
b2b13ee2 621 }
f117e3aa 622 else if (vol8 == 3 || vol8 == 4)
623 {
624 xpad = vol1;
625 ypad = vol2;
626 }
b2b13ee2 627
ecee2a1a 628 AliDebug(2,Form("ZPosition = %f Edeposition = %d",zPos,edep));
f117e3aa 629 //Float_t zposition = TMath::Abs(zPos);
8599803d 630
f117e3aa 631 if (zPos < fZPos)
b2b13ee2 632 {
633 // CPV
634 fDetNo = 1;
635 }
f117e3aa 636 else if (zPos > fZPos)
b2b13ee2 637 {
638 // PMD
639 fDetNo = 0;
640 }
8599803d 641
642 Int_t smn = smnumber - 1;
643 Int_t ixx = xpad - 1;
644 Int_t iyy = ypad - 1;
645 if (fDetNo == 0)
b2b13ee2 646 {
36031625 647 fPRE[smn][ixx][iyy] += edep;
648 fPRECounter[smn][ixx][iyy]++;
8599803d 649
ebd83c56 650 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
8599803d 651
ebd83c56 652 fCell.Add(cell);
b2b13ee2 653 }
8599803d 654 else if(fDetNo == 1)
b2b13ee2 655 {
8599803d 656 fCPV[smn][ixx][iyy] += edep;
4d59e381 657 fCPVCounter[smn][ixx][iyy]++;
658 AliPMDcell* cpvcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
659 fCPVCell.Add(cpvcell);
b2b13ee2 660 }
661 }
662 }
663 } // Track Loop ended
4d59e381 664 TrackAssignment2CPVCell();
b2b13ee2 665 TrackAssignment2Cell();
666 ResetCell();
667
50555ba1 668 Float_t gain1;
7088dbe9 669 Float_t adc;
b2b13ee2 670 Float_t deltaE = 0.;
671 Int_t detno = 0;
b2b13ee2 672 Int_t trno = 1;
b2b13ee2 673 for (Int_t idet = 0; idet < 2; idet++)
5e2cc5bc 674 {
36031625 675 for (Int_t ism = 0; ism < fgkTotUM; ism++)
5e2cc5bc 676 {
36031625 677 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
5e2cc5bc 678 {
36031625 679 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
5e2cc5bc 680 {
b2b13ee2 681 if (idet == 0)
5e2cc5bc 682 {
683 deltaE = fPRE[ism][jrow][kcol];
36031625 684 trno = fPRETrackNo[ism][jrow][kcol];
b2b13ee2 685 detno = 0;
5e2cc5bc 686 }
b2b13ee2 687 else if (idet == 1)
5e2cc5bc 688 {
689 deltaE = fCPV[ism][jrow][kcol];
8599803d 690 trno = fCPVTrackNo[ism][jrow][kcol];
b2b13ee2 691 detno = 1;
5e2cc5bc 692 }
b2b13ee2 693 if (deltaE > 0.)
5e2cc5bc 694 {
7088dbe9 695 MeV2ADC(deltaE,adc);
5e2cc5bc 696
697 // To decalibrate the adc values
698 //
699 gain1 = Gain(idet,ism,jrow,kcol);
700 if (gain1 != 0.)
701 {
702 Int_t adcDecalib = (Int_t)(adc/gain1);
703 adc = (Float_t) adcDecalib;
704 }
705 else if(gain1 == 0.)
706 {
707 adc = 0.;
708 }
35535af7 709
710 // Pedestal Decalibration
711 Int_t pedmeanrms =
712 fCalibPed->GetPedMeanRms(idet,ism,jrow,kcol);
37edc588 713 Int_t pedrms1 = (Int_t) pedmeanrms%100;
35535af7 714 Float_t pedrms = (Float_t)pedrms1/10.;
715 Float_t pedmean =
716 (Float_t) (pedmeanrms - pedrms1)/1000.0;
35535af7 717 if (adc > 0.)
718 {
719 adc += (pedmean + 3.0*pedrms);
720 AddDigit(trno,detno,ism,jrow,kcol,adc);
721 }
5e2cc5bc 722 }
723 } // column loop
724 } // row loop
03965b13 725 treeD->Fill();
726 ResetDigit();
5e2cc5bc 727 } // supermodule loop
728 } // detector loop
03965b13 729
36031625 730 fPMDLoader->WriteDigits("OVERWRITE");
b2b13ee2 731 ResetCellADC();
50555ba1 732
b2b13ee2 733}
7088dbe9 734//____________________________________________________________________________
b2b13ee2 735
736
737void AliPMDDigitizer::SDigits2Digits(Int_t ievt)
738{
36031625 739 // This reads the PMD sdigits tree and converts energy deposition
740 // in a cell to ADC and stores in the digits tree
741 //
ecee2a1a 742
b2b13ee2 743 fRunLoader->GetEvent(ievt);
744
ebd83c56 745 TTree* treeS = fPMDLoader->TreeS();
b2b13ee2 746 AliPMDsdigit *pmdsdigit;
ebd83c56 747 TBranch *branch = treeS->GetBranch("PMDSDigit");
ecee2a1a 748 if(!branch)
749 {
750 AliError("PMD Sdigit branch does not exist");
751 return;
752 }
ebd83c56 753 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
b2b13ee2 754 branch->SetAddress(&fSDigits);
755
ebd83c56 756 TTree* treeD = fPMDLoader->TreeD();
757 if (treeD == 0x0)
b2b13ee2 758 {
36031625 759 fPMDLoader->MakeTree("D");
ebd83c56 760 treeD = fPMDLoader->TreeD();
b2b13ee2 761 }
762 Int_t bufsize = 16000;
ebd83c56 763 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
5e2cc5bc 764 treeD->Branch("PMDDigit", &fDigits, bufsize);
b2b13ee2 765
766 Int_t trno, det, smn;
7088dbe9 767 Int_t irow, icol;
b2b13ee2 768 Float_t edep, adc;
769
ebd83c56 770 Int_t nmodules = (Int_t) treeS->GetEntries();
ecee2a1a 771 AliDebug(1,Form("Number of modules = %d",nmodules));
b2b13ee2 772
773 for (Int_t imodule = 0; imodule < nmodules; imodule++)
774 {
5e2cc5bc 775 treeS->GetEntry(imodule);
b2b13ee2 776 Int_t nentries = fSDigits->GetLast();
ecee2a1a 777 AliDebug(2,Form("Number of entries per module = %d",nentries+1));
b2b13ee2 778 for (Int_t ient = 0; ient < nentries+1; ient++)
779 {
780 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
781 trno = pmdsdigit->GetTrackNumber();
782 det = pmdsdigit->GetDetector();
783 smn = pmdsdigit->GetSMNumber();
7088dbe9 784 irow = pmdsdigit->GetRow();
785 icol = pmdsdigit->GetColumn();
b2b13ee2 786 edep = pmdsdigit->GetCellEdep();
787
788 MeV2ADC(edep,adc);
5e2cc5bc 789
790 // To decalibrte the adc values
791 //
792 Float_t gain1 = Gain(det,smn,irow,icol);
793 if (gain1 != 0.)
794 {
04a35d8d 795 Int_t adcDecalib = (Int_t)(adc/gain1);
796 adc = (Float_t) adcDecalib;
5e2cc5bc 797 }
798 else if(gain1 == 0.)
799 {
800 adc = 0.;
801 }
35535af7 802 // Pedestal Decalibration
803 Int_t pedmeanrms = fCalibPed->GetPedMeanRms(det,smn,irow,icol);
37edc588 804 Int_t pedrms1 = (Int_t) pedmeanrms%100;
35535af7 805 Float_t pedrms = (Float_t)pedrms1/10.;
806 Float_t pedmean = (Float_t) (pedmeanrms - pedrms1)/1000.0;
35535af7 807 if(adc > 0.)
808 {
809 adc += (pedmean + 3.0*pedrms);
810 AddDigit(trno,det,smn,irow,icol,adc);
811 }
5e2cc5bc 812
b2b13ee2 813 }
ebd83c56 814 treeD->Fill();
b2b13ee2 815 ResetDigit();
816 }
36031625 817 fPMDLoader->WriteDigits("OVERWRITE");
ecee2a1a 818
b2b13ee2 819}
7088dbe9 820//____________________________________________________________________________
821void AliPMDDigitizer::Exec(Option_t *option)
822{
823 // Does the event merging and digitization
7088dbe9 824 const char *cdeb = strstr(option,"deb");
825 if(cdeb)
826 {
ecee2a1a 827 AliDebug(100," *** PMD Exec is called ***");
7088dbe9 828 }
ecee2a1a 829
7088dbe9 830 Int_t ninputs = fManager->GetNinputs();
ecee2a1a 831 AliDebug(1,Form("Number of files to be processed = %d",ninputs));
7088dbe9 832 ResetCellADC();
833
834 for (Int_t i = 0; i < ninputs; i++)
835 {
836 Int_t troffset = fManager->GetMask(i);
837 MergeSDigits(i, troffset);
838 }
b2b13ee2 839
7088dbe9 840 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
841 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
842 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
843 if (fPMDLoader == 0x0)
844 {
ecee2a1a 845 AliError("Can not find PMD or PMDLoader");
7088dbe9 846 }
06f2c79d 847 fPMDLoader->LoadDigits("update");
ebd83c56 848 TTree* treeD = fPMDLoader->TreeD();
849 if (treeD == 0x0)
7088dbe9 850 {
851 fPMDLoader->MakeTree("D");
ebd83c56 852 treeD = fPMDLoader->TreeD();
7088dbe9 853 }
854 Int_t bufsize = 16000;
ebd83c56 855 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
5e2cc5bc 856 treeD->Branch("PMDDigit", &fDigits, bufsize);
7088dbe9 857
858 Float_t adc;
859 Float_t deltaE = 0.;
860 Int_t detno = 0;
861 Int_t trno = 1;
862
863 for (Int_t idet = 0; idet < 2; idet++)
864 {
865 for (Int_t ism = 0; ism < fgkTotUM; ism++)
866 {
867 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
868 {
869 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
870 {
871 if (idet == 0)
872 {
873 deltaE = fPRE[ism][jrow][kcol];
874 trno = fPRETrackNo[ism][jrow][kcol];
875 detno = 0;
876 }
877 else if (idet == 1)
878 {
879 deltaE = fCPV[ism][jrow][kcol];
880 trno = fCPVTrackNo[ism][jrow][kcol];
881 detno = 1;
882 }
883 if (deltaE > 0.)
884 {
885 MeV2ADC(deltaE,adc);
35535af7 886
5f566ada 887 //
35535af7 888 // Gain decalibration
5f566ada 889 //
890 Float_t gain1 = Gain(idet,ism,jrow,kcol);
35535af7 891
5f566ada 892 if (gain1 != 0.)
893 {
894 Int_t adcDecalib = (Int_t)(adc/gain1);
895 adc = (Float_t) adcDecalib;
896 }
897 else if(gain1 == 0.)
898 {
899 adc = 0.;
900 }
35535af7 901 // Pedestal Decalibration
902 Int_t pedmeanrms =
903 fCalibPed->GetPedMeanRms(idet,ism,jrow,kcol);
37edc588 904 Int_t pedrms1 = (Int_t) pedmeanrms%100;
35535af7 905 Float_t pedrms = (Float_t)pedrms1/10.;
906 Float_t pedmean =
907 (Float_t) (pedmeanrms - pedrms1)/1000.0;
35535af7 908 if (adc > 0.)
909 {
910 adc += (pedmean + 3.0*pedrms);
911 AddDigit(trno,detno,ism,jrow,kcol,adc);
912 }
5f566ada 913
7088dbe9 914 }
915 } // column loop
916 } // row loop
ebd83c56 917 treeD->Fill();
7088dbe9 918 ResetDigit();
919 } // supermodule loop
920 } // detector loop
5e2cc5bc 921 fPMDLoader->WriteDigits("OVERWRITE");
06f2c79d 922 fPMDLoader->UnloadDigits();
923 ResetCellADC();
7088dbe9 924}
925//____________________________________________________________________________
4d59e381 926void AliPMDDigitizer::TrackAssignment2CPVCell()
927{
928 // This block assigns the cell id when there are
929 // multiple tracks in a cell according to the
930 // energy deposition
931 // This method added by Ajay
932 Bool_t jsort = false;
933
934 Int_t i, j, k;
935
936 Int_t *status1;
937 Int_t *status2;
938 Int_t *trnarray;
939 Float_t *fracEdp;
940 Float_t *trEdp;
941
942 Int_t ****cpvTrack;
943 Float_t ****cpvEdep;
944
945 cpvTrack = new Int_t ***[fgkTotUM];
946 cpvEdep = new Float_t ***[fgkTotUM];
947 for (i=0; i<fgkTotUM; i++)
948 {
949 cpvTrack[i] = new Int_t **[fgkRow];
950 cpvEdep[i] = new Float_t **[fgkRow];
951 }
952
953 for (i = 0; i < fgkTotUM; i++)
954 {
955 for (j = 0; j < fgkRow; j++)
956 {
957 cpvTrack[i][j] = new Int_t *[fgkCol];
958 cpvEdep[i][j] = new Float_t *[fgkCol];
959 }
960 }
961 for (i = 0; i < fgkTotUM; i++)
962 {
963 for (j = 0; j < fgkRow; j++)
964 {
965 for (k = 0; k < fgkCol; k++)
966 {
967 Int_t nn = fCPVCounter[i][j][k];
968 if(nn > 0)
969 {
970 cpvTrack[i][j][k] = new Int_t[nn];
971 cpvEdep[i][j][k] = new Float_t[nn];
972 }
973 else
974 {
975 nn = 1;
976 cpvTrack[i][j][k] = new Int_t[nn];
977 cpvEdep[i][j][k] = new Float_t[nn];
978 }
979 fCPVCounter[i][j][k] = 0;
980 }
981 }
982 }
983
984
985 Int_t nentries = fCPVCell.GetEntries();
986
987 Int_t mtrackno, ism, ixp, iyp;
988 Float_t edep;
989 for (i = 0; i < nentries; i++)
990 {
991 AliPMDcell* cpvcell = (AliPMDcell*)fCPVCell.UncheckedAt(i);
992
993 mtrackno = cpvcell->GetTrackNumber();
994 ism = cpvcell->GetSMNumber();
995 ixp = cpvcell->GetX();
996 iyp = cpvcell->GetY();
997 edep = cpvcell->GetEdep();
998 Int_t nn = fCPVCounter[ism][ixp][iyp];
999 cpvTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
1000 cpvEdep[ism][ixp][iyp][nn] = edep;
1001 fCPVCounter[ism][ixp][iyp]++;
1002 }
1003
1004 Int_t iz, il;
1005 Int_t im, ix, iy;
1006 Int_t nn;
1007 for (im=0; im<fgkTotUM; im++)
1008 {
1009 for (ix=0; ix<fgkRow; ix++)
1010 {
1011 for (iy=0; iy<fgkCol; iy++)
1012 {
1013 nn = fCPVCounter[im][ix][iy];
1014 if (nn > 1)
1015 {
1016 // This block handles if a cell is fired
1017 // many times by many tracks
1018 status1 = new Int_t[nn];
1019 status2 = new Int_t[nn];
1020 trnarray = new Int_t[nn];
1021 for (iz = 0; iz < nn; iz++)
1022 {
1023 status1[iz] = cpvTrack[im][ix][iy][iz];
1024 }
1025 TMath::Sort(nn,status1,status2,jsort);
1026 Int_t trackOld = -99999;
1027 Int_t track, trCount = 0;
1028 for (iz = 0; iz < nn; iz++)
1029 {
1030 track = status1[status2[iz]];
1031 if (trackOld != track)
1032 {
1033 trnarray[trCount] = track;
1034 trCount++;
1035 }
1036 trackOld = track;
1037 }
1038 delete [] status1;
1039 delete [] status2;
1040 Float_t totEdp = 0.;
1041 trEdp = new Float_t[trCount];
1042 fracEdp = new Float_t[trCount];
1043 for (il = 0; il < trCount; il++)
1044 {
1045 trEdp[il] = 0.;
1046 track = trnarray[il];
1047 for (iz = 0; iz < nn; iz++)
1048 {
1049 if (track == cpvTrack[im][ix][iy][iz])
1050 {
1051 trEdp[il] += cpvEdep[im][ix][iy][iz];
1052 }
1053 }
1054 totEdp += trEdp[il];
1055 }
1056 Int_t ilOld = 0;
1057 Float_t fracOld = 0.;
1058
1059 for (il = 0; il < trCount; il++)
1060 {
1061 fracEdp[il] = trEdp[il]/totEdp;
1062 if (fracOld < fracEdp[il])
1063 {
1064 fracOld = fracEdp[il];
1065 ilOld = il;
1066 }
1067 }
1068 fCPVTrackNo[im][ix][iy] = trnarray[ilOld];
1069 delete [] fracEdp;
1070 delete [] trEdp;
1071 delete [] trnarray;
1072 }
1073 else if (nn == 1)
1074 {
1075 // This only handles if a cell is fired
1076 // by only one track
1077
1078 fCPVTrackNo[im][ix][iy] = cpvTrack[im][ix][iy][0];
1079
1080 }
1081 else if (nn ==0)
1082 {
1083 // This is if no cell is fired
1084 fCPVTrackNo[im][ix][iy] = -999;
1085 }
1086 } // end of iy
1087 } // end of ix
1088 } // end of im
1089
1090 // Delete all the pointers
1091
1092 for (i = 0; i < fgkTotUM; i++)
1093 {
1094 for (j = 0; j < fgkRow; j++)
1095 {
1096 for (k = 0; k < fgkCol; k++)
1097 {
1098 delete []cpvTrack[i][j][k];
1099 delete []cpvEdep[i][j][k];
1100 }
1101 }
1102 }
1103
1104 for (i = 0; i < fgkTotUM; i++)
1105 {
1106 for (j = 0; j < fgkRow; j++)
1107 {
1108 delete [] cpvTrack[i][j];
1109 delete [] cpvEdep[i][j];
1110 }
1111 }
1112
1113 for (i = 0; i < fgkTotUM; i++)
1114 {
1115 delete [] cpvTrack[i];
1116 delete [] cpvEdep[i];
1117 }
1118 delete [] cpvTrack;
1119 delete [] cpvEdep;
1120
1121 //
1122 // End of the cell id assignment
1123 //
1124}
1125//____________________________________________________________________________
7088dbe9 1126
1127void AliPMDDigitizer::MergeSDigits(Int_t filenumber, Int_t troffset)
1128{
1129 // merging sdigits
1130 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(filenumber));
1131 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
1132 fPMDLoader->LoadSDigits("read");
ebd83c56 1133 TTree* treeS = fPMDLoader->TreeS();
7088dbe9 1134 AliPMDsdigit *pmdsdigit;
ebd83c56 1135 TBranch *branch = treeS->GetBranch("PMDSDigit");
1136 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
7088dbe9 1137 branch->SetAddress(&fSDigits);
1138
1139 Int_t itrackno, idet, ism;
1140 Int_t ixp, iyp;
1141 Float_t edep;
ebd83c56 1142 Int_t nmodules = (Int_t) treeS->GetEntries();
ecee2a1a 1143 AliDebug(1,Form("Number of Modules in the treeS = %d",nmodules));
1144 AliDebug(1,Form("Track Offset = %d",troffset));
7088dbe9 1145 for (Int_t imodule = 0; imodule < nmodules; imodule++)
1146 {
5e2cc5bc 1147 treeS->GetEntry(imodule);
7088dbe9 1148 Int_t nentries = fSDigits->GetLast();
ecee2a1a 1149 AliDebug(2,Form("Number of Entries per Module = %d",nentries));
7088dbe9 1150 for (Int_t ient = 0; ient < nentries+1; ient++)
1151 {
1152 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
1153 itrackno = pmdsdigit->GetTrackNumber();
1154 idet = pmdsdigit->GetDetector();
1155 ism = pmdsdigit->GetSMNumber();
1156 ixp = pmdsdigit->GetRow();
1157 iyp = pmdsdigit->GetColumn();
1158 edep = pmdsdigit->GetCellEdep();
7088dbe9 1159 if (idet == 0)
1160 {
1161 if (fPRE[ism][ixp][iyp] < edep)
1162 {
1163 fPRETrackNo[ism][ixp][iyp] = troffset + itrackno;
1164 }
1165 fPRE[ism][ixp][iyp] += edep;
1166 }
1167 else if (idet == 1)
1168 {
1169 if (fCPV[ism][ixp][iyp] < edep)
1170 {
1171 fCPVTrackNo[ism][ixp][iyp] = troffset + itrackno;
1172 }
1173 fCPV[ism][ixp][iyp] += edep;
1174 }
1175 }
1176 }
1177
1178}
1179// ----------------------------------------------------------------------
b2b13ee2 1180void AliPMDDigitizer::TrackAssignment2Cell()
1181{
b2b13ee2 1182 //
75bb524e 1183 // This block assigns the cell id when there are
b2b13ee2 1184 // multiple tracks in a cell according to the
1185 // energy deposition
1186 //
75bb524e 1187 Bool_t jsort = false;
8599803d 1188
b2b13ee2 1189 Int_t i, j, k;
1190
4d59e381 1191 Int_t *status1;
1192 Int_t *status2;
1193 Int_t *trnarray;
36031625 1194 Float_t *fracEdp;
1195 Float_t *trEdp;
4d59e381 1196
36031625 1197 Int_t ****pmdTrack;
1198 Float_t ****pmdEdep;
b2b13ee2 1199
36031625 1200 pmdTrack = new Int_t ***[fgkTotUM];
1201 pmdEdep = new Float_t ***[fgkTotUM];
1202 for (i=0; i<fgkTotUM; i++)
b2b13ee2 1203 {
36031625 1204 pmdTrack[i] = new Int_t **[fgkRow];
1205 pmdEdep[i] = new Float_t **[fgkRow];
b2b13ee2 1206 }
1207
36031625 1208 for (i = 0; i < fgkTotUM; i++)
b2b13ee2 1209 {
36031625 1210 for (j = 0; j < fgkRow; j++)
b2b13ee2 1211 {
36031625 1212 pmdTrack[i][j] = new Int_t *[fgkCol];
1213 pmdEdep[i][j] = new Float_t *[fgkCol];
b2b13ee2 1214 }
1215 }
1216
36031625 1217 for (i = 0; i < fgkTotUM; i++)
b2b13ee2 1218 {
36031625 1219 for (j = 0; j < fgkRow; j++)
b2b13ee2 1220 {
36031625 1221 for (k = 0; k < fgkCol; k++)
b2b13ee2 1222 {
36031625 1223 Int_t nn = fPRECounter[i][j][k];
b2b13ee2 1224 if(nn > 0)
1225 {
36031625 1226 pmdTrack[i][j][k] = new Int_t[nn];
1227 pmdEdep[i][j][k] = new Float_t[nn];
b2b13ee2 1228 }
1229 else
1230 {
1231 nn = 1;
36031625 1232 pmdTrack[i][j][k] = new Int_t[nn];
1233 pmdEdep[i][j][k] = new Float_t[nn];
5e2cc5bc 1234 }
36031625 1235 fPRECounter[i][j][k] = 0;
b2b13ee2 1236 }
1237 }
1238 }
1239
1240
ebd83c56 1241 Int_t nentries = fCell.GetEntries();
b2b13ee2 1242
1243 Int_t mtrackno, ism, ixp, iyp;
1244 Float_t edep;
1245
1246 for (i = 0; i < nentries; i++)
1247 {
ebd83c56 1248 AliPMDcell* cell = (AliPMDcell*)fCell.UncheckedAt(i);
b2b13ee2 1249
ebd83c56 1250 mtrackno = cell->GetTrackNumber();
1251 ism = cell->GetSMNumber();
1252 ixp = cell->GetX();
1253 iyp = cell->GetY();
1254 edep = cell->GetEdep();
36031625 1255 Int_t nn = fPRECounter[ism][ixp][iyp];
36031625 1256 pmdTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
1257 pmdEdep[ism][ixp][iyp][nn] = edep;
1258 fPRECounter[ism][ixp][iyp]++;
b2b13ee2 1259 }
1260
1261 Int_t iz, il;
1262 Int_t im, ix, iy;
1263 Int_t nn;
1264
36031625 1265 for (im=0; im<fgkTotUM; im++)
b2b13ee2 1266 {
36031625 1267 for (ix=0; ix<fgkRow; ix++)
b2b13ee2 1268 {
36031625 1269 for (iy=0; iy<fgkCol; iy++)
b2b13ee2 1270 {
36031625 1271 nn = fPRECounter[im][ix][iy];
b2b13ee2 1272 if (nn > 1)
1273 {
1274 // This block handles if a cell is fired
1275 // many times by many tracks
75bb524e 1276 status1 = new Int_t[nn];
1277 status2 = new Int_t[nn];
1278 trnarray = new Int_t[nn];
b2b13ee2 1279 for (iz = 0; iz < nn; iz++)
1280 {
36031625 1281 status1[iz] = pmdTrack[im][ix][iy][iz];
b2b13ee2 1282 }
75bb524e 1283 TMath::Sort(nn,status1,status2,jsort);
36031625 1284 Int_t trackOld = -99999;
1285 Int_t track, trCount = 0;
b2b13ee2 1286 for (iz = 0; iz < nn; iz++)
1287 {
75bb524e 1288 track = status1[status2[iz]];
36031625 1289 if (trackOld != track)
b2b13ee2 1290 {
36031625 1291 trnarray[trCount] = track;
1292 trCount++;
5e2cc5bc 1293 }
36031625 1294 trackOld = track;
b2b13ee2 1295 }
6eb80a7c 1296 delete [] status1;
1297 delete [] status2;
36031625 1298 Float_t totEdp = 0.;
1299 trEdp = new Float_t[trCount];
1300 fracEdp = new Float_t[trCount];
1301 for (il = 0; il < trCount; il++)
b2b13ee2 1302 {
36031625 1303 trEdp[il] = 0.;
75bb524e 1304 track = trnarray[il];
b2b13ee2 1305 for (iz = 0; iz < nn; iz++)
1306 {
36031625 1307 if (track == pmdTrack[im][ix][iy][iz])
b2b13ee2 1308 {
36031625 1309 trEdp[il] += pmdEdep[im][ix][iy][iz];
b2b13ee2 1310 }
1311 }
36031625 1312 totEdp += trEdp[il];
b2b13ee2 1313 }
36031625 1314 Int_t ilOld = 0;
1315 Float_t fracOld = 0.;
b2b13ee2 1316
36031625 1317 for (il = 0; il < trCount; il++)
b2b13ee2 1318 {
36031625 1319 fracEdp[il] = trEdp[il]/totEdp;
1320 if (fracOld < fracEdp[il])
b2b13ee2 1321 {
36031625 1322 fracOld = fracEdp[il];
1323 ilOld = il;
b2b13ee2 1324 }
1325 }
36031625 1326 fPRETrackNo[im][ix][iy] = trnarray[ilOld];
6eb80a7c 1327 delete [] fracEdp;
1328 delete [] trEdp;
1329 delete [] trnarray;
b2b13ee2 1330 }
1331 else if (nn == 1)
1332 {
1333 // This only handles if a cell is fired
1334 // by only one track
1335
36031625 1336 fPRETrackNo[im][ix][iy] = pmdTrack[im][ix][iy][0];
b2b13ee2 1337
1338 }
1339 else if (nn ==0)
1340 {
1341 // This is if no cell is fired
36031625 1342 fPRETrackNo[im][ix][iy] = -999;
b2b13ee2 1343 }
1344 } // end of iy
1345 } // end of ix
1346 } // end of im
1347
1348 // Delete all the pointers
1349
36031625 1350 for (i = 0; i < fgkTotUM; i++)
b2b13ee2 1351 {
36031625 1352 for (j = 0; j < fgkRow; j++)
b2b13ee2 1353 {
36031625 1354 for (k = 0; k < fgkCol; k++)
b2b13ee2 1355 {
36031625 1356 delete [] pmdTrack[i][j][k];
1357 delete [] pmdEdep[i][j][k];
b2b13ee2 1358 }
1359 }
1360 }
1361
36031625 1362 for (i = 0; i < fgkTotUM; i++)
b2b13ee2 1363 {
36031625 1364 for (j = 0; j < fgkRow; j++)
b2b13ee2 1365 {
36031625 1366 delete [] pmdTrack[i][j];
1367 delete [] pmdEdep[i][j];
b2b13ee2 1368 }
1369 }
1370
36031625 1371 for (i = 0; i < fgkTotUM; i++)
b2b13ee2 1372 {
36031625 1373 delete [] pmdTrack[i];
1374 delete [] pmdEdep[i];
b2b13ee2 1375 }
6eb80a7c 1376 delete [] pmdTrack;
1377 delete [] pmdEdep;
b2b13ee2 1378 //
1379 // End of the cell id assignment
1380 //
1381}
7088dbe9 1382//____________________________________________________________________________
a7d110b8 1383void AliPMDDigitizer::MeV2ADC(Float_t mev, Float_t & adc) const
b2b13ee2 1384{
36031625 1385 // This converts the simulated edep to ADC according to the
1386 // Test Beam Data
4d59e381 1387 //PS Test in September 2003 and 2006
1388 // KeV - ADC conversion for 12bit ADC
1389 // Modified by Ajay
04a35d8d 1390
1391 const Float_t kConstant = 0.07;
1392 const Float_t kErConstant = 0.1;
1393 const Float_t kSlope = 76.0;
1394 const Float_t kErSlope = 5.0;
4d59e381 1395
b8e69f1f 1396 Float_t cons = gRandom->Gaus(kConstant,kErConstant);
1397 Float_t slop = gRandom->Gaus(kSlope,kErSlope);
4d59e381 1398
1399 Float_t adc12bit = slop*mev*0.001 + cons;
1400
04a35d8d 1401
4d59e381 1402 if(adc12bit < 1600.0)
b8e69f1f 1403 {
1404 adc = (Float_t) adc12bit;
1405 }
4d59e381 1406 else if (adc12bit >= 1600.0)
b8e69f1f 1407 {
4d59e381 1408 adc = 1600.0;
b8e69f1f 1409 }
b2b13ee2 1410}
7088dbe9 1411//____________________________________________________________________________
5e2cc5bc 1412void AliPMDDigitizer::AddSDigit(Int_t trnumber, Int_t det, Int_t smnumber,
1413 Int_t irow, Int_t icol, Float_t adc)
b2b13ee2 1414{
36031625 1415 // Add SDigit
1416 //
ebd83c56 1417 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
b2b13ee2 1418 TClonesArray &lsdigits = *fSDigits;
7088dbe9 1419 new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,det,smnumber,irow,icol,adc);
b2b13ee2 1420}
7088dbe9 1421//____________________________________________________________________________
b2b13ee2 1422
5e2cc5bc 1423void AliPMDDigitizer::AddDigit(Int_t trnumber, Int_t det, Int_t smnumber,
1424 Int_t irow, Int_t icol, Float_t adc)
b2b13ee2 1425{
36031625 1426 // Add Digit
1427 //
ebd83c56 1428 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
b2b13ee2 1429 TClonesArray &ldigits = *fDigits;
7088dbe9 1430 new(ldigits[fNdigit++]) AliPMDdigit(trnumber,det,smnumber,irow,icol,adc);
b2b13ee2 1431}
7088dbe9 1432//____________________________________________________________________________
b2b13ee2 1433
b2b13ee2 1434void AliPMDDigitizer::SetZPosition(Float_t zpos)
1435{
1436 fZPos = zpos;
1437}
7088dbe9 1438//____________________________________________________________________________
b2b13ee2 1439Float_t AliPMDDigitizer::GetZPosition() const
1440{
1441 return fZPos;
1442}
7088dbe9 1443//____________________________________________________________________________
b2b13ee2 1444
1445void AliPMDDigitizer::ResetCell()
1446{
36031625 1447 // clears the cell array and also the counter
1448 // for each cell
1449 //
4d59e381 1450 fCPVCell.Delete();
ebd83c56 1451 fCell.Delete();
36031625 1452 for (Int_t i = 0; i < fgkTotUM; i++)
b2b13ee2 1453 {
36031625 1454 for (Int_t j = 0; j < fgkRow; j++)
b2b13ee2 1455 {
36031625 1456 for (Int_t k = 0; k < fgkCol; k++)
b2b13ee2 1457 {
4d59e381 1458 fCPVCounter[i][j][k] = 0;
5e2cc5bc 1459 fPRECounter[i][j][k] = 0;
b2b13ee2 1460 }
1461 }
1462 }
1463}
7088dbe9 1464//____________________________________________________________________________
b2b13ee2 1465void AliPMDDigitizer::ResetSDigit()
1466{
36031625 1467 // Clears SDigits
b2b13ee2 1468 fNsdigit = 0;
ebd83c56 1469 if (fSDigits) fSDigits->Delete();
b2b13ee2 1470}
7088dbe9 1471//____________________________________________________________________________
b2b13ee2 1472void AliPMDDigitizer::ResetDigit()
1473{
36031625 1474 // Clears Digits
b2b13ee2 1475 fNdigit = 0;
ebd83c56 1476 if (fDigits) fDigits->Delete();
b2b13ee2 1477}
7088dbe9 1478//____________________________________________________________________________
b2b13ee2 1479
1480void AliPMDDigitizer::ResetCellADC()
1481{
7088dbe9 1482 // Clears individual cells edep and track number
36031625 1483 for (Int_t i = 0; i < fgkTotUM; i++)
b2b13ee2 1484 {
36031625 1485 for (Int_t j = 0; j < fgkRow; j++)
b2b13ee2 1486 {
36031625 1487 for (Int_t k = 0; k < fgkCol; k++)
b2b13ee2 1488 {
5e2cc5bc 1489 fCPV[i][j][k] = 0.;
1490 fPRE[i][j][k] = 0.;
7088dbe9 1491 fCPVTrackNo[i][j][k] = 0;
4d59e381 1492 fPRETrackNo[i][j][k] = 0;
b2b13ee2 1493 }
1494 }
1495 }
1496}
7088dbe9 1497//____________________________________________________________________________
b2b13ee2 1498
1499void AliPMDDigitizer::UnLoad(Option_t *option)
1500{
36031625 1501 // Unloads all the root files
1502 //
b2b13ee2 1503 const char *cS = strstr(option,"S");
1504 const char *cD = strstr(option,"D");
1505
1506 fRunLoader->UnloadgAlice();
1507 fRunLoader->UnloadHeader();
1508 fRunLoader->UnloadKinematics();
1509
1510 if (cS)
1511 {
36031625 1512 fPMDLoader->UnloadHits();
b2b13ee2 1513 }
1514 if (cD)
1515 {
36031625 1516 fPMDLoader->UnloadHits();
1517 fPMDLoader->UnloadSDigits();
b2b13ee2 1518 }
1519}
09a06455 1520
1521//----------------------------------------------------------------------
1522Float_t AliPMDDigitizer::Gain(Int_t det, Int_t smn, Int_t row, Int_t col) const
1523{
1524 // returns of the gain of the cell
1525 // Added this method by ZA
1526
1527 //cout<<" I am here in gain "<<fCalibData<< "smn,row, col "<<smn
1528 //<<" "<<row<<" "<<col<<endl;
1529
35535af7 1530 if(!fCalibGain) {
09a06455 1531 AliError("No calibration data loaded from CDB!!!");
50555ba1 1532 return 1;
09a06455 1533 }
1534
1535 Float_t GainFact;
35535af7 1536 GainFact = fCalibGain->GetGainFact(det,smn,row,col);
09a06455 1537 return GainFact;
1538}
1539//----------------------------------------------------------------------
35535af7 1540AliPMDCalibData* AliPMDDigitizer::GetCalibGain() const
09a06455 1541{
1542 // The run number will be centralized in AliCDBManager,
1543 // you don't need to set it here!
1544 // Added this method by ZA
0dd3d6f9 1545 // Cleaned up by Alberto
35535af7 1546 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Gain");
09a06455 1547
0dd3d6f9 1548 if(!entry) AliFatal("Calibration object retrieval failed!");
09a06455 1549
1550 AliPMDCalibData *calibdata=0;
1551 if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
1552
0dd3d6f9 1553 if (!calibdata) AliFatal("No calibration data from calibration database !");
09a06455 1554
1555 return calibdata;
1556}
35535af7 1557//----------------------------------------------------------------------
1558AliPMDPedestal* AliPMDDigitizer::GetCalibPed() const
1559{
1560 // The run number will be centralized in AliCDBManager,
1561 // you don't need to set it here!
1562
1563 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Ped");
1564
1565 if(!entry) AliFatal("Pedestal object retrieval failed!");
1566
1567 AliPMDPedestal *pedestal=0;
1568 if (entry) pedestal = (AliPMDPedestal*) entry->GetObject();
1569
1570 if (!pedestal) AliFatal("No pedestal data from calibration database !");
1571
1572 return pedestal;
1573}