All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
microboone::CosmicRemovalAna Class Reference
Inheritance diagram for microboone::CosmicRemovalAna:

Public Types

enum  hit_origin_t { hit_origin_Unknown = -1, hit_origin_Cosmic = 0, hit_origin_NonCosmic = 1 }
 

Public Member Functions

 CosmicRemovalAna (fhicl::ParameterSet const &pset)
 
void analyze (const art::Event &evt)
 read access to event More...
 
void beginJob ()
 

Private Member Functions

void InitEventTree (int run_number, int event_number)
 
void FillMCInfo (art::Event const &e, std::vector< recob::Hit > const &hitlist, std::vector< hit_origin_t > &hitOrigins, std::vector< sim::MCHitCollection > const &mchitCollectionVector, std::map< int, const simb::MCTruth * > const &trackIDToTruthMap)
 
void FillTrackInfo (size_t const &hit_iter, hit_origin_t const &origin, float const &charge, std::vector< size_t > const &track_indices_this_hit, std::vector< std::vector< const anab::CosmicTag * >> const &tags_per_cluster, std::vector< bool > &hitsAccounted_per_tag, std::vector< bool > &hitsAllTags)
 
void FillClusterInfo (size_t const &hit_iter, hit_origin_t const &origin, float const &charge, std::vector< size_t > const &cluster_indices_this_hit, std::vector< std::vector< const anab::CosmicTag * >> const &tags_per_cluster, std::vector< bool > &hitsAccounted_per_tag, std::vector< bool > &hitsAllTags)
 
void FillAllTagsInfo (recob::Hit const &hit, hit_origin_t const &origin)
 

Private Attributes

unsigned int nCosmicTags
 
TTree * tEventTree
 
std::string fHitsModuleLabel
 
std::string fMCModuleLabel
 
std::string fMCHitsModuleLabel
 
std::string fClusterModuleLabel
 
std::string fTrackModuleLabel
 
float fHitCompareCut
 
std::vector< std::string > fCosmicTagAssocLabel
 
std::vector< float > fCosmicScoreThresholds
 
std::vector< float > cTaggedCharge_Cosmic
 
std::vector< float > cTaggedCharge_NonCosmic
 
std::vector< int > cTaggedHits_Cosmic
 
std::vector< int > cTaggedHits_NonCosmic
 

Detailed Description

Definition at line 40 of file CosmicRemovalAna_module.cc.

Member Enumeration Documentation

Constructor & Destructor Documentation

microboone::CosmicRemovalAna::CosmicRemovalAna ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 159 of file CosmicRemovalAna_module.cc.

160  : EDAnalyzer(pset)
161  , fHitsModuleLabel(pset.get<std::string>("HitsModuleLabel"))
162  , fMCModuleLabel(pset.get<std::string>("MCModuleLabel"))
163  , fMCHitsModuleLabel(pset.get<std::string>("MCHitsModuleLabel"))
164  , fClusterModuleLabel(pset.get<std::string>("ClusterModuleLabel"))
165  , fTrackModuleLabel(pset.get<std::string>("TrackModuleLabel"))
166  , fHitCompareCut(pset.get<float>("HitCompareCut"))
167  , fCosmicTagAssocLabel(pset.get<std::vector<std::string>>("CosmicTagAssocLabel"))
168  , fCosmicScoreThresholds(pset.get<std::vector<float>>("CosmicScoreThresholds"))
169 {}
std::vector< float > fCosmicScoreThresholds
std::vector< std::string > fCosmicTagAssocLabel

Member Function Documentation

void microboone::CosmicRemovalAna::analyze ( const art::Event &  evt)

read access to event

Definition at line 209 of file CosmicRemovalAna_module.cc.

