PFParticleTrackAna_module.cc
Go to the documentation of this file.
1 /**
2  * @file larpandora/LArPandoraAnalysis/PFParticleTrackAna_module.cc
3  *
4  * @brief Analysis module for created particles
5  */
6 
9 
10 #include "TTree.h"
11 
12 #include <string>
13 
14 //------------------------------------------------------------------------------------------------------------------------------------------
15 
16 namespace lar_pandora {
17 
18  /**
19  * @brief PFParticleTrackAna class
20  */
22  public:
23  /**
24  * @brief Constructor
25  *
26  * @param pset
27  */
29 
30  /**
31  * @brief Destructor
32  */
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 
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"
81 #include "canvas/Persistency/Common/FindManyP.h"
82 #include "canvas/Persistency/Common/FindOneP.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 
108  void
110  {
111  m_useModBox = pset.get<bool>("UeModBox", true);
112  m_isCheated = pset.get<bool>("IsCheated", false);
113  m_trackModuleLabel = pset.get<std::string>("TrackModule", "pandora");
114  }
115 
116  //------------------------------------------------------------------------------------------------------------------------------------------
117 
118  void
120  {
121  //
123 
124  m_pCaloTree = tfs->make<TTree>("calorimetry", "LAr Track Calo Tree");
125  m_pCaloTree->Branch("run", &m_run, "run/I");
126  m_pCaloTree->Branch("event", &m_event, "event/I");
127  m_pCaloTree->Branch("index", &m_index, "index/I");
128  m_pCaloTree->Branch("ntracks", &m_ntracks, "ntracks/I");
129  m_pCaloTree->Branch("trkid", &m_trkid, "trkid/I");
130  m_pCaloTree->Branch("plane", &m_plane, "plane/I");
131  m_pCaloTree->Branch("length", &m_length, "length/D");
132  m_pCaloTree->Branch("dEdx", &m_dEdx, "dEdx/D");
133  m_pCaloTree->Branch("dNdx", &m_dNdx, "dNdx/D");
134  m_pCaloTree->Branch("dQdx", &m_dQdx, "dQdx/D");
135  m_pCaloTree->Branch("residualRange", &m_residualRange, "residualRange/D");
136  m_pCaloTree->Branch("x", &m_x, "x/D");
137  m_pCaloTree->Branch("y", &m_y, "y/D");
138  m_pCaloTree->Branch("z", &m_z, "z/D");
139  m_pCaloTree->Branch("px", &m_px, "px/D");
140  m_pCaloTree->Branch("py", &m_py, "py/D");
141  m_pCaloTree->Branch("pz", &m_pz, "pz/D");
142  }
143 
144  //------------------------------------------------------------------------------------------------------------------------------------------
145 
146  void
148  {}
149 
150  //------------------------------------------------------------------------------------------------------------------------------------------
151 
152  void
154  {
155  std::cout << " *** PFParticleTrackAna::analyze(...) *** " << std::endl;
156 
157  m_run = evt.run();
158  m_event = evt.id().event();
159  m_index = 0;
160 
161  m_ntracks = 0;
162  m_trkid = 0;
163  m_plane = 0;
164  m_length = 0.0;
165  m_dEdx = 0.0;
166  m_dNdx = 0.0;
167  m_dQdx = 0.0;
168  m_residualRange = 0.0;
169 
170  m_x = 0.0;
171  m_y = 0.0;
172  m_z = 0.0;
173  m_px = 0.0;
174  m_py = 0.0;
175  m_pz = 0.0;
176 
177  std::cout << " Run: " << m_run << std::endl;
178  std::cout << " Event: " << m_event << std::endl;
179 
180  TrackVector trackVector;
181  TracksToHits tracksToHits;
182  LArPandoraHelper::CollectTracks(evt, m_trackModuleLabel, trackVector, tracksToHits);
183 
184  std::cout << " Tracks: " << trackVector.size() << std::endl;
185 
186  // art::ServiceHandle<geo::Geometry const> theGeometry;
187  // auto const* theDetector = lar::providerFrom<detinfo::DetectorPropertiesService>();
188 
189  ///// microboone_calorimetryalgmc.CalAreaConstants: [ 5.0142e-3, 5.1605e-3, 5.4354e-3 ]
190  ///// lbne35t_calorimetryalgmc.CalAreaConstants: [ 5.1822e-3, 5.2682e-3, 5.3962e-3 ]
191 
192  // const double adc2eU(5.1e-3);
193  // const double adc2eV(5.2e-3);
194  // const double adc2eW(5.4e-3);
195  // const double adc2eCheat(theDetector->ElectronsToADC());
196 
197  // const double tau(theDetector->ElectronLifetime());
198 
199  m_ntracks = trackVector.size();
200 
201  for (TrackVector::const_iterator iter = trackVector.begin(), iterEnd = trackVector.end();
202  iter != iterEnd;
203  ++iter) {
204  const art::Ptr<recob::Track> track = *iter;
205 
206  m_trkid = track->ID();
207  m_length = track->Length();
208 
209  m_plane = 0;
210  m_dEdx = 0.0;
211  m_dNdx = 0.0;
212  m_dQdx = 0.0;
213  m_residualRange = 0.0;
214 
215  m_x = 0.0;
216  m_y = 0.0;
217  m_z = 0.0;
218  m_px = 0.0;
219  m_py = 0.0;
220  m_pz = 0.0;
221 
222  for (unsigned int p = 0; p < track->NumberTrajectoryPoints(); ++p) {
223  auto pos = track->LocationAtPoint(p);
224  auto dir = track->DirectionAtPoint(p);
225 
226  m_residualRange = track->Length(p);
227 
228  m_x = pos.x();
229  m_y = pos.y();
230  m_z = pos.z();
231  m_px = dir.x();
232  m_py = dir.y();
233  m_pz = dir.z();
234 
235  /*************************************************************/
236  /* WARNING */
237  /*************************************************************/
238  /* The dQdx information in recob::Track has been deprecated */
239  /* since 2016 and in 11/2018 the recob::Track interface was */
240  /* changed and DQdxAtPoint and NumberdQdx were removed. */
241  /* Therefore the code below is now commented out */
242  /* (note that it was most likely not functional anyways). */
243  /* For any issue please contact: larsoft-team@fnal.gov */
244  /*************************************************************/
245  /*
246  const double dQdxU(track->DQdxAtPoint(p, geo::kU)); // plane 0
247  const double dQdxV(track->DQdxAtPoint(p, geo::kV)); // plane 1
248  const double dQdxW(track->DQdxAtPoint(p, geo::kW)); // plane 2
249 
250  m_plane = ((dQdxU > 0.0) ? geo::kU : (dQdxV > 0.0) ? geo::kV : geo::kW);
251 
252  const double adc2e(m_isCheated ? adc2eCheat : (geo::kU == m_plane) ? adc2eU : (geo::kV == m_plane) ? adc2eV : adc2eW);
253 
254  m_dQdx = ((geo::kU == m_plane) ? dQdxU : (geo::kV == m_plane) ? dQdxV : dQdxW);
255 
256  // TODO: Need to include T0 information (currently assume T0 = 0)
257 
258  m_dNdx = ((m_dQdx / adc2e) * exp((m_x / theDetector->GetXTicksCoefficient()) * theDetector->SamplingRate() * 1.e-3 / tau));
259 
260  m_dEdx = (m_useModBox ? theDetector->ModBoxCorrection(m_dNdx) : theDetector->BirksCorrection(m_dNdx));
261  */
262  /*************************************************************/
263 
264  m_pCaloTree->Fill();
265  ++m_index;
266  }
267  }
268  }
269 
270 } //namespace lar_pandora
std::string string
Definition: nybbler.cc:12
Point_t const & LocationAtPoint(size_t i) const
Definition: Track.h:126
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Definition: Track.h:102
intermediate_table::const_iterator const_iterator
string dir
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
art framework interface to geometry description
void reconfigure(fhicl::ParameterSet const &pset)
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
PFParticleTrackAna(fhicl::ParameterSet const &pset)
Constructor.
T get(std::string const &key) const
Definition: ParameterSet.h:271
p
Definition: test.py:223
std::vector< art::Ptr< recob::Track > > TrackVector
RunNumber_t run() const
Definition: DataViewImpl.cc:71
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:198
Provides recob::Track data product.
EventNumber_t event() const
Definition: EventID.h:116
Vector_t DirectionAtPoint(size_t i) const
Definition: Track.h:134
TCEvent evt
Definition: DataStructs.cxx:7
helper function for LArPandoraInterface producer module
EventID id() const
Definition: Event.cc:34
QTextStream & endl(QTextStream &s)