Public Member Functions | Private Types | Private Attributes | List of all members
CRT::CRTSim Class Reference
Inheritance diagram for CRT::CRTSim:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Member Functions

 CRTSim (fhicl::ParameterSet const &p)
 
 CRTSim (CRTSim const &)=delete
 
 CRTSim (CRTSim &&)=delete
 
CRTSimoperator= (CRTSim const &)=delete
 
CRTSimoperator= (CRTSim &&)=delete
 
void produce (art::Event &e) override
 
- Public Member Functions inherited from art::EDProducer
 EDProducer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDProducer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Producer
virtual ~Producer () noexcept
 
 Producer (fhicl::ParameterSet const &)
 
 Producer (Producer const &)=delete
 
 Producer (Producer &&)=delete
 
Produceroperator= (Producer const &)=delete
 
Produceroperator= (Producer &&)=delete
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Types

typedef long long int time
 
typedef unsigned short adc_t
 

Private Attributes

art::InputTag fSimLabel
 
double fGeVToADC
 
time fIntegrationTime
 
size_t fReadoutWindowSize
 
size_t fDeadtime
 
adc_t fDACThreshold
 

Additional Inherited Members

- Public Types inherited from art::EDProducer
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
- Public Types inherited from art::detail::Producer
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 
- Static Public Member Functions inherited from art::EDProducer
static void commitEvent (EventPrincipal &ep, Event &e)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 58 of file CRTSim_module.cc.

Member Typedef Documentation

typedef unsigned short CRT::CRTSim::adc_t
private

Definition at line 89 of file CRTSim_module.cc.

typedef long long int CRT::CRTSim::time
private

Definition at line 88 of file CRTSim_module.cc.

Constructor & Destructor Documentation

CRT::CRTSim::CRTSim ( fhicl::ParameterSet const &  p)
explicit

Definition at line 118 of file CRTSim_module.cc.

118  : EDProducer{p}, fSimLabel(p.get<art::InputTag>("SimLabel")),
119  /*fScintillationYield(p.get<double>("ScintillationYield")),
120  fQuantumEff(p.get<double>("QuantumEff")),
121  fDummyGain(p.get<double>("DummyGain")),*/
122  fGeVToADC(p.get<double>("GeVToADC")),
123  fIntegrationTime(p.get<time>("IntegrationTime")),
124  fReadoutWindowSize(p.get<size_t>("ReadoutWindowSize")),
125  fDeadtime(p.get<size_t>("Deadtime")),
126  fDACThreshold(p.get<adc_t>("DACThreshold"))
127 {
128  //Tell ART that I convert std::vector<AuxDetSimChannel> to CRT::Hits associated with raw::ExternalTriggers
129  produces<std::vector<CRT::Trigger>>();
130  produces<art::Assns<sim::AuxDetSimChannel, CRT::Trigger>>();
131  consumes<std::vector<sim::AuxDetSimChannel>>(fSimLabel);
132 }
size_t fDeadtime
double fGeVToADC
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
time fIntegrationTime
unsigned short adc_t
adc_t fDACThreshold
p
Definition: test.py:223
art::InputTag fSimLabel
size_t fReadoutWindowSize
CRT::CRTSim::CRTSim ( CRTSim const &  )
delete
CRT::CRTSim::CRTSim ( CRTSim &&  )
delete

Member Function Documentation

CRTSim& CRT::CRTSim::operator= ( CRTSim const &  )
delete
CRTSim& CRT::CRTSim::operator= ( CRTSim &&  )
delete
void CRT::CRTSim::produce ( art::Event e)
overridevirtual

Implements art::EDProducer.

Definition at line 135 of file CRTSim_module.cc.

