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 Int_t trnotemp = trackno;
329 //------------------modified by Mriganka ----------------------
330 if(ks==1||(imo = mparticle->GetFirstMother())<0 ){
331 vx = mparticle->Vx();
332 vy = mparticle->Vy();
333 vz = mparticle->Vz();
335 if(trackpid==kGamma||trackpid==11||trackpid==-11||
336 trackpid==kPi0)igstatus=1;
340 while(((imo = mparticle->GetFirstMother()) >= 0)&&
341 (ks = mparticle->GetStatusCode() <1) )
343 mparticle = gAlice->GetMCApp()->Particle(imo);
344 trackpid = mparticle->GetPdgCode();
345 ks = mparticle->GetStatusCode();
346 vx = mparticle->Vx();
347 vy = mparticle->Vy();
348 vz = mparticle->Vz();
361 if(trackpid == kGamma || trackpid == 11 ||
362 trackpid == -11 || trackpid == kPi0) igstatus = 1;
363 mtrackpid = trackpid;
365 trackpid = trackpidOld;
366 trackno = tracknoOld;
368 //-----------------end of modification----------------
373 edep = fPMDHit->GetEnergy();
374 Int_t vol1 = fPMDHit->GetVolume(1); // Column
375 Int_t vol2 = fPMDHit->GetVolume(2); // Row
376 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
377 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
380 // -----------------------------------------//
381 // In new geometry after adding electronics //
382 // For Super Module 1 & 2 //
383 // nrow = 48, ncol = 96 //
384 // For Super Module 3 & 4 //
385 // nrow = 96, ncol = 48 //
386 // -----------------------------------------//
390 smnumber = (vol8-1)*6 + vol7;
392 if (vol8 == 1 || vol8 == 2)
397 else if (vol8 == 3 || vol8 == 4)
403 AliDebug(2,Form("Zposition = %f Edeposition = %f",zPos,edep));
410 else if (zPos > fZPos)
415 Int_t smn = smnumber - 1;
416 Int_t ixx = xpad - 1;
417 Int_t iyy = ypad - 1;
420 fPRE[smn][ixx][iyy] += edep;
421 fPRECounter[smn][ixx][iyy]++;
423 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
428 fCPV[smn][ixx][iyy] += edep;
429 fCPVCounter[smn][ixx][iyy]++;
430 AliPMDcell* cpvcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
431 fCPVCell.Add(cpvcell);
435 } // Track Loop ended
436 TrackAssignment2CPVCell();
437 TrackAssignment2Cell();
444 for (Int_t idet = 0; idet < 2; idet++)
446 for (Int_t ism = 0; ism < fgkTotUM; ism++)
448 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
450 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
454 deltaE = fPRE[ism][jrow][kcol];
455 trno = fPRETrackNo[ism][jrow][kcol];
460 deltaE = fCPV[ism][jrow][kcol];
461 trno = fCPVTrackNo[ism][jrow][kcol];
466 AddSDigit(trno,detno,ism,jrow,kcol,deltaE);
474 fPMDLoader->WriteSDigits("OVERWRITE");
477 //____________________________________________________________________________
479 void AliPMDDigitizer::Hits2Digits(Int_t ievt)
481 // This reads the PMD Hits tree and assigns the right track number
482 // to a cell and stores in the digits tree
484 const Int_t kPi0 = 111;
485 const Int_t kGamma = 22;
493 Float_t xPos, yPos, zPos;
494 Int_t xpad = -1, ypad = -1;
496 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
498 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
501 AliDebug(1,Form("Event Number = %d",ievt));
502 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
503 AliDebug(1,Form("Number of Particles = %d", nparticles));
504 fRunLoader->GetEvent(ievt);
505 // ------------------------------------------------------- //
506 // Pointer to specific detector hits.
507 // Get pointers to Alice detectors and Hits containers
509 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
510 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
512 if (fPMDLoader == 0x0)
514 AliError("Can not find PMD or PMDLoader");
516 TTree* treeH = fPMDLoader->TreeH();
517 Int_t ntracks = (Int_t) treeH->GetEntries();
518 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
519 fPMDLoader->LoadDigits("recreate");
520 TTree* treeD = fPMDLoader->TreeD();
523 fPMDLoader->MakeTree("D");
524 treeD = fPMDLoader->TreeD();
526 Int_t bufsize = 16000;
527 treeD->Branch("PMDDigit", &fDigits, bufsize);
529 TClonesArray* hits = 0;
530 if (fPMD) hits = fPMD->Hits();
532 // Start loop on tracks in the hits containers
534 for (Int_t track=0; track<ntracks;track++)
537 treeH->GetEvent(track);
541 npmd = hits->GetEntriesFast();
542 for (Int_t ipmd = 0; ipmd < npmd; ipmd++)
544 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
545 trackno = fPMDHit->GetTrack();
547 // get kinematics of the particles
549 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
550 trackpid = mparticle->GetPdgCode();
551 Int_t ks = mparticle->GetStatusCode();
553 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
554 if (mparticle->GetFirstMother() == -1)
556 tracknoOld = trackno;
557 trackpidOld = trackpid;
562 //-----------------------modified by Mriganka ------------------
563 if(ks==1||(imo = mparticle->GetFirstMother())<0 ){
564 vx = mparticle->Vx();
565 vy = mparticle->Vy();
566 vz = mparticle->Vz();
568 if(trackpid==kGamma||trackpid==11||trackpid==-11||trackpid==kPi0)
573 while(((imo = mparticle->GetFirstMother()) >= 0)&&
574 (ks = mparticle->GetStatusCode() <1) )
576 mparticle = gAlice->GetMCApp()->Particle(imo);
577 trackpid = mparticle->GetPdgCode();
578 ks = mparticle->GetStatusCode();
579 vx = mparticle->Vx();
580 vy = mparticle->Vy();
581 vz = mparticle->Vz();
587 if(trackpid==kGamma||trackpid==11||trackpid==-11||trackpid==kPi0)
591 trackpid=trackpidOld;
594 //-----------------end of modification----------------
598 edep = fPMDHit->GetEnergy();
599 Int_t vol1 = fPMDHit->GetVolume(1); // Column
600 Int_t vol2 = fPMDHit->GetVolume(2); // Row
601 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
602 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
605 // -----------------------------------------//
606 // In new geometry after adding electronics //
607 // For Super Module 1 & 2 //
608 // nrow = 48, ncol = 96 //
609 // For Super Module 3 & 4 //
610 // nrow = 96, ncol = 48 //
611 // -----------------------------------------//
613 smnumber = (vol8-1)*6 + vol7;
615 if (vol8 == 1 || vol8 == 2)
620 else if (vol8 == 3 || vol8 == 4)
626 AliDebug(2,Form("ZPosition = %f Edeposition = %d",zPos,edep));
627 //Float_t zposition = TMath::Abs(zPos);
634 else if (zPos > fZPos)
640 Int_t smn = smnumber - 1;
641 Int_t ixx = xpad - 1;
642 Int_t iyy = ypad - 1;
645 fPRE[smn][ixx][iyy] += edep;
646 fPRECounter[smn][ixx][iyy]++;
648 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
654 fCPV[smn][ixx][iyy] += edep;
655 fCPVCounter[smn][ixx][iyy]++;
656 AliPMDcell* cpvcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
657 fCPVCell.Add(cpvcell);
661 } // Track Loop ended
662 TrackAssignment2CPVCell();
663 TrackAssignment2Cell();
671 for (Int_t idet = 0; idet < 2; idet++)
673 for (Int_t ism = 0; ism < fgkTotUM; ism++)
675 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
677 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
681 deltaE = fPRE[ism][jrow][kcol];
682 trno = fPRETrackNo[ism][jrow][kcol];
687 deltaE = fCPV[ism][jrow][kcol];
688 trno = fCPVTrackNo[ism][jrow][kcol];
695 // To decalibrate the adc values
697 gain1 = Gain(idet,ism,jrow,kcol);
700 Int_t adcDecalib = (Int_t)(adc/gain1);
701 adc = (Float_t) adcDecalib;
708 // Pedestal Decalibration
710 fCalibPed->GetPedMeanRms(idet,ism,jrow,kcol);
711 Int_t pedrms1 = (Int_t) pedmeanrms%1000;
712 Float_t pedrms = (Float_t)pedrms1/10.;
714 (Float_t) (pedmeanrms - pedrms1)/1000.0;
715 //printf("%f %f\n",pedmean, pedrms);
718 adc += (pedmean + 3.0*pedrms);
719 AddDigit(trno,detno,ism,jrow,kcol,adc);
726 } // supermodule loop
729 fPMDLoader->WriteDigits("OVERWRITE");
733 //____________________________________________________________________________
736 void AliPMDDigitizer::SDigits2Digits(Int_t ievt)
738 // This reads the PMD sdigits tree and converts energy deposition
739 // in a cell to ADC and stores in the digits tree
742 fRunLoader->GetEvent(ievt);
744 TTree* treeS = fPMDLoader->TreeS();
745 AliPMDsdigit *pmdsdigit;
746 TBranch *branch = treeS->GetBranch("PMDSDigit");
749 AliError("PMD Sdigit branch does not exist");
752 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
753 branch->SetAddress(&fSDigits);
755 TTree* treeD = fPMDLoader->TreeD();
758 fPMDLoader->MakeTree("D");
759 treeD = fPMDLoader->TreeD();
761 Int_t bufsize = 16000;
762 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
763 treeD->Branch("PMDDigit", &fDigits, bufsize);
765 Int_t trno, det, smn;
769 Int_t nmodules = (Int_t) treeS->GetEntries();
770 AliDebug(1,Form("Number of modules = %d",nmodules));
772 for (Int_t imodule = 0; imodule < nmodules; imodule++)
774 treeS->GetEntry(imodule);
775 Int_t nentries = fSDigits->GetLast();
776 AliDebug(2,Form("Number of entries per module = %d",nentries+1));
777 for (Int_t ient = 0; ient < nentries+1; ient++)
779 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
780 trno = pmdsdigit->GetTrackNumber();
781 det = pmdsdigit->GetDetector();
782 smn = pmdsdigit->GetSMNumber();
783 irow = pmdsdigit->GetRow();
784 icol = pmdsdigit->GetColumn();
785 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%1000;
805 Float_t pedrms = (Float_t)pedrms1/10.;
806 Float_t pedmean = (Float_t) (pedmeanrms - pedrms1)/1000.0;
807 //printf("%f %f\n",pedmean, pedrms);
810 adc += (pedmean + 3.0*pedrms);
811 AddDigit(trno,det,smn,irow,icol,adc);
818 fPMDLoader->WriteDigits("OVERWRITE");
821 //____________________________________________________________________________
822 void AliPMDDigitizer::Exec(Option_t *option)
824 // Does the event merging and digitization
825 const char *cdeb = strstr(option,"deb");
828 AliDebug(100," *** PMD Exec is called ***");
831 Int_t ninputs = fManager->GetNinputs();
832 AliDebug(1,Form("Number of files to be processed = %d",ninputs));
835 for (Int_t i = 0; i < ninputs; i++)
837 Int_t troffset = fManager->GetMask(i);
838 MergeSDigits(i, troffset);
841 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
842 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
843 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
844 if (fPMDLoader == 0x0)
846 AliError("Can not find PMD or PMDLoader");
848 fPMDLoader->LoadDigits("update");
849 TTree* treeD = fPMDLoader->TreeD();
852 fPMDLoader->MakeTree("D");
853 treeD = fPMDLoader->TreeD();
855 Int_t bufsize = 16000;
856 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
857 treeD->Branch("PMDDigit", &fDigits, bufsize);
864 for (Int_t idet = 0; idet < 2; idet++)
866 for (Int_t ism = 0; ism < fgkTotUM; ism++)
868 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
870 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
874 deltaE = fPRE[ism][jrow][kcol];
875 trno = fPRETrackNo[ism][jrow][kcol];
880 deltaE = fCPV[ism][jrow][kcol];
881 trno = fCPVTrackNo[ism][jrow][kcol];
889 // Gain decalibration
891 Float_t gain1 = Gain(idet,ism,jrow,kcol);
895 Int_t adcDecalib = (Int_t)(adc/gain1);
896 adc = (Float_t) adcDecalib;
902 // Pedestal Decalibration
904 fCalibPed->GetPedMeanRms(idet,ism,jrow,kcol);
905 Int_t pedrms1 = (Int_t) pedmeanrms%1000;
906 Float_t pedrms = (Float_t)pedrms1/10.;
908 (Float_t) (pedmeanrms - pedrms1)/1000.0;
909 //printf("%f %f\n",pedmean, pedrms);
912 adc += (pedmean + 3.0*pedrms);
913 AddDigit(trno,detno,ism,jrow,kcol,adc);
921 } // supermodule loop
923 fPMDLoader->WriteDigits("OVERWRITE");
924 fPMDLoader->UnloadDigits();
927 //____________________________________________________________________________
928 void AliPMDDigitizer::TrackAssignment2CPVCell()
930 // This block assigns the cell id when there are
931 // multiple tracks in a cell according to the
933 // This method added by Ajay
934 Bool_t jsort = false;
947 cpvTrack = new Int_t ***[fgkTotUM];
948 cpvEdep = new Float_t ***[fgkTotUM];
949 for (i=0; i<fgkTotUM; i++)
951 cpvTrack[i] = new Int_t **[fgkRow];
952 cpvEdep[i] = new Float_t **[fgkRow];
955 for (i = 0; i < fgkTotUM; i++)
957 for (j = 0; j < fgkRow; j++)
959 cpvTrack[i][j] = new Int_t *[fgkCol];
960 cpvEdep[i][j] = new Float_t *[fgkCol];
963 for (i = 0; i < fgkTotUM; i++)
965 for (j = 0; j < fgkRow; j++)
967 for (k = 0; k < fgkCol; k++)
969 Int_t nn = fCPVCounter[i][j][k];
972 cpvTrack[i][j][k] = new Int_t[nn];
973 cpvEdep[i][j][k] = new Float_t[nn];
978 cpvTrack[i][j][k] = new Int_t[nn];
979 cpvEdep[i][j][k] = new Float_t[nn];
981 fCPVCounter[i][j][k] = 0;
987 Int_t nentries = fCPVCell.GetEntries();
989 Int_t mtrackno, ism, ixp, iyp;
991 for (i = 0; i < nentries; i++)
993 AliPMDcell* cpvcell = (AliPMDcell*)fCPVCell.UncheckedAt(i);
995 mtrackno = cpvcell->GetTrackNumber();
996 ism = cpvcell->GetSMNumber();
997 ixp = cpvcell->GetX();
998 iyp = cpvcell->GetY();
999 edep = cpvcell->GetEdep();
1000 Int_t nn = fCPVCounter[ism][ixp][iyp];
1001 cpvTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
1002 cpvEdep[ism][ixp][iyp][nn] = edep;
1003 fCPVCounter[ism][ixp][iyp]++;
1009 for (im=0; im<fgkTotUM; im++)
1011 for (ix=0; ix<fgkRow; ix++)
1013 for (iy=0; iy<fgkCol; iy++)
1015 nn = fCPVCounter[im][ix][iy];
1018 // This block handles if a cell is fired
1019 // many times by many tracks
1020 status1 = new Int_t[nn];
1021 status2 = new Int_t[nn];
1022 trnarray = new Int_t[nn];
1023 for (iz = 0; iz < nn; iz++)
1025 status1[iz] = cpvTrack[im][ix][iy][iz];
1027 TMath::Sort(nn,status1,status2,jsort);
1028 Int_t trackOld = -99999;
1029 Int_t track, trCount = 0;
1030 for (iz = 0; iz < nn; iz++)
1032 track = status1[status2[iz]];
1033 if (trackOld != track)
1035 trnarray[trCount] = track;
1042 Float_t totEdp = 0.;
1043 trEdp = new Float_t[trCount];
1044 fracEdp = new Float_t[trCount];
1045 for (il = 0; il < trCount; il++)
1048 track = trnarray[il];
1049 for (iz = 0; iz < nn; iz++)
1051 if (track == cpvTrack[im][ix][iy][iz])
1053 trEdp[il] += cpvEdep[im][ix][iy][iz];
1056 totEdp += trEdp[il];
1059 Float_t fracOld = 0.;
1061 for (il = 0; il < trCount; il++)
1063 fracEdp[il] = trEdp[il]/totEdp;
1064 if (fracOld < fracEdp[il])
1066 fracOld = fracEdp[il];
1070 fCPVTrackNo[im][ix][iy] = trnarray[ilOld];
1077 // This only handles if a cell is fired
1078 // by only one track
1080 fCPVTrackNo[im][ix][iy] = cpvTrack[im][ix][iy][0];
1085 // This is if no cell is fired
1086 fCPVTrackNo[im][ix][iy] = -999;
1092 // Delete all the pointers
1094 for (i = 0; i < fgkTotUM; i++)
1096 for (j = 0; j < fgkRow; j++)
1098 for (k = 0; k < fgkCol; k++)
1100 delete []cpvTrack[i][j][k];
1101 delete []cpvEdep[i][j][k];
1106 for (i = 0; i < fgkTotUM; i++)
1108 for (j = 0; j < fgkRow; j++)
1110 delete [] cpvTrack[i][j];
1111 delete [] cpvEdep[i][j];
1115 for (i = 0; i < fgkTotUM; i++)
1117 delete [] cpvTrack[i];
1118 delete [] cpvEdep[i];
1124 // End of the cell id assignment
1127 //____________________________________________________________________________
1129 void AliPMDDigitizer::MergeSDigits(Int_t filenumber, Int_t troffset)
1132 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(filenumber));
1133 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
1134 fPMDLoader->LoadSDigits("read");
1135 TTree* treeS = fPMDLoader->TreeS();
1136 AliPMDsdigit *pmdsdigit;
1137 TBranch *branch = treeS->GetBranch("PMDSDigit");
1138 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
1139 branch->SetAddress(&fSDigits);
1141 Int_t itrackno, idet, ism;
1144 Int_t nmodules = (Int_t) treeS->GetEntries();
1145 AliDebug(1,Form("Number of Modules in the treeS = %d",nmodules));
1146 AliDebug(1,Form("Track Offset = %d",troffset));
1147 for (Int_t imodule = 0; imodule < nmodules; imodule++)
1149 treeS->GetEntry(imodule);
1150 Int_t nentries = fSDigits->GetLast();
1151 AliDebug(2,Form("Number of Entries per Module = %d",nentries));
1152 for (Int_t ient = 0; ient < nentries+1; ient++)
1154 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
1155 itrackno = pmdsdigit->GetTrackNumber();
1156 idet = pmdsdigit->GetDetector();
1157 ism = pmdsdigit->GetSMNumber();
1158 ixp = pmdsdigit->GetRow();
1159 iyp = pmdsdigit->GetColumn();
1160 edep = pmdsdigit->GetCellEdep();
1163 if (fPRE[ism][ixp][iyp] < edep)
1165 fPRETrackNo[ism][ixp][iyp] = troffset + itrackno;
1167 fPRE[ism][ixp][iyp] += edep;
1171 if (fCPV[ism][ixp][iyp] < edep)
1173 fCPVTrackNo[ism][ixp][iyp] = troffset + itrackno;
1175 fCPV[ism][ixp][iyp] += edep;
1181 // ----------------------------------------------------------------------
1182 void AliPMDDigitizer::TrackAssignment2Cell()
1185 // This block assigns the cell id when there are
1186 // multiple tracks in a cell according to the
1187 // energy deposition
1189 Bool_t jsort = false;
1200 Float_t ****pmdEdep;
1202 pmdTrack = new Int_t ***[fgkTotUM];
1203 pmdEdep = new Float_t ***[fgkTotUM];
1204 for (i=0; i<fgkTotUM; i++)
1206 pmdTrack[i] = new Int_t **[fgkRow];
1207 pmdEdep[i] = new Float_t **[fgkRow];
1210 for (i = 0; i < fgkTotUM; i++)
1212 for (j = 0; j < fgkRow; j++)
1214 pmdTrack[i][j] = new Int_t *[fgkCol];
1215 pmdEdep[i][j] = new Float_t *[fgkCol];
1219 for (i = 0; i < fgkTotUM; i++)
1221 for (j = 0; j < fgkRow; j++)
1223 for (k = 0; k < fgkCol; k++)
1225 Int_t nn = fPRECounter[i][j][k];
1228 pmdTrack[i][j][k] = new Int_t[nn];
1229 pmdEdep[i][j][k] = new Float_t[nn];
1234 pmdTrack[i][j][k] = new Int_t[nn];
1235 pmdEdep[i][j][k] = new Float_t[nn];
1237 fPRECounter[i][j][k] = 0;
1243 Int_t nentries = fCell.GetEntries();
1245 Int_t mtrackno, ism, ixp, iyp;
1248 for (i = 0; i < nentries; i++)
1250 AliPMDcell* cell = (AliPMDcell*)fCell.UncheckedAt(i);
1252 mtrackno = cell->GetTrackNumber();
1253 ism = cell->GetSMNumber();
1256 edep = cell->GetEdep();
1257 Int_t nn = fPRECounter[ism][ixp][iyp];
1258 pmdTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
1259 pmdEdep[ism][ixp][iyp][nn] = edep;
1260 fPRECounter[ism][ixp][iyp]++;
1267 for (im=0; im<fgkTotUM; im++)
1269 for (ix=0; ix<fgkRow; ix++)
1271 for (iy=0; iy<fgkCol; iy++)
1273 nn = fPRECounter[im][ix][iy];
1276 // This block handles if a cell is fired
1277 // many times by many tracks
1278 status1 = new Int_t[nn];
1279 status2 = new Int_t[nn];
1280 trnarray = new Int_t[nn];
1281 for (iz = 0; iz < nn; iz++)
1283 status1[iz] = pmdTrack[im][ix][iy][iz];
1285 TMath::Sort(nn,status1,status2,jsort);
1286 Int_t trackOld = -99999;
1287 Int_t track, trCount = 0;
1288 for (iz = 0; iz < nn; iz++)
1290 track = status1[status2[iz]];
1291 if (trackOld != track)
1293 trnarray[trCount] = track;
1300 Float_t totEdp = 0.;
1301 trEdp = new Float_t[trCount];
1302 fracEdp = new Float_t[trCount];
1303 for (il = 0; il < trCount; il++)
1306 track = trnarray[il];
1307 for (iz = 0; iz < nn; iz++)
1309 if (track == pmdTrack[im][ix][iy][iz])
1311 trEdp[il] += pmdEdep[im][ix][iy][iz];
1314 totEdp += trEdp[il];
1317 Float_t fracOld = 0.;
1319 for (il = 0; il < trCount; il++)
1321 fracEdp[il] = trEdp[il]/totEdp;
1322 if (fracOld < fracEdp[il])
1324 fracOld = fracEdp[il];
1328 fPRETrackNo[im][ix][iy] = trnarray[ilOld];
1335 // This only handles if a cell is fired
1336 // by only one track
1338 fPRETrackNo[im][ix][iy] = pmdTrack[im][ix][iy][0];
1343 // This is if no cell is fired
1344 fPRETrackNo[im][ix][iy] = -999;
1350 // Delete all the pointers
1352 for (i = 0; i < fgkTotUM; i++)
1354 for (j = 0; j < fgkRow; j++)
1356 for (k = 0; k < fgkCol; k++)
1358 delete [] pmdTrack[i][j][k];
1359 delete [] pmdEdep[i][j][k];
1364 for (i = 0; i < fgkTotUM; i++)
1366 for (j = 0; j < fgkRow; j++)
1368 delete [] pmdTrack[i][j];
1369 delete [] pmdEdep[i][j];
1373 for (i = 0; i < fgkTotUM; i++)
1375 delete [] pmdTrack[i];
1376 delete [] pmdEdep[i];
1381 // End of the cell id assignment
1384 //____________________________________________________________________________
1385 void AliPMDDigitizer::MeV2ADC(Float_t mev, Float_t & adc) const
1387 // This converts the simulated edep to ADC according to the
1389 //PS Test in September 2003 and 2006
1390 // KeV - ADC conversion for 12bit ADC
1392 const Float_t kConstant = 9.0809;
1393 const Float_t kErConstant = 1.6763;
1394 const Float_t kSlope = 128.348;
1395 const Float_t kErSlope = 0.4703;
1397 Float_t cons = gRandom->Gaus(kConstant,kErConstant);
1398 Float_t slop = gRandom->Gaus(kSlope,kErSlope);
1400 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 !");