All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbndcode/sbndcode/CRT/CRTSimHitProducer_module.cc
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 /// Class: CRTSimHitProducer
3 /// Module Type: producer
4 /// File: CRTSimHitProducer_module.cc
5 ///
6 /// Producer module for constructing CRTHits from simulated CRT data
7 ///
8 /// Author: Thomas Brooks
9 /// E-mail address: tbrooks@fnal.gov
10 /////////////////////////////////////////////////////////////////////////////
11 
12 // sbndcode includes
16 
17 // Framework includes
18 #include "art/Framework/Core/EDProducer.h"
19 #include "art/Framework/Core/ModuleMacros.h"
20 #include "art/Framework/Principal/Handle.h"
21 #include "art/Framework/Principal/Event.h"
22 #include "canvas/Persistency/Common/Ptr.h"
23 #include "canvas/Persistency/Common/PtrVector.h"
24 #include "art/Framework/Principal/Run.h"
25 #include "art/Framework/Principal/SubRun.h"
26 #include "art_root_io/TFileService.h"
27 #include "art_root_io/TFileDirectory.h"
28 #include "art/Framework/Services/Registry/ServiceHandle.h"
29 #include "art/Framework/Core/ModuleMacros.h"
30 #include "canvas/Persistency/Common/FindManyP.h"
31 #include "art/Persistency/Common/PtrMaker.h"
32 
33 #include "canvas/Utilities/InputTag.h"
34 #include "fhiclcpp/ParameterSet.h"
35 #include "messagefacility/MessageLogger/MessageLogger.h"
36 
37 #include <memory>
38 #include <iostream>
39 #include <map>
40 #include <iterator>
41 #include <algorithm>
42 
43 // LArSoft
59 
60 // ROOT
61 #include "TTree.h"
62 #include "TFile.h"
63 #include "TH1D.h"
64 #include "TH2D.h"
65 #include "TVector3.h"
66 #include "TGeoManager.h"
67 
68 
69 namespace sbnd {
70 
71  class CRTSimHitProducer : public art::EDProducer {
72  public:
73 
74  explicit CRTSimHitProducer(fhicl::ParameterSet const & p);
75 
76  // The destructor generated by the compiler is fine for classes
77  // without bare pointers or other resource use.
78 
79  // Plugins should not be copied or assigned.
80  CRTSimHitProducer(CRTSimHitProducer const &) = delete;
82  CRTSimHitProducer & operator = (CRTSimHitProducer const &) = delete;
84 
85  // Required functions.
86  void produce(art::Event & e) override;
87 
88  // Selected optional functions.
89  void beginJob() override;
90 
91  void endJob() override;
92 
93  void reconfigure(fhicl::ParameterSet const & p);
94 
95  private:
96 
97  // Params from fcl file.......
98  art::InputTag fCrtModuleLabel; ///< name of crt producer
99 
100  double fG4RefTime;
101 
103 
104  }; // class CRTSimHitProducer
105 
106 
107  CRTSimHitProducer::CRTSimHitProducer(fhicl::ParameterSet const & p)
108  : EDProducer(p)
109  , fG4RefTime(art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob().G4ToElecTime(0)) // us
110  , hitAlg(p.get<fhicl::ParameterSet>("HitAlg"), fG4RefTime)
111  // Initialize member data here, if know don't want to reconfigure on the fly
112  {
113 
114  // Call appropriate produces<>() functions here.
115  produces< std::vector<sbn::crt::CRTHit> >();
116  produces< art::Assns<sbn::crt::CRTHit , sbnd::crt::CRTData> >();
117 
118  reconfigure(p);
119 
120  } // CRTSimHitProducer()
121 
122 
123  void CRTSimHitProducer::reconfigure(fhicl::ParameterSet const & p)
124  {
125 
126  fCrtModuleLabel = (p.get<art::InputTag> ("CrtModuleLabel"));
127 
128  } // CRTSimHitProducer::reconfigure()
129 
130 
132  {
133 
134  } // CRTSimHitProducer::beginJob()
135 
136 
137  void CRTSimHitProducer::produce(art::Event & event)
138  {
139 
140  std::unique_ptr< std::vector<sbn::crt::CRTHit> > CRTHitcol( new std::vector<sbn::crt::CRTHit>);
141  std::unique_ptr< art::Assns<sbn::crt::CRTHit, sbnd::crt::CRTData> > Hitassn( new art::Assns<sbn::crt::CRTHit, sbnd::crt::CRTData>);
142  art::PtrMaker<sbn::crt::CRTHit> makeHitPtr(event);
143 
144  int nHits = 0;
145 
146  // Retrieve list of CRT hits
147  art::Handle< std::vector<sbnd::crt::CRTData>> crtListHandle;
148  std::vector<art::Ptr<sbnd::crt::CRTData> > crtList;
149  if (event.getByLabel(fCrtModuleLabel, crtListHandle))
150  art::fill_ptr_vector(crtList, crtListHandle);
151 
152  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event);
153  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(event, clockData);
154  // Fill a vector of pairs of time and width direction for each CRT plane
155  // The y crossing point of z planes and z crossing point of y planes would be constant
156  std::map<std::pair<std::string, unsigned>, std::vector<CRTStrip>> taggerStrips = hitAlg.CreateTaggerStrips(clockData, detProp, crtList);
157 
158  mf::LogInfo("CRTSimHitProducer")
159  <<"Number of SiPM hits = "<<crtList.size();
160 
161  std::vector<std::pair<sbn::crt::CRTHit, std::vector<int>>> crtHitPairs = hitAlg.CreateCRTHits(taggerStrips);
162 
163  for(auto const& crtHitPair : crtHitPairs){
164  CRTHitcol->push_back(crtHitPair.first);
165  art::Ptr<sbn::crt::CRTHit> hitPtr = makeHitPtr(CRTHitcol->size()-1);
166  nHits++;
167  for(auto const& data_i : crtHitPair.second){
168  Hitassn->addSingle(hitPtr, crtList[data_i]);
169  }
170  }
171 
172 
173  event.put(std::move(CRTHitcol));
174  event.put(std::move(Hitassn));
175 
176  mf::LogInfo("CRTSimHitProducer")
177  <<"Number of CRT hits produced = "<<nHits;
178 
179  } // CRTSimHitProducer::produce()
180 
181 
183  {
184 
185  } // CRTSimHitProducer::endJob()
186 
187 
188  DEFINE_ART_MODULE(CRTSimHitProducer)
189 
190 } // sbnd namespace
services DetectorClocksService
CRTSimHitProducer & operator=(CRTSimHitProducer const &)=delete
pdgs p
Definition: selectors.fcl:22
Access the description of detector geometry.
object containing MC truth information necessary for making RawDigits and doing back tracking ...
art framework interface to geometry description for auxiliary detectors
std::map< std::pair< std::string, unsigned >, std::vector< CRTStrip > > CreateTaggerStrips(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< sbnd::crt::CRTData >> data)
std::vector< std::pair< sbn::crt::CRTHit, std::vector< int > > > CreateCRTHits(std::map< std::pair< std::string, unsigned >, std::vector< CRTStrip >> taggerStrips)
Definition of data types for geometry description.
Encapsulate the geometry of a wire.
Encapsulate the construction of a single detector plane.
createEngine fG4RefTime(art::ServiceHandle< detinfo::DetectorClocksService const >() ->DataForJob().G4ToElecTime(0)*1e3)
object containing MC truth information necessary for making RawDigits and doing back tracking ...
do i e
stream1 can override from command line with o or output services user sbnd
art::InputTag fCrtModuleLabel
name of crt producer
Collection of Physical constants used in LArSoft.
art framework interface to geometry description
auto const detProp