CounterFilter_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: CounterFilter
3 // Module Type: filter
4 // File: CounterFilter_module.cc
5 //
6 // Generated at Tue Aug 16 08:12:35 2016 by Matthew Thiesse using artmod
7 // from cetpkgsupport v1_10_02.
8 ////////////////////////////////////////////////////////////////////////
9 
16 #include "fhiclcpp/ParameterSet.h"
20 #include "canvas/Persistency/Common/FindManyP.h"
21 #include <memory>
22 #include <vector>
23 
24 namespace dune {
25  class CounterFilter;
26 }
27 
29 public:
30  explicit CounterFilter(fhicl::ParameterSet const & p);
31  // The destructor generated by the compiler is fine for classes
32  // without bare pointers or other resource use.
33 
34  // Plugins should not be copied or assigned.
35  CounterFilter(CounterFilter const &) = delete;
36  CounterFilter(CounterFilter &&) = delete;
37  CounterFilter & operator = (CounterFilter const &) = delete;
39 
40  // Required functions.
41  bool filter(art::Event & e) override;
42 
43  // Selected optional functions.
44  void reconfigure(fhicl::ParameterSet const & p) ;
45 
46 private:
47 
48  bool OppositeEW(std::vector<unsigned int> c);
49 
51 
52 };
53 
54 
56 {
57  this->reconfigure(p);
58 }
59 
61 {
62  bool valid = false;
63 
64  auto t0Handle = e.getHandle< std::vector< anab::T0> >(fT0ModuleLabel);
65  if (t0Handle)
66  {
67 
68  art::FindManyP<raw::ExternalTrigger> triggers(t0Handle,e,fT0ModuleLabel);
69 
70  for (size_t i_t0 = 0; i_t0 < t0Handle->size(); i_t0++)
71  {
72  art::Ptr<anab::T0> pt0(t0Handle,i_t0);
73  std::vector< art::Ptr<raw::ExternalTrigger> > trigvec = triggers.at(i_t0);
74  if (trigvec.size() != 3) continue;
75 
76  int contains_111 = 0, contains_112 = 0, contains_113 = 0;
77  int contains_Ntrigs = 0, contains_NU = 0, contains_NL = 0, contains_SU = 0, contains_SL = 0;
78  int contains_EL = 0, contains_WU = 0, contains_TEL = 0;
79  for (auto const &trig : trigvec)
80  {
81  unsigned int trigID = trig->GetTrigID();
82  // for c2: unsigned int trigID is always >= 0
83  //if (trigID >= 0 && trigID <= 5) contains_SL++;
84  if (trigID <= 5) contains_SL++;
85  if (trigID >= 6 && trigID <= 15) contains_EL++;
86  if (trigID >= 16 && trigID <= 21) contains_NL++;
87  if (trigID >= 22 && trigID <= 27) contains_NU++;
88  if (trigID >= 28 && trigID <= 37) contains_WU++;
89  if (trigID >= 38 && trigID <= 43) contains_SU++;
90  if (trigID >= 44 && trigID <= 92) contains_TEL++;
91  if (trigID == 111) contains_111++;
92  if (trigID == 112) contains_112++;
93  if (trigID == 113) contains_113++;
94  contains_Ntrigs++;
95  } // end loop over trigvec
96  if (contains_111 + contains_112 + contains_113 != 1) continue; // too many/few coincidences!
97  if (contains_TEL &&
98  (contains_NU || contains_NL || contains_SU || contains_SL || contains_EL || contains_WU)) continue; // track probably doesn't go through detector
99  if (contains_Ntrigs != 3) continue; // too much/little going on!
100  if (contains_111 && (contains_NU || contains_NL || contains_SU || contains_SL)) continue; // 111 should not have NU/NL/SU/SL
101  if (contains_112 && (contains_EL || contains_WU || contains_SU || contains_NL)) continue; // 112 should not have EL/WU/SU/NL
102  if (contains_113 && (contains_EL || contains_WU || contains_NU || contains_SL)) continue; // 113 should not have EL/WU/NU/SL
103  if (contains_111 && (!contains_EL || !contains_WU)) continue; // incomplete trigger
104  if (contains_112 && (!contains_NU || !contains_SL)) continue; // incomplete trigger
105  if (contains_113 && (!contains_SU || !contains_NL)) continue; // incomplete trigger
106 
107  std::vector<unsigned int> counterIDs;
108  unsigned int trignum = 0;
109  for (auto const &trig : trigvec)
110  {
111  unsigned int trigID = trig->GetTrigID();
112  if (trigID >= 44 && trigID <= 100) continue;
113  if (trigID >= 111 && trigID <= 113)
114  {
115  trignum = trigID;
116  continue;
117  }
118  counterIDs.push_back(trigID);
119  }
120  if (counterIDs.size() != 2) continue;
121  if (trignum == 0) continue;
122 
123  if (trignum == 111 && OppositeEW(counterIDs))
124  {
125  std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
126  std::cout << "Event # " << e.event() << std::endl;
127  std::cout << " counter IDs " << counterIDs[0] << " and " << counterIDs[1] << std::endl;
128  std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
129  valid = true;
130 
131  }
132  }
133  }
134  return valid;
135 }
136 
137 bool dune::CounterFilter::OppositeEW(std::vector<unsigned int> c)
138 {
139  if (c.size() != 2) return false;
140  unsigned int c1 = c[0];
141  unsigned int c2 = c[1];
142  if (c1==c2) return false;
143  if (c1%22 == c2 || c2%22 == c1) return true;
144  return false;
145 }
146 
148 {
149  fT0ModuleLabel = p.get<std::string>("T0ModuleLabel");
150 }
151 
EventNumber_t event() const
Definition: DataViewImpl.cc:85
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
bool filter(art::Event &e) override
bool OppositeEW(std::vector< unsigned int > c)
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
T get(std::string const &key) const
Definition: ParameterSet.h:271
p
Definition: test.py:223
CounterFilter(fhicl::ParameterSet const &p)
void reconfigure(fhicl::ParameterSet const &p)
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.h:21
CounterFilter & operator=(CounterFilter const &)=delete
Definition: fwd.h:31
QTextStream & endl(QTextStream &s)