All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MuonS2NStudy_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: MuonS2NStudy
3 // Plugin Type: analyzer (art v3_03_01)
4 // File: MuonS2NStudy_module.cc
5 //
6 // Generated at Wed Mar 25 12:10:37 2020 by Gray Putnam using cetskelgen
7 // from cetlib version v3_08_00.
8 ////////////////////////////////////////////////////////////////////////
9 
10 #include "art/Framework/Core/EDAnalyzer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "art/Framework/Principal/Run.h"
15 #include "art/Framework/Principal/SubRun.h"
16 #include "canvas/Utilities/InputTag.h"
17 #include "fhiclcpp/ParameterSet.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
19 
20 #include "art/Framework/Services/Registry/ServiceHandle.h"
24 
25 // LArSoft includes
32 #include "art_root_io/TFileService.h"
33 
35 
37 
50 #include "nusimdata/SimulationBase/MCParticle.h"
51 #include "nusimdata/SimulationBase/MCTruth.h"
52 
54 
55 #include "TH1D.h"
57 
58 namespace numu {
59  class MuonS2NStudy;
60 }
61 
62 class numu::MuonS2NStudy : public art::EDAnalyzer {
63 public:
64  explicit MuonS2NStudy(fhicl::ParameterSet const& p);
65  // The compiler-generated destructor is fine for non-base
66  // classes without bare pointers or other resource use.
67 
68  // Plugins should not be copied or assigned.
69  MuonS2NStudy(MuonS2NStudy const&) = delete;
70  MuonS2NStudy(MuonS2NStudy&&) = delete;
71  MuonS2NStudy& operator=(MuonS2NStudy const&) = delete;
72  MuonS2NStudy& operator=(MuonS2NStudy&&) = delete;
73 
74  // Required functions.
75  void analyze(art::Event const& e) override;
76 
77 private:
78  std::vector<std::array<TH1D*,3>> fSignal;
79  std::array<TH1D*, 3> fNoise;
80  std::string fHitLabel;
81  std::string fWireLabel;
82 
83 };
84 
85 numu::MuonS2NStudy::MuonS2NStudy(fhicl::ParameterSet const& p)
86  : EDAnalyzer{p}, // ,
87  fHitLabel(p.get<std::string>("HitLabel")),
88  fWireLabel(p.get<std::string>("WireLabel"))
89  // More initializers here.
90 {
91  art::ServiceHandle<art::TFileService> tfs;
92 
93  std::vector<std::string> planes {"U", "V", "Y"};
94  std::vector<std::string> angles {"abs(#theta) < 0.2", "#theta < -0.2", "#theta > 0.2"};
95  // initilize the signal and noise on each plane
96  for (unsigned i = 0; i < 3; i++) {
97  for (unsigned j = 0; j < 3; j++) {
98  fSignal.emplace_back();
99  fSignal[j][i] = tfs->make<TH1D>(("Signal " + angles[j] + " " + planes[i]).c_str(), "Signal", 200, 0., 400.);
100  }
101  fNoise[i] = tfs->make<TH1D>(("Noise " + planes[i]).c_str(), "Noise", 200, 0., 10.);
102  }
103 }
104 
105 void numu::MuonS2NStudy::analyze(art::Event const& ev)
106 {
107  art::ServiceHandle<cheat::BackTrackerService> backtracker;
108  const geo::GeometryCore *geo = lar::providerFrom<geo::Geometry>();
109  auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(ev);
110 
111  // Get the Signal Amplitude
112  const std::vector<simb::MCParticle> &mcparticle_list = *ev.getValidHandle<std::vector<simb::MCParticle>>("largeant");
113 
114  art::Handle<std::vector<recob::Hit>> hit_handle;
115  ev.getByLabel(fHitLabel, hit_handle);
116  std::vector<art::Ptr<recob::Hit>> hits;
117  art::fill_ptr_vector(hits, hit_handle);
118 
119  const simb::MCParticle *muon = NULL;
120 
121  // get the muon
122  for (unsigned i = 0; i < mcparticle_list.size(); i++) {
123  if (mcparticle_list[i].PdgCode() == 13 && mcparticle_list[i].Process() == "primary") {
124  assert(muon == NULL);
125  muon = &mcparticle_list[i];
126  }
127  break;
128  }
129 
130  assert(muon != NULL);
131 
132  std::cout << "Muon Momentum Theta: " << muon->Momentum().Theta() << std::endl;
133  std::cout << "Muon Momentum Phi: " << muon->Momentum().Phi() << std::endl;
134 
135  // find the angular bin
136  int angle_bin = -1;
137  if (abs(muon->Momentum().Theta()) < 0.2) angle_bin = 0;
138  else if (muon->Momentum().Phi() < 0.) angle_bin = 1;
139  else angle_bin = 2;
140 
141  // make sure it's an energetic enough muon
142  // if (muon->E() < fMuonEnergyCut) return;
143 
144  // make sure the muon is mostly perpindicular to the wire-planes
145  // if (muon->Momentum()->CosTheta() < fMuonCosThetaCut) return;
146 
147  // get the true matched hits
148  std::vector<art::Ptr<recob::Hit>> muon_hits = backtracker->TrackIdToHits_Ps(clock_data, muon->TrackId(), hits);
149 
150  // Only consider the hit with the highest amplitude on each channel
151  // (in case of accidental delta rays or split hits)
152  std::map<raw::ChannelID_t, float> amplitude_map;
153 
154  for (art::Ptr<recob::Hit> hit: muon_hits) {
155  if (!amplitude_map.count(hit->Channel()) || amplitude_map.at(hit->Channel()) < hit->PeakAmplitude()) {
156  amplitude_map[hit->Channel()] = hit->PeakAmplitude();
157  }
158  }
159 
160  // fill up all of the signals
161  for (auto const &pair: amplitude_map) {
162  fSignal[angle_bin][geo->View(pair.first)]->Fill(pair.second);
163  }
164 
165  // now get the background noise RMS
166 
167  // figure out which channels do not have any energy depositions
168  std::vector<raw::ChannelID_t> allChannels = geo->ChannelsInTPCs();
169 
170  std::set<raw::ChannelID_t> channelSet;
171  for (raw::ChannelID_t c: allChannels) channelSet.insert(c);
172 
173  // ignore wires that are shorter than the max length
174  for (raw::ChannelID_t c: allChannels) {
175  geo::WireID wireID = geo->ChannelToWire(c).at(0);
176  const geo::WireGeo &wireGeo = geo->Wire(wireID);
177  float length = wireGeo.Length();
178  // TODO: don't hardcode
179  if (geo->SignalType(wireID) == geo::kInduction && length < 577.3) {
180  channelSet.erase(c);
181  }
182  }
183 
184  art::Handle<std::vector<sim::SimChannel>> simChannels;
185  ev.getByLabel("largeant", simChannels);
186  for (const sim::SimChannel &c: *simChannels) {
187  if (c.TDCIDEMap().size()) {
188  channelSet.erase(c.Channel());
189  }
190  }
191 
192  // now get the wires
193  art::Handle<std::vector<recob::Wire>> wires;
194  ev.getByLabel(fWireLabel, wires);
195 
196  for (const recob::Wire &wire: *wires) {
197  if (!channelSet.count(wire.Channel())) continue;
198  // get the noise RMS
199  const recob::Wire::RegionsOfInterest_t &ROI = wire.SignalROI();
200  int ncount = 0;
201  double rms_sum = 0.;
203  for (float v: range) {
204  rms_sum += v * v;
205  ncount ++;
206  }
207  }
208  float noise = sqrt(rms_sum / ncount);
209  // std::cout << "Noise: " << noise;
210  fNoise[geo->View(wire.Channel())]->Fill(noise);
211  }
212 
213 }
214 
215 DEFINE_ART_MODULE(numu::MuonS2NStudy)
Geometry description of a TPC wireThe wire is a single straight segment on a wire plane...
Definition: WireGeo.h:65
Utilities related to art service access.
Energy deposited on a readout channel by simulated tracks.
Definition: SimChannel.h:145
Declaration of signal hit object.
double Length() const
Returns the wire length in centimeters.
Definition: WireGeo.h:236
pdgs p
Definition: selectors.fcl:22
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
void analyze(art::Event const &e) override
const range_list_t & get_ranges() const
Returns the internal list of non-void ranges.
process_name hit
Definition: cheaterreco.fcl:51
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
std::vector< std::array< TH1D *, 3 > > fSignal
Access the description of detector geometry.
T abs(T value)
Signal from induction planes.
Definition: geo_types.h:145
Description of geometry of one entire detector.
Declaration of cluster object.
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
Provides recob::Track data product.
Provides a base class aware of world box coordinates.
BEGIN_PROLOG Z planes
WireGeo const & Wire(geo::WireID const &wireid) const
Returns the specified wire.
MuonS2NStudy & operator=(MuonS2NStudy const &)=delete
process_name can override from command line with o or output muon
Definition: runPID.fcl:28
std::array< TH1D *, 3 > fNoise
MuonS2NStudy(fhicl::ParameterSet const &p)
do i e
Class holding the regions of interest of signal from a channel.
Definition: Wire.h:118
Range class, with range and data.
Declaration of basic channel signal object.
art::ServiceHandle< art::TFileService > tfs
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
art framework interface to geometry description
BEGIN_PROLOG could also be cout
std::vector< raw::ChannelID_t > ChannelsInTPCs() const
Returns an std::vector&lt;ChannelID_t&gt; in all TPCs in a TPCSet.