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>
37 #include "AliDetector.h"
38 #include "AliRunLoader.h"
39 #include "AliLoader.h"
40 #include "AliConfig.h"
42 #include "AliRunDigitizer.h"
43 #include "AliDigitizer.h"
44 #include "AliHeader.h"
45 #include "AliCDBManager.h"
46 #include "AliCDBStorage.h"
47 #include "AliCDBEntry.h"
51 #include "AliPMDhit.h"
52 #include "AliPMDcell.h"
53 #include "AliPMDsdigit.h"
54 #include "AliPMDdigit.h"
55 #include "AliPMDCalibData.h"
56 #include "AliPMDDigitizer.h"
59 ClassImp(AliPMDDigitizer)
61 AliPMDDigitizer::AliPMDDigitizer() :
72 fZPos(361.5)// in units of cm, This is the default position of PMD
74 // Default Constructor
76 for (Int_t i = 0; i < fgkTotUM; i++)
78 for (Int_t j = 0; j < fgkRow; j++)
80 for (Int_t k = 0; k < fgkCol; k++)
84 fPRECounter[i][j][k] = 0;
85 fPRETrackNo[i][j][k] = -1;
86 fCPVTrackNo[i][j][k] = -1;
90 fCalibData = GetCalibData();
93 //____________________________________________________________________________
94 AliPMDDigitizer::AliPMDDigitizer(const AliPMDDigitizer& /*digitizer*/):
95 AliDigitizer(/* digitizer */)
98 AliError("Copy constructor not allowed ");
101 //____________________________________________________________________________
103 AliPMDDigitizer & AliPMDDigitizer::operator=(const AliPMDDigitizer& /*digitizer*/)
105 // Assignment operator
106 AliError("Assignement operator not allowed ");
110 //____________________________________________________________________________
111 AliPMDDigitizer::AliPMDDigitizer(AliRunDigitizer* manager)
112 :AliDigitizer(manager),
117 fSDigits(new TClonesArray("AliPMDsdigit", 1000)),
118 fDigits(new TClonesArray("AliPMDdigit", 1000)),
123 fZPos(361.5)// in units of cm, This is the default position of PMD
125 // ctor which should be used
127 fCalibData = GetCalibData();
129 for (Int_t i = 0; i < fgkTotUM; i++)
131 for (Int_t j = 0; j < fgkRow; j++)
133 for (Int_t k = 0; k < fgkCol; k++)
137 fPRECounter[i][j][k] = 0;
138 fPRETrackNo[i][j][k] = -1;
139 fCPVTrackNo[i][j][k] = -1;
144 //____________________________________________________________________________
145 AliPMDDigitizer::~AliPMDDigitizer()
147 // Default Destructor
164 //____________________________________________________________________________
165 void AliPMDDigitizer::OpengAliceFile(const char *file, Option_t *option)
167 // Loads galice.root file and corresponding header, kinematics
168 // hits and sdigits or digits depending on the option
171 TString evfoldname = AliConfig::GetDefaultEventFolderName();
172 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
174 fRunLoader = AliRunLoader::Open(file,AliConfig::GetDefaultEventFolderName(),
179 AliError(Form("Can not open session for file %s.",file));
182 if (!fRunLoader->GetAliRun()) fRunLoader->LoadgAlice();
183 if (!fRunLoader->TreeE()) fRunLoader->LoadHeader();
184 if (!fRunLoader->TreeK()) fRunLoader->LoadKinematics();
186 gAlice = fRunLoader->GetAliRun();
190 AliDebug(1,"Alirun object found");
194 AliError("Could not found Alirun object");
197 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
198 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
199 if (fPMDLoader == 0x0)
201 AliError("Can not find PMDLoader");
204 const char *cHS = strstr(option,"HS");
205 const char *cHD = strstr(option,"HD");
206 const char *cSD = strstr(option,"SD");
210 fPMDLoader->LoadHits("READ");
211 fPMDLoader->LoadSDigits("recreate");
215 fPMDLoader->LoadHits("READ");
216 fPMDLoader->LoadDigits("recreate");
220 fPMDLoader->LoadSDigits("READ");
221 fPMDLoader->LoadDigits("recreate");
224 //____________________________________________________________________________
225 void AliPMDDigitizer::Hits2SDigits(Int_t ievt)
227 // This reads the PMD Hits tree and assigns the right track number
228 // to a cell and stores in the summable digits tree
231 const Int_t kPi0 = 111;
232 const Int_t kGamma = 22;
240 Float_t xPos, yPos, zPos;
241 Int_t xpad = -1, ypad = -1;
243 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
246 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
249 AliDebug(1,Form("Event Number = %d",ievt));
250 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
251 AliDebug(1,Form("Number of Particles = %d",nparticles));
252 fRunLoader->GetEvent(ievt);
253 // ------------------------------------------------------- //
254 // Pointer to specific detector hits.
255 // Get pointers to Alice detectors and Hits containers
257 TTree* treeH = fPMDLoader->TreeH();
259 Int_t ntracks = (Int_t) treeH->GetEntries();
260 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
261 TTree* treeS = fPMDLoader->TreeS();
264 fPMDLoader->MakeTree("S");
265 treeS = fPMDLoader->TreeS();
267 Int_t bufsize = 16000;
268 treeS->Branch("PMDSDigit", &fSDigits, bufsize);
270 TClonesArray* hits = 0;
271 if (fPMD) hits = fPMD->Hits();
273 // Start loop on tracks in the hits containers
275 for (Int_t track=0; track<ntracks;track++)
278 treeH->GetEvent(track);
281 npmd = hits->GetEntriesFast();
282 for (int ipmd = 0; ipmd < npmd; ipmd++)
284 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
285 trackno = fPMDHit->GetTrack();
286 // get kinematics of the particles
288 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
289 trackpid = mparticle->GetPdgCode();
298 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
299 if (mparticle->GetFirstMother() == -1)
301 tracknoOld = trackno;
302 trackpidOld = trackpid;
306 while((imo = mparticle->GetFirstMother()) >= 0)
310 mparticle = gAlice->GetMCApp()->Particle(imo);
311 idmo = mparticle->GetPdgCode();
313 vx = mparticle->Vx();
314 vy = mparticle->Vy();
315 vz = mparticle->Vz();
317 //printf("==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
318 //fprintf(fpw1,"==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
319 if ((idmo == kGamma || idmo == -11 || idmo == 11) && vx == 0. && vy == 0. && vz == 0.)
327 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
336 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
348 mtrackno = tracknoOld;
349 mtrackpid = trackpidOld;
355 edep = fPMDHit->GetEnergy();
356 Int_t vol1 = fPMDHit->GetVolume(1); // Column
357 Int_t vol2 = fPMDHit->GetVolume(2); // Row
358 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
359 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
362 // -----------------------------------------//
363 // In new geometry after adding electronics //
364 // For Super Module 1 & 2 //
365 // nrow = 48, ncol = 96 //
366 // For Super Module 3 & 4 //
367 // nrow = 96, ncol = 48 //
368 // -----------------------------------------//
372 smnumber = (vol8-1)*6 + vol7;
374 if (vol8 == 1 || vol8 == 2)
379 else if (vol8 == 3 || vol8 == 4)
385 AliDebug(2,Form("Zposition = %f Edeposition = %f",zPos,edep));
386 //Float_t zposition = TMath::Abs(zPos);
392 else if (zPos > fZPos)
397 Int_t smn = smnumber - 1;
398 Int_t ixx = xpad - 1;
399 Int_t iyy = ypad - 1;
402 fPRE[smn][ixx][iyy] += edep;
403 fPRECounter[smn][ixx][iyy]++;
405 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
411 fCPV[smn][ixx][iyy] += edep;
412 fCPVTrackNo[smn][ixx][iyy] = mtrackno;
416 } // Track Loop ended
418 TrackAssignment2Cell();
425 for (Int_t idet = 0; idet < 2; idet++)
427 for (Int_t ism = 0; ism < fgkTotUM; ism++)
429 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
431 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
435 deltaE = fPRE[ism][jrow][kcol];
436 trno = fPRETrackNo[ism][jrow][kcol];
441 deltaE = fCPV[ism][jrow][kcol];
442 trno = fCPVTrackNo[ism][jrow][kcol];
447 AddSDigit(trno,detno,ism,jrow,kcol,deltaE);
455 fPMDLoader->WriteSDigits("OVERWRITE");
458 //____________________________________________________________________________
460 void AliPMDDigitizer::Hits2Digits(Int_t ievt)
462 // This reads the PMD Hits tree and assigns the right track number
463 // to a cell and stores in the digits tree
465 const Int_t kPi0 = 111;
466 const Int_t kGamma = 22;
474 Float_t xPos, yPos, zPos;
475 Int_t xpad = -1, ypad = -1;
477 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
479 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
482 AliDebug(1,Form("Event Number = %d",ievt));
483 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
484 AliDebug(1,Form("Number of Particles = %d", nparticles));
485 fRunLoader->GetEvent(ievt);
486 // ------------------------------------------------------- //
487 // Pointer to specific detector hits.
488 // Get pointers to Alice detectors and Hits containers
490 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
491 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
493 if (fPMDLoader == 0x0)
495 AliError("Can not find PMD or PMDLoader");
497 TTree* treeH = fPMDLoader->TreeH();
498 Int_t ntracks = (Int_t) treeH->GetEntries();
499 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
500 fPMDLoader->LoadDigits("recreate");
501 TTree* treeD = fPMDLoader->TreeD();
504 fPMDLoader->MakeTree("D");
505 treeD = fPMDLoader->TreeD();
507 Int_t bufsize = 16000;
508 treeD->Branch("PMDDigit", &fDigits, bufsize);
510 TClonesArray* hits = 0;
511 if (fPMD) hits = fPMD->Hits();
513 // Start loop on tracks in the hits containers
515 for (Int_t track=0; track<ntracks;track++)
518 treeH->GetEvent(track);
522 npmd = hits->GetEntriesFast();
523 for (int ipmd = 0; ipmd < npmd; ipmd++)
525 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
526 trackno = fPMDHit->GetTrack();
528 // get kinematics of the particles
530 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
531 trackpid = mparticle->GetPdgCode();
540 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
541 if (mparticle->GetFirstMother() == -1)
543 tracknoOld = trackno;
544 trackpidOld = trackpid;
549 while((imo = mparticle->GetFirstMother()) >= 0)
553 mparticle = gAlice->GetMCApp()->Particle(imo);
554 idmo = mparticle->GetPdgCode();
556 vx = mparticle->Vx();
557 vy = mparticle->Vy();
558 vz = mparticle->Vz();
560 //printf("==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
561 //fprintf(fpw1,"==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, idmo, vx, vy, vz);
562 if ((idmo == kGamma || idmo == -11 || idmo == 11) && vx == 0. && vy == 0. && vz == 0.)
570 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
579 if (idmo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
591 mtrackno = tracknoOld;
592 mtrackpid = trackpidOld;
598 edep = fPMDHit->GetEnergy();
599 Int_t vol1 = fPMDHit->GetVolume(1); // Column
600 Int_t vol2 = fPMDHit->GetVolume(2); // Row
601 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
602 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
605 // -----------------------------------------//
606 // In new geometry after adding electronics //
607 // For Super Module 1 & 2 //
608 // nrow = 48, ncol = 96 //
609 // For Super Module 3 & 4 //
610 // nrow = 96, ncol = 48 //
611 // -----------------------------------------//
613 smnumber = (vol8-1)*6 + vol7;
615 if (vol8 == 1 || vol8 == 2)
620 else if (vol8 == 3 || vol8 == 4)
626 AliDebug(2,Form("ZPosition = %f Edeposition = %d",zPos,edep));
627 //Float_t zposition = TMath::Abs(zPos);
634 else if (zPos > fZPos)
640 Int_t smn = smnumber - 1;
641 Int_t ixx = xpad - 1;
642 Int_t iyy = ypad - 1;
645 fPRE[smn][ixx][iyy] += edep;
646 fPRECounter[smn][ixx][iyy]++;
648 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
654 fCPV[smn][ixx][iyy] += edep;
655 fCPVTrackNo[smn][ixx][iyy] = mtrackno;
659 } // Track Loop ended
661 TrackAssignment2Cell();
669 for (Int_t idet = 0; idet < 2; idet++)
671 for (Int_t ism = 0; ism < fgkTotUM; ism++)
673 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
675 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
679 gain1 = Gain(idet,ism,jrow,kcol);
681 deltaE = fPRE[ism][jrow][kcol]*gain1;
682 trno = fPRETrackNo[ism][jrow][kcol];
687 gain1 = Gain(idet,ism,jrow,kcol);
688 deltaE = fCPV[ism][jrow][kcol]*gain1;
689 trno = fCPVTrackNo[ism][jrow][kcol];
695 AddDigit(trno,detno,ism,jrow,kcol,adc);
701 } // supermodule loop
704 fPMDLoader->WriteDigits("OVERWRITE");
708 //____________________________________________________________________________
711 void AliPMDDigitizer::SDigits2Digits(Int_t ievt)
713 // This reads the PMD sdigits tree and converts energy deposition
714 // in a cell to ADC and stores in the digits tree
717 fRunLoader->GetEvent(ievt);
719 TTree* treeS = fPMDLoader->TreeS();
720 AliPMDsdigit *pmdsdigit;
721 TBranch *branch = treeS->GetBranch("PMDSDigit");
724 AliError("PMD Sdigit branch does not exist");
727 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
728 branch->SetAddress(&fSDigits);
730 TTree* treeD = fPMDLoader->TreeD();
733 fPMDLoader->MakeTree("D");
734 treeD = fPMDLoader->TreeD();
736 Int_t bufsize = 16000;
737 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
738 treeD->Branch("PMDDigit", &fDigits, bufsize);
740 Int_t trno, det, smn;
744 Int_t nmodules = (Int_t) treeS->GetEntries();
745 AliDebug(1,Form("Number of modules = %d",nmodules));
747 for (Int_t imodule = 0; imodule < nmodules; imodule++)
749 treeS->GetEntry(imodule);
750 Int_t nentries = fSDigits->GetLast();
751 AliDebug(2,Form("Number of entries per module = %d",nentries+1));
752 for (Int_t ient = 0; ient < nentries+1; ient++)
754 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
755 trno = pmdsdigit->GetTrackNumber();
756 det = pmdsdigit->GetDetector();
757 smn = pmdsdigit->GetSMNumber();
758 irow = pmdsdigit->GetRow();
759 icol = pmdsdigit->GetColumn();
760 edep = pmdsdigit->GetCellEdep();
763 AddDigit(trno,det,smn,irow,icol,adc);
768 fPMDLoader->WriteDigits("OVERWRITE");
771 //____________________________________________________________________________
772 void AliPMDDigitizer::Exec(Option_t *option)
774 // Does the event merging and digitization
775 const char *cdeb = strstr(option,"deb");
778 AliDebug(100," *** PMD Exec is called ***");
781 Int_t ninputs = fManager->GetNinputs();
782 AliDebug(1,Form("Number of files to be processed = %d",ninputs));
785 for (Int_t i = 0; i < ninputs; i++)
787 Int_t troffset = fManager->GetMask(i);
788 MergeSDigits(i, troffset);
791 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
792 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
793 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
794 if (fPMDLoader == 0x0)
796 AliError("Can not find PMD or PMDLoader");
798 fPMDLoader->LoadDigits("update");
799 TTree* treeD = fPMDLoader->TreeD();
802 fPMDLoader->MakeTree("D");
803 treeD = fPMDLoader->TreeD();
805 Int_t bufsize = 16000;
806 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
807 treeD->Branch("PMDDigit", &fDigits, bufsize);
814 for (Int_t idet = 0; idet < 2; idet++)
816 for (Int_t ism = 0; ism < fgkTotUM; ism++)
818 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
820 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
824 deltaE = fPRE[ism][jrow][kcol];
825 trno = fPRETrackNo[ism][jrow][kcol];
830 deltaE = fCPV[ism][jrow][kcol];
831 trno = fCPVTrackNo[ism][jrow][kcol];
837 AddDigit(trno,detno,ism,jrow,kcol,adc);
843 } // supermodule loop
845 fPMDLoader->WriteDigits("OVERWRITE");
846 fPMDLoader->UnloadDigits();
849 //____________________________________________________________________________
851 void AliPMDDigitizer::MergeSDigits(Int_t filenumber, Int_t troffset)
854 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(filenumber));
855 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
856 fPMDLoader->LoadSDigits("read");
857 TTree* treeS = fPMDLoader->TreeS();
858 AliPMDsdigit *pmdsdigit;
859 TBranch *branch = treeS->GetBranch("PMDSDigit");
860 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
861 branch->SetAddress(&fSDigits);
863 Int_t itrackno, idet, ism;
866 Int_t nmodules = (Int_t) treeS->GetEntries();
867 AliDebug(1,Form("Number of Modules in the treeS = %d",nmodules));
868 AliDebug(1,Form("Track Offset = %d",troffset));
869 for (Int_t imodule = 0; imodule < nmodules; imodule++)
871 treeS->GetEntry(imodule);
872 Int_t nentries = fSDigits->GetLast();
873 AliDebug(2,Form("Number of Entries per Module = %d",nentries));
874 for (Int_t ient = 0; ient < nentries+1; ient++)
876 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
877 itrackno = pmdsdigit->GetTrackNumber();
878 idet = pmdsdigit->GetDetector();
879 ism = pmdsdigit->GetSMNumber();
880 ixp = pmdsdigit->GetRow();
881 iyp = pmdsdigit->GetColumn();
882 edep = pmdsdigit->GetCellEdep();
885 if (fPRE[ism][ixp][iyp] < edep)
887 fPRETrackNo[ism][ixp][iyp] = troffset + itrackno;
889 fPRE[ism][ixp][iyp] += edep;
893 if (fCPV[ism][ixp][iyp] < edep)
895 fCPVTrackNo[ism][ixp][iyp] = troffset + itrackno;
897 fCPV[ism][ixp][iyp] += edep;
903 // ----------------------------------------------------------------------
904 void AliPMDDigitizer::TrackAssignment2Cell()
907 // This block assigns the cell id when there are
908 // multiple tracks in a cell according to the
911 Bool_t jsort = false;
923 pmdTrack = new Int_t ***[fgkTotUM];
924 pmdEdep = new Float_t ***[fgkTotUM];
925 for (i=0; i<fgkTotUM; i++)
927 pmdTrack[i] = new Int_t **[fgkRow];
928 pmdEdep[i] = new Float_t **[fgkRow];
931 for (i = 0; i < fgkTotUM; i++)
933 for (j = 0; j < fgkRow; j++)
935 pmdTrack[i][j] = new Int_t *[fgkCol];
936 pmdEdep[i][j] = new Float_t *[fgkCol];
940 for (i = 0; i < fgkTotUM; i++)
942 for (j = 0; j < fgkRow; j++)
944 for (k = 0; k < fgkCol; k++)
946 Int_t nn = fPRECounter[i][j][k];
949 pmdTrack[i][j][k] = new Int_t[nn];
950 pmdEdep[i][j][k] = new Float_t[nn];
955 pmdTrack[i][j][k] = new Int_t[nn];
956 pmdEdep[i][j][k] = new Float_t[nn];
958 fPRECounter[i][j][k] = 0;
964 Int_t nentries = fCell.GetEntries();
966 Int_t mtrackno, ism, ixp, iyp;
969 for (i = 0; i < nentries; i++)
971 AliPMDcell* cell = (AliPMDcell*)fCell.UncheckedAt(i);
973 mtrackno = cell->GetTrackNumber();
974 ism = cell->GetSMNumber();
977 edep = cell->GetEdep();
978 Int_t nn = fPRECounter[ism][ixp][iyp];
979 pmdTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
980 pmdEdep[ism][ixp][iyp][nn] = edep;
981 fPRECounter[ism][ixp][iyp]++;
988 for (im=0; im<fgkTotUM; im++)
990 for (ix=0; ix<fgkRow; ix++)
992 for (iy=0; iy<fgkCol; iy++)
994 nn = fPRECounter[im][ix][iy];
997 // This block handles if a cell is fired
998 // many times by many tracks
999 status1 = new Int_t[nn];
1000 status2 = new Int_t[nn];
1001 trnarray = new Int_t[nn];
1002 for (iz = 0; iz < nn; iz++)
1004 status1[iz] = pmdTrack[im][ix][iy][iz];
1006 TMath::Sort(nn,status1,status2,jsort);
1007 Int_t trackOld = -99999;
1008 Int_t track, trCount = 0;
1009 for (iz = 0; iz < nn; iz++)
1011 track = status1[status2[iz]];
1012 if (trackOld != track)
1014 trnarray[trCount] = track;
1021 Float_t totEdp = 0.;
1022 trEdp = new Float_t[trCount];
1023 fracEdp = new Float_t[trCount];
1024 for (il = 0; il < trCount; il++)
1027 track = trnarray[il];
1028 for (iz = 0; iz < nn; iz++)
1030 if (track == pmdTrack[im][ix][iy][iz])
1032 trEdp[il] += pmdEdep[im][ix][iy][iz];
1035 totEdp += trEdp[il];
1038 Float_t fracOld = 0.;
1040 for (il = 0; il < trCount; il++)
1042 fracEdp[il] = trEdp[il]/totEdp;
1043 if (fracOld < fracEdp[il])
1045 fracOld = fracEdp[il];
1049 fPRETrackNo[im][ix][iy] = trnarray[ilOld];
1056 // This only handles if a cell is fired
1057 // by only one track
1059 fPRETrackNo[im][ix][iy] = pmdTrack[im][ix][iy][0];
1064 // This is if no cell is fired
1065 fPRETrackNo[im][ix][iy] = -999;
1071 // Delete all the pointers
1073 for (i = 0; i < fgkTotUM; i++)
1075 for (j = 0; j < fgkRow; j++)
1077 for (k = 0; k < fgkCol; k++)
1079 delete [] pmdTrack[i][j][k];
1080 delete [] pmdEdep[i][j][k];
1085 for (i = 0; i < fgkTotUM; i++)
1087 for (j = 0; j < fgkRow; j++)
1089 delete [] pmdTrack[i][j];
1090 delete [] pmdEdep[i][j];
1094 for (i = 0; i < fgkTotUM; i++)
1096 delete [] pmdTrack[i];
1097 delete [] pmdEdep[i];
1102 // End of the cell id assignment
1105 //____________________________________________________________________________
1106 void AliPMDDigitizer::MeV2ADC(Float_t mev, Float_t & adc) const
1108 // This converts the simulated edep to ADC according to the
1113 // PS Test in September 2003
1114 // MeV - ADC conversion for 10bit ADC
1116 const Float_t kConstant = 7.181;
1117 const Float_t kErConstant = 0.6899;
1118 const Float_t kSlope = 35.93;
1119 const Float_t kErSlope = 0.306;
1121 //gRandom->SetSeed();
1123 Float_t cons = gRandom->Gaus(kConstant,kErConstant);
1124 Float_t slop = gRandom->Gaus(kSlope,kErSlope);
1126 Float_t adc10bit = slop*mev*0.001 + cons;
1130 Int_t adc12bit = (Int_t) (4.0*adc10bit);
1134 adc = (Float_t) adc12bit;
1136 else if (adc12bit >= 3000)
1142 //____________________________________________________________________________
1143 void AliPMDDigitizer::AddSDigit(Int_t trnumber, Int_t det, Int_t smnumber,
1144 Int_t irow, Int_t icol, Float_t adc)
1148 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
1149 TClonesArray &lsdigits = *fSDigits;
1150 new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,det,smnumber,irow,icol,adc);
1152 //____________________________________________________________________________
1154 void AliPMDDigitizer::AddDigit(Int_t trnumber, Int_t det, Int_t smnumber,
1155 Int_t irow, Int_t icol, Float_t adc)
1159 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
1160 TClonesArray &ldigits = *fDigits;
1161 new(ldigits[fNdigit++]) AliPMDdigit(trnumber,det,smnumber,irow,icol,adc);
1163 //____________________________________________________________________________
1165 void AliPMDDigitizer::SetZPosition(Float_t zpos)
1169 //____________________________________________________________________________
1170 Float_t AliPMDDigitizer::GetZPosition() const
1174 //____________________________________________________________________________
1176 void AliPMDDigitizer::ResetCell()
1178 // clears the cell array and also the counter
1182 for (Int_t i = 0; i < fgkTotUM; i++)
1184 for (Int_t j = 0; j < fgkRow; j++)
1186 for (Int_t k = 0; k < fgkCol; k++)
1188 fPRECounter[i][j][k] = 0;
1193 //____________________________________________________________________________
1194 void AliPMDDigitizer::ResetSDigit()
1198 if (fSDigits) fSDigits->Delete();
1200 //____________________________________________________________________________
1201 void AliPMDDigitizer::ResetDigit()
1205 if (fDigits) fDigits->Delete();
1207 //____________________________________________________________________________
1209 void AliPMDDigitizer::ResetCellADC()
1211 // Clears individual cells edep and track number
1212 for (Int_t i = 0; i < fgkTotUM; i++)
1214 for (Int_t j = 0; j < fgkRow; j++)
1216 for (Int_t k = 0; k < fgkCol; k++)
1220 fPRETrackNo[i][j][k] = 0;
1221 fCPVTrackNo[i][j][k] = 0;
1226 //------------------------------------------------------
1227 //____________________________________________________________________________
1229 void AliPMDDigitizer::UnLoad(Option_t *option)
1231 // Unloads all the root files
1233 const char *cS = strstr(option,"S");
1234 const char *cD = strstr(option,"D");
1236 fRunLoader->UnloadgAlice();
1237 fRunLoader->UnloadHeader();
1238 fRunLoader->UnloadKinematics();
1242 fPMDLoader->UnloadHits();
1246 fPMDLoader->UnloadHits();
1247 fPMDLoader->UnloadSDigits();
1251 //----------------------------------------------------------------------
1252 Float_t AliPMDDigitizer::Gain(Int_t det, Int_t smn, Int_t row, Int_t col) const
1254 // returns of the gain of the cell
1255 // Added this method by ZA
1257 //cout<<" I am here in gain "<<fCalibData<< "smn,row, col "<<smn
1258 //<<" "<<row<<" "<<col<<endl;
1261 AliError("No calibration data loaded from CDB!!!");
1266 GainFact = fCalibData->GetGainFact(det,smn,row,col);
1267 printf("\t gain=%10.3f\n",GainFact);
1270 //----------------------------------------------------------------------
1271 AliPMDCalibData* AliPMDDigitizer::GetCalibData() const
1273 // The run number will be centralized in AliCDBManager,
1274 // you don't need to set it here!
1275 // Added this method by ZA
1276 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Data");
1279 AliWarning("Calibration object retrieval failed! Dummy calibration will be used.");
1281 // this just remembers the actual default storage. No problem if it is null.
1282 AliCDBStorage *origStorage = AliCDBManager::Instance()->GetDefaultStorage();
1283 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
1285 entry = AliCDBManager::Instance()->Get("PMD/Calib/Data");
1287 // now reset the original default storage to AliCDBManager...
1288 AliCDBManager::Instance()->SetDefaultStorage(origStorage);
1291 AliPMDCalibData *calibdata=0;
1292 if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
1294 if (!calibdata) AliError("No calibration data from calibration database !");