Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
tutorial::ClusterCounter Class Reference
Inheritance diagram for tutorial::ClusterCounter:
art::EDAnalyzer art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::detail::Analyzer art::detail::LegacyModule art::Observer art::Observer art::ModuleBase art::ModuleBase

Classes

struct  Config
 

Public Types

using Parameters = art::EDAnalyzer::Table< Config >
 
- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 

Public Member Functions

 ClusterCounter (Parameters const &config)
 
 ClusterCounter (ClusterCounter const &)=delete
 
 ClusterCounter (ClusterCounter &&)=delete
 
ClusterCounteroperator= (ClusterCounter const &)=delete
 
ClusterCounteroperator= (ClusterCounter &&)=delete
 
void analyze (art::Event const &e) override
 
void beginJob () override
 
void endJob () override
 
 ClusterCounter (fhicl::ParameterSet const &p)
 
 ClusterCounter (ClusterCounter const &)=delete
 
 ClusterCounter (ClusterCounter &&)=delete
 
ClusterCounteroperator= (ClusterCounter const &)=delete
 
ClusterCounteroperator= (ClusterCounter &&)=delete
 
void analyze (art::Event const &e) override
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
fhicl::ParameterSetID selectorConfig () const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

float sumAdc (const std::vector< art::Ptr< recob::Hit > > &hits) const
 
const simb::MCParticlegetTruthParticle (detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, float &fraction, bool &foundEmParent) const
 

Private Attributes

size_t fEvNumber
 
TTree * fEventTree
 
size_t fNClusters
 
TTree * fClusterTree
 
size_t fNHits
 
float fAdcSum
 
float fClean
 
art::InputTag fClusterModuleLabel
 
size_t fMinSize
 

Additional Inherited Members

- Protected Member Functions inherited from art::Observer
std::string const & processName () const
 
bool wantAllEvents () const noexcept
 
bool wantEvent (ScheduleID id, Event const &e) const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &select_paths, std::vector< std::string > const &reject_paths, fhicl::ParameterSet const &config)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 34 of file ClusterCounter5_module.cc.

Member Typedef Documentation

Definition at line 51 of file ClusterCounter5_module.cc.

Constructor & Destructor Documentation

tutorial::ClusterCounter::ClusterCounter ( Parameters const &  config)
explicit

Definition at line 91 of file ClusterCounter5_module.cc.

92  fClusterModuleLabel(config().ClusterModuleLabel()),
93  fMinSize(config().MinSize())
94 {
95 }
static Config * config
Definition: config.cpp:1054
tutorial::ClusterCounter::ClusterCounter ( ClusterCounter const &  )
delete
tutorial::ClusterCounter::ClusterCounter ( ClusterCounter &&  )
delete
tutorial::ClusterCounter::ClusterCounter ( fhicl::ParameterSet const &  p)
explicit

Definition at line 37 of file ClusterCounter_module.cc.

37 : EDAnalyzer(p) {}
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
p
Definition: test.py:223
tutorial::ClusterCounter::ClusterCounter ( ClusterCounter const &  )
delete
tutorial::ClusterCounter::ClusterCounter ( ClusterCounter &&  )
delete

Member Function Documentation

void tutorial::ClusterCounter::analyze ( art::Event const &  e)
overridevirtual

Implements art::EDAnalyzer.

void tutorial::ClusterCounter::analyze ( art::Event const &  e)
overridevirtual

Implements art::EDAnalyzer.

Definition at line 112 of file ClusterCounter5_module.cc.