136 {
137  //Get collection of AuxDetSimChannel as input
138  auto channels = e.getValidHandle<std::vector<sim::AuxDetSimChannel>>(fSimLabel);
139 
140  //Collections of CRT::Trigger and AuxDetSimChannel-CRT::Trigger associations that I will std::move() into e at the end of produce
141  auto trigCol = std::make_unique<std::vector<CRT::Trigger>>();
142  auto simToTrigger = std::make_unique<art::Assns<sim::AuxDetSimChannel, CRT::Trigger>>();
143 
144  //Utilities to go along with making Assns
146  art::PtrMaker<CRT::Trigger> makeTrigPtr(e);
147 
148  //Get access to geometry for each event (TODO: -> subrun?) in case CRTs move later
150 
151  //Group AuxDetSimChannels by module they came from for easier access later. Storing AuxDetSimChannels as art::Ptrs so I can make Assns later.
152  //TODO: I'm spending a lot of effort and confusing code on keeping track of sim::AuxDetSimChannels for Assns at the end of this module.
153  // Are raw -> simulation Assns worth this much trouble? Can I restructure my logic somehow to make this association more natural?
154  std::map<uint32_t, art::PtrVector<sim::AuxDetSimChannel>> moduleToChannels;
155  for(size_t channelPos = 0; channelPos < channels->size(); ++channelPos)
156  {
157  const auto id = (*channels)[channelPos].AuxDetID();
158  const auto& det = geom->AuxDet(id);
159  if(det.Name().find("CRT") != std::string::npos) //If this is a CRT AuxDet
160  {
161  moduleToChannels[id].push_back(makeSimPtr(channelPos));
162  } //End if this is a CRT AuxDet
163  } //End for each simulated sensitive volume -> CRT strip
164 
165  MF_LOG_DEBUG("moduleToChannels") << "Got " << moduleToChannels.size() << " modules to process in detector simulation.\n";
166 
167  //For each CRT module
168  for(auto& pair: moduleToChannels)
169  {
170  auto& module = pair.second;
171 
172  //Probably a good idea to write a function/algorithm class for each of these
173  //TODO: Any leftover physics like Birks' Law? I can handle Birks' Law more accurately if I
174  // can get access to individual Geant steps.
175  //TODO: Read detector response from MariaDB database on DAQ machine?
176  //TODO: Simulate detector response with quantum efficiency and detection efficiency?
177  //TODO: simulate time -> timestamp. Check out how 35t example in dunetpc/dunesim/DetSim does this.
178 
179  //Integrate "energy deposited" over time, then form a time-ordered sparse-vector (=std::map) of CRT::Hits
180  //associated with the art::Ptr that produced each hit. Associating each hit with a time value gives me the
181  //option to skip over dead time later. Each time bin contains up to one hit per channel.
182  MF_LOG_DEBUG("moduleToChannels") << "Processing " << module.size() << " channels in module " << pair.first << "\n";
183  std::map<time, std::vector<std::pair<CRT::Hit, art::Ptr<sim::AuxDetSimChannel>>>>timeToHits; //Mapping from integration time bin to list of hit-Ptr pairs
184  for(const auto& channel: module)
185  {
186  MF_LOG_DEBUG("channels") << "Processing channel " << channel->AuxDetSensitiveID() << "\n";
187  const auto& ides = channel->AuxDetIDEs();
188  for(const auto& eDep: ides)
189  {
190  const size_t tAvg = (eDep.exitT+eDep.entryT)/2.;
191  timeToHits[tAvg/fIntegrationTime].emplace_back(CRT::Hit(channel->AuxDetSensitiveID(), eDep.energyDeposited*fGeVToADC), channel);
192  MF_LOG_DEBUG("TrueTimes") << "Assigned true hit at time " << tAvg << " to bin " << tAvg/fIntegrationTime << ".\n";
193  }
194  }
195  //std::map<time, std::vector<std::pair<CRT::Hit, art::Ptr<sim::AuxDetSimChannel>>>> oldWindow;
196  std::stringstream ss;
197  auto lastTimeStamp=time(0);
198  int i=0;
199  for(auto window : timeToHits)
200  {
201  if (i!=0 && (time(fDeadtime)+lastTimeStamp)>window.first && lastTimeStamp<window.first) continue;
202  i++;
203  const auto& hitsInWindow = window.second;
204  const auto aboveThresh = std::find_if(hitsInWindow.begin(), hitsInWindow.end(),
205  [this](const auto& hitPair) { return hitPair.first.ADC() > fDACThreshold; });
206 
207 
208 if(aboveThresh != hitsInWindow.end()){
209 
210  std::vector<CRT::Hit> hits;
211  const time timestamp = window.first; //Set timestamp before window is changed.
212  const time end = (timestamp+fReadoutWindowSize);
213  std::set<uint32_t> channelBusy; //A std::set contains only unique elements. This set stores channels that have already been read out in
214  //this readout window and so are "busy" and cannot contribute any more hits.
215  for(auto busyCheckWindow : timeToHits){
216  if (time(busyCheckWindow.first)<timestamp || time(busyCheckWindow.first)>end) continue;
217  for(const auto& hitPair: window.second)
218  {
219  const auto channel = hitPair.first.Channel(); //TODO: Get channel number back without needing art::Ptr here.
220  // Maybe store crt::Hits.
221  if(channelBusy.insert(channel).second) //If this channel hasn't already contributed to this readout window
222  {
223  hits.push_back(hitPair.first);
224  simToTrigger->addSingle(hitPair.second, makeTrigPtr(trigCol->size()-1));
225  }
226  }
227  }
228  //std::cout<<"Hits Generated:"<<hits.size()<<std::endl;
229  lastTimeStamp=window.first;
230 
231  MF_LOG_DEBUG("CreateTrigger") << "Creating CRT::Trigger...\n";
232  trigCol->emplace_back(pair.first, timestamp*fIntegrationTime, std::move(hits));
233  } // For each readout with a triggerable hit
234  } // For each time window
235 
236  } //For each CRT module
237 
238  //Put Triggers and Assns into the event
239  MF_LOG_DEBUG("CreateTrigger") << "Putting " << trigCol->size() << " CRT::Triggers into the event at the end of analyze().\n";
240  e.put(std::move(trigCol));
241  e.put(std::move(simToTrigger));
242 }
size_t fDeadtime
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
double fGeVToADC
time fIntegrationTime
uint8_t channel
Definition: CRTFragment.hh:201
def move(depos, offset)
Definition: depos.py:107
adc_t fDACThreshold
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
long long int time
art::InputTag fSimLabel
AuxDetGeo const & AuxDet(unsigned int const ad=0) const
Returns the specified auxiliary detector.
size_t fReadoutWindowSize
#define MF_LOG_DEBUG(id)

Member Data Documentation

adc_t CRT::CRTSim::fDACThreshold
private

Definition at line 111 of file CRTSim_module.cc.

size_t CRT::CRTSim::fDeadtime
private

Definition at line 110 of file CRTSim_module.cc.

double CRT::CRTSim::fGeVToADC
private

Definition at line 102 of file CRTSim_module.cc.

time CRT::CRTSim::fIntegrationTime
private

Definition at line 107 of file CRTSim_module.cc.

size_t CRT::CRTSim::fReadoutWindowSize
private

Definition at line 108 of file CRTSim_module.cc.

art::InputTag CRT::CRTSim::fSimLabel
private

Definition at line 92 of file CRTSim_module.cc.


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