LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CheckPhotonHits_module.cc
Go to the documentation of this file.
1 //
2 // __ __ __ __ __
3 // ____ ______/ /_____ _/ // / / /_/ /__
4 // / __ `/ ___/ __/ __ `/ // /_/ __/ //_/
5 // / /_/ / / / /_/ /_/ /__ __/ /_/ ,<
6 // \__,_/_/ \__/\__, / /_/ \__/_/|_|
7 // /____/
8 //
9 // artg4tk: art based Geant 4 Toolkit
10 //
11 //=============================================================================
12 // CheckPhotonHits_module.cc: Analyzer module that demonstrates access to
13 // Photon hits and makes some histograms
14 //
15 // Author: Hans Wenzel (Fermilab)
16 //=============================================================================
17 
18 // C++ includes.
19 #include <iostream>
20 #include <map>
21 
22 // art Framework includes.
29 #include "art_root_io/TFileService.h"
30 
31 // artg4tk includes:
32 #include "artg4tk/pluginDetectors/gdml/PhotonHit.hh"
33 
34 // Root includes.
35 #include "TNtuple.h"
36 
37 using namespace std;
38 namespace artg4tk {
39  class CheckPhotonHits;
40 }
41 
43 public:
44  explicit CheckPhotonHits(fhicl::ParameterSet const& p);
45  void beginJob() override;
46  void endJob() override;
47  void analyze(const art::Event& event) override;
48 
49 private:
50  TNtuple* _ntuple;
51 };
52 
54  : art::EDAnalyzer(p), _ntuple(0)
55 {}
56 
57 void
59 {
61  _ntuple = tfs->make<TNtuple>("ntuple", " ntuple", "Event:Section:ID:NPhotons");
62 } // end beginJob
63 
64 void
66 {
67  typedef std::vector<art::Handle<PhotonHitCollection>> HandleVector;
68  std::map<int, int> photonsperdet;
69  auto allSims = event.getMany<PhotonHitCollection>();
70  int section = 0;
71  for (HandleVector::const_iterator i = allSims.begin(); i != allSims.end(); ++i) {
72  photonsperdet.clear();
73  const PhotonHitCollection& sims(**i);
74  for (PhotonHitCollection::const_iterator j = sims.begin(); j != sims.end(); ++j) {
75  const PhotonHit& hit = *j;
76  if (photonsperdet.find(hit.GetID()) == photonsperdet.end()) // new Detector
77  {
78  photonsperdet.insert(std::make_pair(hit.GetID(), 1));
79  } else // new hit on Detector
80  {
81  photonsperdet[hit.GetID()]++;
82  }
83  }
84  std::map<int, int>::iterator it = photonsperdet.begin();
85  while (it != photonsperdet.end()) {
86  std::cout << it->first << " :: " << it->second << std::endl;
87  it++;
88  }
89  }
90  section++;
91 
92 } // end analyze
93 
94 void
96 {
97  cout << " ******************************** CheckPhotonHits: I am done " << endl;
98 } // end endJob
99 
intermediate_table::iterator iterator
STL namespace.
intermediate_table::const_iterator const_iterator
CheckPhotonHits(fhicl::ParameterSet const &p)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
void beginJob()
Definition: Breakpoints.cc:14
Detector simulation of raw signals on wires.
void analyze(const art::Event &event) override
Definition: MVAAlg.h:12
Event finding and building.