LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
DBcluster_module.cc
Go to the documentation of this file.
1 //
3 // \file DBcluster_module.cc
4 //
5 // \author kinga.partyka@yale.edu
6 //
8 
9 //Framework includes:
12 #include "fhiclcpp/ParameterSet.h"
21 
22 //LArSoft includes
30 #include "larevt/CalibrationDBI/Interface/ChannelStatusService.h"
31 #include "larevt/CalibrationDBI/Interface/ChannelStatusProvider.h"
36 
37 #include <fstream>
38 #include <cstdlib>
39 #include "TGeoManager.h"
40 #include "TH1.h"
41 #include <vector>
42 #include <cmath>
43 #include <iostream>
44 #include <iomanip>
45 
46 class TH1F;
47 
48 namespace cluster{
49 
50  //---------------------------------------------------------------
51  class DBcluster : public art::EDProducer
52  {
53  public:
54  explicit DBcluster(fhicl::ParameterSet const& pset);
55  ~DBcluster();
56  void produce(art::Event& evt);
57  void beginJob();
58  void reconfigure(fhicl::ParameterSet const& p);
59 
60  private:
61 
62  TH1F *fhitwidth;
65 
66  std::string fhitsModuleLabel;
67 
69  };
70 
71 }
72 
73 namespace cluster{
74 
75  //-------------------------------------------------
77  : fDBScan(pset.get< fhicl::ParameterSet >("DBScanAlg"))
78  {
79  this->reconfigure(pset);
80  produces< std::vector<recob::Cluster> >();
81  produces< art::Assns<recob::Cluster, recob::Hit> >();
82  }
83 
84  //-------------------------------------------------
86  {
87  }
88 
89  //-------------------------------------------------
91  {
92  fhitsModuleLabel = p.get< std::string >("HitsModuleLabel");
93  fDBScan.reconfigure(p.get< fhicl::ParameterSet >("DBScanAlg"));
94  }
95 
96  //-------------------------------------------------
98  // get access to the TFile service
100 
101  fhitwidth= tfs->make<TH1F>(" fhitwidth","width of hits in cm", 50000,0 ,5 );
102  fhitwidth_ind_test= tfs->make<TH1F>("fhitwidth_ind_test","width of hits in cm", 50000,0 ,5 );
103  fhitwidth_coll_test= tfs->make<TH1F>("fhitwidth_coll_test","width of hits in cm", 50000,0 ,5 );
104 
105  }
106 
107  //-----------------------------------------------------------------
109  {
110 
111  //get a collection of clusters
112  std::unique_ptr<std::vector<recob::Cluster> > ccol(new std::vector<recob::Cluster>);
113  std::unique_ptr< art::Assns<recob::Cluster, recob::Hit> > assn(new art::Assns<recob::Cluster, recob::Hit>);
114 
115  // prepare the algorithm to compute the cluster characteristics;
116  // we use the "standard" one here; configuration would happen here,
117  // but we are using the default configuration for that algorithm
119 
121 
123  evt.getByLabel(fhitsModuleLabel,hitcol);
124 
125  // loop over all hits in the event and look for clusters (for each plane)
126  std::vector< art::Ptr<recob::Hit> > allhits;
127 
128  // get channel quality service:
129  lariov::ChannelStatusProvider const& channelStatus
131 
132  lariov::ChannelStatusProvider::ChannelSet_t const BadChannels
133  = channelStatus.BadChannels();
134 
135  // make a map of the geo::PlaneID to vectors of art::Ptr<recob::Hit>
136  std::map<geo::PlaneID, std::vector< art::Ptr<recob::Hit> > > planeIDToHits;
137  for(size_t i = 0; i < hitcol->size(); ++i)
138  planeIDToHits[hitcol->at(i).WireID().planeID()].push_back(art::Ptr<recob::Hit>(hitcol, i));
139 
140 
141  for(auto & itr : planeIDToHits){
142 
143  geo::SigType_t sigType = geom->SignalType(itr.first);
144  allhits.resize(itr.second.size());
145  allhits.swap(itr.second);
146 
147  fDBScan.InitScan(allhits, BadChannels);
148 
149  //----------------------------------------------------------------
150  for(unsigned int j = 0; j < fDBScan.fps.size(); ++j){
151 
152  if(allhits.size() != fDBScan.fps.size()) break;
153 
154  fhitwidth->Fill(fDBScan.fps[j][2]);
155 
156  if(sigType == geo::kInduction) fhitwidth_ind_test->Fill(fDBScan.fps[j][2]);
157  if(sigType == geo::kCollection) fhitwidth_coll_test->Fill(fDBScan.fps[j][2]);
158  }
159 
160  //*******************************************************************
162 
163  for(size_t i = 0; i < fDBScan.fclusters.size(); ++i){
164  art::PtrVector<recob::Hit> clusterHits;
165  double totalQ = 0.;
166 
167  for(size_t j = 0; j < fDBScan.fpointId_to_clusterId.size(); ++j){
168  if(fDBScan.fpointId_to_clusterId[j]==i){
169  clusterHits.push_back(allhits[j]);
170  totalQ += clusterHits.back()->Integral();
171  }
172  }
173 
175  if (clusterHits.size()>0){
176 
178  const geo::WireID& wireID = clusterHits.front()->WireID();
179  unsigned int sw = wireID.Wire;
180  unsigned int ew = clusterHits.back()->WireID().Wire;
181 
182  // feed the algorithm with all the cluster hits
183  ClusterParamAlgo.ImportHits(clusterHits);
184 
185  // create the recob::Cluster directly in the vector
187  ClusterParamAlgo, // algo
188  float(sw), // start_wire
189  0., // sigma_start_wire
190  clusterHits.front()->PeakTime(), // start_tick
191  clusterHits.front()->SigmaPeakTime(), // sigma_start_tick
192  float(ew), // end_wire
193  0., // sigma_end_wire,
194  clusterHits.back()->PeakTime(), // end_tick
195  clusterHits.back()->SigmaPeakTime(), // sigma_end_tick
196  ccol->size(), // ID
197  clusterHits.front()->View(), // view
198  wireID.planeID(), // plane
199  recob::Cluster::Sentry // sentry
200  );
201 
202  ccol->emplace_back(cluster.move());
203 
204  // associate the hits to this cluster
205  util::CreateAssn(*this, evt, *(ccol.get()), clusterHits, *(assn.get()));
206 
207  clusterHits.clear();
208 
209  }//end if clusterHits has at least one hit
210 
211  }//end loop over fclusters
212 
213  allhits.clear();
214  } // end loop over PlaneID map
215 
216  mf::LogVerbatim("Summary") << std::setfill('-') << std::setw(175) << "-" << std::setfill(' ');
217  mf::LogVerbatim("Summary") << "DBcluster Summary:";
218  for(unsigned int i = 0; i<ccol->size(); ++i) mf::LogVerbatim("Summary") << ccol->at(i) ;
219 
220  evt.put(std::move(ccol));
221  evt.put(std::move(assn));
222 
223  return;
224  }
225 
226 
227 } // end namespace
228 
229 
230 
231 
232 
233 namespace cluster{
234 
236 
237 }
238 
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 reconfigure(fhicl::ParameterSet const &p)
void InitScan(const std::vector< art::Ptr< recob::Hit > > &allhits, std::set< uint32_t > badChannels, const std::vector< geo::WireID > &wireids=std::vector< geo::WireID >())
Definition: DBScanAlg.cxx:281
Encapsulate the construction of a single cyostat.
Declaration of signal hit object.
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:313
std::vector< std::vector< double > > fps
the collection of points we are working on
Definition: DBScanAlg.h:61
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
DBScanAlg fDBScan
object that implements the DB scan algorithm
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
reference back()
Definition: PtrVector.h:393
std::vector< unsigned int > fpointId_to_clusterId
mapping point_id -> clusterId
Definition: DBScanAlg.h:62
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
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.
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.
Declaration of cluster object.
size_type size() const
Definition: PtrVector.h:308
std::string fhitsModuleLabel
reference front()
Definition: PtrVector.h:379
Float_t sw
Definition: plot.C:23
void produce(art::Event &evt)
T * make(ARGS...args) const
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
std::vector< std::vector< unsigned int > > fclusters
collection of something
Definition: DBScanAlg.h:60
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.
void reconfigure(fhicl::ParameterSet const &p)
Definition: DBScanAlg.cxx:271
DBcluster(fhicl::ParameterSet const &pset)
Interface to class computing cluster parameters.
TCEvent evt
Definition: DataStructs.cxx:5
void clear()
Definition: PtrVector.h:537
art framework interface to geometry description
Encapsulate the construction of a single detector plane.
Signal from collection planes.
Definition: geo_types.h:93