9 #ifndef regcnnana_module 10 #define regcnnana_module 28 #include "art_root_io/TFileService.h" 29 #include "art_root_io/TFileDirectory.h" 90 std::unordered_map<const simb::MCParticle*, double> mcEMap);
217 fTree = tfs->make<TTree>(
"anatree",
"anatree");
218 fTree->Branch(
"ievent", &
ievt,
"ievent/I");
241 fTree->Branch(
"nProtonTruth",
nProton,
"nProtonTruth[NuTruthN]/I");
242 fTree->Branch(
"nPionTruth",
nPion,
"nPionTruth[NuTruthN]/I");
243 fTree->Branch(
"nPizeroTruth",
nPizero,
"nPizeroTruth[NuTruthN]/I");
244 fTree->Branch(
"nNeutronTruth",
nNeutron,
"nNeutronTruth[NuTruthN]/I");
261 fTree->Branch(
"track_id",
track_id,
"track_id[n_track_pad]/I");
300 mf::LogWarning(
"RegCNNAna")<<
" Cannot access the electron shower which is needed for this energy reconstruction method.\n" 308 const double hadronicObservedCharge(eventObservedCharge-electronObservedCharge);
319 mf::LogWarning(
"RegCNNAna")<<
" Cannot access the muon track which is needed for this energy reconstruction method.\n" 326 const double hadronicObservedCharge(eventObservedCharge-leptonObservedCharge);
335 std::vector<art::Ptr<simb::MCTruth> > mclist;
338 if (mctruthListHandle)
343 std::vector<art::Ptr<recob::Hit> > hits;
351 std::vector<art::Ptr<recob::Track> > trackDir;
355 art::FindManyP<recob::Hit> fmtrkDir(trackHandleDir, evt,
fTrackLabelDir);
357 if (trackHandleDir.isValid()) {
359 for (
int itrack= 0; itrack<
n_track_pad; ++itrack) {
366 if (fmtrkDir.isValid()) {
367 std::vector<art::Ptr<recob::Hit> > vhit = fmtrkDir.at(itrack);
368 std::unordered_map<const simb::MCParticle*, double> mcEMap;
369 for (
size_t ihit= 0; ihit< vhit.size(); ++ihit) {
371 for (
size_t e= 0;
e< trackIDs.size(); ++
e) {
375 std::vector<std::pair<const simb::MCParticle*, double> > trkTrue =
get_sortedMCParticle(mcEMap);
376 if (trkTrue.size()> 0) {
378 all_track_true_pdg_mom[itrack] = trkTrue[0].first->Mother()==0 ? -1 : trueParticles[trkTrue[0].first->Mother()]->PdgCode();
379 TVector3 v3_true(trkTrue[0].first->Momentum().Vect());
389 std::vector<art::Ptr<recob::Shower> > showersDir;
393 art::FindManyP<recob::Hit> fmshDir(showerHandleDir, evt,
fShowerLabelDir);
395 if (showerHandleDir.isValid()) {
397 for (
int ishower= 0; ishower<
n_showers; ++ishower) {
404 if (fmshDir.isValid()) {
405 std::vector<art::Ptr<recob::Hit> > vhit = fmshDir.at(ishower);
406 std::unordered_map<const simb::MCParticle*, double> mcEMap;
407 for (
size_t ihit= 0; ihit< vhit.size(); ++ihit) {
409 for (
size_t e= 0;
e< trackIDs.size(); ++
e) {
413 std::vector<std::pair<const simb::MCParticle*, double> > shwTrue =
get_sortedMCParticle(mcEMap);
414 if (shwTrue.size()> 0) {
416 all_shower_true_pdg_mom[ishower] = shwTrue[0].first->Mother()==0 ? -1 : trueParticles[shwTrue[0].first->Mother()]->PdgCode();
417 TVector3 v3_true(shwTrue[0].first->Momentum().Vect());
434 auto cnnresultListHandle = evt.
getHandle<std::vector<cnn::RegCNNResult>>(itag1);
438 auto RegCnnProngResultListHandle = evt.
getHandle<std::vector<cnn::RegCNNResult>>(itag2);
442 auto RegCnnDirResultListHandle = evt.
getHandle<std::vector<cnn::RegCNNResult> >(itag3);
450 if (mclist.size()>0) {
452 for(
size_t iList = 0; (iList < mclist.size()) && (neutrino_i <
kMax) ; ++iList) {
453 if (mclist[iList]->NeutrinoSet()) {
483 if (pdg > 2000000000) {
491 case 111 : ++
nPizero[neutrino_i];
break;
492 case 211 : ++
nPion[neutrino_i];
break;
493 case 2112 : ++
nNeutron[neutrino_i];
break;
494 case 2212 : ++
nProton[neutrino_i];
break;
513 bool fid_flag =
false;
514 for(
size_t iHit = 0; iHit < hits.size(); ++iHit)
523 if (peakT > 4482.) fid_flag =
true;
525 if (tpc < 4 && wire < 5) fid_flag =
true;
526 if (tpc > 19 && wire > 474) fid_flag =
true;
530 if (!fid_flag)
InDet = 1;
543 if (!engrecoHandle.failedToGet())
545 ErecoNu = engrecoHandle->fNuLorentzVector.E();
546 RecoLepEnNu = engrecoHandle->fLepLorentzVector.E();
547 RecoHadEnNu = engrecoHandle->fHadLorentzVector.E();
554 if (!cnnresultListHandle.failedToGet())
556 if (!cnnresultListHandle->empty())
558 const std::vector<float>& v = (*cnnresultListHandle)[0].fOutput;
560 for (
unsigned int ii = 0; ii < 3; ii++){
566 if (!RegCnnProngResultListHandle.failedToGet())
568 if (!RegCnnProngResultListHandle->empty())
570 const std::vector<float>& v = (*RegCnnProngResultListHandle)[0].fOutput;
575 if (!RegCnnDirResultListHandle.failedToGet()) {
576 if (!RegCnnDirResultListHandle->empty()) {
577 const std::vector<float>& v = (*RegCnnDirResultListHandle)[0].fOutput;
578 for (
unsigned int i= 0; i< v.size(); ++i) {
585 for (
int itrack= 0; itrack<
n_track_pad; ++itrack) {
596 double cosTheta = dot/norm_regcnn_dir/norm_true_dir;
603 for (
int ishower= 0; ishower<
n_showers; ++ishower) {
614 double cosTheta = dot/norm_regcnn_dir/norm_true_dir;
650 for (
int ii = 0; ii < 3; ii++){
660 for (
int ii = 0; ii <
kMax; ++ii)
705 if (0 == tracks.size())
708 double longestLength(std::numeric_limits<double>::lowest());
709 for (
unsigned int iTrack = 0; iTrack < tracks.size(); ++iTrack)
711 const double length(tracks[iTrack]->
Length());
712 if (length-longestLength > std::numeric_limits<double>::epsilon())
714 longestLength = length;
715 pTrack = tracks[iTrack];
752 if (0 == showers.size())
755 double maxCharge(std::numeric_limits<double>::lowest());
756 for (
unsigned int iShower = 0; iShower < showers.size(); ++iShower)
761 if (showerCharge-maxCharge > std::numeric_limits<double>::epsilon())
763 maxCharge = showerCharge;
764 pShower = showers[iShower];
801 std::vector<std::pair<const simb::MCParticle*, double> >
803 std::vector<std::pair<const simb::MCParticle*, double> > outVec;
805 for (std::pair<const simb::MCParticle*, double>
const&
p: mcEMap) {
809 std::sort(outVec.begin(), outVec.end(), [](std::pair<const simb::MCParticle*, double>
a, std::pair<const simb::MCParticle*, double>
b){
return a.second >
b.second;});
810 if (
abs(total_E) < 1
e-6) {total_E = 1;}
811 for (std::pair<const simb::MCParticle*, double> &
p: outVec) {
820 #endif // regcnnana_module double E(const int i=0) const
float Length(const PFPStruct &pfp)
Utility containing helpful functions for end users to access information about Hits.
std::string fParticleLabel
double fRecombFactor
the average reccombination factor
double all_shower_true_px[kMax]
float regcnn_nue_dir_diff
double GetMomentumMultiScatterChi2(art::Ptr< recob::Track > const &trk)
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
Utility containing helpful functions for end users to access information about Tracks.
Handle< PROD > getHandle(SelectorBase const &) const
const simb::MCParticle * TrackIdToParticle_P(int id) const
geo::WireID WireID() const
calo::CalorimetryAlg fCalorimetryAlg
the calorimetry algorithm
const simb::MCParticle & Nu() const
art::Ptr< recob::Shower > GetHighestChargeShower(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const art::Event &event)
std::vector< std::pair< const simb::MCParticle *, double > > get_sortedMCParticle(std::unordered_map< const simb::MCParticle *, double > mcEMap)
double all_shower_true_pz[kMax]
Vector_t VertexDirection() const
static std::vector< art::Ptr< recob::Hit > > GetHits(const art::Event &evt, const std::string &label)
Get the hits from the event.
std::vector< const simb::MCParticle * > MCTruthToParticles_Ps(art::Ptr< simb::MCTruth > const &mct) const
int all_track_true_pdg[kMax]
RegCNNAna(fhicl::ParameterSet const &pset)
WireID_t Wire
Index of the wire within its plane.
std::string fRegCNNModuleLabel
std::string fTrackToHitLabel
EDAnalyzer(fhicl::ParameterSet const &pset)
static std::vector< art::Ptr< recob::Hit > > GetHits(const art::Ptr< recob::Track > &pTrack, const art::Event &evt, const std::string &label)
Get the hits associated with the track.
double fUncorrectedMuMomMCS
art framework interface to geometry description
double nuvtxy_truth[kMax]
void reconfigure(fhicl::ParameterSet const &p)
double all_track_true_py[kMax]
double ElectronsFromADCArea(double area, unsigned short plane) const
static std::vector< art::Ptr< recob::Track > > GetTracks(const art::Event &evt, const std::string &label)
Get the tracks from the event. This function shouldn't be used as the basis of an analysis...
constexpr double kGeVToElectrons
23.6eV per ion pair, 1e9 eV/GeV
double Length(size_t p=0) const
Access to various track properties.
const simb::MCParticle & Lepton() const
float regcnn_prong_energy
double lepEng_truth[kMax]
double nuvtxx_truth[kMax]
#define DEFINE_ART_MODULE(klass)
int all_track_true_pdg_mom[kMax]
Utility containing helpful functions for end users to access information about Showers.
double all_track_pz[kMax]
double all_shower_pz[kMax]
T get(std::string const &key) const
int all_shower_true_pdg[kMax]
double fUncorrectedHadEnFromShw
bool isNull() const noexcept
Utility containing helpful functions for end users to access information about PFParticles.
std::string fRegCNNProngModuleLabel
std::string fRegCNNDirModuleLabel
Utility containing helpful functions for end users to access products from events.
const TVector3 & Direction() const
static double LifetimeCorrectedTotalHitCharge(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const std::vector< art::Ptr< recob::Hit > > &hits)
get the total hit charge, corrected for lifetime
PlaneID_t Plane
Index of the plane within its TPC.
Detector simulation of raw signals on wires.
const sim::ParticleList & ParticleList() const
std::string fMCGenModuleLabel
RegCNNResult for RegCNN modified from Result.h.
double Vx(const int i=0) const
art::ServiceHandle< cheat::BackTrackerService > backtracker
std::string fShowerToHitLabel
float PeakTime() const
Time of the signal peak, in tick units.
Declaration of signal hit object.
double all_track_py[kMax]
double fUncorrectedElectronEnergy
static std::vector< art::Ptr< recob::Hit > > GetHits(const art::Ptr< recob::Shower > &pShower, const art::Event &evt, const std::string &label)
Get the hits associated with the shower.
Contains all timing reference information for the detector.
double all_track_true_pz[kMax]
double all_shower_px[kMax]
const TLorentzVector & Momentum(const int i=0) const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Provides recob::Track data product.
art::Ptr< recob::Track > GetLongestTrack(const art::Event &event)
double Vz(const int i=0) const
std::string fRegCNNDirResultLabel
double CalculateEnergyFromCharge(const double charge)
Converts deposited charge into energy by converting to number of electrons and correcting for average...
int all_shower_true_pdg_mom[kMax]
EventNumber_t event() const
std::string fRegCNNResultLabel
Declaration of basic channel signal object.
void beginSubRun(const art::SubRun &sr) override
double all_shower_py[kMax]
std::string fHitsModuleLabel
static std::vector< art::Ptr< recob::Shower > > GetShowers(const art::Event &evt, const std::string &label)
Get the showers from the event. This function shouldn't be used as the basis of an analysis...
std::string fTrackLabelDir
std::string fEnergyRecoNuLabel
auto const & get(AssnsNode< L, R, D > const &r)
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
TPCID_t TPC
Index of the TPC within its cryostat.
double nuvtxz_truth[kMax]
static constexpr double sr
Event generator information.
double all_track_px[kMax]
void endSubRun(const art::SubRun &sr) override
std::string fShowerLabelDir
double all_track_true_px[kMax]
art::ServiceHandle< cheat::ParticleInventoryService > particleinventory
double all_shower_true_py[kMax]
double Vy(const int i=0) const
std::string fRegCNNProngResultLabel
QTextStream & endl(QTextStream &s)
Event finding and building.
static std::vector< art::Ptr< recob::Hit > > GetHitsOnPlane(const std::vector< art::Ptr< recob::Hit >> &hits, const geo::PlaneID::PlaneID_t planeID)
Get all hits on a specific plane.
void analyze(art::Event const &evt) override