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;
335 //------------------modified by Mriganka ----------------------
336 if(ks==1||(imo = mparticle->GetFirstMother())<0 ){
337 vx = mparticle->Vx();
338 vy = mparticle->Vy();
339 vz = mparticle->Vz();
341 if(trackpid==kGamma||trackpid==11||trackpid==-11||
342 trackpid==kPi0)igstatus=1;
346 while(((imo = mparticle->GetFirstMother()) >= 0)&&
347 (ks = mparticle->GetStatusCode() <1) )
349 mparticle = gAlice->GetMCApp()->Particle(imo);
350 trackpid = mparticle->GetPdgCode();
351 ks = mparticle->GetStatusCode();
352 vx = mparticle->Vx();
353 vy = mparticle->Vy();
354 vz = mparticle->Vz();
360 if(trackpid==kGamma||trackpid==11||trackpid==-11||
361 trackpid==kPi0)igstatus=1;
364 trackpid=trackpidOld;
367 //-----------------end of modification----------------
372 edep = fPMDHit->GetEnergy();
373 Int_t vol1 = fPMDHit->GetVolume(1); // Column
374 Int_t vol2 = fPMDHit->GetVolume(2); // Row
375 Int_t vol7 = fPMDHit->GetVolume(4); // Serial Module No
378 // -----------------------------------------//
379 // In new geometry after adding electronics //
380 // For Super Module 1 & 2 //
381 // nrow = 48, ncol = 96 //
382 // For Super Module 3 & 4 //
383 // nrow = 96, ncol = 48 //
384 // -----------------------------------------//
392 smnumber = vol7 - 24;
394 Int_t vol8 = smnumber/6 + 1; // fake supermodule
396 if (vol8 == 1 || vol8 == 2)
401 else if (vol8 == 3 || vol8 == 4)
407 AliDebug(2,Form("Zposition = %f Edeposition = %f",zPos,edep));
408 //Float_t zposition = TMath::Abs(zPos);
414 else if (zPos > fZPos)
419 //Int_t smn = smnumber - 1;
420 Int_t smn = smnumber;
421 Int_t ixx = xpad - 1;
422 Int_t iyy = ypad - 1;
425 fPRE[smn][ixx][iyy] += edep;
426 fPRECounter[smn][ixx][iyy]++;
428 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
433 fCPV[smn][ixx][iyy] += edep;
434 fCPVCounter[smn][ixx][iyy]++;
435 AliPMDcell* cpvcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
436 fCPVCell.Add(cpvcell);
440 } // Track Loop ended
441 TrackAssignment2CPVCell();
442 TrackAssignment2Cell();
450 for (Int_t idet = 0; idet < 2; idet++)
452 for (Int_t ism = 0; ism < fgkTotUM; ism++)
454 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
456 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
460 deltaE = fPRE[ism][jrow][kcol];
461 trno = fPRETrackNo[ism][jrow][kcol];
466 deltaE = fCPV[ism][jrow][kcol];
467 trno = fCPVTrackNo[ism][jrow][kcol];
473 TParticle *mparticle = gAlice->GetMCApp()->Particle(trno);
474 trpid = mparticle->GetPdgCode();
475 AddSDigit(trno,trpid,detno,ism,jrow,kcol,deltaE);
483 fPMDLoader->WriteSDigits("OVERWRITE");
486 //____________________________________________________________________________
488 void AliPMDDigitizer::Hits2Digits(Int_t ievt)
490 // This reads the PMD Hits tree and assigns the right track number
491 // to a cell and stores in the digits tree
493 const Int_t kPi0 = 111;
494 const Int_t kGamma = 22;
502 Float_t xPos, yPos, zPos;
503 Int_t xpad = -1, ypad = -1;
505 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
507 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
510 AliDebug(1,Form("Event Number = %d",ievt));
511 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
512 AliDebug(1,Form("Number of Particles = %d", nparticles));
514 fRunLoader->GetEvent(ievt);
515 // ------------------------------------------------------- //
516 // Pointer to specific detector hits.
517 // Get pointers to Alice detectors and Hits containers
519 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
520 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
522 if (fPMDLoader == 0x0)
524 AliError("Can not find PMD or PMDLoader");
526 TTree* treeH = fPMDLoader->TreeH();
527 Int_t ntracks = (Int_t) treeH->GetEntries();
528 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
529 fPMDLoader->LoadDigits("recreate");
530 TTree* treeD = fPMDLoader->TreeD();
533 fPMDLoader->MakeTree("D");
534 treeD = fPMDLoader->TreeD();
536 Int_t bufsize = 16000;
537 treeD->Branch("PMDDigit", &fDigits, bufsize);
539 TClonesArray* hits = 0;
540 if (fPMD) hits = fPMD->Hits();
542 // Start loop on tracks in the hits containers
544 for (Int_t track=0; track<ntracks;track++)
546 gAlice->GetMCApp()->ResetHits();
547 treeH->GetEvent(track);
551 npmd = hits->GetEntriesFast();
552 for (Int_t ipmd = 0; ipmd < npmd; ipmd++)
554 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
555 trackno = fPMDHit->GetTrack();
557 // get kinematics of the particles
559 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
560 trackpid = mparticle->GetPdgCode();
561 Int_t ks = mparticle->GetStatusCode();
563 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
564 if (mparticle->GetFirstMother() == -1)
566 tracknoOld = trackno;
567 trackpidOld = trackpid;
572 //-----------------------modified by Mriganka ------------------
573 if(ks==1||(imo = mparticle->GetFirstMother())<0 ){
574 vx = mparticle->Vx();
575 vy = mparticle->Vy();
576 vz = mparticle->Vz();
578 if(trackpid==kGamma||trackpid==11||trackpid==-11||trackpid==kPi0)
583 while(((imo = mparticle->GetFirstMother()) >= 0)&&
584 (ks = mparticle->GetStatusCode() <1) )
586 mparticle = gAlice->GetMCApp()->Particle(imo);
587 trackpid = mparticle->GetPdgCode();
588 ks = mparticle->GetStatusCode();
589 vx = mparticle->Vx();
590 vy = mparticle->Vy();
591 vz = mparticle->Vz();
597 if(trackpid==kGamma||trackpid==11||trackpid==-11||trackpid==kPi0)
601 trackpid=trackpidOld;
604 //-----------------end of modification----------------
608 edep = fPMDHit->GetEnergy();
609 Int_t vol1 = fPMDHit->GetVolume(1); // Column
610 Int_t vol2 = fPMDHit->GetVolume(2); // Row
611 Int_t vol7 = fPMDHit->GetVolume(4); // Serial Module No
613 // -----------------------------------------//
614 // In new geometry after adding electronics //
615 // For Super Module 1 & 2 //
616 // nrow = 48, ncol = 96 //
617 // For Super Module 3 & 4 //
618 // nrow = 96, ncol = 48 //
619 // -----------------------------------------//
627 smnumber = vol7 - 24;
629 Int_t vol8 = smnumber/6 + 1; // fake supermodule
631 if (vol8 == 1 || vol8 == 2)
636 else if (vol8 == 3 || vol8 == 4)
642 AliDebug(2,Form("ZPosition = %f Edeposition = %d",zPos,edep));
643 //Float_t zposition = TMath::Abs(zPos);
650 else if (zPos > fZPos)
656 //Int_t smn = smnumber - 1;
657 Int_t smn = smnumber;
658 Int_t ixx = xpad - 1;
659 Int_t iyy = ypad - 1;
662 fPRE[smn][ixx][iyy] += edep;
663 fPRECounter[smn][ixx][iyy]++;
665 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
671 fCPV[smn][ixx][iyy] += edep;
672 fCPVCounter[smn][ixx][iyy]++;
673 AliPMDcell* cpvcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
674 fCPVCell.Add(cpvcell);
678 } // Track Loop ended
679 TrackAssignment2CPVCell();
680 TrackAssignment2Cell();
690 for (Int_t idet = 0; idet < 2; idet++)
692 for (Int_t ism = 0; ism < fgkTotUM; ism++)
694 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
696 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
700 deltaE = fPRE[ism][jrow][kcol];
701 trno = fPRETrackNo[ism][jrow][kcol];
706 deltaE = fCPV[ism][jrow][kcol];
707 trno = fCPVTrackNo[ism][jrow][kcol];
714 // To decalibrate the adc values
716 gain1 = Gain(idet,ism,jrow,kcol);
719 Int_t adcDecalib = (Int_t)(adc/gain1);
720 adc = (Float_t) adcDecalib;
727 // Pedestal Decalibration
729 fCalibPed->GetPedMeanRms(idet,ism,jrow,kcol);
730 Int_t pedrms1 = (Int_t) pedmeanrms%100;
731 Float_t pedrms = (Float_t)pedrms1/10.;
733 (Float_t) (pedmeanrms - pedrms1)/1000.0;
736 adc += (pedmean + 3.0*pedrms);
738 = gAlice->GetMCApp()->Particle(trno);
739 trpid = mparticle->GetPdgCode();
741 AddDigit(trno,trpid,detno,ism,jrow,kcol,adc);
748 } // supermodule loop
751 fPMDLoader->WriteDigits("OVERWRITE");
755 //____________________________________________________________________________
758 void AliPMDDigitizer::SDigits2Digits(Int_t ievt)
760 // This reads the PMD sdigits tree and converts energy deposition
761 // in a cell to ADC and stores in the digits tree
764 fRunLoader->GetEvent(ievt);
766 TTree* treeS = fPMDLoader->TreeS();
767 AliPMDsdigit *pmdsdigit;
768 TBranch *branch = treeS->GetBranch("PMDSDigit");
771 AliError("PMD Sdigit branch does not exist");
774 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
775 branch->SetAddress(&fSDigits);
777 TTree* treeD = fPMDLoader->TreeD();
780 fPMDLoader->MakeTree("D");
781 treeD = fPMDLoader->TreeD();
783 Int_t bufsize = 16000;
784 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
785 treeD->Branch("PMDDigit", &fDigits, bufsize);
787 Int_t trno, trpid, det, smn;
791 Int_t nmodules = (Int_t) treeS->GetEntries();
792 AliDebug(1,Form("Number of modules = %d",nmodules));
794 for (Int_t imodule = 0; imodule < nmodules; imodule++)
796 treeS->GetEntry(imodule);
797 Int_t nentries = fSDigits->GetLast();
798 AliDebug(2,Form("Number of entries per module = %d",nentries+1));
799 for (Int_t ient = 0; ient < nentries+1; ient++)
801 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
802 trno = pmdsdigit->GetTrackNumber();
803 trpid = pmdsdigit->GetTrackPid();
804 det = pmdsdigit->GetDetector();
805 smn = pmdsdigit->GetSMNumber();
806 irow = pmdsdigit->GetRow();
807 icol = pmdsdigit->GetColumn();
808 edep = pmdsdigit->GetCellEdep();
812 // To decalibrte the adc values
814 Float_t gain1 = Gain(det,smn,irow,icol);
817 Int_t adcDecalib = (Int_t)(adc/gain1);
818 adc = (Float_t) adcDecalib;
824 // Pedestal Decalibration
825 Int_t pedmeanrms = fCalibPed->GetPedMeanRms(det,smn,irow,icol);
826 Int_t pedrms1 = (Int_t) pedmeanrms%100;
827 Float_t pedrms = (Float_t)pedrms1/10.;
828 Float_t pedmean = (Float_t) (pedmeanrms - pedrms1)/1000.0;
831 adc += (pedmean + 3.0*pedrms);
832 AddDigit(trno,trpid,det,smn,irow,icol,adc);
839 fPMDLoader->WriteDigits("OVERWRITE");
842 //____________________________________________________________________________
843 void AliPMDDigitizer::Exec(Option_t *option)
845 // Does the event merging and digitization
846 const char *cdeb = strstr(option,"deb");
849 AliDebug(100," *** PMD Exec is called ***");
852 Int_t ninputs = fManager->GetNinputs();
853 AliDebug(1,Form("Number of files to be processed = %d",ninputs));
856 for (Int_t i = 0; i < ninputs; i++)
858 Int_t troffset = fManager->GetMask(i);
859 MergeSDigits(i, troffset);
862 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
863 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
864 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
865 if (fPMDLoader == 0x0)
867 AliError("Can not find PMD or PMDLoader");
869 fPMDLoader->LoadDigits("update");
870 TTree* treeD = fPMDLoader->TreeD();
873 fPMDLoader->MakeTree("D");
874 treeD = fPMDLoader->TreeD();
876 Int_t bufsize = 16000;
877 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
878 treeD->Branch("PMDDigit", &fDigits, bufsize);
886 for (Int_t idet = 0; idet < 2; idet++)
888 for (Int_t ism = 0; ism < fgkTotUM; ism++)
890 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
892 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
896 deltaE = fPRE[ism][jrow][kcol];
897 trno = fPRETrackNo[ism][jrow][kcol];
898 trpid = fPRETrackPid[ism][jrow][kcol];
903 deltaE = fCPV[ism][jrow][kcol];
904 trno = fCPVTrackNo[ism][jrow][kcol];
905 trpid = fCPVTrackPid[ism][jrow][kcol];
913 // Gain decalibration
915 Float_t gain1 = Gain(idet,ism,jrow,kcol);
919 Int_t adcDecalib = (Int_t)(adc/gain1);
920 adc = (Float_t) adcDecalib;
926 // Pedestal Decalibration
928 fCalibPed->GetPedMeanRms(idet,ism,jrow,kcol);
929 Int_t pedrms1 = (Int_t) pedmeanrms%100;
930 Float_t pedrms = (Float_t)pedrms1/10.;
932 (Float_t) (pedmeanrms - pedrms1)/1000.0;
935 adc += (pedmean + 3.0*pedrms);
936 AddDigit(trno,trpid,detno,ism,jrow,kcol,adc);
944 } // supermodule loop
946 fPMDLoader->WriteDigits("OVERWRITE");
947 fPMDLoader->UnloadDigits();
950 //____________________________________________________________________________
951 void AliPMDDigitizer::TrackAssignment2CPVCell()
953 // This block assigns the cell id when there are
954 // multiple tracks in a cell according to the
956 // This method added by Ajay
957 Bool_t jsort = false;
970 cpvTrack = new Int_t ***[fgkTotUM];
971 cpvEdep = new Float_t ***[fgkTotUM];
972 for (i=0; i<fgkTotUM; i++)
974 cpvTrack[i] = new Int_t **[fgkRow];
975 cpvEdep[i] = new Float_t **[fgkRow];
978 for (i = 0; i < fgkTotUM; i++)
980 for (j = 0; j < fgkRow; j++)
982 cpvTrack[i][j] = new Int_t *[fgkCol];
983 cpvEdep[i][j] = new Float_t *[fgkCol];
986 for (i = 0; i < fgkTotUM; i++)
988 for (j = 0; j < fgkRow; j++)
990 for (k = 0; k < fgkCol; k++)
992 Int_t nn = fCPVCounter[i][j][k];
995 cpvTrack[i][j][k] = new Int_t[nn];
996 cpvEdep[i][j][k] = new Float_t[nn];
1001 cpvTrack[i][j][k] = new Int_t[nn];
1002 cpvEdep[i][j][k] = new Float_t[nn];
1004 fCPVCounter[i][j][k] = 0;
1010 Int_t nentries = fCPVCell.GetEntries();
1012 Int_t mtrackno, ism, ixp, iyp;
1014 for (i = 0; i < nentries; i++)
1016 AliPMDcell* cpvcell = (AliPMDcell*)fCPVCell.UncheckedAt(i);
1018 mtrackno = cpvcell->GetTrackNumber();
1019 ism = cpvcell->GetSMNumber();
1020 ixp = cpvcell->GetX();
1021 iyp = cpvcell->GetY();
1022 edep = cpvcell->GetEdep();
1023 Int_t nn = fCPVCounter[ism][ixp][iyp];
1024 cpvTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
1025 cpvEdep[ism][ixp][iyp][nn] = edep;
1026 fCPVCounter[ism][ixp][iyp]++;
1032 for (im=0; im<fgkTotUM; im++)
1034 for (ix=0; ix<fgkRow; ix++)
1036 for (iy=0; iy<fgkCol; iy++)
1038 nn = fCPVCounter[im][ix][iy];
1041 // This block handles if a cell is fired
1042 // many times by many tracks
1043 status1 = new Int_t[nn];
1044 status2 = new Int_t[nn];
1045 trnarray = new Int_t[nn];
1046 for (iz = 0; iz < nn; iz++)
1048 status1[iz] = cpvTrack[im][ix][iy][iz];
1050 TMath::Sort(nn,status1,status2,jsort);
1051 Int_t trackOld = -99999;
1052 Int_t track, trCount = 0;
1053 for (iz = 0; iz < nn; iz++)
1055 track = status1[status2[iz]];
1056 if (trackOld != track)
1058 trnarray[trCount] = track;
1065 Float_t totEdp = 0.;
1066 trEdp = new Float_t[trCount];
1067 fracEdp = new Float_t[trCount];
1068 for (il = 0; il < trCount; il++)
1071 track = trnarray[il];
1072 for (iz = 0; iz < nn; iz++)
1074 if (track == cpvTrack[im][ix][iy][iz])
1076 trEdp[il] += cpvEdep[im][ix][iy][iz];
1079 totEdp += trEdp[il];
1082 Float_t fracOld = 0.;
1084 for (il = 0; il < trCount; il++)
1086 fracEdp[il] = trEdp[il]/totEdp;
1087 if (fracOld < fracEdp[il])
1089 fracOld = fracEdp[il];
1093 fCPVTrackNo[im][ix][iy] = trnarray[ilOld];
1100 // This only handles if a cell is fired
1101 // by only one track
1103 fCPVTrackNo[im][ix][iy] = cpvTrack[im][ix][iy][0];
1108 // This is if no cell is fired
1109 fCPVTrackNo[im][ix][iy] = -999;
1115 // Delete all the pointers
1117 for (i = 0; i < fgkTotUM; i++)
1119 for (j = 0; j < fgkRow; j++)
1121 for (k = 0; k < fgkCol; k++)
1123 delete []cpvTrack[i][j][k];
1124 delete []cpvEdep[i][j][k];
1129 for (i = 0; i < fgkTotUM; i++)
1131 for (j = 0; j < fgkRow; j++)
1133 delete [] cpvTrack[i][j];
1134 delete [] cpvEdep[i][j];
1138 for (i = 0; i < fgkTotUM; i++)
1140 delete [] cpvTrack[i];
1141 delete [] cpvEdep[i];
1147 // End of the cell id assignment
1150 //____________________________________________________________________________
1152 void AliPMDDigitizer::MergeSDigits(Int_t filenumber, Int_t troffset)
1155 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(filenumber));
1156 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
1157 fPMDLoader->LoadSDigits("read");
1158 TTree* treeS = fPMDLoader->TreeS();
1159 AliPMDsdigit *pmdsdigit;
1160 TBranch *branch = treeS->GetBranch("PMDSDigit");
1161 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
1162 branch->SetAddress(&fSDigits);
1164 Int_t itrackno, itrackpid, idet, ism;
1167 Int_t nmodules = (Int_t) treeS->GetEntries();
1168 AliDebug(1,Form("Number of Modules in the treeS = %d",nmodules));
1169 AliDebug(1,Form("Track Offset = %d",troffset));
1170 for (Int_t imodule = 0; imodule < nmodules; imodule++)
1172 treeS->GetEntry(imodule);
1173 Int_t nentries = fSDigits->GetLast();
1174 AliDebug(2,Form("Number of Entries per Module = %d",nentries));
1175 for (Int_t ient = 0; ient < nentries+1; ient++)
1177 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
1178 itrackno = pmdsdigit->GetTrackNumber();
1179 itrackpid = pmdsdigit->GetTrackPid();
1180 idet = pmdsdigit->GetDetector();
1181 ism = pmdsdigit->GetSMNumber();
1182 ixp = pmdsdigit->GetRow();
1183 iyp = pmdsdigit->GetColumn();
1184 edep = pmdsdigit->GetCellEdep();
1187 if (fPRE[ism][ixp][iyp] < edep)
1189 fPRETrackNo[ism][ixp][iyp] = troffset + itrackno;
1190 fPRETrackPid[ism][ixp][iyp] = itrackpid;
1192 fPRE[ism][ixp][iyp] += edep;
1196 if (fCPV[ism][ixp][iyp] < edep)
1198 fCPVTrackNo[ism][ixp][iyp] = troffset + itrackno;
1199 fCPVTrackPid[ism][ixp][iyp] = itrackpid;
1201 fCPV[ism][ixp][iyp] += edep;
1207 // ----------------------------------------------------------------------
1208 void AliPMDDigitizer::TrackAssignment2Cell()
1211 // This block assigns the cell id when there are
1212 // multiple tracks in a cell according to the
1213 // energy deposition
1215 Bool_t jsort = false;
1226 Float_t ****pmdEdep;
1228 pmdTrack = new Int_t ***[fgkTotUM];
1229 pmdEdep = new Float_t ***[fgkTotUM];
1230 for (i=0; i<fgkTotUM; i++)
1232 pmdTrack[i] = new Int_t **[fgkRow];
1233 pmdEdep[i] = new Float_t **[fgkRow];
1236 for (i = 0; i < fgkTotUM; i++)
1238 for (j = 0; j < fgkRow; j++)
1240 pmdTrack[i][j] = new Int_t *[fgkCol];
1241 pmdEdep[i][j] = new Float_t *[fgkCol];
1245 for (i = 0; i < fgkTotUM; i++)
1247 for (j = 0; j < fgkRow; j++)
1249 for (k = 0; k < fgkCol; k++)
1251 Int_t nn = fPRECounter[i][j][k];
1254 pmdTrack[i][j][k] = new Int_t[nn];
1255 pmdEdep[i][j][k] = new Float_t[nn];
1260 pmdTrack[i][j][k] = new Int_t[nn];
1261 pmdEdep[i][j][k] = new Float_t[nn];
1263 fPRECounter[i][j][k] = 0;
1269 Int_t nentries = fCell.GetEntries();
1271 Int_t mtrackno, ism, ixp, iyp;
1274 for (i = 0; i < nentries; i++)
1276 AliPMDcell* cell = (AliPMDcell*)fCell.UncheckedAt(i);
1278 mtrackno = cell->GetTrackNumber();
1279 ism = cell->GetSMNumber();
1282 edep = cell->GetEdep();
1283 Int_t nn = fPRECounter[ism][ixp][iyp];
1284 pmdTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
1285 pmdEdep[ism][ixp][iyp][nn] = edep;
1286 fPRECounter[ism][ixp][iyp]++;
1293 for (im=0; im<fgkTotUM; im++)
1295 for (ix=0; ix<fgkRow; ix++)
1297 for (iy=0; iy<fgkCol; iy++)
1299 nn = fPRECounter[im][ix][iy];
1302 // This block handles if a cell is fired
1303 // many times by many tracks
1304 status1 = new Int_t[nn];
1305 status2 = new Int_t[nn];
1306 trnarray = new Int_t[nn];
1307 for (iz = 0; iz < nn; iz++)
1309 status1[iz] = pmdTrack[im][ix][iy][iz];
1311 TMath::Sort(nn,status1,status2,jsort);
1312 Int_t trackOld = -99999;
1313 Int_t track, trCount = 0;
1314 for (iz = 0; iz < nn; iz++)
1316 track = status1[status2[iz]];
1317 if (trackOld != track)
1319 trnarray[trCount] = track;
1326 Float_t totEdp = 0.;
1327 trEdp = new Float_t[trCount];
1328 fracEdp = new Float_t[trCount];
1329 for (il = 0; il < trCount; il++)
1332 track = trnarray[il];
1333 for (iz = 0; iz < nn; iz++)
1335 if (track == pmdTrack[im][ix][iy][iz])
1337 trEdp[il] += pmdEdep[im][ix][iy][iz];
1340 totEdp += trEdp[il];
1343 Float_t fracOld = 0.;
1345 for (il = 0; il < trCount; il++)
1347 fracEdp[il] = trEdp[il]/totEdp;
1348 if (fracOld < fracEdp[il])
1350 fracOld = fracEdp[il];
1354 fPRETrackNo[im][ix][iy] = trnarray[ilOld];
1361 // This only handles if a cell is fired
1362 // by only one track
1364 fPRETrackNo[im][ix][iy] = pmdTrack[im][ix][iy][0];
1369 // This is if no cell is fired
1370 fPRETrackNo[im][ix][iy] = -999;
1376 // Delete all the pointers
1378 for (i = 0; i < fgkTotUM; i++)
1380 for (j = 0; j < fgkRow; j++)
1382 for (k = 0; k < fgkCol; k++)
1384 delete [] pmdTrack[i][j][k];
1385 delete [] pmdEdep[i][j][k];
1390 for (i = 0; i < fgkTotUM; i++)
1392 for (j = 0; j < fgkRow; j++)
1394 delete [] pmdTrack[i][j];
1395 delete [] pmdEdep[i][j];
1399 for (i = 0; i < fgkTotUM; i++)
1401 delete [] pmdTrack[i];
1402 delete [] pmdEdep[i];
1407 // End of the cell id assignment
1410 //____________________________________________________________________________
1411 void AliPMDDigitizer::MeV2ADC(Float_t mev, Float_t & adc) const
1413 // This converts the simulated edep to ADC according to the
1415 //PS Test in September 2003 and 2006
1416 // KeV - ADC conversion for 12bit ADC
1419 const Float_t kConstant = 0.07;
1420 const Float_t kErConstant = 0.1;
1421 const Float_t kSlope = 76.0;
1422 const Float_t kErSlope = 5.0;
1424 Float_t cons = gRandom->Gaus(kConstant,kErConstant);
1425 Float_t slop = gRandom->Gaus(kSlope,kErSlope);
1427 Float_t adc12bit = slop*mev*0.001 + cons;
1430 if(adc12bit < 1600.0)
1432 adc = (Float_t) adc12bit;
1434 else if (adc12bit >= 1600.0)
1439 //____________________________________________________________________________
1440 void AliPMDDigitizer::AddSDigit(Int_t trnumber, Int_t trpid, Int_t det,
1441 Int_t smnumber, Int_t irow, Int_t icol,
1446 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
1447 TClonesArray &lsdigits = *fSDigits;
1448 new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,trpid,det,smnumber,irow,icol,adc);
1450 //____________________________________________________________________________
1452 void AliPMDDigitizer::AddDigit(Int_t trnumber, Int_t trpid, Int_t det,
1453 Int_t smnumber, Int_t irow, Int_t icol,
1458 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
1459 TClonesArray &ldigits = *fDigits;
1460 new(ldigits[fNdigit++]) AliPMDdigit(trnumber,trpid, det,smnumber,irow,icol,adc);
1462 //____________________________________________________________________________
1464 void AliPMDDigitizer::SetZPosition(Float_t zpos)
1468 //____________________________________________________________________________
1469 Float_t AliPMDDigitizer::GetZPosition() const
1473 //____________________________________________________________________________
1475 void AliPMDDigitizer::ResetCell()
1477 // clears the cell array and also the counter
1482 for (Int_t i = 0; i < fgkTotUM; i++)
1484 for (Int_t j = 0; j < fgkRow; j++)
1486 for (Int_t k = 0; k < fgkCol; k++)
1488 fCPVCounter[i][j][k] = 0;
1489 fPRECounter[i][j][k] = 0;
1494 //____________________________________________________________________________
1495 void AliPMDDigitizer::ResetSDigit()
1499 if (fSDigits) fSDigits->Delete();
1501 //____________________________________________________________________________
1502 void AliPMDDigitizer::ResetDigit()
1506 if (fDigits) fDigits->Delete();
1508 //____________________________________________________________________________
1510 void AliPMDDigitizer::ResetCellADC()
1512 // Clears individual cells edep and track number
1513 for (Int_t i = 0; i < fgkTotUM; i++)
1515 for (Int_t j = 0; j < fgkRow; j++)
1517 for (Int_t k = 0; k < fgkCol; k++)
1521 fCPVTrackNo[i][j][k] = 0;
1522 fPRETrackNo[i][j][k] = 0;
1523 fCPVTrackPid[i][j][k] = -1;
1524 fPRETrackPid[i][j][k] = -1;
1529 //____________________________________________________________________________
1531 void AliPMDDigitizer::UnLoad(Option_t *option)
1533 // Unloads all the root files
1535 const char *cS = strstr(option,"S");
1536 const char *cD = strstr(option,"D");
1538 fRunLoader->UnloadgAlice();
1539 fRunLoader->UnloadHeader();
1540 fRunLoader->UnloadKinematics();
1544 fPMDLoader->UnloadHits();
1548 fPMDLoader->UnloadHits();
1549 fPMDLoader->UnloadSDigits();
1553 //----------------------------------------------------------------------
1554 Float_t AliPMDDigitizer::Gain(Int_t det, Int_t smn, Int_t row, Int_t col) const
1556 // returns of the gain of the cell
1557 // Added this method by ZA
1559 //cout<<" I am here in gain "<<fCalibData<< "smn,row, col "<<smn
1560 //<<" "<<row<<" "<<col<<endl;
1563 AliError("No calibration data loaded from CDB!!!");
1568 GainFact = fCalibGain->GetGainFact(det,smn,row,col);
1571 //----------------------------------------------------------------------
1572 AliPMDCalibData* AliPMDDigitizer::GetCalibGain() const
1574 // The run number will be centralized in AliCDBManager,
1575 // you don't need to set it here!
1576 // Added this method by ZA
1577 // Cleaned up by Alberto
1578 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Gain");
1580 if(!entry) AliFatal("Calibration object retrieval failed!");
1582 AliPMDCalibData *calibdata=0;
1583 if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
1585 if (!calibdata) AliFatal("No calibration data from calibration database !");
1589 //----------------------------------------------------------------------
1590 AliPMDPedestal* AliPMDDigitizer::GetCalibPed() const
1592 // The run number will be centralized in AliCDBManager,
1593 // you don't need to set it here!
1595 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Ped");
1597 if(!entry) AliFatal("Pedestal object retrieval failed!");
1599 AliPMDPedestal *pedestal=0;
1600 if (entry) pedestal = (AliPMDPedestal*) entry->GetObject();
1602 if (!pedestal) AliFatal("No pedestal data from calibration database !");