LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
AnalysisBaseDrawer.cxx
Go to the documentation of this file.
1 
14 
20 
21 #include "TLatex.h"
22 #include "TLine.h"
23 #include "TPolyMarker.h"
24 
25 #include <cmath>
26 
27 namespace evd {
28 
29  //......................................................................
31 
32  //......................................................................
34 
35  //......................................................................
37  {
41 
42  for (size_t imod = 0; imod < recoOpt->fTrackLabels.size(); ++imod) {
43 
44  //Get Track collection
45  art::InputTag which = recoOpt->fTrackLabels[imod];
47  evt.getByLabel(which, trackListHandle);
48  std::vector<art::Ptr<recob::Track>> tracklist;
49  art::fill_ptr_vector(tracklist, trackListHandle);
50 
51  //Loop over Calorimetry collections
52  for (size_t cmod = 0; cmod < anaOpt->fCalorimetryLabels.size(); ++cmod) {
53  std::string const callabel = anaOpt->fCalorimetryLabels[cmod];
54  //Association between Tracks and Calorimetry
55  art::FindMany<anab::Calorimetry> fmcal(trackListHandle, evt, callabel);
56  if (!fmcal.isValid()) continue;
57  //Loop over PID collections
58  for (size_t pmod = 0; pmod < anaOpt->fParticleIDLabels.size(); ++pmod) {
59  std::string const pidlabel = anaOpt->fParticleIDLabels[pmod];
60  //Association between Tracks and PID
61  art::FindMany<anab::ParticleID> fmpid(trackListHandle, evt, pidlabel);
62  if (!fmpid.isValid()) continue;
63 
64  //Loop over Tracks
65  int ntracks = 0;
66  for (size_t trkIter = 0; trkIter < tracklist.size(); ++trkIter) {
67  if (anaOpt->fTrackID >= 0 and tracklist[trkIter]->ID() != anaOpt->fTrackID) continue;
68  ++ntracks;
69  int color = tracklist[trkIter].key() % evd::kNCOLS;
70  std::vector<const anab::Calorimetry*> calos = fmcal.at(trkIter);
71  std::vector<const anab::ParticleID*> pids = fmpid.at(trkIter);
72  if (!calos.size()) continue;
73  if (calos.size() != pids.size()) continue;
74  size_t bestplane = 0;
75  size_t calopl = 0;
76  //size_t pidpl = 0;
77  size_t nmaxhits = 0;
78  for (size_t icalo = 0; icalo < calos.size(); ++icalo) {
79  if (calos[icalo]->dEdx().size() > nmaxhits) {
80  nmaxhits = calos[icalo]->dEdx().size();
81  bestplane = calos[icalo]->PlaneID().Plane;
82  }
83  }
84  if (anaOpt->fCaloPlane >= 0 and anaOpt->fCaloPlane < int(geom->Nplanes())) {
85  for (size_t icalo = 0; icalo < calos.size(); ++icalo) {
86  if (int(calos[icalo]->PlaneID().Plane) == anaOpt->fCaloPlane &&
87  calos[icalo]->dEdx().size())
88  bestplane = calos[icalo]->PlaneID().Plane;
89  }
90  }
91 
92  for (size_t icalo = 0; icalo < calos.size(); ++icalo) {
93  if (calos[icalo]->PlaneID().Plane == bestplane) { calopl = icalo; }
94  }
95  /*
96  for (size_t ipid = 0; ipid < pids.size(); ++ipid){
97  if (pids[ipid]->PlaneID().Plane==bestplane){
98  pidpl = ipid;
99  }
100  }
101  */
102 
103  TPolyMarker& pm =
104  view->AddPolyMarker(calos[calopl]->dEdx().size(), evd::kColor[color], 8, 0.8);
105  for (size_t h = 0; h < calos[calopl]->dEdx().size(); ++h) {
106  double xvalue = calos[calopl]->ResidualRange().at(h);
107  double yvalue = calos[calopl]->dEdx().at(h);
108  pm.SetPoint(h, xvalue, yvalue);
109 
110  double error = yvalue * (0.04231 + 0.0001783 * (yvalue * yvalue));
111  TLine& l = view->AddLine(xvalue, yvalue - error, xvalue, yvalue + error);
112  l.SetLineColor(evd::kColor[color]);
113  }
114 
115  char trackinfo[80];
116  char pida[80];
117  char proton[80];
118  //char kaon[80];
119  char pion[80];
120  //char muon[80];
121  sprintf(trackinfo,
122  "Track #%d: K.E. = %.1f MeV , Range = %.1f cm",
123  int(tracklist[trkIter].key()),
124  calos[calopl]->KineticEnergy(),
125  calos[calopl]->Range());
126  /*
127  sprintf(proton,"Proton Chi2 = %.1f, Kaon Chi2 = %.1f",
128  pids[pidpl]->Chi2Proton(),
129  pids[pidpl]->Chi2Kaon());
130 // sprintf(kaon,"Kaon Chi2 = %.1f",
131 // pids[pidpl]->Chi2Kaon());
132  sprintf(pion,"Pion Chi2 = %.1f, Muon Chi2 = %.1f",
133  pids[pidpl]->Chi2Pion(),
134  pids[pidpl]->Chi2Muon());
135 // sprintf(muon,"Muon Chi2 = %.1f",
136 // pids[pidpl]->Chi2Muon());
137  sprintf(pida,"Plane %d, PIDA = %.1f, NHits = %d",
138  calos[calopl]->PlaneID().Plane,
139  pids[pidpl]->PIDA(),
140  int(calos[calopl]->dEdx().size()));
141 
142  */
143  double offset = (ntracks - 1) * 10.0;
144  TLatex& track_tex = view->AddLatex(13.0, (46.0) - offset, trackinfo);
145  TLatex& pida_tex = view->AddLatex(13.0, (46.0 - 2.5) - offset, pida);
146  TLatex& proton_tex = view->AddLatex(13.0, (46.0 - 5.0) - offset, proton);
147  //TLatex& kaon_tex = view->AddLatex(13.0, (46.0-4.0) - offset,kaon);
148  TLatex& pion_tex = view->AddLatex(13.0, (46.0 - 7.5) - offset, pion);
149  //TLatex& muon_tex = view->AddLatex(13.0, (46.0-8.0) - offset,muon);
150  track_tex.SetTextColor(evd::kColor[color]);
151  proton_tex.SetTextColor(evd::kColor[color]);
152  //kaon_tex.SetTextColor(evd::kColor[color]);
153  pion_tex.SetTextColor(evd::kColor[color]);
154  //muon_tex.SetTextColor(evd::kColor[color]);
155  pida_tex.SetTextColor(evd::kColor[color]);
156  track_tex.SetTextSize(0.05);
157  proton_tex.SetTextSize(0.05);
158  //kaon_tex.SetTextSize(0.05);
159  pion_tex.SetTextSize(0.05);
160  //muon_tex.SetTextSize(0.05);
161  pida_tex.SetTextSize(0.05);
162  }
163  }
164  }
165  }
166  }
167 
168  //......................................................................
170  {
174  //add some legend-like labels with appropriate grayscale
175  char proton[80];
176  char kaon[80];
177  char pion[80];
178  char muon[80];
179  sprintf(proton, "proton");
180  sprintf(kaon, "kaon");
181  sprintf(pion, "pion");
182  sprintf(muon, "muon");
183  TLatex& proton_tex = view->AddLatex(2.0, 180.0, proton);
184  TLatex& kaon_tex = view->AddLatex(2.0, 165.0, kaon);
185  TLatex& pion_tex = view->AddLatex(2.0, 150.0, pion);
186  TLatex& muon_tex = view->AddLatex(2.0, 135.0, muon);
187  proton_tex.SetTextColor(kBlack);
188  kaon_tex.SetTextColor(kGray + 2);
189  pion_tex.SetTextColor(kGray + 1);
190  muon_tex.SetTextColor(kGray);
191  proton_tex.SetTextSize(0.075);
192  kaon_tex.SetTextSize(0.075);
193  pion_tex.SetTextSize(0.075);
194  muon_tex.SetTextSize(0.075);
195 
196  //now get the actual data
197  for (size_t imod = 0; imod < recoOpt->fTrackLabels.size(); ++imod) {
198  //Get Track collection
199  art::InputTag which = recoOpt->fTrackLabels[imod];
200  art::Handle<std::vector<recob::Track>> trackListHandle;
201  evt.getByLabel(which, trackListHandle);
202  std::vector<art::Ptr<recob::Track>> tracklist;
203  art::fill_ptr_vector(tracklist, trackListHandle);
204 
205  //Loop over Calorimetry collections
206  for (size_t cmod = 0; cmod < anaOpt->fCalorimetryLabels.size(); ++cmod) {
207  std::string const callabel = anaOpt->fCalorimetryLabels[cmod];
208  //Association between Tracks and Calorimetry
209  art::FindMany<anab::Calorimetry> fmcal(trackListHandle, evt, callabel);
210  if (!fmcal.isValid()) continue;
211 
212  //Loop over PID collections
213  for (size_t pmod = 0; pmod < anaOpt->fParticleIDLabels.size(); ++pmod) {
214  std::string const pidlabel = anaOpt->fParticleIDLabels[pmod];
215  //Association between Tracks and PID
216  art::FindMany<anab::ParticleID> fmpid(trackListHandle, evt, pidlabel);
217  if (!fmpid.isValid()) continue;
218 
219  //Loop over Tracks
220  for (size_t trkIter = 0; trkIter < tracklist.size(); ++trkIter) {
221  if (anaOpt->fTrackID >= 0 and tracklist[trkIter]->ID() != anaOpt->fTrackID) continue;
222  int color = tracklist[trkIter].key() % evd::kNCOLS;
223 
224  std::vector<const anab::Calorimetry*> calos = fmcal.at(trkIter);
225  if (!calos.size()) continue;
226  size_t bestplane = 0;
227  size_t nmaxhits = 0;
228  for (size_t icalo = 0; icalo < calos.size(); ++icalo) {
229  if (calos[icalo]->dEdx().size() > nmaxhits) {
230  nmaxhits = calos[icalo]->dEdx().size();
231  bestplane = icalo;
232  }
233  }
234  if (anaOpt->fCaloPlane >= 0 and anaOpt->fCaloPlane < int(geom->Nplanes())) {
235  for (size_t i = 0; i < geom->Nplanes(); ++i) {
236  if (int(calos[i]->PlaneID().Plane) == anaOpt->fCaloPlane) bestplane = i;
237  }
238  }
239 
240  double xvalue = calos[bestplane]->Range();
241  double yvalue = calos[bestplane]->KineticEnergy();
242  view->AddMarker(xvalue, yvalue, evd::kColor[color], 8, 0.8);
243  if (yvalue > 0.0) {
244  double error = yvalue * (0.6064 / std::sqrt(yvalue));
245  TLine& l = view->AddLine(xvalue, yvalue - error, xvalue, yvalue + error);
246  l.SetLineColor(evd::kColor[color]);
247  }
248  }
249  }
250  }
251  }
252  }
253 
254  //......................................................................
256  {
259 
260  for (size_t imod = 0; imod < recoOpt->fShowerLabels.size(); ++imod) {
261 
262  //Get Track collection
263  art::InputTag which = recoOpt->fShowerLabels[imod];
265  evt.getByLabel(which, caloListHandle);
266  std::vector<art::Ptr<anab::Calorimetry>> calolist;
267  art::fill_ptr_vector(calolist, caloListHandle);
268 
269  //Loop over PID collections
270  for (size_t pmod = 0; pmod < anaOpt->fParticleIDLabels.size(); ++pmod) {
271  std::string const pidlabel = anaOpt->fParticleIDLabels[pmod];
272  //Association between Tracks and PID
273 
274  //Loop over Tracks
275  for (size_t shwIter = 0; shwIter < calolist.size(); ++shwIter) {
276  int color = kRed;
277 
278  TPolyMarker& pm =
279  view->AddPolyMarker((*calolist.at(shwIter)).dEdx().size(), color, 8, 0.8);
280  for (size_t h = 0; h < (*calolist.at(shwIter)).dEdx().size(); ++h) {
281  pm.SetPoint(h,
282  (*calolist.at(shwIter)).ResidualRange().at(h),
283  (*calolist.at(shwIter)).dEdx().at(h));
284  }
285  }
286  }
287  }
288 
289  char mip[80];
290  char mip2[80];
291 
292  sprintf(mip, "1 MIP");
293  sprintf(mip2, "2 MIP");
294  double offset = 0;
295 
296  double MIP = 2.12; // This is one mip in LAr, taken from uboone docdb #414
297  TLine& Line1Mip = view->AddLine(0, MIP, 100, MIP);
298  TLine& Line2Mip = view->AddLine(0, 2 * MIP, 100, 2 * MIP);
299 
300  TLatex& mip_tex = view->AddLatex(40.0, (23.0 - 20.0) - offset, mip);
301  TLatex& mip2_tex = view->AddLatex(40.0, (23.0 - 18.0) - offset, mip2);
302 
303  mip_tex.SetTextColor(kGray + 3);
304  mip2_tex.SetTextColor(kGray + 2);
305  mip_tex.SetTextSize(0.02);
306  mip2_tex.SetTextSize(0.02);
307 
308  Line1Mip.SetLineStyle(kDashed);
309  Line1Mip.SetLineColor(kGray + 3);
310  Line2Mip.SetLineStyle(kDashed);
311  Line2Mip.SetLineColor(kGray + 2);
312  }
313 
314 } // namespace
void DrawDeDx(const art::Event &evt, evdb::View2D *view)
Class to aid in the rendering of AnalysisBase objects.
std::vector< art::InputTag > fTrackLabels
module labels that produced tracks
std::vector< std::string > fParticleIDLabels
module labels that produced particleid
TLine & AddLine(double x1, double y1, double x2, double y2)
Definition: View2D.cxx:187
A collection of drawable 2-D objects.
static const int kNCOLS
Definition: eventdisplay.h:10
IDparameter< geo::PlaneID > PlaneID
Member type of validated geo::PlaneID parameter.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
LArSoft includes.
std::vector< std::string > fCalorimetryLabels
module labels that produced calorimetry
TPolyMarker & AddPolyMarker(int n, int c, int st, double sz)
Definition: View2D.cxx:157
Provides recob::Track data product.
TLatex & AddLatex(double x, double y, const char *text)
Definition: View2D.cxx:308
float dEdx(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, TP3D &tp3d)
Definition: PFPUtils.cxx:2675
static const int kColor[kNCOLS]
Definition: eventdisplay.h:11
std::size_t color(std::string const &procname)
Place to keep constants for event display.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
unsigned int Nplanes(TPCID const &tpcid=tpc_zero) const
Returns the total number of planes in the specified TPC.
Definition: GeometryCore.h:977
std::vector< art::InputTag > fShowerLabels
module labels that produced showers
TCEvent evt
Definition: DataStructs.cxx:8
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:306
void CalorShower(const art::Event &evt, evdb::View2D *view)
recob::tracking::Plane Plane
Definition: TrackState.h:17
void DrawKineticEnergy(const art::Event &evt, evdb::View2D *view)
TMarker & AddMarker(double x, double y, int c, int st, double sz)
Definition: View2D.cxx:124
art framework interface to geometry description