NuESelect_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: NuESelect
3 // Module Type: filter
4 // \file: NuESelect_module.cc
5 // \brief Select Clusters of activity, trigger on EM like Clusters
6 // \version $Id: NuESelect_module.cc,v 1.2 2012-11-19 20:41:15 janzirn Exp $
7 // \author $Author: janzirn $
8 // \date $Date: 2012-11-19 20:41:15 $
9 //
10 // Generated at Thu Oct 18 17:27:18 2012 by Jan Zirnstein using artmod
11 // from art v1_01_01.
12 ////////////////////////////////////////////////////////////////////////
13 
19 
25 
26 #include <algorithm>
27 #include <cmath>
28 #include <vector>
29 
30 namespace novaddt {
31  class NuESelect;
32 }
33 
35 public:
36  explicit NuESelect(fhicl::ParameterSet const & p);
37  virtual ~NuESelect();
38 
39  virtual bool filter(art::Event & e);
40 
41  virtual void beginJob();
42  virtual void endJob();
43 
44 private:
45 
46  // Declare member data here.
49  double _linelike;
50  bool _trigflag;
51  unsigned int _prescale;
52  unsigned int _tcounts;
53 };
54 
55 
57 :
58 // Initialize member data here.
59 _clustlabel (p.get< std::string >("cluster_label")),
60 _instan (p.get< std::string >("instance")),
61 _linelike (p.get< double >("LinFitVal")),
62 _trigflag (false),
63 _prescale (p.get<unsigned int>("presale",1)),
64 _tcounts (0)
65 {
66  // Call appropriate Produces<>() functions here.
67  produces< std::vector<TriggerDecision>>();
68 }
69 
71 {
72  // Clean up dynamic memory and other resources here.
73 }
74 
76 {
77  // Implementation of optional member function here.
78 }
79 
81 {
82  // Define product to be put in the event
83  std::unique_ptr<std::vector<novaddt::TriggerDecision>> td(new std::vector<novaddt::TriggerDecision>);
84 
85  // Grab the clusters from the event
87  e.getByLabel(_clustlabel, clusters);
88 
89  if(clusters->empty()){
90  mf::LogWarning ("No Clusters")<<"No Clusters in the input file";
91  e.put(std::move(td));
92  return false;
93  }
94 
95  // Grab the hitlists associated with the clusters
97 
98  // Time to go through the clusters, C++11 style!
99  unsigned int i(0);
100  for(auto const& clust: *clusters) {
101  art::Ptr<novaddt::HitList> hl_ptr(hls.at(i));
102  ++i;
103 
104  // Split the hits in x and y to do 2D fitting
105  novaddt::HitList hlist(*hl_ptr);
106  auto bound = std::partition(hlist.begin(),hlist.end(),CompareDAQHit<View>());
107 
108  unsigned int xsize = bound-hlist.begin();
109  unsigned int ysize = hlist.end()-bound;
110 
111  // Smarter way of vector managment
112  std::vector<double> XXpoints;
113  std::vector<double> XZpoints;
114  std::vector<double> YYpoints;
115  std::vector<double> YZpoints;
116 
117  XXpoints.reserve(xsize);
118  XZpoints.reserve(xsize);
119  YYpoints.reserve(ysize);
120  YZpoints.reserve(ysize);
121 
122  {
123  auto it = hlist.begin();
124  for(it=hlist.begin();it!=bound;++it){
125  XXpoints.emplace_back((*it).Cell().val);
126  XZpoints.emplace_back((*it).Plane().val);
127  }
128  for(it=bound;it!=hlist.end();++it){
129  YYpoints.emplace_back((*it).Cell().val);
130  YZpoints.emplace_back((*it).Plane().val);
131  }
132  }
133 
134  // Now we can do the actual fitting
135  double xslope;
136  double xint;
137  unsigned int xdof = xsize-1;
138  double xsigm=0.0;
139  double pred;
140 
141  // First the X fit
142  if(xsize > 1){
143  util::LinFitUnweighted(XXpoints, XZpoints, xslope, xint);
144 
145  // Evaluate the goodness of fit
146  for(unsigned int xi=0;xi<xsize;++xi){
147  pred = xslope*XXpoints[xi] + xint;
148  xsigm += sqrt(util::sqr(XZpoints[xi]-pred));
149  }
150  }
151  else xdof = 1;
152 
153  // Now the Y fit
154  double yslope;
155  double yint;
156  unsigned int ydof = ysize-1;
157  double ysigm=0.0;
158 
159  if(ysize > 1){
160  util::LinFitUnweighted(YYpoints, YZpoints, yslope, yint);
161 
162  // Evaluate the goodness of fit
163  for(unsigned int yi=0;yi<ysize;++yi){
164  pred = yslope*YYpoints[yi] + yint;
165  ysigm += sqrt(util::sqr(YZpoints[yi]-pred));
166  }
167  }
168  else ydof = 1;
169 
170  // Let's see if it passes trigger criterion
171  double ThreeDFit = sqrt(util::sqr(xsigm/xdof)+util::sqr(ysigm/ydof));
172  if(_linelike < ThreeDFit) {
173  ++_tcounts;
174  if (_tcounts%_prescale == 0) {
175  td->emplace_back(clust.EarliestTDC().val,
176  clust.LatestTDC().val - clust.EarliestTDC().val,
178  _prescale);
179  }
180  }
181  } // end of clusters
182 
183  _trigflag = (td->size() > 0);
184  e.put(std::move(td));
185  return _trigflag;
186 } // end filter
187 
188 
190 {
191  // Implementation of optional member function here.
192 }
193 
set< int >::iterator it
std::vector< DAQHit > HitList
Definition: HitList.h:15
const char * p
Definition: xmltok.h:285
T sqrt(T number)
Definition: d0nt_math.hpp:156
DEFINE_ART_MODULE(TestTMapFile)
T sqr(T x)
More efficient square function than pow(x,2)
Definition: MathUtil.h:23
NuESelect(fhicl::ParameterSet const &p)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
unsigned int _prescale
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
void LinFitUnweighted(const std::vector< double > &x, const std::vector< double > &y, double &m, double &c)
Simplified version of LinFit.
Definition: MathUtil.cxx:8
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
virtual bool filter(art::Event &e)
Float_t e
Definition: plot.C:35
virtual void endJob()
Definition: fwd.h:28
virtual void beginJob()