210 {
211 
212  InitEventTree(evt.run(), evt.event());
213 
214  // ##################################################################
215  // ### Grabbing ALL HITS in the event to monitor the backtracking ###
216  // ##################################################################
217  art::Handle<std::vector<recob::Hit>> hitListHandle;
218  evt.getByLabel(fHitsModuleLabel, hitListHandle);
219  std::vector<recob::Hit> const& hitVector(*hitListHandle);
220 
221  std::vector<hit_origin_t> hitOrigins(hitVector.size());
222 
223  //get mcHitCollection
224  art::Handle<std::vector<sim::MCHitCollection>> mchitListHandle;
225  evt.getByLabel(fMCHitsModuleLabel, mchitListHandle);
226  std::vector<sim::MCHitCollection> const& mchitcolVector(*mchitListHandle);
227 
228  //get mcparticles out of the event
229  art::Handle<std::vector<simb::MCParticle>> mcParticleHandle;
230  evt.getByLabel(fMCModuleLabel, mcParticleHandle);
231  std::vector<simb::MCParticle> const& mcParticleVector(*mcParticleHandle);
232 
233  //get associations of mc particles to mc truth
234  art::Handle<art::Assns<simb::MCParticle, simb::MCTruth>> assnMCParticleTruthHandle;
235  evt.getByLabel(fMCModuleLabel, assnMCParticleTruthHandle);
236 
237  std::vector<const simb::MCTruth*> particle_to_truth =
238  util::GetAssociatedVectorOneP(assnMCParticleTruthHandle, mcParticleHandle);
239 
240  //make trackId to MCTruth map
241  std::map<int, const simb::MCTruth*> trackIDToTruthMap;
242  for (size_t p_iter = 0; p_iter < mcParticleVector.size(); p_iter++)
243  trackIDToTruthMap[mcParticleVector[p_iter].TrackId()] = particle_to_truth[p_iter];
244 
245  FillMCInfo(evt, hitVector, hitOrigins, mchitcolVector, trackIDToTruthMap);
246 
247  art::Handle<std::vector<recob::Track>> trackListHandle;
248  evt.getByLabel(fTrackModuleLabel, trackListHandle);
249  std::vector<recob::Track> const& trackVector(*trackListHandle);
250 
251  art::Handle<std::vector<recob::Cluster>> clusterListHandle;
252  evt.getByLabel(fClusterModuleLabel, clusterListHandle);
253  std::vector<recob::Cluster> const& clusterVector(*clusterListHandle);
254 
255  art::Handle<art::Assns<recob::Hit, recob::Track>> assnHitTrackHandle;
256  evt.getByLabel(fTrackModuleLabel, assnHitTrackHandle);
257  std::vector<std::vector<size_t>> track_indices_per_hit =
258  util::GetAssociatedVectorManyI(assnHitTrackHandle, hitListHandle);
259 
260  art::Handle<art::Assns<recob::Hit, recob::Cluster>> assnHitClusterHandle;
261  evt.getByLabel(fClusterModuleLabel, assnHitClusterHandle);
262  std::vector<std::vector<size_t>> cluster_indices_per_hit =
263  util::GetAssociatedVectorManyI(assnHitClusterHandle, hitListHandle);
264 
265  std::vector<art::Handle<std::vector<anab::CosmicTag>>> cosmicTagHandlesVector(
266  fCosmicTagAssocLabel.size());
267  std::vector<art::Handle<art::Assns<recob::Track, anab::CosmicTag>>> assnTrackTagHandlesVector(
268  fCosmicTagAssocLabel.size());
269  std::vector<std::vector<const anab::CosmicTag*>> tags_per_track(
270  trackVector.size(), std::vector<const anab::CosmicTag*>(fCosmicTagAssocLabel.size()));
271  std::vector<art::Handle<art::Assns<recob::Cluster, anab::CosmicTag>>> assnClusterTagHandlesVector(
272  fCosmicTagAssocLabel.size());
273  std::vector<std::vector<const anab::CosmicTag*>> tags_per_cluster(
274  clusterVector.size(), std::vector<const anab::CosmicTag*>(fCosmicTagAssocLabel.size()));
275 
276  for (size_t label_i = 0; label_i < fCosmicTagAssocLabel.size(); label_i++) {
277  try {
278  evt.getByLabel(fCosmicTagAssocLabel[label_i], cosmicTagHandlesVector[label_i]);
279  }
280  catch (...) {
281  continue;
282  }
283  try {
284  evt.getByLabel(fCosmicTagAssocLabel[label_i], assnTrackTagHandlesVector[label_i]);
285  for (auto const& pair : *assnTrackTagHandlesVector[label_i])
286  tags_per_track.at(pair.first.key())[label_i] = &(*(pair.second));
287  }
288  catch (...) {
289  }
290  try {
291  evt.getByLabel(fCosmicTagAssocLabel[label_i], assnClusterTagHandlesVector[label_i]);
292  for (auto const& pair : *assnClusterTagHandlesVector[label_i])
293  tags_per_cluster.at(pair.first.key())[label_i] = &(*(pair.second));
294  }
295  catch (...) {
296  }
297  }
298 
299  std::vector<std::vector<bool>> hitsAccounted(
300  hitVector.size(), std::vector<bool>(fCosmicTagAssocLabel.size(), false));
301  std::vector<bool> hitsAllTags(hitVector.size(), false);
302 
303  for (size_t hit_iter = 0; hit_iter < hitVector.size(); hit_iter++) {
304 
305  float charge = hitVector[hit_iter].Integral();
306  hit_origin_t origin = hitOrigins[hit_iter];
307 
308  if (track_indices_per_hit[hit_iter].size() != 0)
309  FillTrackInfo(hit_iter,
310  origin,
311  charge,
312  track_indices_per_hit[hit_iter],
313  tags_per_track,
314  hitsAccounted[hit_iter],
315  hitsAllTags);
316 
317  if (cluster_indices_per_hit[hit_iter].size() != 0)
318  FillClusterInfo(hit_iter,
319  origin,
320  charge,
321  cluster_indices_per_hit[hit_iter],
322  tags_per_cluster,
323  hitsAccounted[hit_iter],
324  hitsAllTags);
325 
326  if (hitsAllTags[hit_iter]) FillAllTagsInfo(hitVector[hit_iter], origin);
327 
328  } //end loop over all the hits
329 
330  tEventTree->Fill();
331 }
unsigned int event
Definition: DataStructs.h:634
unsigned int run
Definition: DataStructs.h:635
void FillAllTagsInfo(recob::Hit const &hit, hit_origin_t const &origin)
void FillTrackInfo(size_t const &hit_iter, hit_origin_t const &origin, float const &charge, std::vector< size_t > const &track_indices_this_hit, std::vector< std::vector< const anab::CosmicTag * >> const &tags_per_cluster, std::vector< bool > &hitsAccounted_per_tag, std::vector< bool > &hitsAllTags)
std::vector< const U * > GetAssociatedVectorOneP(art::Handle< art::Assns< T, U > > h, art::Handle< std::vector< T > > index_p)
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
void FillMCInfo(art::Event const &e, std::vector< recob::Hit > const &hitlist, std::vector< hit_origin_t > &hitOrigins, std::vector< sim::MCHitCollection > const &mchitCollectionVector, std::map< int, const simb::MCTruth * > const &trackIDToTruthMap)
void InitEventTree(int run_number, int event_number)
std::vector< std::vector< size_t > > GetAssociatedVectorManyI(art::Handle< art::Assns< T, U > > h, art::Handle< std::vector< T > > index_p)
TCEvent evt
Definition: DataStructs.cxx:8
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227
void FillClusterInfo(size_t const &hit_iter, hit_origin_t const &origin, float const &charge, std::vector< size_t > const &cluster_indices_this_hit, std::vector< std::vector< const anab::CosmicTag * >> const &tags_per_cluster, std::vector< bool > &hitsAccounted_per_tag, std::vector< bool > &hitsAllTags)
std::vector< std::string > fCosmicTagAssocLabel
void microboone::CosmicRemovalAna::beginJob ( )

