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