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