All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
icaruscode/icaruscode/CRT/CRTDetSim_module.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 /// Class: CRTDetSim
3 /// Module Type: producer
4 /// \file CRTDetSim_module.cc
5 ///
6 /// Based on LArIAT TOFSimDigits.cc (Author: Lucas Mendes Santos)
7 /// with modifications for SBND (Author: mastbaum@uchicago.edu)
8 /// then modified for ICARUS
9 ///
10 /// Author: Chris.Hilgenberg@colostate.edu
11 ///
12 /// Extracts position, time, and energy deposited, aint with
13 /// trackID associated with deposit from AuxDetSimChannel objects
14 /// produced by G4 stage. The trackID is used for truth matching.
15 /// Simulated CRT data products are intended to match the known
16 /// front-end electronics behavior and basic DAQ format anticipated.
17 /// Each hit strip is assigned a channel and associated with
18 // 1) T0 - hit time relative to t0 (beam signal)
19 // 2) T1 - hit time relative to PPS from GPS
20 // 3) ADC from hit
21 /// Effects included are
22 /// * time
23 /// - light propegation delay in scintillator and WLS fiber
24 /// - smearing in the arrival time at the SiPM due to scattering
25 /// - amplitude dependant smearing due to the discriminator
26 /// * position
27 /// - AuxDetSimChannel provides true entry and exit point in scintillator strip
28 /// - take arithmetic mean as true "hit" position
29 /// - "hit" position defines transverse distance (hit to fiber) and
30 /// intitudinal distance (length of WLS fiber between fiber entry and SiPM)
31 /// * energy deposited
32 /// - take true energy deposited in scintillator strip
33 /// - convert true energy to photons yielded (taken from measurements on
34 /// normally incident MIP muons
35 /// - using known attenuation lengths for bulk scinillator and WLS fiber,
36 /// apply attenuation correction using transverse and intitudinal
37 /// propegation distances respectively and a simple exponential model
38 /// - for the attenuated light arriving at the SiPM, correct for counting
39 /// statistics sampling from Poisson
40 /// - convert N photons seen by SiPM into ADCs using known pedestal and
41 /// gain values for each channel (assumed all the same for now)
42 /// ADC_i = gain_i * nphotons + ped_i
43 /// - smear ADC using guasian with ADC_i as mean and
44 /// width = width_pedestal+sqrt(nphotons)
45 /// * front-end electonics deadtime
46 /// - sort vector of data products by time (T0)
47 /// - for C and D type modules, intermodule coincidence is applied
48 /// - one strip from each of 2 layers must be above threshold
49 /// - for M modules, only one channel is required to be above threshold
50 /// - the earliest channel that was part of the trigger provides the T0
51 /// defining the readout window (set in FHiCL)
52 /// - for each channel in the readout window with an entry above threshold,
53 /// the data (charge and time) is added the "track and hold list"
54 /// - channels in track and hold do not accept new data during the readout window
55 /// - after the readout window has passed, no channels can receive data until the
56 /// (FHiCL congifurable) deadtime has passed. Channels are then reset and
57 /// the front-end board is again able to trigger
58 ///
59 /////////////////////////////////////////////////////////////////////////////////////////
60 
61 //art includes
62 #include "art/Framework/Core/EDProducer.h"
63 #include "art/Framework/Core/ModuleMacros.h"
64 #include "art/Framework/Principal/Event.h"
65 #include "art/Framework/Principal/Handle.h"
66 #include "fhiclcpp/ParameterSet.h"
67 #include "messagefacility/MessageLogger/MessageLogger.h"
68 #include "nurandom/RandomUtils/NuRandomService.h"
69 #include "canvas/Persistency/Common/Ptr.h"
70 #include "canvas/Persistency/Common/PtrVector.h"
71 #include "canvas/Persistency/Common/Assns.h"
72 #include "art/Persistency/Common/PtrMaker.h"
73 
74 //larsoft includes
82 
83 //ROOT includes
84 #include "TFile.h"
85 #include "TNtuple.h"
86 
87 //C++ includes
88 #include <cmath>
89 #include <memory>
90 #include <string>
91 #include <utility>
92 #include <map>
93 #include <vector>
94 
95 //CRT includes
99 
100 using std::string;
101 using std::vector;
102 
103 namespace icarus {
104  namespace crt {
105  class CRTDetSim;
106  }
107 }
108 
109 class icarus::crt::CRTDetSim : public art::EDProducer {
110 
111  public:
112  explicit CRTDetSim(fhicl::ParameterSet const & p);
113 
114  CRTDetSim(CRTDetSim const &) = delete;
115  CRTDetSim(CRTDetSim &&) = delete;
116  CRTDetSim& operator = (CRTDetSim const &) = delete;
117  CRTDetSim& operator = (CRTDetSim &&) = delete;
118  void reconfigure(fhicl::ParameterSet const & p);
119 
120  void produce(art::Event & e) override;
122 
123  private:
124 
125  CLHEP::HepRandomEngine& fRandEngine;
127 
128 }; //class CRTDetSim
129 
130 //getting parameter values from FHiCL
131 void icarus::crt::CRTDetSim::reconfigure(fhicl::ParameterSet const & p) {
132  fG4ModuleLabel = p.get<std::string>("G4ModuleLabel");
133 }//CRTDetSim::reconfigure()
134 
135 // constructor
136 icarus::crt::CRTDetSim::CRTDetSim(fhicl::ParameterSet const & p) : EDProducer{p},
137  fRandEngine(art::ServiceHandle<rndm::NuRandomService>()->createEngine(*this, "HepJamesRandom", "crt", p, "Seed")),
138  detAlg(p.get<fhicl::ParameterSet>("DetSimAlg"),fRandEngine)
139 {
140  this->reconfigure(p);
141 
142  produces< vector<CRTData> >();
143  produces< vector<sim::AuxDetIDE> >();
144  produces< art::Assns<CRTData, sim::AuxDetIDE> >();
145 }
146 
147 //module producer
148 void icarus::crt::CRTDetSim::produce(art::Event& event) {
149 
150  //pointer to vector of CRT data products to be pushed to event
151  std::unique_ptr< vector<CRTData> > triggeredCRTHits (
152  new vector<CRTData>);
153  //pointer to vector of AuxDetIDE products to be pushed to event
154  std::unique_ptr< vector<sim::AuxDetIDE> > ides (
155  new vector<sim::AuxDetIDE>);
156  //pointer associations between CRT data products and AuxDetIDEs to be pushed to event
157  std::unique_ptr< art::Assns<CRTData,sim::AuxDetIDE> > dataAssn (
158  new art::Assns<CRTData,sim::AuxDetIDE> );
159  art::PtrMaker<CRTData> makeDataPtr(event);
160  art::PtrMaker<sim::AuxDetIDE> makeIDEPtr(event);
161 
162  //clear detAlg member data
163  detAlg.ClearTaggers();
164 
165  // Handle for (truth) AuxDetSimChannels
166  art::Handle< vector<sim::AuxDetSimChannel> > adChanHandle;;
167  vector< art::Ptr<sim::AuxDetSimChannel> > adChanList;
168  if (event.getByLabel(fG4ModuleLabel, adChanHandle) )
169  art::fill_ptr_vector(adChanList, adChanHandle);
170 
171  mf::LogInfo("CRTDetSimProducer")
172  <<"Number of AuxDetChannels = " << adChanList.size();
173 
174  int nide=0;
175  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService>()->DataFor(event);
176  for(auto const& adsc : adChanList) {
177 
178  auto const& auxDetIDEs = adsc->AuxDetIDEs();
179  if(auxDetIDEs.size()>0) {
180  nide++;
181  detAlg.FillTaggers(clockData, adsc->AuxDetID(), adsc->AuxDetSensitiveID(), auxDetIDEs);
182  }
183 
184  }//loop over AuxDetSimChannels
185 
186  //generate CRTData products, associates from filled detAlg member data
187  int nData = 0;
188  if(nide>0) {
189  vector<std::pair<CRTData,vector<sim::AuxDetIDE>>> data = detAlg.CreateData();
190  //time sort CRT data (ascending)
191  std::sort(data.begin(),data.end(),
192  [](const std::pair<CRTData,vector<sim::AuxDetIDE>>& d1,
193  const std::pair<CRTData,vector<sim::AuxDetIDE>>& d2) {
194  return d1.first.fTs0 < d2.first.fTs0;
195  });
196 
197  for(auto const& dataPair : data){
198 
199  triggeredCRTHits->push_back(dataPair.first);
200  art::Ptr<CRTData> dataPtr = makeDataPtr(triggeredCRTHits->size()-1);
201  nData++;
202 
203  for(auto const& ide : dataPair.second){
204  ides->push_back(ide);
205  art::Ptr<sim::AuxDetIDE> idePtr = makeIDEPtr(ides->size()-1);
206  dataAssn->addSingle(dataPtr, idePtr);
207  }
208  }
209 
210  }
211 
212  if(nData==0)
213  mf::LogWarning("CRTDetSimProducer")
214  << "0 CRTData produced (expected for most neutrino events, never for cosmics)";
215 
216  //push products to event
217  event.put(std::move(triggeredCRTHits));
218  event.put(std::move(ides));
219  event.put(std::move(dataAssn));
220 
221  mf::LogInfo("CRTDetSimProducer")
222  << "Number of CRT data produced = "<< nData << '\n'
223  << " from " << nide << " AuxDetIDEs";
224 }
225 
226 DEFINE_ART_MODULE(icarus::crt::CRTDetSim)
Functions to help with numbers.
pdgs p
Definition: selectors.fcl:22
for pfile in ack l reconfigure(.*) override"` do echo "checking $
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
object containing MC truth information necessary for making RawDigits and doing back tracking ...
art framework interface to geometry description for auxiliary detectors
Encapsulate the geometry of an auxiliary detector.
void reconfigure(fhicl::ParameterSet const &p)
CRTDetSim & operator=(CRTDetSim const &)=delete
do i e
Class def header for a class ElecClock.
process_name crt
art framework interface to geometry description