All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
hit::HitCheater Class Reference
Inheritance diagram for hit::HitCheater:

Public Member Functions

 HitCheater (fhicl::ParameterSet const &p)
 

Private Member Functions

void produce (art::Event &e) override
 
void FindHitsOnChannel (const sim::SimChannel *sc, std::vector< recob::Hit > &hits, int spill)
 

Private Attributes

std::string fG4ModuleLabel
 label name for module making sim::SimChannels More...
 
std::string fWireModuleLabel
 label name for module making recob::Wires More...
 
double fMinCharge
 Minimum charge required to make a hit. More...
 
double fElectronsToADC
 Conversion factor of electrons to ADC counts. More...
 
std::string fCalDataProductInstanceName
 label name for module making recob::Wires More...
 
int fReadOutWindowSize
 Number of samples in a readout window; NOT total samples. More...
 
int fNumberTimeSamples
 Number of total time samples (N*readoutwindowsize) More...
 
double fSamplingRate
 from detinfo::DetectorPropertiesService More...
 
int fTriggerOffset
 from detinfo::DetectorPropertiesService More...
 
int fNewHitTDCGap
 gap allowed in tdcs without charge before making a new hit More...
 

Detailed Description

Definition at line 41 of file HitCheater_module.cc.

Constructor & Destructor Documentation

hit::HitCheater::HitCheater ( fhicl::ParameterSet const &  p)
explicit

Definition at line 63 of file HitCheater_module.cc.

63  : EDProducer{p}
64 {
65  fG4ModuleLabel = p.get<std::string>("G4ModuleLabel", "largeant");
66  fWireModuleLabel = p.get<std::string>("WireModuleLabel", "caldata");
67  fMinCharge = p.get<double>("MinimumCharge", 5.);
68  fNewHitTDCGap = p.get<int>("NewHitTDCGap", 1);
69 
70  auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
71  auto const det_prop =
72  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob(clock_data);
73  fElectronsToADC = det_prop.ElectronsToADC();
74  fSamplingRate = sampling_rate(clock_data);
75  fTriggerOffset = trigger_offset(clock_data);
76 
78  size_t pos = fWireModuleLabel.find(":");
79  if (pos != std::string::npos) {
81  fWireModuleLabel = fWireModuleLabel.substr(0, pos);
82  }
83 
84  fReadOutWindowSize = det_prop.ReadOutWindowSize();
85  fNumberTimeSamples = det_prop.NumberTimeSamples();
86 
87  // let HitCollectionCreator declare that we are going to produce
88  // hits and associations with wires and raw digits
89  // (with no particular product label)
91 }
int fTriggerOffset
from detinfo::DetectorPropertiesService
double fSamplingRate
from detinfo::DetectorPropertiesService
std::string fWireModuleLabel
label name for module making recob::Wires
int fNumberTimeSamples
Number of total time samples (N*readoutwindowsize)
int fNewHitTDCGap
gap allowed in tdcs without charge before making a new hit
pdgs p
Definition: selectors.fcl:22
std::string fCalDataProductInstanceName
label name for module making recob::Wires
double fMinCharge
Minimum charge required to make a hit.
static void declare_products(art::ProducesCollector &collector, std::string instance_name="", bool doWireAssns=true, bool doRawDigitAssns=true)
Declares the hit products we are going to fill.
Definition: HitCreator.cxx:248
std::string fG4ModuleLabel
label name for module making sim::SimChannels
int fReadOutWindowSize
Number of samples in a readout window; NOT total samples.
int trigger_offset(DetectorClocksData const &data)
double fElectronsToADC
Conversion factor of electrons to ADC counts.
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.

Member Function Documentation

void hit::HitCheater::FindHitsOnChannel ( const sim::SimChannel sc,
std::vector< recob::Hit > &  hits,
int  spill 
)
private

Definition at line 156 of file HitCheater_module.cc.

