15 #include "art/Framework/Core/EDProducer.h"
16 #include "art/Framework/Core/ModuleMacros.h"
17 #include "art/Framework/Principal/Event.h"
18 #include "art/Framework/Services/Registry/ServiceHandle.h"
19 #include "canvas/Persistency/Common/FindOneP.h"
20 #include "canvas/Utilities/Exception.h"
21 #include "canvas/Utilities/InputTag.h"
22 #include "cetlib_except/exception.h"
23 #include "messagefacility/MessageLogger/MessageLogger.h"
46 void produce(art::Event&
e)
override;
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);
70 auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
72 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob(clock_data);
73 fElectronsToADC = det_prop.ElectronsToADC();
77 fCalDataProductInstanceName =
"";
78 size_t pos = fWireModuleLabel.find(
":");
79 if (pos != std::string::npos) {
80 fCalDataProductInstanceName = fWireModuleLabel.substr(pos + 1);
81 fWireModuleLabel = fWireModuleLabel.substr(0, pos);
84 fReadOutWindowSize = det_prop.ReadOutWindowSize();
85 fNumberTimeSamples = det_prop.NumberTimeSamples();
102 art::InputTag WireInputTag(fWireModuleLabel, fCalDataProductInstanceName);
103 art::ValidHandle<std::vector<recob::Wire>> wHandle =
104 e.getValidHandle<std::vector<recob::Wire>>(WireInputTag);
107 if (!fCalDataProductInstanceName.empty()) {
108 if (fCalDataProductInstanceName.find(
"ost") != std::string::npos)
116 art::FindOneP<raw::RawDigit> WireToRawDigits(wHandle, e, WireInputTag);
119 std::map<raw::ChannelID_t, art::Ptr<recob::Wire>> wireMap;
121 for (
size_t wc = 0; wc < wHandle->size(); ++wc) {
122 art::Ptr<recob::Wire> wire(wHandle, wc);
123 wireMap[wire->Channel()] = wire;
127 std::vector<const sim::SimChannel*> sccol;
128 e.getView(fG4ModuleLabel, sccol);
132 std::vector<recob::Hit> hits_on_channel;
134 FindHitsOnChannel(sc, hits_on_channel, whatSpill);
136 art::Ptr<recob::Wire>
const& wire = wireMap[sc->Channel()];
137 art::Ptr<raw::RawDigit> rawdigits;
138 if (wire.isNonnull()) rawdigits = WireToRawDigits.at(wire.key());
148 MF_LOG_DEBUG(
"HitCheater") <<
"putting " << hits.
size() <<
" hits into the event";
157 std::vector<recob::Hit>& hits,
160 art::ServiceHandle<geo::Geometry const> geo;
169 std::vector<geo::WireID> wireids = geo->ChannelToWire(channel);
171 std::map<geo::WireID, std::map<unsigned int, double>> wireIDSignals;
175 for (
auto const& mapitr : idemap) {
176 unsigned short tdc = mapitr.first;
178 if (fReadOutWindowSize != fNumberTimeSamples) {
179 if (tdc < spill * fReadOutWindowSize || tdc > (spill + 1) * fReadOutWindowSize)
continue;
182 if (tdc < 0 || tdc > fReadOutWindowSize)
continue;
187 for (
auto const& ideitr : mapitr.second) {
189 const float edep = ideitr.numElectrons;
191 std::array<double, 3> pos;
196 geo::TPCID tpcID = geo->FindTPCAtPosition(pos.data());
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";
203 const unsigned int tpc = tpcID.
TPC;
204 const unsigned int cstat = tpcID.
Cryostat;
206 for (
auto const& wid : wireids) {
207 if (wid.TPC == tpc && wid.Cryostat == cstat) {
211 if (wid.Wire == geo->NearestWire(pos.data(), wid.Plane, wid.TPC, wid.Cryostat))
212 wireIDSignals[wid][tdc] += edep;
219 for (
auto const& widitr : wireIDSignals) {
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;
231 for (
auto tdcitr : widitr.second) {
232 unsigned short tdc = tdcitr.first;
234 throw art::Exception(art::errors::LogicError) <<
"SimChannel TDCs going backward!";
239 if (tdc - prev > fNewHitTDCGap) {
241 if (totCharge > fMinCharge) {
242 hits.emplace_back(channel,
249 std::sqrt(maxCharge),
252 std::sqrt(totCharge),
262 MF_LOG_DEBUG(
"HitCheater") <<
"new hit is " << hits.back();
275 const double adc = fElectronsToADC * tdcitr.second;
281 time.
add(tdc - startTime, adc);
282 if (adc > maxCharge) {
292 if (totCharge > fMinCharge) {
293 hits.emplace_back(channel,
300 std::sqrt(maxCharge),
303 std::sqrt(totCharge),
313 MF_LOG_DEBUG(
"HitCheater") <<
"last hit is " << hits.back();
int fTriggerOffset
from detinfo::DetectorPropertiesService
double fSamplingRate
from detinfo::DetectorPropertiesService
std::string fWireModuleLabel
label name for module making recob::Wires
Energy deposited on a readout channel by simulated tracks.
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.
void FindHitsOnChannel(const sim::SimChannel *sc, std::vector< recob::Hit > &hits, int spill)
Declaration of signal hit object.
bool isValid
Whether this ID points to a valid element.
CryostatID_t Cryostat
Index of cryostat.
Definition of basic raw digits.
std::string fCalDataProductInstanceName
label name for module making recob::Wires
Classes gathering simple statistics.
Weight_t RMS() const
Returns the root mean square.
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.
int TDCtick_t
Type representing a TDC tick.
Helper functions to create a hit.
A class handling a collection of hits and its associations.
std::string fG4ModuleLabel
label name for module making sim::SimChannels
enum geo::_plane_sigtype SigType_t
void emplace_back(recob::Hit &&hit, art::Ptr< recob::Wire > const &wire=art::Ptr< recob::Wire >(), art::Ptr< raw::RawDigit > const &digits=art::Ptr< raw::RawDigit >())
Adds the specified hit to the data collection.
The data type to uniquely identify a TPC.
Definition of data types for geometry description.
void put_into(art::Event &)
Moves the data into an event.
raw::ChannelID_t Channel() const
Returns the readout channel this object describes.
size_t size() const
Returns the number of hits currently in the collection.
int fReadOutWindowSize
Number of samples in a readout window; NOT total samples.
object containing MC truth information necessary for making RawDigits and doing back tracking ...
void produce(art::Event &e) override
int trigger_offset(DetectorClocksData const &data)
HitCheater(fhicl::ParameterSet const &p)
Declaration of basic channel signal object.
TDCIDEs_t const & TDCIDEMap() const
Returns all the deposited energy information as stored.
2D representation of charge deposited in the TDC/wire plane
unsigned int ChannelID_t
Type representing the ID of a readout channel.
double fElectronsToADC
Conversion factor of electrons to ADC counts.
TPCID_t TPC
Index of the TPC within its cryostat.
void clear()
Clears all the statistics.
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
art framework interface to geometry description
void add(Data_t value, Weight_t weight=Weight_t(1.0))
Adds one entry with specified value and weight.