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"
42 void analyze(art::Event
const&
e)
override;
59 std::vector<float>
_wf;
86 : EDAnalyzer{p}, _wftree(
nullptr), _mchittree(
nullptr), _geotree(
nullptr)
88 _output_fname =
p.get<std::string>(
"OutputFileName" );
89 _wf_label =
p.get<std::string>(
"OpDetWaveformProducer" );
90 _mchit_label =
p.get<std::string>(
"MCOpHitProducer" );
91 _hit_label_v =
p.get<std::vector<std::string> >(
"OpHitProducerList");
92 _match_time_min =
p.get<
double>(
"MatchTimeStart",0.100);
93 _match_time_max =
p.get<
double>(
"MatchTimeEnd",0.120);
94 _match_dt = _match_time_max - _match_time_min;
104 _wftree =
new TTree(name.c_str(),name.c_str());
105 _wftree->Branch(
"run",&
_run,
"run/I");
106 _wftree->Branch(
"event",&
_event,
"event/I");
107 _wftree->Branch(
"ch",&
_ch,
"ch/I");
108 _wftree->Branch(
"wf",&
_wf);
109 _wftree->Branch(
"tstart",&
_tstart,
"tstart/D");
112 _mchittree =
new TTree(
"mchittree",
"mchittree");
121 std::string
name = label +
"_hittree";
122 auto hittree =
new TTree(name.c_str(),name.c_str());
123 hittree->Branch(
"run",&
_run,
"run/I");
124 hittree->Branch(
"event",&
_event,
"event/I");
125 hittree->Branch(
"ch",&
_ch,
"ch/I");
126 hittree->Branch(
"amp",&
_amp,
"amp/D");
127 hittree->Branch(
"area",&
_area,
"area/D");
128 hittree->Branch(
"width",&
_width,
"width/D");
129 hittree->Branch(
"time",&
_time,
"time/D");
130 hittree->Branch(
"pe",&
_pe,
"pe/D");
131 hittree->Branch(
"time_true",&
_time_true,
"time_true/D");
132 hittree->Branch(
"pe_true",&
_pe_true,
"pe_true/D");
133 hittree->Branch(
"mc_idx",&
_mc_idx,
"mc_idx/I");
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());
188 art::Handle< std::vector< raw::OpDetWaveform > > wf_h;
192 throw std::exception();
194 for(
auto const& wf : (*wf_h)) {
195 _wf.resize(wf.size());
196 for(
size_t i=0; i<
_wf.size(); ++i) {
_wf.at(i) = wf.at(i); }
197 _ch=wf.ChannelNumber();
204 art::Handle< std::vector< recob::OpHit > > mchit_h;
206 if(!mchit_h.isValid()) {
208 throw std::exception();
214 std::vector<std::map<double,int> > mchit_db;
216 auto const geop = lar::providerFrom<geo::Geometry>();
217 mchit_db.resize(geop->NOpChannels());
218 for(
size_t mchit_index=0; mchit_index < mchit_h->size(); ++mchit_index) {
219 auto const& mchit = (*mchit_h)[mchit_index];
222 _ch = mchit.OpChannel();
225 auto&
db = mchit_db.at(mchit.OpChannel());
229 for(
size_t label_idx=0; label_idx<
_hit_label_v.size(); ++label_idx) {
233 art::Handle< std::vector< recob::OpHit > > hit_h;
234 e.getByLabel(label,hit_h);
235 if(!hit_h.isValid()){
236 std::cerr <<
"Invalid producer for recob::OpHit: " << label << std::endl;
237 throw std::exception();
241 std::vector<bool> mchit_used(mchit_h->size(),
false);
243 for(
auto const&
hit : (*hit_h)) {
252 auto const&
db = mchit_db.at(
_ch);
255 _time_true = std::numeric_limits<double>::max();
256 if(
low !=
db.begin()) {
259 auto const& mchit = (*mchit_h).at((*low).second);
265 mchit_used[(*low).second] =
true;
271 for(
size_t mchit_idx=0; mchit_idx < mchit_used.size(); ++mchit_idx) {
272 if(mchit_used[mchit_idx])
continue;
273 auto const& mchit = (*mchit_h)[mchit_idx];
274 _ch = mchit.OpChannel();
278 _time = std::numeric_limits<double>::max();
279 _amp = std::numeric_limits<double>::max();
280 _area = std::numeric_limits<double>::max();
ICARUSOpHitAna & operator=(ICARUSOpHitAna const &)=delete
Utilities related to art service access.
BEGIN_PROLOG could also be cerr
void analyze(art::Event const &e) override
std::vector< std::string > _hit_label_v
std::string _output_fname
standard_dbscan3dalg useful for diagnostics hits not in a line will not be clustered on on only for track like only for track like on on the smaller the less shower like tracks low
std::vector< TTree * > _hittree_v
ICARUSOpHitAna(fhicl::ParameterSet const &p)
height to which particles are projected pnfs larsoft persistent physics cosmics Fermilab CORSIKA standard He_showers_ * db
std::vector< std::string > _wf_label_v
art framework interface to geometry description