ClusterCounter3_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: ClusterCounter3
3 // Module Type: analyzer
4 // File: ClusterCounter3_module.cc
5 //
6 // Access clusters, find assigned hits, fill ROOT tree with.
7 // Robert Sulej
8 ////////////////////////////////////////////////////////////////////////
9 
16 #include "art_root_io/TFileService.h"
17 #include "canvas/Persistency/Common/FindManyP.h"
19 #include "fhiclcpp/ParameterSet.h"
21 
24 
25 #include "TTree.h"
26 
27 namespace tutorial {
28 
30 public:
31  explicit ClusterCounter3(fhicl::ParameterSet const & p);
32 
33  // Plugins should not be copied or assigned.
34  ClusterCounter3(ClusterCounter3 const &) = delete;
35  ClusterCounter3(ClusterCounter3 &&) = delete;
36  ClusterCounter3 & operator = (ClusterCounter3 const &) = delete;
38 
39  // Required functions.
40  void analyze(art::Event const & e) override;
41 
42  // Selected optional functions.
43  void beginJob() override;
44  void endJob() override;
45 
46 private:
47  float sumAdc(const std::vector< art::Ptr<recob::Hit> > & hits) const;
48 
49  size_t fEvNumber;
50 
51  TTree *fEventTree;
52  size_t fNClusters;
53 
54  TTree *fClusterTree;
55  size_t fNHits;
56  float fAdcSum;
57 
58  // ******* fcl parameters *******
60  size_t fMinSize;
61 };
62 
64 {
65  fClusterModuleLabel = p.get< std::string >("ClusterModuleLabel");
66  fMinSize = p.get< size_t >("MinSize");
67 }
68 
70 {
71  art::ServiceHandle<art::TFileService> tfs; // TTree's are created in the memory managed by ROOT (you don't delete them)
72 
73  fEventTree = tfs->make<TTree>("EventTree", "event by event info");
74  fEventTree->Branch("event", &fEvNumber, "fEvNumber/I");
75  fEventTree->Branch("nclusters", &fNClusters, "fNClusters/I");
76 
77  fClusterTree = tfs->make<TTree>("ClusterTree", "cluster by cluster info");
78  fClusterTree->Branch("event", &fEvNumber, "fEvNumber/I");
79  fClusterTree->Branch("nhits", &fNHits, "fNHits/I");
80  fClusterTree->Branch("adcsum", &fAdcSum, "fAdcSum/F");
81 }
82 
84 {
85  fEvNumber = evt.id().event();
86  mf::LogVerbatim("ClusterCounter3") << "ClusterCounter3 module on event #" << fEvNumber;
87 
88  // use auto to make the line shorter when you remember all art types,
89  // the full type of the handle is: art::ValidHandle< std::vector<recob::Cluster> >
90  auto cluHandle = evt.getValidHandle< std::vector<recob::Cluster> >(fClusterModuleLabel);
91 
92  // this will let us look for all hits associated to selected cluster
93  art::FindManyP< recob::Hit > hitsFromClusters(cluHandle, evt, fClusterModuleLabel);
94 
95  fNClusters = 0;
96 
97  // and here we go by index:
98  for (size_t i = 0; i < cluHandle->size(); ++i)
99  {
100  fNHits = cluHandle->at(i).NHits();
101  fAdcSum = sumAdc(hitsFromClusters.at(i));
102  fClusterTree->Fill();
103 
104  mf::LogVerbatim("ClusterCounter3")
105  << "NHits() = " << fNHits << ", assn size = " << hitsFromClusters.at(i).size()
106  << " SummedADC() = " << cluHandle->at(i).SummedADC() << ", sum hits adc = " << fAdcSum;
107 
108  if (fNHits >= fMinSize) { ++fNClusters; }
109  }
110  fEventTree->Fill();
111 }
112 
114 {
115  float sum = 0;
116  for (auto const & h : hits)
117  {
118  sum += h->SummedADC();
119  }
120  return sum;
121 }
122 
124 {
125  mf::LogVerbatim("ClusterCounter3") << "ClusterCounter3 finished job";
126 }
127 
128 } // tutorial namespace
129 
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::string string
Definition: nybbler.cc:12
struct vector vector
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
ClusterCounter3(fhicl::ParameterSet const &p)
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
void analyze(art::Event const &e) override
T get(std::string const &key) const
Definition: ParameterSet.h:271
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
ClusterCounter3 & operator=(ClusterCounter3 const &)=delete
Declaration of signal hit object.
EventNumber_t event() const
Definition: EventID.h:116
TCEvent evt
Definition: DataStructs.cxx:7
float sumAdc(const std::vector< art::Ptr< recob::Hit > > &hits) const
EventID id() const
Definition: Event.cc:34