All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
sbn::TrackCaloSkimmer Class Reference

#include <TrackCaloSkimmer.h>

Inheritance diagram for sbn::TrackCaloSkimmer:

Classes

struct  GlobalTrackInfo
 
struct  Snippet
 

Public Member Functions

 TrackCaloSkimmer (fhicl::ParameterSet const &p)
 
 TrackCaloSkimmer (TrackCaloSkimmer const &)=delete
 
 TrackCaloSkimmer (TrackCaloSkimmer &&)=delete
 
TrackCaloSkimmeroperator= (TrackCaloSkimmer const &)=delete
 
TrackCaloSkimmeroperator= (TrackCaloSkimmer &&)=delete
 
 ~TrackCaloSkimmer ()
 
void analyze (art::Event const &e) override
 
void respondToOpenInputFile (const art::FileBlock &fb) override
 

Private Member Functions

void FillTrack (const recob::Track &track, const recob::PFParticle &pfp, float t0, const std::vector< art::Ptr< recob::Hit >> &hits, const std::vector< const recob::TrackHitMeta * > &thms, const std::vector< art::Ptr< recob::SpacePoint >> &sps, const std::vector< art::Ptr< anab::Calorimetry >> &calo, const std::map< geo::WireID, art::Ptr< raw::RawDigit >> &rawdigits, const std::vector< GlobalTrackInfo > &tracks, const geo::GeometryCore *geo, const detinfo::DetectorClocksData &clock_data, const cheat::BackTrackerService *bt_serv, const sbn::EDet det)
 
void FillTrackDaughterRays (const recob::Track &trk, const recob::PFParticle &pfp, const std::vector< art::Ptr< recob::PFParticle >> &PFParticleList, const art::FindManyP< recob::SpacePoint > &PFParticleSPs)
 
void FillTrackEndHits (const geo::GeometryCore *geometry, const detinfo::DetectorPropertiesData &dprop, const recob::Track &track, const std::vector< art::Ptr< recob::Hit >> &allHits, const art::FindManyP< recob::SpacePoint > &allHitSPs)
 
void FillTrackTruth (const detinfo::DetectorClocksData &clock_data, const std::vector< art::Ptr< recob::Hit >> &trkHits, const std::vector< art::Ptr< simb::MCParticle >> &mcparticles, const std::vector< geo::BoxBoundedGeo > &active_volumes, const std::vector< std::vector< geo::BoxBoundedGeo >> &tpc_volumes, const std::map< int, std::vector< std::pair< geo::WireID, const sim::IDE * >>> id_to_ide_map, const std::map< int, std::vector< art::Ptr< recob::Hit >>> id_to_truehit_map, const detinfo::DetectorPropertiesData &dprop, const geo::GeometryCore *geo)
 
TrackHitInfo MakeHit (const recob::Hit &hit, unsigned hkey, const recob::TrackHitMeta &thm, const recob::Track &trk, const art::Ptr< recob::SpacePoint > &sp, const std::vector< art::Ptr< anab::Calorimetry >> &calo, const geo::GeometryCore *geo, const detinfo::DetectorClocksData &dclock, const cheat::BackTrackerService *bt_serv)
 
void DoTailFit ()
 

Private Attributes

art::InputTag fPFPproducer
 
std::vector< art::InputTag > fT0producers
 
art::InputTag fCALOproducer
 
art::InputTag fTRKproducer
 
art::InputTag fTRKHMproducer
 
art::InputTag fHITproducer
 
std::vector< art::InputTag > fRawDigitproducers
 
std::string fG4producer
 
std::string fSimChannelproducer
 
bool fRequireT0
 
bool fDoTailFit
 
bool fVerbose
 
bool fSilenceMissingDataProducts
 
double fHitRawDigitsTickCollectWidth
 
double fTailFitResidualRange
 
int fHitRawDigitsWireCollectWidth
 
bool fFillTrackEndHits
 
float fTrackEndHitWireBox
 
float fTrackEndHitTimeBox
 
std::vector< std::unique_ptr
< sbn::ITCSSelectionTool > > 
fSelectionTools
 
MetaInfo fMeta
 
std::map< Snippet, int > fSnippetCount
 
std::map< geo::WireID,
std::pair< int, int > > 
fWiresToSave
 
TTree * fTree
 
TrackInfofTrack
 
TFitter fFitExp
 
TFitter fFitConst
 

Detailed Description

Definition at line 73 of file TrackCaloSkimmer.h.

Constructor & Destructor Documentation

sbn::TrackCaloSkimmer::TrackCaloSkimmer ( fhicl::ParameterSet const &  p)
explicit

Definition at line 59 of file TrackCaloSkimmer_module.cc.

60  : EDAnalyzer{p},
61  fFitExp(2),
62  fFitConst(1)
63 {
64  // Grab config
65  fPFPproducer = p.get< art::InputTag > ("PFPproducer","pandoraGausCryo0");
66  fT0producers = p.get< std::vector<art::InputTag> > ("T0producers", {"pandoraGausCryo0"} );
67  fCALOproducer = p.get< art::InputTag > ("CALOproducer");
68  fTRKproducer = p.get< art::InputTag > ("TRKproducer" );
69  fTRKHMproducer= p.get< art::InputTag > ("TRKHMproducer", "");
70  fHITproducer = p.get< art::InputTag > ("HITproducer" );
71  fG4producer = p.get< std::string > ("G4producer" );
72  fSimChannelproducer = p.get< std::string > ("SimChannelproducer" );
73  fRequireT0 = p.get<bool>("RequireT0", false);
74  fDoTailFit = p.get<bool>("DoTailFit", true);
75  fVerbose = p.get<bool>("Verbose", false);
76  fSilenceMissingDataProducts = p.get<bool>("SilenceMissingDataProducts", false);
77  fHitRawDigitsTickCollectWidth = p.get<double>("HitRawDigitsTickCollectWidth", 50.);
78  fHitRawDigitsWireCollectWidth = p.get<int>("HitRawDigitsWireCollectWidth", 5);
79  fTailFitResidualRange = p.get<double>("TailFitResidualRange", 5.);
80  if (fTailFitResidualRange > 10.) {
81  std::cout << "sbn::TrackCaloSkimmer: Bad tail fit residual range config :(" << fTailFitResidualRange << "). Fits will not be meaningful.\n";
82  }
83  fFillTrackEndHits = p.get<bool>("FillTrackEndHits", true);
84  fTrackEndHitWireBox = p.get<float>("TrackEndHitWireBox", 60); // 20 cm
85  fTrackEndHitTimeBox = p.get<float>("TrackEndHitTimeBox", 300); // about 20cm
86 
87  fRawDigitproducers = p.get<std::vector<art::InputTag>>("RawDigitproducers", {});
88 
89  std::vector<fhicl::ParameterSet> selection_tool_configs(p.get<std::vector<fhicl::ParameterSet>>("SelectionTools"), {});
90  for (const fhicl::ParameterSet &p: selection_tool_configs) {
91  fSelectionTools.push_back(art::make_tool<sbn::ITCSSelectionTool>(p));
92  }
93 
94  // Setup meta info
95  fMeta.iproc = -1;
96  fMeta.ifile = -1;
97  const char *process_str = std::getenv("PROCESS");
98  if (process_str) {
99  try {
100  fMeta.iproc = std::stoi(process_str);
101  }
102  catch (...) {}
103  }
104 
105  // Output stuff
106  fTrack = new sbn::TrackInfo();
107 
108  art::ServiceHandle<art::TFileService> tfs;
109  fTree = tfs->make<TTree>("TrackCaloSkim", "Calo Tree");
110  fTree->Branch("trk", &fTrack);
111 }
art::InputTag fHITproducer
int ifile
Index of file into processing.
pdgs p
Definition: selectors.fcl:22
std::vector< art::InputTag > fRawDigitproducers
int iproc
Index of process number into processing (useful for grid)
std::string fSimChannelproducer
art::InputTag fPFPproducer
art::InputTag fTRKproducer
art::InputTag fCALOproducer
art::InputTag fTRKHMproducer
std::vector< art::InputTag > fT0producers
art::ServiceHandle< art::TFileService > tfs
std::vector< std::unique_ptr< sbn::ITCSSelectionTool > > fSelectionTools
BEGIN_PROLOG could also be cout
sbn::TrackCaloSkimmer::TrackCaloSkimmer ( TrackCaloSkimmer const &  )
delete
sbn::TrackCaloSkimmer::TrackCaloSkimmer ( TrackCaloSkimmer &&  )
delete
sbn::TrackCaloSkimmer::~TrackCaloSkimmer ( )

