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 const char *cHS = strstr(option,"HS");
198 const char *cHD = strstr(option,"HD");
199 const char *cSD = strstr(option,"SD");
203 if (!fRunLoader->GetAliRun()) fRunLoader->LoadgAlice();
204 if (!fRunLoader->TreeE()) fRunLoader->LoadHeader();
205 if (!fRunLoader->TreeK()) fRunLoader->LoadKinematics();
207 gAlice = fRunLoader->GetAliRun();
211 AliDebug(1,"Alirun object found");
215 AliError("Could not found Alirun object");
218 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
221 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
222 if (fPMDLoader == 0x0)
224 AliError("Can not find PMDLoader");
230 fPMDLoader->LoadHits("READ");
231 fPMDLoader->LoadSDigits("recreate");
235 fPMDLoader->LoadHits("READ");
236 fPMDLoader->LoadDigits("recreate");
240 fPMDLoader->LoadSDigits("READ");
241 fPMDLoader->LoadDigits("recreate");
244 //____________________________________________________________________________
245 void AliPMDDigitizer::Hits2SDigits(Int_t ievt)
247 // This reads the PMD Hits tree and assigns the right track number
248 // to a cell and stores in the summable digits tree
251 const Int_t kPi0 = 111;
252 const Int_t kGamma = 22;
260 Float_t xPos, yPos, zPos;
261 Int_t xpad = -1, ypad = -1;
263 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
266 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
269 AliDebug(1,Form("Event Number = %d",ievt));
270 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
271 AliDebug(1,Form("Number of Particles = %d",nparticles));
272 fRunLoader->GetEvent(ievt);
273 // ------------------------------------------------------- //
274 // Pointer to specific detector hits.
275 // Get pointers to Alice detectors and Hits containers
277 TTree* treeH = fPMDLoader->TreeH();
279 Int_t ntracks = (Int_t) treeH->GetEntries();
280 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
281 TTree* treeS = fPMDLoader->TreeS();
284 fPMDLoader->MakeTree("S");
285 treeS = fPMDLoader->TreeS();
287 Int_t bufsize = 16000;
288 treeS->Branch("PMDSDigit", &fSDigits, bufsize);
290 TClonesArray* hits = 0;
291 if (fPMD) hits = fPMD->Hits();
293 // Start loop on tracks in the hits containers
295 for (Int_t track=0; track<ntracks;track++)
298 treeH->GetEvent(track);
301 npmd = hits->GetEntriesFast();
302 for (int ipmd = 0; ipmd < npmd; ipmd++)
304 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
305 trackno = fPMDHit->GetTrack();
306 // get kinematics of the particles
308 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
309 trackpid = mparticle->GetPdgCode();
318 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
319 if (mparticle->GetFirstMother() == -1)
321 tracknoOld = trackno;
322 trackpidOld = trackpid;
326 while((imo = mparticle->GetFirstMother()) >= 0)
330 mparticle = gAlice->GetMCApp()->Particle(imo);
331 idmo = mparticle->GetPdgCode();
333 vx = mparticle->Vx();
334 vy = mparticle->Vy();
335 vz = mparticle->Vz();
337 //printf("==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
338 //fprintf(fpw1,"==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
339 if ((idmo == kGamma || idmo == -11 || idmo == 11) && vx == 0. && vy == 0. && vz == 0.)
347 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
356 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
368 mtrackno = tracknoOld;
369 mtrackpid = trackpidOld;
375 edep = fPMDHit->GetEnergy();
376 Int_t vol1 = fPMDHit->GetVolume(1); // Column
377 Int_t vol2 = fPMDHit->GetVolume(2); // Row
378 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
379 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
382 // -----------------------------------------//
383 // In new geometry after adding electronics //
384 // For Super Module 1 & 2 //
385 // nrow = 48, ncol = 96 //
386 // For Super Module 3 & 4 //
387 // nrow = 96, ncol = 48 //
388 // -----------------------------------------//
392 smnumber = (vol8-1)*6 + vol7;
394 if (vol8 == 1 || vol8 == 2)
399 else if (vol8 == 3 || vol8 == 4)
405 AliDebug(2,Form("Zposition = %f Edeposition = %f",zPos,edep));
406 //Float_t zposition = TMath::Abs(zPos);
412 else if (zPos > fZPos)
417 Int_t smn = smnumber - 1;
418 Int_t ixx = xpad - 1;
419 Int_t iyy = ypad - 1;
422 fPRE[smn][ixx][iyy] += edep;
423 fPRECounter[smn][ixx][iyy]++;
425 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
431 fCPV[smn][ixx][iyy] += edep;
432 fCPVTrackNo[smn][ixx][iyy] = mtrackno;
436 } // Track Loop ended
438 TrackAssignment2Cell();
445 for (Int_t idet = 0; idet < 2; idet++)
447 for (Int_t ism = 0; ism < fgkTotUM; ism++)
449 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
451 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
455 deltaE = fPRE[ism][jrow][kcol];
456 trno = fPRETrackNo[ism][jrow][kcol];
461 deltaE = fCPV[ism][jrow][kcol];
462 trno = fCPVTrackNo[ism][jrow][kcol];
467 AddSDigit(trno,detno,ism,jrow,kcol,deltaE);
475 fPMDLoader->WriteSDigits("OVERWRITE");
478 //____________________________________________________________________________
480 void AliPMDDigitizer::Hits2Digits(Int_t ievt)
482 // This reads the PMD Hits tree and assigns the right track number
483 // to a cell and stores in the digits tree
485 const Int_t kPi0 = 111;
486 const Int_t kGamma = 22;
494 Float_t xPos, yPos, zPos;
495 Int_t xpad = -1, ypad = -1;
497 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
499 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
502 AliDebug(1,Form("Event Number = %d",ievt));
503 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
504 AliDebug(1,Form("Number of Particles = %d", nparticles));
505 fRunLoader->GetEvent(ievt);
506 // ------------------------------------------------------- //
507 // Pointer to specific detector hits.
508 // Get pointers to Alice detectors and Hits containers
510 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
511 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
513 if (fPMDLoader == 0x0)
515 AliError("Can not find PMD or PMDLoader");
517 TTree* treeH = fPMDLoader->TreeH();
518 Int_t ntracks = (Int_t) treeH->GetEntries();
519 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
520 fPMDLoader->LoadDigits("recreate");
521 TTree* treeD = fPMDLoader->TreeD();
524 fPMDLoader->MakeTree("D");
525 treeD = fPMDLoader->TreeD();
527 Int_t bufsize = 16000;
528 treeD->Branch("PMDDigit", &fDigits, bufsize);
530 TClonesArray* hits = 0;
531 if (fPMD) hits = fPMD->Hits();
533 // Start loop on tracks in the hits containers
535 for (Int_t track=0; track<ntracks;track++)
538 treeH->GetEvent(track);
542 npmd = hits->GetEntriesFast();
543 for (int ipmd = 0; ipmd < npmd; ipmd++)
545 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
546 trackno = fPMDHit->GetTrack();
548 // get kinematics of the particles
550 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
551 trackpid = mparticle->GetPdgCode();
560 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
561 if (mparticle->GetFirstMother() == -1)
563 tracknoOld = trackno;
564 trackpidOld = trackpid;
569 while((imo = mparticle->GetFirstMother()) >= 0)
573 mparticle = gAlice->GetMCApp()->Particle(imo);
574 idmo = mparticle->GetPdgCode();
576 vx = mparticle->Vx();
577 vy = mparticle->Vy();
578 vz = mparticle->Vz();
580 //printf("==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
581 //fprintf(fpw1,"==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
582 if ((idmo == kGamma || idmo == -11 || idmo == 11) && vx == 0. && vy == 0. && vz == 0.)
590 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
599 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
611 mtrackno = tracknoOld;
612 mtrackpid = trackpidOld;
618 edep = fPMDHit->GetEnergy();
619 Int_t vol1 = fPMDHit->GetVolume(1); // Column
620 Int_t vol2 = fPMDHit->GetVolume(2); // Row
621 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
622 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
625 // -----------------------------------------//
626 // In new geometry after adding electronics //
627 // For Super Module 1 & 2 //
628 // nrow = 48, ncol = 96 //
629 // For Super Module 3 & 4 //
630 // nrow = 96, ncol = 48 //
631 // -----------------------------------------//
633 smnumber = (vol8-1)*6 + vol7;
635 if (vol8 == 1 || vol8 == 2)
640 else if (vol8 == 3 || vol8 == 4)
646 AliDebug(2,Form("ZPosition = %f Edeposition = %d",zPos,edep));
647 //Float_t zposition = TMath::Abs(zPos);
654 else if (zPos > fZPos)
660 Int_t smn = smnumber - 1;
661 Int_t ixx = xpad - 1;
662 Int_t iyy = ypad - 1;
665 fPRE[smn][ixx][iyy] += edep;
666 fPRECounter[smn][ixx][iyy]++;
668 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
674 fCPV[smn][ixx][iyy] += edep;
675 fCPVTrackNo[smn][ixx][iyy] = mtrackno;
679 } // Track Loop ended
681 TrackAssignment2Cell();
689 for (Int_t idet = 0; idet < 2; idet++)
691 for (Int_t ism = 0; ism < fgkTotUM; ism++)
693 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
695 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
699 gain1 = Gain(idet,ism,jrow,kcol);
701 deltaE = fPRE[ism][jrow][kcol]*gain1;
702 trno = fPRETrackNo[ism][jrow][kcol];
707 gain1 = Gain(idet,ism,jrow,kcol);
708 deltaE = fCPV[ism][jrow][kcol]*gain1;
709 trno = fCPVTrackNo[ism][jrow][kcol];
715 AddDigit(trno,detno,ism,jrow,kcol,adc);
721 } // supermodule loop
724 fPMDLoader->WriteDigits("OVERWRITE");
728 //____________________________________________________________________________
731 void AliPMDDigitizer::SDigits2Digits(Int_t ievt)
733 // This reads the PMD sdigits tree and converts energy deposition
734 // in a cell to ADC and stores in the digits tree
737 fRunLoader->GetEvent(ievt);
739 TTree* treeS = fPMDLoader->TreeS();
740 AliPMDsdigit *pmdsdigit;
741 TBranch *branch = treeS->GetBranch("PMDSDigit");
744 AliError("PMD Sdigit branch does not exist");
747 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
748 branch->SetAddress(&fSDigits);
750 TTree* treeD = fPMDLoader->TreeD();
753 fPMDLoader->MakeTree("D");
754 treeD = fPMDLoader->TreeD();
756 Int_t bufsize = 16000;
757 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
758 treeD->Branch("PMDDigit", &fDigits, bufsize);
760 Int_t trno, det, smn;
764 Int_t nmodules = (Int_t) treeS->GetEntries();
765 AliDebug(1,Form("Number of modules = %d",nmodules));
767 for (Int_t imodule = 0; imodule < nmodules; imodule++)
769 treeS->GetEntry(imodule);
770 Int_t nentries = fSDigits->GetLast();
771 AliDebug(2,Form("Number of entries per module = %d",nentries+1));
772 for (Int_t ient = 0; ient < nentries+1; ient++)
774 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
775 trno = pmdsdigit->GetTrackNumber();
776 det = pmdsdigit->GetDetector();
777 smn = pmdsdigit->GetSMNumber();
778 irow = pmdsdigit->GetRow();
779 icol = pmdsdigit->GetColumn();
780 edep = pmdsdigit->GetCellEdep();
783 AddDigit(trno,det,smn,irow,icol,adc);
788 fPMDLoader->WriteDigits("OVERWRITE");
791 //____________________________________________________________________________
792 void AliPMDDigitizer::Exec(Option_t *option)
794 // Does the event merging and digitization
795 const char *cdeb = strstr(option,"deb");
798 AliDebug(100," *** PMD Exec is called ***");
801 Int_t ninputs = fManager->GetNinputs();
802 AliDebug(1,Form("Number of files to be processed = %d",ninputs));
805 for (Int_t i = 0; i < ninputs; i++)
807 Int_t troffset = fManager->GetMask(i);
808 MergeSDigits(i, troffset);
811 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
812 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
813 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
814 if (fPMDLoader == 0x0)
816 AliError("Can not find PMD or PMDLoader");
818 fPMDLoader->LoadDigits("update");
819 TTree* treeD = fPMDLoader->TreeD();
822 fPMDLoader->MakeTree("D");
823 treeD = fPMDLoader->TreeD();
825 Int_t bufsize = 16000;
826 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
827 treeD->Branch("PMDDigit", &fDigits, bufsize);
834 for (Int_t idet = 0; idet < 2; idet++)
836 for (Int_t ism = 0; ism < fgkTotUM; ism++)
838 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
840 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
844 deltaE = fPRE[ism][jrow][kcol];
845 trno = fPRETrackNo[ism][jrow][kcol];
850 deltaE = fCPV[ism][jrow][kcol];
851 trno = fCPVTrackNo[ism][jrow][kcol];
857 AddDigit(trno,detno,ism,jrow,kcol,adc);
863 } // supermodule loop
865 fPMDLoader->WriteDigits("OVERWRITE");
866 fPMDLoader->UnloadDigits();
869 //____________________________________________________________________________
871 void AliPMDDigitizer::MergeSDigits(Int_t filenumber, Int_t troffset)
874 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(filenumber));
875 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
876 fPMDLoader->LoadSDigits("read");
877 TTree* treeS = fPMDLoader->TreeS();
878 AliPMDsdigit *pmdsdigit;
879 TBranch *branch = treeS->GetBranch("PMDSDigit");
880 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
881 branch->SetAddress(&fSDigits);
883 Int_t itrackno, idet, ism;
886 Int_t nmodules = (Int_t) treeS->GetEntries();
887 AliDebug(1,Form("Number of Modules in the treeS = %d",nmodules));
888 AliDebug(1,Form("Track Offset = %d",troffset));
889 for (Int_t imodule = 0; imodule < nmodules; imodule++)
891 treeS->GetEntry(imodule);
892 Int_t nentries = fSDigits->GetLast();
893 AliDebug(2,Form("Number of Entries per Module = %d",nentries));
894 for (Int_t ient = 0; ient < nentries+1; ient++)
896 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
897 itrackno = pmdsdigit->GetTrackNumber();
898 idet = pmdsdigit->GetDetector();
899 ism = pmdsdigit->GetSMNumber();
900 ixp = pmdsdigit->GetRow();
901 iyp = pmdsdigit->GetColumn();
902 edep = pmdsdigit->GetCellEdep();
905 if (fPRE[ism][ixp][iyp] < edep)
907 fPRETrackNo[ism][ixp][iyp] = troffset + itrackno;
909 fPRE[ism][ixp][iyp] += edep;
913 if (fCPV[ism][ixp][iyp] < edep)
915 fCPVTrackNo[ism][ixp][iyp] = troffset + itrackno;
917 fCPV[ism][ixp][iyp] += edep;
923 // ----------------------------------------------------------------------
924 void AliPMDDigitizer::TrackAssignment2Cell()
927 // This block assigns the cell id when there are
928 // multiple tracks in a cell according to the
931 Bool_t jsort = false;
943 pmdTrack = new Int_t ***[fgkTotUM];
944 pmdEdep = new Float_t ***[fgkTotUM];
945 for (i=0; i<fgkTotUM; i++)
947 pmdTrack[i] = new Int_t **[fgkRow];
948 pmdEdep[i] = new Float_t **[fgkRow];
951 for (i = 0; i < fgkTotUM; i++)
953 for (j = 0; j < fgkRow; j++)
955 pmdTrack[i][j] = new Int_t *[fgkCol];
956 pmdEdep[i][j] = new Float_t *[fgkCol];
960 for (i = 0; i < fgkTotUM; i++)
962 for (j = 0; j < fgkRow; j++)
964 for (k = 0; k < fgkCol; k++)
966 Int_t nn = fPRECounter[i][j][k];
969 pmdTrack[i][j][k] = new Int_t[nn];
970 pmdEdep[i][j][k] = new Float_t[nn];
975 pmdTrack[i][j][k] = new Int_t[nn];
976 pmdEdep[i][j][k] = new Float_t[nn];
978 fPRECounter[i][j][k] = 0;
984 Int_t nentries = fCell.GetEntries();
986 Int_t mtrackno, ism, ixp, iyp;
989 for (i = 0; i < nentries; i++)
991 AliPMDcell* cell = (AliPMDcell*)fCell.UncheckedAt(i);
993 mtrackno = cell->GetTrackNumber();
994 ism = cell->GetSMNumber();
997 edep = cell->GetEdep();
998 Int_t nn = fPRECounter[ism][ixp][iyp];
999 pmdTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
1000 pmdEdep[ism][ixp][iyp][nn] = edep;
1001 fPRECounter[ism][ixp][iyp]++;
1008 for (im=0; im<fgkTotUM; im++)
1010 for (ix=0; ix<fgkRow; ix++)
1012 for (iy=0; iy<fgkCol; iy++)
1014 nn = fPRECounter[im][ix][iy];
1017 // This block handles if a cell is fired
1018 // many times by many tracks
1019 status1 = new Int_t[nn];
1020 status2 = new Int_t[nn];
1021 trnarray = new Int_t[nn];
1022 for (iz = 0; iz < nn; iz++)
1024 status1[iz] = pmdTrack[im][ix][iy][iz];
1026 TMath::Sort(nn,status1,status2,jsort);
1027 Int_t trackOld = -99999;
1028 Int_t track, trCount = 0;
1029 for (iz = 0; iz < nn; iz++)
1031 track = status1[status2[iz]];
1032 if (trackOld != track)
1034 trnarray[trCount] = track;
1041 Float_t totEdp = 0.;
1042 trEdp = new Float_t[trCount];
1043 fracEdp = new Float_t[trCount];
1044 for (il = 0; il < trCount; il++)
1047 track = trnarray[il];
1048 for (iz = 0; iz < nn; iz++)
1050 if (track == pmdTrack[im][ix][iy][iz])
1052 trEdp[il] += pmdEdep[im][ix][iy][iz];
1055 totEdp += trEdp[il];
1058 Float_t fracOld = 0.;
1060 for (il = 0; il < trCount; il++)
1062 fracEdp[il] = trEdp[il]/totEdp;
1063 if (fracOld < fracEdp[il])
1065 fracOld = fracEdp[il];
1069 fPRETrackNo[im][ix][iy] = trnarray[ilOld];
1076 // This only handles if a cell is fired
1077 // by only one track
1079 fPRETrackNo[im][ix][iy] = pmdTrack[im][ix][iy][0];
1084 // This is if no cell is fired
1085 fPRETrackNo[im][ix][iy] = -999;
1091 // Delete all the pointers
1093 for (i = 0; i < fgkTotUM; i++)
1095 for (j = 0; j < fgkRow; j++)
1097 for (k = 0; k < fgkCol; k++)
1099 delete [] pmdTrack[i][j][k];
1100 delete [] pmdEdep[i][j][k];
1105 for (i = 0; i < fgkTotUM; i++)
1107 for (j = 0; j < fgkRow; j++)
1109 delete [] pmdTrack[i][j];
1110 delete [] pmdEdep[i][j];
1114 for (i = 0; i < fgkTotUM; i++)
1116 delete [] pmdTrack[i];
1117 delete [] pmdEdep[i];
1122 // End of the cell id assignment
1125 //____________________________________________________________________________
1126 void AliPMDDigitizer::MeV2ADC(Float_t mev, Float_t & adc) const
1128 // This converts the simulated edep to ADC according to the
1133 // PS Test in September 2003
1134 // MeV - ADC conversion for 10bit ADC
1136 const Float_t kConstant = 7.181;
1137 const Float_t kErConstant = 0.6899;
1138 const Float_t kSlope = 35.93;
1139 const Float_t kErSlope = 0.306;
1141 //gRandom->SetSeed();
1143 Float_t cons = gRandom->Gaus(kConstant,kErConstant);
1144 Float_t slop = gRandom->Gaus(kSlope,kErSlope);
1146 Float_t adc10bit = slop*mev*0.001 + cons;
1150 Int_t adc12bit = (Int_t) (4.0*adc10bit);
1154 adc = (Float_t) adc12bit;
1156 else if (adc12bit >= 3000)
1162 //____________________________________________________________________________
1163 void AliPMDDigitizer::AddSDigit(Int_t trnumber, Int_t det, Int_t smnumber,
1164 Int_t irow, Int_t icol, Float_t adc)
1168 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
1169 TClonesArray &lsdigits = *fSDigits;
1170 new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,det,smnumber,irow,icol,adc);
1172 //____________________________________________________________________________
1174 void AliPMDDigitizer::AddDigit(Int_t trnumber, Int_t det, Int_t smnumber,
1175 Int_t irow, Int_t icol, Float_t adc)
1179 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
1180 TClonesArray &ldigits = *fDigits;
1181 new(ldigits[fNdigit++]) AliPMDdigit(trnumber,det,smnumber,irow,icol,adc);
1183 //____________________________________________________________________________
1185 void AliPMDDigitizer::SetZPosition(Float_t zpos)
1189 //____________________________________________________________________________
1190 Float_t AliPMDDigitizer::GetZPosition() const
1194 //____________________________________________________________________________
1196 void AliPMDDigitizer::ResetCell()
1198 // clears the cell array and also the counter
1202 for (Int_t i = 0; i < fgkTotUM; i++)
1204 for (Int_t j = 0; j < fgkRow; j++)
1206 for (Int_t k = 0; k < fgkCol; k++)
1208 fPRECounter[i][j][k] = 0;
1213 //____________________________________________________________________________
1214 void AliPMDDigitizer::ResetSDigit()
1218 if (fSDigits) fSDigits->Delete();
1220 //____________________________________________________________________________
1221 void AliPMDDigitizer::ResetDigit()
1225 if (fDigits) fDigits->Delete();
1227 //____________________________________________________________________________
1229 void AliPMDDigitizer::ResetCellADC()
1231 // Clears individual cells edep and track number
1232 for (Int_t i = 0; i < fgkTotUM; i++)
1234 for (Int_t j = 0; j < fgkRow; j++)
1236 for (Int_t k = 0; k < fgkCol; k++)
1240 fPRETrackNo[i][j][k] = 0;
1241 fCPVTrackNo[i][j][k] = 0;
1246 //------------------------------------------------------
1247 //____________________________________________________________________________
1249 void AliPMDDigitizer::UnLoad(Option_t *option)
1251 // Unloads all the root files
1253 const char *cS = strstr(option,"S");
1254 const char *cD = strstr(option,"D");
1256 fRunLoader->UnloadgAlice();
1257 fRunLoader->UnloadHeader();
1258 fRunLoader->UnloadKinematics();
1262 fPMDLoader->UnloadHits();
1266 fPMDLoader->UnloadHits();
1267 fPMDLoader->UnloadSDigits();
1271 //----------------------------------------------------------------------
1272 Float_t AliPMDDigitizer::Gain(Int_t det, Int_t smn, Int_t row, Int_t col) const
1274 // returns of the gain of the cell
1275 // Added this method by ZA
1277 //cout<<" I am here in gain "<<fCalibData<< "smn,row, col "<<smn
1278 //<<" "<<row<<" "<<col<<endl;
1281 AliError("No calibration data loaded from CDB!!!");
1286 GainFact = fCalibData->GetGainFact(det,smn,row,col);
1287 printf("\t gain=%10.3f\n",GainFact);
1290 //----------------------------------------------------------------------
1291 AliPMDCalibData* AliPMDDigitizer::GetCalibData() const
1293 // The run number will be centralized in AliCDBManager,
1294 // you don't need to set it here!
1295 // Added this method by ZA
1296 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Data");
1299 AliWarning("Calibration object retrieval failed! Dummy calibration will be used.");
1301 // this just remembers the actual default storage. No problem if it is null.
1302 AliCDBStorage *origStorage = AliCDBManager::Instance()->GetDefaultStorage();
1303 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
1305 entry = AliCDBManager::Instance()->Get("PMD/Calib/Data");
1307 // now reset the original default storage to AliCDBManager...
1308 AliCDBManager::Instance()->SetDefaultStorage(origStorage);
1311 AliPMDCalibData *calibdata=0;
1312 if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
1314 if (!calibdata) AliError("No calibration data from calibration database !");