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 //____________________________________________________________________________
116 AliPMDDigitizer & AliPMDDigitizer::operator=(const AliPMDDigitizer& /*digitizer*/)
118 // Assignment operator
119 AliError("Assignement operator not allowed ");
123 //____________________________________________________________________________
124 AliPMDDigitizer::AliPMDDigitizer(AliRunDigitizer* manager):
125 AliDigitizer(manager),
130 fCalibData(GetCalibData()),
131 fSDigits(new TClonesArray("AliPMDsdigit", 1000)),
132 fDigits(new TClonesArray("AliPMDdigit", 1000)),
137 fZPos(361.5)// in units of cm, This is the default position of PMD
139 // ctor which should be used
142 for (Int_t i = 0; i < fgkTotUM; i++)
144 for (Int_t j = 0; j < fgkRow; j++)
146 for (Int_t k = 0; k < fgkCol; k++)
150 fPRECounter[i][j][k] = 0;
151 fPRETrackNo[i][j][k] = -1;
152 fCPVTrackNo[i][j][k] = -1;
158 //____________________________________________________________________________
159 AliPMDDigitizer::~AliPMDDigitizer()
161 // Default Destructor
178 //____________________________________________________________________________
179 void AliPMDDigitizer::OpengAliceFile(const char *file, Option_t *option)
181 // Loads galice.root file and corresponding header, kinematics
182 // hits and sdigits or digits depending on the option
185 TString evfoldname = AliConfig::GetDefaultEventFolderName();
186 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
188 fRunLoader = AliRunLoader::Open(file,AliConfig::GetDefaultEventFolderName(), "UPDATE");
192 AliError(Form("Can not open session for file %s.",file));
195 const char *cHS = strstr(option,"HS");
196 const char *cHD = strstr(option,"HD");
197 const char *cSD = strstr(option,"SD");
201 if (!fRunLoader->GetAliRun()) fRunLoader->LoadgAlice();
202 if (!fRunLoader->TreeE()) fRunLoader->LoadHeader();
203 if (!fRunLoader->TreeK()) fRunLoader->LoadKinematics();
205 gAlice = fRunLoader->GetAliRun();
209 AliDebug(1,"Alirun object found");
213 AliError("Could not found Alirun object");
216 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
219 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
220 if (fPMDLoader == 0x0)
222 AliError("Can not find PMDLoader");
228 fPMDLoader->LoadHits("READ");
229 fPMDLoader->LoadSDigits("recreate");
233 fPMDLoader->LoadHits("READ");
234 fPMDLoader->LoadDigits("recreate");
238 fPMDLoader->LoadSDigits("READ");
239 fPMDLoader->LoadDigits("recreate");
242 //____________________________________________________________________________
243 void AliPMDDigitizer::Hits2SDigits(Int_t ievt)
245 // This reads the PMD Hits tree and assigns the right track number
246 // to a cell and stores in the summable digits tree
249 const Int_t kPi0 = 111;
250 const Int_t kGamma = 22;
258 Float_t xPos, yPos, zPos;
259 Int_t xpad = -1, ypad = -1;
261 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
264 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
267 AliDebug(1,Form("Event Number = %d",ievt));
268 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
269 AliDebug(1,Form("Number of Particles = %d",nparticles));
270 fRunLoader->GetEvent(ievt);
271 // ------------------------------------------------------- //
272 // Pointer to specific detector hits.
273 // Get pointers to Alice detectors and Hits containers
275 TTree* treeH = fPMDLoader->TreeH();
277 Int_t ntracks = (Int_t) treeH->GetEntries();
278 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
279 TTree* treeS = fPMDLoader->TreeS();
282 fPMDLoader->MakeTree("S");
283 treeS = fPMDLoader->TreeS();
285 Int_t bufsize = 16000;
286 treeS->Branch("PMDSDigit", &fSDigits, bufsize);
288 TClonesArray* hits = 0;
289 if (fPMD) hits = fPMD->Hits();
291 // Start loop on tracks in the hits containers
293 for (Int_t track=0; track<ntracks;track++)
296 treeH->GetEvent(track);
299 npmd = hits->GetEntriesFast();
300 for (int ipmd = 0; ipmd < npmd; ipmd++)
302 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
303 trackno = fPMDHit->GetTrack();
304 // get kinematics of the particles
306 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
307 trackpid = mparticle->GetPdgCode();
316 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
317 if (mparticle->GetFirstMother() == -1)
319 tracknoOld = trackno;
320 trackpidOld = trackpid;
324 while((imo = mparticle->GetFirstMother()) >= 0)
328 mparticle = gAlice->GetMCApp()->Particle(imo);
329 idmo = mparticle->GetPdgCode();
331 vx = mparticle->Vx();
332 vy = mparticle->Vy();
333 vz = mparticle->Vz();
335 //printf("==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
336 //fprintf(fpw1,"==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
337 if ((idmo == kGamma || idmo == -11 || idmo == 11) && vx == 0. && vy == 0. && vz == 0.)
345 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
354 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
366 mtrackno = tracknoOld;
367 mtrackpid = trackpidOld;
373 edep = fPMDHit->GetEnergy();
374 Int_t vol1 = fPMDHit->GetVolume(1); // Column
375 Int_t vol2 = fPMDHit->GetVolume(2); // Row
376 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
377 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
380 // -----------------------------------------//
381 // In new geometry after adding electronics //
382 // For Super Module 1 & 2 //
383 // nrow = 48, ncol = 96 //
384 // For Super Module 3 & 4 //
385 // nrow = 96, ncol = 48 //
386 // -----------------------------------------//
390 smnumber = (vol8-1)*6 + vol7;
392 if (vol8 == 1 || vol8 == 2)
397 else if (vol8 == 3 || vol8 == 4)
403 AliDebug(2,Form("Zposition = %f Edeposition = %f",zPos,edep));
404 //Float_t zposition = TMath::Abs(zPos);
410 else if (zPos > fZPos)
415 Int_t smn = smnumber - 1;
416 Int_t ixx = xpad - 1;
417 Int_t iyy = ypad - 1;
420 fPRE[smn][ixx][iyy] += edep;
421 fPRECounter[smn][ixx][iyy]++;
423 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
428 fCPV[smn][ixx][iyy] += edep;
429 fCPVTrackNo[smn][ixx][iyy] = mtrackno;
433 } // Track Loop ended
435 TrackAssignment2Cell();
442 for (Int_t idet = 0; idet < 2; idet++)
444 for (Int_t ism = 0; ism < fgkTotUM; ism++)
446 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
448 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
452 deltaE = fPRE[ism][jrow][kcol];
453 trno = fPRETrackNo[ism][jrow][kcol];
458 deltaE = fCPV[ism][jrow][kcol];
459 trno = fCPVTrackNo[ism][jrow][kcol];
464 AddSDigit(trno,detno,ism,jrow,kcol,deltaE);
472 fPMDLoader->WriteSDigits("OVERWRITE");
475 //____________________________________________________________________________
477 void AliPMDDigitizer::Hits2Digits(Int_t ievt)
479 // This reads the PMD Hits tree and assigns the right track number
480 // to a cell and stores in the digits tree
482 const Int_t kPi0 = 111;
483 const Int_t kGamma = 22;
491 Float_t xPos, yPos, zPos;
492 Int_t xpad = -1, ypad = -1;
494 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
496 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
499 AliDebug(1,Form("Event Number = %d",ievt));
500 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
501 AliDebug(1,Form("Number of Particles = %d", nparticles));
502 fRunLoader->GetEvent(ievt);
503 // ------------------------------------------------------- //
504 // Pointer to specific detector hits.
505 // Get pointers to Alice detectors and Hits containers
507 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
508 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
510 if (fPMDLoader == 0x0)
512 AliError("Can not find PMD or PMDLoader");
514 TTree* treeH = fPMDLoader->TreeH();
515 Int_t ntracks = (Int_t) treeH->GetEntries();
516 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
517 fPMDLoader->LoadDigits("recreate");
518 TTree* treeD = fPMDLoader->TreeD();
521 fPMDLoader->MakeTree("D");
522 treeD = fPMDLoader->TreeD();
524 Int_t bufsize = 16000;
525 treeD->Branch("PMDDigit", &fDigits, bufsize);
527 TClonesArray* hits = 0;
528 if (fPMD) hits = fPMD->Hits();
530 // Start loop on tracks in the hits containers
532 for (Int_t track=0; track<ntracks;track++)
535 treeH->GetEvent(track);
539 npmd = hits->GetEntriesFast();
540 for (int ipmd = 0; ipmd < npmd; ipmd++)
542 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
543 trackno = fPMDHit->GetTrack();
545 // get kinematics of the particles
547 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
548 trackpid = mparticle->GetPdgCode();
557 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
558 if (mparticle->GetFirstMother() == -1)
560 tracknoOld = trackno;
561 trackpidOld = trackpid;
566 while((imo = mparticle->GetFirstMother()) >= 0)
570 mparticle = gAlice->GetMCApp()->Particle(imo);
571 idmo = mparticle->GetPdgCode();
573 vx = mparticle->Vx();
574 vy = mparticle->Vy();
575 vz = mparticle->Vz();
577 //printf("==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
578 //fprintf(fpw1,"==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
579 if ((idmo == kGamma || idmo == -11 || idmo == 11) && vx == 0. && vy == 0. && vz == 0.)
587 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
596 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
608 mtrackno = tracknoOld;
609 mtrackpid = trackpidOld;
615 edep = fPMDHit->GetEnergy();
616 Int_t vol1 = fPMDHit->GetVolume(1); // Column
617 Int_t vol2 = fPMDHit->GetVolume(2); // Row
618 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
619 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
622 // -----------------------------------------//
623 // In new geometry after adding electronics //
624 // For Super Module 1 & 2 //
625 // nrow = 48, ncol = 96 //
626 // For Super Module 3 & 4 //
627 // nrow = 96, ncol = 48 //
628 // -----------------------------------------//
630 smnumber = (vol8-1)*6 + vol7;
632 if (vol8 == 1 || vol8 == 2)
637 else if (vol8 == 3 || vol8 == 4)
643 AliDebug(2,Form("ZPosition = %f Edeposition = %d",zPos,edep));
644 //Float_t zposition = TMath::Abs(zPos);
651 else if (zPos > fZPos)
657 Int_t smn = smnumber - 1;
658 Int_t ixx = xpad - 1;
659 Int_t iyy = ypad - 1;
662 fPRE[smn][ixx][iyy] += edep;
663 fPRECounter[smn][ixx][iyy]++;
665 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
671 fCPV[smn][ixx][iyy] += edep;
672 fCPVTrackNo[smn][ixx][iyy] = mtrackno;
676 } // Track Loop ended
678 TrackAssignment2Cell();
686 for (Int_t idet = 0; idet < 2; idet++)
688 for (Int_t ism = 0; ism < fgkTotUM; ism++)
690 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
692 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
696 deltaE = fPRE[ism][jrow][kcol];
697 trno = fPRETrackNo[ism][jrow][kcol];
702 deltaE = fCPV[ism][jrow][kcol];
703 trno = fCPVTrackNo[ism][jrow][kcol];
710 // To decalibrate the adc values
712 gain1 = Gain(idet,ism,jrow,kcol);
715 Int_t adcDecalib = (Int_t)(adc/gain1);
716 adc = (Float_t) adcDecalib;
722 AddDigit(trno,detno,ism,jrow,kcol,adc);
728 } // supermodule loop
731 fPMDLoader->WriteDigits("OVERWRITE");
735 //____________________________________________________________________________
738 void AliPMDDigitizer::SDigits2Digits(Int_t ievt)
740 // This reads the PMD sdigits tree and converts energy deposition
741 // in a cell to ADC and stores in the digits tree
744 fRunLoader->GetEvent(ievt);
746 TTree* treeS = fPMDLoader->TreeS();
747 AliPMDsdigit *pmdsdigit;
748 TBranch *branch = treeS->GetBranch("PMDSDigit");
751 AliError("PMD Sdigit branch does not exist");
754 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
755 branch->SetAddress(&fSDigits);
757 TTree* treeD = fPMDLoader->TreeD();
760 fPMDLoader->MakeTree("D");
761 treeD = fPMDLoader->TreeD();
763 Int_t bufsize = 16000;
764 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
765 treeD->Branch("PMDDigit", &fDigits, bufsize);
767 Int_t trno, det, smn;
771 Int_t nmodules = (Int_t) treeS->GetEntries();
772 AliDebug(1,Form("Number of modules = %d",nmodules));
774 for (Int_t imodule = 0; imodule < nmodules; imodule++)
776 treeS->GetEntry(imodule);
777 Int_t nentries = fSDigits->GetLast();
778 AliDebug(2,Form("Number of entries per module = %d",nentries+1));
779 for (Int_t ient = 0; ient < nentries+1; ient++)
781 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
782 trno = pmdsdigit->GetTrackNumber();
783 det = pmdsdigit->GetDetector();
784 smn = pmdsdigit->GetSMNumber();
785 irow = pmdsdigit->GetRow();
786 icol = pmdsdigit->GetColumn();
787 edep = pmdsdigit->GetCellEdep();
791 // To decalibrte the adc values
793 Float_t gain1 = Gain(det,smn,irow,icol);
796 Int_t adcDecalib = (Int_t)(adc/gain1);
797 adc = (Float_t) adcDecalib;
804 AddDigit(trno,det,smn,irow,icol,adc);
809 fPMDLoader->WriteDigits("OVERWRITE");
812 //____________________________________________________________________________
813 void AliPMDDigitizer::Exec(Option_t *option)
815 // Does the event merging and digitization
816 const char *cdeb = strstr(option,"deb");
819 AliDebug(100," *** PMD Exec is called ***");
822 Int_t ninputs = fManager->GetNinputs();
823 AliDebug(1,Form("Number of files to be processed = %d",ninputs));
826 for (Int_t i = 0; i < ninputs; i++)
828 Int_t troffset = fManager->GetMask(i);
829 MergeSDigits(i, troffset);
832 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
833 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
834 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
835 if (fPMDLoader == 0x0)
837 AliError("Can not find PMD or PMDLoader");
839 fPMDLoader->LoadDigits("update");
840 TTree* treeD = fPMDLoader->TreeD();
843 fPMDLoader->MakeTree("D");
844 treeD = fPMDLoader->TreeD();
846 Int_t bufsize = 16000;
847 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
848 treeD->Branch("PMDDigit", &fDigits, bufsize);
855 for (Int_t idet = 0; idet < 2; idet++)
857 for (Int_t ism = 0; ism < fgkTotUM; ism++)
859 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
861 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
865 deltaE = fPRE[ism][jrow][kcol];
866 trno = fPRETrackNo[ism][jrow][kcol];
871 deltaE = fCPV[ism][jrow][kcol];
872 trno = fCPVTrackNo[ism][jrow][kcol];
879 // To decalibrte the adc values
881 Float_t gain1 = Gain(idet,ism,jrow,kcol);
884 Int_t adcDecalib = (Int_t)(adc/gain1);
885 adc = (Float_t) adcDecalib;
892 AddDigit(trno,detno,ism,jrow,kcol,adc);
898 } // supermodule loop
900 fPMDLoader->WriteDigits("OVERWRITE");
901 fPMDLoader->UnloadDigits();
904 //____________________________________________________________________________
906 void AliPMDDigitizer::MergeSDigits(Int_t filenumber, Int_t troffset)
909 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(filenumber));
910 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
911 fPMDLoader->LoadSDigits("read");
912 TTree* treeS = fPMDLoader->TreeS();
913 AliPMDsdigit *pmdsdigit;
914 TBranch *branch = treeS->GetBranch("PMDSDigit");
915 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
916 branch->SetAddress(&fSDigits);
918 Int_t itrackno, idet, ism;
921 Int_t nmodules = (Int_t) treeS->GetEntries();
922 AliDebug(1,Form("Number of Modules in the treeS = %d",nmodules));
923 AliDebug(1,Form("Track Offset = %d",troffset));
924 for (Int_t imodule = 0; imodule < nmodules; imodule++)
926 treeS->GetEntry(imodule);
927 Int_t nentries = fSDigits->GetLast();
928 AliDebug(2,Form("Number of Entries per Module = %d",nentries));
929 for (Int_t ient = 0; ient < nentries+1; ient++)
931 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
932 itrackno = pmdsdigit->GetTrackNumber();
933 idet = pmdsdigit->GetDetector();
934 ism = pmdsdigit->GetSMNumber();
935 ixp = pmdsdigit->GetRow();
936 iyp = pmdsdigit->GetColumn();
937 edep = pmdsdigit->GetCellEdep();
940 if (fPRE[ism][ixp][iyp] < edep)
942 fPRETrackNo[ism][ixp][iyp] = troffset + itrackno;
944 fPRE[ism][ixp][iyp] += edep;
948 if (fCPV[ism][ixp][iyp] < edep)
950 fCPVTrackNo[ism][ixp][iyp] = troffset + itrackno;
952 fCPV[ism][ixp][iyp] += edep;
958 // ----------------------------------------------------------------------
959 void AliPMDDigitizer::TrackAssignment2Cell()
962 // This block assigns the cell id when there are
963 // multiple tracks in a cell according to the
966 Bool_t jsort = false;
978 pmdTrack = new Int_t ***[fgkTotUM];
979 pmdEdep = new Float_t ***[fgkTotUM];
980 for (i=0; i<fgkTotUM; i++)
982 pmdTrack[i] = new Int_t **[fgkRow];
983 pmdEdep[i] = new Float_t **[fgkRow];
986 for (i = 0; i < fgkTotUM; i++)
988 for (j = 0; j < fgkRow; j++)
990 pmdTrack[i][j] = new Int_t *[fgkCol];
991 pmdEdep[i][j] = new Float_t *[fgkCol];
995 for (i = 0; i < fgkTotUM; i++)
997 for (j = 0; j < fgkRow; j++)
999 for (k = 0; k < fgkCol; k++)
1001 Int_t nn = fPRECounter[i][j][k];
1004 pmdTrack[i][j][k] = new Int_t[nn];
1005 pmdEdep[i][j][k] = new Float_t[nn];
1010 pmdTrack[i][j][k] = new Int_t[nn];
1011 pmdEdep[i][j][k] = new Float_t[nn];
1013 fPRECounter[i][j][k] = 0;
1019 Int_t nentries = fCell.GetEntries();
1021 Int_t mtrackno, ism, ixp, iyp;
1024 for (i = 0; i < nentries; i++)
1026 AliPMDcell* cell = (AliPMDcell*)fCell.UncheckedAt(i);
1028 mtrackno = cell->GetTrackNumber();
1029 ism = cell->GetSMNumber();
1032 edep = cell->GetEdep();
1033 Int_t nn = fPRECounter[ism][ixp][iyp];
1034 pmdTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
1035 pmdEdep[ism][ixp][iyp][nn] = edep;
1036 fPRECounter[ism][ixp][iyp]++;
1043 for (im=0; im<fgkTotUM; im++)
1045 for (ix=0; ix<fgkRow; ix++)
1047 for (iy=0; iy<fgkCol; iy++)
1049 nn = fPRECounter[im][ix][iy];
1052 // This block handles if a cell is fired
1053 // many times by many tracks
1054 status1 = new Int_t[nn];
1055 status2 = new Int_t[nn];
1056 trnarray = new Int_t[nn];
1057 for (iz = 0; iz < nn; iz++)
1059 status1[iz] = pmdTrack[im][ix][iy][iz];
1061 TMath::Sort(nn,status1,status2,jsort);
1062 Int_t trackOld = -99999;
1063 Int_t track, trCount = 0;
1064 for (iz = 0; iz < nn; iz++)
1066 track = status1[status2[iz]];
1067 if (trackOld != track)
1069 trnarray[trCount] = track;
1076 Float_t totEdp = 0.;
1077 trEdp = new Float_t[trCount];
1078 fracEdp = new Float_t[trCount];
1079 for (il = 0; il < trCount; il++)
1082 track = trnarray[il];
1083 for (iz = 0; iz < nn; iz++)
1085 if (track == pmdTrack[im][ix][iy][iz])
1087 trEdp[il] += pmdEdep[im][ix][iy][iz];
1090 totEdp += trEdp[il];
1093 Float_t fracOld = 0.;
1095 for (il = 0; il < trCount; il++)
1097 fracEdp[il] = trEdp[il]/totEdp;
1098 if (fracOld < fracEdp[il])
1100 fracOld = fracEdp[il];
1104 fPRETrackNo[im][ix][iy] = trnarray[ilOld];
1111 // This only handles if a cell is fired
1112 // by only one track
1114 fPRETrackNo[im][ix][iy] = pmdTrack[im][ix][iy][0];
1119 // This is if no cell is fired
1120 fPRETrackNo[im][ix][iy] = -999;
1126 // Delete all the pointers
1128 for (i = 0; i < fgkTotUM; i++)
1130 for (j = 0; j < fgkRow; j++)
1132 for (k = 0; k < fgkCol; k++)
1134 delete [] pmdTrack[i][j][k];
1135 delete [] pmdEdep[i][j][k];
1140 for (i = 0; i < fgkTotUM; i++)
1142 for (j = 0; j < fgkRow; j++)
1144 delete [] pmdTrack[i][j];
1145 delete [] pmdEdep[i][j];
1149 for (i = 0; i < fgkTotUM; i++)
1151 delete [] pmdTrack[i];
1152 delete [] pmdEdep[i];
1157 // End of the cell id assignment
1160 //____________________________________________________________________________
1161 void AliPMDDigitizer::MeV2ADC(Float_t mev, Float_t & adc) const
1163 // This converts the simulated edep to ADC according to the
1168 // PS Test in September 2003
1169 // MeV - ADC conversion for 10bit ADC
1171 const Float_t kConstant = 7.181;
1172 const Float_t kErConstant = 0.6899;
1173 const Float_t kSlope = 35.93;
1174 const Float_t kErSlope = 0.306;
1176 //gRandom->SetSeed();
1178 Float_t cons = gRandom->Gaus(kConstant,kErConstant);
1179 Float_t slop = gRandom->Gaus(kSlope,kErSlope);
1181 Float_t adc10bit = slop*mev*0.001 + cons;
1185 Int_t adc12bit = (Int_t) (4.0*adc10bit);
1189 adc = (Float_t) adc12bit;
1191 else if (adc12bit >= 3000)
1197 //____________________________________________________________________________
1198 void AliPMDDigitizer::AddSDigit(Int_t trnumber, Int_t det, Int_t smnumber,
1199 Int_t irow, Int_t icol, Float_t adc)
1203 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
1204 TClonesArray &lsdigits = *fSDigits;
1205 new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,det,smnumber,irow,icol,adc);
1207 //____________________________________________________________________________
1209 void AliPMDDigitizer::AddDigit(Int_t trnumber, Int_t det, Int_t smnumber,
1210 Int_t irow, Int_t icol, Float_t adc)
1214 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
1215 TClonesArray &ldigits = *fDigits;
1216 new(ldigits[fNdigit++]) AliPMDdigit(trnumber,det,smnumber,irow,icol,adc);
1218 //____________________________________________________________________________
1220 void AliPMDDigitizer::SetZPosition(Float_t zpos)
1224 //____________________________________________________________________________
1225 Float_t AliPMDDigitizer::GetZPosition() const
1229 //____________________________________________________________________________
1231 void AliPMDDigitizer::ResetCell()
1233 // clears the cell array and also the counter
1237 for (Int_t i = 0; i < fgkTotUM; i++)
1239 for (Int_t j = 0; j < fgkRow; j++)
1241 for (Int_t k = 0; k < fgkCol; k++)
1243 fPRECounter[i][j][k] = 0;
1248 //____________________________________________________________________________
1249 void AliPMDDigitizer::ResetSDigit()
1253 if (fSDigits) fSDigits->Delete();
1255 //____________________________________________________________________________
1256 void AliPMDDigitizer::ResetDigit()
1260 if (fDigits) fDigits->Delete();
1262 //____________________________________________________________________________
1264 void AliPMDDigitizer::ResetCellADC()
1266 // Clears individual cells edep and track number
1267 for (Int_t i = 0; i < fgkTotUM; i++)
1269 for (Int_t j = 0; j < fgkRow; j++)
1271 for (Int_t k = 0; k < fgkCol; k++)
1275 fPRETrackNo[i][j][k] = 0;
1276 fCPVTrackNo[i][j][k] = 0;
1281 //____________________________________________________________________________
1283 void AliPMDDigitizer::UnLoad(Option_t *option)
1285 // Unloads all the root files
1287 const char *cS = strstr(option,"S");
1288 const char *cD = strstr(option,"D");
1290 fRunLoader->UnloadgAlice();
1291 fRunLoader->UnloadHeader();
1292 fRunLoader->UnloadKinematics();
1296 fPMDLoader->UnloadHits();
1300 fPMDLoader->UnloadHits();
1301 fPMDLoader->UnloadSDigits();
1305 //----------------------------------------------------------------------
1306 Float_t AliPMDDigitizer::Gain(Int_t det, Int_t smn, Int_t row, Int_t col) const
1308 // returns of the gain of the cell
1309 // Added this method by ZA
1311 //cout<<" I am here in gain "<<fCalibData<< "smn,row, col "<<smn
1312 //<<" "<<row<<" "<<col<<endl;
1315 AliError("No calibration data loaded from CDB!!!");
1320 GainFact = fCalibData->GetGainFact(det,smn,row,col);
1321 printf("\t gain=%10.3f\n",GainFact);
1324 //----------------------------------------------------------------------
1325 AliPMDCalibData* AliPMDDigitizer::GetCalibData() const
1327 // The run number will be centralized in AliCDBManager,
1328 // you don't need to set it here!
1329 // Added this method by ZA
1330 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Data");
1333 AliWarning("Calibration object retrieval failed! Dummy calibration will be used.");
1335 // this just remembers the actual default storage. No problem if it is null
1336 AliCDBStorage *origStorage = AliCDBManager::Instance()->GetDefaultStorage();
1337 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
1339 entry = AliCDBManager::Instance()->Get("PMD/Calib/Data");
1341 // now reset the original default storage to AliCDBManager...
1342 AliCDBManager::Instance()->SetDefaultStorage(origStorage);
1345 AliPMDCalibData *calibdata=0;
1346 if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
1348 if (!calibdata) AliError("No calibration data from calibration database !");