MonopoleCluster_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: MonopoleCluster
3 // Module Type: filter
4 // File: MonopoleCluster_module.cc
5 //
6 // Generated at Mon Jun 22 10:35:45 2015 by Martin Frank using artmod
7 // from cetpkgsupport v1_08_05.
8 ////////////////////////////////////////////////////////////////////////
9 
16 // #include <canvas/Utilities/Exception.h>
17 // #include <canvas/Utilities/InputTag.h>
18 #include <art/Utilities/Exception.h>
19 #include <art/Utilities/InputTag.h>
20 #include <fhiclcpp/ParameterSet.h>
22 
23 #include "MCCheater/BackTracker.h"
24 #include "Monopole/Constants.h"
25 #include "RawData/RawTrigger.h"
26 #include "RecoBase/CellHit.h"
27 #include "RecoBase/Cluster.h"
28 #include "RecoBase/Track.h"
29 
30 #include <chrono>
31 #include <memory>
32 
33 using namespace std::chrono;
34 
35 namespace mono
36 {
37  class MonopoleCluster;
38 }
39 
41 public:
42  explicit MonopoleCluster(fhicl::ParameterSet const & p);
43 
44  MonopoleCluster(MonopoleCluster const &) = delete;
45  MonopoleCluster(MonopoleCluster &&) = delete;
46  MonopoleCluster & operator = (MonopoleCluster const &) = delete;
47  MonopoleCluster & operator = (MonopoleCluster &&) = delete;
48 
49  bool filter(art::Event & e) override;
50 
51 private:
52  rb::Cluster find_isolated_hits(rb::Cluster const& cluster) const;
53  bool hit_is_isolated
54  (std::map<int, std::vector<int> > & hit_table, rb::CellHit const& hit) const;
55  bool is_cosmic_track(rb::Track const& t) const;
56 
57 
66 };
67 
68 
69 
71  cosmic_max_dEdx_ (p.get<double> ("cosmic_max_dEdx")),
72  cosmic_min_length_ (p.get<double> ("cosmic_min_length")),
73  hits_adc_cut_ (p.get<unsigned> ("hits_adc_cut")),
74  hits_label_ (p.get<std::string>("hits_label")),
75  isolation_cell_cut_ (p.get<int> ("isolation_cell_cut")),
76  isolation_plane_cut_(p.get<int> ("isolation_plane_cut")),
77  track_label_ (p.get<std::string>("track_label")),
78  use_cosmic_cuts_ (p.get<bool> ("use_cosmic_cuts"))
79 {
80  produces<std::vector<rb::CellHit> >();
81  produces<std::vector<rb::Cluster> >();
82 }
83 
84 
85 
87 {
88  std::unique_ptr<std::vector<rb::Cluster> >
89  clusters(new std::vector<rb::Cluster>);
90  std::unique_ptr<std::vector<rb::CellHit> >
91  cellhits(new std::vector<rb::CellHit>);
92 
93  //
94  // Extract Objects from the Event
95  //
97  const bool is_mc = bt->HaveTruthInfo();
98 
99  // Tracks
101  e.getByLabel(track_label_, tracks);
102 
103  // Offline Cell Hits
105  e.getByLabel(hits_label_, hits);
106  std::vector<art::Ptr<rb::CellHit> > hitptrs;
107  for (unsigned i = 0; i < hits->size(); ++i)
108  hitptrs.emplace_back(hits, i);
109 
110  // Remove Low ADC Hits
111  auto hitptrs_new_end = std::remove_if
112  (hitptrs.begin(), hitptrs.end(),
113  [&](art::Ptr<rb::CellHit> hit) { return hit->ADC() < hits_adc_cut_; });
114  hitptrs.erase(hitptrs_new_end, hitptrs.end());
115 
116 
117 
118  //
119  // Create Clusters
120  //
121  rb::Cluster all_hits;
122  for (auto const& hit : hitptrs)
123  all_hits.Add(hit);
124 
125  rb::Cluster track_hits;
126  for (auto const& track : *tracks)
127  if (is_cosmic_track(track))
128  for (auto const& track_hit : track.AllCells())
129  if (track_hit->ADC() > hits_adc_cut_)
130  track_hits.Add(track_hit);
131 
132  auto track_removed_hits = all_hits.Exclude(&track_hits);
133 
134  auto isolated_hits = find_isolated_hits(track_removed_hits);
135  auto mono_hits = track_removed_hits.Exclude(&isolated_hits);
136 
137 
138 
139  //
140  // Add Clusters to the Event
141  //
142  if (mono_hits.NCell() > 0)
143  clusters->push_back(mono_hits);
144 
145  for (auto const& cluster : *clusters)
146  for (auto const& hit : cluster.AllCells())
147  cellhits->push_back(*hit);
148 
149  e.put(std::move(clusters));
150  e.put(std::move(cellhits));
151 
152  if (mono_hits.NCell() > 0)
153  return true;
154 
155  return false;
156 }
157 
158 
159 
161 {
162  if (!use_cosmic_cuts_)
163  return true;
164 
166  return false;
167 
168  double dEdx = t.TotalGeV() / t.TotalLength();
169  if (dEdx > cosmic_max_dEdx_)
170  return false;
171 
172  return true;
173 }
174 
175 
176 
178 (rb::Cluster const& cluster) const
179 {
180  rb::Cluster isolated_hits;
181 
182  std::vector<art::PtrVector<rb::CellHit> > views =
183  { cluster.XCells(), cluster.YCells() };
184  for (auto const& view : views)
185  {
186  std::map<int, std::vector<int> > hit_table;
187  for (auto const& hit : view)
188  hit_table[hit->Plane()].push_back(hit->Cell());
189 
190  for (auto const& hit : view)
191  if (hit_is_isolated(hit_table, *hit))
192  isolated_hits.Add(hit);
193  }
194 
195  return isolated_hits;
196 }
197 
198 
199 
201 (std::map<int, std::vector<int> > & hit_table, rb::CellHit const& hit) const
202 {
203  int p_start = int(hit.Plane()) - isolation_plane_cut_;
204  int p_end = int(hit.Plane()) + isolation_plane_cut_;
205 
206  int c_start = int(hit.Cell()) - isolation_cell_cut_;
207  int c_end = int(hit.Cell()) + isolation_cell_cut_;
208 
209  for (int plane = p_start; plane <= p_end; ++plane)
210  for (auto const& cell : hit_table[plane])
211  if (cell >= c_start &&
212  cell <= c_end &&
213  !(cell == hit.Cell() && plane == hit.Plane()))
214  return false;
215 
216  return true;
217 }
218 
219 
220 
back track the reconstruction to the simulation
const art::PtrVector< rb::CellHit > & XCells() const
Get all cells from the x-view.
Definition: Cluster.h:124
Definition: Cluster.h:13
bool is_cosmic_track(rb::Track const &t) const
MonopoleCluster(fhicl::ParameterSet const &p)
unsigned short Plane() const
Definition: CellHit.h:39
const char * p
Definition: xmltok.h:285
Definition: event.h:19
A collection of associated CellHits.
Definition: Cluster.h:47
A rb::Prong with full reconstructed trajectory.
Definition: Track.h:20
rb::Cluster Exclude(const rb::Cluster *excl) const
Create a cluster from this one, but with the hits of excl removed.
Definition: Cluster.cxx:233
DEFINE_ART_MODULE(TestTMapFile)
rb::Cluster find_isolated_hits(rb::Cluster const &cluster) const
bool filter(art::Event &e) override
Module that kips a configurable number of events between each that it allows through. Note that this module really skips (N-1) events, it uses a simple modular division as its critera. This module will cut down the data sample to 1/N of its original size.
virtual void Add(const art::Ptr< rb::CellHit > &cell, double weight=1)
Definition: Cluster.cxx:84
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
virtual double TotalLength() const
Length (cm) of all the track segments.
Definition: Track.cxx:213
unsigned short Cell() const
Definition: CellHit.h:40
void hits()
Definition: readHits.C:15
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
const art::PtrVector< rb::CellHit > & YCells() const
Get all cells from the x-view.
Definition: Cluster.h:126
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
A rawdata::RawDigit with channel information decoded.
Definition: CellHit.h:27
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
bool hit_is_isolated(std::map< int, std::vector< int > > &hit_table, rb::CellHit const &hit) const
Definition: event.h:1
bool HaveTruthInfo() const
Is this a file with truth info in? (Is BackTracker going to be any use to you?)
Definition: BackTracker.h:133
double TotalGeV(EEnergyCalcScheme escheme=kRecomputeEnergy) const
Simple sum of the estimated GeV of all the hits.
Definition: Cluster.cxx:378
Float_t e
Definition: plot.C:35