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 "AliPMDPedestal.h"
58 #include "AliPMDDigitizer.h"
61 ClassImp(AliPMDDigitizer)
63 AliPMDDigitizer::AliPMDDigitizer() :
68 fCalibGain(GetCalibGain()),
69 fCalibPed(GetCalibPed()),
77 fZPos(361.5) // in units of cm, default position of PMD
79 // Default Constructor
81 for (Int_t i = 0; i < fgkTotUM; i++)
83 for (Int_t j = 0; j < fgkRow; j++)
85 for (Int_t k = 0; k < fgkCol; k++)
89 fCPVCounter[i][j][k] = 0;
90 fPRECounter[i][j][k] = 0;
91 fCPVTrackNo[i][j][k] = -1;
92 fPRETrackNo[i][j][k] = -1;
93 fCPVTrackPid[i][j][k] = -1;
94 fPRETrackPid[i][j][k] = -1;
100 //____________________________________________________________________________
101 AliPMDDigitizer::AliPMDDigitizer(const AliPMDDigitizer& digitizer):
102 AliDigitizer(digitizer),
107 fCalibGain(GetCalibGain()),
108 fCalibPed(GetCalibPed()),
116 fZPos(361.5) // in units of cm, default position of PMD
119 AliError("Copy constructor not allowed ");
122 //____________________________________________________________________________
123 AliPMDDigitizer & AliPMDDigitizer::operator=(const AliPMDDigitizer& /*digitizer*/)
125 // Assignment operator
126 AliError("Assignement operator not allowed ");
130 //____________________________________________________________________________
131 AliPMDDigitizer::AliPMDDigitizer(AliRunDigitizer* manager):
132 AliDigitizer(manager),
137 fCalibGain(GetCalibGain()),
138 fCalibPed(GetCalibPed()),
139 fSDigits(new TClonesArray("AliPMDsdigit", 1000)),
140 fDigits(new TClonesArray("AliPMDdigit", 1000)),
146 fZPos(361.5)// in units of cm, This is the default position of PMD
148 // ctor which should be used
151 for (Int_t i = 0; i < fgkTotUM; i++)
153 for (Int_t j = 0; j < fgkRow; j++)
155 for (Int_t k = 0; k < fgkCol; k++)
159 fCPVCounter[i][j][k] = 0;
160 fPRECounter[i][j][k] = 0;
161 fCPVTrackNo[i][j][k] = -1;
162 fPRETrackNo[i][j][k] = -1;
163 fCPVTrackPid[i][j][k] = -1;
164 fPRETrackPid[i][j][k] = -1;
170 //____________________________________________________________________________
171 AliPMDDigitizer::~AliPMDDigitizer()
173 // Default Destructor
191 //____________________________________________________________________________
192 void AliPMDDigitizer::OpengAliceFile(const char *file, Option_t *option)
194 // Loads galice.root file and corresponding header, kinematics
195 // hits and sdigits or digits depending on the option
198 TString evfoldname = AliConfig::GetDefaultEventFolderName();
199 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
201 fRunLoader = AliRunLoader::Open(file,AliConfig::GetDefaultEventFolderName(), "UPDATE");
205 AliError(Form("Can not open session for file %s.",file));
208 const char *cHS = strstr(option,"HS");
209 const char *cHD = strstr(option,"HD");
210 const char *cSD = strstr(option,"SD");
214 if (!fRunLoader->GetAliRun()) fRunLoader->LoadgAlice();
215 if (!fRunLoader->TreeE()) fRunLoader->LoadHeader();
216 if (!fRunLoader->TreeK()) fRunLoader->LoadKinematics();
218 gAlice = fRunLoader->GetAliRun();
222 AliDebug(1,"Alirun object found");
226 AliError("Could not found Alirun object");
229 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
232 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
233 if (fPMDLoader == 0x0)
235 AliError("Can not find PMDLoader");
241 fPMDLoader->LoadHits("READ");
242 fPMDLoader->LoadSDigits("recreate");
246 fPMDLoader->LoadHits("READ");
247 fPMDLoader->LoadDigits("recreate");
251 fPMDLoader->LoadSDigits("READ");
252 fPMDLoader->LoadDigits("recreate");
255 //____________________________________________________________________________
256 void AliPMDDigitizer::Hits2SDigits(Int_t ievt)
258 // This reads the PMD Hits tree and assigns the right track number
259 // to a cell and stores in the summable digits tree
262 const Int_t kPi0 = 111;
263 const Int_t kGamma = 22;
271 Float_t xPos, yPos, zPos;
272 Int_t xpad = -1, ypad = -1;
274 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
277 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
280 AliDebug(1,Form("Event Number = %d",ievt));
281 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
282 AliDebug(1,Form("Number of Particles = %d",nparticles));
284 // Ajay on 24th May 2009
286 Int_t nprimary = fRunLoader->GetHeader()->GetNprimary();
287 Int_t * mtraPid = new Int_t [nprimary];
288 for(Int_t i = 0; i < nprimary; i++)
294 fRunLoader->GetEvent(ievt);
295 // ------------------------------------------------------- //
296 // Pointer to specific detector hits.
297 // Get pointers to Alice detectors and Hits containers
299 TTree* treeH = fPMDLoader->TreeH();
301 Int_t ntracks = (Int_t) treeH->GetEntries();
302 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
303 TTree* treeS = fPMDLoader->TreeS();
306 fPMDLoader->MakeTree("S");
307 treeS = fPMDLoader->TreeS();
309 Int_t bufsize = 16000;
310 treeS->Branch("PMDSDigit", &fSDigits, bufsize);
312 TClonesArray* hits = 0;
313 if (fPMD) hits = fPMD->Hits();
315 // Start loop on tracks in the hits containers
317 for (Int_t track=0; track<ntracks;track++)
319 gAlice->GetMCApp()->ResetHits();
320 treeH->GetEvent(track);
323 npmd = hits->GetEntriesFast();
324 for (Int_t ipmd = 0; ipmd < npmd; ipmd++)
326 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
327 trackno = fPMDHit->GetTrack();
328 // get kinematics of the particles
330 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
331 trackpid = mparticle->GetPdgCode();
332 Int_t ks = mparticle->GetStatusCode();
334 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
336 if (mparticle->GetFirstMother() == -1)
338 tracknoOld = trackno;
339 trackpidOld = trackpid;
343 //------------------modified by Mriganka ----------------------
344 if(ks==1||(imo = mparticle->GetFirstMother())<0 ){
345 vx = mparticle->Vx();
346 vy = mparticle->Vy();
347 vz = mparticle->Vz();
349 if(trackpid==kGamma||trackpid==11||trackpid==-11||
350 trackpid==kPi0)igstatus=1;
354 while(((imo = mparticle->GetFirstMother()) >= 0)&&
355 (ks = mparticle->GetStatusCode() <1) )
357 mparticle = gAlice->GetMCApp()->Particle(imo);
358 trackpid = mparticle->GetPdgCode();
359 ks = mparticle->GetStatusCode();
360 vx = mparticle->Vx();
361 vy = mparticle->Vy();
362 vz = mparticle->Vz();
368 if(trackpid==kGamma||trackpid==11||trackpid==-11||
369 trackpid==kPi0)igstatus=1;
372 trackpid=trackpidOld;
375 mtraPid[trackno] = mtrackpid;
377 //-----------------end of modification----------------
382 edep = fPMDHit->GetEnergy();
383 Int_t vol1 = fPMDHit->GetVolume(1); // Column
384 Int_t vol2 = fPMDHit->GetVolume(2); // Row
385 Int_t vol7 = fPMDHit->GetVolume(4); // Serial Module No
388 // -----------------------------------------//
389 // In new geometry after adding electronics //
390 // For Super Module 1 & 2 //
391 // nrow = 48, ncol = 96 //
392 // For Super Module 3 & 4 //
393 // nrow = 96, ncol = 48 //
394 // -----------------------------------------//
402 smnumber = vol7 - 24;
404 Int_t vol8 = smnumber/6 + 1; // fake supermodule
406 if (vol8 == 1 || vol8 == 2)
411 else if (vol8 == 3 || vol8 == 4)
417 AliDebug(2,Form("Zposition = %f Edeposition = %f",zPos,edep));
418 //Float_t zposition = TMath::Abs(zPos);
424 else if (zPos > fZPos)
429 //Int_t smn = smnumber - 1;
430 Int_t smn = smnumber;
431 Int_t ixx = xpad - 1;
432 Int_t iyy = ypad - 1;
435 fPRE[smn][ixx][iyy] += edep;
436 fPRECounter[smn][ixx][iyy]++;
438 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
443 fCPV[smn][ixx][iyy] += edep;
444 fCPVCounter[smn][ixx][iyy]++;
445 AliPMDcell* cpvcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
446 fCPVCell.Add(cpvcell);
450 } // Track Loop ended
451 TrackAssignment2CPVCell();
452 TrackAssignment2Cell();
460 for (Int_t idet = 0; idet < 2; idet++)
462 for (Int_t ism = 0; ism < fgkTotUM; ism++)
464 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
466 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
470 deltaE = fPRE[ism][jrow][kcol];
471 trno = fPRETrackNo[ism][jrow][kcol];
472 trpid = mtraPid[trno]; // added
477 deltaE = fCPV[ism][jrow][kcol];
478 trno = fCPVTrackNo[ism][jrow][kcol];
479 trpid = mtraPid[trno]; // added
484 AddSDigit(trno,trpid,detno,ism,jrow,kcol,deltaE);
492 fPMDLoader->WriteSDigits("OVERWRITE");
496 //____________________________________________________________________________
498 void AliPMDDigitizer::Hits2Digits(Int_t ievt)
500 // This reads the PMD Hits tree and assigns the right track number
501 // to a cell and stores in the digits tree
503 const Int_t kPi0 = 111;
504 const Int_t kGamma = 22;
512 Float_t xPos, yPos, zPos;
513 Int_t xpad = -1, ypad = -1;
515 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
517 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
520 AliDebug(1,Form("Event Number = %d",ievt));
521 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
522 AliDebug(1,Form("Number of Particles = %d", nparticles));
525 // Ajay on 24th May 2009
527 Int_t nprimary = fRunLoader->GetHeader()->GetNprimary();
528 Int_t * mtraPid = new Int_t [nprimary];
529 for(Int_t i = 0; i < nprimary; i++)
535 fRunLoader->GetEvent(ievt);
536 // ------------------------------------------------------- //
537 // Pointer to specific detector hits.
538 // Get pointers to Alice detectors and Hits containers
540 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
541 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
543 if (fPMDLoader == 0x0)
545 AliError("Can not find PMD or PMDLoader");
547 TTree* treeH = fPMDLoader->TreeH();
548 Int_t ntracks = (Int_t) treeH->GetEntries();
549 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
550 fPMDLoader->LoadDigits("recreate");
551 TTree* treeD = fPMDLoader->TreeD();
554 fPMDLoader->MakeTree("D");
555 treeD = fPMDLoader->TreeD();
557 Int_t bufsize = 16000;
558 treeD->Branch("PMDDigit", &fDigits, bufsize);
560 TClonesArray* hits = 0;
561 if (fPMD) hits = fPMD->Hits();
563 // Start loop on tracks in the hits containers
565 for (Int_t track=0; track<ntracks;track++)
567 gAlice->GetMCApp()->ResetHits();
568 treeH->GetEvent(track);
572 npmd = hits->GetEntriesFast();
573 for (Int_t ipmd = 0; ipmd < npmd; ipmd++)
575 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
576 trackno = fPMDHit->GetTrack();
578 // get kinematics of the particles
580 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
581 trackpid = mparticle->GetPdgCode();
582 Int_t ks = mparticle->GetStatusCode();
584 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
585 if (mparticle->GetFirstMother() == -1)
587 tracknoOld = trackno;
588 trackpidOld = trackpid;
593 //-----------------------modified by Mriganka ------------------
594 if(ks==1||(imo = mparticle->GetFirstMother())<0 ){
595 vx = mparticle->Vx();
596 vy = mparticle->Vy();
597 vz = mparticle->Vz();
599 if(trackpid==kGamma||trackpid==11||trackpid==-11||trackpid==kPi0)
604 while(((imo = mparticle->GetFirstMother()) >= 0)&&
605 (ks = mparticle->GetStatusCode() <1) )
607 mparticle = gAlice->GetMCApp()->Particle(imo);
608 trackpid = mparticle->GetPdgCode();
609 ks = mparticle->GetStatusCode();
610 vx = mparticle->Vx();
611 vy = mparticle->Vy();
612 vz = mparticle->Vz();
618 if(trackpid==kGamma||trackpid==11||trackpid==-11||trackpid==kPi0)
622 trackpid=trackpidOld;
625 mtraPid[mtrackno] = mtrackpid; // added by Ajay
627 //-----------------end of modification----------------
631 edep = fPMDHit->GetEnergy();
632 Int_t vol1 = fPMDHit->GetVolume(1); // Column
633 Int_t vol2 = fPMDHit->GetVolume(2); // Row
634 Int_t vol7 = fPMDHit->GetVolume(4); // Serial Module No
636 // -----------------------------------------//
637 // In new geometry after adding electronics //
638 // For Super Module 1 & 2 //
639 // nrow = 48, ncol = 96 //
640 // For Super Module 3 & 4 //
641 // nrow = 96, ncol = 48 //
642 // -----------------------------------------//
650 smnumber = vol7 - 24;
652 Int_t vol8 = smnumber/6 + 1; // fake supermodule
654 if (vol8 == 1 || vol8 == 2)
659 else if (vol8 == 3 || vol8 == 4)
665 AliDebug(2,Form("ZPosition = %f Edeposition = %d",zPos,edep));
666 //Float_t zposition = TMath::Abs(zPos);
673 else if (zPos > fZPos)
679 //Int_t smn = smnumber - 1;
680 Int_t smn = smnumber;
681 Int_t ixx = xpad - 1;
682 Int_t iyy = ypad - 1;
685 fPRE[smn][ixx][iyy] += edep;
686 fPRECounter[smn][ixx][iyy]++;
688 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
694 fCPV[smn][ixx][iyy] += edep;
695 fCPVCounter[smn][ixx][iyy]++;
696 AliPMDcell* cpvcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
697 fCPVCell.Add(cpvcell);
701 } // Track Loop ended
702 TrackAssignment2CPVCell();
703 TrackAssignment2Cell();
713 for (Int_t idet = 0; idet < 2; idet++)
715 for (Int_t ism = 0; ism < fgkTotUM; ism++)
717 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
719 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
723 deltaE = fPRE[ism][jrow][kcol];
724 trno = fPRETrackNo[ism][jrow][kcol];
725 trpid = mtraPid[trno]; // added
730 deltaE = fCPV[ism][jrow][kcol];
731 trno = fCPVTrackNo[ism][jrow][kcol];
732 trpid = mtraPid[trno]; // added
739 // To decalibrate the adc values
741 gain1 = Gain(idet,ism,jrow,kcol);
744 Int_t adcDecalib = (Int_t)(adc/gain1);
745 adc = (Float_t) adcDecalib;
752 // Pedestal Decalibration
754 fCalibPed->GetPedMeanRms(idet,ism,jrow,kcol);
755 Int_t pedrms1 = (Int_t) pedmeanrms%100;
756 Float_t pedrms = (Float_t)pedrms1/10.;
758 (Float_t) (pedmeanrms - pedrms1)/1000.0;
761 adc += (pedmean + 3.0*pedrms);
762 AddDigit(trno,trpid,detno,ism,jrow,kcol,adc);
769 } // supermodule loop
772 fPMDLoader->WriteDigits("OVERWRITE");
777 //____________________________________________________________________________
780 void AliPMDDigitizer::SDigits2Digits(Int_t ievt)
782 // This reads the PMD sdigits tree and converts energy deposition
783 // in a cell to ADC and stores in the digits tree
786 fRunLoader->GetEvent(ievt);
788 TTree* treeS = fPMDLoader->TreeS();
789 AliPMDsdigit *pmdsdigit;
790 TBranch *branch = treeS->GetBranch("PMDSDigit");
793 AliError("PMD Sdigit branch does not exist");
796 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
797 branch->SetAddress(&fSDigits);
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);
809 Int_t trno, trpid, det, smn;
813 Int_t nmodules = (Int_t) treeS->GetEntries();
814 AliDebug(1,Form("Number of modules = %d",nmodules));
816 for (Int_t imodule = 0; imodule < nmodules; imodule++)
818 treeS->GetEntry(imodule);
819 Int_t nentries = fSDigits->GetLast();
820 AliDebug(2,Form("Number of entries per module = %d",nentries+1));
821 for (Int_t ient = 0; ient < nentries+1; ient++)
823 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
824 trno = pmdsdigit->GetTrackNumber();
825 trpid = pmdsdigit->GetTrackPid();
826 det = pmdsdigit->GetDetector();
827 smn = pmdsdigit->GetSMNumber();
828 irow = pmdsdigit->GetRow();
829 icol = pmdsdigit->GetColumn();
830 edep = pmdsdigit->GetCellEdep();
834 // To decalibrte the adc values
836 Float_t gain1 = Gain(det,smn,irow,icol);
839 Int_t adcDecalib = (Int_t)(adc/gain1);
840 adc = (Float_t) adcDecalib;
846 // Pedestal Decalibration
847 Int_t pedmeanrms = fCalibPed->GetPedMeanRms(det,smn,irow,icol);
848 Int_t pedrms1 = (Int_t) pedmeanrms%100;
849 Float_t pedrms = (Float_t)pedrms1/10.;
850 Float_t pedmean = (Float_t) (pedmeanrms - pedrms1)/1000.0;
853 adc += (pedmean + 3.0*pedrms);
854 AddDigit(trno,trpid,det,smn,irow,icol,adc);
861 fPMDLoader->WriteDigits("OVERWRITE");
864 //____________________________________________________________________________
865 void AliPMDDigitizer::Exec(Option_t *option)
867 // Does the event merging and digitization
868 const char *cdeb = strstr(option,"deb");
871 AliDebug(100," *** PMD Exec is called ***");
874 Int_t ninputs = fManager->GetNinputs();
875 AliDebug(1,Form("Number of files to be processed = %d",ninputs));
878 for (Int_t i = 0; i < ninputs; i++)
880 Int_t troffset = fManager->GetMask(i);
881 MergeSDigits(i, troffset);
884 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
885 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
886 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
887 if (fPMDLoader == 0x0)
889 AliError("Can not find PMD or PMDLoader");
891 fPMDLoader->LoadDigits("update");
892 TTree* treeD = fPMDLoader->TreeD();
895 fPMDLoader->MakeTree("D");
896 treeD = fPMDLoader->TreeD();
898 Int_t bufsize = 16000;
899 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
900 treeD->Branch("PMDDigit", &fDigits, bufsize);
908 for (Int_t idet = 0; idet < 2; idet++)
910 for (Int_t ism = 0; ism < fgkTotUM; ism++)
912 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
914 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
918 deltaE = fPRE[ism][jrow][kcol];
919 trno = fPRETrackNo[ism][jrow][kcol];
920 trpid = fPRETrackPid[ism][jrow][kcol];
925 deltaE = fCPV[ism][jrow][kcol];
926 trno = fCPVTrackNo[ism][jrow][kcol];
927 trpid = fCPVTrackPid[ism][jrow][kcol];
935 // Gain decalibration
937 Float_t gain1 = Gain(idet,ism,jrow,kcol);
941 Int_t adcDecalib = (Int_t)(adc/gain1);
942 adc = (Float_t) adcDecalib;
948 // Pedestal Decalibration
950 fCalibPed->GetPedMeanRms(idet,ism,jrow,kcol);
951 Int_t pedrms1 = (Int_t) pedmeanrms%100;
952 Float_t pedrms = (Float_t)pedrms1/10.;
954 (Float_t) (pedmeanrms - pedrms1)/1000.0;
957 adc += (pedmean + 3.0*pedrms);
958 AddDigit(trno,trpid,detno,ism,jrow,kcol,adc);
966 } // supermodule loop
968 fPMDLoader->WriteDigits("OVERWRITE");
969 fPMDLoader->UnloadDigits();
972 //____________________________________________________________________________
973 void AliPMDDigitizer::TrackAssignment2CPVCell()
975 // This block assigns the cell id when there are
976 // multiple tracks in a cell according to the
978 // This method added by Ajay
979 Bool_t jsort = false;
992 cpvTrack = new Int_t ***[fgkTotUM];
993 cpvEdep = new Float_t ***[fgkTotUM];
994 for (i=0; i<fgkTotUM; i++)
996 cpvTrack[i] = new Int_t **[fgkRow];
997 cpvEdep[i] = new Float_t **[fgkRow];
1000 for (i = 0; i < fgkTotUM; i++)
1002 for (j = 0; j < fgkRow; j++)
1004 cpvTrack[i][j] = new Int_t *[fgkCol];
1005 cpvEdep[i][j] = new Float_t *[fgkCol];
1008 for (i = 0; i < fgkTotUM; i++)
1010 for (j = 0; j < fgkRow; j++)
1012 for (k = 0; k < fgkCol; k++)
1014 Int_t nn = fCPVCounter[i][j][k];
1017 cpvTrack[i][j][k] = new Int_t[nn];
1018 cpvEdep[i][j][k] = new Float_t[nn];
1023 cpvTrack[i][j][k] = new Int_t[nn];
1024 cpvEdep[i][j][k] = new Float_t[nn];
1026 fCPVCounter[i][j][k] = 0;
1032 Int_t nentries = fCPVCell.GetEntries();
1034 Int_t mtrackno, ism, ixp, iyp;
1036 for (i = 0; i < nentries; i++)
1038 AliPMDcell* cpvcell = (AliPMDcell*)fCPVCell.UncheckedAt(i);
1040 mtrackno = cpvcell->GetTrackNumber();
1041 ism = cpvcell->GetSMNumber();
1042 ixp = cpvcell->GetX();
1043 iyp = cpvcell->GetY();
1044 edep = cpvcell->GetEdep();
1045 Int_t nn = fCPVCounter[ism][ixp][iyp];
1046 cpvTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
1047 cpvEdep[ism][ixp][iyp][nn] = edep;
1048 fCPVCounter[ism][ixp][iyp]++;
1054 for (im=0; im<fgkTotUM; im++)
1056 for (ix=0; ix<fgkRow; ix++)
1058 for (iy=0; iy<fgkCol; iy++)
1060 nn = fCPVCounter[im][ix][iy];
1063 // This block handles if a cell is fired
1064 // many times by many tracks
1065 status1 = new Int_t[nn];
1066 status2 = new Int_t[nn];
1067 trnarray = new Int_t[nn];
1068 for (iz = 0; iz < nn; iz++)
1070 status1[iz] = cpvTrack[im][ix][iy][iz];
1072 TMath::Sort(nn,status1,status2,jsort);
1073 Int_t trackOld = -99999;
1074 Int_t track, trCount = 0;
1075 for (iz = 0; iz < nn; iz++)
1077 track = status1[status2[iz]];
1078 if (trackOld != track)
1080 trnarray[trCount] = track;
1087 Float_t totEdp = 0.;
1088 trEdp = new Float_t[trCount];
1089 fracEdp = new Float_t[trCount];
1090 for (il = 0; il < trCount; il++)
1093 track = trnarray[il];
1094 for (iz = 0; iz < nn; iz++)
1096 if (track == cpvTrack[im][ix][iy][iz])
1098 trEdp[il] += cpvEdep[im][ix][iy][iz];
1101 totEdp += trEdp[il];
1104 Float_t fracOld = 0.;
1106 for (il = 0; il < trCount; il++)
1108 fracEdp[il] = trEdp[il]/totEdp;
1109 if (fracOld < fracEdp[il])
1111 fracOld = fracEdp[il];
1115 fCPVTrackNo[im][ix][iy] = trnarray[ilOld];
1122 // This only handles if a cell is fired
1123 // by only one track
1125 fCPVTrackNo[im][ix][iy] = cpvTrack[im][ix][iy][0];
1130 // This is if no cell is fired
1131 fCPVTrackNo[im][ix][iy] = -999;
1137 // Delete all the pointers
1139 for (i = 0; i < fgkTotUM; i++)
1141 for (j = 0; j < fgkRow; j++)
1143 for (k = 0; k < fgkCol; k++)
1145 delete []cpvTrack[i][j][k];
1146 delete []cpvEdep[i][j][k];
1151 for (i = 0; i < fgkTotUM; i++)
1153 for (j = 0; j < fgkRow; j++)
1155 delete [] cpvTrack[i][j];
1156 delete [] cpvEdep[i][j];
1160 for (i = 0; i < fgkTotUM; i++)
1162 delete [] cpvTrack[i];
1163 delete [] cpvEdep[i];
1169 // End of the cell id assignment
1172 //____________________________________________________________________________
1174 void AliPMDDigitizer::MergeSDigits(Int_t filenumber, Int_t troffset)
1177 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(filenumber));
1178 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
1179 fPMDLoader->LoadSDigits("read");
1180 TTree* treeS = fPMDLoader->TreeS();
1181 AliPMDsdigit *pmdsdigit;
1182 TBranch *branch = treeS->GetBranch("PMDSDigit");
1183 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
1184 branch->SetAddress(&fSDigits);
1186 Int_t itrackno, itrackpid, idet, ism;
1189 Int_t nmodules = (Int_t) treeS->GetEntries();
1190 AliDebug(1,Form("Number of Modules in the treeS = %d",nmodules));
1191 AliDebug(1,Form("Track Offset = %d",troffset));
1192 for (Int_t imodule = 0; imodule < nmodules; imodule++)
1194 treeS->GetEntry(imodule);
1195 Int_t nentries = fSDigits->GetLast();
1196 AliDebug(2,Form("Number of Entries per Module = %d",nentries));
1197 for (Int_t ient = 0; ient < nentries+1; ient++)
1199 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
1200 itrackno = pmdsdigit->GetTrackNumber();
1201 itrackpid = pmdsdigit->GetTrackPid();
1202 idet = pmdsdigit->GetDetector();
1203 ism = pmdsdigit->GetSMNumber();
1204 ixp = pmdsdigit->GetRow();
1205 iyp = pmdsdigit->GetColumn();
1206 edep = pmdsdigit->GetCellEdep();
1209 if (fPRE[ism][ixp][iyp] < edep)
1211 fPRETrackNo[ism][ixp][iyp] = troffset + itrackno;
1212 fPRETrackPid[ism][ixp][iyp] = itrackpid;
1214 fPRE[ism][ixp][iyp] += edep;
1218 if (fCPV[ism][ixp][iyp] < edep)
1220 fCPVTrackNo[ism][ixp][iyp] = troffset + itrackno;
1221 fCPVTrackPid[ism][ixp][iyp] = itrackpid;
1223 fCPV[ism][ixp][iyp] += edep;
1229 // ----------------------------------------------------------------------
1230 void AliPMDDigitizer::TrackAssignment2Cell()
1233 // This block assigns the cell id when there are
1234 // multiple tracks in a cell according to the
1235 // energy deposition
1237 Bool_t jsort = false;
1248 Float_t ****pmdEdep;
1250 pmdTrack = new Int_t ***[fgkTotUM];
1251 pmdEdep = new Float_t ***[fgkTotUM];
1252 for (i=0; i<fgkTotUM; i++)
1254 pmdTrack[i] = new Int_t **[fgkRow];
1255 pmdEdep[i] = new Float_t **[fgkRow];
1258 for (i = 0; i < fgkTotUM; i++)
1260 for (j = 0; j < fgkRow; j++)
1262 pmdTrack[i][j] = new Int_t *[fgkCol];
1263 pmdEdep[i][j] = new Float_t *[fgkCol];
1267 for (i = 0; i < fgkTotUM; i++)
1269 for (j = 0; j < fgkRow; j++)
1271 for (k = 0; k < fgkCol; k++)
1273 Int_t nn = fPRECounter[i][j][k];
1276 pmdTrack[i][j][k] = new Int_t[nn];
1277 pmdEdep[i][j][k] = new Float_t[nn];
1282 pmdTrack[i][j][k] = new Int_t[nn];
1283 pmdEdep[i][j][k] = new Float_t[nn];
1285 fPRECounter[i][j][k] = 0;
1291 Int_t nentries = fCell.GetEntries();
1293 Int_t mtrackno, ism, ixp, iyp;
1296 for (i = 0; i < nentries; i++)
1298 AliPMDcell* cell = (AliPMDcell*)fCell.UncheckedAt(i);
1300 mtrackno = cell->GetTrackNumber();
1301 ism = cell->GetSMNumber();
1304 edep = cell->GetEdep();
1305 Int_t nn = fPRECounter[ism][ixp][iyp];
1306 pmdTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
1307 pmdEdep[ism][ixp][iyp][nn] = edep;
1308 fPRECounter[ism][ixp][iyp]++;
1315 for (im=0; im<fgkTotUM; im++)
1317 for (ix=0; ix<fgkRow; ix++)
1319 for (iy=0; iy<fgkCol; iy++)
1321 nn = fPRECounter[im][ix][iy];
1324 // This block handles if a cell is fired
1325 // many times by many tracks
1326 status1 = new Int_t[nn];
1327 status2 = new Int_t[nn];
1328 trnarray = new Int_t[nn];
1329 for (iz = 0; iz < nn; iz++)
1331 status1[iz] = pmdTrack[im][ix][iy][iz];
1333 TMath::Sort(nn,status1,status2,jsort);
1334 Int_t trackOld = -99999;
1335 Int_t track, trCount = 0;
1336 for (iz = 0; iz < nn; iz++)
1338 track = status1[status2[iz]];
1339 if (trackOld != track)
1341 trnarray[trCount] = track;
1348 Float_t totEdp = 0.;
1349 trEdp = new Float_t[trCount];
1350 fracEdp = new Float_t[trCount];
1351 for (il = 0; il < trCount; il++)
1354 track = trnarray[il];
1355 for (iz = 0; iz < nn; iz++)
1357 if (track == pmdTrack[im][ix][iy][iz])
1359 trEdp[il] += pmdEdep[im][ix][iy][iz];
1362 totEdp += trEdp[il];
1365 Float_t fracOld = 0.;
1367 for (il = 0; il < trCount; il++)
1369 fracEdp[il] = trEdp[il]/totEdp;
1370 if (fracOld < fracEdp[il])
1372 fracOld = fracEdp[il];
1376 fPRETrackNo[im][ix][iy] = trnarray[ilOld];
1383 // This only handles if a cell is fired
1384 // by only one track
1386 fPRETrackNo[im][ix][iy] = pmdTrack[im][ix][iy][0];
1391 // This is if no cell is fired
1392 fPRETrackNo[im][ix][iy] = -999;
1398 // Delete all the pointers
1400 for (i = 0; i < fgkTotUM; i++)
1402 for (j = 0; j < fgkRow; j++)
1404 for (k = 0; k < fgkCol; k++)
1406 delete [] pmdTrack[i][j][k];
1407 delete [] pmdEdep[i][j][k];
1412 for (i = 0; i < fgkTotUM; i++)
1414 for (j = 0; j < fgkRow; j++)
1416 delete [] pmdTrack[i][j];
1417 delete [] pmdEdep[i][j];
1421 for (i = 0; i < fgkTotUM; i++)
1423 delete [] pmdTrack[i];
1424 delete [] pmdEdep[i];
1429 // End of the cell id assignment
1432 //____________________________________________________________________________
1433 void AliPMDDigitizer::MeV2ADC(Float_t mev, Float_t & adc) const
1435 // This converts the simulated edep to ADC according to the
1437 //PS Test in September 2003 and 2006
1438 // KeV - ADC conversion for 12bit ADC
1441 const Float_t kConstant = 0.07;
1442 const Float_t kErConstant = 0.1;
1443 const Float_t kSlope = 76.0;
1444 const Float_t kErSlope = 5.0;
1446 Float_t cons = gRandom->Gaus(kConstant,kErConstant);
1447 Float_t slop = gRandom->Gaus(kSlope,kErSlope);
1449 Float_t adc12bit = slop*mev*0.001 + cons;
1452 if(adc12bit < 1600.0)
1454 adc = (Float_t) adc12bit;
1456 else if (adc12bit >= 1600.0)
1461 //____________________________________________________________________________
1462 void AliPMDDigitizer::AddSDigit(Int_t trnumber, Int_t trpid, Int_t det,
1463 Int_t smnumber, Int_t irow, Int_t icol,
1468 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
1469 TClonesArray &lsdigits = *fSDigits;
1470 new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,trpid,det,smnumber,irow,icol,adc);
1472 //____________________________________________________________________________
1474 void AliPMDDigitizer::AddDigit(Int_t trnumber, Int_t trpid, Int_t det,
1475 Int_t smnumber, Int_t irow, Int_t icol,
1480 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
1481 TClonesArray &ldigits = *fDigits;
1482 new(ldigits[fNdigit++]) AliPMDdigit(trnumber,trpid, det,smnumber,irow,icol,adc);
1484 //____________________________________________________________________________
1486 void AliPMDDigitizer::SetZPosition(Float_t zpos)
1490 //____________________________________________________________________________
1491 Float_t AliPMDDigitizer::GetZPosition() const
1495 //____________________________________________________________________________
1497 void AliPMDDigitizer::ResetCell()
1499 // clears the cell array and also the counter
1504 for (Int_t i = 0; i < fgkTotUM; i++)
1506 for (Int_t j = 0; j < fgkRow; j++)
1508 for (Int_t k = 0; k < fgkCol; k++)
1510 fCPVCounter[i][j][k] = 0;
1511 fPRECounter[i][j][k] = 0;
1516 //____________________________________________________________________________
1517 void AliPMDDigitizer::ResetSDigit()
1521 if (fSDigits) fSDigits->Delete();
1523 //____________________________________________________________________________
1524 void AliPMDDigitizer::ResetDigit()
1528 if (fDigits) fDigits->Delete();
1530 //____________________________________________________________________________
1532 void AliPMDDigitizer::ResetCellADC()
1534 // Clears individual cells edep and track number
1535 for (Int_t i = 0; i < fgkTotUM; i++)
1537 for (Int_t j = 0; j < fgkRow; j++)
1539 for (Int_t k = 0; k < fgkCol; k++)
1543 fCPVTrackNo[i][j][k] = 0;
1544 fPRETrackNo[i][j][k] = 0;
1545 fCPVTrackPid[i][j][k] = -1;
1546 fPRETrackPid[i][j][k] = -1;
1551 //____________________________________________________________________________
1553 void AliPMDDigitizer::UnLoad(Option_t *option)
1555 // Unloads all the root files
1557 const char *cS = strstr(option,"S");
1558 const char *cD = strstr(option,"D");
1560 fRunLoader->UnloadgAlice();
1561 fRunLoader->UnloadHeader();
1562 fRunLoader->UnloadKinematics();
1566 fPMDLoader->UnloadHits();
1570 fPMDLoader->UnloadHits();
1571 fPMDLoader->UnloadSDigits();
1575 //----------------------------------------------------------------------
1576 Float_t AliPMDDigitizer::Gain(Int_t det, Int_t smn, Int_t row, Int_t col) const
1578 // returns of the gain of the cell
1579 // Added this method by ZA
1581 //cout<<" I am here in gain "<<fCalibData<< "smn,row, col "<<smn
1582 //<<" "<<row<<" "<<col<<endl;
1585 AliError("No calibration data loaded from CDB!!!");
1590 GainFact = fCalibGain->GetGainFact(det,smn,row,col);
1593 //----------------------------------------------------------------------
1594 AliPMDCalibData* AliPMDDigitizer::GetCalibGain() const
1596 // The run number will be centralized in AliCDBManager,
1597 // you don't need to set it here!
1598 // Added this method by ZA
1599 // Cleaned up by Alberto
1600 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Gain");
1602 if(!entry) AliFatal("Calibration object retrieval failed!");
1604 AliPMDCalibData *calibdata=0;
1605 if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
1607 if (!calibdata) AliFatal("No calibration data from calibration database !");
1611 //----------------------------------------------------------------------
1612 AliPMDPedestal* AliPMDDigitizer::GetCalibPed() const
1614 // The run number will be centralized in AliCDBManager,
1615 // you don't need to set it here!
1617 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Ped");
1619 if(!entry) AliFatal("Pedestal object retrieval failed!");
1621 AliPMDPedestal *pedestal=0;
1622 if (entry) pedestal = (AliPMDPedestal*) entry->GetObject();
1624 if (!pedestal) AliFatal("No pedestal data from calibration database !");