Definition at line 176 of file CosmicRemovalAna_module.cc.

177 {
178 
179  //static cEventProperties_t cEventVals;
180 
186 
187  art::ServiceHandle<art::TFileService const> tfs;
188  tEventTree = (TTree*)tfs->make<TTree>("CosmicEventTree", "CosmicEventTree");
189 
190  tEventTree->Branch(
191  "event",
192  &cEventVals,
193  "runNumber/I:eventNumber/I:nHitsTotal_Unknown/I:nHitsTotal_Cosmic/I:nHitsTotal_NonCosmic/"
194  "I:qTotal_Unknown/F:qTotal_Cosmic/F:qTotal_NonCosmic/F:nHitsTrack/I:nHitsTrack_Cosmic/"
195  "I:nHitsTrack_NonCosmic/I:qTrack/F:qTrack_Cosmic/F:qTrack_NonCosmic/F:nHitsCluster/"
196  "I:nHitsCluster_Cosmic/I:nHitsCluster_NonCosmic/I:qCluster/F:qCluster_Cosmic/"
197  "F:qCluster_NonCosmic/F:TotalTaggedCharge_Cosmic/F:TotalTaggedCharge_NonCosmic/"
198  "F:TotalTaggedHits_Cosmic/I:TotalTaggedHits_NonCosmic/I");
199  tEventTree->Branch("TaggedCharge_Cosmic", &cTaggedCharge_Cosmic);
200  tEventTree->Branch("TaggedCharge_NonCosmic", &cTaggedCharge_NonCosmic);
201  tEventTree->Branch("TaggedHits_Cosmic", &cTaggedHits_Cosmic);
202  tEventTree->Branch("TaggedHits_NonCosmic", &cTaggedHits_NonCosmic);
203 }
cEventProperties_t cEventVals
std::vector< float > cTaggedCharge_NonCosmic
std::vector< float > cTaggedCharge_Cosmic
art::ServiceHandle< art::TFileService > tfs
std::vector< std::string > fCosmicTagAssocLabel
void microboone::CosmicRemovalAna::FillAllTagsInfo ( recob::Hit const &  hit,
hit_origin_t const &  origin 
)
private

