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