SlowMonopoleFilt_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: SlowMonopoleFilt
3 // Module Type: filter
4 // File: SlowMonopoleFilt_module.cc
5 //
6 // Generated at Mon Aug 11 16:08:14 2014 by Martin Frank using artmod
7 // from cetpkgsupport v1_06_02.
8 ////////////////////////////////////////////////////////////////////////
9 
17 #include "fhiclcpp/ParameterSet.h"
19 
22 
24 #include "DDTTools/DDTExtensions.h"
25 #include "DDTTools/DDTHelpers.h"
26 #include "RawData/RawDigit.h"
27 #include "RawData/RawTrigger.h"
28 #include "RecoBase/CellHit.h"
29 #include "RecoBase/Cluster.h"
30 
31 #include <boost/format.hpp>
32 
33 #include <memory>
34 #include <utility>
35 
36 
37 namespace mono {
39  typedef std::pair<uint32_t, uint32_t> TimeWindow;
40 }
41 
42 
44 public:
45  explicit SlowMonopoleFilt(fhicl::ParameterSet const & p);
46 
47  // Plugins should not be copied or assigned.
48  SlowMonopoleFilt(SlowMonopoleFilt const &) = delete;
50  SlowMonopoleFilt & operator = (SlowMonopoleFilt const &) = delete;
52  bool filter(art::Event & e) override;
53 
54 private:
56  (novaddt::TriggerDecision const& td,
57  unsigned buffer, novaddt::TDC event_time) const;
58 
59  void append_cluster
60  (std::map<std::string, rb::Cluster> const& input_clusters,
61  std::unique_ptr<std::vector<rb::Cluster> > & output_clusters,
62  std::string const cluster_name) const;
63 };
64 
65 
66 
68 {
69  produces<std::vector<rb::Cluster> >();
70  produces<std::vector<novaddt::TriggerDecision> >();
71 }
72 
73 
74 
76 {
77  //
78  // Extract Objects from the Event
79  //
80  // High ADC Filtered Hits
82  e.getByLabel("smmhighadcfilter", "HEHits", ddt_hits);
83 
84  // Raw Trigger Header
86  e.getByLabel("daq", raw_triggers);
87  assert(raw_triggers->size() == 1);
88 
89  // Offline Cell Hits
91  e.getByLabel("calhit", hits);
92  std::vector<art::Ptr<rb::CellHit> > hitptrs;
93  for (unsigned i = 0; i < hits->size(); ++i)
94  hitptrs.emplace_back(hits, i);
95 
96  int16_t adc_cut = 150;
97  unsigned long long
98  event_time(raw_triggers->at(0).fTriggerTimingMarker_TimeStart);
99 
100 
101 
102  //
103  // Run Offline Versions of Trigger
104  //
106  config.max_plane_gap_cut = 30;
107  config.sparsification_factor = 10;
108  SlowMonopoleTrigger smt(*ddt_hits, event_time, config);
109 
110  std::unique_ptr<std::vector<novaddt::TriggerDecision> >
111  trigger_decisions
112  (new std::vector<novaddt::TriggerDecision>(smt.trigger_decisions()));
113 
114  std::cout << "MF: Trigger Decision Report"
115  << "\nMF: Run " << e.run() << " Event " << e.event()
116  << "\nMF: Trigger Decisions Size = " << trigger_decisions->size()
117  << std::endl;
118 
119 
120 
121  //
122  // Extract Clusters from Triggers
123  //
124  unsigned time_buffer = smt.trigger_decision_time_buffer();
125 
126  std::unique_ptr<std::vector<rb::Cluster> >
127  clusters(new std::vector<rb::Cluster>);
128 
129  if (trigger_decisions->size() > 0)
130  {
131  TimeWindow time_window =
132  calculate_time_window(trigger_decisions->at(0), time_buffer, event_time);
134  (hitptrs, time_window.first, time_window.second, adc_cut);
135  // clusters->push_back(mf_cluster);
136  }
137 
138  std::map<std::string, rb::Cluster> essential_clusters;
139  for (auto const& essential_hit_list : smt.essential_hit_lists())
140  {
141  for (auto const& essential_hit : essential_hit_list.second)
142  {
143  // use a subset of hits:
144  // art::PtrVector<rb::CellHit> cluster_hits = mf_cluster.AllCells();
145  // use all of the hits:
146  std::vector<art::Ptr<rb::CellHit> > cluster_hits = hitptrs;
147 
148  auto matched_offline_hit = std::find_if
149  (cluster_hits.begin(), cluster_hits.end(),
150  [&](art::Ptr<rb::CellHit> const& cell_hit)
151  {
152  return ddthelpers::is_equal(essential_hit, cell_hit, event_time);
153  });
154 
155  if (matched_offline_hit != cluster_hits.end())
156  {
157  essential_clusters[essential_hit_list.first].
158  Add(*matched_offline_hit);
159  }
160  else {
161  std::cerr << "MF: No matching hit found for:" << std::endl;
162  ddthelpers::print(essential_hit, event_time);
163  // assert(false);
164  }
165  }
166  }
167 
168  // Color Order:
169  // defined in RecoBaseDrawer::GetClusterColor
170  // https://cdcvs.fnal.gov/redmine/projects/novaart/repository/entry/trunk/EventDisplay/RecoBaseDrawer.cxx#L1130
171  // 1. blue
172  // 2. green
173  // 3. red
174  // 4. yellow
175 
176  append_cluster(essential_clusters, clusters, "some_label");
177 
178  e.put(std::move(trigger_decisions));
179  e.put(std::move(clusters));
180 
181  return true;
182 }
183 
184 
185 
188  unsigned buffer, novaddt::TDC event_time) const
189 {
190  auto t_start = td.start() + 2 * buffer - event_time;
191  auto t_end = td.start() + td.duration() - 2 * buffer - event_time;
192 
193  return std::make_pair(t_start, t_end);
194 }
195 
196 
197 
199 (std::map<std::string, rb::Cluster> const& input_clusters,
200  std::unique_ptr<std::vector<rb::Cluster> > & output_clusters,
201  std::string const cluster_name) const
202 {
203  auto cluster = input_clusters.find(cluster_name);
204 
205  if (cluster != input_clusters.end())
206  {
207  if (cluster->second.NCell() > 0)
208  output_clusters->push_back(cluster->second);
209  }
210 }
211 
212 
213 
void append_cluster(std::map< std::string, rb::Cluster > const &input_clusters, std::unique_ptr< std::vector< rb::Cluster > > &output_clusters, std::string const cluster_name) const
std::vector< novaddt::TriggerDecision > trigger_decisions() const
rb::Cluster cluster_hits(std::vector< art::Ptr< rb::CellHit > > const &hits, int32_t t_start, int32_t t_end, int16_t adc_cut=0)
Definition: DDTHelpers.cxx:13
Definition: Cluster.h:13
const char * p
Definition: xmltok.h:285
A collection of associated CellHits.
Definition: Cluster.h:47
OStream cerr
Definition: OStream.cxx:7
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
DEFINE_ART_MODULE(TestTMapFile)
::xsd::cxx::tree::buffer< char > buffer
Definition: Database.h:179
bool filter(art::Event &e) override
std::map< std::string, novaddt::HitList > essential_hit_lists() const
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
void hits()
Definition: readHits.C:15
void print(novaddt::DAQHit const &h, unsigned long long const &event_time=0)
Definition: DDTHelpers.cxx:84
unsigned trigger_decision_time_buffer() const
SlowMonopoleFilt(fhicl::ParameterSet const &p)
EventNumber_t event() const
Definition: Event.h:67
std::pair< uint32_t, uint32_t > TimeWindow
OStream cout
Definition: OStream.cxx:6
TimeWindow calculate_time_window(novaddt::TriggerDecision const &td, unsigned buffer, novaddt::TDC event_time) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
assert(nhit_max >=nhit_nbins)
SlowMonopoleFilt & operator=(SlowMonopoleFilt const &)=delete
Float_t e
Definition: plot.C:35
RunNumber_t run() const
Definition: Event.h:77
TDC::value_type duration() const
TDC::value_type start() const
bool is_equal(novaddt::DAQHit const &ddthit, art::Ptr< rb::CellHit > const &cellhit, novaddt::TDC const &event_time)
Definition: DDTHelpers.cxx:30
enum BeamMode string