Definition at line 540 of file CosmicRemovalAna_module.cc.

541 {
542  if (origin == hit_origin_Cosmic) {
545  }
546  else if (origin == hit_origin_NonCosmic) {
549  }
550 }
cEventProperties_t cEventVals
process_name hit
Definition: cheaterreco.fcl:51
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227
void microboone::CosmicRemovalAna::FillClusterInfo ( size_t const &  hit_iter,
hit_origin_t const &  origin,
float const &  charge,
std::vector< size_t > const &  cluster_indices_this_hit,
std::vector< std::vector< const anab::CosmicTag * >> const &  tags_per_cluster,
std::vector< bool > &  hitsAccounted_per_tag,
std::vector< bool > &  hitsAllTags 
)
private

Definition at line 491 of file CosmicRemovalAna_module.cc.

499 {
500 
502  cEventVals.qCluster += charge;
503 
504  if (origin == hit_origin_Cosmic) {
506  cEventVals.qCluster_Cosmic += charge;
507  }
508  else if (origin == hit_origin_NonCosmic) {
510  cEventVals.qCluster_NonCosmic += charge;
511  }
512 
513  for (unsigned int nCT = 0; nCT < fCosmicTagAssocLabel.size();
514  nCT++) { //<---This loops over the vector of cosmicTags in stored in the event
515  if (hitsAccounted_per_tag[nCT]) continue;
516 
517  for (auto const& cluster_index : cluster_indices_this_hit) {
518  if (!tags_per_cluster[cluster_index][nCT]) continue;
519  const anab::CosmicTag* currentTag(tags_per_cluster[cluster_index][nCT]);
520  if (currentTag->CosmicScore() > fCosmicScoreThresholds[nCT]) {
521 
522  hitsAccounted_per_tag[nCT] = true;
523  hitsAllTags[hit_iter] = true;
524  if (origin == hit_origin_Cosmic) {
525  cTaggedHits_Cosmic[nCT]++;
526  cTaggedCharge_Cosmic[nCT] += charge;
527  }
528  else if (origin == hit_origin_NonCosmic) {
529  cTaggedHits_NonCosmic[nCT]++;
530  cTaggedCharge_NonCosmic[nCT] += charge;
531  }
532  }
533  }
534  }
535 
536 } //end FillClusterInfo
cEventProperties_t cEventVals
std::vector< float > cTaggedCharge_NonCosmic
std::vector< float > fCosmicScoreThresholds
std::vector< float > cTaggedCharge_Cosmic
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227
std::vector< std::string > fCosmicTagAssocLabel
void microboone::CosmicRemovalAna::FillMCInfo ( art::Event const &  e,
std::vector< recob::Hit > const &  hitlist,
std::vector< hit_origin_t > &  hitOrigins,
std::vector< sim::MCHitCollection > const &  mchitCollectionVector,
std::map< int, const simb::MCTruth * > const &  trackIDToTruthMap 
)
private

