ECCE @ EIC 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/TrkrHitv2.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 
31 using namespace std;
32 
34  : SubsysReco(name)
35  , _energy_threshold(0.95e-6)
36 {
37  unsigned int seed = PHRandomSeed(); // fixed seed is handled in this funtcion
38  cout << Name() << " random seed: " << seed << endl;
39  RandomGenerator = gsl_rng_alloc(gsl_rng_mt19937);
40  gsl_rng_set(RandomGenerator, seed);
41 
42  if (Verbosity() > 0)
43  cout << "Creating PHG4MvtxDigitizer with name = " << name << endl;
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  cout << PHWHERE << "DST Node missing, doing nothing." << endl;
64  }
65 
67 
68  //----------------
69  // Report Settings
70  //----------------
71 
72  if (Verbosity() > 0)
73  {
74  cout << "====================== PHG4MvtxDigitizer::InitRun() =====================" << endl;
75  for (std::map<int, unsigned short>::iterator iter = _max_adc.begin();
76  iter != _max_adc.end();
77  ++iter)
78  {
79  cout << " Max ADC in Layer #" << iter->first << " = " << iter->second << endl;
80  }
81  for (std::map<int, float>::iterator iter = _energy_scale.begin();
82  iter != _energy_scale.end();
83  ++iter)
84  {
85  cout << " Energy per ADC in Layer #" << iter->first << " = " << 1.0e6 * iter->second << " keV" << endl;
86  }
87  cout << "===========================================================================" << endl;
88  }
89 
91 }
92 
94 {
95  // This code now only does the Mvtx
96  DigitizeMvtxLadderCells(topNode);
97 
99 }
100 
102 {
103  // defaults to 8-bit ADC, short-axis MIP placed at 1/4 dynamic range
104 
105  PHG4CylinderGeomContainer *geom_container = findNode::getClass<PHG4CylinderGeomContainer>(topNode, "CYLINDERGEOM_MVTX");
106 
107  if (!geom_container) return;
108 
109  if (Verbosity())
110  cout << "Found CYLINDERGEOM_MVTX node" << endl;
111 
112  PHG4CylinderGeomContainer::ConstRange layerrange = geom_container->get_begin_end();
113  for (PHG4CylinderGeomContainer::ConstIterator layeriter = layerrange.first;
114  layeriter != layerrange.second;
115  ++layeriter)
116  {
117  int layer = layeriter->second->get_layer();
118  float thickness = (layeriter->second)->get_pixel_thickness();
119  float pitch = (layeriter->second)->get_pixel_x();
120  float length = (layeriter->second)->get_pixel_z();
121 
122  float minpath = pitch;
123  if (length < minpath) minpath = length;
124  if (thickness < minpath) minpath = thickness;
125  float mip_e = 0.003876 * minpath;
126 
127  if (Verbosity())
128  cout << "mip_e = " << mip_e << endl;
129 
130  if (_max_adc.find(layer) == _max_adc.end())
131  {
132  _max_adc[layer] = 255;
133  _energy_scale[layer] = mip_e / 64;
134  }
135  }
136 
137  return;
138 }
139 
141 {
142  //----------
143  // Get Nodes
144  //----------
145 
146  // new containers
147  //=============
148  // Get the TrkrHitSetContainer node
149  TrkrHitSetContainer *trkrhitsetcontainer = findNode::getClass<TrkrHitSetContainer>(topNode, "TRKR_HITSET");
150  if (!trkrhitsetcontainer)
151  {
152  cout << "Could not locate TRKR_HITSET node, quit! " << endl;
153  exit(1);
154  }
155 
156  // Get the TrkrHitTruthAssoc node
157  auto hittruthassoc = findNode::getClass<TrkrHitTruthAssoc>(topNode, "TRKR_HITTRUTHASSOC");
158 
159  // Digitization
160 
161  // We want all hitsets for the Mvtx
162  TrkrHitSetContainer::ConstRange hitset_range = trkrhitsetcontainer->getHitSets(TrkrDefs::TrkrId::mvtxId);
163  for (TrkrHitSetContainer::ConstIterator hitset_iter = hitset_range.first;
164  hitset_iter != hitset_range.second;
165  ++hitset_iter)
166  {
167  // we have an itrator to one TrkrHitSet for the mvtx from the trkrHitSetContainer
168  // get the hitset key so we can find the layer
169  TrkrDefs::hitsetkey hitsetkey = hitset_iter->first;
170  int layer = TrkrDefs::getLayer(hitsetkey);
171  if (Verbosity() > 1) cout << "PHG4MvtxDigitizer: found hitset with key: " << hitsetkey << " in layer " << layer << endl;
172 
173  // get all of the hits from this hitset
174  TrkrHitSet *hitset = hitset_iter->second;
175  TrkrHitSet::ConstRange hit_range = hitset->getHits();
176  std::set<TrkrDefs::hitkey> hits_rm;
177  for (TrkrHitSet::ConstIterator hit_iter = hit_range.first;
178  hit_iter != hit_range.second;
179  ++hit_iter)
180  {
181  TrkrHit *hit = hit_iter->second;
182 
183  // Convert the signal value to an ADC value and write that to the hit
184  //unsigned int adc = hit->getEnergy() / (TrkrDefs::MvtxEnergyScaleup *_energy_scale[layer]);
185  if (Verbosity() > 0)
186  cout << " PHG4MvtxDigitizer: found hit with key: " << hit_iter->first << " and signal " << hit->getEnergy() / TrkrDefs::MvtxEnergyScaleup << " in layer " << layer << std::endl;
187  // Remove the hits with energy under threshold
188  bool rm_hit = false;
189  if ( (hit->getEnergy() / TrkrDefs::MvtxEnergyScaleup) < _energy_threshold) rm_hit = true;
190 
191  unsigned short adc = (unsigned short) (hit->getEnergy() / (TrkrDefs::MvtxEnergyScaleup *_energy_scale[layer]));
192  if (adc > _max_adc[layer]) adc = _max_adc[layer];
193  hit->setAdc(adc);
194 
195  if (rm_hit) hits_rm.insert(hit_iter->first);
196  }
197 
198  for( const auto& key:hits_rm )
199  {
200  if (Verbosity() > 0) cout << " PHG4MvtxDigitizer: remove hit with key: " << key << endl;
201  hitset->removeHit(key);
202  if( hittruthassoc ) hittruthassoc->removeAssoc(hitsetkey, key);
203  }
204 
205  }
206 
207  // end new containers
208  //===============
209 
210  return;
211 }