StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEmcPmtSimulator.cxx
1 // $Id: StEmcPmtSimulator.cxx,v 1.14 2007/12/14 03:53:44 kocolosk Exp $
2 
3 #include "StEmcPmtSimulator.h"
4 
5 #include "StMessMgr.h"
7 #include "StEvent/StEmcRawHit.h"
8 #include "StMcEvent/StMcCalorimeterHit.hh"
9 #include "StEmcUtil/geometry/StEmcGeom.h"
10 #include "StEmcUtil/database/StBemcTables.h"
11 
12 ClassImp(StEmcPmtSimulator)
13 
14 StEmcPmtSimulator::StEmcPmtSimulator(StDetectorId det, StEmcSimulatorMode mode)
15  : StEmcSimpleSimulator(det, mode)
16 {
17  switch(mDetectorId) {
18  case kBarrelEmcTowerId:
19  mMipPhotoElectrons = 63.0;
20  mMipEnergyDeposit = 0.0198;
21  break;
22 
23  case kBarrelEmcPreShowerId:
24  mMipPhotoElectrons = 6.0;
25  mMipEnergyDeposit = 0.002;
26  break;
27 
28  default:
29  LOG_ERROR << "StEmcPmtSimulator isn't configured for " << mDetectorId << endm;
30  }
31 
32  switch(mMode) {
33  case kPrimarySecondaryFullMode:
34  mVer = StPmtSignal::kFullSimulator;
35  break;
36 
37  case kPrimarySecondaryFastMode:
38  mVer = StPmtSignal::kFastSimulator;
39  break;
40 
41  default: break;
42  }
43 }
44 
46  // remember the problem with negative sub -- let's be careful
47  if(mcHit->module() <= 0 || mcHit->eta() <= 0 || mcHit->sub() <= 0) {
48  LOG_ERROR << "These quantities must all be positive: module=" << mcHit->module()
49  << " eta=" << mcHit->eta() << " sub=" << mcHit->sub() << endm;
50  return NULL;
51  }
52 
53  StEmcRawHit *rawHit = new StEmcRawHit(mDetectorId, mcHit->module(), mcHit->eta(), mcHit->sub(), 0);
54 
55  float pseudoRapidity; mGeom->getEta(mcHit->module(), mcHit->eta(), pseudoRapidity);
56  int softId; mGeom->getId(mcHit->module(), mcHit->eta(), mcHit->sub(), softId);
57 
58  double photoElectrons = mcHit->dE() * mMipPhotoElectrons / mMipEnergyDeposit;
59  photoElectrons = mRandom.PoissonD(photoElectrons);
60 
61  // get the calibration value from DB if available, otherwise use ideal value
62  float calib = mTables->calib(mDetectorId-8, softId);
63 
64  // totalGain is ADC per incident photoElectron in this case
65  double totalGain = calib ? samplingFraction(pseudoRapidity) * (mMipEnergyDeposit / mMipPhotoElectrons) / calib : 0.0;
66 
67  double pedMean(0.0), pedRMS(0.0);
68  if(!mEmbeddingMode) {
69  pedMean = mTables->pedestal(mDetectorId-8, softId);
70  pedRMS = mTables->pedestalRMS(mDetectorId-8, softId);
71  }
72 
73  double ADC(0.0);
74  switch(mMode) {
75  case kTestMode: case kSimpleMode: {
76  delete rawHit;
78  }
79 
80  case kPrimaryOnlyMode: {
81  ADC = totalGain * photoElectrons;
82  ADC += mRandom.Gaus(pedMean, pedRMS);
83  break;
84  }
85 
86  case kPrimarySecondaryFullMode: case kPrimarySecondaryFastMode: {
87  mPmtSignal.setTotalGain(totalGain);
88  mPmtSignal.setPedestalMean(pedMean);
89  mPmtSignal.setPedestalRMS(pedRMS);
90 
91  ADC = mPmtSignal.getAdc(static_cast<int>(photoElectrons), mVer);
92  break;
93  }
94  }
95 
96  // finally smear with any specified calibration jitter
97  ADC = pedMean + (ADC-pedMean) * mRandom.Gaus(mCalibScale, mCalibSpread);
98 
99  // check for a valid ADC range
100  double maxADC = mRandom.Gaus(mMaxADC, mMaxADCSpread);
101  if(ADC < 0) ADC = 0.0;
102  if(ADC > maxADC) ADC = maxADC;
103 
104  rawHit->setAdc(static_cast<unsigned int>(ADC));
105 
106  float energy = (rawHit->adc() - pedMean) * calib;
107  rawHit->setEnergy(energy);
108 
109  LOG_DEBUG << Form("det=%2d softId=%5d dE=%e sF=%.1f ADC=%4d ped=%6.2f rms=%4.2f energy=%.4f",
110  mDetectorId, softId, mcHit->dE(), samplingFraction(pseudoRapidity), rawHit->adc(),
111  pedMean, pedRMS, rawHit->energy()) << endm;
112 
113  return rawHit;
114 }
115 
116 /*****************************************************************************
117  * $Log: StEmcPmtSimulator.cxx,v $
118  * Revision 1.14 2007/12/14 03:53:44 kocolosk
119  * bugfix so channels with zero calibrations still get a simulated pedestal
120  *
121  * Revision 1.13 2007/12/12 22:12:24 kocolosk
122  * calibration spread should only operate on ped-subtracted ADCs, not raw
123  *
124  * Revision 1.12 2007/10/08 15:28:35 kocolosk
125  * setMaximumAdc(Spread) methods allow for better simulation of BSMD ADC response
126  * http://www.star.bnl.gov/HyperNews-star/get/emc2/2507.html
127  *
128  * Revision 1.11 2007/09/12 13:31:45 kocolosk
129  * two small changes to suppress compiler warnings
130  *
131  * Revision 1.10 2007/09/11 21:49:13 kocolosk
132  * complete overhaul of the BEMC simulator
133  * http://www.star.bnl.gov/HyperNews-star/get/emc2/2486.html
134  *
135  * Revision 1.9 2007/01/23 19:44:24 kocolosk
136  * few additional logger fixes
137  *
138  * Revision 1.8 2007/01/22 19:13:39 kocolosk
139  * use STAR logger for all output
140  *
141  * Revision 1.7 2005/03/21 21:36:38 suaide
142  * fixed problem with chain
143  *
144  * Revision 1.6 2004/08/06 13:24:47 suaide
145  * New features added and fixed some bugs in the database
146  *
147  * Revision 1.5 2003/09/23 15:19:43 suaide
148  * fixed bugs and modifications for embedding
149  *
150  * Revision 1.4 2003/01/23 03:09:02 jeromel
151  * Include modif
152  *
153  * Revision 1.3 2002/06/04 16:09:34 pavlinov
154  * added option with DB(pedestal ans calibration coefficients
155  *
156  * Revision 1.2 2001/05/14 01:30:13 pavlinov
157  * Cleanup
158  *
159  * Revision 1.1 2000/10/23 22:53:13 pavlinov
160  * First working C++ version
161  *****************************************************************************/
void setTotalGain(float val)
set the gain of the full PMT chain in ADC counts / photoelectron emitted from cathode ...
Definition: StPmtSignal.h:85
StEmcRawHit * makeRawHit(const StMcCalorimeterHit *mcHit)
workhorse function
virtual StEmcRawHit * makeRawHit(const StMcCalorimeterHit *mcHit)
workhorse function
void setPedestalRMS(float val)
set the width of the pedestal in ADC counts
Definition: StPmtSignal.h:91
void setPedestalMean(float val)
set the pedestal in ADC counts
Definition: StPmtSignal.h:88
int getAdc(int nPhotoElectrons, simulatorVersion version)
return ADC counts for a given # of incident photoelectrons
Definition: StPmtSignal.cxx:53