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