113 {
114  fEvNumber = evt.id().event();
115  mf::LogVerbatim("ClusterCounter") << "ClusterCounter module on event #" << fEvNumber;
116 
117  // use auto to make the line shorter when you remember all art types,
118  // the full type of the handle is: art::ValidHandle< std::vector<recob::Cluster> >
119  auto cluHandle = evt.getValidHandle< std::vector<recob::Cluster> >(fClusterModuleLabel);
120 
121  // this will let us look for all hits associated to selected cluster
122  art::FindManyP< recob::Hit > hitsFromClusters(cluHandle, evt, fClusterModuleLabel);
123 
124  fNClusters = 0;
125 
126  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService>()->DataFor(evt);
127  // and here we go by index:
128  for (size_t i = 0; i < cluHandle->size(); ++i)
129  {
130  fNHits = cluHandle->at(i).NHits();
131  fAdcSum = sumAdc(hitsFromClusters.at(i));
132 
133  bool isEM = false;
134  const simb::MCParticle* p = getTruthParticle(clockData, hitsFromClusters.at(i), fClean, isEM);
135  if (p)
136  {
137  if (isEM) { mf::LogVerbatim("ClusterCounter") << "matched mother particle PDG: " << p->PdgCode(); }
138  else { mf::LogVerbatim("ClusterCounter") << "matched particle PDG: " << p->PdgCode(); }
139  }
140  else { mf::LogWarning("ClusterCounter") << "No matcched particle??"; }
141 
142  fClusterTree->Fill();
143 
144  mf::LogVerbatim("ClusterCounter")
145  << "NHits() = " << fNHits << ", assn size = " << hitsFromClusters.at(i).size()
146  << " SummedADC() = " << cluHandle->at(i).SummedADC() << ", sum hits adc = " << fAdcSum;
147 
148  if (fNHits >= fMinSize) { ++fNClusters; }
149  }
150  fEventTree->Fill();
151 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
int PdgCode() const
Definition: MCParticle.h:212
unsigned int event
Definition: DataStructs.h:636
float sumAdc(const std::vector< art::Ptr< recob::Hit > > &hits) const
p
Definition: test.py:223
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
const simb::MCParticle * getTruthParticle(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, float &fraction, bool &foundEmParent) const
TCEvent evt
Definition: DataStructs.cxx:7
void tutorial::ClusterCounter::beginJob ( )
overridevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 97 of file ClusterCounter5_module.cc.

98 {
99  art::ServiceHandle<art::TFileService> tfs; // TTree's are created in the memory managed by ROOT (you don't delete them)
100 
101  fEventTree = tfs->make<TTree>("EventTree", "event by event info");
102  fEventTree->Branch("event", &fEvNumber, "fEvNumber/I");
103  fEventTree->Branch("nclusters", &fNClusters, "fNClusters/I");
104 
105  fClusterTree = tfs->make<TTree>("ClusterTree", "cluster by cluster info");
106  fClusterTree->Branch("event", &fEvNumber, "fEvNumber/I");
107  fClusterTree->Branch("nhits", &fNHits, "fNHits/I");
108  fClusterTree->Branch("adcsum", &fAdcSum, "fAdcSum/F");
109  fClusterTree->Branch("clean", &fClean, "fClean/F");
110 }
void tutorial::ClusterCounter::endJob ( )
overridevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 209 of file ClusterCounter5_module.cc.

210 {
211  mf::LogVerbatim("ClusterCounter") << "ClusterCounter finished job";
212 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const simb::MCParticle * tutorial::ClusterCounter::getTruthParticle ( detinfo::DetectorClocksData const &  clockData,
const std::vector< art::Ptr< recob::Hit > > &  hits,
float &  fraction,
bool foundEmParent 
) const
private

Definition at line 153 of file ClusterCounter5_module.cc.

156 {
157  const simb::MCParticle* mcParticle =0;
158  fraction = 0;
159  foundEmParent = false;
160 
163  std::unordered_map<int, double> trkIDE;
164  for (auto const & h : hits)
165  {
166  for (auto const & ide : bt_serv->HitToTrackIDEs(clockData, h)) // loop over std::vector<sim::TrackIDE>
167  {
168  trkIDE[ide.trackID] += ide.energy; // sum energy contribution by each track ID
169  }
170  }
171 
172  int best_id = 0;
173  double tot_e = 0, max_e = 0;
174  for (auto const & contrib : trkIDE)
175  {
176  tot_e += contrib.second; // sum total energy in these hits
177  if (contrib.second > max_e) // find track ID corresponding to max energy
178  {
179  max_e = contrib.second;
180  best_id = contrib.first;
181  }
182  }
183 
184  if ((max_e > 0) && (tot_e > 0)) // ok, found something reasonable
185  {
186  if (best_id < 0) // NOTE: negative ID means this is EM activity
187  { // caused by track with the same but positive ID
188  best_id = -best_id; // --> we'll find mother MCParticle of these hits
189  foundEmParent = true;
190  }
191  mcParticle = pi_serv->TrackIdToParticle_P(best_id); // MCParticle corresponding to track ID
192  fraction = max_e / tot_e;
193  }
194  else { mf::LogWarning("ClusterCounter") << "No energy deposits??"; }
195 
196  return mcParticle;
197 }
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
const simb::MCParticle * TrackIdToParticle_P(int id) const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
ClusterCounter& tutorial::ClusterCounter::operator= ( ClusterCounter const &  )
delete
ClusterCounter& tutorial::ClusterCounter::operator= ( ClusterCounter &&  )
delete
ClusterCounter& tutorial::ClusterCounter::operator= ( ClusterCounter const &  )
delete
ClusterCounter& tutorial::ClusterCounter::operator= ( ClusterCounter &&  )
delete
float tutorial::ClusterCounter::sumAdc ( const std::vector< art::Ptr< recob::Hit > > &  hits) const
private

Definition at line 199 of file ClusterCounter5_module.cc.

200 {
201  float sum = 0;
202  for (auto const & h : hits)
203  {
204  sum += h->SummedADC();
205  }
206  return sum;
207 }

Member Data Documentation

float tutorial::ClusterCounter::fAdcSum
private

Definition at line 83 of file ClusterCounter5_module.cc.

float tutorial::ClusterCounter::fClean
private

Definition at line 84 of file ClusterCounter5_module.cc.

art::InputTag tutorial::ClusterCounter::fClusterModuleLabel
private

Definition at line 87 of file ClusterCounter5_module.cc.

TTree* tutorial::ClusterCounter::fClusterTree
private

Definition at line 81 of file ClusterCounter5_module.cc.

TTree* tutorial::ClusterCounter::fEventTree
private

Definition at line 78 of file ClusterCounter5_module.cc.

size_t tutorial::ClusterCounter::fEvNumber
private

Definition at line 76 of file ClusterCounter5_module.cc.

size_t tutorial::ClusterCounter::fMinSize
private

Definition at line 88 of file ClusterCounter5_module.cc.

size_t tutorial::ClusterCounter::fNClusters
private

Definition at line 79 of file ClusterCounter5_module.cc.

size_t tutorial::ClusterCounter::fNHits
private

Definition at line 82 of file ClusterCounter5_module.cc.


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