Definition at line 55 of file TrackCaloSkimmer_module.cc.

55  {
56  delete fTrack;
57 }

Member Function Documentation

void sbn::TrackCaloSkimmer::analyze ( art::Event const &  e)
override

Definition at line 113 of file TrackCaloSkimmer_module.cc.

114 {
115  unsigned evt = e.event();
116  unsigned sub = e.subRun();
117  unsigned run = e.run();
118  if (fVerbose) {
119  std::cout << "[TrackCaloSkimmer::analyzeEvent] Run: " << run << ", SubRun: " << sub << ", Event: "<< evt << ", Is Data: " << e.isRealData() << std::endl;
120  }
121 
122  fMeta.evt = evt;
123  fMeta.subrun = sub;
124  fMeta.run = run;
125  fMeta.time = e.time().value();
126 
127  // Services
128  const geo::GeometryCore *geometry = lar::providerFrom<geo::Geometry>();
129  auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
130  auto const dprop =
131  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e, clock_data);
132 
133  // Identify which detector: can only detect either sbnd or icarus
134 
135  std::string gdml = geometry->GDMLFile();
136  gdml = basename(gdml.c_str());
137 
138  for(unsigned int i = 0; i <gdml.size(); ++i) gdml[i] = std::tolower(gdml[i]);
139 
140  EDet det = kNOTDEFINED;
141 
142  const bool hasSBND = ((gdml.find("sbnd") != std::string::npos) ||
143  (geometry->DetectorName().find("sbnd") != std::string::npos));
144 
145  const bool hasICARUS = ((gdml.find("icarus") != std::string::npos) ||
146  (geometry->DetectorName().find("icarus") != std::string::npos));
147 
148  if(hasSBND == hasICARUS) {
149  std::cout << "TrackCaloSkimmer: Unable to automatically determine either SBND or ICARUS!" << std::endl;
150  abort();
151  }
152 
153  if(hasSBND) det = kSBND;
154  if(hasICARUS) det = kICARUS;
155 
156  // Setup the volumes
157  std::vector<std::vector<geo::BoxBoundedGeo>> TPCVols;
158  std::vector<geo::BoxBoundedGeo> AVs;
159 
160  // First the TPC
161  for (auto const &cryo: geometry->IterateCryostats()) {
162  geo::GeometryCore::TPC_iterator iTPC = geometry->begin_TPC(cryo.ID()),
163  tend = geometry->end_TPC(cryo.ID());
164  std::vector<geo::BoxBoundedGeo> this_tpc_volumes;
165  while (iTPC != tend) {
166  geo::TPCGeo const& TPC = *iTPC;
167  this_tpc_volumes.push_back(TPC.ActiveBoundingBox());
168  iTPC++;
169  }
170  TPCVols.push_back(std::move(this_tpc_volumes));
171  }
172 
173  for (const std::vector<geo::BoxBoundedGeo> &tpcs: TPCVols) {
174  double XMin = std::min_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MinX() < rhs.MinX(); })->MinX();
175  double YMin = std::min_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MinY() < rhs.MinY(); })->MinY();
176  double ZMin = std::min_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MinZ() < rhs.MinZ(); })->MinZ();
177 
178  double XMax = std::max_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MaxX() < rhs.MaxX(); })->MaxX();
179  double YMax = std::max_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MaxY() < rhs.MaxY(); })->MaxY();
180  double ZMax = std::max_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MaxZ() < rhs.MaxZ(); })->MaxZ();
181 
182  AVs.emplace_back(XMin, XMax, YMin, YMax, ZMin, ZMax);
183  }
184 
185  // Truth information
186  std::vector<art::Ptr<simb::MCParticle>> mcparticles;
187  if (fG4producer.size()) {
188  art::ValidHandle<std::vector<simb::MCParticle>> mcparticle_handle = e.getValidHandle<std::vector<simb::MCParticle>>(fG4producer);
189  art::fill_ptr_vector(mcparticles, mcparticle_handle);
190  }
191 
192  std::vector<art::Ptr<sim::SimChannel>> simchannels;
193  if (fSimChannelproducer.size()) {
194  art::ValidHandle<std::vector<sim::SimChannel>> simchannel_handle = e.getValidHandle<std::vector<sim::SimChannel>>(fSimChannelproducer);
195  art::fill_ptr_vector(simchannels, simchannel_handle);
196  }
197 
198  // Reconstructed Information
199  std::vector<art::Ptr<recob::PFParticle>> PFParticleList;
200  try {
201  art::ValidHandle<std::vector<recob::PFParticle>> pfparticles = e.getValidHandle<std::vector<recob::PFParticle>>(fPFPproducer);
202  art::fill_ptr_vector(PFParticleList, pfparticles);
203  }
204  catch(...) {
205  std::cout << "PFP's with tag: " << fPFPproducer << " not present.\n";
206  // Real data may have missing products -- just ignore the event
207  if (fSilenceMissingDataProducts) return;
208  else throw;
209  }
210 
211  // PFP-associated data
212  std::vector<art::FindManyP<anab::T0>> fmT0;
213  for (unsigned i_label = 0; i_label < fT0producers.size(); i_label++) {
214  fmT0.emplace_back(PFParticleList, e, fT0producers[i_label]);
215  }
216  art::FindManyP<recob::SpacePoint> PFParticleSPs(PFParticleList, e, fPFPproducer);
217 
218  // Now we don't need to guard access to further data. If this is an empty event it should be caught by PFP's or Hit's
219  art::ValidHandle<std::vector<recob::Track>> tracks = e.getValidHandle<std::vector<recob::Track>>(fTRKproducer);
220 
221  // Track - associated data
222  art::FindManyP<recob::Track> fmTracks(PFParticleList, e, fTRKproducer);
223 
224  art::InputTag thm_label = fTRKHMproducer.empty() ? fTRKproducer : fTRKHMproducer;
225  art::FindManyP<recob::Hit, recob::TrackHitMeta> fmtrkHits(tracks, e, thm_label);
226  art::FindManyP<anab::Calorimetry> fmCalo(tracks, e, fCALOproducer);
227 
228  // Collect raw digits for saving hits
229  std::vector<art::Ptr<raw::RawDigit>> rawdigitlist;
230  for (const art::InputTag &t: fRawDigitproducers) {
231  art::ValidHandle<std::vector<raw::RawDigit>> thisdigits = e.getValidHandle<std::vector<raw::RawDigit>>(t);
232  art::fill_ptr_vector(rawdigitlist, thisdigits);
233  }
234 
235  // The raw digit list is not sorted, so make it into a map on the WireID
236  std::map<geo::WireID, art::Ptr<raw::RawDigit>> rawdigits;
237  for (const art::Ptr<raw::RawDigit> &d: rawdigitlist) {
238 
239  std::vector<geo::WireID> wids;
240  // Handle bad channel ID
241  try {
242  wids = geometry->ChannelToWire(d->Channel());
243  }
244  catch(...) {
245  continue;
246  }
247 
248  // Ignore channel with no mapped wire
249  if (wids.size() == 0) continue;
250 
251  // Ignore wires that are already mapped
252  if (rawdigits.count(wids[0])) continue;
253 
254  rawdigits[wids[0]] = d;
255  }
256 
257  // Collect all hits
258  art::ValidHandle<std::vector<recob::Hit>> allhit_handle = e.getValidHandle<std::vector<recob::Hit>>(fHITproducer);
259  std::vector<art::Ptr<recob::Hit>> allHits;
260  art::fill_ptr_vector(allHits, allhit_handle);
261 
262  // And lookup the SP's
263  art::FindManyP<recob::SpacePoint> allHitSPs(allHits, e, fPFPproducer);
264 
265  // Prep truth-to-reco-matching info
266  //
267  // Use helper functions from CAFMaker/FillTrue
268  std::map<int, std::vector<std::pair<geo::WireID, const sim::IDE*>>> id_to_ide_map;
269  std::map<int, std::vector<art::Ptr<recob::Hit>>> id_to_truehit_map;
270  const cheat::BackTrackerService *bt = NULL;
271 
272  if (simchannels.size()) {
273  art::ServiceHandle<cheat::BackTrackerService> bt_serv;
274  id_to_ide_map = caf::PrepSimChannels(simchannels, *geometry);
275  id_to_truehit_map = caf::PrepTrueHits(allHits, clock_data, *bt_serv.get());
276  bt = bt_serv.get();
277  }
278 
279  // service data
280 
281  // Build global track info
282  std::vector<GlobalTrackInfo> track_infos;
283  for (const recob::Track &t: *tracks) {
284  track_infos.push_back({
285  t.Start(), t.End(), t.StartDirection(), t.EndDirection(), t.ID()
286  });
287  }
288 
289  for (art::Ptr<recob::PFParticle> p_pfp: PFParticleList) {
290  const recob::PFParticle &pfp = *p_pfp;
291 
292  const std::vector<art::Ptr<recob::Track>> thisTrack = fmTracks.at(p_pfp.key());
293  if (thisTrack.size() != 1)
294  continue;
295 
296  art::Ptr<recob::Track> trkPtr = thisTrack.at(0);
297 
298  std::vector<art::Ptr<anab::Calorimetry>> emptyCaloVector;
299  const std::vector<art::Ptr<anab::Calorimetry>> &calo = fmCalo.isValid() ? fmCalo.at(trkPtr.key()) : emptyCaloVector;
300 
301  std::vector<art::Ptr<recob::Hit>> emptyHitVector;
302  const std::vector<art::Ptr<recob::Hit>> &trkHits = fmtrkHits.isValid() ? fmtrkHits.at(trkPtr.key()) : emptyHitVector;
303 
304  art::FindManyP<recob::SpacePoint> fmtrkHitSPs(trkHits, e, fPFPproducer);
305 
306  std::vector<const recob::TrackHitMeta*> emptyTHMVector;
307  const std::vector<const recob::TrackHitMeta*> &trkHitMetas = fmtrkHits.isValid() ? fmtrkHits.data(trkPtr.key()) : emptyTHMVector;
308 
309  art::Ptr<recob::SpacePoint> nullSP;
310  std::vector<art::Ptr<recob::SpacePoint>> trkHitSPs;
311  if (fmtrkHitSPs.isValid()) {
312  for (unsigned i_hit = 0; i_hit < trkHits.size(); i_hit++) {
313  const std::vector<art::Ptr<recob::SpacePoint>> &h_sp = fmtrkHitSPs.at(i_hit);
314  if (h_sp.size()) {
315  trkHitSPs.push_back(h_sp.at(0));
316  }
317  else {
318  trkHitSPs.push_back(nullSP);
319  }
320  }
321  }
322 
323  int whicht0 = -1;
324  float t0 = std::numeric_limits<float>::signaling_NaN();
325  for (unsigned i_t0 = 0; i_t0 < fmT0.size(); i_t0++) {
326  if (fmT0[i_t0].isValid() && fmT0[i_t0].at(p_pfp.key()).size()) {
327  t0 = fmT0[i_t0].at(p_pfp.key()).at(0)->Time();
328  whicht0 = i_t0;
329 
330  if (fVerbose) std::cout << "Track: " << trkPtr->ID() << " Has T0 (" << fT0producers[i_t0] << ")\n";
331 
332  break;
333  }
334  }
335 
336  if (fRequireT0 && whicht0 < 0) {
337  continue;
338  }
339 
340  if (fVerbose) std::cout << "Processing new track! ID: " << trkPtr->ID() << " time: " << t0 << std::endl;
341 
342  // Reset the track object
343  *fTrack = sbn::TrackInfo();
344 
345  // Reset other persistent info
346  fSnippetCount.clear();
347  fWiresToSave.clear();
348 
349  // Fill the track!
350  FillTrack(*trkPtr, pfp, t0, trkHits, trkHitMetas, trkHitSPs, calo, rawdigits, track_infos, geometry, clock_data, bt, det);
351  fTrack->whicht0 = whicht0;
352 
353  FillTrackDaughterRays(*trkPtr, pfp, PFParticleList, PFParticleSPs);
354 
355  if (fFillTrackEndHits) FillTrackEndHits(geometry, dprop, *trkPtr, allHits, allHitSPs);
356 
357  // Fill the truth information if configured
358  if (simchannels.size()) FillTrackTruth(clock_data, trkHits, mcparticles, AVs, TPCVols, id_to_ide_map, id_to_truehit_map, dprop, geometry);
359 
360  // Save?
361  bool select = false;
362  if (!fSelectionTools.size()) select = true;
363 
364  // Take the OR of each selection tool
365  int i_select = 0;
366  for (const std::unique_ptr<sbn::ITCSSelectionTool> &t: fSelectionTools) {
367  if (t->DoSelect(*fTrack)) {
368  select = true;
369  fTrack->selected = i_select;
370  fTrack->nprescale = t->GetPrescale();
371  break;
372  }
373  i_select ++;
374  }
375 
376  // Save!
377  if (select) {
378  if (fVerbose) std::cout << "Track Selected! By tool: " << i_select << std::endl;
379  fTree->Fill();
380  }
381  }
382 }
std::map< int, std::vector< std::pair< geo::WireID, const sim::IDE * > > > PrepSimChannels(const std::vector< art::Ptr< sim::SimChannel >> &simchannels, const geo::GeometryCore &geo)
Definition: FillTrue.cxx:685
std::map< geo::WireID, std::pair< int, int > > fWiresToSave
art::InputTag fHITproducer
int nprescale
Prescale of the tool that selected this track.
ClusterModuleLabel join with tracks
int subrun
Subrun number.
const geo::GeometryCore * geometry
std::map< Snippet, int > fSnippetCount
void FillTrackEndHits(const geo::GeometryCore *geometry, const detinfo::DetectorPropertiesData &dprop, const recob::Track &track, const std::vector< art::Ptr< recob::Hit >> &allHits, const art::FindManyP< recob::SpacePoint > &allHitSPs)
Geometry information for a single TPC.
Definition: TPCGeo.h:38
geo::BoxBoundedGeo const & ActiveBoundingBox() const
Returns the box of the active volume of this TPC.
Definition: TPCGeo.h:320
std::vector< art::InputTag > fRawDigitproducers
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
void FillTrackDaughterRays(const recob::Track &trk, const recob::PFParticle &pfp, const std::vector< art::Ptr< recob::PFParticle >> &PFParticleList, const art::FindManyP< recob::SpacePoint > &PFParticleSPs)
int whicht0
Which T0 producer was used to tag.
BEGIN_PROLOG TPC
void FillTrackTruth(const detinfo::DetectorClocksData &clock_data, const std::vector< art::Ptr< recob::Hit >> &trkHits, const std::vector< art::Ptr< simb::MCParticle >> &mcparticles, const std::vector< geo::BoxBoundedGeo > &active_volumes, const std::vector< std::vector< geo::BoxBoundedGeo >> &tpc_volumes, const std::map< int, std::vector< std::pair< geo::WireID, const sim::IDE * >>> id_to_ide_map, const std::map< int, std::vector< art::Ptr< recob::Hit >>> id_to_truehit_map, const detinfo::DetectorPropertiesData &dprop, const geo::GeometryCore *geo)
TPC_iterator begin_TPC() const
Returns an iterator pointing to the first TPC in the detector.
process_name can override from command line with o or output calo
Definition: pid.fcl:40
std::string GDMLFile() const
Returns the full directory path to the GDML file source.
void FillTrack(const recob::Track &track, const recob::PFParticle &pfp, float t0, const std::vector< art::Ptr< recob::Hit >> &hits, const std::vector< const recob::TrackHitMeta * > &thms, const std::vector< art::Ptr< recob::SpacePoint >> &sps, const std::vector< art::Ptr< anab::Calorimetry >> &calo, const std::map< geo::WireID, art::Ptr< raw::RawDigit >> &rawdigits, const std::vector< GlobalTrackInfo > &tracks, const geo::GeometryCore *geo, const detinfo::DetectorClocksData &clock_data, const cheat::BackTrackerService *bt_serv, const sbn::EDet det)
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
std::string fSimChannelproducer
art::InputTag fPFPproducer
int run
Run number.
art::InputTag fTRKproducer
Description of geometry of one entire detector.
uint64_t time
Timestamp.
IteratorBox< cryostat_iterator,&GeometryCore::begin_cryostat,&GeometryCore::end_cryostat > IterateCryostats() const
Enables ranged-for loops on all cryostats of the detector.
Hierarchical representation of particle flow.
Definition: PFParticle.h:44
int selected
Index of the tool that selected this track.
std::map< int, std::vector< art::Ptr< recob::Hit > > > PrepTrueHits(const std::vector< art::Ptr< recob::Hit >> &allHits, const detinfo::DetectorClocksData &clockData, const cheat::BackTrackerService &backtracker)
Definition: FillTrue.cxx:674
do i e
art::InputTag fCALOproducer
art::InputTag fTRKHMproducer
std::vector< art::InputTag > fT0producers
TCEvent evt
Definition: DataStructs.cxx:8
std::vector< std::unique_ptr< sbn::ITCSSelectionTool > > fSelectionTools
Forward iterator browsing all geometry elements in the detector.
Definition: GeometryCore.h:727
int evt
Event number.
BEGIN_PROLOG could also be cout
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a &quot;fitted&quot; track:
TPC_iterator end_TPC() const
Returns an iterator pointing after the last TPC in the detector.
std::string sub(const std::string &a, const std::string &b)
Definition: TruthText.cxx:100
void sbn::TrackCaloSkimmer::DoTailFit ( )
private

