StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEmcSimpleSimulator.cxx
1 // $Id: StEmcSimpleSimulator.cxx,v 1.16 2009/12/10 19:54:22 mattheww Exp $
2 
3 #include "StEmcSimpleSimulator.h"
4 
5 #include "TMath.h"
6 
7 #include "StMessMgr.h"
9 #include "StEvent/StEmcRawHit.h"
10 #include "StMcEvent/StMcCalorimeterHit.hh"
11 #include "StEmcUtil/geometry/StEmcGeom.h"
12 #include "StEmcUtil/database/StBemcTables.h"
13 
14 ClassImp(StEmcSimpleSimulator)
15 
16 StEmcSimpleSimulator::StEmcSimpleSimulator(StDetectorId det, StEmcSimulatorMode mode):StEmcVirtualSimulator() {
17  mDetectorId = det;
18  mMode = mode;
19 
20  // set some default values depending on the type of detector being simulated
21  switch(mDetectorId) {
22  case kBarrelEmcTowerId:
23  mMaxADC = 4095.0;
24  mSF[0] = 14.365;
25  mSF[1] = -0.512;
26  mSF[2] = 0.668;
27  break;
28 
29  // BPRS should only report energy in scintillator
30  case kBarrelEmcPreShowerId:
31  mMaxADC = 1023.0;
32  mSF[0] = 1.0;
33  mSF[1] = 0.0;
34  mSF[2] = 0.0;
35  break;
36 
37  case kBarrelSmdEtaStripId:
38  mMaxADC = 1023.9;
39  mSF[0] = 118500.0;
40  mSF[1] = -32920.0;
41  mSF[2] = 31130.0;
42  break;
43 
44  case kBarrelSmdPhiStripId:
45  mMaxADC = 1023.0;
46  mSF[0] = 126000.0;
47  mSF[1] = -13950.0;
48  mSF[2] = 19710.0;
49  break;
50 
51  default:
52  LOG_ERROR << det << " is not an OK value for detector (see StEnumerations.h). BEMC simulations will be JUNK!" << endm;
53  }
54 
55  mGeom = StEmcGeom::instance(det - 8);
56 
57  mEmbeddingMode = false;
58 
59  mTables = NULL;
60 
61  mCalibScale = 1.0;
62  mCalibSpread = 0.0;
63 
64  mMaxADCSpread = 0.0;
65 }
66 
68  // remember the problem with negative sub -- let's be careful
69  if(mcHit->module() <= 0 || mcHit->eta() <= 0 || mcHit->sub() <= 0) {
70  LOG_ERROR << "These quantities must all be positive: module=" << mcHit->module()
71  << " eta=" << mcHit->eta() << " sub=" << mcHit->sub() << endm;
72  return NULL;
73  }
74 
75  StEmcRawHit *rawHit = new StEmcRawHit(mDetectorId, mcHit->module(), mcHit->eta(), mcHit->sub(), 0);
76 
77  float pseudoRapidity; mGeom->getEta(mcHit->module(), mcHit->eta(), pseudoRapidity);
78  int softId; mGeom->getId(mcHit->module(), mcHit->eta(), mcHit->sub(), softId);
79 
80  switch(mMode) {
81  case kTestMode: {
82  rawHit->setEnergy(mcHit->dE() * samplingFraction(pseudoRapidity));
83 
84  LOG_DEBUG << Form("det=%2d softId=%5d dE=%e sF=%.1f ADC=%4d ped=%6.2f rms=%4.2f energy=%.4f",
85  mDetectorId, softId, mcHit->dE(), samplingFraction(pseudoRapidity), rawHit->adc(),
86  0.0, 0.0, rawHit->energy()) << endm;
87 
88  return rawHit;
89  }
90 
91  case kSimpleMode: {
92  float calib = mTables->calib(mDetectorId-8, softId);
93 
94  double ADC = mcHit->dE() * samplingFraction(pseudoRapidity) / calib;
95 
96  // add pedestal noise unless we're doing embedding (when noise is already in the data)
97  float pedMean(0.0), pedRMS(0.0);
98  if(!mEmbeddingMode) {
99  pedMean = mTables->pedestal(mDetectorId-8, softId);
100  pedRMS = mTables->pedestalRMS(mDetectorId-8, softId);
101  ADC += mRandom.Gaus(pedMean, pedRMS);
102  }
103 
104  // finally smear with any specified calibration jitter
105  ADC = pedMean + (ADC-pedMean) * mRandom.Gaus(mCalibScale, mCalibSpread);
106 
107 
108  // check for a valid ADC range
109  double maxADC = mRandom.Gaus(mMaxADC, mMaxADCSpread);
110  if(ADC < 0) ADC = 0.0;
111  if(ADC > maxADC) ADC = maxADC;
112 
113  rawHit->setAdc(static_cast<unsigned int>(ADC));
114 
115  float energy = (rawHit->adc() - pedMean) * calib;
116  rawHit->setEnergy(energy);
117 
118  LOG_DEBUG << Form("det=%2d softId=%5d dE=%e sF=%.1f ADC=%4d ped=%6.2f rms=%4.2f energy=%.4f",
119  mDetectorId, softId, mcHit->dE(), samplingFraction(pseudoRapidity), rawHit->adc(),
120  pedMean, pedRMS, rawHit->energy()) << endm;
121 
122  return rawHit;
123  }
124 
125  default: {
126  LOG_ERROR << "StEmcSimpleSimulator is not configured for " << mMode << " so raw hit is NULL" << endm;
127  delete rawHit;
128  return NULL;
129  }
130  }
131 }
132 
133 double StEmcSimpleSimulator::samplingFraction(double eta) {
134  Double_t x = TMath::Abs(eta);
135  return mSF[0]+mSF[1]*x+mSF[2]*x*x;
136 }
137 
138 /*****************************************************************************
139  * $Log: StEmcSimpleSimulator.cxx,v $
140  * Revision 1.16 2009/12/10 19:54:22 mattheww
141  * Updated BEMC Sampling Fraction for use with LOW_EM
142  *
143  * Revision 1.15 2008/11/17 21:08:36 kocolosk
144  * set BPRS sampling fraction to 1.0 so energy is just energy in scintillator
145  *
146  * Revision 1.14 2007/12/12 22:12:25 kocolosk
147  * calibration spread should only operate on ped-subtracted ADCs, not raw
148  *
149  * Revision 1.13 2007/10/08 15:28:36 kocolosk
150  * setMaximumAdc(Spread) methods allow for better simulation of BSMD ADC response
151  * http://www.star.bnl.gov/HyperNews-star/get/emc2/2507.html
152  *
153  * Revision 1.12 2007/09/11 21:49:13 kocolosk
154  * complete overhaul of the BEMC simulator
155  * http://www.star.bnl.gov/HyperNews-star/get/emc2/2486.html
156  *
157  * Revision 1.11 2007/01/22 19:13:40 kocolosk
158  * use STAR logger for all output
159  *
160  * Revision 1.10 2005/03/21 21:36:39 suaide
161  * fixed problem with chain
162  *
163  * Revision 1.9 2004/08/06 13:24:47 suaide
164  * New features added and fixed some bugs in the database
165  *
166  * Revision 1.8 2003/09/23 15:19:48 suaide
167  * fixed bugs and modifications for embedding
168  *
169  * Revision 1.7 2003/01/23 03:09:02 jeromel
170  * Include modif
171  *
172  * Revision 1.6 2002/10/17 21:17:01 pavlinov
173  * default - no pedestal for all detectors
174  *
175  * Revision 1.5 2002/09/10 16:51:30 pavlinov
176  * Discard line with mDbMaker->SetDateTime
177  *
178  * Revision 1.4 2002/06/04 16:09:35 pavlinov
179  * added option with DB(pedestal ans calibration coefficients
180  *
181  * Revision 1.3 2001/05/14 01:30:13 pavlinov
182  * Cleanup
183  *
184  * Revision 1.2 2001/04/25 17:24:33 perev
185  * HPcorrs
186  *
187  * Revision 1.1 2000/10/23 22:53:14 pavlinov
188  * First working C++ version
189  *****************************************************************************/
virtual StEmcRawHit * makeRawHit(const StMcCalorimeterHit *mcHit)
workhorse function