22 #include "art/Framework/Core/EDAnalyzer.h"
23 #include "art/Framework/Core/ModuleMacros.h"
24 #include "art/Framework/Principal/Event.h"
25 #include "art/Framework/Principal/Handle.h"
26 #include "art/Framework/Services/Registry/ServiceHandle.h"
27 #include "canvas/Persistency/Common/Assns.h"
28 #include "fhiclcpp/ParameterSet.h"
30 #include "art_root_io/TFileService.h"
51 void analyze(art::Event
const&
e)
override;
60 std::vector<recob::Hit>
const&,
64 std::vector<sim::MCHitCollection>
const&,
94 for (HitWireAssns_t::assn_t
const& assn : HitToWire)
95 WireHitAssocVector.at(assn.second.key()).push_back(assn.first.key());
100 std::vector<recob::Hit>
const& hitVector,
103 WireHitAssocVector.resize(wireVector.size());
104 for (
size_t iwire = 0; iwire < wireVector.size(); iwire++) {
105 for (
size_t ihit = 0; ihit < hitVector.size(); ihit++) {
106 if (hitVector[ihit].Channel() == wireVector[iwire].Channel())
107 WireHitAssocVector[iwire].push_back(ihit);
114 std::vector<sim::MCHitCollection>
const& mcHitVector,
115 std::vector<std::vector<int>>& WireMCHitAssocVector)
118 WireMCHitAssocVector.clear();
119 WireMCHitAssocVector.resize(wireVector.size());
124 std::map<unsigned int, std::vector<int>> mcHitIndicesByChannel;
125 for (
unsigned int icol = 0; icol < mcHitVector.size(); icol++)
126 mcHitIndicesByChannel[mcHitVector[icol].Channel()].push_back(icol);
128 for (
unsigned int iwire = 0; iwire < wireVector.size(); iwire++)
129 WireMCHitAssocVector[iwire].insert(WireMCHitAssocVector[iwire].
end(),
130 mcHitIndicesByChannel[wireVector[iwire].Channel()].begin(),
131 mcHitIndicesByChannel[wireVector[iwire].Channel()].end());
138 unsigned int eventNumber = e.id().event();
139 unsigned int runNumber = e.run();
141 analysisAlg.ClearHitModules();
144 auto const& wireVector = *e.getValidHandle<std::vector<recob::Wire>>(fWireModuleLabel);
145 auto const& mcHitVector = *e.getValidHandle<std::vector<sim::MCHitCollection>>(fMCHitModuleLabel);
149 std::vector<std::vector<int>> WireMCHitAssocVector;
150 createMCAssocVector(wireVector, mcHitVector, WireMCHitAssocVector);
153 size_t nHitModules = fHitModuleLabels.size();
154 std::vector<art::Handle<std::vector<recob::Hit>>> hitHandles(nHitModules);
157 std::vector<std::vector<std::vector<int>>> WireHitAssocVectors(nHitModules);
158 for (
size_t iter = 0; iter < nHitModules; iter++) {
160 e.getByLabel(fHitModuleLabels[iter], hitHandles[iter]);
168 WireHitAssocVectors[iter].resize(wireVector.size());
169 art::Handle<HitWireAssns_t> HitToWireAssns;
170 if (e.getByLabel(fHitModuleLabels[iter], HitToWireAssns))
171 createAssocVector(*HitToWireAssns, WireHitAssocVectors[iter]);
173 createAssocVector(wireVector, *(hitHandles[iter]), WireHitAssocVectors[iter]);
176 analysisAlg.LoadHitAssocPair(
177 *(hitHandles[iter]), WireHitAssocVectors[iter], fHitModuleLabels[iter]);
181 auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
184 analysisAlg.AnalyzeWires(
185 wireVector, mcHitVector, WireMCHitAssocVector, clock_data, eventNumber, runNumber);
191 art::ServiceHandle<art::TFileService const>
tfs;
192 wireDataTree = tfs->make<TTree>(
"wireDataTree",
"WireDataTree");
193 analysisAlg.SetWireDataTree(wireDataTree);
200 for (
auto const& label : fHitModuleLabels) {
201 std::string firstArg(
"hitData_");
203 std::string secArg(
"HitDataTree_");
205 TTree* intermediateTree = tfs->make<TTree>(firstArg.c_str(), secArg.c_str());
206 hitDataTree.push_back(intermediateTree);
208 analysisAlg.SetHitDataTree(hitDataTree);
void createMCAssocVector(std::vector< recob::Wire > const &, std::vector< sim::MCHitCollection > const &, std::vector< std::vector< int >> &)
std::vector< std::string > fHitModuleLabels
std::string fWireModuleLabel
std::vector< TTree * > hitDataTree
Declaration of signal hit object.
std::string fMCHitModuleLabel
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
details::FindAllP< recob::Hit, recob::Wire > HitToWire
Query object connecting a hit to a wire.
auto end(FixedBins< T, C > const &) noexcept
art::Assns< recob::Hit, recob::Wire > HitWireAssns_t
HitAnaModule(fhicl::ParameterSet const &p)
void createAssocVector(HitWireAssns_t const &, std::vector< std::vector< int >> &)
Declaration of basic channel signal object.
void analyze(art::Event const &e) override
art::ServiceHandle< art::TFileService > tfs