Definition at line 1114 of file TrackCaloSkimmer_module.cc.

1114  {
1115  // Try fitting the constant and exponentials to the tail of dQ/dx v. RR on the collection plane
1116  std::vector<double> fit_rr;
1117  std::vector<double> fit_dqdx;
1118 
1119  for (const TrackHitInfo &h: fTrack->hits2) {
1120  if (h.oncalo && h.rr > 0. && h.rr < fTailFitResidualRange) {
1121  fit_rr.push_back(h.rr);
1122  fit_dqdx.push_back(h.dqdx);
1123  }
1124  }
1125 
1126  // TODO: should we throw an exception here??
1127  //
1128  // If there is too much data to fit in the array, throw exception
1129  if (fit_rr.size() > MAX_N_FIT_DATA) {
1130  throw cet::exception("sbn::TrackCaloSkimmer::DoTailFit: More fitting points required ("
1131  + std::to_string(fit_rr.size()) + ") than available in fit array (" + std::to_string(MAX_N_FIT_DATA) + ").\n");
1132  }
1133 
1134  // Copy the fit data to the global array
1135  for (unsigned i = 0; i < fit_rr.size() && i < MAX_N_FIT_DATA; i++) {
1136  FIT_RR[i] = fit_rr[i];
1137  FIT_DQDX[i] = fit_dqdx[i];
1138  }
1139  N_FIT_DATA = std::min(fit_rr.size(), MAX_N_FIT_DATA);
1140 
1142  if (fTrack->n_fit_point > 2) { // need more points than params
1143  // Fit the Exponential
1144  fFitExp.SetFCN(ExpResiduals);
1145  fFitExp.SetParameter(0, "A", *std::max_element(fit_dqdx.begin(), fit_dqdx.end()), 200, 0, 5000);
1146  fFitExp.SetParameter(1, "R", 10., 0.5, 0, 1000);
1147  fFitExp.ExecuteCommand("MIGRAD", 0, 0);
1148 
1149  double A = fFitExp.GetParameter(0);
1150  double R = fFitExp.GetParameter(1);
1151 
1152  int nparam;
1153  double param[2] {A, R};
1154  double residuals = -1;
1155  ExpResiduals(nparam, NULL, residuals, param, 0);
1156 
1157  fTrack->exp_fit_A = A;
1158  fTrack->exp_fit_R = R;
1159  fTrack->exp_fit_residuals = residuals;
1160 
1161  // Fit the Constant
1162  fFitConst.SetFCN(ConstResiduals);
1163  fFitConst.SetParameter(0, "C", std::accumulate(fit_dqdx.begin(), fit_dqdx.end(), 0.), 200, 0, 5000);
1164  fFitConst.ExecuteCommand("MIGRAD", 0, 0);
1165 
1166  double C = fFitConst.GetParameter(0);
1167 
1168  double cresiduals = -1;
1169  ConstResiduals(nparam, NULL, cresiduals, &C, 0);
1170 
1171  fTrack->const_fit_C = C;
1172  fTrack->const_fit_residuals = cresiduals;
1173  }
1174 }
static double FIT_RR[MAX_N_FIT_DATA]
void ConstResiduals(int &npar, double *g, double &result, double *par, int flag)
float const_fit_C
Fit parameter.
float exp_fit_A
Fit parameter.
int n_fit_point
Fit parameter.
void ExpResiduals(int &npar, double *g, double &result, double *par, int flag)
while getopts h
const size_t MAX_N_FIT_DATA
static double FIT_DQDX[MAX_N_FIT_DATA]
float const_fit_residuals
Fit parameter.
static int N_FIT_DATA
float exp_fit_residuals
Fit parameter.
std::string to_string(WindowPattern const &pattern)
std::vector< TrackHitInfo > hits2
List of hits on plane 2.
float A
Definition: dedx.py:137
float exp_fit_R
Fit parameter.
void sbn::TrackCaloSkimmer::FillTrack ( const recob::Track track,
const recob::PFParticle pfp,
float  t0,
const std::vector< art::Ptr< recob::Hit >> &  hits,
const std::vector< const recob::TrackHitMeta * > &  thms,
const std::vector< art::Ptr< recob::SpacePoint >> &  sps,
const std::vector< art::Ptr< anab::Calorimetry >> &  calo,
const std::map< geo::WireID, art::Ptr< raw::RawDigit >> &  rawdigits,
const std::vector< GlobalTrackInfo > &  tracks,
const geo::GeometryCore geo,
const detinfo::DetectorClocksData clock_data,
const cheat::BackTrackerService bt_serv,
const sbn::EDet  det 
)
private

