1 /***************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
15 //-----------------------------------------------------//
17 // Source File : PMDDigitizer.cxx, Version 00 //
19 // Date : September 20 2002 //
21 //-----------------------------------------------------//
23 #include <Riostream.h>
27 #include <TGeometry.h>
28 #include <TObjArray.h>
29 #include <TClonesArray.h>
32 #include <TParticle.h>
38 #include "AliDetector.h"
39 #include "AliRunLoader.h"
40 #include "AliLoader.h"
41 #include "AliConfig.h"
43 #include "AliRunDigitizer.h"
44 #include "AliDigitizer.h"
45 #include "AliHeader.h"
46 #include "AliCDBManager.h"
47 #include "AliCDBStorage.h"
48 #include "AliCDBEntry.h"
52 #include "AliPMDhit.h"
53 #include "AliPMDcell.h"
54 #include "AliPMDsdigit.h"
55 #include "AliPMDdigit.h"
56 #include "AliPMDCalibData.h"
57 #include "AliPMDDigitizer.h"
60 ClassImp(AliPMDDigitizer)
62 AliPMDDigitizer::AliPMDDigitizer() :
67 fCalibData(GetCalibData()),
74 fZPos(361.5) // in units of cm, default position of PMD
76 // Default Constructor
78 for (Int_t i = 0; i < fgkTotUM; i++)
80 for (Int_t j = 0; j < fgkRow; j++)
82 for (Int_t k = 0; k < fgkCol; k++)
86 fPRECounter[i][j][k] = 0;
87 fPRETrackNo[i][j][k] = -1;
88 fCPVTrackNo[i][j][k] = -1;
95 //____________________________________________________________________________
96 AliPMDDigitizer::AliPMDDigitizer(const AliPMDDigitizer& digitizer):
97 AliDigitizer(digitizer),
102 fCalibData(GetCalibData()),
109 fZPos(361.5) // in units of cm, default position of PMD
112 AliError("Copy constructor not allowed ");
115 //____________________________________________________________________________
117 AliPMDDigitizer & AliPMDDigitizer::operator=(const AliPMDDigitizer& /*digitizer*/)
119 // Assignment operator
120 AliError("Assignement operator not allowed ");
124 //____________________________________________________________________________
125 AliPMDDigitizer::AliPMDDigitizer(AliRunDigitizer* manager):
126 AliDigitizer(manager),
131 fCalibData(GetCalibData()),
132 fSDigits(new TClonesArray("AliPMDsdigit", 1000)),
133 fDigits(new TClonesArray("AliPMDdigit", 1000)),
138 fZPos(361.5)// in units of cm, This is the default position of PMD
140 // ctor which should be used
143 for (Int_t i = 0; i < fgkTotUM; i++)
145 for (Int_t j = 0; j < fgkRow; j++)
147 for (Int_t k = 0; k < fgkCol; k++)
151 fPRECounter[i][j][k] = 0;
152 fPRETrackNo[i][j][k] = -1;
153 fCPVTrackNo[i][j][k] = -1;
159 //____________________________________________________________________________
160 AliPMDDigitizer::~AliPMDDigitizer()
162 // Default Destructor
179 //____________________________________________________________________________
180 void AliPMDDigitizer::OpengAliceFile(const char *file, Option_t *option)
182 // Loads galice.root file and corresponding header, kinematics
183 // hits and sdigits or digits depending on the option
186 TString evfoldname = AliConfig::GetDefaultEventFolderName();
187 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
189 fRunLoader = AliRunLoader::Open(file,AliConfig::GetDefaultEventFolderName(),
194 AliError(Form("Can not open session for file %s.",file));
197 if (!fRunLoader->GetAliRun()) fRunLoader->LoadgAlice();
198 if (!fRunLoader->TreeE()) fRunLoader->LoadHeader();
199 if (!fRunLoader->TreeK()) fRunLoader->LoadKinematics();
201 gAlice = fRunLoader->GetAliRun();
205 AliDebug(1,"Alirun object found");
209 AliError("Could not found Alirun object");
212 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
213 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
214 if (fPMDLoader == 0x0)
216 AliError("Can not find PMDLoader");
219 const char *cHS = strstr(option,"HS");
220 const char *cHD = strstr(option,"HD");
221 const char *cSD = strstr(option,"SD");
225 fPMDLoader->LoadHits("READ");
226 fPMDLoader->LoadSDigits("recreate");
230 fPMDLoader->LoadHits("READ");
231 fPMDLoader->LoadDigits("recreate");
235 fPMDLoader->LoadSDigits("READ");
236 fPMDLoader->LoadDigits("recreate");
239 //____________________________________________________________________________
240 void AliPMDDigitizer::Hits2SDigits(Int_t ievt)
242 // This reads the PMD Hits tree and assigns the right track number
243 // to a cell and stores in the summable digits tree
246 const Int_t kPi0 = 111;
247 const Int_t kGamma = 22;
255 Float_t xPos, yPos, zPos;
256 Int_t xpad = -1, ypad = -1;
258 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
261 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
264 AliDebug(1,Form("Event Number = %d",ievt));
265 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
266 AliDebug(1,Form("Number of Particles = %d",nparticles));
267 fRunLoader->GetEvent(ievt);
268 // ------------------------------------------------------- //
269 // Pointer to specific detector hits.
270 // Get pointers to Alice detectors and Hits containers
272 TTree* treeH = fPMDLoader->TreeH();
274 Int_t ntracks = (Int_t) treeH->GetEntries();
275 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
276 TTree* treeS = fPMDLoader->TreeS();
279 fPMDLoader->MakeTree("S");
280 treeS = fPMDLoader->TreeS();
282 Int_t bufsize = 16000;
283 treeS->Branch("PMDSDigit", &fSDigits, bufsize);
285 TClonesArray* hits = 0;
286 if (fPMD) hits = fPMD->Hits();
288 // Start loop on tracks in the hits containers
290 for (Int_t track=0; track<ntracks;track++)
293 treeH->GetEvent(track);
296 npmd = hits->GetEntriesFast();
297 for (int ipmd = 0; ipmd < npmd; ipmd++)
299 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
300 trackno = fPMDHit->GetTrack();
301 // get kinematics of the particles
303 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
304 trackpid = mparticle->GetPdgCode();
313 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
314 if (mparticle->GetFirstMother() == -1)
316 tracknoOld = trackno;
317 trackpidOld = trackpid;
321 while((imo = mparticle->GetFirstMother()) >= 0)
325 mparticle = gAlice->GetMCApp()->Particle(imo);
326 idmo = mparticle->GetPdgCode();
328 vx = mparticle->Vx();
329 vy = mparticle->Vy();
330 vz = mparticle->Vz();
332 //printf("==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
333 //fprintf(fpw1,"==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
334 if ((idmo == kGamma || idmo == -11 || idmo == 11) && vx == 0. && vy == 0. && vz == 0.)
342 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
351 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
363 mtrackno = tracknoOld;
364 mtrackpid = trackpidOld;
370 edep = fPMDHit->GetEnergy();
371 Int_t vol1 = fPMDHit->GetVolume(1); // Column
372 Int_t vol2 = fPMDHit->GetVolume(2); // Row
373 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
374 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
377 // -----------------------------------------//
378 // In new geometry after adding electronics //
379 // For Super Module 1 & 2 //
380 // nrow = 48, ncol = 96 //
381 // For Super Module 3 & 4 //
382 // nrow = 96, ncol = 48 //
383 // -----------------------------------------//
387 smnumber = (vol8-1)*6 + vol7;
389 if (vol8 == 1 || vol8 == 2)
394 else if (vol8 == 3 || vol8 == 4)
400 AliDebug(2,Form("Zposition = %f Edeposition = %f",zPos,edep));
401 //Float_t zposition = TMath::Abs(zPos);
407 else if (zPos > fZPos)
412 Int_t smn = smnumber - 1;
413 Int_t ixx = xpad - 1;
414 Int_t iyy = ypad - 1;
417 fPRE[smn][ixx][iyy] += edep;
418 fPRECounter[smn][ixx][iyy]++;
420 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
426 fCPV[smn][ixx][iyy] += edep;
427 fCPVTrackNo[smn][ixx][iyy] = mtrackno;
431 } // Track Loop ended
433 TrackAssignment2Cell();
440 for (Int_t idet = 0; idet < 2; idet++)
442 for (Int_t ism = 0; ism < fgkTotUM; ism++)
444 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
446 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
450 deltaE = fPRE[ism][jrow][kcol];
451 trno = fPRETrackNo[ism][jrow][kcol];
456 deltaE = fCPV[ism][jrow][kcol];
457 trno = fCPVTrackNo[ism][jrow][kcol];
462 AddSDigit(trno,detno,ism,jrow,kcol,deltaE);
470 fPMDLoader->WriteSDigits("OVERWRITE");
473 //____________________________________________________________________________
475 void AliPMDDigitizer::Hits2Digits(Int_t ievt)
477 // This reads the PMD Hits tree and assigns the right track number
478 // to a cell and stores in the digits tree
480 const Int_t kPi0 = 111;
481 const Int_t kGamma = 22;
489 Float_t xPos, yPos, zPos;
490 Int_t xpad = -1, ypad = -1;
492 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
494 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
497 AliDebug(1,Form("Event Number = %d",ievt));
498 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
499 AliDebug(1,Form("Number of Particles = %d", nparticles));
500 fRunLoader->GetEvent(ievt);
501 // ------------------------------------------------------- //
502 // Pointer to specific detector hits.
503 // Get pointers to Alice detectors and Hits containers
505 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
506 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
508 if (fPMDLoader == 0x0)
510 AliError("Can not find PMD or PMDLoader");
512 TTree* treeH = fPMDLoader->TreeH();
513 Int_t ntracks = (Int_t) treeH->GetEntries();
514 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
515 fPMDLoader->LoadDigits("recreate");
516 TTree* treeD = fPMDLoader->TreeD();
519 fPMDLoader->MakeTree("D");
520 treeD = fPMDLoader->TreeD();
522 Int_t bufsize = 16000;
523 treeD->Branch("PMDDigit", &fDigits, bufsize);
525 TClonesArray* hits = 0;
526 if (fPMD) hits = fPMD->Hits();
528 // Start loop on tracks in the hits containers
530 for (Int_t track=0; track<ntracks;track++)
533 treeH->GetEvent(track);
537 npmd = hits->GetEntriesFast();
538 for (int ipmd = 0; ipmd < npmd; ipmd++)
540 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
541 trackno = fPMDHit->GetTrack();
543 // get kinematics of the particles
545 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
546 trackpid = mparticle->GetPdgCode();
555 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
556 if (mparticle->GetFirstMother() == -1)
558 tracknoOld = trackno;
559 trackpidOld = trackpid;
564 while((imo = mparticle->GetFirstMother()) >= 0)
568 mparticle = gAlice->GetMCApp()->Particle(imo);
569 idmo = mparticle->GetPdgCode();
571 vx = mparticle->Vx();
572 vy = mparticle->Vy();
573 vz = mparticle->Vz();
575 //printf("==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
576 //fprintf(fpw1,"==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
577 if ((idmo == kGamma || idmo == -11 || idmo == 11) && vx == 0. && vy == 0. && vz == 0.)
585 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
594 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
606 mtrackno = tracknoOld;
607 mtrackpid = trackpidOld;
613 edep = fPMDHit->GetEnergy();
614 Int_t vol1 = fPMDHit->GetVolume(1); // Column
615 Int_t vol2 = fPMDHit->GetVolume(2); // Row
616 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
617 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
620 // -----------------------------------------//
621 // In new geometry after adding electronics //
622 // For Super Module 1 & 2 //
623 // nrow = 48, ncol = 96 //
624 // For Super Module 3 & 4 //
625 // nrow = 96, ncol = 48 //
626 // -----------------------------------------//
628 smnumber = (vol8-1)*6 + vol7;
630 if (vol8 == 1 || vol8 == 2)
635 else if (vol8 == 3 || vol8 == 4)
641 AliDebug(2,Form("ZPosition = %f Edeposition = %d",zPos,edep));
642 //Float_t zposition = TMath::Abs(zPos);
649 else if (zPos > fZPos)
655 Int_t smn = smnumber - 1;
656 Int_t ixx = xpad - 1;
657 Int_t iyy = ypad - 1;
660 fPRE[smn][ixx][iyy] += edep;
661 fPRECounter[smn][ixx][iyy]++;
663 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
669 fCPV[smn][ixx][iyy] += edep;
670 fCPVTrackNo[smn][ixx][iyy] = mtrackno;
674 } // Track Loop ended
676 TrackAssignment2Cell();
684 for (Int_t idet = 0; idet < 2; idet++)
686 for (Int_t ism = 0; ism < fgkTotUM; ism++)
688 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
690 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
694 gain1 = Gain(idet,ism,jrow,kcol);
696 deltaE = fPRE[ism][jrow][kcol]*gain1;
697 trno = fPRETrackNo[ism][jrow][kcol];
702 gain1 = Gain(idet,ism,jrow,kcol);
703 deltaE = fCPV[ism][jrow][kcol]*gain1;
704 trno = fCPVTrackNo[ism][jrow][kcol];
710 AddDigit(trno,detno,ism,jrow,kcol,adc);
716 } // supermodule loop
719 fPMDLoader->WriteDigits("OVERWRITE");
723 //____________________________________________________________________________
726 void AliPMDDigitizer::SDigits2Digits(Int_t ievt)
728 // This reads the PMD sdigits tree and converts energy deposition
729 // in a cell to ADC and stores in the digits tree
732 fRunLoader->GetEvent(ievt);
734 TTree* treeS = fPMDLoader->TreeS();
735 AliPMDsdigit *pmdsdigit;
736 TBranch *branch = treeS->GetBranch("PMDSDigit");
739 AliError("PMD Sdigit branch does not exist");
742 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
743 branch->SetAddress(&fSDigits);
745 TTree* treeD = fPMDLoader->TreeD();
748 fPMDLoader->MakeTree("D");
749 treeD = fPMDLoader->TreeD();
751 Int_t bufsize = 16000;
752 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
753 treeD->Branch("PMDDigit", &fDigits, bufsize);
755 Int_t trno, det, smn;
759 Int_t nmodules = (Int_t) treeS->GetEntries();
760 AliDebug(1,Form("Number of modules = %d",nmodules));
762 for (Int_t imodule = 0; imodule < nmodules; imodule++)
764 treeS->GetEntry(imodule);
765 Int_t nentries = fSDigits->GetLast();
766 AliDebug(2,Form("Number of entries per module = %d",nentries+1));
767 for (Int_t ient = 0; ient < nentries+1; ient++)
769 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
770 trno = pmdsdigit->GetTrackNumber();
771 det = pmdsdigit->GetDetector();
772 smn = pmdsdigit->GetSMNumber();
773 irow = pmdsdigit->GetRow();
774 icol = pmdsdigit->GetColumn();
775 edep = pmdsdigit->GetCellEdep();
778 AddDigit(trno,det,smn,irow,icol,adc);
783 fPMDLoader->WriteDigits("OVERWRITE");
786 //____________________________________________________________________________
787 void AliPMDDigitizer::Exec(Option_t *option)
789 // Does the event merging and digitization
790 const char *cdeb = strstr(option,"deb");
793 AliDebug(100," *** PMD Exec is called ***");
796 Int_t ninputs = fManager->GetNinputs();
797 AliDebug(1,Form("Number of files to be processed = %d",ninputs));
800 for (Int_t i = 0; i < ninputs; i++)
802 Int_t troffset = fManager->GetMask(i);
803 MergeSDigits(i, troffset);
806 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
807 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
808 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
809 if (fPMDLoader == 0x0)
811 AliError("Can not find PMD or PMDLoader");
813 fPMDLoader->LoadDigits("update");
814 TTree* treeD = fPMDLoader->TreeD();
817 fPMDLoader->MakeTree("D");
818 treeD = fPMDLoader->TreeD();
820 Int_t bufsize = 16000;
821 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
822 treeD->Branch("PMDDigit", &fDigits, bufsize);
829 for (Int_t idet = 0; idet < 2; idet++)
831 for (Int_t ism = 0; ism < fgkTotUM; ism++)
833 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
835 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
839 deltaE = fPRE[ism][jrow][kcol];
840 trno = fPRETrackNo[ism][jrow][kcol];
845 deltaE = fCPV[ism][jrow][kcol];
846 trno = fCPVTrackNo[ism][jrow][kcol];
852 AddDigit(trno,detno,ism,jrow,kcol,adc);
858 } // supermodule loop
860 fPMDLoader->WriteDigits("OVERWRITE");
861 fPMDLoader->UnloadDigits();
864 //____________________________________________________________________________
866 void AliPMDDigitizer::MergeSDigits(Int_t filenumber, Int_t troffset)
869 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(filenumber));
870 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
871 fPMDLoader->LoadSDigits("read");
872 TTree* treeS = fPMDLoader->TreeS();
873 AliPMDsdigit *pmdsdigit;
874 TBranch *branch = treeS->GetBranch("PMDSDigit");
875 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
876 branch->SetAddress(&fSDigits);
878 Int_t itrackno, idet, ism;
881 Int_t nmodules = (Int_t) treeS->GetEntries();
882 AliDebug(1,Form("Number of Modules in the treeS = %d",nmodules));
883 AliDebug(1,Form("Track Offset = %d",troffset));
884 for (Int_t imodule = 0; imodule < nmodules; imodule++)
886 treeS->GetEntry(imodule);
887 Int_t nentries = fSDigits->GetLast();
888 AliDebug(2,Form("Number of Entries per Module = %d",nentries));
889 for (Int_t ient = 0; ient < nentries+1; ient++)
891 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
892 itrackno = pmdsdigit->GetTrackNumber();
893 idet = pmdsdigit->GetDetector();
894 ism = pmdsdigit->GetSMNumber();
895 ixp = pmdsdigit->GetRow();
896 iyp = pmdsdigit->GetColumn();
897 edep = pmdsdigit->GetCellEdep();
900 if (fPRE[ism][ixp][iyp] < edep)
902 fPRETrackNo[ism][ixp][iyp] = troffset + itrackno;
904 fPRE[ism][ixp][iyp] += edep;
908 if (fCPV[ism][ixp][iyp] < edep)
910 fCPVTrackNo[ism][ixp][iyp] = troffset + itrackno;
912 fCPV[ism][ixp][iyp] += edep;
918 // ----------------------------------------------------------------------
919 void AliPMDDigitizer::TrackAssignment2Cell()
922 // This block assigns the cell id when there are
923 // multiple tracks in a cell according to the
926 Bool_t jsort = false;
938 pmdTrack = new Int_t ***[fgkTotUM];
939 pmdEdep = new Float_t ***[fgkTotUM];
940 for (i=0; i<fgkTotUM; i++)
942 pmdTrack[i] = new Int_t **[fgkRow];
943 pmdEdep[i] = new Float_t **[fgkRow];
946 for (i = 0; i < fgkTotUM; i++)
948 for (j = 0; j < fgkRow; j++)
950 pmdTrack[i][j] = new Int_t *[fgkCol];
951 pmdEdep[i][j] = new Float_t *[fgkCol];
955 for (i = 0; i < fgkTotUM; i++)
957 for (j = 0; j < fgkRow; j++)
959 for (k = 0; k < fgkCol; k++)
961 Int_t nn = fPRECounter[i][j][k];
964 pmdTrack[i][j][k] = new Int_t[nn];
965 pmdEdep[i][j][k] = new Float_t[nn];
970 pmdTrack[i][j][k] = new Int_t[nn];
971 pmdEdep[i][j][k] = new Float_t[nn];
973 fPRECounter[i][j][k] = 0;
979 Int_t nentries = fCell.GetEntries();
981 Int_t mtrackno, ism, ixp, iyp;
984 for (i = 0; i < nentries; i++)
986 AliPMDcell* cell = (AliPMDcell*)fCell.UncheckedAt(i);
988 mtrackno = cell->GetTrackNumber();
989 ism = cell->GetSMNumber();
992 edep = cell->GetEdep();
993 Int_t nn = fPRECounter[ism][ixp][iyp];
994 pmdTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
995 pmdEdep[ism][ixp][iyp][nn] = edep;
996 fPRECounter[ism][ixp][iyp]++;
1003 for (im=0; im<fgkTotUM; im++)
1005 for (ix=0; ix<fgkRow; ix++)
1007 for (iy=0; iy<fgkCol; iy++)
1009 nn = fPRECounter[im][ix][iy];
1012 // This block handles if a cell is fired
1013 // many times by many tracks
1014 status1 = new Int_t[nn];
1015 status2 = new Int_t[nn];
1016 trnarray = new Int_t[nn];
1017 for (iz = 0; iz < nn; iz++)
1019 status1[iz] = pmdTrack[im][ix][iy][iz];
1021 TMath::Sort(nn,status1,status2,jsort);
1022 Int_t trackOld = -99999;
1023 Int_t track, trCount = 0;
1024 for (iz = 0; iz < nn; iz++)
1026 track = status1[status2[iz]];
1027 if (trackOld != track)
1029 trnarray[trCount] = track;
1036 Float_t totEdp = 0.;
1037 trEdp = new Float_t[trCount];
1038 fracEdp = new Float_t[trCount];
1039 for (il = 0; il < trCount; il++)
1042 track = trnarray[il];
1043 for (iz = 0; iz < nn; iz++)
1045 if (track == pmdTrack[im][ix][iy][iz])
1047 trEdp[il] += pmdEdep[im][ix][iy][iz];
1050 totEdp += trEdp[il];
1053 Float_t fracOld = 0.;
1055 for (il = 0; il < trCount; il++)
1057 fracEdp[il] = trEdp[il]/totEdp;
1058 if (fracOld < fracEdp[il])
1060 fracOld = fracEdp[il];
1064 fPRETrackNo[im][ix][iy] = trnarray[ilOld];
1071 // This only handles if a cell is fired
1072 // by only one track
1074 fPRETrackNo[im][ix][iy] = pmdTrack[im][ix][iy][0];
1079 // This is if no cell is fired
1080 fPRETrackNo[im][ix][iy] = -999;
1086 // Delete all the pointers
1088 for (i = 0; i < fgkTotUM; i++)
1090 for (j = 0; j < fgkRow; j++)
1092 for (k = 0; k < fgkCol; k++)
1094 delete [] pmdTrack[i][j][k];
1095 delete [] pmdEdep[i][j][k];
1100 for (i = 0; i < fgkTotUM; i++)
1102 for (j = 0; j < fgkRow; j++)
1104 delete [] pmdTrack[i][j];
1105 delete [] pmdEdep[i][j];
1109 for (i = 0; i < fgkTotUM; i++)
1111 delete [] pmdTrack[i];
1112 delete [] pmdEdep[i];
1117 // End of the cell id assignment
1120 //____________________________________________________________________________
1121 void AliPMDDigitizer::MeV2ADC(Float_t mev, Float_t & adc) const
1123 // This converts the simulated edep to ADC according to the
1128 // PS Test in September 2003
1129 // MeV - ADC conversion for 10bit ADC
1131 const Float_t kConstant = 7.181;
1132 const Float_t kErConstant = 0.6899;
1133 const Float_t kSlope = 35.93;
1134 const Float_t kErSlope = 0.306;
1136 //gRandom->SetSeed();
1138 Float_t cons = gRandom->Gaus(kConstant,kErConstant);
1139 Float_t slop = gRandom->Gaus(kSlope,kErSlope);
1141 Float_t adc10bit = slop*mev*0.001 + cons;
1145 Int_t adc12bit = (Int_t) (4.0*adc10bit);
1149 adc = (Float_t) adc12bit;
1151 else if (adc12bit >= 3000)
1157 //____________________________________________________________________________
1158 void AliPMDDigitizer::AddSDigit(Int_t trnumber, Int_t det, Int_t smnumber,
1159 Int_t irow, Int_t icol, Float_t adc)
1163 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
1164 TClonesArray &lsdigits = *fSDigits;
1165 new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,det,smnumber,irow,icol,adc);
1167 //____________________________________________________________________________
1169 void AliPMDDigitizer::AddDigit(Int_t trnumber, Int_t det, Int_t smnumber,
1170 Int_t irow, Int_t icol, Float_t adc)
1174 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
1175 TClonesArray &ldigits = *fDigits;
1176 new(ldigits[fNdigit++]) AliPMDdigit(trnumber,det,smnumber,irow,icol,adc);
1178 //____________________________________________________________________________
1180 void AliPMDDigitizer::SetZPosition(Float_t zpos)
1184 //____________________________________________________________________________
1185 Float_t AliPMDDigitizer::GetZPosition() const
1189 //____________________________________________________________________________
1191 void AliPMDDigitizer::ResetCell()
1193 // clears the cell array and also the counter
1197 for (Int_t i = 0; i < fgkTotUM; i++)
1199 for (Int_t j = 0; j < fgkRow; j++)
1201 for (Int_t k = 0; k < fgkCol; k++)
1203 fPRECounter[i][j][k] = 0;
1208 //____________________________________________________________________________
1209 void AliPMDDigitizer::ResetSDigit()
1213 if (fSDigits) fSDigits->Delete();
1215 //____________________________________________________________________________
1216 void AliPMDDigitizer::ResetDigit()
1220 if (fDigits) fDigits->Delete();
1222 //____________________________________________________________________________
1224 void AliPMDDigitizer::ResetCellADC()
1226 // Clears individual cells edep and track number
1227 for (Int_t i = 0; i < fgkTotUM; i++)
1229 for (Int_t j = 0; j < fgkRow; j++)
1231 for (Int_t k = 0; k < fgkCol; k++)
1235 fPRETrackNo[i][j][k] = 0;
1236 fCPVTrackNo[i][j][k] = 0;
1241 //------------------------------------------------------
1242 //____________________________________________________________________________
1244 void AliPMDDigitizer::UnLoad(Option_t *option)
1246 // Unloads all the root files
1248 const char *cS = strstr(option,"S");
1249 const char *cD = strstr(option,"D");
1251 fRunLoader->UnloadgAlice();
1252 fRunLoader->UnloadHeader();
1253 fRunLoader->UnloadKinematics();
1257 fPMDLoader->UnloadHits();
1261 fPMDLoader->UnloadHits();
1262 fPMDLoader->UnloadSDigits();
1266 //----------------------------------------------------------------------
1267 Float_t AliPMDDigitizer::Gain(Int_t det, Int_t smn, Int_t row, Int_t col) const
1269 // returns of the gain of the cell
1270 // Added this method by ZA
1272 //cout<<" I am here in gain "<<fCalibData<< "smn,row, col "<<smn
1273 //<<" "<<row<<" "<<col<<endl;
1276 AliError("No calibration data loaded from CDB!!!");
1281 GainFact = fCalibData->GetGainFact(det,smn,row,col);
1282 printf("\t gain=%10.3f\n",GainFact);
1285 //----------------------------------------------------------------------
1286 AliPMDCalibData* AliPMDDigitizer::GetCalibData() const
1288 // The run number will be centralized in AliCDBManager,
1289 // you don't need to set it here!
1290 // Added this method by ZA
1291 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Data");
1294 AliWarning("Calibration object retrieval failed! Dummy calibration will be used.");
1296 // this just remembers the actual default storage. No problem if it is null.
1297 AliCDBStorage *origStorage = AliCDBManager::Instance()->GetDefaultStorage();
1298 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
1300 entry = AliCDBManager::Instance()->Get("PMD/Calib/Data");
1302 // now reset the original default storage to AliCDBManager...
1303 AliCDBManager::Instance()->SetDefaultStorage(origStorage);
1306 AliPMDCalibData *calibdata=0;
1307 if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
1309 if (!calibdata) AliError("No calibration data from calibration database !");