RockPresel_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////
2 // \file RockPresel_module.cc
3 // \brief Preselection to filter rock muon events
4 // \author Andrew Sutton
5 ///////////////////////////////////////////////////////////////////////////
6 #include "TMath.h"
7 #include "TVector3.h"
8 
9 //Novasoft includes
10 #include "CosRej/CosRejFxs.h"
11 #include "Geometry/Geometry.h"
12 #include "Geometry/LiveGeometry.h"
13 #include "MCCheater/BackTracker.h"
14 #include "NovaDAQConventions/DAQConventions.h"
15 #include "RecoBase/Cluster.h"
16 #include "RecoBase/FilterList.h"
17 #include "RecoBase/Vertex.h"
18 #include "Preselection/PreselObj.h"
19 #include "Utilities/AssociationUtil.h"
22 // Framework includes
29 #include "fhiclcpp/ParameterSet.h"
31 
32 namespace presel
33 {
35  {
36  public:
37  explicit RockPresel(fhicl::ParameterSet const &pset);
38  virtual ~RockPresel();
39  void beginRun(art::Run& run);
40  virtual void produce(art::Event& evt);
41 
42  protected:
43 
46  bool fRunFilter;
47 
48  private:
49  bool isND = false;
50 
51  };
52 
53 }//End namespace presel
54 
55 namespace presel
56 {
57  //----------------------------------------------------------------------
59  fSlicerLabel (pset.get< std::string >("SlicerLabel")),
60  fVertexLabel (pset.get< std::string >("VertexLabel") ),
61  fRunFilter (pset.get< bool >("RunFilter"))
62  {
63  produces< rb::FilterList<rb::Cluster> >();
64  produces< std::vector<PreselObj> >();
65  produces< art::Assns<PreselObj, rb::Cluster> >();
66  }
67 
68  //----------------------------------------------------------------------
70  {
71  }
72 
73  //----------------------------------------------------------------------
75  {
77 
78  // Only apply the filter to ND events
79  if(geom->DetId() == novadaq::cnv::kNEARDET)
80  isND = true;
81  }
82 
83  //----------------------------------------------------------------------
85  {
86  std::unique_ptr< rb::FilterList<rb::Cluster> > filtcol(new rb::FilterList<rb::Cluster>);
87  std::unique_ptr< std::vector<presel::PreselObj> > preselcol(new std::vector<presel::PreselObj>);
88  std::unique_ptr< art::Assns<presel::PreselObj, rb::Cluster> > preselinfo(new art::Assns<presel::PreselObj, rb::Cluster>);
89 
90 
91  // Grab event's slices
93  evt.getByLabel(fSlicerLabel, slices);
94 
95  // Object holding tracks associated with slice
96  art::FindManyP<rb::Vertex> fmpVertex(slices, evt, fVertexLabel);
97 
98  // Loop over slices
99  for(uint sliceIdx = 0; sliceIdx < slices->size(); ++sliceIdx){
100  const rb::Cluster& slice = (*slices)[sliceIdx];
101 
102  if(slice.IsNoise()) continue;
103 
104  // initialize presel object and set the default selection to true
105  presel::PreselObj preselobj;
106  bool sel = true;
107 
108  // check filter conditions
109  // only check ND events
110  if(isND && fmpVertex.isValid()){
111  std::vector< art::Ptr<rb::Vertex> > vertexes = fmpVertex.at(sliceIdx);
112 
113  // assuming only one vertex
114  if(vertexes.size()) {
115  double vertX = vertexes[0]->GetX();
116  double vertY = vertexes[0]->GetY();
117  double vertZ = vertexes[0]->GetZ();
118 
119  sel = vertX < 179 && vertY < 179 && vertX > -179 && vertY > -179 && vertZ > 21;
120  }
121  }
122 
123  if(!isND && !sel) {
124  std::cout << "\n*******************************************************"
125  << "\n Not ND but sel is false, this shouldn't happen!!! "
126  << "\n*******************************************************"
127  << std::endl;
128  }
129 
130  if(!sel && fRunFilter)
131  filtcol->Add(slices, sliceIdx);
132 
133  preselobj.SetPassPresel(sel);
134  preselcol->push_back(preselobj);
135 
136  util::CreateAssn(*this, evt, *preselcol, art::Ptr<rb::Cluster>(slices,sliceIdx), *preselinfo);
137 
138  } // end of slice loop
139 
140  evt.put(std::move(filtcol));
141  evt.put(std::move(preselcol));
142  evt.put(std::move(preselinfo));
143 
144  }
145  //............................................................................................
146 }//end namespace presel
147 
148 namespace presel
149 {
151 }
Preselection Object.
Definition: FillPIDs.h:20
A simple list of products that have been marked "filtered out".
Definition: FilterList.h:74
back track the reconstruction to the simulation
static bool CreateAssn(art::EDProducer const &prod, art::Event &evt, std::vector< T > &a, art::Ptr< U > b, art::Assns< T, U > &assn, size_t indx=UINT_MAX, std::string const &instance=std::string())
Create a 1 to 1 association between a new product and one already in the event.
virtual void produce(art::Event &evt)
A collection of associated CellHits.
Definition: Cluster.h:47
DEFINE_ART_MODULE(TestTMapFile)
Definition: Run.h:31
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
void SetPassPresel(bool pass)
holds pass/fail output of presel
Definition: PreselObj.cxx:24
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
Near Detector in the NuMI cavern.
Vertex location in position and time.
Definition: run.py:1
OStream cout
Definition: OStream.cxx:6
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
void beginRun(art::Run &run)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
void geom(int which=0)
Definition: geom.C:163
bool IsNoise() const
Is the noise flag set?
Definition: Cluster.h:163
Object collecting Preselection variables.
Encapsulate the geometry of one entire detector (near, far, ndos)
RockPresel(fhicl::ParameterSet const &pset)
unsigned int uint