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