GapFilter_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: GapFilter //
3 // Module Type: Analyzer //
4 // File: GapFilter_module.cc //
5 // Author: Tristan Blackburn - t.blackburn@sussex.ac.uk //
6 // Description: Module takes RawDigit input, produces hits, and uses //
7 // hit information to filter gap crossing events. //
8 ////////////////////////////////////////////////////////////////////////
9 #ifndef GapFilter_Module
10 #define GapFilter_Module
11 
12 // Framework includes
16 #include "fhiclcpp/ParameterSet.h"
21 #include "art_root_io/TFileService.h"
22 #include "art_root_io/TFileDirectory.h"
25 
26 // LArSoft includes
37 
38 // ROOT includes
39 #include "TTree.h"
40 #include "TTimeStamp.h"
41 #include "TLorentzVector.h"
42 #include "TVector3.h"
43 #include "TH1.h"
44 #include "TH2.h"
45 #include "TH3.h"
46 
47 // C++ Includes
48 #include <map>
49 #include <vector>
50 #include <algorithm>
51 #include <iostream>
52 #include <string>
53 #include <cmath>
54 
55 
56 const int kMaxHits = 10000; //maximum number of hits
57 
58 namespace MyGapFilter {
59 
60  class GapFilter : public art::EDAnalyzer {
61  public:
62  explicit GapFilter(fhicl::ParameterSet const & p);
63  virtual ~GapFilter();
64 
65  void beginJob();
66 
67  void reconfigure(fhicl::ParameterSet const& pset);
68 
69  void analyze (const art::Event& evt);
70 
72 
73  private:
74 
75  void ResetVars();
76 
77  TTree* fTree;
78 
79  //run information
80  int run;
81  int subrun;
82  int event;
83  double evttime;
84  double efield[3];
85  int t0;
86 
87  //Comparison
88  int nhits;
96  double hit_ph[kMaxHits];
97 
98  //Basic crossings
99  std::vector<int> gap1;
100  std::vector<int> gap2;
101  std::vector<int> gap3;
102  std::vector<int> gap4;
103  std::vector<int> gap5;
104 
105  //Horizontal crossings
106  std::vector<int> cross12;
107  std::vector<int> cross34;
108 
109  //Diagonal crossings
110  std::vector<int> cross14;
111  std::vector<int> cross23;
112 
113  //Inclusive crossings
114  std::vector<int> cross1and2or4;
115  std::vector<int> cross2and1or3;
116  std::vector<int> cross1or3and2or4;
117 
118  //Bools for deciding on gap crossers
119  bool TPC1 = false;
120  bool TPC7 = false;
121 
122  bool TPC5GAP1 = false;
123  bool GAP1 = false;
124 
125  bool TPC5GAP2 = false;
126  bool GAP2 = false;
127 
128  bool TPC3GAP3 = false;
129  bool GAP3 = false;
130 
131  bool TPC3GAP4 = false;
132  bool GAP4 = false;
133 
134  bool TPC3 = false;
135  bool TPC5 = false;
136  bool GAP5 = false;
137 
138  //FCL labels
141 
142  };
143 
144 
146  : EDAnalyzer(pset)
147  {
148  // Read in the parameters from the .fcl file.
149  this->reconfigure(pset);
150  }
151 
153  {
154  // Read parameters from the .fcl file. The names in the arguments
155  // to p.get<TYPE> must match names in the .fcl file.
156 
157  fHitsModuleLabel = p.get< std::string >("HitsModuleLabel");
158  fSimulationProducerLabel = p.get< std::string >("SimulationProducerLabel");
159  return;
160  }
161 
163  {
164  // Clean up dynamic memory and other resources here.
165  }
166 
168  {
169  // Implementation of required member function here.
170  ResetVars();
171 
173 
174  run = evt.run();
175  subrun = evt.subRun();
176  event = evt.id().event();
177 
178  //Reset vectors per event
179  gap1.clear();
180  gap2.clear();
181  gap3.clear();
182  gap4.clear();
183  gap5.clear();
184  cross12.clear();
185  cross34.clear();
186  cross14.clear();
187  cross23.clear();
188  cross1and2or4.clear();
189  cross2and1or3.clear();
190  cross1or3and2or4.clear();
191 
192  //Art handles
193 
195  evt.getByLabel(fSimulationProducerLabel, particleHandle);
197  evt.getByLabel(fSimulationProducerLabel, simChannelHandle);
198  std::map< int, const simb::MCParticle* > particleMap;
199 
200  // Get hit list
201  art::Handle< std::vector<recob::Hit> > hitListHandle;
202  std::vector<art::Ptr<recob::Hit> > hitlist;
203  if (evt.getByLabel(fHitsModuleLabel,hitListHandle))
204  art::fill_ptr_vector(hitlist, hitListHandle);
205  nhits = hitlist.size();
206 
207  //loop to determine hits and assign bool metrics for deciding on crossers
208  for (size_t k = 0; k < hitlist.size(); ++k){
209  unsigned int channel = hitlist[k]->Channel();
210  geo::WireID wireid = hitlist[k]->WireID();
211  hit_cryostat[k] = wireid.Cryostat;
212  hit_tpc[k] = wireid.TPC;
213  hit_plane[k] = wireid.Plane;
214  hit_wire[k] = wireid.Wire;
215  hit_channel[k] = channel;
216  hit_peakT[k] = hitlist[k]->PeakTime();
217  hit_charge[k] = hitlist[k]->Integral();
218  hit_ph[k] = hitlist[k]->PeakAmplitude();
219 
220  if (hit_channel[k] == 511 && hit_charge[k] != 0) TPC1 = true;
221  if (hit_channel[k] == 1424 && hit_charge[k] != 0) TPC5GAP1 = true;
222  if (hit_channel[k] == 1535 && hit_charge[k] != 0) TPC5GAP2 = true;
223  if (hit_channel[k] == 912 && hit_charge[k] != 0) TPC3GAP3 = true;
224  if (hit_channel[k] == 1023 && hit_charge[k] != 0) TPC3GAP4 = true;
225  if (hit_channel[k] == 1936 && hit_charge[k] != 0) TPC7 = true;
226  if (hit_channel[k] >= 912 && hit_channel[k] <= 1023 && hit_charge[k] != 0) TPC3 = true;
227  if (hit_channel[k] >= 1424 && hit_channel[k] <= 1535 && hit_charge[k] != 0) TPC5 = true;
228  }
229 
230  //Use bools to decide whether an event crosses a gap
231 
232  if (TPC1 == true && TPC5GAP1 == true) {
233  GAP1 = true;
234  gap1.push_back(event);
235  }
236  else GAP1 = false;
237 
238  if (TPC5GAP2 == true && TPC7 == true) {
239  GAP2 = true;
240  gap2.push_back(event);
241  }
242  else GAP2 = false;
243 
244  if (TPC1 == true && TPC3GAP3 == true) {
245  GAP3 = true;
246  gap3.push_back(event);
247  }
248  else GAP3 = false;
249 
250  if (TPC3GAP4 == true && TPC7 == true) {
251  GAP4 = true;
252  gap4.push_back(event);
253  }
254  else GAP4 = false;
255 
256  if (TPC3 == true && TPC5 == true) {
257  GAP5 = true;
258  gap5.push_back(event);
259  }
260  else GAP5 = false;
261 
262  //Use gap crossers to determine multiple gap crossing events
263  if (GAP1 == true && GAP2 == true) cross12.push_back(event);
264  if (GAP3 == true && GAP4 == true) cross34.push_back(event);
265  if (GAP1 == true && GAP4 == true) cross14.push_back(event);
266  if (GAP2 == true && GAP3 == true) cross23.push_back(event);
267  if (GAP1 == true && (GAP2 == true || GAP4 == true)) cross1and2or4.push_back(event);
268  if (GAP2 == true && (GAP1 == true || GAP3 == true)) cross2and1or3.push_back(event);
269  if ((GAP1 == true || GAP3 == true) && (GAP2 == true || GAP4 == true)) cross1or3and2or4.push_back(event);
270 
271  //Reset bools for next event
272 
273  TPC1 = false;
274  TPC7 = false;
275  TPC5GAP1 = false;
276  GAP1 = false;
277  TPC5GAP2 = false;
278  GAP2 = false;
279  TPC3GAP3 = false;
280  GAP3 = false;
281  TPC3GAP4 = false;
282  GAP4 = false;
283  TPC3 = false;
284  TPC5 = false;
285  GAP5 = false;
286 
287  fTree->Fill();
288  }
289 
291  {
292  // Implementation of optional member function here.
294 
295  fTree = tfs->make<TTree>("hitdumper","analysis tree");
296  fTree->Branch("run",&run,"run/I");
297  fTree->Branch("subrun",&subrun,"subrun/I");
298  fTree->Branch("event",&event,"event/I");
299  fTree->Branch("evttime",&evttime,"evttime/D");
300  fTree->Branch("efield",efield,"efield[3]/D");
301  fTree->Branch("t0",&t0,"t0/I");
302 
303  fTree->Branch("nhits",&nhits,"nhits/I");
304  fTree->Branch("hit_cryostat",hit_cryostat,"hit_cryostat[nhits]/I");
305  fTree->Branch("hit_tpc",hit_tpc,"hit_tpc[nhits]/I");
306  fTree->Branch("hit_plane",hit_plane,"hit_plane[nhits]/I");
307  fTree->Branch("hit_wire",hit_wire,"hit_wire[nhits]/I");
308  fTree->Branch("hit_channel",hit_channel,"hit_channel[nhits]/I");
309  fTree->Branch("hit_peakT",hit_peakT,"hit_peakT[nhits]/D");
310  fTree->Branch("hit_charge",hit_charge,"hit_charge[nhits]/D");
311  fTree->Branch("hit_ph",hit_ph,"hit_ph[nhits]/D");
312 
313  fTree->Branch("gap1", &gap1);
314  fTree->Branch("gap2", &gap2);
315  fTree->Branch("gap3", &gap3);
316  fTree->Branch("gap4", &gap4);
317  fTree->Branch("gap5", &gap5);
318 
319  fTree->Branch("cross12", &cross12);
320  fTree->Branch("cross34", &cross34);
321 
322  fTree->Branch("cross14", &cross14);
323  fTree->Branch("cross23", &cross23);
324 
325  fTree->Branch("cross1and2or4", &cross1and2or4);
326  fTree->Branch("cross2and1or3", &cross2and1or3);
327  fTree->Branch("cross1or3and2or4", &cross1or3and2or4);
328  }
329 
331 
332  run = -99999;
333  subrun = -99999;
334  event = -99999;
335  evttime = -99999;
336  for (int i = 0; i<3; ++i){
337  efield[i] = -99999;
338  }
339  t0 = -99999;
340  nhits = -99999;
341  for (int i = 0; i<kMaxHits; ++i){
342  hit_cryostat[i] = -99999;
343  hit_tpc[i] = -99999;
344  hit_plane[i] = -99999;
345  hit_wire[i] = -99999;
346  hit_channel[i] = -99999;
347  hit_peakT[i] = -99999;
348  hit_charge[i] = -99999;
349  hit_ph[i] = -99999;
350  }
351  }
353 } // namespace GapFilter
354 
355 #endif // GapFilter_Module
code to link reconstructed objects back to the MC truth information
std::vector< int > cross34
Trajectory class.
std::vector< int > cross2and1or3
double hit_peakT[kMaxHits]
std::string string
Definition: nybbler.cc:12
double hit_charge[kMaxHits]
Declaration of signal hit object.
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:212
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:580
std::vector< int > cross1and2or4
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:27
Particle class.
std::vector< int > cross14
void analyze(const art::Event &evt)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:446
std::vector< int > gap5
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:69
std::vector< int > gap4
std::vector< int > cross1or3and2or4
T get(std::string const &key) const
Definition: ParameterSet.h:231
double hit_ph[kMaxHits]
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:89
GapFilter(fhicl::ParameterSet const &p)
RunNumber_t run() const
Definition: DataViewImpl.cc:82
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
std::vector< int > gap3
Encapsulate the geometry of a wire.
p
Definition: test.py:223
std::vector< int > gap1
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
object containing MC truth information necessary for making RawDigits and doing back tracking ...
EventNumber_t event() const
Definition: EventID.h:116
void reconfigure(fhicl::ParameterSet const &pset)
TCEvent evt
Definition: DataStructs.cxx:7
std::string fSimulationProducerLabel
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:291
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406
EventID id() const
Definition: Event.cc:37
Event finding and building.
std::vector< int > gap2
std::vector< int > cross23
std::vector< int > cross12
const int kMaxHits