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));
286 fRunLoader->GetEvent(ievt);
287 // ------------------------------------------------------- //
288 // Pointer to specific detector hits.
289 // Get pointers to Alice detectors and Hits containers
291 TTree* treeH = fPMDLoader->TreeH();
293 Int_t ntracks = (Int_t) treeH->GetEntries();
294 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
295 TTree* treeS = fPMDLoader->TreeS();
298 fPMDLoader->MakeTree("S");
299 treeS = fPMDLoader->TreeS();
301 Int_t bufsize = 16000;
302 treeS->Branch("PMDSDigit", &fSDigits, bufsize);
304 TClonesArray* hits = 0;
305 if (fPMD) hits = fPMD->Hits();
307 // Start loop on tracks in the hits containers
309 for (Int_t track=0; track<ntracks;track++)
311 gAlice->GetMCApp()->ResetHits();
312 treeH->GetEvent(track);
315 npmd = hits->GetEntriesFast();
316 for (Int_t ipmd = 0; ipmd < npmd; ipmd++)
318 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
319 trackno = fPMDHit->GetTrack();
320 // get kinematics of the particles
322 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
323 trackpid = mparticle->GetPdgCode();
324 Int_t ks = mparticle->GetStatusCode();
326 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
328 if (mparticle->GetFirstMother() == -1)
330 tracknoOld = trackno;
331 trackpidOld = trackpid;
336 Int_t trnotemp = trackno; // Modified on 25th Nov 2009
337 if(ks==1||(imo = mparticle->GetFirstMother())<0 ){
338 vx = mparticle->Vx();
339 vy = mparticle->Vy();
340 vz = mparticle->Vz();
342 if(trackpid==kGamma||trackpid==11||trackpid==-11||
343 trackpid==kPi0)igstatus=1;
347 while(((imo = mparticle->GetFirstMother()) >= 0)&&
348 (ks = mparticle->GetStatusCode() <1) )
350 mparticle = gAlice->GetMCApp()->Particle(imo);
351 trackpid = mparticle->GetPdgCode();
352 ks = mparticle->GetStatusCode();
353 vx = mparticle->Vx();
354 vy = mparticle->Vy();
355 vz = mparticle->Vz();
357 // Modified on 25th Nov 2009
368 // end of modification on 25th Nov 2009
371 if(trackpid==kGamma||trackpid==11||trackpid==-11||
372 trackpid==kPi0)igstatus=1;
375 trackpid=trackpidOld;
378 //-----------------end of modification----------------
383 edep = fPMDHit->GetEnergy();
384 Int_t vol1 = fPMDHit->GetVolume(1); // Column
385 Int_t vol2 = fPMDHit->GetVolume(2); // Row
386 Int_t vol7 = fPMDHit->GetVolume(4); // Serial Module No
389 // -----------------------------------------//
390 // In new geometry after adding electronics //
391 // For Super Module 1 & 2 //
392 // nrow = 48, ncol = 96 //
393 // For Super Module 3 & 4 //
394 // nrow = 96, ncol = 48 //
395 // -----------------------------------------//
403 smnumber = vol7 - 24;
405 Int_t vol8 = smnumber/6 + 1; // fake supermodule
407 if (vol8 == 1 || vol8 == 2)
412 else if (vol8 == 3 || vol8 == 4)
418 AliDebug(2,Form("Zposition = %f Edeposition = %f",zPos,edep));
431 Int_t smn = smnumber;
432 Int_t ixx = xpad - 1;
433 Int_t iyy = ypad - 1;
436 fPRE[smn][ixx][iyy] += edep;
437 fPRECounter[smn][ixx][iyy]++;
439 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
444 fCPV[smn][ixx][iyy] += edep;
445 fCPVCounter[smn][ixx][iyy]++;
446 AliPMDcell* cpvcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
447 fCPVCell.Add(cpvcell);
451 } // Track Loop ended
452 TrackAssignment2CPVCell();
453 TrackAssignment2Cell();
461 for (Int_t idet = 0; idet < 2; idet++)
463 for (Int_t ism = 0; ism < fgkTotUM; ism++)
465 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
467 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
471 deltaE = fPRE[ism][jrow][kcol];
472 trno = fPRETrackNo[ism][jrow][kcol];
477 deltaE = fCPV[ism][jrow][kcol];
478 trno = fCPVTrackNo[ism][jrow][kcol];
484 TParticle *mparticle = gAlice->GetMCApp()->Particle(trno);
485 trpid = mparticle->GetPdgCode();
486 AddSDigit(trno,trpid,detno,ism,jrow,kcol,deltaE);
494 fPMDLoader->WriteSDigits("OVERWRITE");
497 //____________________________________________________________________________
499 void AliPMDDigitizer::Hits2Digits(Int_t ievt)
501 // This reads the PMD Hits tree and assigns the right track number
502 // to a cell and stores in the digits tree
504 const Int_t kPi0 = 111;
505 const Int_t kGamma = 22;
513 Float_t xPos, yPos, zPos;
514 Int_t xpad = -1, ypad = -1;
516 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
518 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
521 AliDebug(1,Form("Event Number = %d",ievt));
522 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
523 AliDebug(1,Form("Number of Particles = %d", nparticles));
525 fRunLoader->GetEvent(ievt);
526 // ------------------------------------------------------- //
527 // Pointer to specific detector hits.
528 // Get pointers to Alice detectors and Hits containers
530 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
531 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
533 if (fPMDLoader == 0x0)
535 AliError("Can not find PMD or PMDLoader");
537 TTree* treeH = fPMDLoader->TreeH();
538 Int_t ntracks = (Int_t) treeH->GetEntries();
539 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
540 fPMDLoader->LoadDigits("recreate");
541 TTree* treeD = fPMDLoader->TreeD();
544 fPMDLoader->MakeTree("D");
545 treeD = fPMDLoader->TreeD();
547 Int_t bufsize = 16000;
548 treeD->Branch("PMDDigit", &fDigits, bufsize);
550 TClonesArray* hits = 0;
551 if (fPMD) hits = fPMD->Hits();
553 // Start loop on tracks in the hits containers
555 for (Int_t track=0; track<ntracks;track++)
557 gAlice->GetMCApp()->ResetHits();
558 treeH->GetEvent(track);
562 npmd = hits->GetEntriesFast();
563 for (Int_t ipmd = 0; ipmd < npmd; ipmd++)
565 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
566 trackno = fPMDHit->GetTrack();
568 // get kinematics of the particles
570 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
571 trackpid = mparticle->GetPdgCode();
572 Int_t ks = mparticle->GetStatusCode();
574 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
575 if (mparticle->GetFirstMother() == -1)
577 tracknoOld = trackno;
578 trackpidOld = trackpid;
584 Int_t trnotemp = trackno; // modified on 25th Nov 2009
585 if(ks==1||(imo = mparticle->GetFirstMother())<0 ){
586 vx = mparticle->Vx();
587 vy = mparticle->Vy();
588 vz = mparticle->Vz();
590 if(trackpid==kGamma||trackpid==11||trackpid==-11||trackpid==kPi0)
595 while(((imo = mparticle->GetFirstMother()) >= 0)&&
596 (ks = mparticle->GetStatusCode() <1) )
598 mparticle = gAlice->GetMCApp()->Particle(imo);
599 trackpid = mparticle->GetPdgCode();
600 ks = mparticle->GetStatusCode();
601 vx = mparticle->Vx();
602 vy = mparticle->Vy();
603 vz = mparticle->Vz();
605 // Modified on 25th Nov 2009
618 if(trackpid==kGamma||trackpid==11||trackpid==-11||trackpid==kPi0)
622 trackpid=trackpidOld;
628 edep = fPMDHit->GetEnergy();
629 Int_t vol1 = fPMDHit->GetVolume(1); // Column
630 Int_t vol2 = fPMDHit->GetVolume(2); // Row
631 Int_t vol7 = fPMDHit->GetVolume(4); // Serial Module No
633 // -----------------------------------------//
634 // In new geometry after adding electronics //
635 // For Super Module 1 & 2 //
636 // nrow = 48, ncol = 96 //
637 // For Super Module 3 & 4 //
638 // nrow = 96, ncol = 48 //
639 // -----------------------------------------//
647 smnumber = vol7 - 24;
649 Int_t vol8 = smnumber/6 + 1; // fake supermodule
651 if (vol8 == 1 || vol8 == 2)
656 else if (vol8 == 3 || vol8 == 4)
662 AliDebug(2,Form("ZPosition = %f Edeposition = %d",zPos,edep));
679 else if (zPos > fZPos)
685 Int_t smn = smnumber;
686 Int_t ixx = xpad - 1;
687 Int_t iyy = ypad - 1;
690 fPRE[smn][ixx][iyy] += edep;
691 fPRECounter[smn][ixx][iyy]++;
693 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
699 fCPV[smn][ixx][iyy] += edep;
700 fCPVCounter[smn][ixx][iyy]++;
701 AliPMDcell* cpvcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
702 fCPVCell.Add(cpvcell);
706 } // Track Loop ended
707 TrackAssignment2CPVCell();
708 TrackAssignment2Cell();
718 for (Int_t idet = 0; idet < 2; idet++)
720 for (Int_t ism = 0; ism < fgkTotUM; ism++)
722 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
724 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
728 deltaE = fPRE[ism][jrow][kcol];
729 trno = fPRETrackNo[ism][jrow][kcol];
734 deltaE = fCPV[ism][jrow][kcol];
735 trno = fCPVTrackNo[ism][jrow][kcol];
742 // To decalibrate the adc values
744 gain1 = Gain(idet,ism,jrow,kcol);
747 Int_t adcDecalib = (Int_t)(adc/gain1);
748 adc = (Float_t) adcDecalib;
755 // Pedestal Decalibration
757 fCalibPed->GetPedMeanRms(idet,ism,jrow,kcol);
758 Int_t pedrms1 = (Int_t) pedmeanrms%100;
759 Float_t pedrms = (Float_t)pedrms1/10.;
761 (Float_t) (pedmeanrms - pedrms1)/1000.0;
764 adc += (pedmean + 3.0*pedrms);
766 = gAlice->GetMCApp()->Particle(trno);
767 trpid = mparticle->GetPdgCode();
769 AddDigit(trno,trpid,detno,ism,jrow,kcol,adc);
776 } // supermodule loop
779 fPMDLoader->WriteDigits("OVERWRITE");
783 //____________________________________________________________________________
786 void AliPMDDigitizer::SDigits2Digits(Int_t ievt)
788 // This reads the PMD sdigits tree and converts energy deposition
789 // in a cell to ADC and stores in the digits tree
792 fRunLoader->GetEvent(ievt);
794 TTree* treeS = fPMDLoader->TreeS();
795 AliPMDsdigit *pmdsdigit;
796 TBranch *branch = treeS->GetBranch("PMDSDigit");
799 AliError("PMD Sdigit branch does not exist");
802 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
803 branch->SetAddress(&fSDigits);
805 TTree* treeD = fPMDLoader->TreeD();
808 fPMDLoader->MakeTree("D");
809 treeD = fPMDLoader->TreeD();
811 Int_t bufsize = 16000;
812 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
813 treeD->Branch("PMDDigit", &fDigits, bufsize);
815 Int_t trno, trpid, det, smn;
819 Int_t nmodules = (Int_t) treeS->GetEntries();
820 AliDebug(1,Form("Number of modules = %d",nmodules));
822 for (Int_t imodule = 0; imodule < nmodules; imodule++)
824 treeS->GetEntry(imodule);
825 Int_t nentries = fSDigits->GetLast();
826 AliDebug(2,Form("Number of entries per module = %d",nentries+1));
827 for (Int_t ient = 0; ient < nentries+1; ient++)
829 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
830 trno = pmdsdigit->GetTrackNumber();
831 trpid = pmdsdigit->GetTrackPid();
832 det = pmdsdigit->GetDetector();
833 smn = pmdsdigit->GetSMNumber();
834 irow = pmdsdigit->GetRow();
835 icol = pmdsdigit->GetColumn();
836 edep = pmdsdigit->GetCellEdep();
840 // To decalibrte the adc values
842 Float_t gain1 = Gain(det,smn,irow,icol);
845 Int_t adcDecalib = (Int_t)(adc/gain1);
846 adc = (Float_t) adcDecalib;
852 // Pedestal Decalibration
853 Int_t pedmeanrms = fCalibPed->GetPedMeanRms(det,smn,irow,icol);
854 Int_t pedrms1 = (Int_t) pedmeanrms%100;
855 Float_t pedrms = (Float_t)pedrms1/10.;
856 Float_t pedmean = (Float_t) (pedmeanrms - pedrms1)/1000.0;
859 adc += (pedmean + 3.0*pedrms);
860 AddDigit(trno,trpid,det,smn,irow,icol,adc);
867 fPMDLoader->WriteDigits("OVERWRITE");
870 //____________________________________________________________________________
871 void AliPMDDigitizer::Exec(Option_t *option)
873 // Does the event merging and digitization
874 const char *cdeb = strstr(option,"deb");
877 AliDebug(100," *** PMD Exec is called ***");
880 Int_t ninputs = fManager->GetNinputs();
881 AliDebug(1,Form("Number of files to be processed = %d",ninputs));
884 for (Int_t i = 0; i < ninputs; i++)
886 Int_t troffset = fManager->GetMask(i);
887 MergeSDigits(i, troffset);
890 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
891 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
892 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
893 if (fPMDLoader == 0x0)
895 AliError("Can not find PMD or PMDLoader");
897 fPMDLoader->LoadDigits("update");
898 TTree* treeD = fPMDLoader->TreeD();
901 fPMDLoader->MakeTree("D");
902 treeD = fPMDLoader->TreeD();
904 Int_t bufsize = 16000;
905 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
906 treeD->Branch("PMDDigit", &fDigits, bufsize);
914 for (Int_t idet = 0; idet < 2; idet++)
916 for (Int_t ism = 0; ism < fgkTotUM; ism++)
918 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
920 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
924 deltaE = fPRE[ism][jrow][kcol];
925 trno = fPRETrackNo[ism][jrow][kcol];
926 trpid = fPRETrackPid[ism][jrow][kcol];
931 deltaE = fCPV[ism][jrow][kcol];
932 trno = fCPVTrackNo[ism][jrow][kcol];
933 trpid = fCPVTrackPid[ism][jrow][kcol];
941 // Gain decalibration
943 Float_t gain1 = Gain(idet,ism,jrow,kcol);
947 Int_t adcDecalib = (Int_t)(adc/gain1);
948 adc = (Float_t) adcDecalib;
954 // Pedestal Decalibration
956 fCalibPed->GetPedMeanRms(idet,ism,jrow,kcol);
957 Int_t pedrms1 = (Int_t) pedmeanrms%100;
958 Float_t pedrms = (Float_t)pedrms1/10.;
960 (Float_t) (pedmeanrms - pedrms1)/1000.0;
963 adc += (pedmean + 3.0*pedrms);
964 AddDigit(trno,trpid,detno,ism,jrow,kcol,adc);
972 } // supermodule loop
974 fPMDLoader->WriteDigits("OVERWRITE");
975 fPMDLoader->UnloadDigits();
978 //____________________________________________________________________________
979 void AliPMDDigitizer::TrackAssignment2CPVCell()
981 // This block assigns the cell id when there are
982 // multiple tracks in a cell according to the
984 // This method added by Ajay
985 Bool_t jsort = false;
998 cpvTrack = new Int_t ***[fgkTotUM];
999 cpvEdep = new Float_t ***[fgkTotUM];
1000 for (i=0; i<fgkTotUM; i++)
1002 cpvTrack[i] = new Int_t **[fgkRow];
1003 cpvEdep[i] = new Float_t **[fgkRow];
1006 for (i = 0; i < fgkTotUM; i++)
1008 for (j = 0; j < fgkRow; j++)
1010 cpvTrack[i][j] = new Int_t *[fgkCol];
1011 cpvEdep[i][j] = new Float_t *[fgkCol];
1014 for (i = 0; i < fgkTotUM; i++)
1016 for (j = 0; j < fgkRow; j++)
1018 for (k = 0; k < fgkCol; k++)
1020 Int_t nn = fCPVCounter[i][j][k];
1023 cpvTrack[i][j][k] = new Int_t[nn];
1024 cpvEdep[i][j][k] = new Float_t[nn];
1029 cpvTrack[i][j][k] = new Int_t[nn];
1030 cpvEdep[i][j][k] = new Float_t[nn];
1032 fCPVCounter[i][j][k] = 0;
1038 Int_t nentries = fCPVCell.GetEntries();
1040 Int_t mtrackno, ism, ixp, iyp;
1042 for (i = 0; i < nentries; i++)
1044 AliPMDcell* cpvcell = (AliPMDcell*)fCPVCell.UncheckedAt(i);
1046 mtrackno = cpvcell->GetTrackNumber();
1047 ism = cpvcell->GetSMNumber();
1048 ixp = cpvcell->GetX();
1049 iyp = cpvcell->GetY();
1050 edep = cpvcell->GetEdep();
1051 Int_t nn = fCPVCounter[ism][ixp][iyp];
1052 cpvTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
1053 cpvEdep[ism][ixp][iyp][nn] = edep;
1054 fCPVCounter[ism][ixp][iyp]++;
1060 for (im=0; im<fgkTotUM; im++)
1062 for (ix=0; ix<fgkRow; ix++)
1064 for (iy=0; iy<fgkCol; iy++)
1066 nn = fCPVCounter[im][ix][iy];
1069 // This block handles if a cell is fired
1070 // many times by many tracks
1071 status1 = new Int_t[nn];
1072 status2 = new Int_t[nn];
1073 trnarray = new Int_t[nn];
1074 for (iz = 0; iz < nn; iz++)
1076 status1[iz] = cpvTrack[im][ix][iy][iz];
1078 TMath::Sort(nn,status1,status2,jsort);
1079 Int_t trackOld = -99999;
1080 Int_t track, trCount = 0;
1081 for (iz = 0; iz < nn; iz++)
1083 track = status1[status2[iz]];
1084 if (trackOld != track)
1086 trnarray[trCount] = track;
1093 Float_t totEdp = 0.;
1094 trEdp = new Float_t[trCount];
1095 fracEdp = new Float_t[trCount];
1096 for (il = 0; il < trCount; il++)
1099 track = trnarray[il];
1100 for (iz = 0; iz < nn; iz++)
1102 if (track == cpvTrack[im][ix][iy][iz])
1104 trEdp[il] += cpvEdep[im][ix][iy][iz];
1107 totEdp += trEdp[il];
1110 Float_t fracOld = 0.;
1112 for (il = 0; il < trCount; il++)
1114 fracEdp[il] = trEdp[il]/totEdp;
1115 if (fracOld < fracEdp[il])
1117 fracOld = fracEdp[il];
1121 fCPVTrackNo[im][ix][iy] = trnarray[ilOld];
1128 // This only handles if a cell is fired
1129 // by only one track
1131 fCPVTrackNo[im][ix][iy] = cpvTrack[im][ix][iy][0];
1136 // This is if no cell is fired
1137 fCPVTrackNo[im][ix][iy] = -999;
1143 // Delete all the pointers
1145 for (i = 0; i < fgkTotUM; i++)
1147 for (j = 0; j < fgkRow; j++)
1149 for (k = 0; k < fgkCol; k++)
1151 delete []cpvTrack[i][j][k];
1152 delete []cpvEdep[i][j][k];
1157 for (i = 0; i < fgkTotUM; i++)
1159 for (j = 0; j < fgkRow; j++)
1161 delete [] cpvTrack[i][j];
1162 delete [] cpvEdep[i][j];
1166 for (i = 0; i < fgkTotUM; i++)
1168 delete [] cpvTrack[i];
1169 delete [] cpvEdep[i];
1175 // End of the cell id assignment
1178 //____________________________________________________________________________
1180 void AliPMDDigitizer::MergeSDigits(Int_t filenumber, Int_t troffset)
1183 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(filenumber));
1184 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
1185 fPMDLoader->LoadSDigits("read");
1186 TTree* treeS = fPMDLoader->TreeS();
1187 AliPMDsdigit *pmdsdigit;
1188 TBranch *branch = treeS->GetBranch("PMDSDigit");
1189 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
1190 branch->SetAddress(&fSDigits);
1192 Int_t itrackno, itrackpid, idet, ism;
1195 Int_t nmodules = (Int_t) treeS->GetEntries();
1196 AliDebug(1,Form("Number of Modules in the treeS = %d",nmodules));
1197 AliDebug(1,Form("Track Offset = %d",troffset));
1198 for (Int_t imodule = 0; imodule < nmodules; imodule++)
1200 treeS->GetEntry(imodule);
1201 Int_t nentries = fSDigits->GetLast();
1202 AliDebug(2,Form("Number of Entries per Module = %d",nentries));
1203 for (Int_t ient = 0; ient < nentries+1; ient++)
1205 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
1206 itrackno = pmdsdigit->GetTrackNumber();
1207 itrackpid = pmdsdigit->GetTrackPid();
1208 idet = pmdsdigit->GetDetector();
1209 ism = pmdsdigit->GetSMNumber();
1210 ixp = pmdsdigit->GetRow();
1211 iyp = pmdsdigit->GetColumn();
1212 edep = pmdsdigit->GetCellEdep();
1215 if (fPRE[ism][ixp][iyp] < edep)
1217 fPRETrackNo[ism][ixp][iyp] = troffset + itrackno;
1218 fPRETrackPid[ism][ixp][iyp] = itrackpid;
1220 fPRE[ism][ixp][iyp] += edep;
1224 if (fCPV[ism][ixp][iyp] < edep)
1226 fCPVTrackNo[ism][ixp][iyp] = troffset + itrackno;
1227 fCPVTrackPid[ism][ixp][iyp] = itrackpid;
1229 fCPV[ism][ixp][iyp] += edep;
1235 // ----------------------------------------------------------------------
1236 void AliPMDDigitizer::TrackAssignment2Cell()
1239 // This block assigns the cell id when there are
1240 // multiple tracks in a cell according to the
1241 // energy deposition
1243 Bool_t jsort = false;
1254 Float_t ****pmdEdep;
1256 pmdTrack = new Int_t ***[fgkTotUM];
1257 pmdEdep = new Float_t ***[fgkTotUM];
1258 for (i=0; i<fgkTotUM; i++)
1260 pmdTrack[i] = new Int_t **[fgkRow];
1261 pmdEdep[i] = new Float_t **[fgkRow];
1264 for (i = 0; i < fgkTotUM; i++)
1266 for (j = 0; j < fgkRow; j++)
1268 pmdTrack[i][j] = new Int_t *[fgkCol];
1269 pmdEdep[i][j] = new Float_t *[fgkCol];
1273 for (i = 0; i < fgkTotUM; i++)
1275 for (j = 0; j < fgkRow; j++)
1277 for (k = 0; k < fgkCol; k++)
1279 Int_t nn = fPRECounter[i][j][k];
1282 pmdTrack[i][j][k] = new Int_t[nn];
1283 pmdEdep[i][j][k] = new Float_t[nn];
1288 pmdTrack[i][j][k] = new Int_t[nn];
1289 pmdEdep[i][j][k] = new Float_t[nn];
1291 fPRECounter[i][j][k] = 0;
1297 Int_t nentries = fCell.GetEntries();
1299 Int_t mtrackno, ism, ixp, iyp;
1302 for (i = 0; i < nentries; i++)
1304 AliPMDcell* cell = (AliPMDcell*)fCell.UncheckedAt(i);
1306 mtrackno = cell->GetTrackNumber();
1307 ism = cell->GetSMNumber();
1310 edep = cell->GetEdep();
1311 Int_t nn = fPRECounter[ism][ixp][iyp];
1312 pmdTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
1313 pmdEdep[ism][ixp][iyp][nn] = edep;
1314 fPRECounter[ism][ixp][iyp]++;
1321 for (im=0; im<fgkTotUM; im++)
1323 for (ix=0; ix<fgkRow; ix++)
1325 for (iy=0; iy<fgkCol; iy++)
1327 nn = fPRECounter[im][ix][iy];
1330 // This block handles if a cell is fired
1331 // many times by many tracks
1332 status1 = new Int_t[nn];
1333 status2 = new Int_t[nn];
1334 trnarray = new Int_t[nn];
1335 for (iz = 0; iz < nn; iz++)
1337 status1[iz] = pmdTrack[im][ix][iy][iz];
1339 TMath::Sort(nn,status1,status2,jsort);
1340 Int_t trackOld = -99999;
1341 Int_t track, trCount = 0;
1342 for (iz = 0; iz < nn; iz++)
1344 track = status1[status2[iz]];
1345 if (trackOld != track)
1347 trnarray[trCount] = track;
1354 Float_t totEdp = 0.;
1355 trEdp = new Float_t[trCount];
1356 fracEdp = new Float_t[trCount];
1357 for (il = 0; il < trCount; il++)
1360 track = trnarray[il];
1361 for (iz = 0; iz < nn; iz++)
1363 if (track == pmdTrack[im][ix][iy][iz])
1365 trEdp[il] += pmdEdep[im][ix][iy][iz];
1368 totEdp += trEdp[il];
1371 Float_t fracOld = 0.;
1373 for (il = 0; il < trCount; il++)
1375 fracEdp[il] = trEdp[il]/totEdp;
1376 if (fracOld < fracEdp[il])
1378 fracOld = fracEdp[il];
1382 fPRETrackNo[im][ix][iy] = trnarray[ilOld];
1389 // This only handles if a cell is fired
1390 // by only one track
1392 fPRETrackNo[im][ix][iy] = pmdTrack[im][ix][iy][0];
1397 // This is if no cell is fired
1398 fPRETrackNo[im][ix][iy] = -999;
1404 // Delete all the pointers
1406 for (i = 0; i < fgkTotUM; i++)
1408 for (j = 0; j < fgkRow; j++)
1410 for (k = 0; k < fgkCol; k++)
1412 delete [] pmdTrack[i][j][k];
1413 delete [] pmdEdep[i][j][k];
1418 for (i = 0; i < fgkTotUM; i++)
1420 for (j = 0; j < fgkRow; j++)
1422 delete [] pmdTrack[i][j];
1423 delete [] pmdEdep[i][j];
1427 for (i = 0; i < fgkTotUM; i++)
1429 delete [] pmdTrack[i];
1430 delete [] pmdEdep[i];
1435 // End of the cell id assignment
1438 //____________________________________________________________________________
1439 void AliPMDDigitizer::MeV2ADC(Float_t mev, Float_t & adc) const
1441 // This converts the simulated edep to ADC according to the
1443 //PS Test in May 2009, Voltage @ 1350 V
1444 // KeV - ADC conversion for 12bit ADC
1445 // MPV data used for the fit and taken here
1447 const Float_t kConstant = -0.1602;
1448 const Float_t kErConstant = 0.9914;
1449 const Float_t kSlope = 77.47;
1450 const Float_t kErSlope = 3.16;
1452 Float_t cons = gRandom->Gaus(kConstant,kErConstant);
1453 Float_t slop = gRandom->Gaus(kSlope,kErSlope);
1455 Float_t adc12bit = slop*mev*0.001 + cons;
1457 if (adc12bit < 0.) adc12bit = 0.;
1459 if(adc12bit < 1600.0)
1461 adc = (Float_t) adc12bit;
1463 else if (adc12bit >= 1600.0)
1468 //____________________________________________________________________________
1469 void AliPMDDigitizer::AddSDigit(Int_t trnumber, Int_t trpid, Int_t det,
1470 Int_t smnumber, Int_t irow, Int_t icol,
1475 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
1476 TClonesArray &lsdigits = *fSDigits;
1477 new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,trpid,det,smnumber,irow,icol,adc);
1479 //____________________________________________________________________________
1481 void AliPMDDigitizer::AddDigit(Int_t trnumber, Int_t trpid, Int_t det,
1482 Int_t smnumber, Int_t irow, Int_t icol,
1487 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
1488 TClonesArray &ldigits = *fDigits;
1489 new(ldigits[fNdigit++]) AliPMDdigit(trnumber,trpid, det,smnumber,irow,icol,adc);
1491 //____________________________________________________________________________
1493 void AliPMDDigitizer::SetZPosition(Float_t zpos)
1497 //____________________________________________________________________________
1498 Float_t AliPMDDigitizer::GetZPosition() const
1502 //____________________________________________________________________________
1504 void AliPMDDigitizer::ResetCell()
1506 // clears the cell array and also the counter
1511 for (Int_t i = 0; i < fgkTotUM; i++)
1513 for (Int_t j = 0; j < fgkRow; j++)
1515 for (Int_t k = 0; k < fgkCol; k++)
1517 fCPVCounter[i][j][k] = 0;
1518 fPRECounter[i][j][k] = 0;
1523 //____________________________________________________________________________
1524 void AliPMDDigitizer::ResetSDigit()
1528 if (fSDigits) fSDigits->Delete();
1530 //____________________________________________________________________________
1531 void AliPMDDigitizer::ResetDigit()
1535 if (fDigits) fDigits->Delete();
1537 //____________________________________________________________________________
1539 void AliPMDDigitizer::ResetCellADC()
1541 // Clears individual cells edep and track number
1542 for (Int_t i = 0; i < fgkTotUM; i++)
1544 for (Int_t j = 0; j < fgkRow; j++)
1546 for (Int_t k = 0; k < fgkCol; k++)
1550 fCPVTrackNo[i][j][k] = 0;
1551 fPRETrackNo[i][j][k] = 0;
1552 fCPVTrackPid[i][j][k] = -1;
1553 fPRETrackPid[i][j][k] = -1;
1558 //____________________________________________________________________________
1560 void AliPMDDigitizer::UnLoad(Option_t *option)
1562 // Unloads all the root files
1564 const char *cS = strstr(option,"S");
1565 const char *cD = strstr(option,"D");
1567 fRunLoader->UnloadgAlice();
1568 fRunLoader->UnloadHeader();
1569 fRunLoader->UnloadKinematics();
1573 fPMDLoader->UnloadHits();
1577 fPMDLoader->UnloadHits();
1578 fPMDLoader->UnloadSDigits();
1582 //----------------------------------------------------------------------
1583 Float_t AliPMDDigitizer::Gain(Int_t det, Int_t smn, Int_t row, Int_t col) const
1585 // returns of the gain of the cell
1586 // Added this method by ZA
1588 //cout<<" I am here in gain "<<fCalibData<< "smn,row, col "<<smn
1589 //<<" "<<row<<" "<<col<<endl;
1592 AliError("No calibration data loaded from CDB!!!");
1597 GainFact = fCalibGain->GetGainFact(det,smn,row,col);
1600 //----------------------------------------------------------------------
1601 AliPMDCalibData* AliPMDDigitizer::GetCalibGain() const
1603 // The run number will be centralized in AliCDBManager,
1604 // you don't need to set it here!
1605 // Added this method by ZA
1606 // Cleaned up by Alberto
1607 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Gain");
1609 if(!entry) AliFatal("Calibration object retrieval failed!");
1611 AliPMDCalibData *calibdata=0;
1612 if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
1614 if (!calibdata) AliFatal("No calibration data from calibration database !");
1618 //----------------------------------------------------------------------
1619 AliPMDPedestal* AliPMDDigitizer::GetCalibPed() const
1621 // The run number will be centralized in AliCDBManager,
1622 // you don't need to set it here!
1624 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Ped");
1626 if(!entry) AliFatal("Pedestal object retrieval failed!");
1628 AliPMDPedestal *pedestal=0;
1629 if (entry) pedestal = (AliPMDPedestal*) entry->GetObject();
1631 if (!pedestal) AliFatal("No pedestal data from calibration database !");