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

Public Member Functions

 ClusterCounter4 (fhicl::ParameterSet const &p)
 
 ClusterCounter4 (ClusterCounter4 const &)=delete
 
 ClusterCounter4 (ClusterCounter4 &&)=delete
 
ClusterCounter4operator= (ClusterCounter4 const &)=delete
 
ClusterCounter4operator= (ClusterCounter4 &&)=delete
 
void analyze (art::Event const &e) override
 
void beginJob () override
 
void endJob () 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

- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 
- 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 35 of file ClusterCounter4_module.cc.

Constructor & Destructor Documentation

tutorial::ClusterCounter4::ClusterCounter4 ( fhicl::ParameterSet const &  p)
explicit

Definition at line 75 of file ClusterCounter4_module.cc.

75  : EDAnalyzer(p)
76 {
77  fClusterModuleLabel = p.get< std::string >("ClusterModuleLabel");
78  fMinSize = p.get< size_t >("MinSize");
79 }
std::string string
Definition: nybbler.cc:12
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
p
Definition: test.py:223
tutorial::ClusterCounter4::ClusterCounter4 ( ClusterCounter4 const &  )
delete
tutorial::ClusterCounter4::ClusterCounter4 ( ClusterCounter4 &&  )
delete

Member Function Documentation

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

Implements art::EDAnalyzer.

Definition at line 96 of file ClusterCounter4_module.cc.

97 {
98  fEvNumber = evt.id().event();
99  mf::LogVerbatim("ClusterCounter4") << "ClusterCounter4 module on event #" << fEvNumber;
100 
101  // use auto to make the line shorter when you remember all art types,
102  // the full type of the handle is: art::ValidHandle< std::vector<recob::Cluster> >
103  auto cluHandle = evt.getValidHandle< std::vector<recob::Cluster> >(fClusterModuleLabel);
104 
105  // this will let us look for all hits associated to selected cluster
106  art::FindManyP< recob::Hit > hitsFromClusters(cluHandle, evt, fClusterModuleLabel);
107 
108  fNClusters = 0;
109 
110  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService>()->DataFor(evt);
111  // and here we go by index:
112  for (size_t i = 0; i < cluHandle->size(); ++i)
113  {
114  fNHits = cluHandle->at(i).NHits();
115  fAdcSum = sumAdc(hitsFromClusters.at(i));
116 
117  bool isEM = false;
118  const simb::MCParticle* p = getTruthParticle(clockData, hitsFromClusters.at(i), fClean, isEM);
119  if (p)
120  {
121  if (isEM) { mf::LogVerbatim("ClusterCounter4") << "matched mother particle PDG: " << p->PdgCode(); }
122  else { mf::LogVerbatim("ClusterCounter4") << "matched particle PDG: " << p->PdgCode(); }
123  }
124  else { mf::LogWarning("ClusterCounter4") << "No matcched particle??"; }
125 
126  fClusterTree->Fill();
127 
128  mf::LogVerbatim("ClusterCounter4")
129  << "NHits() = " << fNHits << ", assn size = " << hitsFromClusters.at(i).size()
130  << " SummedADC() = " << cluHandle->at(i).SummedADC() << ", sum hits adc = " << fAdcSum;
131 
132  if (fNHits >= fMinSize) { ++fNClusters; }
133  }
134  fEventTree->Fill();
135 }
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
const simb::MCParticle * getTruthParticle(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, float &fraction, bool &foundEmParent) const
p
Definition: test.py:223
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
TCEvent evt
Definition: DataStructs.cxx:7
void tutorial::ClusterCounter4::beginJob ( )
overridevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 81 of file ClusterCounter4_module.cc.

