]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PMD/AliPMDDigitizer.cxx
Mother volume corrected to avoid overlaps with the ITS
[u/mrichter/AliRoot.git] / PMD / AliPMDDigitizer.cxx
CommitLineData
b9746a9e 1/***************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
b2b13ee2 15//-----------------------------------------------------//
16// //
8599803d 17// Source File : PMDDigitizer.cxx, Version 00 //
b2b13ee2 18// //
19// Date : September 20 2002 //
20// //
21//-----------------------------------------------------//
22
36031625 23#include <Riostream.h>
b2b13ee2 24#include <TBRIK.h>
25#include <TNode.h>
26#include <TTree.h>
27#include <TGeometry.h>
28#include <TObjArray.h>
29#include <TClonesArray.h>
30#include <TFile.h>
31#include <TNtuple.h>
32#include <TParticle.h>
33
34#include "AliRun.h"
35#include "AliPMD.h"
36#include "AliHit.h"
37#include "AliDetector.h"
38#include "AliRunLoader.h"
39#include "AliLoader.h"
40#include "AliConfig.h"
41#include "AliMagF.h"
42#include "AliRunDigitizer.h"
43#include "AliHeader.h"
44
45#include "AliPMDcell.h"
46#include "AliPMDsdigit.h"
47#include "AliPMDdigit.h"
48#include "AliPMDDigitizer.h"
49#include "AliPMDClustering.h"
5d12ce38 50#include "AliMC.h"
b2b13ee2 51
52ClassImp(AliPMDDigitizer)
a7d110b8 53
b2b13ee2 54AliPMDDigitizer::AliPMDDigitizer()
55{
36031625 56 // Default Constructor
57 //
b2b13ee2 58 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
59 fNsdigit = 0;
60 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
61 fNdigit = 0;
62
36031625 63 for (Int_t i = 0; i < fgkTotUM; i++)
b2b13ee2 64 {
36031625 65 for (Int_t j = 0; j < fgkRow; j++)
b2b13ee2 66 {
36031625 67 for (Int_t k = 0; k < fgkCol; k++)
b2b13ee2 68 {
69 fCPV[i][j][k] = 0.;
36031625 70 fPRE[i][j][k] = 0.;
b2b13ee2 71 }
72 }
73 }
74
75 if (!fCell) fCell = new TObjArray();
76
77 fZPos = 361.5; // in units of cm, This is the default position of PMD
b2b13ee2 78}
79AliPMDDigitizer::~AliPMDDigitizer()
80{
36031625 81 // Default Destructor
82 //
b2b13ee2 83 delete fSDigits;
84 delete fDigits;
85 delete fCell;
86}
87//
88// Member functions
89//
85a5290f 90void AliPMDDigitizer::OpengAliceFile(const char *file, Option_t *option)
b2b13ee2 91{
36031625 92 // Loads galice.root file and corresponding header, kinematics
93 // hits and sdigits or digits depending on the option
94 //
85a5290f 95 fRunLoader = AliRunLoader::Open(file,AliConfig::fgkDefaultEventFolderName);
b2b13ee2 96
97 if (!fRunLoader)
98 {
99 Error("Open","Can not open session for file %s.",file);
100 }
101
102 fRunLoader->LoadgAlice();
103 fRunLoader->LoadHeader();
104 fRunLoader->LoadKinematics();
105
b208c6a3 106 gAlice = fRunLoader->GetAliRun();
b2b13ee2 107
b208c6a3 108 if (gAlice)
b2b13ee2 109 {
110 printf("<AliPMDdigitizer::Open> ");
111 printf("AliRun object found on file.\n");
112 }
113 else
114 {
115 printf("<AliPMDdigitizer::Open> ");
116 printf("Could not find AliRun object.\n");
117 }
118
b208c6a3 119 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
36031625 120 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
121 if (fPMDLoader == 0x0)
b2b13ee2 122 {
123 cerr<<"Hits2Digits : Can not find PMD or PMDLoader\n";
124 }
125
126 const char *cHS = strstr(option,"HS");
127 const char *cHD = strstr(option,"HD");
128 const char *cSD = strstr(option,"SD");
129
130 if (cHS)
131 {
36031625 132 fPMDLoader->LoadHits("READ");
133 fPMDLoader->LoadSDigits("recreate");
b2b13ee2 134 }
135 else if (cHD)
136 {
36031625 137 fPMDLoader->LoadHits("READ");
138 fPMDLoader->LoadDigits("recreate");
b2b13ee2 139 }
140 else if (cSD)
141 {
36031625 142 fPMDLoader->LoadSDigits("READ");
143 fPMDLoader->LoadDigits("recreate");
b2b13ee2 144 }
145
146}
147void AliPMDDigitizer::Hits2SDigits(Int_t ievt)
148{
36031625 149 // This reads the PMD Hits tree and assigns the right track number
150 // to a cell and stores in the summable digits tree
151 //
152 // cout << " -------- Beginning of Hits2SDigits ----------- " << endl;
b2b13ee2 153
36031625 154 const Int_t kPi0 = 111;
155 const Int_t kGamma = 22;
b2b13ee2 156 Int_t npmd;
157 Int_t trackno;
b2b13ee2 158 Int_t smnumber;
159 Int_t trackpid;
160 Int_t mtrackno;
161 Int_t mtrackpid;
162
163 Float_t xPos, yPos, zPos;
8599803d 164 Int_t xpad = -1, ypad = -1;
b2b13ee2 165 Float_t edep;
166 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
167
a7d110b8 168
b2b13ee2 169 ResetSDigit();
170
171 printf("Event Number = %d \n",ievt);
172 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
173 printf("Number of Particles = %d \n", nparticles);
174 fRunLoader->GetEvent(ievt);
a7d110b8 175 // fPArray = gAlice->GetMCApp()->Particles();
b2b13ee2 176 // ------------------------------------------------------- //
177 // Pointer to specific detector hits.
178 // Get pointers to Alice detectors and Hits containers
179
36031625 180 fTreeH = fPMDLoader->TreeH();
b2b13ee2 181
36031625 182 Int_t ntracks = (Int_t) fTreeH->GetEntries();
b2b13ee2 183 printf("Number of Tracks in the TreeH = %d \n", ntracks);
184
36031625 185 fTreeS = fPMDLoader->TreeS();
186 if (fTreeS == 0x0)
b2b13ee2 187 {
36031625 188 fPMDLoader->MakeTree("S");
189 fTreeS = fPMDLoader->TreeS();
b2b13ee2 190 }
191 Int_t bufsize = 16000;
36031625 192 fTreeS->Branch("PMDSDigit", &fSDigits, bufsize);
b2b13ee2 193
36031625 194 if (fPMD) fHits = fPMD->Hits();
b2b13ee2 195
196 // Start loop on tracks in the hits containers
a7d110b8 197
b2b13ee2 198 for (Int_t track=0; track<ntracks;track++)
199 {
b208c6a3 200 gAlice->ResetHits();
36031625 201 fTreeH->GetEvent(track);
36031625 202 if (fPMD)
b2b13ee2 203 {
36031625 204 npmd = fHits->GetEntriesFast();
b2b13ee2 205 for (int ipmd = 0; ipmd < npmd; ipmd++)
206 {
36031625 207 fPMDHit = (AliPMDhit*) fHits->UncheckedAt(ipmd);
208 trackno = fPMDHit->GetTrack();
b2b13ee2 209 // get kinematics of the particles
36031625 210
b208c6a3 211 fParticle = gAlice->GetMCApp()->Particle(trackno);
36031625 212 trackpid = fParticle->GetPdgCode();
b2b13ee2 213
214 Int_t igatr = -999;
215 Int_t ichtr = -999;
8599803d 216 Int_t igapid = -999;
b2b13ee2 217 Int_t imo;
218 Int_t igen = 0;
36031625 219 Int_t idmo = -999;
8599803d 220
36031625 221 TParticle* mparticle = fParticle;
222 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
8599803d 223 if (mparticle->GetFirstMother() == -1)
224 {
36031625 225 tracknoOld = trackno;
226 trackpidOld = trackpid;
227 statusOld = -1;
8599803d 228 }
8599803d 229 Int_t igstatus = 0;
b2b13ee2 230 while((imo = mparticle->GetFirstMother()) >= 0)
231 {
232 igen++;
36031625 233
b208c6a3 234 mparticle = gAlice->GetMCApp()->Particle(imo);
36031625 235 idmo = mparticle->GetPdgCode();
b2b13ee2 236
237 vx = mparticle->Vx();
238 vy = mparticle->Vy();
239 vz = mparticle->Vz();
240
36031625 241 //printf("==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
242 //fprintf(fpw1,"==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
243 if ((idmo == kGamma || idmo == -11 || idmo == 11) && vx == 0. && vy == 0. && vz == 0.)
b2b13ee2 244 {
245 igatr = imo;
36031625 246 igapid = idmo;
8599803d 247 igstatus = 1;
248 }
249 if(igstatus == 0)
250 {
36031625 251 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
8599803d 252 {
253 igatr = imo;
36031625 254 igapid = idmo;
8599803d 255 }
b2b13ee2 256 }
257 ichtr = imo;
258 }
259
36031625 260 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
b2b13ee2 261 {
262 mtrackno = igatr;
8599803d 263 mtrackpid = igapid;
b2b13ee2 264 }
265 else
266 {
267 mtrackno = ichtr;
36031625 268 mtrackpid = idmo;
b2b13ee2 269 }
36031625 270 if (statusOld == -1)
8599803d 271 {
36031625 272 mtrackno = tracknoOld;
273 mtrackpid = trackpidOld;
8599803d 274 }
36031625 275 xPos = fPMDHit->X();
276 yPos = fPMDHit->Y();
277 zPos = fPMDHit->Z();
278 edep = fPMDHit->fEnergy;
279 Int_t vol1 = fPMDHit->fVolume[1]; // Column
280 Int_t vol2 = fPMDHit->fVolume[2]; // Row
281 Int_t vol3 = fPMDHit->fVolume[3]; // UnitModule
282 Int_t vol6 = fPMDHit->fVolume[6]; // SuperModule
8599803d 283 // -----------------------------------------//
284 // For Super Module 1 & 2 //
285 // nrow = 96, ncol = 48 //
286 // For Super Module 3 & 4 //
287 // nrow = 48, ncol = 96 //
288 // -----------------------------------------//
b2b13ee2 289
36031625 290 smnumber = (vol6-1)*6 + vol3;
8599803d 291
36031625 292 if (vol6 == 1 || vol6 == 2)
8599803d 293 {
36031625 294 xpad = vol1;
295 ypad = vol2;
8599803d 296 }
36031625 297 else if (vol6 == 3 || vol6 == 4)
b2b13ee2 298 {
36031625 299 xpad = vol2;
300 ypad = vol1;
b2b13ee2 301 }
b2b13ee2 302
75bb524e 303 //cout << "zpos = " << zPos << " edep = " << edep << endl;
b2b13ee2 304
8599803d 305 Float_t zposition = TMath::Abs(zPos);
306 if (zposition < fZPos)
b2b13ee2 307 {
308 // CPV
309 fDetNo = 1;
310 }
8599803d 311 else if (zposition > fZPos)
b2b13ee2 312 {
313 // PMD
314 fDetNo = 0;
315 }
8599803d 316 Int_t smn = smnumber - 1;
317 Int_t ixx = xpad - 1;
318 Int_t iyy = ypad - 1;
b2b13ee2 319 if (fDetNo == 0)
320 {
36031625 321 fPRE[smn][ixx][iyy] += edep;
322 fPRECounter[smn][ixx][iyy]++;
b2b13ee2 323
36031625 324 fPMDcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
b2b13ee2 325
36031625 326 fCell->Add(fPMDcell);
b2b13ee2 327 }
328 else if(fDetNo == 1)
329 {
8599803d 330 fCPV[smn][ixx][iyy] += edep;
331 fCPVTrackNo[smn][ixx][iyy] = mtrackno;
b2b13ee2 332 }
333 }
334 }
335 } // Track Loop ended
8599803d 336
b2b13ee2 337 TrackAssignment2Cell();
b2b13ee2 338 ResetCell();
339
340 Float_t deltaE = 0.;
341 Int_t detno = 0;
b2b13ee2 342 Int_t trno = -1;
343 Int_t cellno = 0;
344
345 for (Int_t idet = 0; idet < 2; idet++)
346 {
36031625 347 for (Int_t ism = 0; ism < fgkTotUM; ism++)
b2b13ee2 348 {
36031625 349 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
b2b13ee2 350 {
36031625 351 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
b2b13ee2 352 {
36031625 353 cellno = jrow*fgkCol + kcol;
b2b13ee2 354 if (idet == 0)
355 {
36031625 356 deltaE = fPRE[ism][jrow][kcol];
357 trno = fPRETrackNo[ism][jrow][kcol];
b2b13ee2 358 detno = 0;
359 }
360 else if (idet == 1)
361 {
362 deltaE = fCPV[ism][jrow][kcol];
363 trno = fCPVTrackNo[ism][jrow][kcol];
364 detno = 1;
365 }
366 if (deltaE > 0.)
367 {
b2b13ee2 368 AddSDigit(trno,detno,ism,cellno,deltaE);
369 }
370 }
371 }
36031625 372 fTreeS->Fill();
b2b13ee2 373 ResetSDigit();
374 }
375 }
36031625 376 fPMDLoader->WriteSDigits("OVERWRITE");
b2b13ee2 377 ResetCellADC();
378
379 // cout << " -------- End of Hits2SDigit ----------- " << endl;
380}
381
382void AliPMDDigitizer::Hits2Digits(Int_t ievt)
383{
36031625 384 // This reads the PMD Hits tree and assigns the right track number
385 // to a cell and stores in the digits tree
386 //
387 const Int_t kPi0 = 111;
388 const Int_t kGamma = 22;
b2b13ee2 389 Int_t npmd;
390 Int_t trackno;
b2b13ee2 391 Int_t smnumber;
392 Int_t trackpid;
393 Int_t mtrackno;
394 Int_t mtrackpid;
395
396 Float_t xPos, yPos, zPos;
8599803d 397 Int_t xpad = -1, ypad = -1;
b2b13ee2 398 Float_t edep;
399 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
400
b2b13ee2 401 ResetDigit();
402
403 printf("Event Number = %d \n",ievt);
404
405 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
406 printf("Number of Particles = %d \n", nparticles);
407 fRunLoader->GetEvent(ievt);
a7d110b8 408 // fPArray = gAlice->GetMCApp()->Particles();
b2b13ee2 409 // ------------------------------------------------------- //
410 // Pointer to specific detector hits.
411 // Get pointers to Alice detectors and Hits containers
412
b208c6a3 413 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
36031625 414 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
b2b13ee2 415
36031625 416 if (fPMDLoader == 0x0)
b2b13ee2 417 {
418 cerr<<"Hits2Digits method : Can not find PMD or PMDLoader\n";
419 }
36031625 420 fTreeH = fPMDLoader->TreeH();
421 Int_t ntracks = (Int_t) fTreeH->GetEntries();
b2b13ee2 422 printf("Number of Tracks in the TreeH = %d \n", ntracks);
36031625 423 fPMDLoader->LoadDigits("recreate");
424 fTreeD = fPMDLoader->TreeD();
425 if (fTreeD == 0x0)
b2b13ee2 426 {
36031625 427 fPMDLoader->MakeTree("D");
428 fTreeD = fPMDLoader->TreeD();
b2b13ee2 429 }
430 Int_t bufsize = 16000;
36031625 431 fTreeD->Branch("PMDDigit", &fDigits, bufsize);
b2b13ee2 432
36031625 433 if (fPMD) fHits = fPMD->Hits();
b2b13ee2 434
435 // Start loop on tracks in the hits containers
436
437 for (Int_t track=0; track<ntracks;track++)
438 {
b208c6a3 439 gAlice->ResetHits();
36031625 440 fTreeH->GetEvent(track);
b2b13ee2 441
36031625 442 if (fPMD)
b2b13ee2 443 {
36031625 444 npmd = fHits->GetEntriesFast();
b2b13ee2 445 for (int ipmd = 0; ipmd < npmd; ipmd++)
446 {
36031625 447 fPMDHit = (AliPMDhit*) fHits->UncheckedAt(ipmd);
448 trackno = fPMDHit->GetTrack();
b2b13ee2 449
450 // get kinematics of the particles
451
b208c6a3 452 fParticle = gAlice->GetMCApp()->Particle(trackno);
36031625 453 trackpid = fParticle->GetPdgCode();
b2b13ee2 454
455 Int_t igatr = -999;
456 Int_t ichtr = -999;
8599803d 457 Int_t igapid = -999;
b2b13ee2 458 Int_t imo;
459 Int_t igen = 0;
36031625 460 Int_t idmo = -999;
8599803d 461
36031625 462 TParticle* mparticle = fParticle;
463 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
8599803d 464 if (mparticle->GetFirstMother() == -1)
465 {
36031625 466 tracknoOld = trackno;
467 trackpidOld = trackpid;
468 statusOld = -1;
8599803d 469 }
470
471 Int_t igstatus = 0;
b2b13ee2 472 while((imo = mparticle->GetFirstMother()) >= 0)
473 {
474 igen++;
36031625 475
b208c6a3 476 mparticle = gAlice->GetMCApp()->Particle(imo);
36031625 477 idmo = mparticle->GetPdgCode();
b2b13ee2 478
479 vx = mparticle->Vx();
480 vy = mparticle->Vy();
481 vz = mparticle->Vz();
482
36031625 483 //printf("==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
484 //fprintf(fpw1,"==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
485 if ((idmo == kGamma || idmo == -11 || idmo == 11) && vx == 0. && vy == 0. && vz == 0.)
b2b13ee2 486 {
487 igatr = imo;
36031625 488 igapid = idmo;
8599803d 489 igstatus = 1;
490 }
491 if(igstatus == 0)
492 {
36031625 493 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
8599803d 494 {
495 igatr = imo;
36031625 496 igapid = idmo;
8599803d 497 }
b2b13ee2 498 }
499 ichtr = imo;
500 }
501
36031625 502 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
b2b13ee2 503 {
504 mtrackno = igatr;
8599803d 505 mtrackpid = igapid;
b2b13ee2 506 }
507 else
508 {
509 mtrackno = ichtr;
36031625 510 mtrackpid = idmo;
b2b13ee2 511 }
36031625 512 if (statusOld == -1)
8599803d 513 {
36031625 514 mtrackno = tracknoOld;
515 mtrackpid = trackpidOld;
8599803d 516 }
b2b13ee2 517
36031625 518 xPos = fPMDHit->X();
519 yPos = fPMDHit->Y();
520 zPos = fPMDHit->Z();
521 edep = fPMDHit->fEnergy;
522 Int_t vol1 = fPMDHit->fVolume[1]; // Column
523 Int_t vol2 = fPMDHit->fVolume[2]; // Row
524 Int_t vol3 = fPMDHit->fVolume[3]; // UnitModule
525 Int_t vol6 = fPMDHit->fVolume[6]; // SuperModule
8599803d 526
527 // -----------------------------------------//
528 // For Super Module 1 & 2 //
529 // nrow = 96, ncol = 48 //
530 // For Super Module 3 & 4 //
531 // nrow = 48, ncol = 96 //
532 // -----------------------------------------//
b2b13ee2 533
36031625 534 smnumber = (vol6-1)*6 + vol3;
8599803d 535
36031625 536 if (vol6 == 1 || vol6 == 2)
b2b13ee2 537 {
36031625 538 xpad = vol1;
539 ypad = vol2;
8599803d 540 }
36031625 541 else if (vol6 == 3 || vol6 == 4)
8599803d 542 {
36031625 543 xpad = vol2;
544 ypad = vol1;
b2b13ee2 545 }
b2b13ee2 546
547 //cout << "-zpos = " << -zPos << endl;
8599803d 548
549 Float_t zposition = TMath::Abs(zPos);
550
551 if (zposition < fZPos)
b2b13ee2 552 {
553 // CPV
554 fDetNo = 1;
555 }
8599803d 556 else if (zposition > fZPos)
b2b13ee2 557 {
558 // PMD
559 fDetNo = 0;
560 }
8599803d 561
562 Int_t smn = smnumber - 1;
563 Int_t ixx = xpad - 1;
564 Int_t iyy = ypad - 1;
565 if (fDetNo == 0)
b2b13ee2 566 {
36031625 567 fPRE[smn][ixx][iyy] += edep;
568 fPRECounter[smn][ixx][iyy]++;
8599803d 569
36031625 570 fPMDcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
8599803d 571
36031625 572 fCell->Add(fPMDcell);
b2b13ee2 573 }
8599803d 574 else if(fDetNo == 1)
b2b13ee2 575 {
8599803d 576 fCPV[smn][ixx][iyy] += edep;
577 fCPVTrackNo[smn][ixx][iyy] = mtrackno;
b2b13ee2 578 }
579 }
580 }
581 } // Track Loop ended
582
583 TrackAssignment2Cell();
584 ResetCell();
585
586 Float_t deltaE = 0.;
587 Int_t detno = 0;
b2b13ee2 588 Int_t trno = 1;
589 Int_t cellno;
590
591 for (Int_t idet = 0; idet < 2; idet++)
592 {
36031625 593 for (Int_t ism = 0; ism < fgkTotUM; ism++)
b2b13ee2 594 {
36031625 595 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
b2b13ee2 596 {
36031625 597 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
b2b13ee2 598 {
36031625 599 cellno = jrow*fgkCol + kcol;
b2b13ee2 600 if (idet == 0)
601 {
36031625 602 deltaE = fPRE[ism][jrow][kcol];
603 trno = fPRETrackNo[ism][jrow][kcol];
b2b13ee2 604 detno = 0;
605 }
606 else if (idet == 1)
607 {
608 deltaE = fCPV[ism][jrow][kcol];
8599803d 609 trno = fCPVTrackNo[ism][jrow][kcol];
b2b13ee2 610 detno = 1;
611 }
612 if (deltaE > 0.)
613 {
b2b13ee2 614 AddDigit(trno,detno,ism,cellno,deltaE);
615 }
616 } // column loop
617 } // row loop
618 } // supermodule loop
36031625 619 fTreeD->Fill();
b2b13ee2 620 ResetDigit();
621 } // detector loop
622
36031625 623 fPMDLoader->WriteDigits("OVERWRITE");
b2b13ee2 624 ResetCellADC();
625
626 // cout << " -------- End of Hits2Digit ----------- " << endl;
627}
628
629
630void AliPMDDigitizer::SDigits2Digits(Int_t ievt)
631{
36031625 632 // This reads the PMD sdigits tree and converts energy deposition
633 // in a cell to ADC and stores in the digits tree
634 //
b2b13ee2 635 // cout << " -------- Beginning of SDigits2Digit ----------- " << endl;
636 fRunLoader->GetEvent(ievt);
637
36031625 638 fTreeS = fPMDLoader->TreeS();
b2b13ee2 639 AliPMDsdigit *pmdsdigit;
36031625 640 TBranch *branch = fTreeS->GetBranch("PMDSDigit");
b2b13ee2 641 branch->SetAddress(&fSDigits);
642
36031625 643 fTreeD = fPMDLoader->TreeD();
644 if (fTreeD == 0x0)
b2b13ee2 645 {
36031625 646 fPMDLoader->MakeTree("D");
647 fTreeD = fPMDLoader->TreeD();
b2b13ee2 648 }
649 Int_t bufsize = 16000;
36031625 650 fTreeD->Branch("PMDDigit", &fDigits, bufsize);
b2b13ee2 651
652 Int_t trno, det, smn;
653 Int_t cellno;
654 Float_t edep, adc;
655
36031625 656 Int_t nmodules = (Int_t) fTreeS->GetEntries();
b2b13ee2 657
658 for (Int_t imodule = 0; imodule < nmodules; imodule++)
659 {
36031625 660 fTreeS->GetEntry(imodule);
b2b13ee2 661 Int_t nentries = fSDigits->GetLast();
662 //cout << " nentries = " << nentries << endl;
663 for (Int_t ient = 0; ient < nentries+1; ient++)
664 {
665 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
666 trno = pmdsdigit->GetTrackNumber();
667 det = pmdsdigit->GetDetector();
668 smn = pmdsdigit->GetSMNumber();
669 cellno = pmdsdigit->GetCellNumber();
670 edep = pmdsdigit->GetCellEdep();
671
672 MeV2ADC(edep,adc);
b2b13ee2 673 AddDigit(trno,det,smn,cellno,adc);
674 }
36031625 675 fTreeD->Fill();
b2b13ee2 676 ResetDigit();
677 }
36031625 678 fPMDLoader->WriteDigits("OVERWRITE");
b2b13ee2 679 // cout << " -------- End of SDigits2Digit ----------- " << endl;
680}
681
682void AliPMDDigitizer::TrackAssignment2Cell()
683{
b2b13ee2 684 //
75bb524e 685 // This block assigns the cell id when there are
b2b13ee2 686 // multiple tracks in a cell according to the
687 // energy deposition
688 //
75bb524e 689 Bool_t jsort = false;
8599803d 690
b2b13ee2 691 Int_t i, j, k;
692
36031625 693 Float_t *fracEdp;
694 Float_t *trEdp;
75bb524e 695 Int_t *status1;
696 Int_t *status2;
697 Int_t *trnarray;
36031625 698 Int_t ****pmdTrack;
699 Float_t ****pmdEdep;
b2b13ee2 700
36031625 701 pmdTrack = new Int_t ***[fgkTotUM];
702 pmdEdep = new Float_t ***[fgkTotUM];
703 for (i=0; i<fgkTotUM; i++)
b2b13ee2 704 {
36031625 705 pmdTrack[i] = new Int_t **[fgkRow];
706 pmdEdep[i] = new Float_t **[fgkRow];
b2b13ee2 707 }
708
36031625 709 for (i = 0; i < fgkTotUM; i++)
b2b13ee2 710 {
36031625 711 for (j = 0; j < fgkRow; j++)
b2b13ee2 712 {
36031625 713 pmdTrack[i][j] = new Int_t *[fgkCol];
714 pmdEdep[i][j] = new Float_t *[fgkCol];
b2b13ee2 715 }
716 }
717
36031625 718 for (i = 0; i < fgkTotUM; i++)
b2b13ee2 719 {
36031625 720 for (j = 0; j < fgkRow; j++)
b2b13ee2 721 {
36031625 722 for (k = 0; k < fgkCol; k++)
b2b13ee2 723 {
36031625 724 Int_t nn = fPRECounter[i][j][k];
b2b13ee2 725 if(nn > 0)
726 {
36031625 727 pmdTrack[i][j][k] = new Int_t[nn];
728 pmdEdep[i][j][k] = new Float_t[nn];
b2b13ee2 729 }
730 else
731 {
732 nn = 1;
36031625 733 pmdTrack[i][j][k] = new Int_t[nn];
734 pmdEdep[i][j][k] = new Float_t[nn];
b2b13ee2 735 }
36031625 736 fPRECounter[i][j][k] = 0;
b2b13ee2 737 }
738 }
739 }
740
741
742 Int_t nentries = fCell->GetEntries();
743
744 Int_t mtrackno, ism, ixp, iyp;
745 Float_t edep;
746
747 for (i = 0; i < nentries; i++)
748 {
36031625 749 fPMDcell = (AliPMDcell*)fCell->UncheckedAt(i);
b2b13ee2 750
36031625 751 mtrackno = fPMDcell->GetTrackNumber();
752 ism = fPMDcell->GetSMNumber();
753 ixp = fPMDcell->GetX();
754 iyp = fPMDcell->GetY();
755 edep = fPMDcell->GetEdep();
756 Int_t nn = fPRECounter[ism][ixp][iyp];
b2b13ee2 757 // cout << " nn = " << nn << endl;
36031625 758 pmdTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
759 pmdEdep[ism][ixp][iyp][nn] = edep;
760 fPRECounter[ism][ixp][iyp]++;
b2b13ee2 761 }
762
763 Int_t iz, il;
764 Int_t im, ix, iy;
765 Int_t nn;
766
36031625 767 for (im=0; im<fgkTotUM; im++)
b2b13ee2 768 {
36031625 769 for (ix=0; ix<fgkRow; ix++)
b2b13ee2 770 {
36031625 771 for (iy=0; iy<fgkCol; iy++)
b2b13ee2 772 {
36031625 773 nn = fPRECounter[im][ix][iy];
b2b13ee2 774 if (nn > 1)
775 {
776 // This block handles if a cell is fired
777 // many times by many tracks
75bb524e 778 status1 = new Int_t[nn];
779 status2 = new Int_t[nn];
780 trnarray = new Int_t[nn];
b2b13ee2 781 for (iz = 0; iz < nn; iz++)
782 {
36031625 783 status1[iz] = pmdTrack[im][ix][iy][iz];
b2b13ee2 784 }
75bb524e 785 TMath::Sort(nn,status1,status2,jsort);
36031625 786 Int_t trackOld = -99999;
787 Int_t track, trCount = 0;
b2b13ee2 788 for (iz = 0; iz < nn; iz++)
789 {
75bb524e 790 track = status1[status2[iz]];
36031625 791 if (trackOld != track)
b2b13ee2 792 {
36031625 793 trnarray[trCount] = track;
794 trCount++;
b2b13ee2 795 }
36031625 796 trackOld = track;
b2b13ee2 797 }
75bb524e 798 delete status1;
799 delete status2;
36031625 800 Float_t totEdp = 0.;
801 trEdp = new Float_t[trCount];
802 fracEdp = new Float_t[trCount];
803 for (il = 0; il < trCount; il++)
b2b13ee2 804 {
36031625 805 trEdp[il] = 0.;
75bb524e 806 track = trnarray[il];
b2b13ee2 807 for (iz = 0; iz < nn; iz++)
808 {
36031625 809 if (track == pmdTrack[im][ix][iy][iz])
b2b13ee2 810 {
36031625 811 trEdp[il] += pmdEdep[im][ix][iy][iz];
b2b13ee2 812 }
813 }
36031625 814 totEdp += trEdp[il];
b2b13ee2 815 }
36031625 816 Int_t ilOld = 0;
817 Float_t fracOld = 0.;
b2b13ee2 818
36031625 819 for (il = 0; il < trCount; il++)
b2b13ee2 820 {
36031625 821 fracEdp[il] = trEdp[il]/totEdp;
822 if (fracOld < fracEdp[il])
b2b13ee2 823 {
36031625 824 fracOld = fracEdp[il];
825 ilOld = il;
b2b13ee2 826 }
827 }
36031625 828 fPRETrackNo[im][ix][iy] = trnarray[ilOld];
829 delete fracEdp;
830 delete trEdp;
75bb524e 831 delete trnarray;
b2b13ee2 832 }
833 else if (nn == 1)
834 {
835 // This only handles if a cell is fired
836 // by only one track
837
36031625 838 fPRETrackNo[im][ix][iy] = pmdTrack[im][ix][iy][0];
b2b13ee2 839
840 }
841 else if (nn ==0)
842 {
843 // This is if no cell is fired
36031625 844 fPRETrackNo[im][ix][iy] = -999;
b2b13ee2 845 }
846 } // end of iy
847 } // end of ix
848 } // end of im
849
850 // Delete all the pointers
851
36031625 852 for (i = 0; i < fgkTotUM; i++)
b2b13ee2 853 {
36031625 854 for (j = 0; j < fgkRow; j++)
b2b13ee2 855 {
36031625 856 for (k = 0; k < fgkCol; k++)
b2b13ee2 857 {
36031625 858 delete [] pmdTrack[i][j][k];
859 delete [] pmdEdep[i][j][k];
b2b13ee2 860 }
861 }
862 }
863
36031625 864 for (i = 0; i < fgkTotUM; i++)
b2b13ee2 865 {
36031625 866 for (j = 0; j < fgkRow; j++)
b2b13ee2 867 {
36031625 868 delete [] pmdTrack[i][j];
869 delete [] pmdEdep[i][j];
b2b13ee2 870 }
871 }
872
36031625 873 for (i = 0; i < fgkTotUM; i++)
b2b13ee2 874 {
36031625 875 delete [] pmdTrack[i];
876 delete [] pmdEdep[i];
b2b13ee2 877 }
36031625 878 delete pmdTrack;
879 delete pmdEdep;
b2b13ee2 880 //
881 // End of the cell id assignment
882 //
883}
884
a7d110b8 885void AliPMDDigitizer::MeV2ADC(Float_t mev, Float_t & adc) const
b2b13ee2 886{
36031625 887 // This converts the simulated edep to ADC according to the
888 // Test Beam Data
b2b13ee2 889 // To be done
36031625 890 //
b2b13ee2 891 adc = mev*1.;
892}
893void AliPMDDigitizer::AddSDigit(Int_t trnumber, Int_t det, Int_t smnumber,
894 Int_t cellnumber, Float_t adc)
895{
36031625 896 // Add SDigit
897 //
b2b13ee2 898 TClonesArray &lsdigits = *fSDigits;
899 AliPMDsdigit *newcell;
900 newcell = new AliPMDsdigit(trnumber,det,smnumber,cellnumber,adc);
901 new(lsdigits[fNsdigit++]) AliPMDsdigit(newcell);
902 delete newcell;
903}
904
905void AliPMDDigitizer::AddDigit(Int_t trnumber, Int_t det, Int_t smnumber,
906 Int_t cellnumber, Float_t adc)
907{
36031625 908 // Add Digit
909 //
b2b13ee2 910 TClonesArray &ldigits = *fDigits;
911 AliPMDdigit *newcell;
912 newcell = new AliPMDdigit(trnumber,det,smnumber,cellnumber,adc);
913 new(ldigits[fNdigit++]) AliPMDdigit(newcell);
914 delete newcell;
915}
916
b2b13ee2 917void AliPMDDigitizer::SetZPosition(Float_t zpos)
918{
919 fZPos = zpos;
920}
921Float_t AliPMDDigitizer::GetZPosition() const
922{
923 return fZPos;
924}
925
926void AliPMDDigitizer::ResetCell()
927{
36031625 928 // clears the cell array and also the counter
929 // for each cell
930 //
b2b13ee2 931 fCell->Clear();
36031625 932 for (Int_t i = 0; i < fgkTotUM; i++)
b2b13ee2 933 {
36031625 934 for (Int_t j = 0; j < fgkRow; j++)
b2b13ee2 935 {
36031625 936 for (Int_t k = 0; k < fgkCol; k++)
b2b13ee2 937 {
36031625 938 fPRECounter[i][j][k] = 0;
b2b13ee2 939 }
940 }
941 }
942}
943void AliPMDDigitizer::ResetSDigit()
944{
36031625 945 // Clears SDigits
b2b13ee2 946 fNsdigit = 0;
947 if (fSDigits) fSDigits->Clear();
948}
949void AliPMDDigitizer::ResetDigit()
950{
36031625 951 // Clears Digits
b2b13ee2 952 fNdigit = 0;
953 if (fDigits) fDigits->Clear();
954}
955
956void AliPMDDigitizer::ResetCellADC()
957{
36031625 958 // Clears individual cells edep
959 for (Int_t i = 0; i < fgkTotUM; i++)
b2b13ee2 960 {
36031625 961 for (Int_t j = 0; j < fgkRow; j++)
b2b13ee2 962 {
36031625 963 for (Int_t k = 0; k < fgkCol; k++)
b2b13ee2 964 {
965 fCPV[i][j][k] = 0.;
36031625 966 fPRE[i][j][k] = 0.;
b2b13ee2 967 }
968 }
969 }
970}
971
972void AliPMDDigitizer::UnLoad(Option_t *option)
973{
36031625 974 // Unloads all the root files
975 //
b2b13ee2 976 const char *cS = strstr(option,"S");
977 const char *cD = strstr(option,"D");
978
979 fRunLoader->UnloadgAlice();
980 fRunLoader->UnloadHeader();
981 fRunLoader->UnloadKinematics();
982
983 if (cS)
984 {
36031625 985 fPMDLoader->UnloadHits();
b2b13ee2 986 }
987 if (cD)
988 {
36031625 989 fPMDLoader->UnloadHits();
990 fPMDLoader->UnloadSDigits();
b2b13ee2 991 }
992}