All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRTSlimmer_module.cc
Go to the documentation of this file.
1 /**
2  * \brief Makes sbnd::crt::CRTData from sbnd::crt::FEBData
3  *
4  * \details This class loops over sbnd::crt::FEBData objects and only selects
5  * strips which have both SiPM ADC values above a certain (configurable) threshold.
6  * The two SiPMs in the selected strips are then saved in sbnd::crt::CRTData objects.
7  *
8  * \author Marco Del Tutto
9  */
10 
11 ////////////////////////////////////////////////////////////////////////
12 // Class: CRTSlimmer
13 // Plugin Type: producer (Unknown Unknown)
14 // File: CRTSlimmer_module.cc
15 //
16 // Generated at Thu Mar 24 11:27:06 2022 by Marco Del Tutto using cetskelgen
17 // from version .
18 ////////////////////////////////////////////////////////////////////////
19 
20 #include "art/Framework/Core/EDProducer.h"
21 #include "art/Framework/Core/ModuleMacros.h"
22 #include "art/Framework/Principal/Event.h"
23 #include "art/Framework/Principal/Handle.h"
24 #include "art/Framework/Principal/Run.h"
25 #include "art/Framework/Principal/SubRun.h"
26 #include "canvas/Utilities/InputTag.h"
27 #include "fhiclcpp/ParameterSet.h"
28 #include "messagefacility/MessageLogger/MessageLogger.h"
29 #include "canvas/Persistency/Common/FindManyP.h"
30 #include "canvas/Persistency/Common/Ptr.h"
31 #include "canvas/Persistency/Common/Assns.h"
32 #include "art/Persistency/Common/PtrMaker.h"
33 
34 
35 #include <memory>
36 #include <math.h>
37 
42 
43 namespace sbnd {
44  namespace crt {
45  class CRTSlimmer;
46  }
47 }
48 
49 
50 class sbnd::crt::CRTSlimmer : public art::EDProducer {
51 public:
52  explicit CRTSlimmer(fhicl::ParameterSet const& p);
53  // The compiler-generated destructor is fine for non-base
54  // classes without bare pointers or other resource use.
55 
56  // Plugins should not be copied or assigned.
57  CRTSlimmer(CRTSlimmer const&) = delete;
58  CRTSlimmer(CRTSlimmer&&) = delete;
59  CRTSlimmer& operator=(CRTSlimmer const&) = delete;
60  CRTSlimmer& operator=(CRTSlimmer&&) = delete;
61 
62  // Required functions.
63  void produce(art::Event& e) override;
64 
65 private:
66 
67  std::string _feb_data_producer;
68  uint16_t _adc_threshold;
69 
70 };
71 
72 
73 sbnd::crt::CRTSlimmer::CRTSlimmer(fhicl::ParameterSet const& p)
74  : EDProducer{p}
75  , _feb_data_producer(p.get<std::string>("FEBDataProducer"))
76  , _adc_threshold(p.get<uint16_t>("ADCThreshold"))
77 {
78  produces<std::vector<sbnd::crt::CRTData>>();
79  produces<art::Assns<sbnd::crt::CRTData, sbnd::crt::FEBData>>();
80  produces<art::Assns<sbnd::crt::CRTData, sim::AuxDetIDE>>();
81 
82  consumes<std::vector<sbnd::crt::FEBData>>(_feb_data_producer);
83  consumes<art::Assns<sbnd::crt::FEBData, sim::AuxDetIDE, sbnd::crt::FEBTruthInfo>>(_feb_data_producer);
84 }
85 
87 {
88  // Implementation of required member function here.
89  std::unique_ptr<std::vector<sbnd::crt::CRTData>> crt_data_v(new std::vector<sbnd::crt::CRTData>);
90  std::unique_ptr<art::Assns<sbnd::crt::CRTData, sbnd::crt::FEBData>> crtdata_to_febdata_assns
91  (new art::Assns<sbnd::crt::CRTData, sbnd::crt::FEBData>);
92  std::unique_ptr<art::Assns<sbnd::crt::CRTData, sim::AuxDetIDE>> crtdata_to_ide_assns
93  (new art::Assns<sbnd::crt::CRTData, sim::AuxDetIDE>);
94 
95  art::Handle<std::vector<sbnd::crt::FEBData>> feb_data_h;
96  e.getByLabel(_feb_data_producer, feb_data_h);
97 
98  // make sure hits look good
99  if (!feb_data_h.isValid()) {
100  throw art::Exception(art::errors::Configuration) << "could not locate FEBData." << std::endl;;
101  }
102 
103  std::vector<art::Ptr<sbnd::crt::FEBData>> feb_data_v;
104  art::fill_ptr_vector(feb_data_v, feb_data_h);
105 
106  art::FindManyP<sim::AuxDetIDE, sbnd::crt::FEBTruthInfo> febdata_to_ides (feb_data_h, e, _feb_data_producer);
107 
108  art::PtrMaker<sbnd::crt::CRTData> makeDataPtr(e);
109 
110  for (size_t feb_i = 0; feb_i < feb_data_v.size(); feb_i++) {
111 
112  auto const feb_data = feb_data_v[feb_i];
113  mf::LogDebug("CRTSlimmer") << "FEB " << feb_i << " with mac " << feb_data->Mac5() << std::endl;
114 
115  auto ides = febdata_to_ides.at(feb_data.key());
116  mf::LogDebug("CRTSlimmer") << "We have " << ides.size() << " IDEs." << std::endl;
117 
118  // Construct a map to go from SiPM ID to the index of the IDE
119  // FEBTruthInfo stores, for each AuxDetIDE, a vector containing
120  // the SiPM IDs contributing to that energy deposit
121  std::map<int, std::vector<int>> sipm_to_ideids;
122  for (size_t j = 0; j < 32; j++) sipm_to_ideids[j] = std::vector<int>();
123  for (size_t ide_i = 0; ide_i < febdata_to_ides.data(feb_i).size(); ide_i++) {
124  const sbnd::crt::FEBTruthInfo *fti = febdata_to_ides.data(feb_i)[ide_i];
125  sipm_to_ideids[fti->GetChannel()].push_back(ide_i);
126  mf::LogDebug("CRTSlimmer") << "ide_i " << ide_i << " ene " << ides[ide_i]->energyDeposited << " fti->GetChannel() " << fti->GetChannel() << std::endl;
127  }
128 
129  auto adcs = feb_data->ADC();
130 
131  for (size_t i = 0; i < adcs.size(); i+=2) {
132 
133  // Both sipms need to be above threshold to save them
134  if (not (adcs[i] >= _adc_threshold and adcs[i+1] >= _adc_threshold)) {
135  continue;
136  }
137 
138  for (size_t sipm = 0; sipm < 2; sipm++) {
139  sbnd::crt::CRTData crt_data = sbnd::crt::CRTData(feb_data->Mac5() * 32 + i + sipm,
140  feb_data->Ts0(),
141  feb_data->Ts1(),
142  adcs[i+sipm]);
143 
144  mf::LogDebug("CRTSlimmer") << "Adding SiPM " << i + sipm << " with mac " << feb_data->Mac5()
145  << " mapped to channel " << crt_data.Channel() << std::endl;
146 
147  crt_data_v->emplace_back(std::move(crt_data));
148 
149  art::Ptr<sbnd::crt::CRTData> crt_data_p = makeDataPtr(crt_data_v->size() - 1);
150 
151  // Create the association between CRTData and FEBData
152  crtdata_to_febdata_assns->addSingle(crt_data_p, feb_data);
153 
154  // Create the association between CRTData and AuxDetIDEs
155  auto & ide_ids = sipm_to_ideids[i];
156  for (auto ide_id: ide_ids) {
157  auto ide = ides[ide_id];
158  mf::LogDebug("CRTSlimmer") << "Adding IDE with ID " << ide_id << std::endl;
159  crtdata_to_ide_assns->addSingle(crt_data_p, ide);
160  }
161  }
162  }
163  }
164 
165  mf::LogInfo("CRTSlimmer") << "Creating " << crt_data_v->size()
166  << " CRTData products." << std::endl;
167 
168  e.put(std::move(crt_data_v));
169  e.put(std::move(crtdata_to_febdata_assns));
170  e.put(std::move(crtdata_to_ide_assns));
171 }
172 
173 
174 
175 DEFINE_ART_MODULE(sbnd::crt::CRTSlimmer)
176 
177 
178 
uint32_t Channel() const
Definition: CRTData.cxx:20
pdgs p
Definition: selectors.fcl:22
CRTSlimmer & operator=(CRTSlimmer const &)=delete
object containing MC truth information necessary for making RawDigits and doing back tracking ...
void produce(art::Event &e) override
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
CRTSlimmer(fhicl::ParameterSet const &p)
do i e
stream1 can override from command line with o or output services user sbnd
process_name crt