Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4MvtxDigitizer.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4MvtxDigitizer.cc
1 // This is the new trackbase container version
2 
3 #include "PHG4MvtxDigitizer.h"
4 
5 // Move to new storage containers
6 #include <trackbase/TrkrDefs.h>
7 #include <trackbase/TrkrHit.h> // for TrkrHit
8 #include <trackbase/TrkrHitSet.h>
11 
14 
16 #include <fun4all/SubsysReco.h> // for SubsysReco
17 
18 #include <phool/PHCompositeNode.h>
19 #include <phool/PHNode.h> // for PHNode
20 #include <phool/PHNodeIterator.h>
21 #include <phool/PHRandomSeed.h>
22 #include <phool/getClass.h>
23 #include <phool/phool.h> // for PHWHERE
24 
25 #include <gsl/gsl_rng.h> // for gsl_rng_alloc
26 
27 #include <cstdlib> // for exit
28 #include <iostream>
29 #include <set>
30 
32  : SubsysReco(name)
33  , _energy_threshold(0.95e-6)
34 {
35  unsigned int seed = PHRandomSeed(); // fixed seed is handled in this funtcion
36  std::cout << Name() << " random seed: " << seed << std::endl;
37  RandomGenerator = gsl_rng_alloc(gsl_rng_mt19937);
39 
40  if (Verbosity() > 0)
41  {
42  std::cout << "Creating PHG4MvtxDigitizer with name = " << name << std::endl;
43  }
44 }
45 
47 {
48  gsl_rng_free(RandomGenerator);
49 }
50 
52 {
53  //-------------
54  // Add Hit Node
55  //-------------
56  PHNodeIterator iter(topNode);
57 
58  // Looking for the DST node
59  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
60  if (!dstNode)
61  {
62  std::cout << PHWHERE << "DST Node missing, doing nothing." << std::endl;
64  }
65 
67 
68  //----------------
69  // Report Settings
70  //----------------
71 
72  if (Verbosity() > 0)
73  {
74  std::cout << "====================== PHG4MvtxDigitizer::InitRun() =====================" << std::endl;
75  for (auto &miter : _max_adc)
76  {
77  std::cout << " Max ADC in Layer #" << miter.first << " = " << miter.second << std::endl;
78  }
79  for (auto &miter : _energy_scale)
80  {
81  std::cout << " Energy per ADC in Layer #" << miter.first << " = " << 1.0e6 * miter.second << " keV" << std::endl;
82  }
83  std::cout << "===========================================================================" << std::endl;
84  }
85 
87 }
88 
90 {
91  // This code now only does the Mvtx
92  DigitizeMvtxLadderCells(topNode);
93 
95 }
96 
98 {
99  // defaults to 8-bit ADC, short-axis MIP placed at 1/4 dynamic range
100 
101  PHG4CylinderGeomContainer *geom_container = findNode::getClass<PHG4CylinderGeomContainer>(topNode, "CYLINDERGEOM_MVTX");
102 
103  if (!geom_container)
104  {
105  return;
106  }
107 
108  if (Verbosity())
109  {
110  std::cout << "Found CYLINDERGEOM_MVTX node" << std::endl;
111  }
112 
113  PHG4CylinderGeomContainer::ConstRange layerrange = geom_container->get_begin_end();
114  for (PHG4CylinderGeomContainer::ConstIterator layeriter = layerrange.first;
115  layeriter != layerrange.second;
116  ++layeriter)
117  {
118  int layer = layeriter->second->get_layer();
119  float thickness = (layeriter->second)->get_pixel_thickness();
120  float pitch = (layeriter->second)->get_pixel_x();
121  float length = (layeriter->second)->get_pixel_z();
122 
123  float minpath = pitch;
124  if (length < minpath)
125  {
126  minpath = length;
127  }
128  if (thickness < minpath)
129  {
130  minpath = thickness;
131  }
132  float mip_e = 0.003876 * minpath;
133 
134  if (Verbosity())
135  {
136  std::cout << "mip_e = " << mip_e << std::endl;
137  }
138 
139  if (_max_adc.find(layer) == _max_adc.end())
140  {
141  // cppcheck-suppress stlFindInsert
142  _max_adc[layer] = 255;
143  _energy_scale[layer] = mip_e / 64;
144  }
145  }
146 
147  return;
148 }
149 
151 {
152  //----------
153  // Get Nodes
154  //----------
155 
156  // new containers
157  //=============
158  // Get the TrkrHitSetContainer node
159  TrkrHitSetContainer *trkrhitsetcontainer = findNode::getClass<TrkrHitSetContainer>(topNode, "TRKR_HITSET");
160  if (!trkrhitsetcontainer)
161  {
162  std::cout << "Could not locate TRKR_HITSET node, quit! " << std::endl;
163  exit(1);
164  }
165 
166  // Get the TrkrHitTruthAssoc node
167  auto hittruthassoc = findNode::getClass<TrkrHitTruthAssoc>(topNode, "TRKR_HITTRUTHASSOC");
168 
169  // Digitization
170 
171  // We want all hitsets for the Mvtx
172  TrkrHitSetContainer::ConstRange hitset_range = trkrhitsetcontainer->getHitSets(TrkrDefs::TrkrId::mvtxId);
173  for (TrkrHitSetContainer::ConstIterator hitset_iter = hitset_range.first;
174  hitset_iter != hitset_range.second;
175  ++hitset_iter)
176  {
177  // we have an itrator to one TrkrHitSet for the mvtx from the trkrHitSetContainer
178  // get the hitset key so we can find the layer
179  TrkrDefs::hitsetkey hitsetkey = hitset_iter->first;
180  int layer = TrkrDefs::getLayer(hitsetkey);
181  if (Verbosity() > 1)
182  {
183  std::cout << "PHG4MvtxDigitizer: found hitset with key: " << hitsetkey << " in layer " << layer << std::endl;
184  }
185 
186  // get all of the hits from this hitset
187  TrkrHitSet *hitset = hitset_iter->second;
188  TrkrHitSet::ConstRange hit_range = hitset->getHits();
189  std::set<TrkrDefs::hitkey> hits_rm;
190  for (TrkrHitSet::ConstIterator hit_iter = hit_range.first;
191  hit_iter != hit_range.second;
192  ++hit_iter)
193  {
194  TrkrHit *hit = hit_iter->second;
195 
196  // Convert the signal value to an ADC value and write that to the hit
197  // unsigned int adc = hit->getEnergy() / (TrkrDefs::MvtxEnergyScaleup *_energy_scale[layer]);
198  if (Verbosity() > 0)
199  {
200  std::cout << " PHG4MvtxDigitizer: found hit with key: " << hit_iter->first << " and signal " << hit->getEnergy() / TrkrDefs::MvtxEnergyScaleup << " in layer " << layer << std::endl;
201  }
202  // Remove the hits with energy under threshold
203  bool rm_hit = false;
204  if ((hit->getEnergy() / TrkrDefs::MvtxEnergyScaleup) < _energy_threshold)
205  {
206  if (Verbosity() > 0)
207  {
208  std::cout << " remove hit, below energy threshold of " << _energy_threshold << std::endl;
209  }
210  rm_hit = true;
211  }
212  unsigned short adc = (unsigned short) (hit->getEnergy() / (TrkrDefs::MvtxEnergyScaleup * _energy_scale[layer]));
213  if (adc > _max_adc[layer])
214  {
215  adc = _max_adc[layer];
216  }
217  hit->setAdc(adc);
218 
219  if (rm_hit)
220  {
221  hits_rm.insert(hit_iter->first);
222  }
223  }
224 
225  for (const auto &key : hits_rm)
226  {
227  if (Verbosity() > 0)
228  {
229  std::cout << " PHG4MvtxDigitizer: remove hit with key: " << key << std::endl;
230  }
231  hitset->removeHit(key);
232  if (hittruthassoc)
233  {
234  hittruthassoc->removeAssoc(hitsetkey, key);
235  }
236  }
237  }
238 
239  // end new containers
240  //===============
241 
242  return;
243 }