Definition at line 985 of file TrackCaloSkimmer_module.cc.

996  {
997 
998  // Fill top level stuff
999  fTrack->meta = fMeta;
1000  fTrack->t0 = t0;
1001  fTrack->id = track.ID();
1003 
1004  fTrack->length = track.Length();
1005  fTrack->start.x = track.Start().X();
1006  fTrack->start.y = track.Start().Y();
1007  fTrack->start.z = track.Start().Z();
1008  fTrack->end.x = track.End().X();
1009  fTrack->end.y = track.End().Y();
1010  fTrack->end.z = track.End().Z();
1011  fTrack->dir.x = track.StartDirection().X();
1012  fTrack->dir.y = track.StartDirection().Y();
1013  fTrack->dir.z = track.StartDirection().Z();
1014 
1015  if (hits.size() > 0) {
1016  fTrack->cryostat = hits[0]->WireID().Cryostat;
1017  }
1018 
1019  // Fill each hit
1020  for (unsigned i_hit = 0; i_hit < hits.size(); i_hit++) {
1021  sbn::TrackHitInfo hinfo = MakeHit(*hits[i_hit], hits[i_hit].key(), *thms[i_hit], track, sps[i_hit], calo, geo, clock_data, bt_serv);
1022  if (hinfo.h.plane == 0) {
1023  fTrack->hits0.push_back(hinfo);
1024  }
1025  else if (hinfo.h.plane == 1) {
1026  fTrack->hits1.push_back(hinfo);
1027  }
1028  else if (hinfo.h.plane == 2) {
1029  fTrack->hits2.push_back(hinfo);
1030  }
1031  }
1032 
1033  // Hit summary info
1046 
1047  // Save information on a fit to the end of the track
1048  if (fDoTailFit) DoTailFit();
1049 
1050  // Save the Wire ADC values we need to
1051  for (auto const &w_pair: fWiresToSave) {
1052  geo::WireID wire = w_pair.first;
1053 
1054  if (rawdigits.count(wire)) {
1055  const raw::RawDigit &thisdigit = *rawdigits.at(wire);
1056  int min_tick = std::max(0, w_pair.second.first);
1057  int max_tick = std::min((int)thisdigit.NADC(), w_pair.second.second);
1058 
1059  // collect the adcs
1060  std::vector<short> adcs;
1061  for (int t = min_tick; t < max_tick; t++) {
1062  adcs.push_back(thisdigit.ADC(t));
1063  }
1064 
1065  WireInfo winfo;
1066  winfo.wire = wire.Wire;
1067  winfo.plane = wire.Plane;
1068  winfo.tpc = wire.TPC;
1069  winfo.channel = geo->PlaneWireToChannel(wire);
1070  winfo.tdc0 = min_tick;
1071  winfo.adcs = adcs;
1072 
1073  if (winfo.plane == 0) {
1074  fTrack->wires0.push_back(winfo);
1075  }
1076  else if (winfo.plane == 1) {
1077  fTrack->wires1.push_back(winfo);
1078  }
1079  else if (winfo.plane == 2) {
1080  fTrack->wires2.push_back(winfo);
1081  }
1082  }
1083  }
1084  // Sort the ADC values by wire
1085  std::sort(fTrack->wires0.begin(), fTrack->wires0.end(), [](auto const &lhs, auto const &rhs) {return lhs.wire < rhs.wire;});
1086  std::sort(fTrack->wires1.begin(), fTrack->wires1.end(), [](auto const &lhs, auto const &rhs) {return lhs.wire < rhs.wire;});
1087  std::sort(fTrack->wires2.begin(), fTrack->wires2.end(), [](auto const &lhs, auto const &rhs) {return lhs.wire < rhs.wire;});
1088 
1089  // get information on nearby tracks
1090  for (const GlobalTrackInfo &othr: tracks) {
1091  if (othr.ID == track.ID()) continue;
1092 
1093  if ((track.End() - othr.start).r() < 50. || (track.End() - othr.end).r() < 50.) {
1094  fTrack->tracks_near_end_dist.push_back(std::min((track.End() - othr.start).r(), (track.End() - othr.end).r()));
1095  fTrack->tracks_near_end_costh.push_back(
1096  (track.End() - othr.start).r() < (track.End() - othr.end).r() ?
1097  track.EndDirection().Dot(othr.dir) : track.EndDirection().Dot(othr.enddir));
1098  }
1099  }
1100 
1101  for (const GlobalTrackInfo &othr: tracks) {
1102  if (othr.ID == track.ID()) continue;
1103 
1104  if ((track.Start() - othr.start).r() < 50. || (track.Start() - othr.end).r() < 50.) {
1105  fTrack->tracks_near_start_dist.push_back(std::min((track.Start() - othr.start).r(), (track.Start() - othr.end).r()));
1106  fTrack->tracks_near_start_costh.push_back(
1107  (track.Start() - othr.start).r() < (track.Start() - othr.end).r() ?
1108  track.StartDirection().Dot(othr.dir) : track.StartDirection().Dot(othr.enddir));
1109  }
1110  }
1111 
1112 }
std::vector< float > tracks_near_start_costh
List of tracks near the start of this track.
float hit_max_time_p1_tpcE
Max hit time of track on plane 1 TPC E.
float hit_max_time_p2_tpcE
Max hit time of track on plane 2 TPC E.
std::map< geo::WireID, std::pair< int, int > > fWiresToSave
float hit_max_time_p1_tpcW
Max hit time of track on plane 1 TPC W.
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
short ADC(int i) const
ADC vector element number i; no decompression is applied.
Definition: RawDigit.h:208
static constexpr size_t kPFParticlePrimary
Define index to signify primary particle.
Definition: PFParticle.h:61
HitInfo h
Hit information by itself.
float length
Length of track [cm].
std::vector< WireInfo > wires1
List of wire information on plane 1.
std::vector< float > tracks_near_end_dist
List of tracks near the end of this track.
float HitMinTime(const std::vector< sbn::TrackHitInfo > &hits, bool TPCE, sbn::EDet det)
float hit_min_time_p2_tpcE
Min hit time of track on plane 2 TPC E.
float hit_min_time_p0_tpcW
Min hit time of track on plane 0 TPC W.
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:580
Vector3D end
End position of track [cm].
uint16_t plane
Plane number of hit.
int cryostat
Cryostat number of track.
std::vector< float > tracks_near_start_dist
List of tracks near the start of this track.
float hit_max_time_p0_tpcW
Max hit time of track on plane 0 TPC W.
bool clear_cosmic_muon
Whether Pandora thinks the track is &quot;clearly&quot; a cosmic.
Vector3D start
Start position of track [cm].
MetaInfo meta
Meta-data associated with this track.
TrackHitInfo MakeHit(const recob::Hit &hit, unsigned hkey, const recob::TrackHitMeta &thm, const recob::Track &trk, const art::Ptr< recob::SpacePoint > &sp, const std::vector< art::Ptr< anab::Calorimetry >> &calo, const geo::GeometryCore *geo, const detinfo::DetectorClocksData &dclock, const cheat::BackTrackerService *bt_serv)
Vector_t StartDirection() const
Access to track direction at different points.
double Length(size_t p=0) const
Access to various track properties.
std::vector< WireInfo > wires0
List of wire information on plane 0.
Point_t const & Start() const
Access to track position at different points.
size_t Parent() const
Definition: PFParticle.h:96
int id
ID of track.
std::vector< TrackHitInfo > hits1
List of hits on plane 1.
size_t NADC() const
Number of elements in the compressed ADC sample vector.
Definition: RawDigit.h:207
float hit_min_time_p0_tpcE
Min hit time of track on plane 0 TPC E.
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
std::vector< WireInfo > wires2
List of wire information on plane 2.
float hit_min_time_p1_tpcE
Min hit time of track on plane 1 TPC E.
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
float hit_min_time_p1_tpcW
Min hit time of track on plane 1 TPC W.
float HitMaxTime(const std::vector< sbn::TrackHitInfo > &hits, bool TPCE, sbn::EDet det)
float hit_min_time_p2_tpcW
Min hit time of track on plane 2 TPC W.
std::vector< TrackHitInfo > hits0
List of hits on plane 0.
float t0
T0 of track [us].
Vector_t EndDirection() const
float hit_max_time_p0_tpcE
Max hit time of track on plane 0 TPC E.
std::vector< TrackHitInfo > hits2
List of hits on plane 2.
Point_t const & End() const
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406
std::vector< float > tracks_near_end_costh
List of tracks near the end of this track.
Vector3D dir
Direction of track.
esac echo uname r
float hit_max_time_p2_tpcW
Max hit time of track on plane 2 TPC W.
void sbn::TrackCaloSkimmer::FillTrackDaughterRays ( const recob::Track trk,
const recob::PFParticle pfp,
const std::vector< art::Ptr< recob::PFParticle >> &  PFParticleList,
const art::FindManyP< recob::SpacePoint > &  PFParticleSPs 
)
private

