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