Definition at line 381 of file CosmicRemovalAna_module.cc.

387 {
388  auto const clock_data =
389  art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
390 
391  for (size_t itr = 0; itr < hitlist.size(); itr++) {
392 
393  recob::Hit const& this_hit = hitlist[itr];
394 
395  std::vector<int> trackIDs;
396  std::vector<double> energy;
397 
398  for (auto const& mchit : mchitCollectionVector[this_hit.Channel()]) {
399  if (std::abs(clock_data.TPCTDC2Tick(mchit.PeakTime()) - this_hit.PeakTime()) <
400  fHitCompareCut) {
401  trackIDs.push_back(mchit.PartTrackId());
402  energy.push_back(mchit.PartEnergy());
403  }
404  }
405 
406  if (trackIDs.size() == 0) {
407  hitOrigins[itr] = hit_origin_Unknown;
409  cEventVals.qTotal_Unknown += this_hit.Integral();
410  continue;
411  }
412 
413  float cosmic_energy = 0;
414  float non_cosmic_energy = 0;
415 
416  for (size_t iter = 0; iter < trackIDs.size(); iter++) {
417  auto map_element = trackIdToTruthMap.find(std::abs(trackIDs[iter]));
418  if (map_element == trackIdToTruthMap.end()) continue;
419  int origin = map_element->second->Origin();
420  if (origin == simb::kBeamNeutrino)
421  non_cosmic_energy += energy[iter];
422  else
423  cosmic_energy += energy[iter];
424  }
425 
426  if (non_cosmic_energy > cosmic_energy) {
427  hitOrigins[itr] = hit_origin_NonCosmic;
429  cEventVals.qTotal_NonCosmic += this_hit.Integral();
430  }
431  else {
432  hitOrigins[itr] = hit_origin_Cosmic;
434  cEventVals.qTotal_Cosmic += this_hit.Integral();
435  }
436  }
437 
438 } //end FillMCInfo
cEventProperties_t cEventVals
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:224
T abs(T value)
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:218
do i e
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Definition: Hit.h:230
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227
void microboone::CosmicRemovalAna::FillTrackInfo ( size_t const &  hit_iter,
hit_origin_t const &  origin,
float const &  charge,
std::vector< size_t > const &  track_indices_this_hit,
std::vector< std::vector< const anab::CosmicTag * >> const &  tags_per_cluster,
std::vector< bool > &  hitsAccounted_per_tag,
std::vector< bool > &  hitsAllTags 
)
private

Definition at line 442 of file CosmicRemovalAna_module.cc.

