StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFmsSimulatorMaker.cxx
1 //
2 // Pibero Djawotho <pibero@tamu.edu>
3 // Texas A&M University
4 // 4 Jan 2011
5 //
6 // For descriptions of FMS hits in GEANT:
7 //
8 // http://www.star.bnl.gov/protected/spin/akio/fpd_geant/
9 // http://drupal.star.bnl.gov/STAR/event/2011/01/05/software-and-computing-phone-meeting/fms-simulation-open-request-and-readiness
10 //
11 // For descriptions of FMS geometry and mapping in the FMS database:
12 //
13 // http://drupal.star.bnl.gov/STAR/book/export/html/15527
14 //
15 // $STAR/StDb/idl/fmsChannelGeometry.idl
16 // $STAR/StDb/idl/fmsDetectorPosition.idl
17 // $STAR/StDb/idl/fmsDetectorPosition.idl
18 // $STAR/StDb/idl/fmsPatchPannelMap.idl
19 // $STAR/StDb/idl/fmsQTMap.idl
20 //
21 
22 #include "StMcEventTypes.hh"
23 #include "StEventTypes.h"
24 #include "StFmsDbMaker/StFmsDbMaker.h"
25 #include "StFmsSimulatorMaker.h"
26 
27 ClassImp(StFmsSimulatorMaker);
28 
29 int StFmsSimulatorMaker::getDetectorId(int ew, int nstb) const
30 {
31  /* Detector Name detectorId ew ns type nX nY */
32  /* FPD-North 0 0 0 0 7 7 */
33  /* FPD-South 1 0 1 0 7 7 */
34  /* FPD-North-Pres 2 0 0 1 7 1 */
35  /* FPD-South-Pres 3 0 1 1 7 1 */
36  /* FPD-North-SMDV 4 0 0 2 48 1 */
37  /* FPD-South-SMDV 5 0 1 2 48 1 */
38  /* FPD-North-SMDH 6 0 0 3 1 48 */
39  /* FPD-South-SMDH 7 0 1 3 1 48 */
40  /* FMS-North-Large 8 1 0 4 17 34 */
41  /* FMS-South-Large 9 1 1 4 17 34 */
42  /* FMS-North-Small 10 1 0 4 12 24 */
43  /* FMS-South-Small 11 1 1 4 12 24 */
44  /* FHC-North 12 1 0 5 9 12 */
45  /* FHC-South 13 1 1 5 9 12 */
46 
47  switch (ew) {
48  case 1: // fpd
49  switch (nstb) {
50  case 1: return 0; // north
51  case 2: return 1; // south
52  case 5: return 2; // preshower north
53  case 6: return 3; // preshower south
54  }
55  break;
56  case 2: // fms
57  switch (nstb) {
58  case 1: return 8; // north large cells
59  case 2: return 9; // south large cells
60  case 3: return 10; // north small cells
61  case 4: return 11; // south small cells
62  }
63  break;
64  }
65  return -1;
66 }
67 
68 StFmsHit* StFmsSimulatorMaker::makeFmsHit(const StMcCalorimeterHit* hit) const
69 {
70  const int MAX_ADC = 4095;
71  const int ew = hit->module();
72  const int nstb = hit->sub();
73  const int channel = hit->eta();
74  int detectorId = getDetectorId(ew,nstb);
75  int qtCrate, qtSlot, qtChannel;
76  mFmsDbMaker->getMap(detectorId,channel,&qtCrate,&qtSlot,&qtChannel);
77  float gain = mFmsDbMaker->getGain(detectorId,channel);
78  float gainCorrection = mFmsDbMaker->getGainCorrection(detectorId,channel);
79  int adc = int(hit->dE()/(gain*gainCorrection)+0.5);
80  if (adc < 0) adc = 0; // underflow
81  if (adc > MAX_ADC) adc = MAX_ADC; // overflow
82  int tdc = 0;
83  float energy = adc*gain*gainCorrection;
84  return new StFmsHit(detectorId,channel,qtCrate,qtSlot,qtChannel,adc,tdc,energy);
85 }
86 
88 {
89  // Get StMcEvent
90  StMcEvent* mcEvent = (StMcEvent*)GetDataSet("StMcEvent");
91  if (!mcEvent) {
92  LOG_ERROR << "No StMcEvent" << endm;
93  return kStErr;
94  }
95 
96  // Nothing to do
97  if (!mcEvent->fpdHitCollection()) return kStOk;
98 
99  // Get StEvent
100  StEvent* event = (StEvent*)GetDataSet("StEvent");
101  if (!event) {
102  event = new StEvent;
103  AddData(event);
104  }
105 
106  // Get FMS collection
107  if (!event->fmsCollection()) event->setFmsCollection(new StFmsCollection);
108 
109  mFmsDbMaker = static_cast<StFmsDbMaker*>(GetMaker("fmsDb"));
110  if(!mFmsDbMaker){
111  LOG_ERROR << "No StFmsDbMaker" << endm;
112  return kStErr;
113  }
114 
115  // Digitize GEANT FPD/FMS hits
116  fillStEvent(mcEvent,event);
117  printStEventSummary(event);
118 
119  return kStOk;
120 }
121 
122 void StFmsSimulatorMaker::fillStEvent(const StMcEvent* mcEvent, StEvent* event)
123 {
124  for (size_t m = 1; m <= mcEvent->fpdHitCollection()->numberOfModules(); ++m) {
125  const StMcEmcModuleHitCollection* module = mcEvent->fpdHitCollection()->module(m);
126  if (module)
127  for (size_t i = 0; i < module->detectorHits().size(); ++i)
128  event->fmsCollection()->addHit(makeFmsHit(module->detectorHits()[i]));
129  }
130 }
131 
132 void StFmsSimulatorMaker::printStEventSummary(const StEvent* event)
133 {
134  // Summarize number of hits and energy per detector
135  const int NDETECTORS = 14;
136  const char* detectorNames[NDETECTORS] = { "FPD-North ", "FPD-South", "FPD-North-Pres", "FPD-South-Pres", "FPD-North-SMDV", "FPD-South-SMDV", "FPD-North-SMDH", "FPD-South-SMDH", "FMS-North-Large", "FMS-South-Large", "FMS-North-Small", "FMS-South-Small", "FHC-North", "FHC-South" };
137  int nhits[NDETECTORS];
138  float detectorEnergy[NDETECTORS];
139 
140  // Zero
141  fill(nhits,nhits+NDETECTORS,0);
142  fill(detectorEnergy,detectorEnergy+NDETECTORS,0.);
143 
144  // Sum number of hits and energies
145  const StSPtrVecFmsHit& hits = event->fmsCollection()->hits();
146  for (size_t i = 0; i < hits.size(); ++i) {
147  const StFmsHit* hit = hits[i];
148  if (Debug()) hit->print();
149  ++nhits[hit->detectorId()];
150  detectorEnergy[hit->detectorId()] += hit->energy();
151  }
152 
153  // Print detectors summary
154  LOG_INFO << "ID\tNAME\t\tNHITS\tENERGY" << endm;
155  for (int detectorId = 0; detectorId < NDETECTORS; ++detectorId) {
156  LOG_INFO << detectorId << '\t' << detectorNames[detectorId] << '\t' << nhits[detectorId] << '\t' << detectorEnergy[detectorId] << endm;
157  }
158 }
Float_t getGainCorrection(Int_t detectorId, Int_t ch) const
get the gain for the channel
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
Definition: StMaker.cxx:332
Definition: Stypes.h:44
Event data structure to hold all information from a Monte Carlo simulation. This class is the interfa...
Definition: StMcEvent.hh:169
Definition: Stypes.h:41