All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRTEventDisplay.cc
Go to the documentation of this file.
1 #include "CRTEventDisplay.h"
2 
3 namespace sbnd{
4 
6 
7  this->reconfigure(config);
8 
9 }
10 
11 
13 
14 }
15 
16 
18 
19 }
20 
21 
23 
24  fSimLabel = config.SimLabel();
25  fCRTDataLabel = config.CRTDataLabel();
26  fCRTHitLabel = config.CRTHitLabel();
27  fCRTTrackLabel = config.CRTTrackLabel();
28  fTPCTrackLabel = config.TPCTrackLabel();
29  fClockSpeedCRT = config.ClockSpeedCRT();
30 
31  fDrawTaggers = config.DrawTaggers();
32  fDrawModules = config.DrawModules();
33  fDrawTpc = config.DrawTpc();
34  fDrawCrtData = config.DrawCrtData();
35  fDrawCrtHits = config.DrawCrtHits();
36  fDrawCrtTracks = config.DrawCrtTracks();
38  fDrawTpcTracks = config.DrawTpcTracks();
40 
41  fTaggerColour = config.TaggerColour();
42  fTpcColour = config.TpcColour();
43  fCrtDataColour = config.CrtDataColour();
44  fCrtHitColour = config.CrtHitColour();
48 
49  fUseTrueID = config.UseTrueID();
50  fTrueID = config.TrueID();
51 
52  fPrint = config.Print();
53 
54  fLineWidth = config.LineWidth();
56  fMinTime = config.MinTime();
57  fMaxTime = config.MaxTime();
58 
59  fCrtBackTrack = config.CrtBackTrack();
60 
61  return;
62 
63 }
64 
66  fDrawTaggers = tf;
67 }
69  fDrawTpc = tf;
70 }
72  fDrawCrtData = tf;
73 }
75  fDrawCrtHits = tf;
76 }
78  fDrawCrtTracks = tf;
79 }
81  fDrawTpcTracks = tf;
82 }
84  fDrawTrueTracks = tf;
85 }
87  fPrint = tf;
88 }
89 
91  fUseTrueID = true;
92  fTrueID = id;
93 }
94 
95 bool CRTEventDisplay::IsVisible(const simb::MCParticle& particle){
96  int pdg = std::abs(particle.PdgCode());
97  double momentum = particle.P();
98  double momLimit = 0.05;
99  if(momentum < momLimit) return false;
100  if(pdg == 13) return true;
101  if(pdg == 11) return true;
102  if(pdg == 2212) return true;
103  if(pdg == 211) return true;
104  if(pdg == 321) return true;
105  return false;
106 }
107 
108 void CRTEventDisplay::DrawCube(TCanvas *c1, double *rmin, double *rmax, int colour){
109 
110  c1->cd();
111  TList *outline = new TList;
112  TPolyLine3D *p1 = new TPolyLine3D(4);
113  TPolyLine3D *p2 = new TPolyLine3D(4);
114  TPolyLine3D *p3 = new TPolyLine3D(4);
115  TPolyLine3D *p4 = new TPolyLine3D(4);
116  p1->SetLineColor(colour);
117  p1->SetLineWidth(fLineWidth);
118  p1->Copy(*p2);
119  p1->Copy(*p3);
120  p1->Copy(*p4);
121  outline->Add(p1);
122  outline->Add(p2);
123  outline->Add(p3);
124  outline->Add(p4);
125  TPolyLine3D::DrawOutlineCube(outline, rmin, rmax);
126  p1->Draw();
127  p2->Draw();
128  p3->Draw();
129  p4->Draw();
130 
131 }
132 
134  const art::Event& event){
135  // Create a canvas
136  TCanvas *c1 = new TCanvas("c1","",700,700);
137 
138  // Draw the CRT taggers
139  if(fDrawTaggers){
140  for(size_t i = 0; i < fCrtGeo.NumTaggers(); i++){
141  double rmin[3] = {fCrtGeo.GetTagger(i).minX,
142  fCrtGeo.GetTagger(i).minY,
143  fCrtGeo.GetTagger(i).minZ};
144  double rmax[3] = {fCrtGeo.GetTagger(i).maxX,
145  fCrtGeo.GetTagger(i).maxY,
146  fCrtGeo.GetTagger(i).maxZ};
147  DrawCube(c1, rmin, rmax, fTaggerColour);
148  }
149  }
150 
151  // Draw individual CRT modules
152  if(fDrawModules){
153  for(size_t i = 0; i < fCrtGeo.NumModules(); i++){
154  double rmin[3] = {fCrtGeo.GetModule(i).minX,
155  fCrtGeo.GetModule(i).minY,
156  fCrtGeo.GetModule(i).minZ};
157  double rmax[3] = {fCrtGeo.GetModule(i).maxX,
158  fCrtGeo.GetModule(i).maxY,
159  fCrtGeo.GetModule(i).maxZ};
160  DrawCube(c1, rmin, rmax, fTaggerColour);
161  }
162  }
163 
164  // Draw the TPC with central cathode
165  if(fDrawTpc){
166  double rmin[3] = {fTpcGeo.MinX(),
167  fTpcGeo.MinY(),
168  fTpcGeo.MinZ()};
169  double rmax[3] = {-fTpcGeo.CpaWidth(),
170  fTpcGeo.MaxY(),
171  fTpcGeo.MaxZ()};
172  DrawCube(c1, rmin, rmax, fTpcColour);
173  double rmin2[3] = {fTpcGeo.CpaWidth(),
174  fTpcGeo.MinY(),
175  fTpcGeo.MinZ()};
176  double rmax2[3] = {fTpcGeo.MaxX(),
177  fTpcGeo.MaxY(),
178  fTpcGeo.MaxZ()};
179  DrawCube(c1, rmin2, rmax2, fTpcColour);
180  }
181 
182  // Draw the CRT data in the event
183  if(fDrawCrtData){
184 
185  if(fPrint) std::cout<<"\nCRT data in event:\n";
186 
187  auto crtDataHandle = event.getValidHandle<std::vector<sbnd::crt::CRTData>>(fCRTDataLabel);
188  //detinfo::DetectorClocks const* fDetectorClocks = lar::providerFrom<detinfo::DetectorClocksService>();
189  //detinfo::ElecClock fTrigClock = fDetectorClocks->TriggerClock();
190  for(auto const& data : (*crtDataHandle)){
191 
192  // Skip if outside specified time window if time window used
193  //fTrigClock.SetTime(data.T0());
194  //double time = fTrigClock.Time();
195  double time = (double)(int)data.T0()/fClockSpeedCRT; // [tick -> us]
196  if(!(fMinTime == fMaxTime || (time > fMinTime && time < fMaxTime))) continue;
197 
198  // Skip if it doesn't match the true ID if true ID is used
199  int trueId = fCrtBackTrack.TrueIdFromTotalEnergy(event, data);
200  if(fUseTrueID && trueId != fTrueID) continue;
201 
202  std::string stripName = fCrtGeo.ChannelToStripName(data.Channel());
203  double rmin[3] = {fCrtGeo.GetStrip(stripName).minX,
204  fCrtGeo.GetStrip(stripName).minY,
205  fCrtGeo.GetStrip(stripName).minZ};
206  double rmax[3] = {fCrtGeo.GetStrip(stripName).maxX,
207  fCrtGeo.GetStrip(stripName).maxY,
208  fCrtGeo.GetStrip(stripName).maxZ};
209  DrawCube(c1, rmin, rmax, fCrtDataColour);
210 
211  if(fPrint) std::cout<<"->True ID: "<<trueId<<", channel = "<<data.Channel()<<", tagger = "
212  <<fCrtGeo.GetModule(fCrtGeo.GetStrip(stripName).module).tagger<<", time = "<<time<<"\n";
213  }
214  }
215 
216  // Draw the CRT hits in the event
217  if(fDrawCrtHits){
218 
219  if(fPrint) std::cout<<"\nCRT hits in event:\n";
220 
221  auto crtHitHandle = event.getValidHandle<std::vector<sbn::crt::CRTHit>>(fCRTHitLabel);
222  for(auto const& hit : (*crtHitHandle)){
223 
224  // Skip if outside specified time window if time window used
225  double time = (double)(int)hit.ts1_ns * 1e-3;
226  if(!(fMinTime == fMaxTime || (time > fMinTime && time < fMaxTime))) continue;
227 
228  // Skip if it doesn't match the true ID if true ID is used
229  int trueId = fCrtBackTrack.TrueIdFromTotalEnergy(event, hit);
230  if(fUseTrueID && trueId != fTrueID) continue;
231 
232  double rmin[3] = {hit.x_pos - hit.x_err,
233  hit.y_pos - hit.y_err,
234  hit.z_pos - hit.z_err};
235  double rmax[3] = {hit.x_pos + hit.x_err,
236  hit.y_pos + hit.y_err,
237  hit.z_pos + hit.z_err};
238  DrawCube(c1, rmin, rmax, fCrtHitColour);
239 
240  if(fPrint) std::cout<<"->True ID: "<<trueId<<", position = ("<<hit.x_pos<<", "
241  <<hit.y_pos<<", "<<hit.z_pos<<"), time = "<<time<<"\n";
242  }
243  }
244 
245  // Draw CRT tracks in the event
246  if(fDrawCrtTracks){
247 
248  if(fPrint) std::cout<<"\nCRT tracks in event:\n";
249 
250  auto crtTrackHandle = event.getValidHandle<std::vector<sbn::crt::CRTTrack>>(fCRTTrackLabel);
251  for(auto const& track : (*crtTrackHandle)){
252 
253  // Skip if outside specified time window if time window used
254  double time = (double)(int)track.ts1_ns * 1e-3;
255  if(!(fMinTime == fMaxTime || (time > fMinTime && time < fMaxTime))) continue;
256 
257  // Skip if it doesn't match the true ID if true ID is used
258  int trueId = fCrtBackTrack.TrueIdFromTotalEnergy(event, track);
259  if(fUseTrueID && trueId != fTrueID) continue;
260 
261  TPolyLine3D *line = new TPolyLine3D(2);
262  line->SetPoint(0, track.x1_pos, track.y1_pos, track.z1_pos);
263  line->SetPoint(1, track.x2_pos, track.y2_pos, track.z2_pos);
264  line->SetLineColor(fCrtTrackColour);
265  line->SetLineWidth(fLineWidth);
266  if(track.complete) line->Draw();
267  else if(fDrawIncompleteTracks){
268  TVector3 start(track.x1_pos, track.y1_pos, track.z1_pos);
269  TVector3 end(track.x2_pos, track.y2_pos, track.z2_pos);
270  if(start.Y() < end.Y()) std::swap(start, end);
271  TVector3 diff = (end - start).Unit();
272  TVector3 newEnd = start + fIncompleteTrackLength * diff;
273  line->SetPoint(0, start.X(), start.Y(), start.Z());
274  line->SetPoint(1, newEnd.X(), newEnd.Y(), newEnd.Z());
275  line->Draw();
276  }
277 
278  if(fPrint) std::cout<<"->True ID: "<<trueId<<", start = ("<<track.x1_pos<<", "
279  <<track.y1_pos<<", "<<track.z1_pos<<"), end = ("<<track.x2_pos
280  <<", "<<track.y2_pos<<", "<<track.z2_pos<<"), time = "<<time<<"\n";
281  }
282  }
283 
284  // Draw reconstructed TPC tracks in the event
285  if(fDrawTpcTracks){
286 
287  if(fPrint) std::cout<<"\nTPC tracks in event:\n";
288 
289  auto tpcTrackHandle = event.getValidHandle<std::vector<recob::Track>>(fTPCTrackLabel);
290  art::FindManyP<recob::Hit> findManyHits(tpcTrackHandle, event, fTPCTrackLabel);
291  for(auto const& track : (*tpcTrackHandle)){
292 
293  // Skip if it doesn't match the true ID if true ID is used
294  std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(track.ID());
295  int trueId = RecoUtils::TrueParticleIDFromTotalRecoHits(clockData, hits, false);
296  if(fUseTrueID && trueId != fTrueID) continue;
297 
298  size_t npts = track.NumberTrajectoryPoints();
299  TPolyLine3D *line = new TPolyLine3D(npts);
300  int ipt = 0;
301  bool first = true;
302  geo::Point_t start {0,0,0};
303  geo::Point_t end {0,0,0};
304  for(size_t i = 0; i < npts; i++){
305  auto& pos = track.LocationAtPoint(i);
306 
307  // Don't draw invalid points
308  if(!track.HasValidPoint(i)) continue;
309  //if(pos.X() == -999 || (pos.X() == 0 && pos.Y() == 0)) continue;
310 
311  if(first){
312  first = false;
313  start = pos;
314  }
315  end = pos;
316 
317  line->SetPoint(ipt, pos.X(), pos.Y(), pos.Z());
318  ipt++;
319  }
320  line->SetLineColor(fTpcTrackColour);
321  line->SetLineWidth(fLineWidth);
322  line->Draw();
323 
324  if(fPrint) std::cout<<"->True ID: "<<trueId<<", start = ("<<start.X()<<", "<<start.Y()<<", "
325  <<start.Z()<<"), end = ("<<end.X()<<", "<<end.Y()<<", "<<end.Z()<<")\n";
326  }
327  }
328 
329  // Draw true track trajectories for visible particles that cross the CRT
330  if(fDrawTrueTracks){
331 
332  if(fPrint) std::cout<<"\nTrue tracks in event:\n";
333 
334  auto particleHandle = event.getValidHandle<std::vector<simb::MCParticle>>(fSimLabel);
335  std::vector<double> crtLims = fCrtGeo.CRTLimits();
336  for(auto const& part : (*particleHandle)){
337 
338  // Skip if it doesn't match the true ID if true ID is used
339  if(fUseTrueID && part.TrackId() != fTrueID) continue;
340 
341  // Skip if outside specified time window if time window used
342  double time = part.T() * 1e-3;
343  if(!(fMinTime == fMaxTime || (time > fMinTime && time < fMaxTime))) continue;
344 
345  // Skip if particle isn't visible
346  if(!IsVisible(part)) continue;
347 
348  // Skip if particle doesn't cross the boundary enclosed by the CRTs
349  if(!fCrtGeo.EntersVolume(part)) continue;
350 
351  size_t npts = part.NumberTrajectoryPoints();
352  TPolyLine3D *line = new TPolyLine3D(npts);
353  int ipt = 0;
354  bool first = true;
355  geo::Point_t start {0,0,0};
356  geo::Point_t end {0,0,0};
357  for(size_t i = 0; i < npts; i++){
358  geo::Point_t pos {part.Vx(i), part.Vy(i), part.Vz(i)};
359 
360  // Don't draw trajectories outside of the CRT volume
361  if(pos.X() < crtLims[0] || pos.X() > crtLims[3] || pos.Y() < crtLims[1]
362  || pos.Y() > crtLims[4] || pos.Z() < crtLims[2] || pos.Z() > crtLims[5]) continue;
363 
364  if(first){
365  first = false;
366  start = pos;
367  }
368  end = pos;
369 
370  line->SetPoint(ipt, pos.X(), pos.Y(), pos.Z());
371  ipt++;
372  }
373  line->SetLineColor(fTrueTrackColour);
374  line->SetLineWidth(fLineWidth);
375  line->Draw();
376 
377  if(fPrint) std::cout<<"->True ID: "<<part.TrackId()<<", start = ("<<start.X()<<", "<<start.Y()<<", "
378  <<start.Z()<<"), end = ("<<end.X()<<", "<<end.Y()<<", "<<end.Z()<<")\n";
379  }
380  }
381 
382  c1->SaveAs("crtEventDisplay.root");
383 
384 }
385 
386 }
art::InputTag fTPCTrackLabel
void Draw(detinfo::DetectorClocksData const &clockData, const art::Event &event)
bool IsVisible(const simb::MCParticle &particle)
fhicl::Atom< bool > DrawTpcTracks
fhicl::Atom< double > IncompleteTrackLength
var pdg
Definition: selectors.fcl:14
fhicl::Atom< int > TpcTrackColour
CRTEventDisplay(const Config &config)
CRTTaggerGeo GetTagger(std::string taggerName) const
fhicl::Atom< double > MinTime
fhicl::Atom< bool > DrawTaggers
fhicl::Atom< int > CrtDataColour
fhicl::Atom< int > TaggerColour
process_name use argoneut_mc_hitfinder track
process_name hit
Definition: cheaterreco.fcl:51
int TrueIdFromTotalEnergy(const art::Event &event, const sbnd::crt::CRTData &data)
fhicl::Atom< int > CrtHitColour
CRTModuleGeo GetModule(std::string moduleName) const
T abs(T value)
fhicl::Atom< bool > DrawCrtTracks
void reconfigure(const Config &config)
fhicl::Atom< int > TrueTrackColour
void DrawCube(TCanvas *c1, double *rmin, double *rmax, int colour)
CRTBackTracker fCrtBackTrack
fhicl::Atom< bool > DrawTpc
std::string ChannelToStripName(size_t channel) const
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
fhicl::Atom< art::InputTag > TPCTrackLabel
fhicl::Atom< art::InputTag > CRTDataLabel
CRTStripGeo GetStrip(std::string stripName) const
fhicl::Atom< bool > DrawTrueTracks
int TrueParticleIDFromTotalRecoHits(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
fhicl::Atom< double > MaxTime
fhicl::Atom< double > LineWidth
fhicl::Atom< art::InputTag > SimLabel
fhicl::Atom< double > ClockSpeedCRT
art::InputTag fCRTTrackLabel
void SetDrawCrtTracks(bool tf)
fhicl::Table< CRTBackTracker::Config > CrtBackTrack
void SetDrawTpcTracks(bool tf)
void SetDrawTaggers(bool tf)
art::InputTag fCRTDataLabel
fhicl::Atom< bool > UseTrueID
Contains all timing reference information for the detector.
void SetDrawTrueTracks(bool tf)
fhicl::Atom< bool > DrawModules
fhicl::Atom< int > CrtTrackColour
art::InputTag fCRTHitLabel
do i e
fhicl::Atom< bool > DrawCrtData
bool EntersVolume(const simb::MCParticle &particle)
stream1 can override from command line with o or output services user sbnd
void SetDrawTpc(bool tf)
void SetDrawCrtHits(bool tf)
fhicl::Atom< bool > DrawIncompleteTracks
fhicl::Atom< art::InputTag > CRTHitLabel
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
fhicl::Atom< bool > DrawCrtHits
void SetDrawCrtData(bool tf)
fhicl::Atom< art::InputTag > CRTTrackLabel
physics associatedGroupsWithLeft p1
BEGIN_PROLOG could also be cout