All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbndcode/sbndcode/CRT/CRTDetSim_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 /// \file CRTDetSim_module.cc
3 ///
4 /// \author mastbaum@uchicago.edu
5 ////////////////////////////////////////////////////////////////////////////////
6 
7 #include "art/Framework/Core/EDProducer.h"
8 #include "art/Framework/Core/ModuleMacros.h"
9 #include "art/Framework/Principal/Event.h"
10 #include "art/Framework/Principal/Handle.h"
11 #include "fhiclcpp/ParameterSet.h"
12 #include "messagefacility/MessageLogger/MessageLogger.h"
13 #include "nurandom/RandomUtils/NuRandomService.h"
14 #include "canvas/Persistency/Common/Ptr.h"
15 #include "canvas/Persistency/Common/Assns.h"
16 #include "art/Persistency/Common/PtrMaker.h"
17 
25 #include "larcorealg/CoreUtils/NumericUtils.h" // util::absDiff()
26 
27 #include "CLHEP/Random/RandomEngine.h"
28 #include "CLHEP/Random/RandFlat.h"
29 #include "CLHEP/Random/RandGauss.h"
30 #include "CLHEP/Random/RandPoisson.h"
31 
32 #include "TFile.h"
33 #include "TNtuple.h"
34 #include "TGeoManager.h"
35 #include "TGeoNode.h"
39 #include "sbndcode/CRT/CRTDetSim.h"
40 
41 #include <cmath>
42 #include <memory>
43 #include <string>
44 
45 namespace sbnd {
46 namespace crt {
47 
48 void CRTDetSim::reconfigure(fhicl::ParameterSet const & p) {
49  fG4ModuleLabel = p.get<std::string>("G4ModuleLabel");
50 }
51 
52 
53 CRTDetSim::CRTDetSim(fhicl::ParameterSet const & p)
54  : EDProducer{p}
55  , fEngine(art::ServiceHandle<rndm::NuRandomService>{}->createEngine(*this, "HepJamesRandom", "crt", p, "Seed"))
56  , fG4RefTime(art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob().G4ToElecTime(0) * 1e3) // ns
57  , fDetAlg(p.get<fhicl::ParameterSet>("DetSimParams"), fEngine, fG4RefTime)
58 {
59  this->reconfigure(p);
60 
61  produces<std::vector<sbnd::crt::FEBData> >();
62  produces<std::vector<sim::AuxDetIDE> >();
63  produces<art::Assns<sbnd::crt::FEBData , sim::AuxDetIDE , sbnd::crt::FEBTruthInfo>>();
64 
65  consumes<std::vector<sim::AuxDetSimChannel>>(fG4ModuleLabel);
66 }
67 
68 
69 
70 void CRTDetSim::produce(art::Event & e) {
71 
72  std::unique_ptr<std::vector<sbnd::crt::FEBData> > FEBDataOut(new std::vector<sbnd::crt::FEBData>);
73  art::PtrMaker<sbnd::crt::FEBData> makeDataPtr(e);
74 
75  std::unique_ptr<std::vector<sim::AuxDetIDE> > auxDetIdes(new std::vector<sim::AuxDetIDE>);
76  art::PtrMaker<sim::AuxDetIDE> makeIdePtr(e);
77 
78  std::unique_ptr<art::Assns<sbnd::crt::FEBData, sim::AuxDetIDE, sbnd::crt::FEBTruthInfo>> Dataassn
79  (new art::Assns<sbnd::crt::FEBData, sim::AuxDetIDE, sbnd::crt::FEBTruthInfo>);
80 
81  // Handle for (truth) AuxDetSimChannels
82  art::Handle<std::vector<sim::AuxDetSimChannel> > channels;
83  e.getByLabel(fG4ModuleLabel, channels);
84 
85  if (!channels.isValid()) {
86  mf::LogWarning("CRTDetSim") << "No AuxDetSimChannel..." << std::endl;
87  }
88 
90 
91 
92  //
93  // Step 1: Construct Taggers
94  //
95  for(auto const& adsc : *channels) {
96 
97  if(adsc.AuxDetID() == UINT_MAX || adsc.AuxDetSensitiveID() == UINT_MAX) {
98  mf::LogWarning("CRTDetSim") << "AuxDetSimChannel with ID: UINT_MAX\n"
99  << "skipping channel...";
100  continue;
101  }
102 
103  if(adsc.AuxDetIDEs().size() > 0) {
104  mf::LogDebug("CRTDetSim") << "Adding AuxDetSimChannel with AuxDetID " << adsc.AuxDetID()
105  << ", AuxDetSensitiveID " << adsc.AuxDetSensitiveID() << std::endl;
106  fDetAlg.FillTaggers(adsc.AuxDetID(), adsc.AuxDetSensitiveID(), adsc.AuxDetIDEs());
107  }
108 
109  } // loop over AuxDetSimChannels
110 
111 
112  //
113  // Step 1: Apply Coincidence, deadtime, etc.
114  //
115 
117  std::vector<std::pair<sbnd::crt::FEBData, std::vector<sim::AuxDetIDE>>> data = fDetAlg.GetData();
118  std::vector<std::vector<int>> auxdata = fDetAlg.GetAuxData();
119 
120  //
121  // Step 3: Save output
122  //
123 
124  // for(auto const& dataPair : data){
125  for (size_t i = 0; i < data.size(); i++) {
126 
127  auto & dataPair = data[i];
128  auto & feb = dataPair.first;
129  auto & ides = dataPair.second;
130  auto & idxs = auxdata.at(i);
131 
132  FEBDataOut->push_back(feb);
133  art::Ptr<FEBData> dataPtr = makeDataPtr(FEBDataOut->size()-1);
134 
135  for(size_t j = 0; j < ides.size(); j++){
136  auto const& ide = ides[j];
137  auxDetIdes->push_back(ide);
138  FEBTruthInfo const feb_truth_info {idxs[j]};
139  mf::LogDebug("CRTDetSim") << "Adding " << idxs[j] << " to FEBTruthInfo." << std::endl;
140  art::Ptr<sim::AuxDetIDE> idePtr = makeIdePtr(auxDetIdes->size()-1);
141  Dataassn->addSingle(dataPtr, idePtr, feb_truth_info);
142  }
143  }
144 
145  mf::LogInfo("CRTDetSim") << "Number of FEBData objects produced: " << FEBDataOut->size() << "\n";
146 
147  e.put(std::move(FEBDataOut));
148  e.put(std::move(auxDetIdes));
149  e.put(std::move(Dataassn));
150 }
151 
152 DEFINE_ART_MODULE(CRTDetSim)
153 
154 } // namespace crt
155 } // namespace sbnd
Functions to help with numbers.
Encapsulate the construction of a single cyostat.
std::vector< std::pair< sbnd::crt::FEBData, std::vector< AuxDetIDE > > > GetData()
pdgs p
Definition: selectors.fcl:22
void FillTaggers(const uint32_t adid, const uint32_t adsid, std::vector< AuxDetIDE > ides)
createEngine fDetAlg(p.get< fhicl::ParameterSet >("DetSimParams"), fEngine, fG4RefTime)
for pfile in ack l reconfigure(.*) override"` do echo "checking $
object containing MC truth information necessary for making RawDigits and doing back tracking ...
std::string fG4ModuleLabel
Definition: CRTDetSim.h:42
std::vector< std::vector< int > > GetAuxData()
art framework interface to geometry description for auxiliary detectors
fEngine(art::ServiceHandle< rndm::NuRandomService >() ->createEngine(*this, pset,"Seed"))
Encapsulate the geometry of an auxiliary detector.
CRTDetSim(fhicl::ParameterSet const &p)
void reconfigure(fhicl::ParameterSet const &p)
createEngine fG4RefTime(art::ServiceHandle< detinfo::DetectorClocksService const >() ->DataForJob().G4ToElecTime(0)*1e3)
do i e
Class def header for a class ElecClock.
stream1 can override from command line with o or output services user sbnd
CRTDetSimAlg fDetAlg
Instance of the CRT detector simulation algorithm.
Definition: CRTDetSim.h:48
process_name crt
art framework interface to geometry description