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