Public Member Functions | Private Member Functions | Private Attributes | List of all members
filt::NucleonDecayFilter Class Reference
Inheritance diagram for filt::NucleonDecayFilter:
art::EDFilter art::detail::Filter art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Member Functions

 NucleonDecayFilter (fhicl::ParameterSet const &pset)
 
virtual ~NucleonDecayFilter ()
 
virtual bool filter (art::Event &e)
 
void reconfigure (fhicl::ParameterSet const &pset)
 
void beginJob ()
 
- Public Member Functions inherited from art::EDFilter
 EDFilter (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDFilter (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Filter
virtual ~Filter () noexcept
 
 Filter (fhicl::ParameterSet const &)
 
 Filter (Filter const &)=delete
 
 Filter (Filter &&)=delete
 
Filteroperator= (Filter const &)=delete
 
Filteroperator= (Filter &&)=delete
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void FillVars (std::vector< int > &TrackIDVec, int &numParts, int ThisID)
 

Private Attributes

double ActiveBounds [6]
 
std::map< int, const simb::MCParticle * > truthmap
 
art::ServiceHandle< geo::Geometrygeom
 
bool fWantMuon
 
bool fWantPion
 
bool fWantPi0
 
bool fWantKaon
 
bool fWantElec
 
TTree * MyOutTree
 
int Run
 
int SubRun
 
int Event
 
int nMuon
 
int nPion
 
int nPi0
 
int nKaon
 
int nElec
 

Additional Inherited Members

- Public Types inherited from art::EDFilter
using ModuleType = EDFilter
 
using WorkerType = WorkerT< EDFilter >
 
- Public Types inherited from art::detail::Filter
template<typename UserConfig >
using Table = Modifier::Table< UserConfig >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 
- Static Public Attributes inherited from art::detail::Filter
static constexpr bool Pass {true}
 
static constexpr bool Fail {false}
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 50 of file NucleonDecayFilter_module.cc.

Constructor & Destructor Documentation

filt::NucleonDecayFilter::NucleonDecayFilter ( fhicl::ParameterSet const &  pset)
explicit
virtual filt::NucleonDecayFilter::~NucleonDecayFilter ( )
inlinevirtual

Definition at line 53 of file NucleonDecayFilter_module.cc.

53 {};

Member Function Documentation

void filt::NucleonDecayFilter::beginJob ( )
virtual

Reimplemented from art::EDFilter.

Definition at line 195 of file NucleonDecayFilter_module.cc.

195  {
196  ActiveBounds[0] = ActiveBounds[2] = ActiveBounds[4] = DBL_MAX;
197  ActiveBounds[1] = ActiveBounds[3] = ActiveBounds[5] = -DBL_MAX;
198  // ----- FixMe: Assume single cryostats ------
199  auto const* geom = lar::providerFrom<geo::Geometry>();
200  for (geo::TPCGeo const& TPC: geom->IterateTPCs()) {
201  // get center in world coordinates
202  const double origin[3] = {0.};
203  double center[3] = {0.};
204  TPC.LocalToWorld(origin, center);
205  double tpcDim[3] = {TPC.HalfWidth(), TPC.HalfHeight(), 0.5*TPC.Length() };
206  if( center[0] - tpcDim[0] < ActiveBounds[0] ) ActiveBounds[0] = center[0] - tpcDim[0];
207  if( center[0] + tpcDim[0] > ActiveBounds[1] ) ActiveBounds[1] = center[0] + tpcDim[0];
208  if( center[1] - tpcDim[1] < ActiveBounds[2] ) ActiveBounds[2] = center[1] - tpcDim[1];
209  if( center[1] + tpcDim[1] > ActiveBounds[3] ) ActiveBounds[3] = center[1] + tpcDim[1];
210  if( center[2] - tpcDim[2] < ActiveBounds[4] ) ActiveBounds[4] = center[2] - tpcDim[2];
211  if( center[2] + tpcDim[2] > ActiveBounds[5] ) ActiveBounds[5] = center[2] + tpcDim[2];
212  } // for all TPC
213  std::cout << "Active Boundaries: "
214  << "\n\tx: " << ActiveBounds[0] << " to " << ActiveBounds[1]
215  << "\n\ty: " << ActiveBounds[2] << " to " << ActiveBounds[3]
216  << "\n\tz: " << ActiveBounds[4] << " to " << ActiveBounds[5]
217  << std::endl;
218 
220  MyOutTree = tfs->make<TTree>("FilterTree","FilterTree");
221  MyOutTree->Branch( "Run", &Run , "Run/I" );
222  MyOutTree->Branch( "SubRun",&SubRun, "SubRun/I" );
223  MyOutTree->Branch( "Event", &Event , "Event/I" );
224  MyOutTree->Branch( "nMuon", &nMuon , "nMuon/I" );
225  MyOutTree->Branch( "nPion", &nPion , "nPion/I" );
226  MyOutTree->Branch( "nPi0" , &nPi0 , "nPi0/I" );
227  MyOutTree->Branch( "nKaon", &nKaon , "nKaon/I" );
228  MyOutTree->Branch( "nElec", &nElec , "nElec/I" );
229  }
Geometry information for a single TPC.
Definition: TPCGeo.h:38
art::ServiceHandle< geo::Geometry > geom
IteratorBox< TPC_iterator,&GeometryCore::begin_TPC,&GeometryCore::end_TPC > IterateTPCs() const
Enables ranged-for loops on all TPCs of the detector.
def center(depos, point)
Definition: depos.py:117
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227
QTextStream & endl(QTextStream &s)
void filt::NucleonDecayFilter::FillVars ( std::vector< int > &  TrackIDVec,
int &  numParts,
int  ThisID 
)
private

Definition at line 231 of file NucleonDecayFilter_module.cc.

231  {
232  std::vector<int>::iterator it=std::find( TrackIDVec.begin(), TrackIDVec.end(), abs(ThisID) );
233  if ( it==TrackIDVec.end() ) {
234  TrackIDVec.push_back ( abs(ThisID) ); // Push back this particle type IDVec
235  ++numParts;
236  }
237  }
intermediate_table::iterator iterator
T abs(T value)
bool filt::NucleonDecayFilter::filter ( art::Event e)
virtual

Implements art::EDFilter.

Definition at line 104 of file NucleonDecayFilter_module.cc.

104  {
105  Run = e.run();
106  SubRun = e.subRun();
107  Event = e.event();
108  nMuon = nPion = nPi0 = nKaon = nElec = 0;
109 
110  // Any providers I need.
111  auto const* geo = lar::providerFrom<geo::Geometry>();
112 
113  // Make a map of MCParticles which I can access later.
114  auto truth = e.getHandle<std::vector<simb::MCParticle> >("largeant");
115  truthmap.clear();
116  for (size_t i=0; i<truth->size(); i++)
117  truthmap[truth->at(i).TrackId()]=&((*truth)[i]);
118  //std::cout << "The primary muon in this event had an energy of " << truthmap[1]->E() << std::endl;
119 
120  // Get a vector of sim channels.
121  auto simchannels = e.getHandle<std::vector<sim::SimChannel> >("largeant");
122 
123  // Make vectors to hold all of my particle TrackIDs
124  std::vector<int> MuonVec, PionVec, Pi0Vec, KaonVec, ElecVec;
125 
126  // ------ Now loop through all of my hits ------
127  for (auto const& simchannel:*simchannels) {
128  // ------ Only want to look at collection plane hits ------
129  if (geo->SignalType(simchannel.Channel()) != geo::kCollection) continue;
130  // ------ Loop through all the IDEs for this channel ------
131  for (auto const& tdcide:simchannel.TDCIDEMap()) {
132  auto const& idevec=tdcide.second;
133  // ------ Look at each individual IDE ------
134  for (auto const& ide:idevec) {
135  int ideTrackID = ide.trackID;
136  double idePos[3];
137  idePos[0] = ide.x;
138  idePos[1] = ide.y;
139  idePos[2] = ide.z;
140  // ------ Is the hit in a TPC? ------
141  geo::TPCID tpcid=geo->FindTPCAtPosition(idePos);
142  if (!(geo->HasTPC(tpcid)) ) {
143  //std::cout << "Outside the Active volume I found at the top!" << std::endl;
144  continue;
145  }
146  // ------ Now to work out which particles in particular I want to save more information about... ------
147  // ----------------- I want to write out the IDE to the relevant parent particle type -----------------
148  // ------- This means looping back through the IDE's parents until I find an interesting TrackID ------
149  bool WrittenOut = false;
150  while ( ideTrackID != 0 && !WrittenOut ) {
151  const simb::MCParticle& part=*( truthmap[ abs(ideTrackID) ] );
152  int PdgCode=part.PdgCode();
153  WrittenOut = true; // If one of my particles don't want to go further back.
154  // ========== Muons ==========
155  if ( (PdgCode == -13 || PdgCode == 13) )
156  FillVars( MuonVec, nMuon, ideTrackID );
157  // ========== Pions ==========
158  else if ( (PdgCode == -211 || PdgCode == 211) && part.Process() != "pi+Inelastic" && part.Process() != "pi-Inelastic" )
159  FillVars( PionVec, nPion, ideTrackID );
160  // ========== Pi0s ==========
161  else if ( PdgCode == 111 )
162  FillVars( Pi0Vec , nPi0 , ideTrackID );
163  // ========== Kaons ===========
164  else if ( (PdgCode == 321 || PdgCode == -321) && part.Process() != "kaon+Inelastic" && part.Process() != "kaon-Inelastic" )
165  FillVars( KaonVec, nKaon, ideTrackID );
166  // ========== Elecs ===========
167  else if ( (PdgCode == -11 || PdgCode == 11) )
168  FillVars( ElecVec, nElec, ideTrackID );
169  // ========== If still not one of my intersting particles I need to find this particles parent ==========
170  else {
171  ideTrackID = part.Mother();
172  PdgCode = truthmap[ abs(ideTrackID) ]->PdgCode();
173  WrittenOut = false; // If not one of my particles change back to false.
174  } // If not one of chosen particles.
175  } // While loop
176  } // Each IDE ( ide:idevec )
177  } // IDE vector for SimChannel ( tdcide:simcahnnel.TPCIDEMap() )
178  } // Loop through simchannels
179  /*
180  std::cout << "Looking at Run " << Run << " SubRun " << SubRun << " Event " << Event
181  << ". There were " << nMuon << " muons, " << nPion << " pions, " << nPi0 << " pi0s, " << nKaon << " Kaons, " << nElec << " Electrons."
182  << std::endl;
183  */
184  // Fill Tree and decide whether to keep this event...
185  MyOutTree->Fill();
186  bool EventPasses = true;
187  if ( (fWantMuon && nMuon == 0) || nMuon > MaxPart) EventPasses = false;
188  if ( (fWantPion && nPion == 0) || nPi0 > MaxPart) EventPasses = false;
189  if ( (fWantPi0 && nPi0 == 0) || nPion > MaxPart) EventPasses = false;
190  if ( (fWantKaon && nKaon == 0) || nKaon > MaxPart) EventPasses = false;
191  if ( (fWantElec && nElec == 0) || nElec > MaxPart) EventPasses = false;
192  return EventPasses;
193  }
int PdgCode() const
Definition: MCParticle.h:212
EventNumber_t event() const
Definition: DataViewImpl.cc:85
std::map< int, const simb::MCParticle * > truthmap
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
int Mother() const
Definition: MCParticle.h:213
std::string Process() const
Definition: MCParticle.h:215
T abs(T value)
int PdgCode(Resonance_t res, int Q)
(resonance id, charge) -> PDG code
#define MaxPart
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
RunNumber_t run() const
Definition: DataViewImpl.cc:71
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
void FillVars(std::vector< int > &TrackIDVec, int &numParts, int ThisID)
LArSoft geometry interface.
Definition: ChannelGeo.h:16
Signal from collection planes.
Definition: geo_types.h:146
void filt::NucleonDecayFilter::reconfigure ( fhicl::ParameterSet const &  pset)

Definition at line 89 of file NucleonDecayFilter_module.cc.

89  {
90  fWantMuon = pset.get<bool>("WantMuon");
91  fWantPion = pset.get<bool>("WantPion");
92  fWantPi0 = pset.get<bool>("WantPi0" );
93  fWantKaon = pset.get<bool>("WantKaon");
94  fWantElec = pset.get<bool>("WantElec");
95  std::cout << "Your filter is selecting only events with: "
96  << "Muons " << fWantMuon << ", "
97  << "Pions " << fWantPion << ", "
98  << "Pi0s " << fWantPi0 << ", "
99  << "Kaons " << fWantKaon << ", "
100  << "Elecs " << fWantElec << "."
101  << std::endl;
102  }
QTextStream & endl(QTextStream &s)

Member Data Documentation

double filt::NucleonDecayFilter::ActiveBounds[6]
private

Definition at line 63 of file NucleonDecayFilter_module.cc.

int filt::NucleonDecayFilter::Event
private

Definition at line 80 of file NucleonDecayFilter_module.cc.

bool filt::NucleonDecayFilter::fWantElec
private

Definition at line 74 of file NucleonDecayFilter_module.cc.

bool filt::NucleonDecayFilter::fWantKaon
private

Definition at line 73 of file NucleonDecayFilter_module.cc.

bool filt::NucleonDecayFilter::fWantMuon
private

Definition at line 70 of file NucleonDecayFilter_module.cc.

bool filt::NucleonDecayFilter::fWantPi0
private

Definition at line 72 of file NucleonDecayFilter_module.cc.

bool filt::NucleonDecayFilter::fWantPion
private

Definition at line 71 of file NucleonDecayFilter_module.cc.

art::ServiceHandle<geo::Geometry> filt::NucleonDecayFilter::geom
private

Definition at line 67 of file NucleonDecayFilter_module.cc.

TTree* filt::NucleonDecayFilter::MyOutTree
private

Definition at line 77 of file NucleonDecayFilter_module.cc.

int filt::NucleonDecayFilter::nElec
private

Definition at line 81 of file NucleonDecayFilter_module.cc.

int filt::NucleonDecayFilter::nKaon
private

Definition at line 81 of file NucleonDecayFilter_module.cc.

int filt::NucleonDecayFilter::nMuon
private

Definition at line 81 of file NucleonDecayFilter_module.cc.

int filt::NucleonDecayFilter::nPi0
private

Definition at line 81 of file NucleonDecayFilter_module.cc.

int filt::NucleonDecayFilter::nPion
private

Definition at line 81 of file NucleonDecayFilter_module.cc.

int filt::NucleonDecayFilter::Run
private

Definition at line 78 of file NucleonDecayFilter_module.cc.

int filt::NucleonDecayFilter::SubRun
private

Definition at line 79 of file NucleonDecayFilter_module.cc.

std::map<int, const simb::MCParticle*> filt::NucleonDecayFilter::truthmap
private

Definition at line 64 of file NucleonDecayFilter_module.cc.


The documentation for this class was generated from the following file: