PrimaryPionSelection_module.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////
2 // Class: PrimaryPionSelection
3 // Plugin Type: filter (art v3_02_06)
4 // File: PrimaryPionSelection_module.cc
5 //
6 // Generated at Tue Jul 9 08:37:33 2019 by Jacob Calcutt using cetskelgen
7 // from cetlib version v3_07_02.
8 ////////////////////////////////////////////////////////////////////////
9 
17 #include "fhiclcpp/ParameterSet.h"
19 
20 #include <memory>
21 
27 
32 #include "canvas/Persistency/Common/FindManyP.h"
35 
36 #include "TFile.h"
37 #include "TProfile.h"
38 
40 
41 
43 public:
45  // The compiler-generated destructor is fine for non-base
46  // classes without bare pointers or other resource use.
47 
48  // Plugins should not be copied or assigned.
53 
54  // Required functions.
55  bool filter(art::Event& e) override;
56 
57 private:
58 
60  //fhicl::ParameterSet BeamCuts;
67 
70 
71  //std::pair< double, double > fTrackStartXCut;
72  //std::pair< double, double > fTrackStartYCut;
73  //std::pair< double, double > fTrackStartZCut;
74  double fTrackEndZCut;
75  //double fTrackDirCut;
77  bool fUseMVA;
79  double fChi2PIDCut;
80 
83  TProfile * profile;
84 
85  bool InRange(double, double, double);
86 };
87 
88 
90  : EDFilter{p} ,
91 
92  beamlineUtil( p.get< fhicl::ParameterSet >("BeamlineUtils")),
93  beam_cuts( p.get< fhicl::ParameterSet >("BeamCuts") ),
94  fNominalMomentum( p.get< std::string >("NominalMomentum") ),
95  fPFParticleTag( p.get< std::string >("PFParticleTag")),
96  fTrackerTag( p.get< std::string >("TrackerTag")),
97  fShowerTag( p.get< std::string >("ShowerTag")),
98  fCalorimetryTag( p.get< std::string >("CalorimetryTag")),
99  fCalorimetryParameters( p.get< fhicl::ParameterSet >("CalorimetryParameters")),
100  fGeneratorTag( p.get< std::string >("GeneratorTag") ),
101 
102  //fTrackStartXCut( p.get< std::pair< double, double> >("TrackStartXCut") ),
103  //fTrackStartYCut( p.get< std::pair< double, double> >("TrackStartYCut") ),
104  //fTrackStartZCut( p.get< std::pair< double, double> >("TrackStartZCut") ),
105  fTrackEndZCut( p.get< double >("TrackEndZCut") ),
106  // fTrackDirCut( p.get< double>("TrackDirCut") ),
107  fStrictNTracks( p.get< bool >("StrictNTracks") ),
108  fUseMVA( p.get< bool >("UseMVA") ),
109  fDaughterCNNCut( p.get< double >("DaughterCNNCut") ),
110  fChi2PIDCut( p.get< double >("Chi2PIDCut") ),
111 
112  dEdX_template_name(p.get<std::string>("dEdX_template_name")),
113  dEdX_template_file( dEdX_template_name.c_str(), "OPEN" )
114 
115 {
116  profile = (TProfile*)dEdX_template_file.Get( "dedx_range_pro" );
117 }
118 
120 {
124 
125  if( e.isRealData() ){
126  if( !fBeamlineUtils.IsGoodBeamlineTrigger( e ) ){
127  MF_LOG_INFO("PrimaryPionSelection") << "Failed Beamline Trigger Check" << "\n";
128  return false;
129  }
130  }
131 
132 
133  std::vector<const recob::PFParticle*> beamParticles = pfpUtil.GetPFParticlesFromBeamSlice(e,fPFParticleTag);
134  if(beamParticles.size() == 0){
135  MF_LOG_INFO("PrimaryPionSelection") << "We found no beam particles for this event... moving on" << "\n";
136  return false;
137  }
138 
139  // Get the reconstructed PFParticle tagged as beam by Pandora
140  const recob::PFParticle* particle = beamParticles.at(0);
141 
142  // Determine if the beam particle is track-like or shower-like
143  const recob::Track* thisTrack = pfpUtil.GetPFParticleTrack(*particle,e,fPFParticleTag,fTrackerTag);
144  const recob::Shower* thisShower = pfpUtil.GetPFParticleShower(*particle,e,fPFParticleTag,fShowerTag);
145 
146  if( !thisTrack && thisShower ){
147  MF_LOG_INFO("PrimaryPionSelection") << "Beam Particle Reconstructed as shower" << "\n";
148  return false;
149  }
150  else if( !thisShower && !thisTrack ){
151  MF_LOG_INFO("PrimaryPionSelection") << "Beam Particle Not Reconstructed" << "\n";
152  return false;
153  }
154  else{
155  MF_LOG_INFO("PrimaryPionSelection") << "Beam Particle Reconstructed as track" << "\n";
156  }
157  ////////////////////////////////////////////////////////////////////
158  //The beam Particle has beam Type 13 like in PionAnalyzer module ////
159 
160 
161  if( !beam_cuts.IsBeamlike( *thisTrack, e, fNominalMomentum ) ){
162  MF_LOG_INFO("PrimaryPionSelection") << "Beam Particle failed Beam Cuts" << "\n";
163  return false;
164  }
165 
166 
167  //Here add in the cuts for the position of the beam and the incident angle
168  //First: need to switch reversed tracks
169  double endZ = thisTrack->Trajectory().End().Z();
170  double startZ = thisTrack->Trajectory().Start().Z();
171  if( startZ > endZ ){
172  double tempZ = endZ;
173  endZ = startZ;
174  startZ = tempZ;
175  }
176  //Cut for track length to cut out muons/keep the track within the APA3?
177  if( endZ > fTrackEndZCut ){
178  MF_LOG_INFO("PrimaryPionSelection") << "Failed End Z cut" << "\n";
179  return false;
180  }
181 
182 
183  //**********IGNORE DAUGHTERS FOR NOW*******
184  //Get some objects to use for CNN output checking later
185  //anab::MVAReader< recob::Hit, 4 > * hitResults = 0x0;
186  ////if( fUseMVA ) hitResults = new anab::MVAReader<recob::Hit,4>(e, "emtrkmichelid:emtrkmichel" );
187  //auto recoTracks = e.getValidHandle<std::vector<recob::Track> >(fTrackerTag);
188  //art::FindManyP<recob::Hit> findHits(recoTracks,e,fTrackerTag);
189  ////////////////////////////
190 
191 
192  //Look at the daughters and check for track-like daughters that look like showers
193  //to try to pick out misreco'd pi0 gammas
194  /*
195 
196  const std::vector< const recob::Track* > trackDaughters = pfpUtil.GetPFParticleDaughterTracks( *particle, e, fPFParticleTag, fTrackerTag );
197 
198  for( size_t i = 0; i < trackDaughters.size(); ++i ){
199  auto daughterTrack = trackDaughters.at(i);
200 
201 
202  auto daughterHits = findHits.at( daughterTrack->ID() );
203 
204  if( fUseMVA ){
205  double track_total = 0.;
206  for( size_t h = 0; h < daughterHits.size(); ++h ){
207  std::array<float,4> cnn_out = hitResults->getOutput( daughterHits[h] );
208  track_total += cnn_out[ hitResults->getIndex("track") ];
209  }
210 
211  if( track_total < fDaughterCNNCut ){
212  MF_LOG_INFO("PrimaryPionSelection") << "Found daughter track that looks like shower" << "\n";
213  continue;
214  }
215  }
216 
217  //Now: If it's not a potential gamma, pass the calorimetry through the
218  // Chi2 PID and see if any MIP-like daughters are associated
219 
220  auto daughter_calo = trackUtil.GetRecoTrackCalorimetry( *daughterTrack, e, fTrackerTag, fCalorimetryTag );
221  std::vector<float> calo_range = daughter_calo[0].ResidualRange();
222  std::vector<float> calo_dEdX;
223  if( e.isRealData() ) calo_dEdX = trackUtil.CalibrateCalorimetry( *daughterTrack, e, fTrackerTag, fCalorimetryTag, fCalorimetryParameters );
224  else calo_dEdX = daughter_calo[0].dEdx();
225 
226  std::vector<double> daughter_range, daughter_dEdX;
227  for( size_t j = 0; j < calo_range.size(); ++j ){
228  daughter_range.push_back( calo_range[i] );
229  daughter_dEdX.push_back( calo_dEdX[i] );
230  }
231 
232  std::pair< double,int > chi2_pid_results = trackUtil.Chi2PID( daughter_dEdX, daughter_range, profile );
233 
234  if( chi2_pid_results.first > fChi2PIDCut ){
235  MF_LOG_INFO("PrimaryPionSelection") << "Found daughter with MIP-like Chi2 PID" << "\n";
236  return false;
237  }
238  }
239 
240  */
241 
242 
243 
244  return true;
245 }
246 
247 bool PrimaryPionSelection::InRange(double input, double low, double high){
248  return ( (input >= low) && (input <= high) );
249 }
250 
protoana::ProtoDUNEBeamCuts beam_cuts
const recob::Shower * GetPFParticleShower(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string showerLabel) const
Get the shower associated to this particle. Returns a null pointer if not found.
std::string string
Definition: nybbler.cc:12
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Definition: Track.h:98
PrimaryPionSelection & operator=(PrimaryPionSelection const &)=delete
bool filter(art::Event &e) override
bool InRange(double, double, double)
Particle class.
PrimaryPionSelection(fhicl::ParameterSet const &p)
bool IsBeamlike(const recob::Track &, const art::Event &, std::string)
bool isRealData() const
const double e
static int input(void)
Definition: code.cpp:15695
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
const recob::Track * GetPFParticleTrack(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
Get the track associated to this particle. Returns a null pointer if not found.
p
Definition: test.py:223
const std::vector< const recob::PFParticle * > GetPFParticlesFromBeamSlice(art::Event const &evt, const std::string particleLabel) const
Return the pointers for the PFParticles in the beam slice. Returns an empty vector is no beam slice w...
bool IsGoodBeamlineTrigger(art::Event const &evt) const
fhicl::ParameterSet fCalorimetryParameters
#define MF_LOG_INFO(category)
Hierarchical representation of particle flow.
Definition: PFParticle.h:44
Point_t const & End() const
Returns the position of the last valid point of the trajectory [cm].
Provides recob::Track data product.
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.h:21
Point_t const & Start() const
Returns the position of the first valid point of the trajectory [cm].
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49