LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
PFParticleTrackAna_module.cc
Go to the documentation of this file.
1 
9 
10 #include "TTree.h"
11 
12 #include <string>
13 
14 //------------------------------------------------------------------------------------------------------------------------------------------
15 
16 namespace lar_pandora
17 {
18 
23 {
24 public:
31 
35  virtual ~PFParticleTrackAna();
36 
37  void beginJob();
38  void endJob();
39  void analyze(const art::Event &evt);
40  void reconfigure(fhicl::ParameterSet const &pset);
41 
42 private:
43 
44  TTree *m_pCaloTree;
45 
46  int m_run;
47  int m_event;
48  int m_index;
49  int m_ntracks;
50  int m_trkid;
51  int m_plane;
52 
53  double m_length;
54  double m_dEdx;
55  double m_dNdx;
56  double m_dQdx;
57  double m_residualRange;
58 
59  double m_x;
60  double m_y;
61  double m_z;
62  double m_px;
63  double m_py;
64  double m_pz;
65 
66  bool m_useModBox;
67  bool m_isCheated;
68 
69  std::string m_trackModuleLabel;
70 };
71 
73 
74 } // namespace lar_pandora
75 
76 //------------------------------------------------------------------------------------------------------------------------------------------
77 // implementation follows
78 
80 #include "fhiclcpp/ParameterSet.h"
88 
93 
95 
96 #include <iostream>
97 
98 namespace lar_pandora
99 {
100 
102 {
103  this->reconfigure(pset);
104 }
105 
106 //------------------------------------------------------------------------------------------------------------------------------------------
107 
109 {
110 }
111 
112 //------------------------------------------------------------------------------------------------------------------------------------------
113 
115 {
116  m_useModBox = pset.get<bool>("UeModBox",true);
117  m_isCheated = pset.get<bool>("IsCheated",false);
118  m_trackModuleLabel = pset.get<std::string>("TrackModule","pandora");
119 }
120 
121 //------------------------------------------------------------------------------------------------------------------------------------------
122 
124 {
125  //
127 
128  m_pCaloTree = tfs->make<TTree>("calorimetry", "LAr Track Calo Tree");
129  m_pCaloTree->Branch("run", &m_run, "run/I");
130  m_pCaloTree->Branch("event", &m_event, "event/I");
131  m_pCaloTree->Branch("index", &m_index, "index/I");
132  m_pCaloTree->Branch("ntracks", &m_ntracks, "ntracks/I");
133  m_pCaloTree->Branch("trkid", &m_trkid, "trkid/I");
134  m_pCaloTree->Branch("plane", &m_plane, "plane/I");
135  m_pCaloTree->Branch("length", &m_length, "length/D");
136  m_pCaloTree->Branch("dEdx", &m_dEdx, "dEdx/D");
137  m_pCaloTree->Branch("dNdx", &m_dNdx, "dNdx/D");
138  m_pCaloTree->Branch("dQdx", &m_dQdx, "dQdx/D");
139  m_pCaloTree->Branch("residualRange", &m_residualRange, "residualRange/D");
140  m_pCaloTree->Branch("x", &m_x, "x/D");
141  m_pCaloTree->Branch("y", &m_y, "y/D");
142  m_pCaloTree->Branch("z", &m_z, "z/D");
143  m_pCaloTree->Branch("px", &m_px, "px/D");
144  m_pCaloTree->Branch("py", &m_py, "py/D");
145  m_pCaloTree->Branch("pz", &m_pz, "pz/D");
146 }
147 
148 //------------------------------------------------------------------------------------------------------------------------------------------
149 
151 {
152 }
153 
154 //------------------------------------------------------------------------------------------------------------------------------------------
155 
157 {
158  std::cout << " *** PFParticleTrackAna::analyze(...) *** " << std::endl;
159 
160  m_run = evt.run();
161  m_event = evt.id().event();
162  m_index = 0;
163 
164  m_ntracks = 0;
165  m_trkid = 0;
166  m_plane = 0;
167  m_length = 0.0;
168  m_dEdx = 0.0;
169  m_dNdx = 0.0;
170  m_dQdx = 0.0;
171  m_residualRange = 0.0;
172 
173  m_x = 0.0;
174  m_y = 0.0;
175  m_z = 0.0;
176  m_px = 0.0;
177  m_py = 0.0;
178  m_pz = 0.0;
179 
180  std::cout << " Run: " << m_run << std::endl;
181  std::cout << " Event: " << m_event << std::endl;
182 
183  TrackVector trackVector;
184  TracksToHits tracksToHits;
185  LArPandoraHelper::CollectTracks(evt, m_trackModuleLabel, trackVector, tracksToHits);
186 
187  std::cout << " Tracks: " << trackVector.size() << std::endl;
188 
189  // art::ServiceHandle<geo::Geometry> theGeometry;
190  // auto const* theDetector = lar::providerFrom<detinfo::DetectorPropertiesService>();
191 
194 
195  // const double adc2eU(5.1e-3);
196  // const double adc2eV(5.2e-3);
197  // const double adc2eW(5.4e-3);
198  // const double adc2eCheat(theDetector->ElectronsToADC());
199 
200  // const double tau(theDetector->ElectronLifetime());
201 
202  m_ntracks = trackVector.size();
203 
204  for (TrackVector::const_iterator iter = trackVector.begin(), iterEnd = trackVector.end(); iter != iterEnd; ++iter)
205  {
206  const art::Ptr<recob::Track> track = *iter;
207 
208  m_trkid = track->ID();
209  m_length = track->Length();
210 
211  m_plane = 0;
212  m_dEdx = 0.0;
213  m_dNdx = 0.0;
214  m_dQdx = 0.0;
215  m_residualRange = 0.0;
216 
217  m_x = 0.0;
218  m_y = 0.0;
219  m_z = 0.0;
220  m_px = 0.0;
221  m_py = 0.0;
222  m_pz = 0.0;
223 
224  for (unsigned int p = 0; p < track->NumberTrajectoryPoints(); ++p)
225  {
226  auto pos = track->LocationAtPoint(p);
227  auto dir = track->DirectionAtPoint(p);
228 
229  m_residualRange = track->Length(p);
230 
231  m_x = pos.x();
232  m_y = pos.y();
233  m_z = pos.z();
234  m_px = dir.x();
235  m_py = dir.y();
236  m_pz = dir.z();
237 
238  /*************************************************************/
239  /* WARNING */
240  /*************************************************************/
241  /* The dQdx information in recob::Track has been deprecated */
242  /* since 2016 and in 11/2018 the recob::Track interface was */
243  /* changed and DQdxAtPoint and NumberdQdx were removed. */
244  /* Therefore the code below is now commented out */
245  /* (note that it was most likely not functional anyways). */
246  /* For any issue please contact: larsoft-team@fnal.gov */
247  /*************************************************************/
248  /*
249  const double dQdxU(track->DQdxAtPoint(p, geo::kU)); // plane 0
250  const double dQdxV(track->DQdxAtPoint(p, geo::kV)); // plane 1
251  const double dQdxW(track->DQdxAtPoint(p, geo::kW)); // plane 2
252 
253  m_plane = ((dQdxU > 0.0) ? geo::kU : (dQdxV > 0.0) ? geo::kV : geo::kW);
254 
255  const double adc2e(m_isCheated ? adc2eCheat : (geo::kU == m_plane) ? adc2eU : (geo::kV == m_plane) ? adc2eV : adc2eW);
256 
257  m_dQdx = ((geo::kU == m_plane) ? dQdxU : (geo::kV == m_plane) ? dQdxV : dQdxW);
258 
259  // TODO: Need to include T0 information (currently assume T0 = 0)
260 
261  m_dNdx = ((m_dQdx / adc2e) * exp((m_x / theDetector->GetXTicksCoefficient()) * theDetector->SamplingRate() * 1.e-3 / tau));
262 
263  m_dEdx = (m_useModBox ? theDetector->ModBoxCorrection(m_dNdx) : theDetector->BirksCorrection(m_dNdx));
264  */
265  /*************************************************************/
266 
267  m_pCaloTree->Fill();
268  ++m_index;
269  }
270  }
271 }
272 
273 } //namespace lar_pandora
Point_t const & LocationAtPoint(size_t i) const
Access to track position at different points.
Definition: Track.h:129
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Definition: Track.h:105
std::map< art::Ptr< recob::Track >, HitVector > TracksToHits
std::vector< art::Ptr< recob::Track > > TrackVector
void reconfigure(fhicl::ParameterSet const &pset)
double Length(size_t p=0) const
Access to various track properties.
Definition: Track.h:170
intermediate_table::const_iterator const_iterator
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
Provides recob::Track data product.
PFParticleTrackAna(fhicl::ParameterSet const &pset)
Constructor.
T get(std::string const &key) const
Definition: ParameterSet.h:231
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
static void CollectTracks(const art::Event &evt, const std::string &label, TrackVector &trackVector, PFParticlesToTracks &particlesToTracks)
Collect the reconstructed PFParticles and associated Tracks from the ART event record.
int ID() const
Definition: Track.h:201
T * make(ARGS...args) const
TDirectory * dir
Definition: macro.C:5
HLT enums.
EventNumber_t event() const
Definition: EventID.h:117
Vector_t DirectionAtPoint(size_t i) const
Access to track direction at different points.
Definition: Track.h:137
TCEvent evt
Definition: DataStructs.cxx:5
RunNumber_t run() const
Definition: Event.h:77
Float_t track
Definition: plot.C:34
helper function for LArPandoraInterface producer module
EventID id() const
Definition: Event.h:56
art framework interface to geometry description