CosmicCVNVeto_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////
2 // \file CosmicCVNVeto_module.cc
3 // \brief Preselection to filter cosmic events for reconstruction/PID
4 // for everything
5 // \author Gavin Davies, Kirk Bays
6 ///////////////////////////////////////////////////////////////////////////
7 #include "TMath.h"
8 #include "TVector3.h"
9 
10 //Novasoft includes
11 #include "CosRej/CosRejFxs.h"
12 #include "Geometry/Geometry.h"
13 #include "Geometry/LiveGeometry.h"
14 #include "MCCheater/BackTracker.h"
15 #include "NovaDAQConventions/DAQConventions.h"
16 #include "RecoBase/Cluster.h"
17 #include "RecoBase/FilterList.h"
18 #include "RecoBase/Track.h"
19 #include "Preselection/Veto.h"
20 #include "Utilities/AssociationUtil.h"
24 // Framework includes
31 #include "fhiclcpp/ParameterSet.h"
33 
34 namespace presel
35 {
37  {
38  public:
39  explicit CosmicCVNVeto(fhicl::ParameterSet const &pset);
40  virtual ~CosmicCVNVeto();
41  void beginRun(art::Run& run);
42  virtual void produce(art::Event& evt);
43 
44  protected:
45 
48  bool fRunFilter;
49 
53  bool isFD = false;
54  unsigned int fNCellHigh;
55 
57  private:
58 
59 
60  };
61 
62 }//End namespace presel
63 
64 namespace presel
65 {
66  //----------------------------------------------------------------------
68  fSlicerLabel (pset.get< std::string >("SlicerLabel")),
69  fCosmicCVNLabel (pset.get< std::string >("CosmicCVNLabel") ),
70  fRunFilter (pset.get< bool >("RunFilter")),
71  fDoNCellHighCut (0),
72  fDoCosmicCVNCut (0),
73  fKeepNuMIInTime (0),
74  fNCellHigh (0),
75  fPSetNDOS (pset.get<fhicl::ParameterSet>("ndos")),
76  fPSetND (pset.get<fhicl::ParameterSet>("nd")),
77  fPSetFD (pset.get<fhicl::ParameterSet>("fd")),
78  fPSetTB (pset.get<fhicl::ParameterSet>("tb"))
79 
80  {
81  produces< rb::FilterList<rb::Cluster> >();
82  }
83 
84  //----------------------------------------------------------------------
86  {
87  }
88 
89  //----------------------------------------------------------------------
91  {
93 
95 
96  switch(geom->DetId()){
98  pset = fPSetNDOS;
99  break;
101  pset = fPSetND;
102  break;
104  pset = fPSetFD;
105  isFD = true;
106  break;
108  pset = fPSetTB;
109  break;
110  default:
111  assert(0 && "Unknown detector");
112  }
113  fDoNCellHighCut = pset.get< bool >("DoNCellHighCut");
114  fDoCosmicCVNCut = pset.get< bool >("DoCosmicCVNCut");
115  fKeepNuMIInTime = pset.get< bool >("KeepNuMIInTime");
116  fNCellHigh = pset.get< unsigned int >("NCellHigh");
117  if(fKeepNuMIInTime)
118  std::cout<<"Not applying cuts to events in time with NuMI\n";
119  }
120 
121  //----------------------------------------------------------------------
123  {
124  std::unique_ptr< rb::FilterList<rb::Cluster> > filtcol(new rb::FilterList<rb::Cluster>);
125 
126  if (!isFD){
127  evt.put(std::move(filtcol));
128  return;
129  }
130 
131 
132  //Grab event's slices
134  evt.getByLabel(fSlicerLabel, slices);
135 
136  //Grab the cosmic CVN filter objects
138  evt.getByLabel(fCosmicCVNLabel, cosmiccvn);
139  std::vector<cvntf::CVNCosmicFiltList> cosmicList = *cosmiccvn;
140 
141 
142  const int sliceMax = slices->size();
143 
144  for(int sliceIdx = 0; sliceIdx < sliceMax; ++sliceIdx){
145  art::Ptr<rb::Cluster> slicePtr(slices,sliceIdx); // Used to write association
146 
147  const rb::Cluster& slice = (*slices)[sliceIdx];
148 
149  if(slice.IsNoise()) continue;
150 
151 
152  const double nCells = slice.NCell(); //Number of cells in slice
153  // Selected unless we fail any cuts below
154  bool sel = true;
155 
156  if(fDoNCellHighCut){
157  if(nCells > fNCellHigh) sel = false;
158  }
159  if( fDoCosmicCVNCut ){
160  double cVal = 999.0;
161  bool keep = false;
162  for (unsigned int iC = 0; iC < cosmicList[0].ListSize(); ++iC){
163  cvntf::CVNCosmicFilt cvn = cosmicList[0].GetTimeSlice(iC);
164  if ((slice.MeanTNS() > cvn.timeWinMin) &&
165  (slice.MeanTNS() < cvn.timeWinMax)){
166  if (cvn.cosmicVal < cVal){
167  cVal = cvn.cosmicVal;
168  keep = cvn.passSel;
169  }
170  }
171  }
172  if (!keep) sel = false;
173  }
174 
175  if( util::IsInBeamWindow(evt.run(), slice.MeanTNS()) ){
176 
177  if(fKeepNuMIInTime){
178  // if this slice is in the numi beam window,
179  // keep it.
180  sel = true;
181  }
182  }
183 
184  if(!sel && fRunFilter)
185  filtcol->Add(slices, sliceIdx);
186 
187  } // end for sliceIdx
188 
189  evt.put(std::move(filtcol));
190 
191  }
192  //............................................................................................
193 }//end namespace presel
194 
195 namespace presel
196 {
198 }
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
unsigned int NCell(geo::View_t view) const
Number of cells in view view.
Definition: Cluster.cxx:134
static bool IsInBeamWindow(const int run, const double time)
float cosmicVal
Cosmic CVN cosmic score for each time slice.
A collection of associated CellHits.
Definition: Cluster.h:47
DEFINE_ART_MODULE(TestTMapFile)
Defines an enumeration for prong classification.
Definition: Run.h:31
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
Far Detector at Ash River, MN.
Prototype Near Detector on the surface at FNAL.
T get(std::string const &key) const
Definition: ParameterSet.h:231
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
Near Detector in the NuMI cavern.
virtual void produce(art::Event &evt)
fhicl::ParameterSet fPSetFD
CosmicCVNVeto(fhicl::ParameterSet const &pset)
fhicl::ParameterSet fPSetNDOS
Definition: run.py:1
OStream cout
Definition: OStream.cxx:6
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
fhicl::ParameterSet fPSetND
Result for collection of time slices evaluated by CVN for cosmic rejectionN.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
double MeanTNS(rb::AveragingScheme scheme=kDefaultScheme) const
Definition: Cluster.cxx:554
void geom(int which=0)
Definition: geom.C:163
assert(nhit_max >=nhit_nbins)
bool IsNoise() const
Is the noise flag set?
Definition: Cluster.h:163
RunNumber_t run() const
Definition: Event.h:77
fhicl::ParameterSet fPSetTB
Encapsulate the geometry of one entire detector (near, far, ndos)
void beginRun(art::Run &run)