ProtoDUNEFembFilter_module.cc
Go to the documentation of this file.
1 // A module to filter out events with inactive FEMBs
2 // owen.goodwin@postgrad.manchester.ac.uk
3 
4 #include <iostream>
5 #include <utility>
6 #include <set>
7 
8 #include "TH1.h"
9 #include "TFile.h"
10 
15 #include "art_root_io/TFileService.h"
16 
19 
20 
21 
22 
23 namespace filt{
24 
26  public:
27  explicit ProtoDUNEFembFilter(fhicl::ParameterSet const & pset);
28  virtual ~ProtoDUNEFembFilter() {};
29  virtual bool filter(art::Event& e);
30  void beginJob();
31 
32  private:
34 
35  unsigned int fLogLevel;
38 
40  TH1D* fTotalEvents;
41 
42  };
43 
44  ProtoDUNEFembFilter::ProtoDUNEFembFilter::ProtoDUNEFembFilter(fhicl::ParameterSet const & pset):
45  EDFilter(pset), fDataUtils(pset.get<fhicl::ParameterSet>("DataUtils"))
46  {
47 
48  fLogLevel = pset.get<unsigned int>("LogLevel");
49  fRequireBeamsideFembsOnly = pset.get<bool>("RequireBeamsideFembsOnly");
50  fRequireBeamsideTimestampConsistencyOnly = pset.get<bool>("RequireBeamsideTimestampConsistencyOnly");
51  if ( fLogLevel >= 1 ) {
52  std::cout << " LogLevel: " << fLogLevel << std::endl;
53  if(fRequireBeamsideFembsOnly){
54  std::cout << "Filtering events with inactive FEMBs on beamside APAs"<< std::endl;
55  }
56  else{
57  std::cout << "Filtering events with any inactive FEMBs"<< std::endl;
58  }
59  if(fRequireBeamsideTimestampConsistencyOnly){
60  std::cout << "Filtering events with inconsistent timestmaps on beamside APAs"<< std::endl;
61  }
62  else{
63  std::cout << "Filtering events with any inconsistent timestamps"<< std::endl;
64  }
65  }
66 
67  }
68 
70 
72  fSelectedEvents = tfs->make<TH1D>("fSelectedEvents", "Number of Selected Events", 3, 0, 3); //counts the number of selected events
73  fTotalEvents = tfs->make<TH1D>("fTotalEvents", "Total Events", 3, 0, 3); //counts the initial number of events in the unfiltered root input file
74 
75  }
76 
78 
79 
80  fTotalEvents->Fill(1); //count total events
81 
82 
83  if(!evt.isRealData()){
84  fSelectedEvents->Fill(1);
85  return true; //Filter is designed for Data only. Don't want to filter on MC
86  }
87 
88 
89 
90 
91  std::vector<int> BeamsideAPAs;
92  std::vector<int> AllAPAs;
93  std::vector<int> checkedAPAs;
94  std::vector<int> TScheckedAPAs;
95 
96  // Add some elements to myIntVector
97  BeamsideAPAs.push_back(0);
98  BeamsideAPAs.push_back(2);
99  BeamsideAPAs.push_back(4);
100 
101  AllAPAs.push_back(0);
102  AllAPAs.push_back(1);
103  AllAPAs.push_back(2);
104  AllAPAs.push_back(3);
105  AllAPAs.push_back(4);
106  AllAPAs.push_back(5);
107 
108  const std::string myname = "ProtoDUNEFembFilter::filter: ";
109 
111  checkedAPAs=BeamsideAPAs;
112  }
113  else{
114  checkedAPAs=AllAPAs;
115  }
117  TScheckedAPAs=BeamsideAPAs;
118  }
119  else{
120  TScheckedAPAs=AllAPAs;
121  }
122 
123  // make a set out of these for faster lookup by the timestamp checker
124 
125  std::set<int> checkedAPAset;
126  for (size_t i=0; i < checkedAPAs.size(); ++i)
127  {
128  checkedAPAset.emplace(TScheckedAPAs.at(i));
129  }
130 
131  bool keep = true;
132  // Helper utility functions
133 
134  fTotalEvents->Fill(1); //count total events
135  for (auto APA = checkedAPAs.begin(); APA != checkedAPAs.end(); ++APA){ //loop through beam side APAs
136  //std::cout<<"APA:"<<*APA<<std::endl;
137  //std::cout<<fDataUtils.GetNActiveFembsForAPA(evt, *APA)<<std::endl;
138  if (fDataUtils.GetNActiveFembsForAPA(evt, *APA)!=20){ //check if APA has all 20 fembs active
139 
140  if (fLogLevel >=2) std::cout<<"Missing FEMBs on APA: "<<*APA<<std::endl;
141  keep=false; //if not remove event
142  }
143  }
144 
145  // check timestamp consistency
146 
147  ULong64_t timestamp=0;
148  ULong64_t timestamp2=0;
149  int apainconsist=0;
150  if (!fDataUtils.CheckTimeStampConsistencyForAPAs(evt, checkedAPAset, timestamp, timestamp2, apainconsist ))
151  {
152  keep = false;
153  if (fLogLevel >=2) std::cout<<"ProtoDUNEFembFilter Timestamp mismatch: " << timestamp << " vs " << timestamp2 << " on TPC set " << apainconsist << std::endl;
154  }
155 
156  if ( fLogLevel >=2 ) std::cout << myname << (keep ? "Keep" : "Reject") << "ing event." << std::endl;
157  if (keep==true) fSelectedEvents->Fill(1); //count total events
158 
159  return keep;
160 
161  }
162 
164 
165 }
protoana::ProtoDUNEDataUtils fDataUtils
std::string string
Definition: nybbler.cc:12
virtual bool filter(art::Event &e)
ProtoDUNEFembFilter(fhicl::ParameterSet const &pset)
bool isRealData() const
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
T get(std::string const &key) const
Definition: ParameterSet.h:271
int GetNActiveFembsForAPA(art::Event const &evt, int apa) const
Get number of active fembs in an APA.
bool CheckTimeStampConsistencyForAPAs(art::Event const &evt, std::set< int > apas, ULong64_t &timestamp, ULong64_t &timestamp2, int &apainconsist) const
Check for consistency of timestamp values for a set of APAs. True if consistent, false if there are m...
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.h:21
TCEvent evt
Definition: DataStructs.cxx:7
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
QTextStream & endl(QTextStream &s)