159 {
160  art::ServiceHandle<geo::Geometry const> geo;
161 
162  raw::ChannelID_t channel = sc->Channel();
163  geo::SigType_t signal_type = geo->SignalType(channel);
164  geo::View_t view = geo->View(channel);
165 
166  // determine the possible geo::WireIDs for this particular channel
167  // then make a map of tdc to electrons for each one of those geo::WireIDs
168  // then find hits on each geo::WireID
169  std::vector<geo::WireID> wireids = geo->ChannelToWire(channel);
170 
171  std::map<geo::WireID, std::map<unsigned int, double>> wireIDSignals;
172 
173  auto const& idemap = sc->TDCIDEMap();
174 
175  for (auto const& mapitr : idemap) {
176  unsigned short tdc = mapitr.first;
177 
179  if (tdc < spill * fReadOutWindowSize || tdc > (spill + 1) * fReadOutWindowSize) continue;
180  }
181  else {
182  if (tdc < 0 || tdc > fReadOutWindowSize) continue;
183  }
184 
185  // figure out which TPC we are in for each voxel
186 
187  for (auto const& ideitr : mapitr.second) {
188 
189  const float edep = ideitr.numElectrons;
190 
191  std::array<double, 3> pos;
192  pos[0] = ideitr.x;
193  pos[1] = ideitr.y;
194  pos[2] = ideitr.z;
195 
196  geo::TPCID tpcID = geo->FindTPCAtPosition(pos.data());
197  if (!tpcID.isValid) {
198  mf::LogWarning("HitCheater")
199  << "TPC for position ( " << pos[0] << " ; " << pos[1] << " ; " << pos[2] << " )"
200  << " in no TPC; move on to the next sim::IDE";
201  continue;
202  }
203  const unsigned int tpc = tpcID.TPC;
204  const unsigned int cstat = tpcID.Cryostat;
205 
206  for (auto const& wid : wireids) {
207  if (wid.TPC == tpc && wid.Cryostat == cstat) {
208  // in the right TPC, now figure out which wire we want
209  // this works because there is only one plane option for
210  // each WireID in each TPC
211  if (wid.Wire == geo->NearestWire(pos.data(), wid.Plane, wid.TPC, wid.Cryostat))
212  wireIDSignals[wid][tdc] += edep;
213  } // end if in the correct TPC and Cryostat
214  } // end loop over wireids for this channel
215  } // end loop over ides for this channel
216  } // end loop over tdcs for this channel
217 
218  // now loop over each wire ID and determine where the hits are
219  for (auto const& widitr : wireIDSignals) {
220 
221  // get the first tdc in the
222  unsigned short prev = widitr.second.begin()->first;
223  unsigned short startTime = prev;
224  double totCharge = 0.;
225  double maxCharge = -1.;
226  double peakTime = 0.;
227  int multiplicity = 1;
228  lar::util::StatCollector<double> time; // reduce rounding errors
229 
230  // loop over all the tdcs for this geo::WireID
231  for (auto tdcitr : widitr.second) {
232  unsigned short tdc = tdcitr.first;
233  if (tdc < prev) {
234  throw art::Exception(art::errors::LogicError) << "SimChannel TDCs going backward!";
235  }
236 
237  // more than a one tdc gap between times with
238  // signal, start a new hit
239  if (tdc - prev > fNewHitTDCGap) {
240 
241  if (totCharge > fMinCharge) {
242  hits.emplace_back(channel, // channel
243  (raw::TDCtick_t)startTime, // start_tick
244  (raw::TDCtick_t)prev, // end_tick
245  peakTime, // peak_time
246  1., // sigma_peak_time
247  time.RMS(), // RMS
248  maxCharge, // peak_amplitude
249  std::sqrt(maxCharge), // sigma_peak_amplitude
250  totCharge, // summedADC
251  totCharge, // hit_integral
252  std::sqrt(totCharge), // hit_sigma_integral
253  multiplicity, // multiplicity
254  0, // local_index
255  1., // goodness_of_fit
256  0., // dof
257  view, // view
258  signal_type, // signal_type
259  widitr.first // wireID
260  );
261 
262  MF_LOG_DEBUG("HitCheater") << "new hit is " << hits.back();
263 
264  } // end if charge is large enough
265 
266  // reset the variables for each hit
267  startTime = tdc;
268  peakTime = tdc;
269  totCharge = 0.;
270  maxCharge = -1.;
271  time.clear();
272 
273  } // end if need to start a new hit
274 
275  const double adc = fElectronsToADC * tdcitr.second;
276 
277  totCharge += adc;
278  // use ADC as weight; the shift reduces the precision needed;
279  // average would need to be shifted back: time.Averatge() + startTime
280  // but RMS is not affected
281  time.add(tdc - startTime, adc);
282  if (adc > maxCharge) {
283  maxCharge = adc;
284  peakTime = tdc;
285  }
286 
287  prev = tdc;
288 
289  } // end loop over tdc values for the current geo::WireID
290 
291  // We might have missed the last hit, so do it now
292  if (totCharge > fMinCharge) {
293  hits.emplace_back(channel, // channel
294  (raw::TDCtick_t)startTime, // start_tick
295  (raw::TDCtick_t)prev + 1, // end_tick; prev included in the hit
296  peakTime, // peak_time
297  1., // sigma_peak_time
298  time.RMS(), // RMS
299  maxCharge, // peak_amplitude
300  std::sqrt(maxCharge), // sigma_peak_amplitude
301  totCharge, // summedADC
302  totCharge, // hit_integral
303  std::sqrt(totCharge), // hit_sigma_integral
304  multiplicity, // multiplicity
305  0, // local_index
306  1., // goodness_of_fit
307  0., // dof
308  view, // view
309  signal_type, // signal_type
310  widitr.first // wireID
311  );
312 
313  MF_LOG_DEBUG("HitCheater") << "last hit is " << hits.back();
314 
315  } // end if charge is large enough
316 
317  } // end loop over map of geo::WireID to map<tdc,electrons>
318 
319  return;
320 }
int fNumberTimeSamples
Number of total time samples (N*readoutwindowsize)
int fNewHitTDCGap
gap allowed in tdcs without charge before making a new hit
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
bool isValid
Whether this ID points to a valid element.
Definition: geo_types.h:211
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:212
Weight_t RMS() const
Returns the root mean square.
double fMinCharge
Minimum charge required to make a hit.
int TDCtick_t
Type representing a TDC tick.
Definition: RawTypes.h:25
enum geo::_plane_sigtype SigType_t
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
raw::ChannelID_t Channel() const
Returns the readout channel this object describes.
Definition: SimChannel.h:335
int fReadOutWindowSize
Number of samples in a readout window; NOT total samples.
TDCIDEs_t const & TDCIDEMap() const
Returns all the deposited energy information as stored.
Definition: SimChannel.h:334
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
double fElectronsToADC
Conversion factor of electrons to ADC counts.
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406
void clear()
Clears all the statistics.
void add(Data_t value, Weight_t weight=Weight_t(1.0))
Adds one entry with specified value and weight.
void hit::HitCheater::produce ( art::Event &  e)
overrideprivate

