All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AggregateVertexAna_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // AggregateVertexAna module
4 //
5 // brebel@fnal.gov
6 //
7 ////////////////////////////////////////////////////////////////////////
8 
9 // Framework includes
10 #include "art/Framework/Principal/Event.h"
11 #include "fhiclcpp/ParameterSet.h"
12 #include "art/Framework/Principal/Handle.h"
13 #include "art/Framework/Services/Registry/ServiceHandle.h"
14 #include "art_root_io/TFileService.h"
15 #include "messagefacility/MessageLogger/MessageLogger.h"
16 #include "art/Framework/Core/ModuleMacros.h"
17 #include "art/Framework/Core/EDAnalyzer.h"
18 #include "canvas/Persistency/Common/FindManyP.h"
19 #include "canvas/Persistency/Common/Ptr.h"
20 #include "canvas/Persistency/Common/PtrVector.h"
21 
22 #include <string>
23 
28 
29 #include "TH1.h"
30 #include "TH2.h"
31 
32 namespace vertex {
33 
34  class AggregateVertexAna : public art::EDAnalyzer {
35 
36  public:
37 
38  explicit AggregateVertexAna(fhicl::ParameterSet const& pset);
40 
41  private:
42 
43  void analyze (const art::Event& evt);
44  void beginJob();
45 
46  TH1F* HnTrksVtx;
47  TH1F* HnVtxes;
48  TH1F* HVtxSep;
49  TH2F* HVtxRZ;
50 
51  std::string fDBScanModuleLabel;
52  std::string fHoughModuleLabel;
53  std::string fHitModuleLabel;
54  std::string fTrack3DModuleLabel;
55  std::string fEndPointModuleLabel;
56  std::string fVertexModuleLabel;
57 
58  art::PtrVector<recob::Hit> fhitlist;
59  art::PtrVector<recob::EndPoint2D> feplist;
60  art::PtrVector<recob::Track> ftracklist;
61  art::PtrVector<recob::Vertex> fVertexlist;
62 
63 
64  }; // class AggregateVertexAna
65 
66 } // Namespace aggr
67 
68 namespace vertex{
69 
70  //-----------------------------------------------
71  AggregateVertexAna::AggregateVertexAna(fhicl::ParameterSet const& pset)
72  : EDAnalyzer(pset)
73  , fHitModuleLabel (pset.get< std::string >("FFFTHitModuleLabel"))
74  , fTrack3DModuleLabel (pset.get< std::string >("Track3DModuleLabel"))
75  , fEndPointModuleLabel(pset.get< std::string >("EndPointModuleLabel"))
76  , fVertexModuleLabel (pset.get< std::string >("VertexModuleLabel"))
77  {
78 
79 
80  }
81 
82  //-----------------------------------------------
84  {
85  }
86 
87  //-----------------------------------------------
89  {
90  art::ServiceHandle<art::TFileService const> tfs;
91 
92  HnVtxes = tfs->make<TH1F>("Num Vertices","Num Vertices",8,-0.5,7.5);
93  HVtxSep = tfs->make<TH1F>("Vertices spacing","Vertices spacing",20,0.001,5.0);
94  HVtxRZ = tfs->make<TH2F>("Vtx in RZ","Vtx in RZ",20,-50.0,+50.0,20,0.0,50.0);
95  HnTrksVtx = tfs->make<TH1F>("Tracks per vtx","Tracks per vtx",8,-0.5,7.5);
96 
97  return;
98  }
99 
100  //-----------------------------------------------
101  void AggregateVertexAna::analyze(const art::Event& evt)
102  {
103  art::Handle< std::vector<recob::Hit> > hitListHandle;
104  evt.getByLabel(fHitModuleLabel,hitListHandle);
105  for(unsigned int ii = 0; ii < hitListHandle->size(); ++ii){
106  art::Ptr<recob::Hit> hit(hitListHandle, ii);
107  fhitlist.push_back(hit); // class member
108  }
109 
110  art::Handle< std::vector<recob::EndPoint2D> > epListHandle;
111  evt.getByLabel(fEndPointModuleLabel,epListHandle);
112  for(unsigned int ii = 0; ii < epListHandle->size(); ++ii){
113  art::Ptr<recob::EndPoint2D> ep(epListHandle, ii);
114  feplist.push_back(ep); // class member
115  }
116 
117  art::Handle< std::vector<recob::Track> > trackListHandle;
118  evt.getByLabel(fTrack3DModuleLabel,trackListHandle);
119  for(unsigned int ii = 0; ii < trackListHandle->size(); ++ii){
120  art::Ptr<recob::Track> track(trackListHandle, ii);
121  ftracklist.push_back(track); // class member
122  }
123 
124  art::Handle< std::vector<recob::Vertex> > vertexListHandle;
125  evt.getByLabel(fVertexModuleLabel,vertexListHandle);
126  for(unsigned int ii = 0; ii < vertexListHandle->size(); ++ii){
127  art::Ptr<recob::Vertex> vertex(vertexListHandle, ii);
128  fVertexlist.push_back(vertex); // class member
129  }
130 
131  HnVtxes->Fill(feplist.size(),1);
132 
133  art::FindManyP<recob::Track> fmt(vertexListHandle, evt, fVertexModuleLabel);
134  art::FindManyP<recob::Hit> fmh(vertexListHandle, evt, fVertexModuleLabel);
135 
136  for(size_t v1 = 0; v1 < fVertexlist.size(); ++v1) {
137 
138  std::vector< art::Ptr<recob::Track> > tvlist = fmt.at(v1);
139 
140  HnTrksVtx->Fill(tvlist.size(),1);
141 
142  if(tvlist.size() < 1) continue;
143 
144  std::vector< art::Ptr<recob::Hit> > hitvlist = fmh.at(v1);
145 
146  // Hits no longer has XYZ() method. To get 3d hit position info I'm going to have to
147  // loop on all the SpacePoints and loop on all Hits from there till it matches
148  // one from this vertex. This affects the two Fill() efforts below. EC, 19-Nov-2010.
149  art::PtrVector<recob::Hit>::const_iterator hitv = hitvlist.begin();
150 
151  for(size_t v2 = v1+1; v2 < fVertexlist.size(); ++v2){
152 
153  std::vector< art::Ptr<recob::Hit> > hitvlist2 = fmh.at(v2);
154 
155  std::vector< art::Ptr<recob::Hit> >::const_iterator hitv2 = hitvlist2.begin();
156 
157  // These two whiles should be each precisely one iteration long.
158  while( hitv != hitvlist.end() ){
159  while( hitv2 != hitvlist2.end() ){
160  TVector3 dist;
161  mf::LogInfo("AggregateVertexAna") << "AggregateVertexAna: dist is " << dist.Mag() << ".";
162  HVtxSep->Fill(dist.Mag(),1);
163  hitv2++;
164  }
165  hitv++;
166  }// end loop over hitv entries
167 
168  }// end loop over v2
169  }// end loop over v1
170 
171  return;
172  }// end analyze
173 }// end namespace
174 
175 namespace vertex{
176 
177  DEFINE_ART_MODULE(AggregateVertexAna)
178 
179 }
process_name vertex
Definition: cheaterreco.fcl:51
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
Declaration of signal hit object.
art::PtrVector< recob::Track > ftracklist
process_name use argoneut_mc_hitfinder track
process_name hit
Definition: cheaterreco.fcl:51
art::PtrVector< recob::Hit > fhitlist
void analyze(const art::Event &evt)
art::PtrVector< recob::EndPoint2D > feplist
Provides recob::Track data product.
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
art::PtrVector< recob::Vertex > fVertexlist
art::ServiceHandle< art::TFileService > tfs
TCEvent evt
Definition: DataStructs.cxx:8
AggregateVertexAna(fhicl::ParameterSet const &pset)