450 {
451 
453  cEventVals.qTrack += charge;
454 
455  if (origin == hit_origin_Cosmic) {
457  cEventVals.qTrack_Cosmic += charge;
458  }
459  else if (origin == hit_origin_NonCosmic) {
461  cEventVals.qTrack_NonCosmic += charge;
462  }
463 
464  for (unsigned int nCT = 0; nCT < fCosmicTagAssocLabel.size();
465  nCT++) { //<---This loops over the vector of cosmicTags in stored in the event
466  if (hitsAccounted_per_tag[nCT]) continue;
467 
468  for (auto const& track_index : track_indices_this_hit) {
469  if (!tags_per_track[track_index][nCT]) continue;
470  const anab::CosmicTag* currentTag(tags_per_track[track_index][nCT]);
471  if (currentTag->CosmicScore() > fCosmicScoreThresholds[nCT]) {
472 
473  hitsAccounted_per_tag[nCT] = true;
474  hitsAllTags[hit_iter] = true;
475  if (origin == hit_origin_Cosmic) {
476  cTaggedHits_Cosmic[nCT]++;
477  cTaggedCharge_Cosmic[nCT] += charge;
478  }
479  else if (origin == hit_origin_NonCosmic) {
480  cTaggedHits_NonCosmic[nCT]++;
481  cTaggedCharge_NonCosmic[nCT] += charge;
482  }
483  }
484  }
485  }
486 
487 } //end FillTrackInfo
cEventProperties_t cEventVals
std::vector< float > cTaggedCharge_NonCosmic
std::vector< float > fCosmicScoreThresholds
std::vector< float > cTaggedCharge_Cosmic
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227
std::vector< std::string > fCosmicTagAssocLabel
void microboone::CosmicRemovalAna::InitEventTree ( int  run_number,
int  event_number 
)
private

Definition at line 335 of file CosmicRemovalAna_module.cc.

336 {
337 
338  cEventVals.runNumber = run_number; //evt.run();
339  cEventVals.eventNumber = event_number; //evt.event();
340 
344 
348 
352 
353  cEventVals.qTrack = 0;
356 
360 
361  cEventVals.qCluster = 0;
364 
369 
370  for (size_t iter = 0; iter < fCosmicTagAssocLabel.size(); iter++) {
371  cTaggedHits_Cosmic.at(iter) = 0;
372  cTaggedCharge_Cosmic.at(iter) = 0;
373  cTaggedHits_NonCosmic.at(iter) = 0;
374  cTaggedCharge_NonCosmic.at(iter) = 0;
375  }
376 }
cEventProperties_t cEventVals
std::vector< float > cTaggedCharge_NonCosmic
std::vector< float > cTaggedCharge_Cosmic
std::vector< std::string > fCosmicTagAssocLabel

Member Data Documentation

std::vector<float> microboone::CosmicRemovalAna::cTaggedCharge_Cosmic
private

Definition at line 92 of file CosmicRemovalAna_module.cc.

std::vector<float> microboone::CosmicRemovalAna::cTaggedCharge_NonCosmic
private

Definition at line 93 of file CosmicRemovalAna_module.cc.

std::vector<int> microboone::CosmicRemovalAna::cTaggedHits_Cosmic
private

Definition at line 94 of file CosmicRemovalAna_module.cc.

std::vector<int> microboone::CosmicRemovalAna::cTaggedHits_NonCosmic
private

Definition at line 95 of file CosmicRemovalAna_module.cc.

std::string microboone::CosmicRemovalAna::fClusterModuleLabel
private

Definition at line 60 of file CosmicRemovalAna_module.cc.

std::vector<float> microboone::CosmicRemovalAna::fCosmicScoreThresholds
private

Definition at line 64 of file CosmicRemovalAna_module.cc.

std::vector<std::string> microboone::CosmicRemovalAna::fCosmicTagAssocLabel
private

Definition at line 63 of file CosmicRemovalAna_module.cc.

float microboone::CosmicRemovalAna::fHitCompareCut
private

Definition at line 62 of file CosmicRemovalAna_module.cc.

std::string microboone::CosmicRemovalAna::fHitsModuleLabel
private

Definition at line 57 of file CosmicRemovalAna_module.cc.

std::string microboone::CosmicRemovalAna::fMCHitsModuleLabel
private

Definition at line 59 of file CosmicRemovalAna_module.cc.

std::string microboone::CosmicRemovalAna::fMCModuleLabel
private

Definition at line 58 of file CosmicRemovalAna_module.cc.

std::string microboone::CosmicRemovalAna::fTrackModuleLabel
private

Definition at line 61 of file CosmicRemovalAna_module.cc.

unsigned int microboone::CosmicRemovalAna::nCosmicTags
private

Definition at line 52 of file CosmicRemovalAna_module.cc.

TTree* microboone::CosmicRemovalAna::tEventTree
private

Definition at line 55 of file CosmicRemovalAna_module.cc.


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