All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
trkf::SpacePointCheater Class Reference
Inheritance diagram for trkf::SpacePointCheater:

Public Member Functions

 SpacePointCheater (fhicl::ParameterSet const &pset)
 

Private Member Functions

void produce (art::Event &evt) override
 
void endJob () override
 

Private Attributes

SpacePointAlg fSptalg
 
std::string fClusterModuleLabel
 
unsigned int fMinHits
 
bool fClusterAssns
 
int fNumEvent
 
int fNumSpt2
 
int fNumSpt3
 

Detailed Description

Definition at line 36 of file SpacePointCheater_module.cc.

Constructor & Destructor Documentation

trkf::SpacePointCheater::SpacePointCheater ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 61 of file SpacePointCheater_module.cc.

67  : EDProducer{pset}
68  , fSptalg(pset.get<fhicl::ParameterSet>("SpacePointAlg"))
69  , fMinHits(0)
70  , fClusterAssns(false)
71  , fNumEvent(0)
72  , fNumSpt2(0)
73  , fNumSpt3(0)
74  {
75  fClusterModuleLabel = pset.get<std::string>("ClusterModuleLabel");
76  fMinHits = pset.get<unsigned int>("MinHits");
77  fClusterAssns = pset.get<bool>("ClusterAssns");
78 
79  produces<std::vector<art::PtrVector<recob::SpacePoint>>>();
80  produces<std::vector<recob::SpacePoint>>();
81  produces<art::Assns<recob::SpacePoint, recob::Hit>>();
82  if (fClusterAssns) produces<art::Assns<recob::SpacePoint, recob::Cluster>>();
83 
84  mf::LogInfo("SpacePointCheater")
85  << "SpacePointCheater configured with the following parameters:\n"
86  << " ClusterModuleLabel = " << fClusterModuleLabel << "\n"
87  << " Minimum Hits per Cluster = " << fMinHits << "\n"
88  << " Cluster associations = " << fClusterAssns;
89  }

Member Function Documentation

void trkf::SpacePointCheater::endJob ( )
overrideprivate

Definition at line 315 of file SpacePointCheater_module.cc.

319  {
320  mf::LogInfo("SpacePointCheater")
321  << "SpacePointCheater statistics:\n"
322  << " Number of events = " << fNumEvent << "\n"
323  << " Number of 2-view space points created = " << fNumSpt2 << "\n"
324  << " Number of 3-view space points created = " << fNumSpt3;
325  }
void trkf::SpacePointCheater::produce ( art::Event &  evt)
overrideprivate

Definition at line 93 of file SpacePointCheater_module.cc.

99  {
100  ++fNumEvent;
101 
102  // Get Services.
103 
104  art::ServiceHandle<geo::Geometry const> geom;
105 
106  // Get clusters.
107 
108  art::Handle<std::vector<recob::Cluster>> clusterh;
109  evt.getByLabel(fClusterModuleLabel, clusterh);
110 
111  // Make a double or triple loop over clusters in distinct views
112  // (depending on minimum number of views configured in SpacePointAlg).
113 
114  if (clusterh.isValid()) {
115 
116  // Make a collection of space points that will be inserted into the event.
117 
118  auto sptvecs = std::make_unique<std::vector<art::PtrVector<recob::SpacePoint>>>();
119  auto spts = std::make_unique<std::vector<recob::SpacePoint>>();
120  auto sphitassn = std::make_unique<art::Assns<recob::SpacePoint, recob::Hit>>();
121  auto spclassn = std::make_unique<art::Assns<recob::SpacePoint, recob::Cluster>>();
122 
123  // Make a hit vector which will be used to store hits to be passed
124  // to SpacePointAlg.
125 
126  art::PtrVector<recob::Hit> hits;
127  art::FindManyP<recob::Hit> fm(clusterh, evt, fClusterModuleLabel);
128 
129  // Loop over first cluster.
130 
131  auto const clockData =
132  art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
133  auto const detProp =
134  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clockData);
135 
136  int nclus = clusterh->size();
137  for (int iclus = 0; iclus < nclus; ++iclus) {
138  art::Ptr<recob::Cluster> piclus(clusterh, iclus);
139  geo::View_t iview = piclus->View();
140 
141  std::vector<art::Ptr<recob::Hit>> ihits = fm.at(iclus);
142 
143  // Test first view.
144 
145  if (ihits.size() >= fMinHits &&
146  ((iview == geo::kU && fSptalg.enableU()) || (iview == geo::kV && fSptalg.enableV()) ||
147  (iview == geo::kZ && fSptalg.enableW()))) {
148 
149  // Store hits from first view into hit vector.
150 
151  unsigned int nihits = ihits.size();
152  hits.clear();
153  hits.reserve(nihits);
154  for (std::vector<art::Ptr<recob::Hit>>::const_iterator i = ihits.begin();
155  i != ihits.end();
156  ++i)
157  hits.push_back(*i);
158 
159  // Loop over second cluster.
160 
161  for (int jclus = 0; jclus < iclus; ++jclus) {
162  art::Ptr<recob::Cluster> pjclus(clusterh, jclus);
163  geo::View_t jview = pjclus->View();
164 
165  std::vector<art::Ptr<recob::Hit>> jhits = fm.at(jclus);
166 
167  // Test second view.
168 
169  if (jhits.size() >= fMinHits &&
170  ((jview == geo::kU && fSptalg.enableU()) ||
171  (jview == geo::kV && fSptalg.enableV()) ||
172  (jview == geo::kZ && fSptalg.enableW())) &&
173  jview != iview) {
174 
175  // Store hits from second view into hit vector.
176 
177  unsigned int njhits = jhits.size();
178  assert(hits.size() >= nihits);
179  //hits.resize(nihits);
180  while (hits.size() > nihits)
181  hits.pop_back();
182  assert(hits.size() == nihits);
183  hits.reserve(nihits + njhits);
184  for (std::vector<art::Ptr<recob::Hit>>::const_iterator j = jhits.begin();
185  j != jhits.end();
186  ++j)
187  hits.push_back(*j);
188 
189  // If two-view space points are allowed, make them here.
190 
191  if (fSptalg.minViews() <= 2) {
192  std::vector<recob::SpacePoint> new_spts;
193  fSptalg.makeMCTruthSpacePoints(clockData, detProp, hits, new_spts);
194 
195  // If we found some space points, insert them into the event.
196 
197  if (new_spts.size() > 0) {
198  fNumSpt2 += new_spts.size();
199  art::PtrVector<recob::Cluster> clusters;
200  clusters.reserve(2);
201  clusters.push_back(piclus);
202  clusters.push_back(pjclus);
203 
204  // Insert newly found space points into event collection.
205 
206  int nspt = spts->size();
207  spts->insert(spts->end(), new_spts.begin(), new_spts.end());
208 
209  // Associate space points with hits and clusters.
210 
211  art::PtrVector<recob::SpacePoint> sptvec;
212  for (unsigned int ispt = nspt; ispt < spts->size(); ++ispt) {
213  const recob::SpacePoint& spt = (*spts)[ispt];
214  const art::PtrVector<recob::Hit>& hits = fSptalg.getAssociatedHits(spt);
215  util::CreateAssn(evt, *spts, hits, *sphitassn, ispt);
216  if (fClusterAssns) util::CreateAssn(evt, *spts, clusters, *spclassn, ispt);
217 
218  // make the PtrVector for this collection of space points
219  // Do not reproduce the following lines
220  // Contact brebel@fnal.gov if you think you need to reproduce these lines.
221  art::ProductID spid = evt.getProductID<std::vector<recob::SpacePoint>>();
222  art::Ptr<recob::SpacePoint> spptr(spid, ispt, evt.productGetter(spid));
223  sptvec.push_back(spptr);
224  }
225  sptvecs->push_back(sptvec);
226  }
227  }
228 
229  // Loop over third cluster.
230 
231  for (int kclus = 0; kclus < jclus; ++kclus) {
232  art::Ptr<recob::Cluster> pkclus(clusterh, kclus);
233  geo::View_t kview = pkclus->View();
234 
235  std::vector<art::Ptr<recob::Hit>> khits = fm.at(kclus);
236 
237  // Test third view.
238 
239  if (khits.size() >= fMinHits &&
240  ((kview == geo::kU && fSptalg.enableU()) ||
241  (kview == geo::kV && fSptalg.enableV()) ||
242  (kview == geo::kZ && fSptalg.enableW())) &&
243  kview != iview && kview != jview) {
244 
245  // Store hits from third view into hit vector.
246 
247  unsigned int nkhits = khits.size();
248  assert(hits.size() >= nihits + njhits);
249  //hits.resize(nihits + njhits);
250  while (hits.size() > nihits + njhits)
251  hits.pop_back();
252  assert(hits.size() == nihits + njhits);
253  hits.reserve(nihits + njhits + nkhits);
254  for (std::vector<art::Ptr<recob::Hit>>::const_iterator k = khits.begin();
255  k != khits.end();
256  ++k)
257  hits.push_back(*k);
258 
259  // Make three-view space points.
260 
261  std::vector<recob::SpacePoint> new_spts;
262  fSptalg.makeMCTruthSpacePoints(clockData, detProp, hits, new_spts);
263 
264  // If we found some space points, insert them into the event.
265 
266  if (new_spts.size() > 0) {
267  fNumSpt3 += new_spts.size();
268  art::PtrVector<recob::Cluster> clusters;
269  clusters.reserve(3);
270  clusters.push_back(piclus);
271  clusters.push_back(pjclus);
272  clusters.push_back(pkclus);
273 
274  // Insert newly found space points into event collection.
275 
276  int nspt = spts->size();
277  spts->insert(spts->end(), new_spts.begin(), new_spts.end());
278 
279  // Associate space points with hits and clusters.
280 
281  art::PtrVector<recob::SpacePoint> sptvec;
282  for (unsigned int ispt = nspt; ispt < spts->size(); ++ispt) {
283  const recob::SpacePoint& spt = (*spts)[ispt];
284  const art::PtrVector<recob::Hit>& hits = fSptalg.getAssociatedHits(spt);
285  util::CreateAssn(evt, *spts, hits, *sphitassn, ispt);
286  if (fClusterAssns) util::CreateAssn(evt, *spts, clusters, *spclassn, ispt);
287 
288  // make the PtrVector for this collection of space points
289  // Do not reproduce the following lines
290  // Contact brebel@fnal.gov if you think you need to reproduce these lines.
291  art::ProductID spid = evt.getProductID<std::vector<recob::SpacePoint>>();
292  art::Ptr<recob::SpacePoint> spptr(spid, ispt, evt.productGetter(spid));
293  sptvec.push_back(spptr);
294  }
295  sptvecs->push_back(sptvec);
296  }
297  }
298  }
299  }
300  }
301  }
302  }
303 
304  // Add space points and associations to event.
305 
306  evt.put(std::move(spts));
307  evt.put(std::move(sptvecs));
308  evt.put(std::move(sphitassn));
309  if (fClusterAssns) evt.put(std::move(spclassn));
310  }
311  }
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Planes which measure V.
Definition: geo_types.h:130
Planes which measure Z direction.
Definition: geo_types.h:132
bool enableV() const noexcept
const art::PtrVector< recob::Hit > & getAssociatedHits(const recob::SpacePoint &spt) const
void makeMCTruthSpacePoints(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const art::PtrVector< recob::Hit > &hits, std::vector< recob::SpacePoint > &spts) const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
Planes which measure U.
Definition: geo_types.h:129
bool enableU() const noexcept
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
bool enableW() const noexcept
TCEvent evt
Definition: DataStructs.cxx:8
pdgs k
Definition: selectors.fcl:22
int minViews() const noexcept
auto const detProp

Member Data Documentation

bool trkf::SpacePointCheater::fClusterAssns
private

Definition at line 49 of file SpacePointCheater_module.cc.

std::string trkf::SpacePointCheater::fClusterModuleLabel
private

Definition at line 47 of file SpacePointCheater_module.cc.

unsigned int trkf::SpacePointCheater::fMinHits
private

Definition at line 48 of file SpacePointCheater_module.cc.

int trkf::SpacePointCheater::fNumEvent
private

Definition at line 53 of file SpacePointCheater_module.cc.

int trkf::SpacePointCheater::fNumSpt2
private

Definition at line 54 of file SpacePointCheater_module.cc.

int trkf::SpacePointCheater::fNumSpt3
private

Definition at line 55 of file SpacePointCheater_module.cc.

SpacePointAlg trkf::SpacePointCheater::fSptalg
private

Definition at line 46 of file SpacePointCheater_module.cc.


The documentation for this class was generated from the following file: