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 if(ks==1||(imo = mparticle->GetFirstMother())<0 ){
327 vx = mparticle->Vx();
328 vy = mparticle->Vy();
329 vz = mparticle->Vz();
331 if(trackpid==kGamma||trackpid==11||trackpid==-11||
332 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();
350 if(trackpid==kGamma||trackpid==11||trackpid==-11||
351 trackpid==kPi0)igstatus=1;
354 trackpid=trackpidOld;
357 //-----------------end of modification----------------
362 edep = fPMDHit->GetEnergy();
363 Int_t vol1 = fPMDHit->GetVolume(1); // Column
364 Int_t vol2 = fPMDHit->GetVolume(2); // Row
365 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
366 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
369 // -----------------------------------------//
370 // In new geometry after adding electronics //
371 // For Super Module 1 & 2 //
372 // nrow = 48, ncol = 96 //
373 // For Super Module 3 & 4 //
374 // nrow = 96, ncol = 48 //
375 // -----------------------------------------//
379 smnumber = (vol8-1)*6 + vol7;
381 if (vol8 == 1 || vol8 == 2)
386 else if (vol8 == 3 || vol8 == 4)
392 AliDebug(2,Form("Zposition = %f Edeposition = %f",zPos,edep));
393 //Float_t zposition = TMath::Abs(zPos);
399 else if (zPos > fZPos)
404 Int_t smn = smnumber - 1;
405 Int_t ixx = xpad - 1;
406 Int_t iyy = ypad - 1;
409 fPRE[smn][ixx][iyy] += edep;
410 fPRECounter[smn][ixx][iyy]++;
412 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
417 fCPV[smn][ixx][iyy] += edep;
418 fCPVCounter[smn][ixx][iyy]++;
419 AliPMDcell* cpvcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
420 fCPVCell.Add(cpvcell);
424 } // Track Loop ended
425 TrackAssignment2CPVCell();
426 TrackAssignment2Cell();
433 for (Int_t idet = 0; idet < 2; idet++)
435 for (Int_t ism = 0; ism < fgkTotUM; ism++)
437 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
439 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
443 deltaE = fPRE[ism][jrow][kcol];
444 trno = fPRETrackNo[ism][jrow][kcol];
449 deltaE = fCPV[ism][jrow][kcol];
450 trno = fCPVTrackNo[ism][jrow][kcol];
455 AddSDigit(trno,detno,ism,jrow,kcol,deltaE);
463 fPMDLoader->WriteSDigits("OVERWRITE");
466 //____________________________________________________________________________
468 void AliPMDDigitizer::Hits2Digits(Int_t ievt)
470 // This reads the PMD Hits tree and assigns the right track number
471 // to a cell and stores in the digits tree
473 const Int_t kPi0 = 111;
474 const Int_t kGamma = 22;
482 Float_t xPos, yPos, zPos;
483 Int_t xpad = -1, ypad = -1;
485 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
487 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
490 AliDebug(1,Form("Event Number = %d",ievt));
491 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
492 AliDebug(1,Form("Number of Particles = %d", nparticles));
493 fRunLoader->GetEvent(ievt);
494 // ------------------------------------------------------- //
495 // Pointer to specific detector hits.
496 // Get pointers to Alice detectors and Hits containers
498 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
499 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
501 if (fPMDLoader == 0x0)
503 AliError("Can not find PMD or PMDLoader");
505 TTree* treeH = fPMDLoader->TreeH();
506 Int_t ntracks = (Int_t) treeH->GetEntries();
507 AliDebug(1,Form("Number of Tracks in the TreeH = %d", ntracks));
508 fPMDLoader->LoadDigits("recreate");
509 TTree* treeD = fPMDLoader->TreeD();
512 fPMDLoader->MakeTree("D");
513 treeD = fPMDLoader->TreeD();
515 Int_t bufsize = 16000;
516 treeD->Branch("PMDDigit", &fDigits, bufsize);
518 TClonesArray* hits = 0;
519 if (fPMD) hits = fPMD->Hits();
521 // Start loop on tracks in the hits containers
523 for (Int_t track=0; track<ntracks;track++)
525 gAlice->GetMCApp()->ResetHits();
526 treeH->GetEvent(track);
530 npmd = hits->GetEntriesFast();
531 for (Int_t ipmd = 0; ipmd < npmd; ipmd++)
533 fPMDHit = (AliPMDhit*) hits->UncheckedAt(ipmd);
534 trackno = fPMDHit->GetTrack();
536 // get kinematics of the particles
538 TParticle* mparticle = gAlice->GetMCApp()->Particle(trackno);
539 trackpid = mparticle->GetPdgCode();
540 Int_t ks = mparticle->GetStatusCode();
542 Int_t tracknoOld=0, trackpidOld=0, statusOld = 0;
543 if (mparticle->GetFirstMother() == -1)
545 tracknoOld = trackno;
546 trackpidOld = trackpid;
551 //-----------------------modified by Mriganka ------------------
552 if(ks==1||(imo = mparticle->GetFirstMother())<0 ){
553 vx = mparticle->Vx();
554 vy = mparticle->Vy();
555 vz = mparticle->Vz();
557 if(trackpid==kGamma||trackpid==11||trackpid==-11||trackpid==kPi0)
562 while(((imo = mparticle->GetFirstMother()) >= 0)&&
563 (ks = mparticle->GetStatusCode() <1) )
565 mparticle = gAlice->GetMCApp()->Particle(imo);
566 trackpid = mparticle->GetPdgCode();
567 ks = mparticle->GetStatusCode();
568 vx = mparticle->Vx();
569 vy = mparticle->Vy();
570 vz = mparticle->Vz();
576 if(trackpid==kGamma||trackpid==11||trackpid==-11||trackpid==kPi0)
580 trackpid=trackpidOld;
583 //-----------------end of modification----------------
587 edep = fPMDHit->GetEnergy();
588 Int_t vol1 = fPMDHit->GetVolume(1); // Column
589 Int_t vol2 = fPMDHit->GetVolume(2); // Row
590 Int_t vol7 = fPMDHit->GetVolume(7); // UnitModule
591 Int_t vol8 = fPMDHit->GetVolume(8); // SuperModule
594 // -----------------------------------------//
595 // In new geometry after adding electronics //
596 // For Super Module 1 & 2 //
597 // nrow = 48, ncol = 96 //
598 // For Super Module 3 & 4 //
599 // nrow = 96, ncol = 48 //
600 // -----------------------------------------//
602 smnumber = (vol8-1)*6 + vol7;
604 if (vol8 == 1 || vol8 == 2)
609 else if (vol8 == 3 || vol8 == 4)
615 AliDebug(2,Form("ZPosition = %f Edeposition = %d",zPos,edep));
616 //Float_t zposition = TMath::Abs(zPos);
623 else if (zPos > fZPos)
629 Int_t smn = smnumber - 1;
630 Int_t ixx = xpad - 1;
631 Int_t iyy = ypad - 1;
634 fPRE[smn][ixx][iyy] += edep;
635 fPRECounter[smn][ixx][iyy]++;
637 AliPMDcell* cell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
643 fCPV[smn][ixx][iyy] += edep;
644 fCPVCounter[smn][ixx][iyy]++;
645 AliPMDcell* cpvcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
646 fCPVCell.Add(cpvcell);
650 } // Track Loop ended
651 TrackAssignment2CPVCell();
652 TrackAssignment2Cell();
660 for (Int_t idet = 0; idet < 2; idet++)
662 for (Int_t ism = 0; ism < fgkTotUM; ism++)
664 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
666 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
670 deltaE = fPRE[ism][jrow][kcol];
671 trno = fPRETrackNo[ism][jrow][kcol];
676 deltaE = fCPV[ism][jrow][kcol];
677 trno = fCPVTrackNo[ism][jrow][kcol];
684 // To decalibrate the adc values
686 gain1 = Gain(idet,ism,jrow,kcol);
689 Int_t adcDecalib = (Int_t)(adc/gain1);
690 adc = (Float_t) adcDecalib;
697 // Pedestal Decalibration
699 fCalibPed->GetPedMeanRms(idet,ism,jrow,kcol);
700 Int_t pedrms1 = (Int_t) pedmeanrms%100;
701 Float_t pedrms = (Float_t)pedrms1/10.;
703 (Float_t) (pedmeanrms - pedrms1)/1000.0;
706 adc += (pedmean + 3.0*pedrms);
707 AddDigit(trno,detno,ism,jrow,kcol,adc);
714 } // supermodule loop
717 fPMDLoader->WriteDigits("OVERWRITE");
721 //____________________________________________________________________________
724 void AliPMDDigitizer::SDigits2Digits(Int_t ievt)
726 // This reads the PMD sdigits tree and converts energy deposition
727 // in a cell to ADC and stores in the digits tree
730 fRunLoader->GetEvent(ievt);
732 TTree* treeS = fPMDLoader->TreeS();
733 AliPMDsdigit *pmdsdigit;
734 TBranch *branch = treeS->GetBranch("PMDSDigit");
737 AliError("PMD Sdigit branch does not exist");
740 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
741 branch->SetAddress(&fSDigits);
743 TTree* treeD = fPMDLoader->TreeD();
746 fPMDLoader->MakeTree("D");
747 treeD = fPMDLoader->TreeD();
749 Int_t bufsize = 16000;
750 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
751 treeD->Branch("PMDDigit", &fDigits, bufsize);
753 Int_t trno, det, smn;
757 Int_t nmodules = (Int_t) treeS->GetEntries();
758 AliDebug(1,Form("Number of modules = %d",nmodules));
760 for (Int_t imodule = 0; imodule < nmodules; imodule++)
762 treeS->GetEntry(imodule);
763 Int_t nentries = fSDigits->GetLast();
764 AliDebug(2,Form("Number of entries per module = %d",nentries+1));
765 for (Int_t ient = 0; ient < nentries+1; ient++)
767 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
768 trno = pmdsdigit->GetTrackNumber();
769 det = pmdsdigit->GetDetector();
770 smn = pmdsdigit->GetSMNumber();
771 irow = pmdsdigit->GetRow();
772 icol = pmdsdigit->GetColumn();
773 edep = pmdsdigit->GetCellEdep();
777 // To decalibrte the adc values
779 Float_t gain1 = Gain(det,smn,irow,icol);
782 Int_t adcDecalib = (Int_t)(adc/gain1);
783 adc = (Float_t) adcDecalib;
789 // Pedestal Decalibration
790 Int_t pedmeanrms = fCalibPed->GetPedMeanRms(det,smn,irow,icol);
791 Int_t pedrms1 = (Int_t) pedmeanrms%100;
792 Float_t pedrms = (Float_t)pedrms1/10.;
793 Float_t pedmean = (Float_t) (pedmeanrms - pedrms1)/1000.0;
796 adc += (pedmean + 3.0*pedrms);
797 AddDigit(trno,det,smn,irow,icol,adc);
804 fPMDLoader->WriteDigits("OVERWRITE");
807 //____________________________________________________________________________
808 void AliPMDDigitizer::Exec(Option_t *option)
810 // Does the event merging and digitization
811 const char *cdeb = strstr(option,"deb");
814 AliDebug(100," *** PMD Exec is called ***");
817 Int_t ninputs = fManager->GetNinputs();
818 AliDebug(1,Form("Number of files to be processed = %d",ninputs));
821 for (Int_t i = 0; i < ninputs; i++)
823 Int_t troffset = fManager->GetMask(i);
824 MergeSDigits(i, troffset);
827 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
828 fPMD = (AliPMD*)gAlice->GetDetector("PMD");
829 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
830 if (fPMDLoader == 0x0)
832 AliError("Can not find PMD or PMDLoader");
834 fPMDLoader->LoadDigits("update");
835 TTree* treeD = fPMDLoader->TreeD();
838 fPMDLoader->MakeTree("D");
839 treeD = fPMDLoader->TreeD();
841 Int_t bufsize = 16000;
842 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
843 treeD->Branch("PMDDigit", &fDigits, bufsize);
850 for (Int_t idet = 0; idet < 2; idet++)
852 for (Int_t ism = 0; ism < fgkTotUM; ism++)
854 for (Int_t jrow = 0; jrow < fgkRow; jrow++)
856 for (Int_t kcol = 0; kcol < fgkCol; kcol++)
860 deltaE = fPRE[ism][jrow][kcol];
861 trno = fPRETrackNo[ism][jrow][kcol];
866 deltaE = fCPV[ism][jrow][kcol];
867 trno = fCPVTrackNo[ism][jrow][kcol];
875 // Gain decalibration
877 Float_t gain1 = Gain(idet,ism,jrow,kcol);
881 Int_t adcDecalib = (Int_t)(adc/gain1);
882 adc = (Float_t) adcDecalib;
888 // Pedestal Decalibration
890 fCalibPed->GetPedMeanRms(idet,ism,jrow,kcol);
891 Int_t pedrms1 = (Int_t) pedmeanrms%100;
892 Float_t pedrms = (Float_t)pedrms1/10.;
894 (Float_t) (pedmeanrms - pedrms1)/1000.0;
897 adc += (pedmean + 3.0*pedrms);
898 AddDigit(trno,detno,ism,jrow,kcol,adc);
906 } // supermodule loop
908 fPMDLoader->WriteDigits("OVERWRITE");
909 fPMDLoader->UnloadDigits();
912 //____________________________________________________________________________
913 void AliPMDDigitizer::TrackAssignment2CPVCell()
915 // This block assigns the cell id when there are
916 // multiple tracks in a cell according to the
918 // This method added by Ajay
919 Bool_t jsort = false;
932 cpvTrack = new Int_t ***[fgkTotUM];
933 cpvEdep = new Float_t ***[fgkTotUM];
934 for (i=0; i<fgkTotUM; i++)
936 cpvTrack[i] = new Int_t **[fgkRow];
937 cpvEdep[i] = new Float_t **[fgkRow];
940 for (i = 0; i < fgkTotUM; i++)
942 for (j = 0; j < fgkRow; j++)
944 cpvTrack[i][j] = new Int_t *[fgkCol];
945 cpvEdep[i][j] = new Float_t *[fgkCol];
948 for (i = 0; i < fgkTotUM; i++)
950 for (j = 0; j < fgkRow; j++)
952 for (k = 0; k < fgkCol; k++)
954 Int_t nn = fCPVCounter[i][j][k];
957 cpvTrack[i][j][k] = new Int_t[nn];
958 cpvEdep[i][j][k] = new Float_t[nn];
963 cpvTrack[i][j][k] = new Int_t[nn];
964 cpvEdep[i][j][k] = new Float_t[nn];
966 fCPVCounter[i][j][k] = 0;
972 Int_t nentries = fCPVCell.GetEntries();
974 Int_t mtrackno, ism, ixp, iyp;
976 for (i = 0; i < nentries; i++)
978 AliPMDcell* cpvcell = (AliPMDcell*)fCPVCell.UncheckedAt(i);
980 mtrackno = cpvcell->GetTrackNumber();
981 ism = cpvcell->GetSMNumber();
982 ixp = cpvcell->GetX();
983 iyp = cpvcell->GetY();
984 edep = cpvcell->GetEdep();
985 Int_t nn = fCPVCounter[ism][ixp][iyp];
986 cpvTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
987 cpvEdep[ism][ixp][iyp][nn] = edep;
988 fCPVCounter[ism][ixp][iyp]++;
994 for (im=0; im<fgkTotUM; im++)
996 for (ix=0; ix<fgkRow; ix++)
998 for (iy=0; iy<fgkCol; iy++)
1000 nn = fCPVCounter[im][ix][iy];
1003 // This block handles if a cell is fired
1004 // many times by many tracks
1005 status1 = new Int_t[nn];
1006 status2 = new Int_t[nn];
1007 trnarray = new Int_t[nn];
1008 for (iz = 0; iz < nn; iz++)
1010 status1[iz] = cpvTrack[im][ix][iy][iz];
1012 TMath::Sort(nn,status1,status2,jsort);
1013 Int_t trackOld = -99999;
1014 Int_t track, trCount = 0;
1015 for (iz = 0; iz < nn; iz++)
1017 track = status1[status2[iz]];
1018 if (trackOld != track)
1020 trnarray[trCount] = track;
1027 Float_t totEdp = 0.;
1028 trEdp = new Float_t[trCount];
1029 fracEdp = new Float_t[trCount];
1030 for (il = 0; il < trCount; il++)
1033 track = trnarray[il];
1034 for (iz = 0; iz < nn; iz++)
1036 if (track == cpvTrack[im][ix][iy][iz])
1038 trEdp[il] += cpvEdep[im][ix][iy][iz];
1041 totEdp += trEdp[il];
1044 Float_t fracOld = 0.;
1046 for (il = 0; il < trCount; il++)
1048 fracEdp[il] = trEdp[il]/totEdp;
1049 if (fracOld < fracEdp[il])
1051 fracOld = fracEdp[il];
1055 fCPVTrackNo[im][ix][iy] = trnarray[ilOld];
1062 // This only handles if a cell is fired
1063 // by only one track
1065 fCPVTrackNo[im][ix][iy] = cpvTrack[im][ix][iy][0];
1070 // This is if no cell is fired
1071 fCPVTrackNo[im][ix][iy] = -999;
1077 // Delete all the pointers
1079 for (i = 0; i < fgkTotUM; i++)
1081 for (j = 0; j < fgkRow; j++)
1083 for (k = 0; k < fgkCol; k++)
1085 delete []cpvTrack[i][j][k];
1086 delete []cpvEdep[i][j][k];
1091 for (i = 0; i < fgkTotUM; i++)
1093 for (j = 0; j < fgkRow; j++)
1095 delete [] cpvTrack[i][j];
1096 delete [] cpvEdep[i][j];
1100 for (i = 0; i < fgkTotUM; i++)
1102 delete [] cpvTrack[i];
1103 delete [] cpvEdep[i];
1109 // End of the cell id assignment
1112 //____________________________________________________________________________
1114 void AliPMDDigitizer::MergeSDigits(Int_t filenumber, Int_t troffset)
1117 fRunLoader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(filenumber));
1118 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
1119 fPMDLoader->LoadSDigits("read");
1120 TTree* treeS = fPMDLoader->TreeS();
1121 AliPMDsdigit *pmdsdigit;
1122 TBranch *branch = treeS->GetBranch("PMDSDigit");
1123 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
1124 branch->SetAddress(&fSDigits);
1126 Int_t itrackno, idet, ism;
1129 Int_t nmodules = (Int_t) treeS->GetEntries();
1130 AliDebug(1,Form("Number of Modules in the treeS = %d",nmodules));
1131 AliDebug(1,Form("Track Offset = %d",troffset));
1132 for (Int_t imodule = 0; imodule < nmodules; imodule++)
1134 treeS->GetEntry(imodule);
1135 Int_t nentries = fSDigits->GetLast();
1136 AliDebug(2,Form("Number of Entries per Module = %d",nentries));
1137 for (Int_t ient = 0; ient < nentries+1; ient++)
1139 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
1140 itrackno = pmdsdigit->GetTrackNumber();
1141 idet = pmdsdigit->GetDetector();
1142 ism = pmdsdigit->GetSMNumber();
1143 ixp = pmdsdigit->GetRow();
1144 iyp = pmdsdigit->GetColumn();
1145 edep = pmdsdigit->GetCellEdep();
1148 if (fPRE[ism][ixp][iyp] < edep)
1150 fPRETrackNo[ism][ixp][iyp] = troffset + itrackno;
1152 fPRE[ism][ixp][iyp] += edep;
1156 if (fCPV[ism][ixp][iyp] < edep)
1158 fCPVTrackNo[ism][ixp][iyp] = troffset + itrackno;
1160 fCPV[ism][ixp][iyp] += edep;
1166 // ----------------------------------------------------------------------
1167 void AliPMDDigitizer::TrackAssignment2Cell()
1170 // This block assigns the cell id when there are
1171 // multiple tracks in a cell according to the
1172 // energy deposition
1174 Bool_t jsort = false;
1185 Float_t ****pmdEdep;
1187 pmdTrack = new Int_t ***[fgkTotUM];
1188 pmdEdep = new Float_t ***[fgkTotUM];
1189 for (i=0; i<fgkTotUM; i++)
1191 pmdTrack[i] = new Int_t **[fgkRow];
1192 pmdEdep[i] = new Float_t **[fgkRow];
1195 for (i = 0; i < fgkTotUM; i++)
1197 for (j = 0; j < fgkRow; j++)
1199 pmdTrack[i][j] = new Int_t *[fgkCol];
1200 pmdEdep[i][j] = new Float_t *[fgkCol];
1204 for (i = 0; i < fgkTotUM; i++)
1206 for (j = 0; j < fgkRow; j++)
1208 for (k = 0; k < fgkCol; k++)
1210 Int_t nn = fPRECounter[i][j][k];
1213 pmdTrack[i][j][k] = new Int_t[nn];
1214 pmdEdep[i][j][k] = new Float_t[nn];
1219 pmdTrack[i][j][k] = new Int_t[nn];
1220 pmdEdep[i][j][k] = new Float_t[nn];
1222 fPRECounter[i][j][k] = 0;
1228 Int_t nentries = fCell.GetEntries();
1230 Int_t mtrackno, ism, ixp, iyp;
1233 for (i = 0; i < nentries; i++)
1235 AliPMDcell* cell = (AliPMDcell*)fCell.UncheckedAt(i);
1237 mtrackno = cell->GetTrackNumber();
1238 ism = cell->GetSMNumber();
1241 edep = cell->GetEdep();
1242 Int_t nn = fPRECounter[ism][ixp][iyp];
1243 pmdTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
1244 pmdEdep[ism][ixp][iyp][nn] = edep;
1245 fPRECounter[ism][ixp][iyp]++;
1252 for (im=0; im<fgkTotUM; im++)
1254 for (ix=0; ix<fgkRow; ix++)
1256 for (iy=0; iy<fgkCol; iy++)
1258 nn = fPRECounter[im][ix][iy];
1261 // This block handles if a cell is fired
1262 // many times by many tracks
1263 status1 = new Int_t[nn];
1264 status2 = new Int_t[nn];
1265 trnarray = new Int_t[nn];
1266 for (iz = 0; iz < nn; iz++)
1268 status1[iz] = pmdTrack[im][ix][iy][iz];
1270 TMath::Sort(nn,status1,status2,jsort);
1271 Int_t trackOld = -99999;
1272 Int_t track, trCount = 0;
1273 for (iz = 0; iz < nn; iz++)
1275 track = status1[status2[iz]];
1276 if (trackOld != track)
1278 trnarray[trCount] = track;
1285 Float_t totEdp = 0.;
1286 trEdp = new Float_t[trCount];
1287 fracEdp = new Float_t[trCount];
1288 for (il = 0; il < trCount; il++)
1291 track = trnarray[il];
1292 for (iz = 0; iz < nn; iz++)
1294 if (track == pmdTrack[im][ix][iy][iz])
1296 trEdp[il] += pmdEdep[im][ix][iy][iz];
1299 totEdp += trEdp[il];
1302 Float_t fracOld = 0.;
1304 for (il = 0; il < trCount; il++)
1306 fracEdp[il] = trEdp[il]/totEdp;
1307 if (fracOld < fracEdp[il])
1309 fracOld = fracEdp[il];
1313 fPRETrackNo[im][ix][iy] = trnarray[ilOld];
1320 // This only handles if a cell is fired
1321 // by only one track
1323 fPRETrackNo[im][ix][iy] = pmdTrack[im][ix][iy][0];
1328 // This is if no cell is fired
1329 fPRETrackNo[im][ix][iy] = -999;
1335 // Delete all the pointers
1337 for (i = 0; i < fgkTotUM; i++)
1339 for (j = 0; j < fgkRow; j++)
1341 for (k = 0; k < fgkCol; k++)
1343 delete [] pmdTrack[i][j][k];
1344 delete [] pmdEdep[i][j][k];
1349 for (i = 0; i < fgkTotUM; i++)
1351 for (j = 0; j < fgkRow; j++)
1353 delete [] pmdTrack[i][j];
1354 delete [] pmdEdep[i][j];
1358 for (i = 0; i < fgkTotUM; i++)
1360 delete [] pmdTrack[i];
1361 delete [] pmdEdep[i];
1366 // End of the cell id assignment
1369 //____________________________________________________________________________
1370 void AliPMDDigitizer::MeV2ADC(Float_t mev, Float_t & adc) const
1372 // This converts the simulated edep to ADC according to the
1374 //PS Test in September 2003 and 2006
1375 // KeV - ADC conversion for 12bit ADC
1378 const Float_t kConstant = 0.07;
1379 const Float_t kErConstant = 0.1;
1380 const Float_t kSlope = 76.0;
1381 const Float_t kErSlope = 5.0;
1383 Float_t cons = gRandom->Gaus(kConstant,kErConstant);
1384 Float_t slop = gRandom->Gaus(kSlope,kErSlope);
1386 Float_t adc12bit = slop*mev*0.001 + cons;
1389 if(adc12bit < 1600.0)
1391 adc = (Float_t) adc12bit;
1393 else if (adc12bit >= 1600.0)
1398 //____________________________________________________________________________
1399 void AliPMDDigitizer::AddSDigit(Int_t trnumber, Int_t det, Int_t smnumber,
1400 Int_t irow, Int_t icol, Float_t adc)
1404 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
1405 TClonesArray &lsdigits = *fSDigits;
1406 new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,det,smnumber,irow,icol,adc);
1408 //____________________________________________________________________________
1410 void AliPMDDigitizer::AddDigit(Int_t trnumber, Int_t det, Int_t smnumber,
1411 Int_t irow, Int_t icol, Float_t adc)
1415 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
1416 TClonesArray &ldigits = *fDigits;
1417 new(ldigits[fNdigit++]) AliPMDdigit(trnumber,det,smnumber,irow,icol,adc);
1419 //____________________________________________________________________________
1421 void AliPMDDigitizer::SetZPosition(Float_t zpos)
1425 //____________________________________________________________________________
1426 Float_t AliPMDDigitizer::GetZPosition() const
1430 //____________________________________________________________________________
1432 void AliPMDDigitizer::ResetCell()
1434 // clears the cell array and also the counter
1439 for (Int_t i = 0; i < fgkTotUM; i++)
1441 for (Int_t j = 0; j < fgkRow; j++)
1443 for (Int_t k = 0; k < fgkCol; k++)
1445 fCPVCounter[i][j][k] = 0;
1446 fPRECounter[i][j][k] = 0;
1451 //____________________________________________________________________________
1452 void AliPMDDigitizer::ResetSDigit()
1456 if (fSDigits) fSDigits->Delete();
1458 //____________________________________________________________________________
1459 void AliPMDDigitizer::ResetDigit()
1463 if (fDigits) fDigits->Delete();
1465 //____________________________________________________________________________
1467 void AliPMDDigitizer::ResetCellADC()
1469 // Clears individual cells edep and track number
1470 for (Int_t i = 0; i < fgkTotUM; i++)
1472 for (Int_t j = 0; j < fgkRow; j++)
1474 for (Int_t k = 0; k < fgkCol; k++)
1478 fCPVTrackNo[i][j][k] = 0;
1479 fPRETrackNo[i][j][k] = 0;
1484 //____________________________________________________________________________
1486 void AliPMDDigitizer::UnLoad(Option_t *option)
1488 // Unloads all the root files
1490 const char *cS = strstr(option,"S");
1491 const char *cD = strstr(option,"D");
1493 fRunLoader->UnloadgAlice();
1494 fRunLoader->UnloadHeader();
1495 fRunLoader->UnloadKinematics();
1499 fPMDLoader->UnloadHits();
1503 fPMDLoader->UnloadHits();
1504 fPMDLoader->UnloadSDigits();
1508 //----------------------------------------------------------------------
1509 Float_t AliPMDDigitizer::Gain(Int_t det, Int_t smn, Int_t row, Int_t col) const
1511 // returns of the gain of the cell
1512 // Added this method by ZA
1514 //cout<<" I am here in gain "<<fCalibData<< "smn,row, col "<<smn
1515 //<<" "<<row<<" "<<col<<endl;
1518 AliError("No calibration data loaded from CDB!!!");
1523 GainFact = fCalibGain->GetGainFact(det,smn,row,col);
1526 //----------------------------------------------------------------------
1527 AliPMDCalibData* AliPMDDigitizer::GetCalibGain() const
1529 // The run number will be centralized in AliCDBManager,
1530 // you don't need to set it here!
1531 // Added this method by ZA
1532 // Cleaned up by Alberto
1533 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Gain");
1535 if(!entry) AliFatal("Calibration object retrieval failed!");
1537 AliPMDCalibData *calibdata=0;
1538 if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
1540 if (!calibdata) AliFatal("No calibration data from calibration database !");
1544 //----------------------------------------------------------------------
1545 AliPMDPedestal* AliPMDDigitizer::GetCalibPed() const
1547 // The run number will be centralized in AliCDBManager,
1548 // you don't need to set it here!
1550 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Ped");
1552 if(!entry) AliFatal("Pedestal object retrieval failed!");
1554 AliPMDPedestal *pedestal=0;
1555 if (entry) pedestal = (AliPMDPedestal*) entry->GetObject();
1557 if (!pedestal) AliFatal("No pedestal data from calibration database !");