LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
CosmicClusterTagger_module.cc
Go to the documentation of this file.
1 // Class: CosmicTagger
3 // Module Type: producer
4 // File: CosmicTagger_module.cc
5 //
6 // Generated at Mon Sep 24 18:21:00 2012 by Sarah Lockwitz using artmod
7 // from art v1_02_02.
8 // artmod -e beginJob -e reconfigure -e endJob producer trkf::CosmicTagger
10 
15 
16 #include <algorithm> // std::minmax() ...
17 #include <memory> // std::unique_ptr<>
18 #include <string>
19 #include <utility> // std::pair<>, std::move()
20 
29 
30 namespace cosmic {
31  class CosmicClusterTagger;
32 }
33 
35 public:
36  explicit CosmicClusterTagger(fhicl::ParameterSet const& p);
37 
38  void produce(art::Event& e) override;
39 
40 private:
41  std::string fClusterModuleLabel;
46 };
47 
49 {
50  auto const& tpc = lar::providerFrom<geo::Geometry>()->TPC({0, 0});
51 
52  auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
53  auto const detp =
55  double const samplingRate = sampling_rate(clock_data);
56  fClusterModuleLabel = p.get<std::string>("ClusterModuleLabel", "cluster");
57  fTickLimit = p.get<int>("TickLimit", 0);
58  const double driftVelocity = detp.DriftVelocity(detp.Efield(), detp.Temperature()); // cm/us
59 
60  fDetectorWidthTicks = 2 * tpc.HalfWidth() / (driftVelocity * samplingRate / 1000); // ~3200 for uB
61  fMinTickDrift = p.get("MinTickDrift", 3200);
63 
64  produces<std::vector<anab::CosmicTag>>();
65  produces<art::Assns<recob::Cluster, anab::CosmicTag>>();
66 }
67 
69 {
70  std::unique_ptr<std::vector<anab::CosmicTag>> cosmicTagClusterVector(
71  new std::vector<anab::CosmicTag>);
72  std::unique_ptr<art::Assns<recob::Cluster, anab::CosmicTag>> assnOutCosmicTagCluster(
74 
76  e.getByLabel(fClusterModuleLabel, Cluster_h);
77  std::vector<art::Ptr<recob::Cluster>> ClusterVec;
78  art::fill_ptr_vector(ClusterVec, Cluster_h);
79 
81  // LOOP OVER CLUSTERS
83 
84  for (unsigned int iCluster = 0; iCluster < Cluster_h->size(); iCluster++) {
85 
86  float cosmicScore = 0;
88 
89  art::Ptr<recob::Cluster> tCluster = ClusterVec.at(iCluster);
90  // art::Ptr<recob::Track> tTrack; // unused
91 
92  std::vector<float> endPt1;
93  std::vector<float> endPt2;
94 
95  // Doing some checks on the cluster to determine if it's a cosmic
96  bool failClusterTickCheck = false;
97 
98  auto const [t0, t1] = std::minmax({tCluster->StartTick(), tCluster->EndTick()});
99  if (t0 + fTickLimit < fMinTickDrift) { // This is into the pre-spill window
100  failClusterTickCheck = true;
101  }
102  if (t1 - fTickLimit > fMaxTickDrift) { // This is into the post-spill window
103  failClusterTickCheck = true;
104  }
105 
106  if (failClusterTickCheck) {
107  cosmicScore = 1.;
109  }
110 
111  if (endPt1.size() < 1) {
112  for (int s = 0; s < 3; s++) {
113  endPt1.push_back(-999);
114  endPt2.push_back(-999);
115  }
116  }
117 
118  // Making stuff to save!
119  cosmicTagClusterVector->emplace_back(endPt1, endPt2, cosmicScore, tag_id);
120 
121  util::CreateAssn(e, *cosmicTagClusterVector, tCluster, *assnOutCosmicTagCluster);
122  }
123 
125  // END OF CLUSTER LOOP
127 
128  e.put(std::move(cosmicTagClusterVector));
129  e.put(std::move(assnOutCosmicTagCluster));
130 
131 } // end of produce
133 
code to link reconstructed objects back to the MC truth information
Utilities related to art service access.
TTree * t1
Definition: plottest35.C:26
void produce(art::Event &e) override
std::pair< float, float > minmax(const float a, const float b)
minmax
Unknown view.
Definition: geo_types.h:138
enum anab::cosmic_tag_id CosmicTagID_t
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
float EndTick() const
Returns the tick coordinate of the end of the cluster.
Definition: Cluster.h:331
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
CosmicClusterTagger(fhicl::ParameterSet const &p)
Declaration of cluster object.
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Utility object to perform functions of association.
Provides recob::Track data product.
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:306
Float_t e
Definition: plot.C:35
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
float StartTick() const
Returns the tick coordinate of the start of the cluster.
Definition: Cluster.h:287
art framework interface to geometry description