Definition at line 960 of file TrackCaloSkimmer_module.cc.

963  {
964 
965  for (unsigned d: pfp.Daughters()) {
966  const recob::PFParticle &d_pfp = *PFParticleList[d];
967 
968  fTrack->daughter_pdg.push_back(d_pfp.PdgCode());
969 
970  unsigned nsp = 0;
971  float min_distance = -1.;
972  for (const art::Ptr<recob::SpacePoint> &sp: PFParticleSPs.at(d)) {
973  if (min_distance < 0. || (sp->position() - trk.End()).r() < min_distance) {
974  min_distance = (sp->position() - trk.End()).r();
975  }
976  nsp++;
977  }
978 
979  fTrack->daughter_sp_toend_dist.push_back(min_distance);
980  fTrack->daughter_nsp.push_back(nsp);
981  }
982 
983 }
const std::vector< size_t > & Daughters() const
Returns the collection of daughter particles.
Definition: PFParticle.h:114
int PdgCode() const
Return the type of particle as a PDG ID.
Definition: PFParticle.h:83
std::vector< int > daughter_pdg
Pandora PDG codes of daughter PFP&#39;s.
std::vector< unsigned > daughter_nsp
Number of space points in each daughter.
std::vector< float > daughter_sp_toend_dist
Smallest distance from any daughter Space Point to Track End [cm].
Hierarchical representation of particle flow.
Definition: PFParticle.h:44
Point_t const & End() const
esac echo uname r
void sbn::TrackCaloSkimmer::FillTrackEndHits ( const geo::GeometryCore geometry,
const detinfo::DetectorPropertiesData dprop,
const recob::Track track,
const std::vector< art::Ptr< recob::Hit >> &  allHits,
const art::FindManyP< recob::SpacePoint > &  allHitSPs 
)
private

