]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PMD/AliPMDDigitizer.cxx
Bugfixes and additional protection (Cvetan and Marian)
[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();
b2b13ee2 436}
7088dbe9 437//____________________________________________________________________________
b2b13ee2 438
439void AliPMDDigitizer::Hits2Digits(Int_t ievt)
440{
36031625 441 // This reads the PMD Hits tree and assigns the right track number
442 // to a cell and stores in the digits tree
443 //
444 const Int_t kPi0 = 111;
445 const Int_t kGamma = 22;
b2b13ee2 446 Int_t npmd;
447 Int_t trackno;
b2b13ee2 448 Int_t smnumber;
449 Int_t trackpid;
450 Int_t mtrackno;
451 Int_t mtrackpid;
452
453 Float_t xPos, yPos, zPos;
8599803d 454 Int_t xpad = -1, ypad = -1;
b2b13ee2 455 Float_t edep;
456 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
457
ebd83c56 458 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
b2b13ee2 459 ResetDigit();
460
ecee2a1a 461 AliDebug(1,Form("Event Number = %d",ievt));
b2b13ee2 462 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
ecee2a1a 463 AliDebug(1,Form("Number of Particles = %d", nparticles));
b2b13ee2 464 fRunLoader->GetEvent(ievt);
b2b13ee2 465 // ------------------------------------------------------- //
466 // Pointer to specific detector hits.
467 // Get pointers to Alice detectors and Hits containers
468
b208c6a3 469 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
36031625 470 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
b2b13ee2 471
36031625 472 if (fPMDLoader == 0x0)
b2b13ee2 473 {
ecee2a1a 474 AliError("Can not find PMD or PMDLoader");
b2b13ee2 475 }
ebd83c56 476 TTree* treeH = fPMDLoader->TreeH();
477 Int_t ntracks = (Int_t) treeH->GetEntries();
ecee2a1a 478 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
36031625 479 fPMDLoader->LoadDigits("recreate");
ebd83c56 480 TTree* treeD = fPMDLoader->TreeD();
481 if (treeD == 0x0)
b2b13ee2 482 {
36031625 483 fPMDLoader->MakeTree("D");
ebd83c56 484 treeD = fPMDLoader->TreeD();
b2b13ee2 485 }
486 Int_t bufsize = 16000;
ebd83c56 487 treeD->Branch("PMDDigit", &fDigits, bufsize);
b2b13ee2 488
ebd83c56 489 TClonesArray* hits = 0;
490 if (fPMD) hits = fPMD->Hits();
b2b13ee2 491
492 // Start loop on tracks in the hits containers
493
494 for (Int_t track=0; track<ntracks;track++)
495 {
b208c6a3 496 gAlice->ResetHits();
ebd83c56 497 treeH->GetEvent(track);
b2b13ee2 498
36031625 499 if (fPMD)
b2b13ee2 500 {
ebd83c56 501 npmd = hits->GetEntriesFast();
b2b13ee2 502 for (int ipmd = 0; ipmd < npmd; ipmd++)
503 {
ebd83c56 504 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
36031625 505 trackno = fPMDHit->GetTrack();
b2b13ee2 506
507 // get kinematics of the particles
508
ebd83c56 509 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
510 trackpid = mparticle->GetPdgCode();
b2b13ee2 511
512 Int_t igatr = -999;
513 Int_t ichtr = -999;
8599803d 514 Int_t igapid = -999;
b2b13ee2 515 Int_t imo;
516 Int_t igen = 0;
36031625 517 Int_t idmo = -999;
8599803d 518
36031625 519 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
8599803d 520 if (mparticle->GetFirstMother() == -1)
521 {
36031625 522 tracknoOld = trackno;
523 trackpidOld = trackpid;
524 statusOld = -1;
8599803d 525 }
526
527 Int_t igstatus = 0;
b2b13ee2 528 while((imo = mparticle->GetFirstMother()) >= 0)
529 {
530 igen++;
36031625 531
b208c6a3 532 mparticle = gAlice->GetMCApp()->Particle(imo);
36031625 533 idmo = mparticle->GetPdgCode();
b2b13ee2 534
535 vx = mparticle->Vx();
536 vy = mparticle->Vy();
537 vz = mparticle->Vz();
538
36031625 539 //printf("==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
540 //fprintf(fpw1,"==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
541 if ((idmo == kGamma || idmo == -11 || idmo == 11) && vx == 0. && vy == 0. && vz == 0.)
b2b13ee2 542 {
543 igatr = imo;
36031625 544 igapid = idmo;
8599803d 545 igstatus = 1;
546 }
547 if(igstatus == 0)
548 {
36031625 549 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
8599803d 550 {
551 igatr = imo;
36031625 552 igapid = idmo;
8599803d 553 }
b2b13ee2 554 }
555 ichtr = imo;
556 }
557
36031625 558 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
b2b13ee2 559 {
560 mtrackno = igatr;
8599803d 561 mtrackpid = igapid;
b2b13ee2 562 }
563 else
564 {
565 mtrackno = ichtr;
36031625 566 mtrackpid = idmo;
b2b13ee2 567 }
36031625 568 if (statusOld == -1)
8599803d 569 {
36031625 570 mtrackno = tracknoOld;
571 mtrackpid = trackpidOld;
8599803d 572 }
b2b13ee2 573
36031625 574 xPos = fPMDHit->X();
575 yPos = fPMDHit->Y();
576 zPos = fPMDHit->Z();
7088dbe9 577
c35544fe 578 Int_t vol1 = fPMDHit->GetVolume(1); // Column
579 Int_t vol2 = fPMDHit->GetVolume(2); // Row
580 Int_t vol3 = fPMDHit->GetVolume(3); // UnitModule
581 Int_t vol6 = fPMDHit->GetVolume(6); // SuperModule
09a06455 582 edep = fPMDHit->GetEnergy();
8599803d 583
584 // -----------------------------------------//
585 // For Super Module 1 & 2 //
586 // nrow = 96, ncol = 48 //
587 // For Super Module 3 & 4 //
588 // nrow = 48, ncol = 96 //
589 // -----------------------------------------//
b2b13ee2 590
36031625 591 smnumber = (vol6-1)*6 + vol3;
8599803d 592
36031625 593 if (vol6 == 1 || vol6 == 2)
b2b13ee2 594 {
36031625 595 xpad = vol1;
596 ypad = vol2;
8599803d 597 }
36031625 598 else if (vol6 == 3 || vol6 == 4)
8599803d 599 {
36031625 600 xpad = vol2;
601 ypad = vol1;
b2b13ee2 602 }
b2b13ee2 603
ecee2a1a 604 AliDebug(2,Form("ZPosition = %f Edeposition = %d",zPos,edep));
8599803d 605 Float_t zposition = TMath::Abs(zPos);
606
607 if (zposition < fZPos)
b2b13ee2 608 {
609 // CPV
610 fDetNo = 1;
611 }
8599803d 612 else if (zposition > fZPos)
b2b13ee2 613 {
614 // PMD
615 fDetNo = 0;
616 }
8599803d 617
618 Int_t smn = smnumber - 1;
619 Int_t ixx = xpad - 1;
620 Int_t iyy = ypad - 1;
621 if (fDetNo == 0)
b2b13ee2 622 {
36031625 623 fPRE[smn][ixx][iyy] += edep;
624 fPRECounter[smn][ixx][iyy]++;
8599803d 625
ebd83c56 626 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
8599803d 627
ebd83c56 628 fCell.Add(cell);
b2b13ee2 629 }
8599803d 630 else if(fDetNo == 1)
b2b13ee2 631 {
8599803d 632 fCPV[smn][ixx][iyy] += edep;
633 fCPVTrackNo[smn][ixx][iyy] = mtrackno;
b2b13ee2 634 }
635 }
636 }
637 } // Track Loop ended
638
639 TrackAssignment2Cell();
640 ResetCell();
641
50555ba1 642 Float_t gain1;
7088dbe9 643 Float_t adc;
b2b13ee2 644 Float_t deltaE = 0.;
645 Int_t detno = 0;
b2b13ee2 646 Int_t trno = 1;
b2b13ee2 647 for (Int_t idet = 0; idet < 2; idet++)
648 {
36031625 649 for (Int_t ism = 0; ism < fgkTotUM; ism++)
b2b13ee2 650 {
36031625 651 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
b2b13ee2 652 {
36031625 653 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
b2b13ee2 654 {
b2b13ee2 655 if (idet == 0)
656 {
50555ba1 657 gain1 = Gain(idet,ism,jrow,kcol);
658
09a06455 659 deltaE = fPRE[ism][jrow][kcol]*gain1;
36031625 660 trno = fPRETrackNo[ism][jrow][kcol];
b2b13ee2 661 detno = 0;
662 }
663 else if (idet == 1)
664 {
50555ba1 665 gain1 = Gain(idet,ism,jrow,kcol);
666 deltaE = fCPV[ism][jrow][kcol]*gain1;
8599803d 667 trno = fCPVTrackNo[ism][jrow][kcol];
b2b13ee2 668 detno = 1;
669 }
670 if (deltaE > 0.)
671 {
7088dbe9 672 MeV2ADC(deltaE,adc);
673 AddDigit(trno,detno,ism,jrow,kcol,adc);
b2b13ee2 674 }
675 } // column loop
676 } // row loop
03965b13 677 treeD->Fill();
678 ResetDigit();
b2b13ee2 679 } // supermodule loop
b2b13ee2 680 } // detector loop
03965b13 681
36031625 682 fPMDLoader->WriteDigits("OVERWRITE");
b2b13ee2 683 ResetCellADC();
50555ba1 684
b2b13ee2 685}
7088dbe9 686//____________________________________________________________________________
b2b13ee2 687
688
689void AliPMDDigitizer::SDigits2Digits(Int_t ievt)
690{
36031625 691 // This reads the PMD sdigits tree and converts energy deposition
692 // in a cell to ADC and stores in the digits tree
693 //
ecee2a1a 694
b2b13ee2 695 fRunLoader->GetEvent(ievt);
696
ebd83c56 697 TTree* treeS = fPMDLoader->TreeS();
b2b13ee2 698 AliPMDsdigit *pmdsdigit;
ebd83c56 699 TBranch *branch = treeS->GetBranch("PMDSDigit");
ecee2a1a 700 if(!branch)
701 {
702 AliError("PMD Sdigit branch does not exist");
703 return;
704 }
ebd83c56 705 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
b2b13ee2 706 branch->SetAddress(&fSDigits);
707
ebd83c56 708 TTree* treeD = fPMDLoader->TreeD();
709 if (treeD == 0x0)
b2b13ee2 710 {
36031625 711 fPMDLoader->MakeTree("D");
ebd83c56 712 treeD = fPMDLoader->TreeD();
b2b13ee2 713 }
714 Int_t bufsize = 16000;
ebd83c56 715 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
716 treeD->Branch("PMDDigit", &fDigits, bufsize);
b2b13ee2 717
718 Int_t trno, det, smn;
7088dbe9 719 Int_t irow, icol;
b2b13ee2 720 Float_t edep, adc;
721
ebd83c56 722 Int_t nmodules = (Int_t) treeS->GetEntries();
ecee2a1a 723 AliDebug(1,Form("Number of modules = %d",nmodules));
b2b13ee2 724
725 for (Int_t imodule = 0; imodule < nmodules; imodule++)
726 {
ebd83c56 727 treeS->GetEntry(imodule);
b2b13ee2 728 Int_t nentries = fSDigits->GetLast();
ecee2a1a 729 AliDebug(2,Form("Number of entries per module = %d",nentries+1));
b2b13ee2 730 for (Int_t ient = 0; ient < nentries+1; ient++)
731 {
732 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
733 trno = pmdsdigit->GetTrackNumber();
734 det = pmdsdigit->GetDetector();
735 smn = pmdsdigit->GetSMNumber();
7088dbe9 736 irow = pmdsdigit->GetRow();
737 icol = pmdsdigit->GetColumn();
b2b13ee2 738 edep = pmdsdigit->GetCellEdep();
739
740 MeV2ADC(edep,adc);
7088dbe9 741 AddDigit(trno,det,smn,irow,icol,adc);
b2b13ee2 742 }
ebd83c56 743 treeD->Fill();
b2b13ee2 744 ResetDigit();
745 }
36031625 746 fPMDLoader->WriteDigits("OVERWRITE");
ecee2a1a 747
b2b13ee2 748}
7088dbe9 749//____________________________________________________________________________
750void AliPMDDigitizer::Exec(Option_t *option)
751{
752 // Does the event merging and digitization
7088dbe9 753 const char *cdeb = strstr(option,"deb");
754 if(cdeb)
755 {
ecee2a1a 756 AliDebug(100," *** PMD Exec is called ***");
7088dbe9 757 }
ecee2a1a 758
7088dbe9 759 Int_t ninputs = fManager->GetNinputs();
ecee2a1a 760 AliDebug(1,Form("Number of files to be processed = %d",ninputs));
7088dbe9 761 ResetCellADC();
762
763 for (Int_t i = 0; i < ninputs; i++)
764 {
765 Int_t troffset = fManager->GetMask(i);
766 MergeSDigits(i, troffset);
767 }
b2b13ee2 768
7088dbe9 769 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
770 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
771 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
772 if (fPMDLoader == 0x0)
773 {
ecee2a1a 774 AliError("Can not find PMD or PMDLoader");
7088dbe9 775 }
06f2c79d 776 fPMDLoader->LoadDigits("update");
ebd83c56 777 TTree* treeD = fPMDLoader->TreeD();
778 if (treeD == 0x0)
7088dbe9 779 {
780 fPMDLoader->MakeTree("D");
ebd83c56 781 treeD = fPMDLoader->TreeD();
7088dbe9 782 }
783 Int_t bufsize = 16000;
ebd83c56 784 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
785 treeD->Branch("PMDDigit", &fDigits, bufsize);
7088dbe9 786
787 Float_t adc;
788 Float_t deltaE = 0.;
789 Int_t detno = 0;
790 Int_t trno = 1;
791
792 for (Int_t idet = 0; idet < 2; idet++)
793 {
794 for (Int_t ism = 0; ism < fgkTotUM; ism++)
795 {
796 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
797 {
798 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
799 {
800 if (idet == 0)
801 {
802 deltaE = fPRE[ism][jrow][kcol];
803 trno = fPRETrackNo[ism][jrow][kcol];
804 detno = 0;
805 }
806 else if (idet == 1)
807 {
808 deltaE = fCPV[ism][jrow][kcol];
809 trno = fCPVTrackNo[ism][jrow][kcol];
810 detno = 1;
811 }
812 if (deltaE > 0.)
813 {
814 MeV2ADC(deltaE,adc);
815 AddDigit(trno,detno,ism,jrow,kcol,adc);
816 }
817 } // column loop
818 } // row loop
ebd83c56 819 treeD->Fill();
7088dbe9 820 ResetDigit();
821 } // supermodule loop
822 } // detector loop
7088dbe9 823 fPMDLoader->WriteDigits("OVERWRITE");
06f2c79d 824 fPMDLoader->UnloadDigits();
825 ResetCellADC();
7088dbe9 826}
827//____________________________________________________________________________
828
829void AliPMDDigitizer::MergeSDigits(Int_t filenumber, Int_t troffset)
830{
831 // merging sdigits
832 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(filenumber));
833 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
834 fPMDLoader->LoadSDigits("read");
ebd83c56 835 TTree* treeS = fPMDLoader->TreeS();
7088dbe9 836 AliPMDsdigit *pmdsdigit;
ebd83c56 837 TBranch *branch = treeS->GetBranch("PMDSDigit");
838 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
7088dbe9 839 branch->SetAddress(&fSDigits);
840
841 Int_t itrackno, idet, ism;
842 Int_t ixp, iyp;
843 Float_t edep;
ebd83c56 844 Int_t nmodules = (Int_t) treeS->GetEntries();
ecee2a1a 845 AliDebug(1,Form("Number of Modules in the treeS = %d",nmodules));
846 AliDebug(1,Form("Track Offset = %d",troffset));
7088dbe9 847 for (Int_t imodule = 0; imodule < nmodules; imodule++)
848 {
ebd83c56 849 treeS->GetEntry(imodule);
7088dbe9 850 Int_t nentries = fSDigits->GetLast();
ecee2a1a 851 AliDebug(2,Form("Number of Entries per Module = %d",nentries));
7088dbe9 852 for (Int_t ient = 0; ient < nentries+1; ient++)
853 {
854 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
855 itrackno = pmdsdigit->GetTrackNumber();
856 idet = pmdsdigit->GetDetector();
857 ism = pmdsdigit->GetSMNumber();
858 ixp = pmdsdigit->GetRow();
859 iyp = pmdsdigit->GetColumn();
860 edep = pmdsdigit->GetCellEdep();
7088dbe9 861 if (idet == 0)
862 {
863 if (fPRE[ism][ixp][iyp] < edep)
864 {
865 fPRETrackNo[ism][ixp][iyp] = troffset + itrackno;
866 }
867 fPRE[ism][ixp][iyp] += edep;
868 }
869 else if (idet == 1)
870 {
871 if (fCPV[ism][ixp][iyp] < edep)
872 {
873 fCPVTrackNo[ism][ixp][iyp] = troffset + itrackno;
874 }
875 fCPV[ism][ixp][iyp] += edep;
876 }
877 }
878 }
879
880}
881// ----------------------------------------------------------------------
b2b13ee2 882void AliPMDDigitizer::TrackAssignment2Cell()
883{
b2b13ee2 884 //
75bb524e 885 // This block assigns the cell id when there are
b2b13ee2 886 // multiple tracks in a cell according to the
887 // energy deposition
888 //
75bb524e 889 Bool_t jsort = false;
8599803d 890
b2b13ee2 891 Int_t i, j, k;
892
36031625 893 Float_t *fracEdp;
894 Float_t *trEdp;
75bb524e 895 Int_t *status1;
896 Int_t *status2;
897 Int_t *trnarray;
36031625 898 Int_t ****pmdTrack;
899 Float_t ****pmdEdep;
b2b13ee2 900
36031625 901 pmdTrack = new Int_t ***[fgkTotUM];
902 pmdEdep = new Float_t ***[fgkTotUM];
903 for (i=0; i<fgkTotUM; i++)
b2b13ee2 904 {
36031625 905 pmdTrack[i] = new Int_t **[fgkRow];
906 pmdEdep[i] = new Float_t **[fgkRow];
b2b13ee2 907 }
908
36031625 909 for (i = 0; i < fgkTotUM; i++)
b2b13ee2 910 {
36031625 911 for (j = 0; j < fgkRow; j++)
b2b13ee2 912 {
36031625 913 pmdTrack[i][j] = new Int_t *[fgkCol];
914 pmdEdep[i][j] = new Float_t *[fgkCol];
b2b13ee2 915 }
916 }
917
36031625 918 for (i = 0; i < fgkTotUM; i++)
b2b13ee2 919 {
36031625 920 for (j = 0; j < fgkRow; j++)
b2b13ee2 921 {
36031625 922 for (k = 0; k < fgkCol; k++)
b2b13ee2 923 {
36031625 924 Int_t nn = fPRECounter[i][j][k];
b2b13ee2 925 if(nn > 0)
926 {
36031625 927 pmdTrack[i][j][k] = new Int_t[nn];
928 pmdEdep[i][j][k] = new Float_t[nn];
b2b13ee2 929 }
930 else
931 {
932 nn = 1;
36031625 933 pmdTrack[i][j][k] = new Int_t[nn];
934 pmdEdep[i][j][k] = new Float_t[nn];
b2b13ee2 935 }
36031625 936 fPRECounter[i][j][k] = 0;
b2b13ee2 937 }
938 }
939 }
940
941
ebd83c56 942 Int_t nentries = fCell.GetEntries();
b2b13ee2 943
944 Int_t mtrackno, ism, ixp, iyp;
945 Float_t edep;
946
947 for (i = 0; i < nentries; i++)
948 {
ebd83c56 949 AliPMDcell* cell = (AliPMDcell*)fCell.UncheckedAt(i);
b2b13ee2 950
ebd83c56 951 mtrackno = cell->GetTrackNumber();
952 ism = cell->GetSMNumber();
953 ixp = cell->GetX();
954 iyp = cell->GetY();
955 edep = cell->GetEdep();
36031625 956 Int_t nn = fPRECounter[ism][ixp][iyp];
36031625 957 pmdTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
958 pmdEdep[ism][ixp][iyp][nn] = edep;
959 fPRECounter[ism][ixp][iyp]++;
b2b13ee2 960 }
961
962 Int_t iz, il;
963 Int_t im, ix, iy;
964 Int_t nn;
965
36031625 966 for (im=0; im<fgkTotUM; im++)
b2b13ee2 967 {
36031625 968 for (ix=0; ix<fgkRow; ix++)
b2b13ee2 969 {
36031625 970 for (iy=0; iy<fgkCol; iy++)
b2b13ee2 971 {
36031625 972 nn = fPRECounter[im][ix][iy];
b2b13ee2 973 if (nn > 1)
974 {
975 // This block handles if a cell is fired
976 // many times by many tracks
75bb524e 977 status1 = new Int_t[nn];
978 status2 = new Int_t[nn];
979 trnarray = new Int_t[nn];
b2b13ee2 980 for (iz = 0; iz < nn; iz++)
981 {
36031625 982 status1[iz] = pmdTrack[im][ix][iy][iz];
b2b13ee2 983 }
75bb524e 984 TMath::Sort(nn,status1,status2,jsort);
36031625 985 Int_t trackOld = -99999;
986 Int_t track, trCount = 0;
b2b13ee2 987 for (iz = 0; iz < nn; iz++)
988 {
75bb524e 989 track = status1[status2[iz]];
36031625 990 if (trackOld != track)
b2b13ee2 991 {
36031625 992 trnarray[trCount] = track;
993 trCount++;
b2b13ee2 994 }
36031625 995 trackOld = track;
b2b13ee2 996 }
6eb80a7c 997 delete [] status1;
998 delete [] status2;
36031625 999 Float_t totEdp = 0.;
1000 trEdp = new Float_t[trCount];
1001 fracEdp = new Float_t[trCount];
1002 for (il = 0; il < trCount; il++)
b2b13ee2 1003 {
36031625 1004 trEdp[il] = 0.;
75bb524e 1005 track = trnarray[il];
b2b13ee2 1006 for (iz = 0; iz < nn; iz++)
1007 {
36031625 1008 if (track == pmdTrack[im][ix][iy][iz])
b2b13ee2 1009 {
36031625 1010 trEdp[il] += pmdEdep[im][ix][iy][iz];
b2b13ee2 1011 }
1012 }
36031625 1013 totEdp += trEdp[il];
b2b13ee2 1014 }
36031625 1015 Int_t ilOld = 0;
1016 Float_t fracOld = 0.;
b2b13ee2 1017
36031625 1018 for (il = 0; il < trCount; il++)
b2b13ee2 1019 {
36031625 1020 fracEdp[il] = trEdp[il]/totEdp;
1021 if (fracOld < fracEdp[il])
b2b13ee2 1022 {
36031625 1023 fracOld = fracEdp[il];
1024 ilOld = il;
b2b13ee2 1025 }
1026 }
36031625 1027 fPRETrackNo[im][ix][iy] = trnarray[ilOld];
6eb80a7c 1028 delete [] fracEdp;
1029 delete [] trEdp;
1030 delete [] trnarray;
b2b13ee2 1031 }
1032 else if (nn == 1)
1033 {
1034 // This only handles if a cell is fired
1035 // by only one track
1036
36031625 1037 fPRETrackNo[im][ix][iy] = pmdTrack[im][ix][iy][0];
b2b13ee2 1038
1039 }
1040 else if (nn ==0)
1041 {
1042 // This is if no cell is fired
36031625 1043 fPRETrackNo[im][ix][iy] = -999;
b2b13ee2 1044 }
1045 } // end of iy
1046 } // end of ix
1047 } // end of im
1048
1049 // Delete all the pointers
1050
36031625 1051 for (i = 0; i < fgkTotUM; i++)
b2b13ee2 1052 {
36031625 1053 for (j = 0; j < fgkRow; j++)
b2b13ee2 1054 {
36031625 1055 for (k = 0; k < fgkCol; k++)
b2b13ee2 1056 {
36031625 1057 delete [] pmdTrack[i][j][k];
1058 delete [] pmdEdep[i][j][k];
b2b13ee2 1059 }
1060 }
1061 }
1062
36031625 1063 for (i = 0; i < fgkTotUM; i++)
b2b13ee2 1064 {
36031625 1065 for (j = 0; j < fgkRow; j++)
b2b13ee2 1066 {
36031625 1067 delete [] pmdTrack[i][j];
1068 delete [] pmdEdep[i][j];
b2b13ee2 1069 }
1070 }
1071
36031625 1072 for (i = 0; i < fgkTotUM; i++)
b2b13ee2 1073 {
36031625 1074 delete [] pmdTrack[i];
1075 delete [] pmdEdep[i];
b2b13ee2 1076 }
6eb80a7c 1077 delete [] pmdTrack;
1078 delete [] pmdEdep;
b2b13ee2 1079 //
1080 // End of the cell id assignment
1081 //
1082}
7088dbe9 1083//____________________________________________________________________________
a7d110b8 1084void AliPMDDigitizer::MeV2ADC(Float_t mev, Float_t & adc) const
b2b13ee2 1085{
36031625 1086 // This converts the simulated edep to ADC according to the
1087 // Test Beam Data
b2b13ee2 1088 // To be done
36031625 1089 //
b8e69f1f 1090
b8e69f1f 1091 // PS Test in September 2003
1092 // MeV - ADC conversion for 10bit ADC
1093
1094 const Float_t kConstant = 7.181;
1095 const Float_t kErConstant = 0.6899;
1096 const Float_t kSlope = 35.93;
1097 const Float_t kErSlope = 0.306;
1098
1099 //gRandom->SetSeed();
1100
1101 Float_t cons = gRandom->Gaus(kConstant,kErConstant);
1102 Float_t slop = gRandom->Gaus(kSlope,kErSlope);
1103
1104 Float_t adc10bit = slop*mev*0.001 + cons;
1105
1106 // 12 bit adc
1107
1108 Int_t adc12bit = (Int_t) (4.0*adc10bit);
1109
1110 if(adc12bit < 3000)
1111 {
1112 adc = (Float_t) adc12bit;
1113 }
1114 else if (adc12bit >= 3000)
1115 {
1116 adc = 3000.0;
1117 }
1118
b2b13ee2 1119}
7088dbe9 1120//____________________________________________________________________________
b2b13ee2 1121void AliPMDDigitizer::AddSDigit(Int_t trnumber, Int_t det, Int_t smnumber,
7088dbe9 1122 Int_t irow, Int_t icol, Float_t adc)
b2b13ee2 1123{
36031625 1124 // Add SDigit
1125 //
ebd83c56 1126 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
b2b13ee2 1127 TClonesArray &lsdigits = *fSDigits;
7088dbe9 1128 new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,det,smnumber,irow,icol,adc);
b2b13ee2 1129}
7088dbe9 1130//____________________________________________________________________________
b2b13ee2 1131
1132void AliPMDDigitizer::AddDigit(Int_t trnumber, Int_t det, Int_t smnumber,
7088dbe9 1133 Int_t irow, Int_t icol, Float_t adc)
b2b13ee2 1134{
36031625 1135 // Add Digit
1136 //
ebd83c56 1137 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
b2b13ee2 1138 TClonesArray &ldigits = *fDigits;
7088dbe9 1139 new(ldigits[fNdigit++]) AliPMDdigit(trnumber,det,smnumber,irow,icol,adc);
b2b13ee2 1140}
7088dbe9 1141//____________________________________________________________________________
b2b13ee2 1142
b2b13ee2 1143void AliPMDDigitizer::SetZPosition(Float_t zpos)
1144{
1145 fZPos = zpos;
1146}
7088dbe9 1147//____________________________________________________________________________
b2b13ee2 1148Float_t AliPMDDigitizer::GetZPosition() const
1149{
1150 return fZPos;
1151}
7088dbe9 1152//____________________________________________________________________________
b2b13ee2 1153
1154void AliPMDDigitizer::ResetCell()
1155{
36031625 1156 // clears the cell array and also the counter
1157 // for each cell
1158 //
ebd83c56 1159 fCell.Delete();
36031625 1160 for (Int_t i = 0; i < fgkTotUM; i++)
b2b13ee2 1161 {
36031625 1162 for (Int_t j = 0; j < fgkRow; j++)
b2b13ee2 1163 {
36031625 1164 for (Int_t k = 0; k < fgkCol; k++)
b2b13ee2 1165 {
36031625 1166 fPRECounter[i][j][k] = 0;
b2b13ee2 1167 }
1168 }
1169 }
1170}
7088dbe9 1171//____________________________________________________________________________
b2b13ee2 1172void AliPMDDigitizer::ResetSDigit()
1173{
36031625 1174 // Clears SDigits
b2b13ee2 1175 fNsdigit = 0;
ebd83c56 1176 if (fSDigits) fSDigits->Delete();
b2b13ee2 1177}
7088dbe9 1178//____________________________________________________________________________
b2b13ee2 1179void AliPMDDigitizer::ResetDigit()
1180{
36031625 1181 // Clears Digits
b2b13ee2 1182 fNdigit = 0;
ebd83c56 1183 if (fDigits) fDigits->Delete();
b2b13ee2 1184}
7088dbe9 1185//____________________________________________________________________________
b2b13ee2 1186
1187void AliPMDDigitizer::ResetCellADC()
1188{
7088dbe9 1189 // Clears individual cells edep and track number
36031625 1190 for (Int_t i = 0; i < fgkTotUM; i++)
b2b13ee2 1191 {
36031625 1192 for (Int_t j = 0; j < fgkRow; j++)
b2b13ee2 1193 {
36031625 1194 for (Int_t k = 0; k < fgkCol; k++)
b2b13ee2 1195 {
1196 fCPV[i][j][k] = 0.;
36031625 1197 fPRE[i][j][k] = 0.;
7088dbe9 1198 fPRETrackNo[i][j][k] = 0;
1199 fCPVTrackNo[i][j][k] = 0;
b2b13ee2 1200 }
1201 }
1202 }
1203}
09a06455 1204//------------------------------------------------------
7088dbe9 1205//____________________________________________________________________________
b2b13ee2 1206
1207void AliPMDDigitizer::UnLoad(Option_t *option)
1208{
36031625 1209 // Unloads all the root files
1210 //
b2b13ee2 1211 const char *cS = strstr(option,"S");
1212 const char *cD = strstr(option,"D");
1213
1214 fRunLoader->UnloadgAlice();
1215 fRunLoader->UnloadHeader();
1216 fRunLoader->UnloadKinematics();
1217
1218 if (cS)
1219 {
36031625 1220 fPMDLoader->UnloadHits();
b2b13ee2 1221 }
1222 if (cD)
1223 {
36031625 1224 fPMDLoader->UnloadHits();
1225 fPMDLoader->UnloadSDigits();
b2b13ee2 1226 }
1227}
09a06455 1228
1229//----------------------------------------------------------------------
1230Float_t AliPMDDigitizer::Gain(Int_t det, Int_t smn, Int_t row, Int_t col) const
1231{
1232 // returns of the gain of the cell
1233 // Added this method by ZA
1234
1235 //cout<<" I am here in gain "<<fCalibData<< "smn,row, col "<<smn
1236 //<<" "<<row<<" "<<col<<endl;
1237
1238 if(!fCalibData) {
1239 AliError("No calibration data loaded from CDB!!!");
50555ba1 1240 return 1;
09a06455 1241 }
1242
1243 Float_t GainFact;
1244 GainFact = fCalibData->GetGainFact(det,smn,row,col);
1245 printf("\t gain=%10.3f\n",GainFact);
1246 return GainFact;
1247}
1248//----------------------------------------------------------------------
1249AliPMDCalibData* AliPMDDigitizer::GetCalibData() const
1250{
1251 // The run number will be centralized in AliCDBManager,
1252 // you don't need to set it here!
1253 // Added this method by ZA
1254 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Data");
1255
1256 if(!entry){
1257 AliWarning("Calibration object retrieval failed! Dummy calibration will be used.");
1258
1259 // this just remembers the actual default storage. No problem if it is null.
1260 AliCDBStorage *origStorage = AliCDBManager::Instance()->GetDefaultStorage();
1261 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
1262
1263 entry = AliCDBManager::Instance()->Get("PMD/Calib/Data");
1264
1265 // now reset the original default storage to AliCDBManager...
1266 AliCDBManager::Instance()->SetDefaultStorage(origStorage);
1267 }
1268
1269 AliPMDCalibData *calibdata=0;
1270 if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
1271
1272 if (!calibdata) AliError("No calibration data from calibration database !");
1273
1274 return calibdata;
1275}