82 {
83  art::ServiceHandle<art::TFileService> tfs; // TTree's are created in the memory managed by ROOT (you don't delete them)
84 
85  fEventTree = tfs->make<TTree>("EventTree", "event by event info");
86  fEventTree->Branch("event", &fEvNumber, "fEvNumber/I");
87  fEventTree->Branch("nclusters", &fNClusters, "fNClusters/I");
88 
89  fClusterTree = tfs->make<TTree>("ClusterTree", "cluster by cluster info");
90  fClusterTree->Branch("event", &fEvNumber, "fEvNumber/I");
91  fClusterTree->Branch("nhits", &fNHits, "fNHits/I");
92  fClusterTree->Branch("adcsum", &fAdcSum, "fAdcSum/F");
93  fClusterTree->Branch("clean", &fClean, "fClean/F");
94 }
void tutorial::ClusterCounter4::endJob ( )
overridevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 193 of file ClusterCounter4_module.cc.

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

Definition at line 137 of file ClusterCounter4_module.cc.

140 {
141  const simb::MCParticle* mcParticle = 0;
142  fraction = 0;
143  foundEmParent = false;
144 
147  std::unordered_map<int, double> trkIDE;
148  for (auto const & h : hits)
149  {
150  for (auto const & ide : bt_serv->HitToTrackIDEs(clockData, h)) // loop over std::vector<sim::TrackIDE>
151  {
152  trkIDE[ide.trackID] += ide.energy; // sum energy contribution by each track ID
153  }
154  }
155 
156  int best_id = 0;
157  double tot_e = 0, max_e = 0;
158  for (auto const & contrib : trkIDE)
159  {
160  tot_e += contrib.second; // sum total energy in these hits
161  if (contrib.second > max_e) // find track ID corresponding to max energy
162  {
163  max_e = contrib.second;
164  best_id = contrib.first;
165  }
166  }
167 
168  if ((max_e > 0) && (tot_e > 0)) // ok, found something reasonable
169  {
170  if (best_id < 0) // NOTE: negative ID means this is EM activity
171  { // caused by track with the same but positive ID
172  best_id = -best_id; // --> we'll find mother MCParticle of these hits
173  foundEmParent = true;
174  }
175  mcParticle = pi_serv->TrackIdToParticle_P(best_id); // MCParticle corresponding to track ID
176  fraction = max_e / tot_e;
177  }
178  else { mf::LogWarning("ClusterCounter4") << "No energy deposits??"; }
179 
180  return mcParticle;
181 }
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
ClusterCounter4& tutorial::ClusterCounter4::operator= ( ClusterCounter4 const &  )
delete
ClusterCounter4& tutorial::ClusterCounter4::operator= ( ClusterCounter4 &&  )
delete
float tutorial::ClusterCounter4::sumAdc ( const std::vector< art::Ptr< recob::Hit > > &  hits) const
private

Definition at line 183 of file ClusterCounter4_module.cc.

184 {
185  float sum = 0;
186  for (auto const & h : hits)
187  {
188  sum += h->SummedADC();
189  }
190  return sum;
191 }

Member Data Documentation

float tutorial::ClusterCounter4::fAdcSum
private

Definition at line 67 of file ClusterCounter4_module.cc.

float tutorial::ClusterCounter4::fClean
private

Definition at line 68 of file ClusterCounter4_module.cc.

art::InputTag tutorial::ClusterCounter4::fClusterModuleLabel
private

Definition at line 71 of file ClusterCounter4_module.cc.

TTree* tutorial::ClusterCounter4::fClusterTree
private

Definition at line 65 of file ClusterCounter4_module.cc.

TTree* tutorial::ClusterCounter4::fEventTree
private

Definition at line 62 of file ClusterCounter4_module.cc.

size_t tutorial::ClusterCounter4::fEvNumber
private

Definition at line 60 of file ClusterCounter4_module.cc.

size_t tutorial::ClusterCounter4::fMinSize
private

Definition at line 72 of file ClusterCounter4_module.cc.

size_t tutorial::ClusterCounter4::fNClusters
private

Definition at line 63 of file ClusterCounter4_module.cc.

size_t tutorial::ClusterCounter4::fNHits
private

Definition at line 66 of file ClusterCounter4_module.cc.


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