10 #include "art/Framework/Core/EDAnalyzer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "art/Framework/Principal/Run.h"
15 #include "art/Framework/Principal/SubRun.h"
16 #include "canvas/Utilities/InputTag.h"
17 #include "fhiclcpp/ParameterSet.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
20 #include "nusimdata/SimulationBase/MCTruth.h"
43 void analyze(art::Event
const&
e)
override;
65 std::vector<float>
_wf;
83 : EDAnalyzer{p}, _wftree(
nullptr), _geotree(
nullptr)
85 _output_fname =
p.get<std::string>(
"OutputFileName" );
86 _wf_label =
p.get<std::string>(
"OpDetWaveformProducer" );
87 _mct_label =
p.get<std::string>(
"MCTruthProducer",
"generator");
88 _hit_label_v =
p.get<std::vector<std::string> >(
"OpHitProducerList");
97 _wftree =
new TTree(name.c_str(),name.c_str());
98 _wftree->Branch(
"run",&
_run,
"run/I");
99 _wftree->Branch(
"event",&
_event,
"event/I");
100 _wftree->Branch(
"event_time",&
_event_time,
"event_time/D");
101 _wftree->Branch(
"event_x",&
_event_x,
"event_x/D");
102 _wftree->Branch(
"event_y",&
_event_y,
"event_y/D");
103 _wftree->Branch(
"event_z",&
_event_z,
"event_z/D");
104 _wftree->Branch(
"event_dr",&
_event_dr,
"event_dr/D");
105 _wftree->Branch(
"event_dx",&
_event_dx,
"event_dx/D");
106 _wftree->Branch(
"event_dy",&
_event_dy,
"event_dy/D");
107 _wftree->Branch(
"event_dz",&
_event_dz,
"event_dz/D");
108 _wftree->Branch(
"tpc",&
_tpc,
"tpc/I");
109 _wftree->Branch(
"ch",&
_ch,
"ch/I");
110 _wftree->Branch(
"wf",&
_wf);
111 _wftree->Branch(
"tstart",&
_tstart,
"tstart/D");
115 std::string
name = label +
"_hittree";
116 auto hittree =
new TTree(name.c_str(),name.c_str());
117 hittree->Branch(
"run",&
_run,
"run/I");
118 hittree->Branch(
"event",&
_event,
"event/I");
119 hittree->Branch(
"event_time",&
_event_time,
"event_time/D");
120 hittree->Branch(
"event_x",&
_event_x,
"event_x/D");
121 hittree->Branch(
"event_y",&
_event_y,
"event_y/D");
122 hittree->Branch(
"event_z",&
_event_z,
"event_z/D");
123 hittree->Branch(
"event_dr",&
_event_dr,
"event_dr/D");
124 hittree->Branch(
"event_dx",&
_event_dx,
"event_dx/D");
125 hittree->Branch(
"event_dy",&
_event_dy,
"event_dy/D");
126 hittree->Branch(
"event_dz",&
_event_dz,
"event_dz/D");
127 hittree->Branch(
"tpc",&
_tpc,
"tpc/I");
128 hittree->Branch(
"ch",&
_ch,
"ch/I");
129 hittree->Branch(
"amp",&
_amp,
"amp/D");
130 hittree->Branch(
"area",&
_area,
"area/D");
131 hittree->Branch(
"width",&
_width,
"width/D");
132 hittree->Branch(
"time",&
_time,
"time/D");
133 hittree->Branch(
"pe",&
_pe,
"pe/D");
137 _geotree =
new TTree(
"geotree",
"geotree");
138 std::vector<double> pmtX, pmtY, pmtZ;
139 std::vector<double> minX, minY, minZ;
140 std::vector<double> maxX, maxY, maxZ;
141 auto const geop = lar::providerFrom<geo::Geometry>();
143 for(
size_t opch=0; opch<geop->NOpChannels(); ++opch) {
144 geop->OpDetGeoFromOpChannel(opch).GetCenter(PMTxyz);
145 pmtX.push_back(PMTxyz[0]);
146 pmtY.push_back(PMTxyz[1]);
147 pmtZ.push_back(PMTxyz[2]);
149 for(
auto iter=geop->begin_TPC(); iter!=geop->end_TPC(); ++iter) {
150 auto const& tpc = (*iter);
151 minX.push_back(tpc.BoundingBox().MinX());
152 minY.push_back(tpc.BoundingBox().MinY());
153 minZ.push_back(tpc.BoundingBox().MinZ());
154 maxX.push_back(tpc.BoundingBox().MaxX());
155 maxY.push_back(tpc.BoundingBox().MaxY());
156 maxZ.push_back(tpc.BoundingBox().MaxZ());
187 art::Handle< std::vector< raw::OpDetWaveform > > wf_h;
191 throw std::exception();
193 for(
auto const& wf : (*wf_h)) {
194 _wf.resize(wf.size());
195 for(
size_t i=0; i<
_wf.size(); ++i) {
_wf.at(i) = wf.at(i); }
196 _ch=wf.ChannelNumber();
206 art::Handle< std::vector<simb::MCTruth> > mct_h;
208 if(!mct_h.isValid()) {
210 throw std::exception();
212 for(
size_t mct_index=0; mct_index<mct_h->size(); ++mct_index) {
214 auto const& mct = (*mct_h)[mct_index];
216 for(
int i=0; i<mct.NParticles(); ++i) {
217 auto const& mcp = mct.GetParticle(i);
218 if(mcp.StatusCode() != 1)
continue;
220 auto const& pos = mcp.Position(0);
233 if(
_event_time != std::numeric_limits<double>::max()) {
234 auto const geop = lar::providerFrom<geo::Geometry>();
237 for(
size_t opch=0; opch<geop->NOpChannels(); ++opch) {
238 geop->OpDetGeoFromOpChannel(opch).GetCenter(PMTxyz);
242 double dr = sqrt(pow(dx,2)+pow(dy,2)+pow(dz,2));
252 for(
size_t label_idx=0; label_idx<
_hit_label_v.size(); ++label_idx) {
256 art::Handle< std::vector< recob::OpHit > > hit_h;
257 e.getByLabel(label,hit_h);
258 if(!hit_h.isValid()){
259 std::cerr <<
"Invalid producer for recob::OpHit: " << label << std::endl;
260 throw std::exception();
264 for(
auto const&
hit : (*hit_h)) {
Utilities related to art service access.
BEGIN_PROLOG could also be cerr
std::string _output_fname
ICARUSOpHitTuple(fhicl::ParameterSet const &p)
void analyze(art::Event const &e) override
std::vector< std::string > _hit_label_v
ICARUSOpHitTuple & operator=(ICARUSOpHitTuple const &)=delete
std::vector< std::string > _wf_label_v
std::vector< TTree * > _hittree_v
art framework interface to geometry description