Definition at line 835 of file TrackCaloSkimmer_module.cc.

839  {
840 
841  (void) dprop; // TODO: use??
842 
843  geo::TPCID tpc_end = geometry->FindTPCAtPosition(track.End());
844  if (!tpc_end) return;
845 
846  geo::PlaneID plane_end(tpc_end, 2 /* collection */);
847 
848  float end_w = geometry->WireCoordinate(track.End(), plane_end);
849 
850  float end_t = -1000.;
851  float closest_wire_dist = -1.;
852  // Get the hit closest to the end to get the end time
853  for (const TrackHitInfo &h: fTrack->hits2) {
854  if (h.oncalo && (closest_wire_dist < 0. || abs(h.h.wire - end_w) < closest_wire_dist)) {
855  closest_wire_dist = abs(h.h.wire - end_w);
856  end_t = h.h.time;
857  }
858  }
859 
860  for (const art::Ptr<recob::Hit> &hit: allHits) {
861  geo::PlaneID h_p = hit->WireID();
862  if (h_p != plane_end) continue;
863 
864  // Inside the box?
865  float h_w = (float)hit->WireID().Wire;
866  float h_t = hit->PeakTime();
867 
868  if (abs(h_w - end_w) < fTrackEndHitWireBox &&
869  abs(h_t - end_t) < fTrackEndHitTimeBox) {
870 
871  // HitInfo to save
872  sbn::HitInfo hinfo;
873 
874  // information from the hit object
875  hinfo.integral = hit->Integral();
876  hinfo.sumadc = hit->SummedADC();
877  hinfo.width = hit->RMS();
878  hinfo.time = hit->PeakTime();
879  hinfo.mult = hit->Multiplicity();
880  hinfo.wire = hit->WireID().Wire;
881  hinfo.plane = hit->WireID().Plane;
882  hinfo.tpc = hit->WireID().TPC;
883  hinfo.end = hit->EndTick();
884  hinfo.start = hit->StartTick();
885  hinfo.id = hit.key();
886 
887  const std::vector<art::Ptr<recob::SpacePoint>> &h_sp = allHitSPs.at(hit.key());
888  if (h_sp.size()) {
889  const recob::SpacePoint &sp = *h_sp[0];
890  hinfo.sp.x = sp.position().x();
891  hinfo.sp.y = sp.position().y();
892  hinfo.sp.z = sp.position().z();
893 
894  hinfo.hasSP = true;
895  }
896  else {
897  hinfo.hasSP = false;
898  }
899 
900  fTrack->endhits.push_back(hinfo);
901 
902  }
903  }
904 
905 }
geo::Length_t WireCoordinate(double YPos, double ZPos, geo::PlaneID const &planeid) const
Returns the index of the nearest wire to the specified position.
Vector3D sp
Space-Point Position of hit [cm].
uint16_t tpc
TPC number of hit.
int id
ID of hit.
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
geo::Point_t position() const
Returns the position of the point in world coordinates [cm].
Definition: SpacePoint.h:80
uint16_t plane
Plane number of hit.
float integral
Integral of gaussian fit to ADC values in hit [ADC].
process_name hit
Definition: cheaterreco.fcl:51
std::vector< HitInfo > endhits
List of hits near the endpoint of the track on the collection plane.
uint16_t mult
Multiplicity of hit.
uint16_t wire
Wire number of hit.
int16_t start
Start tick of hit [ticks].
while getopts h
geo::TPCID FindTPCAtPosition(double const worldLoc[3]) const
Returns the ID of the TPC at specified location.
T abs(T value)
float time
Peak time of hit [ticks].
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
j template void())
Definition: json.hpp:3108
float sumadc
&quot;SummedADC&quot; – sum of ADC values under gaussian fit [ADC]
std::vector< TrackHitInfo > hits2
List of hits on plane 2.
bool hasSP
Whether the hit has a SpacePoint.
Point_t const & End() const
float width
Width of fitted gaussian hit [ticks].
int16_t end
End tick of hit [ticks].
void sbn::TrackCaloSkimmer::FillTrackTruth ( const detinfo::DetectorClocksData clock_data,
const std::vector< art::Ptr< recob::Hit >> &  trkHits,
const std::vector< art::Ptr< simb::MCParticle >> &  mcparticles,
const std::vector< geo::BoxBoundedGeo > &  active_volumes,
const std::vector< std::vector< geo::BoxBoundedGeo >> &  tpc_volumes,
const std::map< int, std::vector< std::pair< geo::WireID, const sim::IDE * >>>  id_to_ide_map,
const std::map< int, std::vector< art::Ptr< recob::Hit >>>  id_to_truehit_map,
const detinfo::DetectorPropertiesData dprop,
const geo::GeometryCore geo 
)
private

Definition at line 907 of file TrackCaloSkimmer_module.cc.