Definition at line 95 of file HitCheater_module.cc.

96 {
97  // this object contains the hit collection
98  // and its associations to wires and raw digits:
100 
101  // Read in the wire List object(s).
102  art::InputTag WireInputTag(fWireModuleLabel, fCalDataProductInstanceName);
103  art::ValidHandle<std::vector<recob::Wire>> wHandle =
104  e.getValidHandle<std::vector<recob::Wire>>(WireInputTag);
105 
106  int whatSpill = 1;
107  if (!fCalDataProductInstanceName.empty()) {
108  if (fCalDataProductInstanceName.find("ost") != std::string::npos)
109  whatSpill = 2;
110  else
111  whatSpill = 0;
112  }
113 
114  // also get the raw digits associated with the wires;
115  // we assume they have been created by the same module as the wires
116  art::FindOneP<raw::RawDigit> WireToRawDigits(wHandle, e, WireInputTag);
117 
118  // make a map of wires to channel numbers
119  std::map<raw::ChannelID_t, art::Ptr<recob::Wire>> wireMap;
120 
121  for (size_t wc = 0; wc < wHandle->size(); ++wc) {
122  art::Ptr<recob::Wire> wire(wHandle, wc);
123  wireMap[wire->Channel()] = wire;
124  }
125 
126  // get the sim::SimChannels out of the event
127  std::vector<const sim::SimChannel*> sccol;
128  e.getView(fG4ModuleLabel, sccol);
129 
130  // find the hits on each channel
131  for (sim::SimChannel const* sc : sccol) {
132  std::vector<recob::Hit> hits_on_channel;
133 
134  FindHitsOnChannel(sc, hits_on_channel, whatSpill);
135 
136  art::Ptr<recob::Wire> const& wire = wireMap[sc->Channel()];
137  art::Ptr<raw::RawDigit> rawdigits; // null by default
138  if (wire.isNonnull()) rawdigits = WireToRawDigits.at(wire.key());
139 
140  // add all the hits found on this channel to the data product,
141  // all associated to the same hit and wire
142  for (recob::Hit& hit : hits_on_channel)
143  hits.emplace_back(std::move(hit), wire, rawdigits);
144 
145  } // end loop over SimChannels
146 
147  // put the cheated hits into the event
148  MF_LOG_DEBUG("HitCheater") << "putting " << hits.size() << " hits into the event";
149  hits.put_into(e);
150 
151  return;
152 }
std::string fWireModuleLabel
label name for module making recob::Wires
Energy deposited on a readout channel by simulated tracks.
Definition: SimChannel.h:145
void FindHitsOnChannel(const sim::SimChannel *sc, std::vector< recob::Hit > &hits, int spill)
process_name hit
Definition: cheaterreco.fcl:51
std::string fCalDataProductInstanceName
label name for module making recob::Wires
A class handling a collection of hits and its associations.
Definition: HitCreator.h:508
std::string fG4ModuleLabel
label name for module making sim::SimChannels
do i e
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48

Member Data Documentation

std::string hit::HitCheater::fCalDataProductInstanceName
private

label name for module making recob::Wires

Definition at line 54 of file HitCheater_module.cc.

double hit::HitCheater::fElectronsToADC
private

Conversion factor of electrons to ADC counts.

Definition at line 53 of file HitCheater_module.cc.

std::string hit::HitCheater::fG4ModuleLabel
private

label name for module making sim::SimChannels

Definition at line 50 of file HitCheater_module.cc.

double hit::HitCheater::fMinCharge
private

Minimum charge required to make a hit.

Definition at line 52 of file HitCheater_module.cc.

int hit::HitCheater::fNewHitTDCGap
private

gap allowed in tdcs without charge before making a new hit

Definition at line 59 of file HitCheater_module.cc.

int hit::HitCheater::fNumberTimeSamples
private

Number of total time samples (N*readoutwindowsize)

Definition at line 56 of file HitCheater_module.cc.

int hit::HitCheater::fReadOutWindowSize
private

Number of samples in a readout window; NOT total samples.

Definition at line 55 of file HitCheater_module.cc.

double hit::HitCheater::fSamplingRate
private
int hit::HitCheater::fTriggerOffset
private
std::string hit::HitCheater::fWireModuleLabel
private

label name for module making recob::Wires

Definition at line 51 of file HitCheater_module.cc.


The documentation for this class was generated from the following file: