LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
SimpleLineCluster_module.cc
Go to the documentation of this file.
1 // Class: SimpleLineCluster
3 // Plugin Type: producer (art v2_11_02)
4 // File: SimpleLineCluster_module.cc
5 //
6 // Generated at Fri Jun 22 19:50:13 2018 by Tingjun Yang using cetskelgen
7 // from cetlib version v3_03_01.
9 
17 #include "fhiclcpp/ParameterSet.h"
19 
20 
21 //LArSoft includes
29 #include <memory>
30 
31 namespace cluster {
32  class SimpleLineCluster;
33 }
34 
35 
37 public:
38  explicit SimpleLineCluster(fhicl::ParameterSet const & p);
39  // The compiler-generated destructor is fine for non-base
40  // classes without bare pointers or other resource use.
41 
42  // Plugins should not be copied or assigned.
43  SimpleLineCluster(SimpleLineCluster const &) = delete;
47 
48  // Required functions.
49  void produce(art::Event & e) override;
50 
51 private:
52 
53  std::unique_ptr<ClusterCrawlerAlg> fCCAlg; // define ClusterCrawlerAlg object
54 
57 
58 };
59 
60 
62  : fHitFinderLabel(p.get<art::InputTag>("HitFinderModuleLabel"))
63  , fPFParticleLabel(p.get<art::InputTag>("PFParticleModuleLabel"))
64 {
65  // this trick avoids double configuration on construction
66  if (fCCAlg)
67  fCCAlg->reconfigure(p.get< fhicl::ParameterSet >("ClusterCrawlerAlg"));
68  else {
69  fCCAlg.reset(new ClusterCrawlerAlg
70  (p.get< fhicl::ParameterSet >("ClusterCrawlerAlg")));
71  }
72 
74  produces< std::vector<recob::Cluster> >();
75  produces< art::Assns<recob::Cluster, recob::Hit> >();
76 }
77 
79 {
80  //Retrieve data products
81  auto hitsHandle = evt.getValidHandle< std::vector<recob::Hit> >(fHitFinderLabel);
82  auto clusHandle = evt.getValidHandle< std::vector<recob::Cluster> >(fPFParticleLabel);
83  auto pfpsHandle = evt.getValidHandle< std::vector<recob::PFParticle> >(fPFParticleLabel);
84 
85  // all hits in the collection
86  std::vector< art::Ptr<recob::Hit> > hits;
87  art::fill_ptr_vector(hits, hitsHandle);
88 
89  // all pfps in the collection
90  std::vector< art::Ptr<recob::PFParticle> > pfps;
91  art::fill_ptr_vector(pfps, pfpsHandle);
92 
93  art::FindManyP < recob::Cluster > cluFromPfp(pfpsHandle, evt, fPFParticleLabel);
94  art::FindManyP < recob::Hit > hitFromClu(clusHandle, evt, fPFParticleLabel);
95 
96  // also get the associated wires and raw digits;
97  // we assume they have been created by the same module as the hits
98  art::FindOneP<raw::RawDigit> channelHitRawDigits(hitsHandle, evt, fHitFinderLabel);
99  art::FindOneP<recob::Wire> channelHitWires (hitsHandle, evt, fHitFinderLabel);
100 
101  std::vector<recob::Hit> allHits;
102  std::vector<ClusterCrawlerAlg::ClusterStore> allClusters;
103  std::vector<unsigned int> clusterhitindex;
104 
105  for (size_t i = 0; i < pfps.size(); ++i){
106  std::vector<recob::Hit> pfphits;
107  auto& clus_in_pfp = cluFromPfp.at(i);
108  for (auto& clu : clus_in_pfp){
109  auto& hits_in_clu = hitFromClu.at(clu.key());
110  for (auto& hit : hits_in_clu) pfphits.push_back(*hit);
111  }
112  fCCAlg->RunCrawler(pfphits);
113 
114  //copy hits
115  size_t nhits = allHits.size();
116  for (auto & hit : fCCAlg->GetHits()){
117  allHits.push_back(hit);
118  }
119 
120  auto & Clusters = fCCAlg->GetClusters();
121  for(auto &clstr : Clusters){
122  allClusters.push_back(clstr);
123  clusterhitindex.push_back(nhits);
124  }
125 
126  fCCAlg->ClearResults();
127  }
128 
129 
130  std::vector<recob::Cluster> sccol;
131 
132  std::unique_ptr<art::Assns<recob::Cluster, recob::Hit> >
134 
135  // make the clusters and associations
136  float sumChg, sumADC;
137  unsigned int clsID = 0, nclhits;
138  for(unsigned int icl = 0; icl < allClusters.size(); ++icl) {
139  ClusterCrawlerAlg::ClusterStore const& clstr = allClusters[icl];
140  if(clstr.ID < 0) continue;
141  ++clsID;
142  sumChg = 0;
143  sumADC = 0;
145  //unsigned short plane = planeID.Plane;
146  nclhits = clstr.tclhits.size();
147  std::vector<unsigned int> clsHitIndices;
148  // correct the hit indices to refer to the valid hits that were just added
149  for(unsigned int itt = 0; itt < nclhits; ++itt) {
150  unsigned int iht = clstr.tclhits[itt];
151  recob::Hit const& hit = allHits[iht];
152  sumChg += hit.Integral();
153  sumADC += hit.SummedADC();
154  } // itt
155  // get the wire, plane from a hit
156  unsigned int iht = clstr.tclhits[0];
157 
158  geo::View_t view = allHits[iht].View();
159  sccol.emplace_back(
160  (float)clstr.BeginWir, // Start wire
161  0, // sigma start wire
162  clstr.BeginTim, // start tick
163  0, // sigma start tick
164  clstr.BeginChg, // start charge
165  clstr.BeginAng, // start angle
166  0, // start opening angle (0 for line-like clusters)
167  (float)clstr.EndWir, // end wire
168  0, // sigma end wire
169  clstr.EndTim, // end tick
170  0, // sigma end tick
171  clstr.EndChg, // end charge
172  clstr.EndAng, // end angle
173  0, // end opening angle (0 for line-like clusters)
174  sumChg, // integral
175  0, // sigma integral
176  sumADC, // summed ADC
177  0, // sigma summed ADC
178  nclhits, // n hits
179  0, // wires over hits
180  0, // width (0 for line-like clusters)
181  clsID, // ID
182  view, // view
183  planeID, // plane
184  recob::Cluster::Sentry // sentry
185  );
186  // make the cluster - hit association
187  std::vector<size_t> indices;
188  for (auto & ih : clstr.tclhits){
189  indices.push_back(ih+clusterhitindex[icl]);
190  }
191  if(!util::CreateAssn(
192  *this, evt, sccol, allHits, *hc_assn, indices)
193  )
194  {
196  <<"Failed to associate hit "<<iht<<" with cluster "<<icl;
197  } // exception
198  }
199 
200  // convert cluster vector to unique_ptrs
201  std::unique_ptr<std::vector<recob::Cluster> > ccol(new std::vector<recob::Cluster>(std::move(sccol)));
202 
203  std::unique_ptr<std::vector<recob::Hit>> FinalHits
204  (new std::vector<recob::Hit>(std::move(allHits)));
205 
206  recob::HitRefinerAssociator shcol(*this, evt, fHitFinderLabel,
207  channelHitWires.isValid(),
208  channelHitRawDigits.isValid());
209 
210  shcol.use_hits(std::move(FinalHits));
211 
212  // move the hit collection and the associations into the event:
213  shcol.put_into(evt);
214  evt.put(std::move(ccol));
215  evt.put(std::move(hc_assn));
216 
217 
218 }
219 
art::InputTag fPFParticleLabel
label of module producing input pfparticles
SimpleLineCluster(fhicl::ParameterSet const &p)
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Declaration of signal hit object.
The data type to uniquely identify a Plane.
Definition: geo_types.h:250
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:225
Cluster finding and building.
static void declare_products(ModuleType &producer, std::string instance_name="", bool doWireAssns=true, bool doRawDigitAssns=true)
Declares the hit products we are going to fill.
Definition: HitCreator.h:1117
static const SentryArgument_t Sentry
An instance of the sentry object.
Definition: Cluster.h:182
static geo::PlaneID DecodeCTP(CTP_t CTP)
std::unique_ptr< ClusterCrawlerAlg > fCCAlg
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
Helper functions to create a hit.
void hits()
Definition: readHits.C:15
void use_hits(std::unique_ptr< std::vector< recob::Hit >> &&srchits)
Uses the specified collection as data product.
Definition: HitCreator.cxx:431
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
SimpleLineCluster & operator=(SimpleLineCluster const &)=delete
T get(std::string const &key) const
Definition: ParameterSet.h:231
constexpr std::array< std::size_t, geo::vect::dimension< Vector >)> indices()
Returns a sequence of indices valid for a vector of the specified type.
A class handling a collection of hits and its associations.
Definition: HitCreator.h:865
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
Declaration of cluster object.
Detector simulation of raw signals on wires.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Utility object to perform functions of association.
art::InputTag fHitFinderLabel
label of module producing input hits
float SummedADC() const
The sum of calibrated ADC counts of the hit (0. by default)
Definition: Hit.h:224
HLT enums.
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:49
TCEvent evt
Definition: DataStructs.cxx:5
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
Float_t e
Definition: plot.C:34
void produce(art::Event &e) override