LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
HitAnaModule_module.cc
Go to the documentation of this file.
1 // Class: HitAnaModule
3 // Module Type: analyzer
4 // File: HitAnaModule_module.cc
5 //
6 // Generated at Sun Jun 22 08:40:08 2014 by Wesley Ketchum using artmod
7 // from cetpkgsupport v1_05_04.
9 
30 #include "fhiclcpp/ParameterSet.h"
31 
33 
34 #include <vector>
35 #include <string>
36 
42 
43 namespace hit {
44  class HitAnaModule;
45 }
46 
48 public:
49  explicit HitAnaModule(fhicl::ParameterSet const & p);
50  virtual ~HitAnaModule();
51 
52  void analyze(art::Event const & e) override;
53 
54  void beginJob() override;
55  void reconfigure(fhicl::ParameterSet const & p) ;
56 
57 private:
59 
60  void createAssocVector(
61  HitWireAssns_t const&,
62  std::vector< std::vector<int> > &
63  );
64 
65  void createAssocVector(std::vector<recob::Wire> const&,
66  std::vector<recob::Hit> const&,
67  std::vector< std::vector<int> > &);
68 
69  void createMCAssocVector( std::vector<recob::Wire> const&,
70  std::vector<sim::MCHitCollection> const&,
71  std::vector< std::vector<int> >&);
72 
73  // Declare member data here.
74  std::vector<std::string> fHitModuleLabels;
75  std::string fMCHitModuleLabel;
76  std::string fWireModuleLabel;
77 
78  TTree *wireDataTree;
79  std::vector<TTree *> hitDataTree;
80 
82 
83 };
84 
85 
87  :
88  EDAnalyzer(p) // ,
89  // More initializers here.
90 { this->reconfigure(p); }
91 
93 {
94  // Clean up dynamic memory and other resources here.
95 }
96 
99  std::vector< std::vector<int> > & WireHitAssocVector
100 ) {
101  // WireHitAssocVector: for each wire, indices of all the hits associated to it
102 
103  // the iteration to art::Assns<Hit, Wire> points to a art::Ptr pair (assn_t)
104  // with a hit as first element ("left") and a wire as the second one ("right")
105  for (HitWireAssns_t::assn_t const& assn: HitToWire)
106  WireHitAssocVector.at(assn.second.key()).push_back(assn.first.key());
107 
108 }
109 
110 void hit::HitAnaModule::createAssocVector(std::vector<recob::Wire> const& wireVector,
111  std::vector<recob::Hit> const& hitVector,
112  std::vector< std::vector<int> > & WireHitAssocVector)
113 {
114  WireHitAssocVector.resize(wireVector.size());
115  for(size_t iwire=0; iwire<wireVector.size(); iwire++){
116  for(size_t ihit=0; ihit<hitVector.size(); ihit++){
117  if(hitVector[ihit].Channel()==wireVector[iwire].Channel())
118  WireHitAssocVector[iwire].push_back(ihit);
119  }
120  }
121 }
122 
123 void hit::HitAnaModule::createMCAssocVector( std::vector<recob::Wire> const& wireVector,
124  std::vector<sim::MCHitCollection> const& mcHitVector,
125  std::vector< std::vector<int> > & WireMCHitAssocVector){
126 
127  WireMCHitAssocVector.clear(); WireMCHitAssocVector.resize(wireVector.size());
128 
129  //first, store all the MCHitCollection indices in a map keyed on channel
130  //then, loop through wires, and lookup mchitcollections based on the wire's channel
131 
132  std::map<unsigned int,std::vector<int> > mcHitIndicesByChannel;
133  for(unsigned int icol=0; icol<mcHitVector.size(); icol++)
134  mcHitIndicesByChannel[mcHitVector[icol].Channel()].push_back(icol);
135 
136 
137  for(unsigned int iwire=0; iwire<wireVector.size(); iwire++)
138  WireMCHitAssocVector[iwire].insert(WireMCHitAssocVector[iwire].end(),
139  mcHitIndicesByChannel[wireVector[iwire].Channel()].begin(),
140  mcHitIndicesByChannel[wireVector[iwire].Channel()].end());
141 
142 }
143 
145 {
146  //get event and run numbers
147  unsigned int eventNumber = e.id().event();
148  unsigned int runNumber = e.run();
149 
151 
152  //get time service
153  const detinfo::DetectorClocks* ts = lar::providerFrom<detinfo::DetectorClocksService>();
154 
155  //get the wire data
157  e.getByLabel(fWireModuleLabel,wireHandle);
158  std::vector<recob::Wire> const& wireVector(*wireHandle);
159 
160  //get the MC hits
162  e.getByLabel(fMCHitModuleLabel,mcHitHandle);
163  std::vector<sim::MCHitCollection> const& mcHitVector(*mcHitHandle);
164 
165  //make the association vector. First index is wire index, second is mcHitCollection index
166  std::vector< std::vector<int> > WireMCHitAssocVector;
167  createMCAssocVector(wireVector,mcHitVector,WireMCHitAssocVector);
168 
169  //get the hit data
170  size_t nHitModules = fHitModuleLabels.size();
171  std::vector< art::Handle< std::vector<recob::Hit> > > hitHandles(nHitModules);
172  // for each hit module output (first index), for each wire (second index)
173  // the list of hits associated with that wire is stored
174  std::vector< std::vector< std::vector<int> > > WireHitAssocVectors(nHitModules);
175  for(size_t iter=0; iter < nHitModules; iter++){
176 
177  e.getByLabel(fHitModuleLabels[iter],hitHandles[iter]);
178 
179  //create association vectors by hand for now
180  //art::ValidHandle<HitWireAssns_t> HitToWireAssns
181  //= e.getValidHandle<HitWireAssns_t>(fHitModuleLabels[iter]);
182  //WireHitAssocVectors[iter].resize(wireVector.size());
183  //createAssocVector(*HitToWireAssns,WireHitAssocVectors[iter]);
184 
185  WireHitAssocVectors[iter].resize(wireVector.size());
186  art::Handle<HitWireAssns_t> HitToWireAssns;
187  if( e.getByLabel(fHitModuleLabels[iter],HitToWireAssns) )
188  createAssocVector(*HitToWireAssns,WireHitAssocVectors[iter]);
189  else
190  createAssocVector(wireVector,*(hitHandles[iter]),WireHitAssocVectors[iter]);
191 
192  //load in this hit/assoc pair
193  analysisAlg.LoadHitAssocPair( *(hitHandles[iter]),
194  WireHitAssocVectors[iter],
195  fHitModuleLabels[iter]);
196 
197  }
198 
199  //run the analzyer alg
200  analysisAlg.AnalyzeWires(wireVector,mcHitVector,WireMCHitAssocVector,ts,eventNumber,runNumber);
201 
202 }
203 
205 {
207  wireDataTree = tfs->make<TTree>("wireDataTree","WireDataTree");
209 
210  // The below creates a Tree with one branch - a recob::Hit branch - for each
211  // Hit module specified in the fcl file. So, don't run this module once per Hit
212  // Finder as one normally would. Just run it once and specify all HitFinders.
213  // This was the design for the WireDataTree; we follow it here for the
214  // Hit trees.
215  for(auto const& label : fHitModuleLabels) {
216  std::string firstArg("hitData_");
217  firstArg += label;
218  std::string secArg("HitDataTree_");
219  secArg += label;
220  TTree* intermediateTree = tfs->make<TTree>(firstArg.c_str(),secArg.c_str());
221  hitDataTree.push_back(intermediateTree);
222  }
224 }
225 
227 {
228  // Implementation of optional member function here.
229 
230  fHitModuleLabels = p.get< std::vector<std::string> >("HitModuleLabels");
231  fWireModuleLabel = p.get< std::string >("WireModuleLabel");
232  fMCHitModuleLabel = p.get< std::string >("MCHitModuleLabel");
233 
234 }
235 
void SetHitDataTree(std::vector< TTree * > &trees)
Definition: HitAnaAlg.cxx:27
std::vector< std::string > fHitModuleLabels
void beginJob() override
std::string fWireModuleLabel
const std::string label
Declaration of signal hit object.
std::string fMCHitModuleLabel
void reconfigure(fhicl::ParameterSet const &p)
void LoadHitAssocPair(std::vector< recob::Hit > const &, std::vector< std::vector< int > > const &, std::string const &)
Definition: HitAnaAlg.cxx:86
void SetWireDataTree(TTree *)
Definition: HitAnaAlg.cxx:22
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
void createAssocVector(HitWireAssns_t const &, std::vector< std::vector< int > > &)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
T get(std::string const &key) const
Definition: ParameterSet.h:231
details::FindAllP< recob::Hit, recob::Wire > HitToWire
Query object connecting a hit to a wire.
Definition: HitUtils.h:56
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
Detector simulation of raw signals on wires.
Conversion of times between different formats and references.
void createMCAssocVector(std::vector< recob::Wire > const &, std::vector< sim::MCHitCollection > const &, std::vector< std::vector< int > > &)
T * make(ARGS...args) const
HitAnaModule(fhicl::ParameterSet const &p)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
EventNumber_t event() const
Definition: EventID.h:117
Declaration of basic channel signal object.
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
void analyze(art::Event const &e) override
Float_t e
Definition: plot.C:34
RunNumber_t run() const
Definition: Event.h:77
void ClearHitModules()
Definition: HitAnaAlg.cxx:80
void AnalyzeWires(std::vector< recob::Wire > const &, std::vector< sim::MCHitCollection > const &, std::vector< std::vector< int > > const &, const detinfo::DetectorClocks *, unsigned int, unsigned int)
Definition: HitAnaAlg.cxx:98
EventID id() const
Definition: Event.h:56
std::vector< TTree * > hitDataTree