TrackHitInfo_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: TrackHitInfo
3 // Plugin Type: analyzer (art v3_05_01)
4 // File: TrackHitInfo_module.cc
5 //
6 // Check the TPC ID of hits associated to ProtoDUNE DP tracks
7 //
8 ////////////////////////////////////////////////////////////////////////
9 #include <iostream>
10 #include <vector>
11 #include <utility>
12 
20 #include "fhiclcpp/ParameterSet.h"
22 
23 #include "art_root_io/TFileService.h"
24 
25 // LArSoft includes
34 
35 //
37 
38 
39 //
40 using std::cerr;
41 using std::cout;
42 using std::endl;
43 using std::vector;
44 using std::string;
45 using std::pair;
46 
47 //
48 namespace pddpana {
49  class TrackHitInfo;
50 }
51 
52 
53 //
55 public:
56  explicit TrackHitInfo(fhicl::ParameterSet const& p);
57  // The compiler-generated destructor is fine for non-base
58  // classes without bare pointers or other resource use.
59 
60  // Plugins should not be copied or assigned.
61  TrackHitInfo(TrackHitInfo const&) = delete;
62  TrackHitInfo(TrackHitInfo&&) = delete;
63  TrackHitInfo& operator=(TrackHitInfo const&) = delete;
64  TrackHitInfo& operator=(TrackHitInfo&&) = delete;
65 
66  // Required functions.
67  void analyze(art::Event const& e) override;
68 
69  // Selected optional functions.
70  void beginJob() override;
71  void endJob() override;
72 
73 private:
74 
75  int fLogLevel;
77  unsigned fTracksTotal;
78  unsigned fTracksRejected;
79 
80  // track utils
82 
83  // detector geometry
85  // detector properties
86  //const detinfo::DetectorProperties* fDetprop;
87 };
88 
89 
91  : EDAnalyzer{p} ,
92  fLogLevel( p.get< int >("LogLevel") ),
93  fTrackModuleLabel( p.get< std::string >("TrackModuleLabel") )
94  {
96  //fDetprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
97 
98  }
99 
100 //
102 {
103  const string myname = "pddpana::TrackHitInfo::analyze: ";
104 
105  // get hits ValidHandle< std::vector<recob::Hits> >
106  auto Tracks = e.getValidHandle<vector<recob::Track>>(fTrackModuleLabel);
107 
108  if( fLogLevel >= 2 ){
109  cout<<myname<<"The event contains "<< Tracks->size() <<" tracks\n";
110  }
111 
112  unsigned EventId = e.id().event();
113 
114  fTracksTotal += Tracks->size();
115 
116  // loop over tracks
117  for (unsigned itrk = 0; itrk < Tracks->size(); ++itrk) {
118  const recob::Track& track = Tracks->at(itrk);
119  unsigned TrackId = itrk;
120  unsigned TrajPnts = track.NumberTrajectoryPoints();
121  float TrackLen = track.Length();
122 
123  if( fLogLevel >= 3 ){
124  cout<<myname<<"Track ID "<<TrackId<<" has "
125  <<TrajPnts<<" points and is "<<TrackLen<<" cm long"
126  << "\n start at: ( " << track.Vertex().X()
127  << " ; " << track.Vertex().Y()
128  << " ; " << track.Vertex().Z()
129  << "\n end at: ( " << track.End().X()
130  << " ; " << track.End().Y()
131  << " ; " << track.End().Z()<<" )"<<endl;
132  }
133 
134  vector<unsigned> hitsTpcId( fGeom->Nplanes() );
135 
136  // loop over the planes
137  for(size_t i_plane = 0; i_plane<fGeom->Nplanes(); i_plane++) {
138 
139  // get hits in this plane
140  auto hits = trackUtil.GetRecoTrackHitsFromPlane( track, e, fTrackModuleLabel, i_plane );
141  if( fLogLevel >= 3 ){
142  cout<<myname<<"Hits in plane "<<i_plane<<" "<<hits.size()<<endl;
143  }
144 
145  vector<unsigned> plane_hits_tpcid( hits.size() );
146  // loop over hits
147  for(size_t i_hit = 0; i_hit<hits.size(); i_hit++ ){
148  plane_hits_tpcid[i_hit] = hits[i_hit]->WireID().TPC;
149  }
150 
151  int this_tpcid = -1;
152  auto start = plane_hits_tpcid.begin();
153  auto end = plane_hits_tpcid.end();
154  if( std::equal(start + 1, end, start)) {
155  this_tpcid = (int)(*start);
156  } //
157  else {
158  if( fLogLevel>= 2){
159  cout<<myname<<"hits for the same plane have mixed TPC IDs. Skipping...\n";
160  }
161  }
162  if( this_tpcid < 0 ){
163  hitsTpcId.clear();
164  break;
165  }
166  else{
167  hitsTpcId[i_plane] = (unsigned)this_tpcid;
168  }
169  }// end plane loop
170 
171  if( hitsTpcId.empty() ) continue;
172 
173  auto start = hitsTpcId.begin();
174  auto end = hitsTpcId.end();
175  if( !std::equal(start + 1, end, start)) {
176  if( fLogLevel >= 2 ){
177  cout<<myname<<"mismatch in TPC ID for the initial hits: ";
178  cout<<" event ID "<<EventId<<"; hit TPC IDs ";
179  for( auto const &v: hitsTpcId ){ cout<<v<<" ";}
180  cout<<endl;
181  }
182  fTracksRejected++;
183  } //
184 
185  }// end track loop
186 
187  //
188 
189 } // end analyze()
190 
191 //
192 //
194 {
195  fTracksTotal = 0;
196  fTracksRejected = 0;
197 }
198 
199 //
200 //
202 {
203  cout<<"Tracks total : "<<fTracksTotal<<endl;
204  cout<<"Tracks rejected : "<<fTracksRejected<<endl;
205 }
206 
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
TrackHitInfo & operator=(TrackHitInfo const &)=delete
std::string string
Definition: nybbler.cc:12
struct vector vector
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Definition: Track.h:102
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
art framework interface to geometry description
TrackHitInfo(fhicl::ParameterSet const &p)
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
const double e
double Length(size_t p=0) const
Access to various track properties.
Definition: Track.h:167
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
Point_t const & Vertex() const
Definition: Track.h:124
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
void analyze(art::Event const &e) override
The geometry of one entire detector, as served by art.
Definition: Geometry.h:196
const std::vector< const recob::Hit * > GetRecoTrackHitsFromPlane(const recob::Track &track, art::Event const &evt, const std::string trackModule, unsigned int planeID) const
Get the hits from a given reco track from a specific plane.
Declaration of signal hit object.
protoana::ProtoDUNETrackUtils trackUtil
Provides recob::Track data product.
EventNumber_t event() const
Definition: EventID.h:116
Point_t const & End() const
Definition: Track.h:125
const geo::Geometry * fGeom
Declaration of basic channel signal object.
Utility functions to extract information from recob::Track
EventID id() const
Definition: Event.cc:34
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
QTextStream & endl(QTextStream &s)