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>
25 #include <TObjArray.h>
26 #include <TClonesArray.h>
29 #include <TParticle.h>
35 #include "AliDetector.h"
36 #include "AliRunLoader.h"
37 #include "AliLoader.h"
38 #include "AliConfig.h"
40 #include "AliRunDigitizer.h"
41 #include "AliDigitizer.h"
42 #include "AliHeader.h"
43 #include "AliCDBManager.h"
44 #include "AliCDBStorage.h"
45 #include "AliCDBEntry.h"
49 #include "AliPMDhit.h"
50 #include "AliPMDcell.h"
51 #include "AliPMDsdigit.h"
52 #include "AliPMDdigit.h"
53 #include "AliPMDCalibData.h"
54 #include "AliPMDPedestal.h"
55 #include "AliPMDDigitizer.h"
58 ClassImp(AliPMDDigitizer)
60 AliPMDDigitizer::AliPMDDigitizer() :
65 fCalibGain(GetCalibGain()),
66 fCalibPed(GetCalibPed()),
74 fZPos(361.5) // in units of cm, default position of PMD
76 // Default Constructor
78 for (Int_t i = 0; i < fgkTotUM; i++)
80 for (Int_t j = 0; j < fgkRow; j++)
82 for (Int_t k = 0; k < fgkCol; k++)
86 fCPVCounter[i][j][k] = 0;
87 fPRECounter[i][j][k] = 0;
88 fCPVTrackNo[i][j][k] = -1;
89 fPRETrackNo[i][j][k] = -1;
95 //____________________________________________________________________________
96 AliPMDDigitizer::AliPMDDigitizer(const AliPMDDigitizer& digitizer):
97 AliDigitizer(digitizer),
102 fCalibGain(GetCalibGain()),
103 fCalibPed(GetCalibPed()),
111 fZPos(361.5) // in units of cm, default position of PMD
114 AliError("Copy constructor not allowed ");
117 //____________________________________________________________________________
118 AliPMDDigitizer & AliPMDDigitizer::operator=(const AliPMDDigitizer& /*digitizer*/)
120 // Assignment operator
121 AliError("Assignement operator not allowed ");
125 //____________________________________________________________________________
126 AliPMDDigitizer::AliPMDDigitizer(AliRunDigitizer* manager):
127 AliDigitizer(manager),
132 fCalibGain(GetCalibGain()),
133 fCalibPed(GetCalibPed()),
134 fSDigits(new TClonesArray("AliPMDsdigit", 1000)),
135 fDigits(new TClonesArray("AliPMDdigit", 1000)),
141 fZPos(361.5)// in units of cm, This is the default position of PMD
143 // ctor which should be used
146 for (Int_t i = 0; i < fgkTotUM; i++)
148 for (Int_t j = 0; j < fgkRow; j++)
150 for (Int_t k = 0; k < fgkCol; k++)
154 fCPVCounter[i][j][k] = 0;
155 fPRECounter[i][j][k] = 0;
156 fCPVTrackNo[i][j][k] = -1;
157 fPRETrackNo[i][j][k] = -1;
163 //____________________________________________________________________________
164 AliPMDDigitizer::~AliPMDDigitizer()
166 // Default Destructor
184 //____________________________________________________________________________
185 void AliPMDDigitizer::OpengAliceFile(const char *file, Option_t *option)
187 // Loads galice.root file and corresponding header, kinematics
188 // hits and sdigits or digits depending on the option
191 TString evfoldname = AliConfig::GetDefaultEventFolderName();
192 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
194 fRunLoader = AliRunLoader::Open(file,AliConfig::GetDefaultEventFolderName(), "UPDATE");
198 AliError(Form("Can not open session for file %s.",file));
201 const char *cHS = strstr(option,"HS");
202 const char *cHD = strstr(option,"HD");
203 const char *cSD = strstr(option,"SD");
207 if (!fRunLoader->GetAliRun()) fRunLoader->LoadgAlice();
208 if (!fRunLoader->TreeE()) fRunLoader->LoadHeader();
209 if (!fRunLoader->TreeK()) fRunLoader->LoadKinematics();
211 gAlice = fRunLoader->GetAliRun();
215 AliDebug(1,"Alirun object found");
219 AliError("Could not found Alirun object");
222 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
225 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
226 if (fPMDLoader == 0x0)
228 AliError("Can not find PMDLoader");
234 fPMDLoader->LoadHits("READ");
235 fPMDLoader->LoadSDigits("recreate");
239 fPMDLoader->LoadHits("READ");
240 fPMDLoader->LoadDigits("recreate");
244 fPMDLoader->LoadSDigits("READ");
245 fPMDLoader->LoadDigits("recreate");
248 //____________________________________________________________________________
249 void AliPMDDigitizer::Hits2SDigits(Int_t ievt)
251 // This reads the PMD Hits tree and assigns the right track number
252 // to a cell and stores in the summable digits tree
255 const Int_t kPi0 = 111;
256 const Int_t kGamma = 22;
264 Float_t xPos, yPos, zPos;
265 Int_t xpad = -1, ypad = -1;
267 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
270 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
273 AliDebug(1,Form("Event Number = %d",ievt));
274 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
275 AliDebug(1,Form("Number of Particles = %d",nparticles));
276 fRunLoader->GetEvent(ievt);
277 // ------------------------------------------------------- //
278 // Pointer to specific detector hits.
279 // Get pointers to Alice detectors and Hits containers
281 TTree* treeH = fPMDLoader->TreeH();
283 Int_t ntracks = (Int_t) treeH->GetEntries();
284 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
285 TTree* treeS = fPMDLoader->TreeS();
288 fPMDLoader->MakeTree("S");
289 treeS = fPMDLoader->TreeS();
291 Int_t bufsize = 16000;
292 treeS->Branch("PMDSDigit", &fSDigits, bufsize);
294 TClonesArray* hits = 0;
295 if (fPMD) hits = fPMD->Hits();
297 // Start loop on tracks in the hits containers
299 for (Int_t track=0; track<ntracks;track++)
301 gAlice->GetMCApp()->ResetHits();
302 treeH->GetEvent(track);
305 npmd = hits->GetEntriesFast();
306 for (Int_t ipmd = 0; ipmd < npmd; ipmd++)
308 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
309 trackno = fPMDHit->GetTrack();
310 // get kinematics of the particles
312 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
313 trackpid = mparticle->GetPdgCode();
314 Int_t ks = mparticle->GetStatusCode();
316 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
318 if (mparticle->GetFirstMother() == -1)
320 tracknoOld = trackno;
321 trackpidOld = trackpid;
325 //------------------modified by Mriganka ----------------------
326 Int_t trnotemp = trackno;
328 if(ks==1||(imo = mparticle->GetFirstMother())<0 ){
329 vx = mparticle->Vx();
330 vy = mparticle->Vy();
331 vz = mparticle->Vz();
333 if(trackpid==kGamma||trackpid==11||trackpid==-11||
334 trackpid==kPi0)igstatus=1;
336 while(((imo = mparticle->GetFirstMother()) >= 0)&&
337 (ks = mparticle->GetStatusCode() <1) )
339 mparticle = gAlice->GetMCApp()->Particle(imo);
340 trackpid = mparticle->GetPdgCode();
341 ks = mparticle->GetStatusCode();
342 vx = mparticle->Vx();
343 vy = mparticle->Vy();
344 vz = mparticle->Vz();
356 if(trackpid==kGamma||trackpid==11||trackpid==-11||
357 trackpid==kPi0)igstatus=1;
360 trackpid=trackpidOld;
362 //-----------------end of modification----------------
368 edep = fPMDHit->GetEnergy();
369 Int_t vol1 = fPMDHit->GetVolume(1); // Column
370 Int_t vol2 = fPMDHit->GetVolume(2); // Row
371 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
372 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
375 // -----------------------------------------//
376 // In new geometry after adding electronics //
377 // For Super Module 1 & 2 //
378 // nrow = 48, ncol = 96 //
379 // For Super Module 3 & 4 //
380 // nrow = 96, ncol = 48 //
381 // -----------------------------------------//
385 smnumber = (vol8-1)*6 + vol7;
387 if (vol8 == 1 || vol8 == 2)
392 else if (vol8 == 3 || vol8 == 4)
398 AliDebug(2,Form("Zposition = %f Edeposition = %f",zPos,edep));
399 //Float_t zposition = TMath::Abs(zPos);
405 else if (zPos > fZPos)
410 Int_t smn = smnumber - 1;
411 Int_t ixx = xpad - 1;
412 Int_t iyy = ypad - 1;
415 fPRE[smn][ixx][iyy] += edep;
416 fPRECounter[smn][ixx][iyy]++;
418 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
423 fCPV[smn][ixx][iyy] += edep;
424 fCPVCounter[smn][ixx][iyy]++;
425 AliPMDcell* cpvcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
426 fCPVCell.Add(cpvcell);
430 } // Track Loop ended
431 TrackAssignment2CPVCell();
432 TrackAssignment2Cell();
439 for (Int_t idet = 0; idet < 2; idet++)
441 for (Int_t ism = 0; ism < fgkTotUM; ism++)
443 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
445 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
449 deltaE = fPRE[ism][jrow][kcol];
450 trno = fPRETrackNo[ism][jrow][kcol];
455 deltaE = fCPV[ism][jrow][kcol];
456 trno = fCPVTrackNo[ism][jrow][kcol];
461 AddSDigit(trno,detno,ism,jrow,kcol,deltaE);
469 fPMDLoader->WriteSDigits("OVERWRITE");
472 //____________________________________________________________________________
474 void AliPMDDigitizer::Hits2Digits(Int_t ievt)
476 // This reads the PMD Hits tree and assigns the right track number
477 // to a cell and stores in the digits tree
479 const Int_t kPi0 = 111;
480 const Int_t kGamma = 22;
488 Float_t xPos, yPos, zPos;
489 Int_t xpad = -1, ypad = -1;
491 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
493 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
496 AliDebug(1,Form("Event Number = %d",ievt));
497 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
498 AliDebug(1,Form("Number of Particles = %d", nparticles));
499 fRunLoader->GetEvent(ievt);
500 // ------------------------------------------------------- //
501 // Pointer to specific detector hits.
502 // Get pointers to Alice detectors and Hits containers
504 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
505 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
507 if (fPMDLoader == 0x0)
509 AliError("Can not find PMD or PMDLoader");
511 TTree* treeH = fPMDLoader->TreeH();
512 Int_t ntracks = (Int_t) treeH->GetEntries();
513 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
514 fPMDLoader->LoadDigits("recreate");
515 TTree* treeD = fPMDLoader->TreeD();
518 fPMDLoader->MakeTree("D");
519 treeD = fPMDLoader->TreeD();
521 Int_t bufsize = 16000;
522 treeD->Branch("PMDDigit", &fDigits, bufsize);
524 TClonesArray* hits = 0;
525 if (fPMD) hits = fPMD->Hits();
527 // Start loop on tracks in the hits containers
529 for (Int_t track=0; track<ntracks;track++)
531 gAlice->GetMCApp()->ResetHits();
532 treeH->GetEvent(track);
536 npmd = hits->GetEntriesFast();
537 for (Int_t ipmd = 0; ipmd < npmd; ipmd++)
539 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
540 trackno = fPMDHit->GetTrack();
542 // get kinematics of the particles
544 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
545 trackpid = mparticle->GetPdgCode();
546 Int_t ks = mparticle->GetStatusCode();
548 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
549 if (mparticle->GetFirstMother() == -1)
551 tracknoOld = trackno;
552 trackpidOld = trackpid;
557 //-----------------------modified by Mriganka ------------------
558 Int_t trnotemp = trackno;
559 if(ks==1||(imo = mparticle->GetFirstMother())<0 ){
560 vx = mparticle->Vx();
561 vy = mparticle->Vy();
562 vz = mparticle->Vz();
564 if(trackpid==kGamma||trackpid==11||trackpid==-11||trackpid==kPi0)
569 while(((imo = mparticle->GetFirstMother()) >= 0)&&
570 (ks = mparticle->GetStatusCode() <1) )
572 mparticle = gAlice->GetMCApp()->Particle(imo);
573 trackpid = mparticle->GetPdgCode();
574 ks = mparticle->GetStatusCode();
575 vx = mparticle->Vx();
576 vy = mparticle->Vy();
577 vz = mparticle->Vz();
589 if(trackpid==kGamma||trackpid==11||trackpid==-11||trackpid==kPi0)
593 trackpid=trackpidOld;
596 //-----------------end of modification----------------
600 edep = fPMDHit->GetEnergy();
601 Int_t vol1 = fPMDHit->GetVolume(1); // Column
602 Int_t vol2 = fPMDHit->GetVolume(2); // Row
603 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
604 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
607 // -----------------------------------------//
608 // In new geometry after adding electronics //
609 // For Super Module 1 & 2 //
610 // nrow = 48, ncol = 96 //
611 // For Super Module 3 & 4 //
612 // nrow = 96, ncol = 48 //
613 // -----------------------------------------//
615 smnumber = (vol8-1)*6 + vol7;
617 if (vol8 == 1 || vol8 == 2)
622 else if (vol8 == 3 || vol8 == 4)
628 AliDebug(2,Form("ZPosition = %f Edeposition = %d",zPos,edep));
629 //Float_t zposition = TMath::Abs(zPos);
636 else if (zPos > fZPos)
642 Int_t smn = smnumber - 1;
643 Int_t ixx = xpad - 1;
644 Int_t iyy = ypad - 1;
647 fPRE[smn][ixx][iyy] += edep;
648 fPRECounter[smn][ixx][iyy]++;
650 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
656 fCPV[smn][ixx][iyy] += edep;
657 fCPVCounter[smn][ixx][iyy]++;
658 AliPMDcell* cpvcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
659 fCPVCell.Add(cpvcell);
663 } // Track Loop ended
664 TrackAssignment2CPVCell();
665 TrackAssignment2Cell();
673 for (Int_t idet = 0; idet < 2; idet++)
675 for (Int_t ism = 0; ism < fgkTotUM; ism++)
677 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
679 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
683 deltaE = fPRE[ism][jrow][kcol];
684 trno = fPRETrackNo[ism][jrow][kcol];
689 deltaE = fCPV[ism][jrow][kcol];
690 trno = fCPVTrackNo[ism][jrow][kcol];
697 // To decalibrate the adc values
699 gain1 = Gain(idet,ism,jrow,kcol);
702 Int_t adcDecalib = (Int_t)(adc/gain1);
703 adc = (Float_t) adcDecalib;
710 // Pedestal Decalibration
712 fCalibPed->GetPedMeanRms(idet,ism,jrow,kcol);
713 Int_t pedrms1 = (Int_t) pedmeanrms%100;
714 Float_t pedrms = (Float_t)pedrms1/10.;
716 (Float_t) (pedmeanrms - pedrms1)/1000.0;
719 adc += (pedmean + 3.0*pedrms);
720 AddDigit(trno,detno,ism,jrow,kcol,adc);
727 } // supermodule loop
730 fPMDLoader->WriteDigits("OVERWRITE");
734 //____________________________________________________________________________
737 void AliPMDDigitizer::SDigits2Digits(Int_t ievt)
739 // This reads the PMD sdigits tree and converts energy deposition
740 // in a cell to ADC and stores in the digits tree
743 fRunLoader->GetEvent(ievt);
745 TTree* treeS = fPMDLoader->TreeS();
746 AliPMDsdigit *pmdsdigit;
747 TBranch *branch = treeS->GetBranch("PMDSDigit");
750 AliError("PMD Sdigit branch does not exist");
753 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
754 branch->SetAddress(&fSDigits);
756 TTree* treeD = fPMDLoader->TreeD();
759 fPMDLoader->MakeTree("D");
760 treeD = fPMDLoader->TreeD();
762 Int_t bufsize = 16000;
763 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
764 treeD->Branch("PMDDigit", &fDigits, bufsize);
766 Int_t trno, det, smn;
770 Int_t nmodules = (Int_t) treeS->GetEntries();
771 AliDebug(1,Form("Number of modules = %d",nmodules));
773 for (Int_t imodule = 0; imodule < nmodules; imodule++)
775 treeS->GetEntry(imodule);
776 Int_t nentries = fSDigits->GetLast();
777 AliDebug(2,Form("Number of entries per module = %d",nentries+1));
778 for (Int_t ient = 0; ient < nentries+1; ient++)
780 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
781 trno = pmdsdigit->GetTrackNumber();
782 det = pmdsdigit->GetDetector();
783 smn = pmdsdigit->GetSMNumber();
784 irow = pmdsdigit->GetRow();
785 icol = pmdsdigit->GetColumn();
786 edep = pmdsdigit->GetCellEdep();
790 // To decalibrte the adc values
792 Float_t gain1 = Gain(det,smn,irow,icol);
795 Int_t adcDecalib = (Int_t)(adc/gain1);
796 adc = (Float_t) adcDecalib;
802 // Pedestal Decalibration
803 Int_t pedmeanrms = fCalibPed->GetPedMeanRms(det,smn,irow,icol);
804 Int_t pedrms1 = (Int_t) pedmeanrms%100;
805 Float_t pedrms = (Float_t)pedrms1/10.;
806 Float_t pedmean = (Float_t) (pedmeanrms - pedrms1)/1000.0;
809 adc += (pedmean + 3.0*pedrms);
810 AddDigit(trno,det,smn,irow,icol,adc);
817 fPMDLoader->WriteDigits("OVERWRITE");
820 //____________________________________________________________________________
821 void AliPMDDigitizer::Exec(Option_t *option)
823 // Does the event merging and digitization
824 const char *cdeb = strstr(option,"deb");
827 AliDebug(100," *** PMD Exec is called ***");
830 Int_t ninputs = fManager->GetNinputs();
831 AliDebug(1,Form("Number of files to be processed = %d",ninputs));
834 for (Int_t i = 0; i < ninputs; i++)
836 Int_t troffset = fManager->GetMask(i);
837 MergeSDigits(i, troffset);
840 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
841 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
842 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
843 if (fPMDLoader == 0x0)
845 AliError("Can not find PMD or PMDLoader");
847 fPMDLoader->LoadDigits("update");
848 TTree* treeD = fPMDLoader->TreeD();
851 fPMDLoader->MakeTree("D");
852 treeD = fPMDLoader->TreeD();
854 Int_t bufsize = 16000;
855 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
856 treeD->Branch("PMDDigit", &fDigits, bufsize);
863 for (Int_t idet = 0; idet < 2; idet++)
865 for (Int_t ism = 0; ism < fgkTotUM; ism++)
867 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
869 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
873 deltaE = fPRE[ism][jrow][kcol];
874 trno = fPRETrackNo[ism][jrow][kcol];
879 deltaE = fCPV[ism][jrow][kcol];
880 trno = fCPVTrackNo[ism][jrow][kcol];
888 // Gain decalibration
890 Float_t gain1 = Gain(idet,ism,jrow,kcol);
894 Int_t adcDecalib = (Int_t)(adc/gain1);
895 adc = (Float_t) adcDecalib;
901 // Pedestal Decalibration
903 fCalibPed->GetPedMeanRms(idet,ism,jrow,kcol);
904 Int_t pedrms1 = (Int_t) pedmeanrms%100;
905 Float_t pedrms = (Float_t)pedrms1/10.;
907 (Float_t) (pedmeanrms - pedrms1)/1000.0;
910 adc += (pedmean + 3.0*pedrms);
911 AddDigit(trno,detno,ism,jrow,kcol,adc);
919 } // supermodule loop
921 fPMDLoader->WriteDigits("OVERWRITE");
922 fPMDLoader->UnloadDigits();
925 //____________________________________________________________________________
926 void AliPMDDigitizer::TrackAssignment2CPVCell()
928 // This block assigns the cell id when there are
929 // multiple tracks in a cell according to the
931 // This method added by Ajay
932 Bool_t jsort = false;
945 cpvTrack = new Int_t ***[fgkTotUM];
946 cpvEdep = new Float_t ***[fgkTotUM];
947 for (i=0; i<fgkTotUM; i++)
949 cpvTrack[i] = new Int_t **[fgkRow];
950 cpvEdep[i] = new Float_t **[fgkRow];
953 for (i = 0; i < fgkTotUM; i++)
955 for (j = 0; j < fgkRow; j++)
957 cpvTrack[i][j] = new Int_t *[fgkCol];
958 cpvEdep[i][j] = new Float_t *[fgkCol];
961 for (i = 0; i < fgkTotUM; i++)
963 for (j = 0; j < fgkRow; j++)
965 for (k = 0; k < fgkCol; k++)
967 Int_t nn = fCPVCounter[i][j][k];
970 cpvTrack[i][j][k] = new Int_t[nn];
971 cpvEdep[i][j][k] = new Float_t[nn];
976 cpvTrack[i][j][k] = new Int_t[nn];
977 cpvEdep[i][j][k] = new Float_t[nn];
979 fCPVCounter[i][j][k] = 0;
985 Int_t nentries = fCPVCell.GetEntries();
987 Int_t mtrackno, ism, ixp, iyp;
989 for (i = 0; i < nentries; i++)
991 AliPMDcell* cpvcell = (AliPMDcell*)fCPVCell.UncheckedAt(i);
993 mtrackno = cpvcell->GetTrackNumber();
994 ism = cpvcell->GetSMNumber();
995 ixp = cpvcell->GetX();
996 iyp = cpvcell->GetY();
997 edep = cpvcell->GetEdep();
998 Int_t nn = fCPVCounter[ism][ixp][iyp];
999 cpvTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
1000 cpvEdep[ism][ixp][iyp][nn] = edep;
1001 fCPVCounter[ism][ixp][iyp]++;
1007 for (im=0; im<fgkTotUM; im++)
1009 for (ix=0; ix<fgkRow; ix++)
1011 for (iy=0; iy<fgkCol; iy++)
1013 nn = fCPVCounter[im][ix][iy];
1016 // This block handles if a cell is fired
1017 // many times by many tracks
1018 status1 = new Int_t[nn];
1019 status2 = new Int_t[nn];
1020 trnarray = new Int_t[nn];
1021 for (iz = 0; iz < nn; iz++)
1023 status1[iz] = cpvTrack[im][ix][iy][iz];
1025 TMath::Sort(nn,status1,status2,jsort);
1026 Int_t trackOld = -99999;
1027 Int_t track, trCount = 0;
1028 for (iz = 0; iz < nn; iz++)
1030 track = status1[status2[iz]];
1031 if (trackOld != track)
1033 trnarray[trCount] = track;
1040 Float_t totEdp = 0.;
1041 trEdp = new Float_t[trCount];
1042 fracEdp = new Float_t[trCount];
1043 for (il = 0; il < trCount; il++)
1046 track = trnarray[il];
1047 for (iz = 0; iz < nn; iz++)
1049 if (track == cpvTrack[im][ix][iy][iz])
1051 trEdp[il] += cpvEdep[im][ix][iy][iz];
1054 totEdp += trEdp[il];
1057 Float_t fracOld = 0.;
1059 for (il = 0; il < trCount; il++)
1061 fracEdp[il] = trEdp[il]/totEdp;
1062 if (fracOld < fracEdp[il])
1064 fracOld = fracEdp[il];
1068 fCPVTrackNo[im][ix][iy] = trnarray[ilOld];
1075 // This only handles if a cell is fired
1076 // by only one track
1078 fCPVTrackNo[im][ix][iy] = cpvTrack[im][ix][iy][0];
1083 // This is if no cell is fired
1084 fCPVTrackNo[im][ix][iy] = -999;
1090 // Delete all the pointers
1092 for (i = 0; i < fgkTotUM; i++)
1094 for (j = 0; j < fgkRow; j++)
1096 for (k = 0; k < fgkCol; k++)
1098 delete []cpvTrack[i][j][k];
1099 delete []cpvEdep[i][j][k];
1104 for (i = 0; i < fgkTotUM; i++)
1106 for (j = 0; j < fgkRow; j++)
1108 delete [] cpvTrack[i][j];
1109 delete [] cpvEdep[i][j];
1113 for (i = 0; i < fgkTotUM; i++)
1115 delete [] cpvTrack[i];
1116 delete [] cpvEdep[i];
1122 // End of the cell id assignment
1125 //____________________________________________________________________________
1127 void AliPMDDigitizer::MergeSDigits(Int_t filenumber, Int_t troffset)
1130 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(filenumber));
1131 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
1132 fPMDLoader->LoadSDigits("read");
1133 TTree* treeS = fPMDLoader->TreeS();
1134 AliPMDsdigit *pmdsdigit;
1135 TBranch *branch = treeS->GetBranch("PMDSDigit");
1136 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
1137 branch->SetAddress(&fSDigits);
1139 Int_t itrackno, idet, ism;
1142 Int_t nmodules = (Int_t) treeS->GetEntries();
1143 AliDebug(1,Form("Number of Modules in the treeS = %d",nmodules));
1144 AliDebug(1,Form("Track Offset = %d",troffset));
1145 for (Int_t imodule = 0; imodule < nmodules; imodule++)
1147 treeS->GetEntry(imodule);
1148 Int_t nentries = fSDigits->GetLast();
1149 AliDebug(2,Form("Number of Entries per Module = %d",nentries));
1150 for (Int_t ient = 0; ient < nentries+1; ient++)
1152 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
1153 itrackno = pmdsdigit->GetTrackNumber();
1154 idet = pmdsdigit->GetDetector();
1155 ism = pmdsdigit->GetSMNumber();
1156 ixp = pmdsdigit->GetRow();
1157 iyp = pmdsdigit->GetColumn();
1158 edep = pmdsdigit->GetCellEdep();
1161 if (fPRE[ism][ixp][iyp] < edep)
1163 fPRETrackNo[ism][ixp][iyp] = troffset + itrackno;
1165 fPRE[ism][ixp][iyp] += edep;
1169 if (fCPV[ism][ixp][iyp] < edep)
1171 fCPVTrackNo[ism][ixp][iyp] = troffset + itrackno;
1173 fCPV[ism][ixp][iyp] += edep;
1179 // ----------------------------------------------------------------------
1180 void AliPMDDigitizer::TrackAssignment2Cell()
1183 // This block assigns the cell id when there are
1184 // multiple tracks in a cell according to the
1185 // energy deposition
1187 Bool_t jsort = false;
1198 Float_t ****pmdEdep;
1200 pmdTrack = new Int_t ***[fgkTotUM];
1201 pmdEdep = new Float_t ***[fgkTotUM];
1202 for (i=0; i<fgkTotUM; i++)
1204 pmdTrack[i] = new Int_t **[fgkRow];
1205 pmdEdep[i] = new Float_t **[fgkRow];
1208 for (i = 0; i < fgkTotUM; i++)
1210 for (j = 0; j < fgkRow; j++)
1212 pmdTrack[i][j] = new Int_t *[fgkCol];
1213 pmdEdep[i][j] = new Float_t *[fgkCol];
1217 for (i = 0; i < fgkTotUM; i++)
1219 for (j = 0; j < fgkRow; j++)
1221 for (k = 0; k < fgkCol; k++)
1223 Int_t nn = fPRECounter[i][j][k];
1226 pmdTrack[i][j][k] = new Int_t[nn];
1227 pmdEdep[i][j][k] = new Float_t[nn];
1232 pmdTrack[i][j][k] = new Int_t[nn];
1233 pmdEdep[i][j][k] = new Float_t[nn];
1235 fPRECounter[i][j][k] = 0;
1241 Int_t nentries = fCell.GetEntries();
1243 Int_t mtrackno, ism, ixp, iyp;
1246 for (i = 0; i < nentries; i++)
1248 AliPMDcell* cell = (AliPMDcell*)fCell.UncheckedAt(i);
1250 mtrackno = cell->GetTrackNumber();
1251 ism = cell->GetSMNumber();
1254 edep = cell->GetEdep();
1255 Int_t nn = fPRECounter[ism][ixp][iyp];
1256 pmdTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
1257 pmdEdep[ism][ixp][iyp][nn] = edep;
1258 fPRECounter[ism][ixp][iyp]++;
1265 for (im=0; im<fgkTotUM; im++)
1267 for (ix=0; ix<fgkRow; ix++)
1269 for (iy=0; iy<fgkCol; iy++)
1271 nn = fPRECounter[im][ix][iy];
1274 // This block handles if a cell is fired
1275 // many times by many tracks
1276 status1 = new Int_t[nn];
1277 status2 = new Int_t[nn];
1278 trnarray = new Int_t[nn];
1279 for (iz = 0; iz < nn; iz++)
1281 status1[iz] = pmdTrack[im][ix][iy][iz];
1283 TMath::Sort(nn,status1,status2,jsort);
1284 Int_t trackOld = -99999;
1285 Int_t track, trCount = 0;
1286 for (iz = 0; iz < nn; iz++)
1288 track = status1[status2[iz]];
1289 if (trackOld != track)
1291 trnarray[trCount] = track;
1298 Float_t totEdp = 0.;
1299 trEdp = new Float_t[trCount];
1300 fracEdp = new Float_t[trCount];
1301 for (il = 0; il < trCount; il++)
1304 track = trnarray[il];
1305 for (iz = 0; iz < nn; iz++)
1307 if (track == pmdTrack[im][ix][iy][iz])
1309 trEdp[il] += pmdEdep[im][ix][iy][iz];
1312 totEdp += trEdp[il];
1315 Float_t fracOld = 0.;
1317 for (il = 0; il < trCount; il++)
1319 fracEdp[il] = trEdp[il]/totEdp;
1320 if (fracOld < fracEdp[il])
1322 fracOld = fracEdp[il];
1326 fPRETrackNo[im][ix][iy] = trnarray[ilOld];
1333 // This only handles if a cell is fired
1334 // by only one track
1336 fPRETrackNo[im][ix][iy] = pmdTrack[im][ix][iy][0];
1341 // This is if no cell is fired
1342 fPRETrackNo[im][ix][iy] = -999;
1348 // Delete all the pointers
1350 for (i = 0; i < fgkTotUM; i++)
1352 for (j = 0; j < fgkRow; j++)
1354 for (k = 0; k < fgkCol; k++)
1356 delete [] pmdTrack[i][j][k];
1357 delete [] pmdEdep[i][j][k];
1362 for (i = 0; i < fgkTotUM; i++)
1364 for (j = 0; j < fgkRow; j++)
1366 delete [] pmdTrack[i][j];
1367 delete [] pmdEdep[i][j];
1371 for (i = 0; i < fgkTotUM; i++)
1373 delete [] pmdTrack[i];
1374 delete [] pmdEdep[i];
1379 // End of the cell id assignment
1382 //____________________________________________________________________________
1383 void AliPMDDigitizer::MeV2ADC(Float_t mev, Float_t & adc) const
1385 // This converts the simulated edep to ADC according to the
1387 //PS Test in September 2003 and 2006
1388 // KeV - ADC conversion for 12bit ADC
1391 const Float_t kConstant = 0.07;
1392 const Float_t kErConstant = 0.1;
1393 const Float_t kSlope = 76.0;
1394 const Float_t kErSlope = 5.0;
1396 Float_t cons = gRandom->Gaus(kConstant,kErConstant);
1397 Float_t slop = gRandom->Gaus(kSlope,kErSlope);
1399 Float_t adc12bit = slop*mev*0.001 + cons;
1402 if(adc12bit < 1600.0)
1404 adc = (Float_t) adc12bit;
1406 else if (adc12bit >= 1600.0)
1411 //____________________________________________________________________________
1412 void AliPMDDigitizer::AddSDigit(Int_t trnumber, Int_t det, Int_t smnumber,
1413 Int_t irow, Int_t icol, Float_t adc)
1417 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
1418 TClonesArray &lsdigits = *fSDigits;
1419 new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,det,smnumber,irow,icol,adc);
1421 //____________________________________________________________________________
1423 void AliPMDDigitizer::AddDigit(Int_t trnumber, Int_t det, Int_t smnumber,
1424 Int_t irow, Int_t icol, Float_t adc)
1428 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
1429 TClonesArray &ldigits = *fDigits;
1430 new(ldigits[fNdigit++]) AliPMDdigit(trnumber,det,smnumber,irow,icol,adc);
1432 //____________________________________________________________________________
1434 void AliPMDDigitizer::SetZPosition(Float_t zpos)
1438 //____________________________________________________________________________
1439 Float_t AliPMDDigitizer::GetZPosition() const
1443 //____________________________________________________________________________
1445 void AliPMDDigitizer::ResetCell()
1447 // clears the cell array and also the counter
1452 for (Int_t i = 0; i < fgkTotUM; i++)
1454 for (Int_t j = 0; j < fgkRow; j++)
1456 for (Int_t k = 0; k < fgkCol; k++)
1458 fCPVCounter[i][j][k] = 0;
1459 fPRECounter[i][j][k] = 0;
1464 //____________________________________________________________________________
1465 void AliPMDDigitizer::ResetSDigit()
1469 if (fSDigits) fSDigits->Delete();
1471 //____________________________________________________________________________
1472 void AliPMDDigitizer::ResetDigit()
1476 if (fDigits) fDigits->Delete();
1478 //____________________________________________________________________________
1480 void AliPMDDigitizer::ResetCellADC()
1482 // Clears individual cells edep and track number
1483 for (Int_t i = 0; i < fgkTotUM; i++)
1485 for (Int_t j = 0; j < fgkRow; j++)
1487 for (Int_t k = 0; k < fgkCol; k++)
1491 fCPVTrackNo[i][j][k] = 0;
1492 fPRETrackNo[i][j][k] = 0;
1497 //____________________________________________________________________________
1499 void AliPMDDigitizer::UnLoad(Option_t *option)
1501 // Unloads all the root files
1503 const char *cS = strstr(option,"S");
1504 const char *cD = strstr(option,"D");
1506 fRunLoader->UnloadgAlice();
1507 fRunLoader->UnloadHeader();
1508 fRunLoader->UnloadKinematics();
1512 fPMDLoader->UnloadHits();
1516 fPMDLoader->UnloadHits();
1517 fPMDLoader->UnloadSDigits();
1521 //----------------------------------------------------------------------
1522 Float_t AliPMDDigitizer::Gain(Int_t det, Int_t smn, Int_t row, Int_t col) const
1524 // returns of the gain of the cell
1525 // Added this method by ZA
1527 //cout<<" I am here in gain "<<fCalibData<< "smn,row, col "<<smn
1528 //<<" "<<row<<" "<<col<<endl;
1531 AliError("No calibration data loaded from CDB!!!");
1536 GainFact = fCalibGain->GetGainFact(det,smn,row,col);
1539 //----------------------------------------------------------------------
1540 AliPMDCalibData* AliPMDDigitizer::GetCalibGain() const
1542 // The run number will be centralized in AliCDBManager,
1543 // you don't need to set it here!
1544 // Added this method by ZA
1545 // Cleaned up by Alberto
1546 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Gain");
1548 if(!entry) AliFatal("Calibration object retrieval failed!");
1550 AliPMDCalibData *calibdata=0;
1551 if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
1553 if (!calibdata) AliFatal("No calibration data from calibration database !");
1557 //----------------------------------------------------------------------
1558 AliPMDPedestal* AliPMDDigitizer::GetCalibPed() const
1560 // The run number will be centralized in AliCDBManager,
1561 // you don't need to set it here!
1563 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Ped");
1565 if(!entry) AliFatal("Pedestal object retrieval failed!");
1567 AliPMDPedestal *pedestal=0;
1568 if (entry) pedestal = (AliPMDPedestal*) entry->GetObject();
1570 if (!pedestal) AliFatal("No pedestal data from calibration database !");