915  {
916 
917  // Lookup the true-particle match -- use utils in CAF
918  std::vector<std::pair<int, float>> matches = CAFRecoUtils::AllTrueParticleIDEnergyMatches(clock_data, trkHits, true);
919  float total_energy = CAFRecoUtils::TotalHitEnergy(clock_data, trkHits);
920 
921  fTrack->truth.depE = total_energy / 1000. /* MeV -> GeV */;
922 
923  // sort highest energy match to lowest
924  std::sort(matches.begin(), matches.end(),
925  [](const auto &a, const auto &b) {
926  return a.second > b.second;
927  }
928  );
929 
930  // Save the best match
931  if (matches.size()) {
932  std::pair<int, float> bestmatch = matches[0];
933 
934  fTrack->truth.pur = bestmatch.second / total_energy;
935 
936  for (const art::Ptr<simb::MCParticle> &p_mcp: mcparticles) {
937  if (p_mcp->TrackId() == bestmatch.first) {
938  if (fVerbose) std::cout << "Matched! Track ID: " << p_mcp->TrackId() << " pdg: " << p_mcp->PdgCode() << " process: " << p_mcp->EndProcess() << std::endl;
939  fTrack->truth.p = TrueParticleInfo(*p_mcp, active_volumes, tpc_volumes, id_to_ide_map, id_to_truehit_map, dprop, geo);
941 
942  // Lookup any Michel
943  for (const art::Ptr<simb::MCParticle> &d_mcp: mcparticles) {
944  if (d_mcp->Mother() == p_mcp->TrackId() && // correct parent
945  (d_mcp->Process() == "Decay" || d_mcp->Process() == "muMinusCaptureAtRest") && // correct process
946  abs(d_mcp->PdgCode()) == 11) { // correct PDG code
947 
948  fTrack->truth.michel = TrueParticleInfo(*d_mcp, active_volumes, tpc_volumes, id_to_ide_map, id_to_truehit_map, dprop, geo);
949  break;
950  }
951  }
952 
953  break;
954  }
955  }
956  }
957 }
float depE
Total deposited energy of hits matched to track [GeV].
float eff
Efficiency of truth matching.
TrackTruth truth
Truth-matching information.
process_name gaushit a
sbn::TrueParticle TrueParticleInfo(const simb::MCParticle &particle, const std::vector< geo::BoxBoundedGeo > &active_volumes, const std::vector< std::vector< geo::BoxBoundedGeo >> &tpc_volumes, const std::map< int, std::vector< std::pair< geo::WireID, const sim::IDE * >>> &id_to_ide_map, const std::map< int, std::vector< art::Ptr< recob::Hit >>> &id_to_truehit_map, const detinfo::DetectorPropertiesData &dprop, const geo::GeometryCore *geo)
std::vector< std::pair< int, float > > AllTrueParticleIDEnergyMatches(const detinfo::DetectorClocksData &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
T abs(T value)
float plane2VisE
Sum of energy deposited on plane 2 (Col.) [GeV].
float pur
Purity of truth matching.
float plane1VisE
Sum of energy deposited on plane 1 (2nd Ind.) [GeV].
TrueParticle michel
Truth information on daughter-Michel-electron. Invalid if it doesn&#39;t exist.
float plane0VisE
Sum of energy deposited on plane 0 (1st Ind.) [GeV].
float TotalHitEnergy(const detinfo::DetectorClocksData &clockData, const std::vector< art::Ptr< recob::Hit > > &hits)
TrueParticle p
Truth information on particle.
BEGIN_PROLOG could also be cout
sbn::TrackHitInfo sbn::TrackCaloSkimmer::MakeHit ( const recob::Hit hit,
unsigned  hkey,
const recob::TrackHitMeta thm,
const recob::Track trk,
const art::Ptr< recob::SpacePoint > &  sp,
const std::vector< art::Ptr< anab::Calorimetry >> &  calo,
const geo::GeometryCore geo,
const detinfo::DetectorClocksData dclock,
const cheat::BackTrackerService bt_serv 
)
private

Definition at line 1177 of file TrackCaloSkimmer_module.cc.

1185  {
1186 
1187  // TrackHitInfo to save
1188  sbn::TrackHitInfo hinfo;
1189 
1190  // information from the hit object
1191  hinfo.h.integral = hit.Integral();
1192  hinfo.h.sumadc = hit.SummedADC();
1193  hinfo.h.width = hit.RMS();
1194  hinfo.h.time = hit.PeakTime();
1195  hinfo.h.mult = hit.Multiplicity();
1196  hinfo.h.wire = hit.WireID().Wire;
1197  hinfo.h.plane = hit.WireID().Plane;
1198  hinfo.h.channel = geo->PlaneWireToChannel(hit.WireID());
1199  hinfo.h.tpc = hit.WireID().TPC;
1200  hinfo.h.end = hit.EndTick();
1201  hinfo.h.start = hit.StartTick();
1202  hinfo.h.id = (int)hkey;
1203 
1204  // Do back-tracking on each hit
1205  if (bt_serv) {
1206  // The default BackTracking function goes from (peak - width, peak + width).
1207  //
1208  // This time range does not match well hits with a non-Gaussian shape where
1209  // the Gaussian-fit-width does not replicate the width of the pulse.
1210  //
1211  // Instead, we use the Hit (start, end) time range. This is also more relevant
1212  // for (e.g.) the SummedADC charge extraction method.
1213  //
1214  // Don't use this:
1215  // std::vector<sim::TrackIDE> ides = bt_serv->HitToTrackIDEs(dclock, hit);
1216  //
1217  // Use this:
1218  std::vector<sim::TrackIDE> ides = bt_serv->ChannelToTrackIDEs(dclock, hit.Channel(), hit.StartTick(), hit.EndTick());
1219 
1220  hinfo.h.truth.e = 0.;
1221  hinfo.h.truth.nelec = 0.;
1222 
1223  for (const sim::TrackIDE &ide: ides) {
1224  hinfo.h.truth.e += ide.energy;
1225  hinfo.h.truth.nelec += ide.numElectrons;
1226  }
1227  }
1228  else {
1229  hinfo.h.truth.e = -1.;
1230  hinfo.h.truth.nelec = -1.;
1231  }
1232 
1233  // look up the snippet
1234  sbn::TrackCaloSkimmer::Snippet snippet {hit.WireID(), hit.StartTick(), hit.EndTick()};
1235  if (!fSnippetCount.count(snippet)) {
1236  fSnippetCount[snippet] = 0;
1237  hinfo.i_snippet = 0;
1238  }
1239  else {
1240  fSnippetCount[snippet] ++;
1241  hinfo.i_snippet = fSnippetCount[snippet];
1242  }
1243 
1244  // Which wires to save
1245  int min_tick = (int)std::floor(hit.PeakTime() - fHitRawDigitsTickCollectWidth);
1246  int max_tick = (int)std::ceil(hit.PeakTime() + fHitRawDigitsTickCollectWidth);
1247  for (int wire = hinfo.h.wire - fHitRawDigitsWireCollectWidth; wire <= hinfo.h.wire + fHitRawDigitsWireCollectWidth; wire++) {
1248  geo::WireID w(hit.WireID(), wire);
1249 
1250  if (fWiresToSave.count(w)) {
1251  fWiresToSave.at(w).first = std::min(fWiresToSave.at(w).first, min_tick);
1252  fWiresToSave.at(w).second = std::max(fWiresToSave.at(w).second, max_tick);
1253  }
1254  else {
1255  fWiresToSave[w] = {min_tick, max_tick};
1256  }
1257  }
1258 
1259  // Information from the TrackHitMeta
1260  bool badhit = (thm.Index() == std::numeric_limits<unsigned int>::max()) ||
1261  (!trk.HasValidPoint(thm.Index()));
1262 
1263  hinfo.ontraj = !badhit;
1264 
1265  // Save trajectory information if we can
1266  if (!badhit) {
1267  geo::Point_t loc = trk.LocationAtPoint(thm.Index());
1268  hinfo.tp.x = loc.X();
1269  hinfo.tp.y = loc.Y();
1270  hinfo.tp.z = loc.Z();
1271 
1272  geo::Vector_t dir = trk.DirectionAtPoint(thm.Index());
1273  hinfo.dir.x = dir.X();
1274  hinfo.dir.y = dir.Y();
1275  hinfo.dir.z = dir.Z();
1276 
1277  // And determine if the Hit is on a Calorimetry object
1278  for (const art::Ptr<anab::Calorimetry> &c: calo) {
1279  if (c->PlaneID().Plane != hinfo.h.plane) continue;
1280 
1281  // Found the plane! Now find the hit:
1282  for (unsigned i_calo = 0; i_calo < c->dQdx().size(); i_calo++) {
1283  if (c->TpIndices()[i_calo] == hkey) { // "TpIndices" match to the hit key
1284  // Fill the calo information associated with the hit
1285  hinfo.oncalo = true;
1286  hinfo.pitch = c->TrkPitchVec()[i_calo];
1287  hinfo.dqdx = c->dQdx()[i_calo];
1288  hinfo.rr = c->ResidualRange()[i_calo];
1289  break;
1290  }
1291  }
1292  break;
1293  }
1294  }
1295 
1296  // Save SpacePoint information
1297  if (sp) {
1298  hinfo.h.sp.x = sp->position().x();
1299  hinfo.h.sp.y = sp->position().y();
1300  hinfo.h.sp.z = sp->position().z();
1301 
1302  hinfo.h.hasSP = true;
1303  }
1304  else {
1305  hinfo.h.hasSP = false;
1306  }
1307 
1308  return hinfo;
1309 }
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
std::map< geo::WireID, std::pair< int, int > > fWiresToSave
Vector3D sp
Space-Point Position of hit [cm].
uint16_t tpc
TPC number of hit.
HitInfo h
Hit information by itself.
geo::WireID WireID() const
Definition: Hit.h:233
float RMS() const
RMS of the hit shape, in tick units.
Definition: Hit.h:220
std::map< Snippet, int > fSnippetCount
int id
ID of hit.
Point_t const & LocationAtPoint(size_t i) const
uint16_t channel
Channel number of hit.
bool HasValidPoint(size_t i) const
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:224
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:580
uint16_t plane
Plane number of hit.
float integral
Integral of gaussian fit to ADC values in hit [ADC].
float pitch
Pitch of track across wire the hit is on [cm].
short int Multiplicity() const
How many hits could this one be shared with.
Definition: Hit.h:226
uint16_t mult
Multiplicity of hit.
Vector3D dir
Direction of track at hit location.
uint16_t wire
Wire number of hit.
int16_t start
Start tick of hit [ticks].
float dqdx
Initial computed dq/dx of hit [ADC/cm].
Vector3D tp
Track Trajectory position of hit [cm].
float time
Peak time of hit [ticks].
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
float sumadc
&quot;SummedADC&quot; – sum of ADC values under gaussian fit [ADC]
raw::TDCtick_t StartTick() const
Initial tdc tick for hit.
Definition: Hit.h:216
float rr
Residual range of hit along track [cm].
tuple dir
Definition: dropbox.py:28
raw::TDCtick_t EndTick() const
Final tdc tick for hit.
Definition: Hit.h:217
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:218
uint16_t i_snippet
Index of hit into snippet.
bool hasSP
Whether the hit has a SpacePoint.
float SummedADC() const
The sum of calibrated ADC counts of the hit (0. by default)
Definition: Hit.h:223
unsigned int Index() const
Hit index along the track trajectory.
Definition: TrackHitMeta.h:55
Vector_t DirectionAtPoint(size_t i) const
float width
Width of fitted gaussian hit [ticks].
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406
int16_t end
End tick of hit [ticks].
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
Ionization energy from a Geant4 track.
Definition: SimChannel.h:26
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Definition: Hit.h:230
bool oncalo
Whether the hit is on the track calorimetry.
bool ontraj
Whether the hit is on the track trajectory.
std::vector< sim::TrackIDE > ChannelToTrackIDEs(detinfo::DetectorClocksData const &clockData, raw::ChannelID_t channel, const double hit_start_time, const double hit_end_time) const
TrackCaloSkimmer& sbn::TrackCaloSkimmer::operator= ( TrackCaloSkimmer const &  )
delete
TrackCaloSkimmer& sbn::TrackCaloSkimmer::operator= ( TrackCaloSkimmer &&  )
delete
void sbn::TrackCaloSkimmer::respondToOpenInputFile ( const art::FileBlock &  fb)
inlineoverride

Definition at line 89 of file TrackCaloSkimmer.h.

89  {
90  (void) fb;
91  fMeta.ifile ++;
92  }
int ifile
Index of file into processing.
j template void())
Definition: json.hpp:3108

