LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
fuzzyCluster_module.cc
Go to the documentation of this file.
1 
7 #include <vector>
8 #include <cmath>
9 #include <iostream>
10 #include <fstream>
11 #include <cstdlib>
12 #include "TGeoManager.h"
13 #include "TH1.h"
14 
15 //Framework includes:
19 #include "fhiclcpp/ParameterSet.h"
27 #include "CLHEP/Random/JamesRandom.h"
28 
29 // art extensions
31 
32 // LArSoft includes
33 #include "lardataobj/RawData/raw.h"
36 #include "larevt/CalibrationDBI/Interface/ChannelStatusService.h"
37 #include "larevt/CalibrationDBI/Interface/ChannelStatusProvider.h"
48 
49 
50 class TH1F;
51 
52 namespace cluster{
53 
54  //---------------------------------------------------------------
56  {
57  public:
58  explicit fuzzyCluster(fhicl::ParameterSet const& pset);
59  ~fuzzyCluster();
60  void produce(art::Event& evt);
61  void beginJob();
62  void reconfigure(fhicl::ParameterSet const& p);
63 
64  private:
65 
66  TH1F *fhitwidth;
69 
70  std::string fhitsModuleLabel;
71  unsigned int fHoughSeed;
72 
74  };
75 
76 }
77 
78 namespace cluster{
79 
80 
81  //-------------------------------------------------
83  ffuzzyCluster(pset.get< fhicl::ParameterSet >("fuzzyClusterAlg"))
84  {
85  this->reconfigure(pset);
86  produces< std::vector<recob::Cluster> >();
87  produces< art::Assns<recob::Cluster, recob::Hit> >();
88 
89  // create a default random engine; obtain the random seed from NuRandomService,
90  // unless overridden in configuration with key "Seed"
92  ->createEngine(*this, pset, "Seed");
93 
94  }
95 
96  //-------------------------------------------------
98  {
99  }
100 
101  //-------------------------------------------------
103  {
104  fhitsModuleLabel = p.get< std::string >("HitsModuleLabel");
105  fHoughSeed = p.get< unsigned int >("HoughSeed");
106  ffuzzyCluster.reconfigure(p.get< fhicl::ParameterSet >("fuzzyClusterAlg"));
107  }
108 
109  //-------------------------------------------------
111  // get access to the TFile service
113 
114  fhitwidth= tfs->make<TH1F>(" fhitwidth","width of hits in cm", 50000,0 ,5 );
115  fhitwidth_ind_test= tfs->make<TH1F>("fhitwidth_ind_test","width of hits in cm", 50000,0 ,5 );
116  fhitwidth_coll_test= tfs->make<TH1F>("fhitwidth_coll_test","width of hits in cm", 50000,0 ,5 );
117 
118  }
119 
120  //-----------------------------------------------------------------
122  {
123 
124  //get a collection of clusters
125  std::unique_ptr<std::vector<recob::Cluster> > ccol(new std::vector<recob::Cluster>);
126  std::unique_ptr< art::Assns<recob::Cluster, recob::Hit> > assn(new art::Assns<recob::Cluster, recob::Hit>);
127 
129 
131  evt.getByLabel(fhitsModuleLabel,hitcol);
132 
133  // loop over all hits in the event and look for clusters (for each plane)
134  std::vector<art::Ptr<recob::Hit> > allhits;
135 
136  // If a nonzero random number seed has been provided,
137  // overwrite the seed already initialized
138  if(fHoughSeed != 0){
140  CLHEP::HepRandomEngine &engine = rng->getEngine();
141  engine.setSeed(fHoughSeed,0);
142  }
143 
144  // get the ChannelFilter
145  // get channel quality service:
146  lariov::ChannelStatusProvider const& channelStatus
148 
149  lariov::ChannelStatusProvider::ChannelSet_t const BadChannels
150  = channelStatus.BadChannels();
151 
152  // prepare the algorithm to compute the cluster characteristics;
153  // we use the "standard" one here; configuration would happen here,
154  // but we are using the default configuration for that algorithm
156 
157  // make a map of the geo::PlaneID to vectors of art::Ptr<recob::Hit>
158  std::map<geo::PlaneID, std::vector< art::Ptr<recob::Hit> > > planeIDToHits;
159  for(size_t i = 0; i < hitcol->size(); ++i)
160  planeIDToHits[hitcol->at(i).WireID().planeID()].push_back(art::Ptr<recob::Hit>(hitcol, i));
161 
162 
163  for(auto & itr : planeIDToHits){
164 
165  geo::SigType_t sigType = geom->SignalType(itr.first);
166  allhits.resize(itr.second.size());
167  allhits.swap(itr.second);
168 
169  //Begin clustering with fuzzy
170 
171  ffuzzyCluster.InitFuzzy(allhits, BadChannels);
172 
173  //----------------------------------------------------------------
174  for(unsigned int j = 0; j < ffuzzyCluster.fps.size(); ++j){
175 
176  if(allhits.size() != ffuzzyCluster.fps.size()) break;
177 
178  fhitwidth->Fill(ffuzzyCluster.fps[j][2]);
179 
180  if(sigType == geo::kInduction) fhitwidth_ind_test->Fill(ffuzzyCluster.fps[j][2]);
181  if(sigType == geo::kCollection) fhitwidth_coll_test->Fill(ffuzzyCluster.fps[j][2]);
182  }
183 
184  //*******************************************************************
186 
187  //End clustering with fuzzy
188 
189 
190  for(size_t i = 0; i < ffuzzyCluster.fclusters.size(); ++i){
191  std::vector<art::Ptr<recob::Hit> > clusterHits;
192 
193  for(size_t j = 0; j < ffuzzyCluster.fpointId_to_clusterId.size(); ++j){
195  clusterHits.push_back(allhits[j]);
196  }
197  }
198 
199 
201  if (!clusterHits.empty()){
203  const geo::WireID& wireID = clusterHits.front()->WireID();
204  unsigned int sw = wireID.Wire;
205  unsigned int ew = clusterHits.back()->WireID().Wire;
206 
207  // feed the algorithm with all the cluster hits
208  ClusterParamAlgo.ImportHits(clusterHits);
209 
210  // create the recob::Cluster directly in the vector
212  ClusterParamAlgo, // algo
213  float(sw), // start_wire
214  0., // sigma_start_wire
215  clusterHits.front()->PeakTime(), // start_tick
216  clusterHits.front()->SigmaPeakTime(), // sigma_start_tick
217  float(ew), // end_wire
218  0., // sigma_end_wire,
219  clusterHits.back()->PeakTime(), // end_tick
220  clusterHits.back()->SigmaPeakTime(), // sigma_end_tick
221  ccol->size(), // ID
222  clusterHits.front()->View(), // view
223  wireID.planeID(), // plane
224  recob::Cluster::Sentry // sentry
225  );
226 
227  ccol->emplace_back(cluster.move());
228 
229  // associate the hits to this cluster
230  util::CreateAssn(*this, evt, *ccol, clusterHits, *assn);
231 
232  clusterHits.clear();
233 
234  }//end if clusterHits has at least one hit
235 
236  }//end loop over fclusters
237 
238  allhits.clear();
239  } // end loop over map
240 
241  mf::LogVerbatim("Summary") << std::setfill('-') << std::setw(175) << "-" << std::setfill(' ');
242  mf::LogVerbatim("Summary") << "fuzzyCluster Summary:";
243  for(size_t i = 0; i<ccol->size(); ++i) mf::LogVerbatim("Summary") << ccol->at(i) ;
244 
245  evt.put(std::move(ccol));
246  evt.put(std::move(assn));
247 
248  return;
249  } // end produce
250 
251 } // end namespace
252 
253 namespace cluster{
254 
256 
257 }
258 
259 
260 
261 
262 
263 
264 
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
PlaneID const & planeID() const
Definition: geo_types.h:355
Class managing the creation of a new recob::Cluster object.
void run_fuzzy_cluster(const std::vector< art::Ptr< recob::Hit > > &allhits)
Encapsulate the construction of a single cyostat.
Declaration of signal hit object.
Definition of basic raw digits.
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:313
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
Cluster finding and building.
static const SentryArgument_t Sentry
An instance of the sentry object.
Definition: Cluster.h:182
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
void InitFuzzy(std::vector< art::Ptr< recob::Hit > > &allhits, std::set< uint32_t > badChannels)
fuzzyClusterAlg ffuzzyCluster
object that implements the fuzzy cluster algorithm
base_engine_t & getEngine() const
base_engine_t & createEngine(seed_t seed)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
Signal from induction planes.
Definition: geo_types.h:92
enum geo::_plane_sigtype SigType_t
Enumerate the possible plane projections.
parameter set interface
Helper functions to create a cluster.
Wrapper for ClusterParamsAlgBase objects to accept diverse input.
Collect all the RawData header files together.
T get(std::string const &key) const
Definition: ParameterSet.h:231
Wrapper for ClusterParamsAlgBase objects to accept arbitrary input.
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.
std::vector< std::vector< double > > fps
the collection of points we are working on
Declaration of cluster object.
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
void produce(art::Event &evt)
Float_t sw
Definition: plot.C:23
T * make(ARGS...args) const
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -> clusterId
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
void ImportHits(Iter begin, Iter end)
Calls SetHits() with the hits in the sequence.
std::vector< std::vector< unsigned int > > fclusters
collection of something
void reconfigure(fhicl::ParameterSet const &p)
Interface to class computing cluster parameters.
void reconfigure(fhicl::ParameterSet const &p)
fuzzyCluster(fhicl::ParameterSet const &pset)
art framework interface to geometry description
Encapsulate the construction of a single detector plane.
Signal from collection planes.
Definition: geo_types.h:93