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"
63 void produce(art::Event&
e)
override;
75 , _feb_data_producer(
p.get<std::string>(
"FEBDataProducer"))
76 , _adc_threshold(
p.get<uint16_t>(
"ADCThreshold"))
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>>();
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);
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>);
95 art::Handle<std::vector<sbnd::crt::FEBData>> feb_data_h;
96 e.getByLabel(_feb_data_producer, feb_data_h);
99 if (!feb_data_h.isValid()) {
100 throw art::Exception(art::errors::Configuration) <<
"could not locate FEBData." << std::endl;;
103 std::vector<art::Ptr<sbnd::crt::FEBData>> feb_data_v;
104 art::fill_ptr_vector(feb_data_v, feb_data_h);
106 art::FindManyP<sim::AuxDetIDE, sbnd::crt::FEBTruthInfo> febdata_to_ides (feb_data_h, e, _feb_data_producer);
108 art::PtrMaker<sbnd::crt::CRTData> makeDataPtr(e);
110 for (
size_t feb_i = 0; feb_i < feb_data_v.size(); feb_i++) {
112 auto const feb_data = feb_data_v[feb_i];
113 mf::LogDebug(
"CRTSlimmer") <<
"FEB " << feb_i <<
" with mac " << feb_data->Mac5() << std::endl;
115 auto ides = febdata_to_ides.at(feb_data.key());
116 mf::LogDebug(
"CRTSlimmer") <<
"We have " << ides.size() <<
" IDEs." << std::endl;
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++) {
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;
129 auto adcs = feb_data->ADC();
131 for (
size_t i = 0; i < adcs.size(); i+=2) {
134 if (not (adcs[i] >= _adc_threshold
and adcs[i+1] >= _adc_threshold)) {
138 for (
size_t sipm = 0; sipm < 2; sipm++) {
144 mf::LogDebug(
"CRTSlimmer") <<
"Adding SiPM " << i + sipm <<
" with mac " << feb_data->Mac5()
145 <<
" mapped to channel " << crt_data.
Channel() << std::endl;
147 crt_data_v->emplace_back(std::move(crt_data));
149 art::Ptr<sbnd::crt::CRTData> crt_data_p = makeDataPtr(crt_data_v->size() - 1);
152 crtdata_to_febdata_assns->addSingle(crt_data_p, feb_data);
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);
165 mf::LogInfo(
"CRTSlimmer") <<
"Creating " << crt_data_v->size()
166 <<
" CRTData products." << std::endl;
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));
std::string _feb_data_producer
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)
stream1 can override from command line with o or output services user sbnd