All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
icaruscode/icaruscode/CRT/CRTSimHitProducer_module.cc
Go to the documentation of this file.
1 // icaruscode includes
6 
7 // Framework includes
8 #include "art/Framework/Core/EDProducer.h"
9 #include "art/Framework/Core/ModuleMacros.h"
10 #include "art/Framework/Principal/Handle.h"
11 #include "art/Framework/Principal/Event.h"
12 #include "canvas/Persistency/Common/Ptr.h"
13 #include "canvas/Persistency/Common/PtrVector.h"
14 #include "art/Framework/Principal/Run.h"
15 #include "art/Framework/Principal/SubRun.h"
16 #include "art_root_io/TFileService.h"
17 #include "art_root_io/TFileDirectory.h"
18 #include "art/Framework/Services/Registry/ServiceHandle.h"
19 #include "art/Framework/Core/ModuleMacros.h"
20 #include "canvas/Persistency/Common/FindManyP.h"
21 #include "art/Persistency/Common/PtrMaker.h"
22 #include "canvas/Utilities/InputTag.h"
23 #include "fhiclcpp/ParameterSet.h"
24 #include "messagefacility/MessageLogger/MessageLogger.h"
25 #include "canvas/Utilities/Exception.h"
26 
27 // C++ includes
28 #include <memory>
29 #include <iostream>
30 #include <map>
31 #include <iterator>
32 #include <algorithm>
33 #include <vector>
34 
35 // LArSoft
48 
49 // ROOT
50 #include "TTree.h"
51 #include "TFile.h"
52 #include "TH1D.h"
53 #include "TH2D.h"
54 #include "TVector3.h"
55 #include "TGeoManager.h"
56 
57 using std::vector;
58 
59 namespace icarus {
60 namespace crt {
61 
62  class CRTSimHitProducer : public art::EDProducer {
63  public:
64 
66 
67  explicit CRTSimHitProducer(fhicl::ParameterSet const & p);
68 
69  // The destructor generated by the compiler is fine for classes
70  // without bare pointers or other resource use.
71 
72  // Plugins should not be copied or assigned.
73  CRTSimHitProducer(CRTSimHitProducer const &) = delete;
75  CRTSimHitProducer & operator = (CRTSimHitProducer const &) = delete;
77 
78  // Required functions.
79  void produce(art::Event & e) override;
80 
81  // Selected optional functions.
82  void beginJob() override;
83 
84  void endJob() override;
85 
86  void reconfigure(fhicl::ParameterSet const & p);
87 
88  private:
89 
90  // Params from fcl file.......
91  art::InputTag fCrtModuleLabel; ///< name of crt producer
92  art::InputTag fTriggerLabel; ///< name of trigger producer
94 
96 
97  }; // class CRTSimHitProducer
98 
99  CRTSimHitProducer::CRTSimHitProducer(fhicl::ParameterSet const & p)
100  : EDProducer{p}, hitAlg(p.get<fhicl::ParameterSet>("HitAlg"))
101  // Initialize member data here, if know don't want to reconfigure on the fly
102  {
103 
104  // Call appropriate produces<>() functions here.
105  produces< vector<CRTHit> >();
106  produces< art::Assns<CRTHit, CRTData> >();
107 
108  reconfigure(p);
109 
110  } // CRTSimHitProducer()
111 
112  void CRTSimHitProducer::reconfigure(fhicl::ParameterSet const & p)
113  {
114  fCrtModuleLabel = (p.get<art::InputTag> ("CrtModuleLabel"));
115  fTriggerLabel = (p.get<art::InputTag> ("TriggerLabel"));
116  } // CRTSimHitProducer::reconfigure()
117 
119  {
120 
121  } // CRTSimHitProducer::beginJob()
122 
123  void CRTSimHitProducer::produce(art::Event & event)
124  {
125 
126  std::unique_ptr< vector<CRTHit> > CRTHitcol( new vector<CRTHit>);
127  std::unique_ptr< art::Assns<CRTHit, CRTData> > Hitassn( new art::Assns<CRTHit, CRTData>);
128  art::PtrMaker<sbn::crt::CRTHit> makeHitPtr(event);
129 
130  int nHits = 0;
131 
132  // Retrieve list of CRT hits
133  art::Handle< std::vector<CRTData>> crtListHandle;
134  vector<art::Ptr<CRTData> > crtList;
135 
136  if (event.getByLabel(fCrtModuleLabel, crtListHandle))
137  art::fill_ptr_vector(crtList, crtListHandle);
138 
139  //add trigger info
140  if( !fTriggerLabel.empty() ) {
141 
142  art::Handle<sbn::ExtraTriggerInfo> trigger_handle;
143  event.getByLabel( fTriggerLabel, trigger_handle );
144  if( trigger_handle.isValid() )
145  m_trigger_timestamp = trigger_handle->triggerTimestamp;
146  else
147  mf::LogError("CRTSimHitProducer") << "No raw::Trigger associated to label: " << fTriggerLabel.label() << "\n" ;
148  } else{
149  std::cout << "Trigger Data product " << fTriggerLabel.label() << " not found!\n" ;
150  }
151 
152  mf::LogInfo("CRTSimHitProducer")
153  <<"Number of SiPM hits = "<<crtList.size();
154  //m_trigger_timestamp = event.getProduct<sbn::ExtraTriggerInfo>(fTriggerLabel).triggerTimestamp;
155 
156  mf::LogInfo("CRTSimHitProducer")
157  <<"Number of SiPM hits = "<<crtList.size();
158 
159  vector<art::Ptr<CRTData>> crtData = hitAlg.PreselectCRTData(crtList, m_trigger_timestamp);
160 
161  vector<std::pair<CRTHit, vector<int>>> crtHitPairs = hitAlg.CreateCRTHits(crtData, m_trigger_timestamp);
162  //vector<std::pair<CRTHit, vector<int>>> crtHitPairs = hitAlg.CreateCRTHits(crtList);
163 
164  mf::LogInfo("CRTSimHitProducer")
165  << "Number of CRTHit,data indices pairs = " << crtHitPairs.size();
166 
167  for(auto const& crtHitPair : crtHitPairs){
168 
169  CRTHitcol->push_back(crtHitPair.first);
170  art::Ptr<CRTHit> hitPtr = makeHitPtr(CRTHitcol->size()-1);
171  nHits++;
172 
173  for(auto const& data_i : crtHitPair.second){
174 
175  Hitassn->addSingle(hitPtr, crtList[data_i]);
176  }
177  }
178 
179  event.put(std::move(CRTHitcol));
180  event.put(std::move(Hitassn));
181 
182  mf::LogInfo("CRTSimHitProducer")
183  <<"Number of CRT hits produced = "<<nHits;
184 
185  } // CRTSimHitProducer::produce()
186 
188  {
189 
190  } // CRTSimHitProducer::endJob()
191 
192  DEFINE_ART_MODULE(CRTSimHitProducer)
193 
194 }
195 } //end namespace
pdgs p
Definition: selectors.fcl:22
for pfile in ack l reconfigure(.*) override"` do echo "checking $
vector< art::Ptr< CRTData > > PreselectCRTData(const vector< art::Ptr< CRTData >> &crtList, uint64_t trigger_timestamp)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
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
Definition of data types for geometry description.
object containing MC truth information necessary for making RawDigits and doing back tracking ...
do i e
Data product holding additional trigger information.
CRTSimHitProducer & operator=(CRTSimHitProducer const &)=delete
Collection of Physical constants used in LArSoft.
process_name crt
art framework interface to geometry description
BEGIN_PROLOG could also be cout
vector< pair< CRTHit, vector< int > > > CreateCRTHits(vector< art::Ptr< CRTData >> crtList, uint64_t trigger_timestamp)