Member Data Documentation

art::InputTag sbn::TrackCaloSkimmer::fCALOproducer
private

Definition at line 172 of file TrackCaloSkimmer.h.

bool sbn::TrackCaloSkimmer::fDoTailFit
private

Definition at line 180 of file TrackCaloSkimmer.h.

bool sbn::TrackCaloSkimmer::fFillTrackEndHits
private

Definition at line 186 of file TrackCaloSkimmer.h.

TFitter sbn::TrackCaloSkimmer::fFitConst
private

Definition at line 205 of file TrackCaloSkimmer.h.

TFitter sbn::TrackCaloSkimmer::fFitExp
private

Definition at line 204 of file TrackCaloSkimmer.h.

std::string sbn::TrackCaloSkimmer::fG4producer
private

Definition at line 177 of file TrackCaloSkimmer.h.

art::InputTag sbn::TrackCaloSkimmer::fHITproducer
private

Definition at line 175 of file TrackCaloSkimmer.h.

double sbn::TrackCaloSkimmer::fHitRawDigitsTickCollectWidth
private

Definition at line 183 of file TrackCaloSkimmer.h.

int sbn::TrackCaloSkimmer::fHitRawDigitsWireCollectWidth
private

Definition at line 185 of file TrackCaloSkimmer.h.

MetaInfo sbn::TrackCaloSkimmer::fMeta
private

Definition at line 194 of file TrackCaloSkimmer.h.

art::InputTag sbn::TrackCaloSkimmer::fPFPproducer
private

Definition at line 170 of file TrackCaloSkimmer.h.

std::vector<art::InputTag> sbn::TrackCaloSkimmer::fRawDigitproducers
private

Definition at line 176 of file TrackCaloSkimmer.h.

bool sbn::TrackCaloSkimmer::fRequireT0
private

Definition at line 179 of file TrackCaloSkimmer.h.

std::vector<std::unique_ptr<sbn::ITCSSelectionTool> > sbn::TrackCaloSkimmer::fSelectionTools
private

Definition at line 191 of file TrackCaloSkimmer.h.

bool sbn::TrackCaloSkimmer::fSilenceMissingDataProducts
private

Definition at line 182 of file TrackCaloSkimmer.h.

std::string sbn::TrackCaloSkimmer::fSimChannelproducer
private

Definition at line 178 of file TrackCaloSkimmer.h.

std::map<Snippet, int> sbn::TrackCaloSkimmer::fSnippetCount
private

Definition at line 196 of file TrackCaloSkimmer.h.

std::vector<art::InputTag> sbn::TrackCaloSkimmer::fT0producers
private

Definition at line 171 of file TrackCaloSkimmer.h.

double sbn::TrackCaloSkimmer::fTailFitResidualRange
private

Definition at line 184 of file TrackCaloSkimmer.h.

TrackInfo* sbn::TrackCaloSkimmer::fTrack
private

Definition at line 201 of file TrackCaloSkimmer.h.

float sbn::TrackCaloSkimmer::fTrackEndHitTimeBox
private

Definition at line 188 of file TrackCaloSkimmer.h.

float sbn::TrackCaloSkimmer::fTrackEndHitWireBox
private

Definition at line 187 of file TrackCaloSkimmer.h.

TTree* sbn::TrackCaloSkimmer::fTree
private

Definition at line 200 of file TrackCaloSkimmer.h.

art::InputTag sbn::TrackCaloSkimmer::fTRKHMproducer
private

Definition at line 174 of file TrackCaloSkimmer.h.

art::InputTag sbn::TrackCaloSkimmer::fTRKproducer
private

Definition at line 173 of file TrackCaloSkimmer.h.

bool sbn::TrackCaloSkimmer::fVerbose
private

Definition at line 181 of file TrackCaloSkimmer.h.

std::map<geo::WireID, std::pair<int, int> > sbn::TrackCaloSkimmer::fWiresToSave
private

Definition at line 197 of file TrackCaloSkimmer.h.


The documentation for this class was generated from the following files: