All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbndcode/sbndcode/CRT/CRTSimulation/CRTDetSimAlg.h
Go to the documentation of this file.
1 /**
2  * \brief Class for SBND CRT detector simulation.
3  *
4  * \details This class performs the SBND CRT detector simulation starting from AuxDetSimChannels.
5  * Each AuxDetSimChannel can be passed to this class by calling method FillTaggers for each
6  * AuxDetSimChannel. Then, the CreateData method performs the CRT detector simulation
7  * (time and charge responde, and triggering).
8  *
9  * \author Andy Mastbaum
10  * \author Marco Del Tutto
11  */
12 
13 #ifndef SBND_CRTDETSIMALG_H
14 #define SBND_CRTDETSIMALG_H
15 
16 // art includes
17 #include "fhiclcpp/ParameterSet.h"
18 #include "art/Framework/Services/Registry/ServiceHandle.h"
19 
20 // larsoft includes
26 #include "messagefacility/MessageLogger/MessageLogger.h"
27 
28 // CLHEP includes
29 #include "CLHEP/Random/RandomEngine.h"
30 #include "CLHEP/Random/RandFlat.h"
31 #include "CLHEP/Random/RandGauss.h"
32 #include "CLHEP/Random/RandPoisson.h"
33 
34 //C++ includes
35 #include <cmath>
36 #include <map>
37 #include <set>
38 #include <vector>
39 #include <string>
40 #include <utility>
41 #include <algorithm>
42 
43 // ROOT includes
44 #include "TGeoManager.h"
45 #include "TGeoNode.h"
46 #include "Math/Interpolator.h"
47 
48 // CRT includes
51 #include "CRTDetSimParams.h"
52 
53 using std::vector;
54 using std::pair;
55 using std::map;
56 using std::set;
57 using std::string;
58 using sim::AuxDetIDE;
59 
60 namespace sbnd {
61  namespace crt {
62  class CRTDetSimAlg;
63  struct SiPMData;
64  struct StripData;
65  struct Tagger;
66  struct Trigger;
67  }
68 }
69 
70 /** A struct to temporarily store information on a single SiPM.
71  */
73  SiPMData(int _sipmID, int _channel, uint64_t _t0, uint64_t _t1, double _adc) :
74  sipmID(_sipmID)
75  , channel(_channel)
76  , t0(_t0)
77  , t1(_t1)
78  , adc(_adc)
79  {};
80 
81  int sipmID; ///< The SiPM ID in the strip (0-31)
82  int channel; ///< The SiPM global channel number, calculated as 32 x (module) + 2 x (strip) + j
83  uint64_t t0; ///< The SiPM Ts0
84  uint64_t t1; ///< The SiPM Ts1
85  double adc; ///< The SiPM simulated ADC value in double format
86 };
87 
88 /** A struct to temporarily store information on a single CRT Strip.
89  */
91  StripData(uint16_t _mac5, unsigned _planeID, SiPMData _sipm0, SiPMData _sipm1,
92  bool _sipm_coinc, sim::AuxDetIDE _ide) :
93  mac5(_mac5)
94  , planeID(_planeID)
95  , sipm0(_sipm0)
96  , sipm1(_sipm1)
97  , sipm_coinc(_sipm_coinc)
98  , ide(_ide)
99  {};
100 
101  uint16_t mac5; ///< The FEB number this strip is in
102  unsigned planeID; ///< The plane ID (0 or 1 for horizontal or vertical)
103  SiPMData sipm0; ///< One SiPM (the one that sees signal first)
104  SiPMData sipm1; ///< One SiPM
105  bool sipm_coinc; ///< Stores the ID of the SiPM that sees signal first (0-31)
106  sim::AuxDetIDE ide; ///< The AuxDetIDE associated with this strip
107 };
108 
109 /** A struct to temporarily store information on a CRT Tagger.
110  */
112  std::vector<StripData> data; ///< A vector of strips that have energy deposits
113 
114  /** \brief Returns the number of strips with energy deposits for this tagger */
115  int size() {return data.size();}
116 };
117 
118 
120 
121 public:
122 
123  using Parameters = fhicl::Table<CRTDetSimParams>;
124  CRTDetSimAlg(const Parameters & p, CLHEP::HepRandomEngine& fRandEngine, double g4RefTime);
125 
126  /**
127  * Function to clear member data at beginning of each art::event
128  */
129  void ClearTaggers();
130 
131 
132  /**
133  * Filles CRT taggers from AuxDetSimChannels.
134  *
135  * Intented to be called within loop over AuxDetChannels and provided the
136  * AuxDetChannelID, AuxDetSensitiveChannelID, vector of AuxDetIDEs and
137  * the number of ides from the end of the vector to include in the detector sim.
138  * It handles deposited energy ti light output at SiPM (including attenuation)
139  * and to PEs from the SiPM with associated time stamps.
140  *
141  * @param adid The AuxDetChannelID
142  * @param adsid The AuxDetSensitiveChannelID
143  * @param ides The vector of AuxDetIDE
144  */
145  void FillTaggers(const uint32_t adid, const uint32_t adsid, std::vector<AuxDetIDE> ides);
146 
147  /**
148  * Returns FEBData objects.
149  *
150  * This function is called after loop over AuxDetSimChannels where FillTaggers
151  * was used to perform first detsim step. This function applies trigger logic,
152  * deadtime, and close-in-time signal biasing effects. it produces the
153  * "triggered data" products which make it into the event. Use "GetData"
154  * to retrieve the result.
155  *
156  * @return Vector of pairs (FEBData, vector of AuxDetIDE)
157  */
158  void CreateData();
159 
160  /**
161  * Returns the simulated FEBData and AuxDetIDEs
162  *
163  * @return Vector of pairs (FEBData, vector of AuxDetIDE)
164  */
165  std::vector<std::pair<sbnd::crt::FEBData, std::vector<AuxDetIDE>>> GetData();
166 
167  /**
168  * Returns the indeces of SiPMs associated to the AuxDetIDEs
169  *
170  * @return Vector of vector (1: FEBs, 2: SiPMs indeces per AuxDetIDE)
171  */
172  std::vector<std::vector<int>> GetAuxData();
173 
174 
175  /**
176  * Get the channel trigger time relative to the start of the MC event.
177  *
178  * @param clock The clock to count ticks on
179  * @param t0 The starting time (which delay is added to)
180  * @param npe Number of observed photoelectrons
181  * @param r Distance between the energy deposit and strip readout end [mm]
182  * @return Trigger clock ticks at this true hit time
183  */
184  uint32_t getChannelTriggerTicks(/*detinfo::ElecClock& clock,*/
185  float t0, float npeMean, float r);
186 
187 
188  /**
189  * Simulated the CRT charge response. Does not include waveform emulation.
190  *
191  * @param eDep The simulated energy deposited on the strip from G4
192  * @param d0 The distance to the optical fiber connected to SiPM 0
193  * @param d1 The distance to the optical fiber connected to SiPM 1
194  * @param distToReadout The distance to the readout
195  * @param npe0 The output number of PEs for SiPM 0
196  * @param npe1 The output number of PEs for SiPM 1
197  * @param q0 The output ADC simulated value (double) for SiPM 0
198  * @param q1 The output ADC simulated value (double) for SiPM 1
199  */
200  void ChargeResponse(double eDep, double d0, double d1, double distToReadout,
201  long & npe0, long & npe1, double & q0, double & q1);
202 
203 
204  /**
205  * Emulated the CRT slow-shaped waveform. This is not a full waveform simulation,
206  * but it tries to encapsulate the main effect of the waveform, which is that the ADC
207  * counts are reduced if the signal arrives with a time delay w.r.t. the primary event
208  * trigger.
209  *
210  * @param time_delay The time delay of this SiPM signal w.r.t. the primary event trigger.
211  * @param adc The simulated ADC counts (double) of this SiPM.
212  * @return The simulated ADC counts after waveform emulation (in uint16_t format).
213  */
214  uint16_t WaveformEmulation(const uint32_t & time_delay, const double & adc);
215 
216 
217  /**
218  * Returns the CRT simulation parmeters
219  *
220  * @return The CRT simulation parameters
221  */
222  const CRTDetSimParams & Params() {return fParams;}
223 
224 
225 
226 private:
227 
228  CRTDetSimParams fParams; //!< The table of CRT simulation parameters
229 
230  CLHEP::HepRandomEngine& fEngine; //!< The random-number engine
231 
232  double fG4RefTime; //!< The G4 reference time that can be used as a time offset
233  double fTimeOffset; //!< The time that will be used in the simulation
234 
235  std::unique_ptr<ROOT::Math::Interpolator> fInterpolator; //!< The interpolator used to estimate the CRT waveform
236 
237  std::map<std::string, Tagger> fTaggers; //!< A list of hit taggers, before any coincidence requirement (name -> tagger)
238 
239  std::vector<std::pair<sbnd::crt::FEBData, std::vector<AuxDetIDE>>> fData; //!< This member stores the final FEBData for the CRT simulation
240 
241  std::vector<std::vector<int>> fAuxData; //!< This member stores the indeces of SiPM per AuxDetIDE
242 
243  /**
244  * Configures the waveform by reading waveform points from configuration and
245  * setting up the interpolator.
246  */
247  void ConfigureWaveform();
248 
249  /**
250  * Configures the time offset to use, either a custom number,
251  * of the G4RefTime, depending on user configuration.
252  */
253  void ConfigureTimeOffset();
254 
255  /**
256  * Proccesses a set of CRT strips that belong to the same trigger. This method
257  * takes as input all the strips that belong to a single CRT tagger-level trigger
258  * and constructs FEBData objects from them.
259  *
260  * @param strips The set of strips that belong to the same trigger
261  */
262  void ProcessStrips(const std::vector<StripData> & strips);
263 
264  /**
265  * Adds ADCs to a certain SiPM in a FEBData object
266  *
267  * @param feb_data The FEBData object.
268  * @param sipmID The SiPM index (0-31).
269  * @param adc ADC value to be added.
270  */
271  void AddADC(sbnd::crt::FEBData & feb_data, const int & sipmID, const uint16_t & adc);
272 
273 };
274 
275 #endif
uint32_t getChannelTriggerTicks(float t0, float npeMean, float r)
Functions to help with numbers.
void AddADC(sbnd::crt::FEBData &feb_data, const int &sipmID, const uint16_t &adc)
int channel
The SiPM global channel number, calculated as 32 x (module) + 2 x (strip) + j.
std::vector< std::pair< sbnd::crt::FEBData, std::vector< AuxDetIDE > > > GetData()
std::unique_ptr< ROOT::Math::Interpolator > fInterpolator
The interpolator used to estimate the CRT waveform.
CRTDetSimParams fParams
The table of CRT simulation parameters.
pdgs p
Definition: selectors.fcl:22
void FillTaggers(const uint32_t adid, const uint32_t adsid, std::vector< AuxDetIDE > ides)
void ProcessStrips(const std::vector< StripData > &strips)
double fG4RefTime
The G4 reference time that can be used as a time offset.
double adc
The SiPM simulated ADC value in double format.
StripData(uint16_t _mac5, unsigned _planeID, SiPMData _sipm0, SiPMData _sipm1, bool _sipm_coinc, sim::AuxDetIDE _ide)
std::vector< std::pair< sbnd::crt::FEBData, std::vector< AuxDetIDE > > > fData
This member stores the final FEBData for the CRT simulation.
unsigned planeID
The plane ID (0 or 1 for horizontal or vertical)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
SiPMData(int _sipmID, int _channel, uint64_t _t0, uint64_t _t1, double _adc)
object containing MC truth information necessary for making RawDigits and doing back tracking ...
SiPMData sipm0
One SiPM (the one that sees signal first)
std::vector< std::vector< int > > GetAuxData()
std::map< std::string, Tagger > fTaggers
A list of hit taggers, before any coincidence requirement (name -&gt; tagger)
std::vector< StripData > data
A vector of strips that have energy deposits.
art framework interface to geometry description for auxiliary detectors
void ChargeResponse(double eDep, double d0, double d1, double distToReadout, long &npe0, long &npe1, double &q0, double &q1)
sim::AuxDetIDE ide
The AuxDetIDE associated with this strip.
Encapsulate the geometry of an auxiliary detector.
int sipmID
The SiPM ID in the strip (0-31)
MC truth information to make RawDigits and do back tracking.
CLHEP::HepRandomEngine & fEngine
The random-number engine.
uint16_t mac5
The FEB number this strip is in.
stream1 can override from command line with o or output services user sbnd
CRTDetSimAlg(const Parameters &p, CLHEP::HepRandomEngine &fRandEngine, double g4RefTime)
Definition: CRTDetSimAlg.cxx:9
bool sipm_coinc
Stores the ID of the SiPM that sees signal first (0-31)
std::vector< std::vector< int > > fAuxData
This member stores the indeces of SiPM per AuxDetIDE.
process_name crt
double fTimeOffset
The time that will be used in the simulation.
esac echo uname r
int size()
Returns the number of strips with energy deposits for this tagger.
uint16_t WaveformEmulation(const uint32_t &time_delay, const double &adc)
art framework interface to geometry description