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"
27 #include <TLorentzVector.h>
46 void analyze(art::Event
const&
e)
override;
88 : EDAnalyzer{p}, _geotree(
nullptr)
90 _output_fname =
p.get<std::string>(
"OutputFileName");
91 _mcflash_label =
p.get<std::string>(
"MCOpFlashProducer",
"");
92 _mctruth_label =
p.get<std::string>(
"MCTruthProducer",
"");
93 _flash_label_v =
p.get<std::vector<std::string> >(
"OpFlashProducerList");
94 _match_time_min =
p.get<
double>(
"MatchTimeStart",0.105);
95 _match_time_max =
p.get<
double>(
"MatchTimeEnd",0.120);
96 _match_dt = _match_time_max - _match_time_min;
105 std::string
name = label +
"_flashtree";
106 auto flashtree =
new TTree(name.c_str(),name.c_str());
107 flashtree->Branch(
"run",&
_run,
"run/I");
108 flashtree->Branch(
"event",&
_event,
"event/I");
109 flashtree->Branch(
"time",&
_time,
"time/D");
110 flashtree->Branch(
"pe_v",&
_pe_v);
111 flashtree->Branch(
"pe_sum",&
_pe_sum,
"pe_sum/D");
113 flashtree->Branch(
"time_true",&
_time_true,
"time_true/D");
115 flashtree->Branch(
"pe_sum_true",&
_pe_sum_true,
"pe_sum_true/D");
116 flashtree->Branch(
"x",&
_x,
"x/D");
117 flashtree->Branch(
"y",&
_y,
"y/D");
118 flashtree->Branch(
"z",&
_z,
"z/D");
119 flashtree->Branch(
"nphotons",&
_nphotons,
"nphotons/D");
124 _geotree =
new TTree(
"geotree",
"geotree");
125 std::vector<double> pmtX, pmtY, pmtZ;
126 std::vector<double> minX, minY, minZ;
127 std::vector<double> maxX, maxY, maxZ;
128 auto const geop = lar::providerFrom<geo::Geometry>();
130 for(
size_t opch=0; opch<geop->NOpChannels(); ++opch) {
131 geop->OpDetGeoFromOpChannel(opch).GetCenter(PMTxyz);
132 pmtX.push_back(PMTxyz[0]);
133 pmtY.push_back(PMTxyz[1]);
134 pmtZ.push_back(PMTxyz[2]);
136 for(
auto iter=geop->begin_TPC(); iter!=geop->end_TPC(); ++iter) {
137 auto const& tpc = (*iter);
138 minX.push_back(tpc.ActiveBoundingBox().MinX());
139 minY.push_back(tpc.ActiveBoundingBox().MinY());
140 minZ.push_back(tpc.ActiveBoundingBox().MinZ());
141 maxX.push_back(tpc.ActiveBoundingBox().MaxX());
142 maxY.push_back(tpc.ActiveBoundingBox().MaxY());
143 maxZ.push_back(tpc.ActiveBoundingBox().MaxZ());
172 art::Handle< std::vector< simb::MCTruth > > mctruth_h;
173 std::map<double, int> mctruth_db;
176 for (
size_t mctruth_index = 0; mctruth_index < mctruth_h->size(); ++mctruth_index) {
177 auto const& mctruth = (*mctruth_h)[mctruth_index];
178 for (
int part_idx = 0; part_idx < mctruth.NParticles(); ++part_idx) {
179 const simb::MCParticle & particle = mctruth.GetParticle(part_idx);
188 art::Handle< std::vector< recob::OpFlash > > mcflash_h;
191 if(!mcflash_h.isValid()) {
193 throw std::exception();
199 std::map<double,int> mcflash_db;
203 for(
size_t mcflash_index=0; mcflash_index < mcflash_h->size(); ++mcflash_index) {
204 auto const&
mcflash = (*mcflash_h)[mcflash_index];
209 for(
size_t label_idx=0; label_idx<
_flash_label_v.size(); ++label_idx) {
213 art::Handle< std::vector< recob::OpFlash > > flash_h;
214 e.getByLabel(label,flash_h);
215 if(!flash_h.isValid()){
216 std::cerr <<
"Invalid producer for recob::OpFlash: " << label << std::endl;
217 throw std::exception();
221 std::vector<bool> mcflash_used;
222 if(!
_mcflash_label.empty()) { mcflash_used.resize(mcflash_h->size(),
false); }
224 for(
auto const& flash : (*flash_h)) {
226 _time = flash.Time();
232 auto low_mct = mctruth_db.lower_bound(
_time);
233 if (low_mct != mctruth_db.begin()) {
235 auto const& mctruth = (*mctruth_h).at(0);
236 auto const& particle = mctruth.GetParticle((*low_mct).second);
237 if ( (particle.T() - (*low_mct).first) <
_match_dt) {
245 auto low = mcflash_db.lower_bound(
_time);
248 _time_true = std::numeric_limits<double>::max();
250 if(
low != mcflash_db.begin()) {
253 auto const&
mcflash = (*mcflash_h).at((*low).second);
260 mcflash_used[(*low).second] =
true;
261 std::cout <<
mcflash.TotalPE() <<
" " << std::accumulate(_pe_true_v.begin(), _pe_true_v.end(), 0.) << std::endl;
271 for(
size_t mcflash_idx=0; mcflash_idx < mcflash_used.size(); ++mcflash_idx) {
272 if(mcflash_used[mcflash_idx])
continue;
273 auto const&
mcflash = (*mcflash_h)[mcflash_idx];
279 _time = std::numeric_limits<double>::max();
Utilities related to art service access.
BEGIN_PROLOG could also be cerr
std::string _mctruth_label
std::vector< TTree * > _flashtree_v
ICARUSOpFlashAna(fhicl::ParameterSet const &p)
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< double > _pe_true_v
std::vector< double > _pe_v
std::vector< std::string > _flash_label_v
std::string _mcflash_label
ICARUSOpFlashAna & operator=(ICARUSOpFlashAna const &)=delete
art framework interface to geometry description
BEGIN_PROLOG could also be cout
std::string _output_fname
void analyze(art::Event const &e) override