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