26 #include <TGeoVolume.h> 35 #include <torch/script.h> 36 #include <torch/torch.h> 88 produces<std::vector<raw::RawDigit>>();
95 if (detProp.NumberTimeSamples() > 6000) {
96 std::cerr <<
"InfillChannels_module.cc: Networks cannot handle more than 6000 time ticks\n";
100 typedef std::array<short, 6000> vecAdc;
101 std::map<raw::ChannelID_t, vecAdc> infilledAdcs;
102 torch::Tensor maskedRopTensor;
103 torch::Tensor infilledRopTensor;
109 maskedRopTensor = torch::zeros(
110 {1, 1 ,6000,
fGeom->
Nchannels(currentRop)}, torch::dtype(torch::kFloat32).device(torch::kCPU).requires_grad(
false)
112 auto maskedRopTensorAccess = maskedRopTensor.accessor<
float, 4>();
121 if (rop != currentRop)
continue;
126 for (
unsigned int tick = 0;
tick < adcs.size(); ++
tick) {
127 const int adc = adcs[
tick] ?
int(adcs[
tick]) - dig.GetPedestal() : 0;
129 maskedRopTensorAccess[0][0][
tick][dig.Channel() - firstCh] =
adc;
134 std::vector<torch::jit::IValue>
inputs;
135 inputs.push_back(maskedRopTensor);
137 torch::NoGradGuard no_grad_guard;
141 torch::NoGradGuard no_grad_guard;
146 auto infilledRopTensorAccess = infilledRopTensor.accessor<
float, 4>();
149 for (
unsigned int tick = 0;
tick < detProp.NumberTimeSamples(); ++
tick) {
150 infilledAdcs[ch][
tick] = (short)std::round(infilledRopTensorAccess[0][0][
tick][ch - firstCh]);
157 auto infilledDigs = std::make_unique<std::vector<raw::RawDigit>>();
158 *infilledDigs = *digs;
160 if (infilledAdcs.count(dig.Channel())) {
162 infilledAdcs[dig.Channel()].begin(), (infilledAdcs[dig.Channel()].begin() + detProp.NumberTimeSamples())
166 auto infilledAdcMin = std::min_element(infilledAdc.begin(), infilledAdc.end());
167 short ped = *infilledAdcMin < 0 ?
std::abs(*infilledAdcMin) + 1 : 0;
168 for (
short&
adc : infilledAdc)
adc += ped;
171 dig =
raw::RawDigit(dig.Channel(), dig.Samples(), infilledAdc, dig.Compression());
194 for (iRop = rBegin; iRop != rEnd; ++iRop) {
195 bool hasDeadCh =
false;
202 if (!hasDeadCh)
continue;
208 if (tpcVol->Capacity() > 1000000) {
211 std::cerr <<
"InfillChannels_module.cc: Induction view network cannot handle more then 800 channels\n";
215 std::cerr <<
"InfillChannels_module.cc: Collection view network cannot handle more then 400 channels\n";
228 if (fDeadChannels.count(ch + 1)) {
234 std::cerr <<
"There are dead channel gap larger than what was seen in training --- ";
235 std::cerr <<
"**Consider retraining collection plane infill network**" <<
std::endl;
238 std::cerr <<
"There are dead channel gap larger than what was seen in training --- ";
239 std::cerr <<
"**Consider retraining induction plane infill network**" <<
std::endl;
246 std::cout <<
"Loading modules..." <<
std::endl;
248 if (networkPath ==
nullptr) {
249 std::cerr <<
"InfillChannels_module.cc: Environment variable " <<
fNetworkPath <<
" was not found";
257 std::cout <<
"Induction module loaded from " << networkLocInduction <<
std::endl;
260 std::cerr <<
"error loading the model\n";
261 std::cerr << err.what();
265 std::cout <<
"Collection module loaded from " << networkLocCollection <<
std::endl;
268 std::cerr <<
"error loading the model\n";
269 std::cerr << err.what();
void produce(art::Event &e) override
std::vector< geo::TPCID > ROPtoTPCs(readout::ROPID const &ropid) const
Returns a list of ID of TPCs the specified ROP spans.
std::set< raw::ChannelID_t > fDeadChannels
Collection of charge vs time digitized from a single readout channel.
const std::string fNetworkNameCollection
std::set< raw::ChannelID_t > fBadChannels
static constexpr BeginPos_t begin_pos
Handle< PROD > getHandle(SelectorBase const &) const
Base forward iterator browsing all readout plane IDs in the detector.
InfillChannels(fhicl::ParameterSet const &p)
EDProducer(fhicl::ParameterSet const &pset)
Geometry information for a single TPC.
static constexpr EndPos_t end_pos
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
virtual const provider_type * provider() const override
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
const std::string fInputLabel
art framework interface to geometry description
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
InfillChannels & operator=(InfillChannels const &)=delete
std::set< raw::ChannelID_t > fNoisyChannels
const geo::GeometryCore * fGeom
#define DEFINE_ART_MODULE(klass)
Signal from induction planes.
raw::ChannelID_t FirstChannelInROP(readout::ROPID const &ropid) const
Returns the ID of the first channel in the specified readout plane.
nvidia::inferenceserver::client::Error Error
std::string getenv(std::string const &name)
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
const TGeoVolume * ActiveVolume() const
The data type to uniquely identify a TPC.
Description of geometry of one entire detector.
void err(const char *fmt,...)
Class identifying a set of planes sharing readout channels.
readout::ROPID ChannelToROP(raw::ChannelID_t channel) const
const std::string fNetworkPath
const std::string fNetworkNameInduction
void SetPedestal(float ped, float sigma=1.)
Set pedestal and its RMS (the latter is 0 by default)
void Compress(std::vector< short > &adc, raw::Compress_t compress)
Compresses a raw data buffer.
Access the description of detector geometry.
torch::jit::script::Module fInductionModule
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
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.
torch::jit::script::Module fCollectionModule
QTextStream & endl(QTextStream &s)
Signal from collection planes.
def load(filename, jpath="depos")
std::set< readout::ROPID > fActiveRops