33 #include "art/Framework/Core/ModuleMacros.h"
34 #include "art/Framework/Core/EDProducer.h"
35 #include "art/Framework/Principal/Event.h"
36 #include "art/Framework/Principal/Handle.h"
37 #include "art/Framework/Services/Registry/ServiceHandle.h"
38 #include "art_root_io/TFileService.h"
39 #include "art_root_io/TFileDirectory.h"
40 #include "art/Utilities/make_tool.h"
41 #include "fhiclcpp/ParameterSet.h"
42 #include "messagefacility/MessageLogger/MessageLogger.h"
45 #include "nurandom/RandomUtils/NuRandomService.h"
64 #include "icarus_signal_processing/Filters/ICARUSFFT.h"
79 void produce (art::Event&
evt);
86 void MakeADCVec(std::vector<short>& adc,
icarusutil::TimeVec const& charge,
float ped_mean)
const;
99 const float adcsaturation = 4095;
112 using FFTPointer = std::unique_ptr<icarus_signal_processing::ICARUSFFT<double>>;
126 , fGeometry(*lar::providerFrom<geo::Geometry>()),
127 fPedestalRetrievalAlg(*lar::providerFrom<lariov::DetPedestalService>())
131 produces< std::vector<raw::RawDigit> >();
133 TString
compression(pset.get< std::string >(
"CompressionType"));
140 OverlayICARUS::~OverlayICARUS() {}
145 fInputRawDataLabel = p.get< art::InputTag >(
"InputRawDataLabel",
"daq");
146 fDriftEModuleLabel = p.get< art::InputTag >(
"DriftEModuleLabel",
"largeant");
149 auto const detprop = art::ServiceHandle<detinfo::DetectorPropertiesService>()->DataForJob();
151 fSignalShapingService = art::ServiceHandle<icarusutil::SignalShapingICARUSService>{}.get();
153 fFFT = std::make_unique<icarus_signal_processing::ICARUSFFT<double>>(detprop.NumberTimeSamples());
159 void OverlayICARUS::beginJob()
162 art::ServiceHandle<art::TFileService>
tfs;
164 fSimCharge = tfs->make<TH1F>(
"fSimCharge",
"simulated charge", 150, 0, 1500);
165 fSimChargeWire = tfs->make<TH2F>(
"fSimChargeWire",
"simulated charge", 5600,0.,5600.,500, 0, 1500);
171 void OverlayICARUS::endJob()
174 void OverlayICARUS::produce(art::Event&
evt)
183 art::Handle<std::vector<raw::RawDigit>> inputRawDigitHandle;
185 evt.getByLabel(fInputRawDataLabel, inputRawDigitHandle);
187 if (!inputRawDigitHandle.isValid())
throw std::runtime_error(
"Failed to read back RawDigits for overlay!");
190 art::Handle<std::vector<sim::SimChannel>> simChanHandle;
191 evt.getByLabel(fDriftEModuleLabel, simChanHandle);
193 if (!simChanHandle.isValid())
throw std::runtime_error(
"Failed to recover the SimChannel information for the overlay");
196 using SimChannelMap = std::unordered_map<raw::ChannelID_t, const sim::SimChannel*>;
200 for(
const auto& simChannel : *simChanHandle) simChannelMap[simChannel.Channel()] = &simChannel;
204 std::unique_ptr< std::vector<raw::RawDigit>> digcol(
new std::vector<raw::RawDigit>);
205 digcol->reserve(inputRawDigitHandle->size());
208 std::vector<short> adcvec;
212 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService>()->DataFor(evt);
215 for(
const auto& rawDigit : *inputRawDigitHandle)
221 std::vector<geo::WireID> widVec = fGeometry.ChannelToWire(channel);
226 size_t plane = widVec[0].Plane;
232 adcvec.resize(rawDigit.Samples(),0);
233 zeroCharge.resize(rawDigit.Samples(),0);
239 SimChannelMap::const_iterator simChanItr = simChannelMap.find(channel);
241 if (simChanItr != simChannelMap.end())
253 double gain = fSignalShapingService->GetASICGain(channel) *
sampling_rate(clockData) * 1.e-3;
256 for(
const auto& tdcide : simChan->
TDCIDEMap())
258 unsigned int tdc = tdcide.first;
261 int tick = clockData.TPCTDC2Tick(tdc);
264 if (tick < 0 ||tick >
int(adcvec.size()))
266 std::cout <<
"tick out of range: " << tick <<
", tdc: " << tdc << std::endl;
271 double charge = simChan->
Charge(tdc);
273 chargeWork[
tick] += charge / gain;
278 fFFT->convolute(chargeWork, response.
getConvKernel(), fSignalShapingService->ResponseTOffset(channel));
281 float pedestal = fPedestalRetrievalAlg.PedMean(channel);
284 MakeADCVec(adcvec, chargeWork, pedestal);
287 if(fMakeHistograms && plane==2)
289 short area = std::accumulate(adcvec.begin(),adcvec.end(),0,[](
const auto& val,
const auto& sum){
return sum + val - 400;});
293 fSimCharge->Fill(area);
294 fSimChargeWire->Fill(widVec[0].Wire,area);
308 rd.
SetPedestal(rawDigit.GetPedestal(),rawDigit.GetSigma());
309 digcol->push_back(std::move(rd));
312 evt.put(std::move(digcol));
317 void OverlayICARUS::MakeADCVec(std::vector<short>& adcvec,
icarusutil::TimeVec const& chargevec,
float ped_mean)
const
319 for(
unsigned int i = 0; i < adcvec.size(); ++i)
322 float adcval = chargevec[i] + ped_mean;
325 adcval = std::max(
float(0.), std::min(adcval, adcsaturation));
328 adcvec[i] += std::round(adcval - ped_mean);
TString compression(pset.get< std::string >("CompressionType"))
enum raw::_compress Compress_t
std::map< int, art::Ptr< sim::SimChannel > > SimChannelMap
Collection of charge vs time digitized from a single readout channel.
Energy deposited on a readout channel by simulated tracks.
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
art::InputTag fDriftEModuleLabel
module making the ionization electrons
Definition of basic raw digits.
raw::Compress_t fCompression
compression type to use
icarusutil::SignalShapingICARUSService * fSignalShapingService
Access to the response functions.
Access the description of detector geometry.
This is the interface class for a tool to handle a GenNoise for the overall response.
double Charge(TDC_t tdc) const
Returns the total number of ionization electrons on this channel in the specified TDC...
Collect all the RawData header files together.
std::vector< SigProcPrecision > TimeVec
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Description of geometry of one entire detector.
art::InputTag fInputRawDataLabel
Label for the underlying raw digit data.
ResponseParams(double charge, size_t time)
const lariov::DetPedestalProvider & fPedestalRetrievalAlg
Keep track of an instance to the pedestal retrieval alg.
std::unique_ptr< icarus_signal_processing::ICARUSFFT< double >> FFTPointer
void SetPedestal(float ped, float sigma=1.)
Set pedestal and its RMS (the latter is 0 by default)
object containing MC truth information necessary for making RawDigits and doing back tracking ...
Interface for experiment-specific channel quality info provider.
void Compress(std::vector< short > &adc, raw::Compress_t compress)
Compresses a raw data buffer.
TDCIDEs_t const & TDCIDEMap() const
Returns all the deposited energy information as stored.
art::ServiceHandle< art::TFileService > tfs
const geo::GeometryCore & fGeometry
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Interface for experiment-specific service for channel quality info.
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
Tools and modules for checking out the basics of the Monte Carlo.
art framework interface to geometry description
BEGIN_PROLOG could also be cout