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;
98 //____________________________________________________________________________
99 AliPMDDigitizer::AliPMDDigitizer(const AliPMDDigitizer& digitizer):
100 AliDigitizer(digitizer),
105 fCalibGain(GetCalibGain()),
106 fCalibPed(GetCalibPed()),
114 fZPos(361.5) // in units of cm, default position of PMD
117 AliError("Copy constructor not allowed ");
120 //____________________________________________________________________________
121 AliPMDDigitizer & AliPMDDigitizer::operator=(const AliPMDDigitizer& /*digitizer*/)
123 // Assignment operator
124 AliError("Assignement operator not allowed ");
128 //____________________________________________________________________________
129 AliPMDDigitizer::AliPMDDigitizer(AliRunDigitizer* manager):
130 AliDigitizer(manager),
135 fCalibGain(GetCalibGain()),
136 fCalibPed(GetCalibPed()),
137 fSDigits(new TClonesArray("AliPMDsdigit", 1000)),
138 fDigits(new TClonesArray("AliPMDdigit", 1000)),
144 fZPos(361.5)// in units of cm, This is the default position of PMD
146 // ctor which should be used
149 for (Int_t i = 0; i < fgkTotUM; i++)
151 for (Int_t j = 0; j < fgkRow; j++)
153 for (Int_t k = 0; k < fgkCol; k++)
157 fCPVCounter[i][j][k] = 0;
158 fPRECounter[i][j][k] = 0;
159 fCPVTrackNo[i][j][k] = -1;
160 fPRETrackNo[i][j][k] = -1;
166 //____________________________________________________________________________
167 AliPMDDigitizer::~AliPMDDigitizer()
169 // Default Destructor
187 //____________________________________________________________________________
188 void AliPMDDigitizer::OpengAliceFile(const char *file, Option_t *option)
190 // Loads galice.root file and corresponding header, kinematics
191 // hits and sdigits or digits depending on the option
194 TString evfoldname = AliConfig::GetDefaultEventFolderName();
195 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
197 fRunLoader = AliRunLoader::Open(file,AliConfig::GetDefaultEventFolderName(), "UPDATE");
201 AliError(Form("Can not open session for file %s.",file));
204 const char *cHS = strstr(option,"HS");
205 const char *cHD = strstr(option,"HD");
206 const char *cSD = strstr(option,"SD");
210 if (!fRunLoader->GetAliRun()) fRunLoader->LoadgAlice();
211 if (!fRunLoader->TreeE()) fRunLoader->LoadHeader();
212 if (!fRunLoader->TreeK()) fRunLoader->LoadKinematics();
214 gAlice = fRunLoader->GetAliRun();
218 AliDebug(1,"Alirun object found");
222 AliError("Could not found Alirun object");
225 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
228 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
229 if (fPMDLoader == 0x0)
231 AliError("Can not find PMDLoader");
237 fPMDLoader->LoadHits("READ");
238 fPMDLoader->LoadSDigits("recreate");
242 fPMDLoader->LoadHits("READ");
243 fPMDLoader->LoadDigits("recreate");
247 fPMDLoader->LoadSDigits("READ");
248 fPMDLoader->LoadDigits("recreate");
251 //____________________________________________________________________________
252 void AliPMDDigitizer::Hits2SDigits(Int_t ievt)
254 // This reads the PMD Hits tree and assigns the right track number
255 // to a cell and stores in the summable digits tree
258 const Int_t kPi0 = 111;
259 const Int_t kGamma = 22;
267 Float_t xPos, yPos, zPos;
268 Int_t xpad = -1, ypad = -1;
270 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
273 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
276 AliDebug(1,Form("Event Number = %d",ievt));
277 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
278 AliDebug(1,Form("Number of Particles = %d",nparticles));
279 fRunLoader->GetEvent(ievt);
280 // ------------------------------------------------------- //
281 // Pointer to specific detector hits.
282 // Get pointers to Alice detectors and Hits containers
284 TTree* treeH = fPMDLoader->TreeH();
286 Int_t ntracks = (Int_t) treeH->GetEntries();
287 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
288 TTree* treeS = fPMDLoader->TreeS();
291 fPMDLoader->MakeTree("S");
292 treeS = fPMDLoader->TreeS();
294 Int_t bufsize = 16000;
295 treeS->Branch("PMDSDigit", &fSDigits, bufsize);
297 TClonesArray* hits = 0;
298 if (fPMD) hits = fPMD->Hits();
300 // Start loop on tracks in the hits containers
302 for (Int_t track=0; track<ntracks;track++)
305 treeH->GetEvent(track);
308 npmd = hits->GetEntriesFast();
309 for (Int_t ipmd = 0; ipmd < npmd; ipmd++)
311 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
312 trackno = fPMDHit->GetTrack();
313 // get kinematics of the particles
315 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
316 trackpid = mparticle->GetPdgCode();
317 Int_t ks = mparticle->GetStatusCode();
319 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
321 if (mparticle->GetFirstMother() == -1)
323 tracknoOld = trackno;
324 trackpidOld = trackpid;
328 //------------------modified by Mriganka ----------------------
329 if(ks==1||(imo = mparticle->GetFirstMother())<0 ){
330 vx = mparticle->Vx();
331 vy = mparticle->Vy();
332 vz = mparticle->Vz();
334 if(trackpid==kGamma||trackpid==11||trackpid==-11||
335 trackpid==kPi0)igstatus=1;
339 while(((imo = mparticle->GetFirstMother()) >= 0)&&
340 (ks = mparticle->GetStatusCode() <1) )
342 mparticle = gAlice->GetMCApp()->Particle(imo);
343 trackpid = mparticle->GetPdgCode();
344 ks = mparticle->GetStatusCode();
345 vx = mparticle->Vx();
346 vy = mparticle->Vy();
347 vz = mparticle->Vz();
353 if(trackpid==kGamma||trackpid==11||trackpid==-11||
354 trackpid==kPi0)igstatus=1;
357 trackpid=trackpidOld;
360 //-----------------end of modification----------------
365 edep = fPMDHit->GetEnergy();
366 Int_t vol1 = fPMDHit->GetVolume(1); // Column
367 Int_t vol2 = fPMDHit->GetVolume(2); // Row
368 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
369 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
372 // -----------------------------------------//
373 // In new geometry after adding electronics //
374 // For Super Module 1 & 2 //
375 // nrow = 48, ncol = 96 //
376 // For Super Module 3 & 4 //
377 // nrow = 96, ncol = 48 //
378 // -----------------------------------------//
382 smnumber = (vol8-1)*6 + vol7;
384 if (vol8 == 1 || vol8 == 2)
389 else if (vol8 == 3 || vol8 == 4)
395 AliDebug(2,Form("Zposition = %f Edeposition = %f",zPos,edep));
396 //Float_t zposition = TMath::Abs(zPos);
402 else if (zPos > fZPos)
407 Int_t smn = smnumber - 1;
408 Int_t ixx = xpad - 1;
409 Int_t iyy = ypad - 1;
412 fPRE[smn][ixx][iyy] += edep;
413 fPRECounter[smn][ixx][iyy]++;
415 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
420 fCPV[smn][ixx][iyy] += edep;
421 fCPVCounter[smn][ixx][iyy]++;
422 AliPMDcell* cpvcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
423 fCPVCell.Add(cpvcell);
427 } // Track Loop ended
428 TrackAssignment2CPVCell();
429 TrackAssignment2Cell();
436 for (Int_t idet = 0; idet < 2; idet++)
438 for (Int_t ism = 0; ism < fgkTotUM; ism++)
440 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
442 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
446 deltaE = fPRE[ism][jrow][kcol];
447 trno = fPRETrackNo[ism][jrow][kcol];
452 deltaE = fCPV[ism][jrow][kcol];
453 trno = fCPVTrackNo[ism][jrow][kcol];
458 AddSDigit(trno,detno,ism,jrow,kcol,deltaE);
466 fPMDLoader->WriteSDigits("OVERWRITE");
469 //____________________________________________________________________________
471 void AliPMDDigitizer::Hits2Digits(Int_t ievt)
473 // This reads the PMD Hits tree and assigns the right track number
474 // to a cell and stores in the digits tree
476 const Int_t kPi0 = 111;
477 const Int_t kGamma = 22;
485 Float_t xPos, yPos, zPos;
486 Int_t xpad = -1, ypad = -1;
488 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
490 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
493 AliDebug(1,Form("Event Number = %d",ievt));
494 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
495 AliDebug(1,Form("Number of Particles = %d", nparticles));
496 fRunLoader->GetEvent(ievt);
497 // ------------------------------------------------------- //
498 // Pointer to specific detector hits.
499 // Get pointers to Alice detectors and Hits containers
501 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
502 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
504 if (fPMDLoader == 0x0)
506 AliError("Can not find PMD or PMDLoader");
508 TTree* treeH = fPMDLoader->TreeH();
509 Int_t ntracks = (Int_t) treeH->GetEntries();
510 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
511 fPMDLoader->LoadDigits("recreate");
512 TTree* treeD = fPMDLoader->TreeD();
515 fPMDLoader->MakeTree("D");
516 treeD = fPMDLoader->TreeD();
518 Int_t bufsize = 16000;
519 treeD->Branch("PMDDigit", &fDigits, bufsize);
521 TClonesArray* hits = 0;
522 if (fPMD) hits = fPMD->Hits();
524 // Start loop on tracks in the hits containers
526 for (Int_t track=0; track<ntracks;track++)
529 treeH->GetEvent(track);
533 npmd = hits->GetEntriesFast();
534 for (Int_t ipmd = 0; ipmd < npmd; ipmd++)
536 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
537 trackno = fPMDHit->GetTrack();
539 // get kinematics of the particles
541 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
542 trackpid = mparticle->GetPdgCode();
543 Int_t ks = mparticle->GetStatusCode();
545 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
546 if (mparticle->GetFirstMother() == -1)
548 tracknoOld = trackno;
549 trackpidOld = trackpid;
554 //-----------------------modified by Mriganka ------------------
555 if(ks==1||(imo = mparticle->GetFirstMother())<0 ){
556 vx = mparticle->Vx();
557 vy = mparticle->Vy();
558 vz = mparticle->Vz();
560 if(trackpid==kGamma||trackpid==11||trackpid==-11||trackpid==kPi0)
565 while(((imo = mparticle->GetFirstMother()) >= 0)&&
566 (ks = mparticle->GetStatusCode() <1) )
568 mparticle = gAlice->GetMCApp()->Particle(imo);
569 trackpid = mparticle->GetPdgCode();
570 ks = mparticle->GetStatusCode();
571 vx = mparticle->Vx();
572 vy = mparticle->Vy();
573 vz = mparticle->Vz();
579 if(trackpid==kGamma||trackpid==11||trackpid==-11||trackpid==kPi0)
583 trackpid=trackpidOld;
586 //-----------------end of modification----------------
590 edep = fPMDHit->GetEnergy();
591 Int_t vol1 = fPMDHit->GetVolume(1); // Column
592 Int_t vol2 = fPMDHit->GetVolume(2); // Row
593 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
594 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
597 // -----------------------------------------//
598 // In new geometry after adding electronics //
599 // For Super Module 1 & 2 //
600 // nrow = 48, ncol = 96 //
601 // For Super Module 3 & 4 //
602 // nrow = 96, ncol = 48 //
603 // -----------------------------------------//
605 smnumber = (vol8-1)*6 + vol7;
607 if (vol8 == 1 || vol8 == 2)
612 else if (vol8 == 3 || vol8 == 4)
618 AliDebug(2,Form("ZPosition = %f Edeposition = %d",zPos,edep));
619 //Float_t zposition = TMath::Abs(zPos);
626 else if (zPos > fZPos)
632 Int_t smn = smnumber - 1;
633 Int_t ixx = xpad - 1;
634 Int_t iyy = ypad - 1;
637 fPRE[smn][ixx][iyy] += edep;
638 fPRECounter[smn][ixx][iyy]++;
640 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
646 fCPV[smn][ixx][iyy] += edep;
647 fCPVCounter[smn][ixx][iyy]++;
648 AliPMDcell* cpvcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
649 fCPVCell.Add(cpvcell);
653 } // Track Loop ended
654 TrackAssignment2CPVCell();
655 TrackAssignment2Cell();
663 for (Int_t idet = 0; idet < 2; idet++)
665 for (Int_t ism = 0; ism < fgkTotUM; ism++)
667 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
669 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
673 deltaE = fPRE[ism][jrow][kcol];
674 trno = fPRETrackNo[ism][jrow][kcol];
679 deltaE = fCPV[ism][jrow][kcol];
680 trno = fCPVTrackNo[ism][jrow][kcol];
687 // To decalibrate the adc values
689 gain1 = Gain(idet,ism,jrow,kcol);
692 Int_t adcDecalib = (Int_t)(adc/gain1);
693 adc = (Float_t) adcDecalib;
700 // Pedestal Decalibration
702 fCalibPed->GetPedMeanRms(idet,ism,jrow,kcol);
703 Int_t pedrms1 = (Int_t) pedmeanrms%1000;
704 Float_t pedrms = (Float_t)pedrms1/10.;
706 (Float_t) (pedmeanrms - pedrms1)/1000.0;
707 //printf("%f %f\n",pedmean, pedrms);
710 adc += (pedmean + 3.0*pedrms);
711 AddDigit(trno,detno,ism,jrow,kcol,adc);
718 } // supermodule loop
721 fPMDLoader->WriteDigits("OVERWRITE");
725 //____________________________________________________________________________
728 void AliPMDDigitizer::SDigits2Digits(Int_t ievt)
730 // This reads the PMD sdigits tree and converts energy deposition
731 // in a cell to ADC and stores in the digits tree
734 fRunLoader->GetEvent(ievt);
736 TTree* treeS = fPMDLoader->TreeS();
737 AliPMDsdigit *pmdsdigit;
738 TBranch *branch = treeS->GetBranch("PMDSDigit");
741 AliError("PMD Sdigit branch does not exist");
744 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
745 branch->SetAddress(&fSDigits);
747 TTree* treeD = fPMDLoader->TreeD();
750 fPMDLoader->MakeTree("D");
751 treeD = fPMDLoader->TreeD();
753 Int_t bufsize = 16000;
754 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
755 treeD->Branch("PMDDigit", &fDigits, bufsize);
757 Int_t trno, det, smn;
761 Int_t nmodules = (Int_t) treeS->GetEntries();
762 AliDebug(1,Form("Number of modules = %d",nmodules));
764 for (Int_t imodule = 0; imodule < nmodules; imodule++)
766 treeS->GetEntry(imodule);
767 Int_t nentries = fSDigits->GetLast();
768 AliDebug(2,Form("Number of entries per module = %d",nentries+1));
769 for (Int_t ient = 0; ient < nentries+1; ient++)
771 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
772 trno = pmdsdigit->GetTrackNumber();
773 det = pmdsdigit->GetDetector();
774 smn = pmdsdigit->GetSMNumber();
775 irow = pmdsdigit->GetRow();
776 icol = pmdsdigit->GetColumn();
777 edep = pmdsdigit->GetCellEdep();
781 // To decalibrte the adc values
783 Float_t gain1 = Gain(det,smn,irow,icol);
786 Int_t adcDecalib = (Int_t)(adc/gain1);
787 adc = (Float_t) adcDecalib;
793 // Pedestal Decalibration
794 Int_t pedmeanrms = fCalibPed->GetPedMeanRms(det,smn,irow,icol);
795 Int_t pedrms1 = (Int_t) pedmeanrms%1000;
796 Float_t pedrms = (Float_t)pedrms1/10.;
797 Float_t pedmean = (Float_t) (pedmeanrms - pedrms1)/1000.0;
798 //printf("%f %f\n",pedmean, pedrms);
802 adc += (pedmean + 3.0*pedrms);
803 AddDigit(trno,det,smn,irow,icol,adc);
810 fPMDLoader->WriteDigits("OVERWRITE");
813 //____________________________________________________________________________
814 void AliPMDDigitizer::Exec(Option_t *option)
816 // Does the event merging and digitization
817 const char *cdeb = strstr(option,"deb");
820 AliDebug(100," *** PMD Exec is called ***");
823 Int_t ninputs = fManager->GetNinputs();
824 AliDebug(1,Form("Number of files to be processed = %d",ninputs));
827 for (Int_t i = 0; i < ninputs; i++)
829 Int_t troffset = fManager->GetMask(i);
830 MergeSDigits(i, troffset);
833 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
834 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
835 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
836 if (fPMDLoader == 0x0)
838 AliError("Can not find PMD or PMDLoader");
840 fPMDLoader->LoadDigits("update");
841 TTree* treeD = fPMDLoader->TreeD();
844 fPMDLoader->MakeTree("D");
845 treeD = fPMDLoader->TreeD();
847 Int_t bufsize = 16000;
848 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
849 treeD->Branch("PMDDigit", &fDigits, bufsize);
856 for (Int_t idet = 0; idet < 2; idet++)
858 for (Int_t ism = 0; ism < fgkTotUM; ism++)
860 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
862 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
866 deltaE = fPRE[ism][jrow][kcol];
867 trno = fPRETrackNo[ism][jrow][kcol];
872 deltaE = fCPV[ism][jrow][kcol];
873 trno = fCPVTrackNo[ism][jrow][kcol];
881 // Gain decalibration
883 Float_t gain1 = Gain(idet,ism,jrow,kcol);
887 Int_t adcDecalib = (Int_t)(adc/gain1);
888 adc = (Float_t) adcDecalib;
894 // Pedestal Decalibration
896 fCalibPed->GetPedMeanRms(idet,ism,jrow,kcol);
897 Int_t pedrms1 = (Int_t) pedmeanrms%1000;
898 Float_t pedrms = (Float_t)pedrms1/10.;
900 (Float_t) (pedmeanrms - pedrms1)/1000.0;
901 //printf("%f %f\n",pedmean, pedrms);
904 adc += (pedmean + 3.0*pedrms);
905 AddDigit(trno,detno,ism,jrow,kcol,adc);
913 } // supermodule loop
915 fPMDLoader->WriteDigits("OVERWRITE");
916 fPMDLoader->UnloadDigits();
919 //____________________________________________________________________________
920 void AliPMDDigitizer::TrackAssignment2CPVCell()
922 // This block assigns the cell id when there are
923 // multiple tracks in a cell according to the
925 // This method added by Ajay
926 Bool_t jsort = false;
939 cpvTrack = new Int_t ***[fgkTotUM];
940 cpvEdep = new Float_t ***[fgkTotUM];
941 for (i=0; i<fgkTotUM; i++)
943 cpvTrack[i] = new Int_t **[fgkRow];
944 cpvEdep[i] = new Float_t **[fgkRow];
947 for (i = 0; i < fgkTotUM; i++)
949 for (j = 0; j < fgkRow; j++)
951 cpvTrack[i][j] = new Int_t *[fgkCol];
952 cpvEdep[i][j] = new Float_t *[fgkCol];
955 for (i = 0; i < fgkTotUM; i++)
957 for (j = 0; j < fgkRow; j++)
959 for (k = 0; k < fgkCol; k++)
961 Int_t nn = fCPVCounter[i][j][k];
964 cpvTrack[i][j][k] = new Int_t[nn];
965 cpvEdep[i][j][k] = new Float_t[nn];
970 cpvTrack[i][j][k] = new Int_t[nn];
971 cpvEdep[i][j][k] = new Float_t[nn];
973 fCPVCounter[i][j][k] = 0;
979 Int_t nentries = fCPVCell.GetEntries();
981 Int_t mtrackno, ism, ixp, iyp;
983 for (i = 0; i < nentries; i++)
985 AliPMDcell* cpvcell = (AliPMDcell*)fCPVCell.UncheckedAt(i);
987 mtrackno = cpvcell->GetTrackNumber();
988 ism = cpvcell->GetSMNumber();
989 ixp = cpvcell->GetX();
990 iyp = cpvcell->GetY();
991 edep = cpvcell->GetEdep();
992 Int_t nn = fCPVCounter[ism][ixp][iyp];
993 cpvTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
994 cpvEdep[ism][ixp][iyp][nn] = edep;
995 fCPVCounter[ism][ixp][iyp]++;
1001 for (im=0; im<fgkTotUM; im++)
1003 for (ix=0; ix<fgkRow; ix++)
1005 for (iy=0; iy<fgkCol; iy++)
1007 nn = fCPVCounter[im][ix][iy];
1010 // This block handles if a cell is fired
1011 // many times by many tracks
1012 status1 = new Int_t[nn];
1013 status2 = new Int_t[nn];
1014 trnarray = new Int_t[nn];
1015 for (iz = 0; iz < nn; iz++)
1017 status1[iz] = cpvTrack[im][ix][iy][iz];
1019 TMath::Sort(nn,status1,status2,jsort);
1020 Int_t trackOld = -99999;
1021 Int_t track, trCount = 0;
1022 for (iz = 0; iz < nn; iz++)
1024 track = status1[status2[iz]];
1025 if (trackOld != track)
1027 trnarray[trCount] = track;
1034 Float_t totEdp = 0.;
1035 trEdp = new Float_t[trCount];
1036 fracEdp = new Float_t[trCount];
1037 for (il = 0; il < trCount; il++)
1040 track = trnarray[il];
1041 for (iz = 0; iz < nn; iz++)
1043 if (track == cpvTrack[im][ix][iy][iz])
1045 trEdp[il] += cpvEdep[im][ix][iy][iz];
1048 totEdp += trEdp[il];
1051 Float_t fracOld = 0.;
1053 for (il = 0; il < trCount; il++)
1055 fracEdp[il] = trEdp[il]/totEdp;
1056 if (fracOld < fracEdp[il])
1058 fracOld = fracEdp[il];
1062 fCPVTrackNo[im][ix][iy] = trnarray[ilOld];
1069 // This only handles if a cell is fired
1070 // by only one track
1072 fCPVTrackNo[im][ix][iy] = cpvTrack[im][ix][iy][0];
1077 // This is if no cell is fired
1078 fCPVTrackNo[im][ix][iy] = -999;
1084 // Delete all the pointers
1086 for (i = 0; i < fgkTotUM; i++)
1088 for (j = 0; j < fgkRow; j++)
1090 for (k = 0; k < fgkCol; k++)
1092 delete []cpvTrack[i][j][k];
1093 delete []cpvEdep[i][j][k];
1098 for (i = 0; i < fgkTotUM; i++)
1100 for (j = 0; j < fgkRow; j++)
1102 delete [] cpvTrack[i][j];
1103 delete [] cpvEdep[i][j];
1107 for (i = 0; i < fgkTotUM; i++)
1109 delete [] cpvTrack[i];
1110 delete [] cpvEdep[i];
1116 // End of the cell id assignment
1119 //____________________________________________________________________________
1121 void AliPMDDigitizer::MergeSDigits(Int_t filenumber, Int_t troffset)
1124 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(filenumber));
1125 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
1126 fPMDLoader->LoadSDigits("read");
1127 TTree* treeS = fPMDLoader->TreeS();
1128 AliPMDsdigit *pmdsdigit;
1129 TBranch *branch = treeS->GetBranch("PMDSDigit");
1130 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
1131 branch->SetAddress(&fSDigits);
1133 Int_t itrackno, idet, ism;
1136 Int_t nmodules = (Int_t) treeS->GetEntries();
1137 AliDebug(1,Form("Number of Modules in the treeS = %d",nmodules));
1138 AliDebug(1,Form("Track Offset = %d",troffset));
1139 for (Int_t imodule = 0; imodule < nmodules; imodule++)
1141 treeS->GetEntry(imodule);
1142 Int_t nentries = fSDigits->GetLast();
1143 AliDebug(2,Form("Number of Entries per Module = %d",nentries));
1144 for (Int_t ient = 0; ient < nentries+1; ient++)
1146 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
1147 itrackno = pmdsdigit->GetTrackNumber();
1148 idet = pmdsdigit->GetDetector();
1149 ism = pmdsdigit->GetSMNumber();
1150 ixp = pmdsdigit->GetRow();
1151 iyp = pmdsdigit->GetColumn();
1152 edep = pmdsdigit->GetCellEdep();
1155 if (fPRE[ism][ixp][iyp] < edep)
1157 fPRETrackNo[ism][ixp][iyp] = troffset + itrackno;
1159 fPRE[ism][ixp][iyp] += edep;
1163 if (fCPV[ism][ixp][iyp] < edep)
1165 fCPVTrackNo[ism][ixp][iyp] = troffset + itrackno;
1167 fCPV[ism][ixp][iyp] += edep;
1173 // ----------------------------------------------------------------------
1174 void AliPMDDigitizer::TrackAssignment2Cell()
1177 // This block assigns the cell id when there are
1178 // multiple tracks in a cell according to the
1179 // energy deposition
1181 Bool_t jsort = false;
1192 Float_t ****pmdEdep;
1194 pmdTrack = new Int_t ***[fgkTotUM];
1195 pmdEdep = new Float_t ***[fgkTotUM];
1196 for (i=0; i<fgkTotUM; i++)
1198 pmdTrack[i] = new Int_t **[fgkRow];
1199 pmdEdep[i] = new Float_t **[fgkRow];
1202 for (i = 0; i < fgkTotUM; i++)
1204 for (j = 0; j < fgkRow; j++)
1206 pmdTrack[i][j] = new Int_t *[fgkCol];
1207 pmdEdep[i][j] = new Float_t *[fgkCol];
1211 for (i = 0; i < fgkTotUM; i++)
1213 for (j = 0; j < fgkRow; j++)
1215 for (k = 0; k < fgkCol; k++)
1217 Int_t nn = fPRECounter[i][j][k];
1220 pmdTrack[i][j][k] = new Int_t[nn];
1221 pmdEdep[i][j][k] = new Float_t[nn];
1226 pmdTrack[i][j][k] = new Int_t[nn];
1227 pmdEdep[i][j][k] = new Float_t[nn];
1229 fPRECounter[i][j][k] = 0;
1235 Int_t nentries = fCell.GetEntries();
1237 Int_t mtrackno, ism, ixp, iyp;
1240 for (i = 0; i < nentries; i++)
1242 AliPMDcell* cell = (AliPMDcell*)fCell.UncheckedAt(i);
1244 mtrackno = cell->GetTrackNumber();
1245 ism = cell->GetSMNumber();
1248 edep = cell->GetEdep();
1249 Int_t nn = fPRECounter[ism][ixp][iyp];
1250 pmdTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
1251 pmdEdep[ism][ixp][iyp][nn] = edep;
1252 fPRECounter[ism][ixp][iyp]++;
1259 for (im=0; im<fgkTotUM; im++)
1261 for (ix=0; ix<fgkRow; ix++)
1263 for (iy=0; iy<fgkCol; iy++)
1265 nn = fPRECounter[im][ix][iy];
1268 // This block handles if a cell is fired
1269 // many times by many tracks
1270 status1 = new Int_t[nn];
1271 status2 = new Int_t[nn];
1272 trnarray = new Int_t[nn];
1273 for (iz = 0; iz < nn; iz++)
1275 status1[iz] = pmdTrack[im][ix][iy][iz];
1277 TMath::Sort(nn,status1,status2,jsort);
1278 Int_t trackOld = -99999;
1279 Int_t track, trCount = 0;
1280 for (iz = 0; iz < nn; iz++)
1282 track = status1[status2[iz]];
1283 if (trackOld != track)
1285 trnarray[trCount] = track;
1292 Float_t totEdp = 0.;
1293 trEdp = new Float_t[trCount];
1294 fracEdp = new Float_t[trCount];
1295 for (il = 0; il < trCount; il++)
1298 track = trnarray[il];
1299 for (iz = 0; iz < nn; iz++)
1301 if (track == pmdTrack[im][ix][iy][iz])
1303 trEdp[il] += pmdEdep[im][ix][iy][iz];
1306 totEdp += trEdp[il];
1309 Float_t fracOld = 0.;
1311 for (il = 0; il < trCount; il++)
1313 fracEdp[il] = trEdp[il]/totEdp;
1314 if (fracOld < fracEdp[il])
1316 fracOld = fracEdp[il];
1320 fPRETrackNo[im][ix][iy] = trnarray[ilOld];
1327 // This only handles if a cell is fired
1328 // by only one track
1330 fPRETrackNo[im][ix][iy] = pmdTrack[im][ix][iy][0];
1335 // This is if no cell is fired
1336 fPRETrackNo[im][ix][iy] = -999;
1342 // Delete all the pointers
1344 for (i = 0; i < fgkTotUM; i++)
1346 for (j = 0; j < fgkRow; j++)
1348 for (k = 0; k < fgkCol; k++)
1350 delete [] pmdTrack[i][j][k];
1351 delete [] pmdEdep[i][j][k];
1356 for (i = 0; i < fgkTotUM; i++)
1358 for (j = 0; j < fgkRow; j++)
1360 delete [] pmdTrack[i][j];
1361 delete [] pmdEdep[i][j];
1365 for (i = 0; i < fgkTotUM; i++)
1367 delete [] pmdTrack[i];
1368 delete [] pmdEdep[i];
1373 // End of the cell id assignment
1376 //____________________________________________________________________________
1377 void AliPMDDigitizer::MeV2ADC(Float_t mev, Float_t & adc) const
1379 // This converts the simulated edep to ADC according to the
1381 //PS Test in September 2003 and 2006
1382 // KeV - ADC conversion for 12bit ADC
1385 const Float_t kConstant = 0.07;
1386 const Float_t kErConstant = 0.1;
1387 const Float_t kSlope = 76.0;
1388 const Float_t kErSlope = 5.0;
1390 Float_t cons = gRandom->Gaus(kConstant,kErConstant);
1391 Float_t slop = gRandom->Gaus(kSlope,kErSlope);
1393 Float_t adc12bit = slop*mev*0.001 + cons;
1396 if(adc12bit < 1600.0)
1398 adc = (Float_t) adc12bit;
1400 else if (adc12bit >= 1600.0)
1405 //____________________________________________________________________________
1406 void AliPMDDigitizer::AddSDigit(Int_t trnumber, Int_t det, Int_t smnumber,
1407 Int_t irow, Int_t icol, Float_t adc)
1411 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
1412 TClonesArray &lsdigits = *fSDigits;
1413 new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,det,smnumber,irow,icol,adc);
1415 //____________________________________________________________________________
1417 void AliPMDDigitizer::AddDigit(Int_t trnumber, Int_t det, Int_t smnumber,
1418 Int_t irow, Int_t icol, Float_t adc)
1422 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
1423 TClonesArray &ldigits = *fDigits;
1424 new(ldigits[fNdigit++]) AliPMDdigit(trnumber,det,smnumber,irow,icol,adc);
1426 //____________________________________________________________________________
1428 void AliPMDDigitizer::SetZPosition(Float_t zpos)
1432 //____________________________________________________________________________
1433 Float_t AliPMDDigitizer::GetZPosition() const
1437 //____________________________________________________________________________
1439 void AliPMDDigitizer::ResetCell()
1441 // clears the cell array and also the counter
1446 for (Int_t i = 0; i < fgkTotUM; i++)
1448 for (Int_t j = 0; j < fgkRow; j++)
1450 for (Int_t k = 0; k < fgkCol; k++)
1452 fCPVCounter[i][j][k] = 0;
1453 fPRECounter[i][j][k] = 0;
1458 //____________________________________________________________________________
1459 void AliPMDDigitizer::ResetSDigit()
1463 if (fSDigits) fSDigits->Delete();
1465 //____________________________________________________________________________
1466 void AliPMDDigitizer::ResetDigit()
1470 if (fDigits) fDigits->Delete();
1472 //____________________________________________________________________________
1474 void AliPMDDigitizer::ResetCellADC()
1476 // Clears individual cells edep and track number
1477 for (Int_t i = 0; i < fgkTotUM; i++)
1479 for (Int_t j = 0; j < fgkRow; j++)
1481 for (Int_t k = 0; k < fgkCol; k++)
1485 fCPVTrackNo[i][j][k] = 0;
1486 fPRETrackNo[i][j][k] = 0;
1491 //____________________________________________________________________________
1493 void AliPMDDigitizer::UnLoad(Option_t *option)
1495 // Unloads all the root files
1497 const char *cS = strstr(option,"S");
1498 const char *cD = strstr(option,"D");
1500 fRunLoader->UnloadgAlice();
1501 fRunLoader->UnloadHeader();
1502 fRunLoader->UnloadKinematics();
1506 fPMDLoader->UnloadHits();
1510 fPMDLoader->UnloadHits();
1511 fPMDLoader->UnloadSDigits();
1515 //----------------------------------------------------------------------
1516 Float_t AliPMDDigitizer::Gain(Int_t det, Int_t smn, Int_t row, Int_t col) const
1518 // returns of the gain of the cell
1519 // Added this method by ZA
1521 //cout<<" I am here in gain "<<fCalibData<< "smn,row, col "<<smn
1522 //<<" "<<row<<" "<<col<<endl;
1525 AliError("No calibration data loaded from CDB!!!");
1530 GainFact = fCalibGain->GetGainFact(det,smn,row,col);
1533 //----------------------------------------------------------------------
1534 AliPMDCalibData* AliPMDDigitizer::GetCalibGain() const
1536 // The run number will be centralized in AliCDBManager,
1537 // you don't need to set it here!
1538 // Added this method by ZA
1539 // Cleaned up by Alberto
1540 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Gain");
1542 if(!entry) AliFatal("Calibration object retrieval failed!");
1544 AliPMDCalibData *calibdata=0;
1545 if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
1547 if (!calibdata) AliFatal("No calibration data from calibration database !");
1551 //----------------------------------------------------------------------
1552 AliPMDPedestal* AliPMDDigitizer::GetCalibPed() const
1554 // The run number will be centralized in AliCDBManager,
1555 // you don't need to set it here!
1557 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Ped");
1559 if(!entry) AliFatal("Pedestal object retrieval failed!");
1561 AliPMDPedestal *pedestal=0;
1562 if (entry) pedestal = (AliPMDPedestal*) entry->GetObject();
1564 if (!pedestal) AliFatal("No pedestal data from calibration database !");