35 #include "CLHEP/Random/RandFlat.h" 45 class NoiseWaveformDump;
87 std::string
const instanceName =
"NoiseWaveformDump";
103 -> declareEngine(instanceName, p,
"SeedForNoiseWaveformDump"),
107 if (std::getenv(
"CLUSTER") && std::getenv(
"PROCESS")) {
109 string(std::getenv(
"CLUSTER")) +
"-" + string(std::getenv(
"PROCESS")) +
"-";
113 throw cet::exception(
"NoiseWaveformDump") <<
"DigitModuleLabel is empty";
128 for (
unsigned int i = 0; i < 5; i++) {
129 std::ostringstream name;
164 for (
unsigned int i = 0;
167 std::ostringstream name;
182 cout <<
"Event " << evt.
id().
run() <<
" " << evt.
id().
subRun() <<
" " << evt.
id().
event() << endl;
187 std::cout <<
" !!!!! Size of digitVecHandle: " << digitVecHandle->size() << std::endl;
188 if (!digitVecHandle->size())
return;
195 std::vector<raw::RawDigit>
const& rawDigits = *digitVecHandle;
197 unsigned int dataSize = digitVec0.
Samples();
198 if (dataSize != detProp.ReadOutWindowSize()) {
199 throw cet::exception(
"NoiseWaveformDumpNoiseWaveformDump") <<
"Bad dataSize: " << dataSize;
203 std::map<raw::ChannelID_t, raw::RawDigit const*> rawdigitMap;
205 for (
size_t rdIter = 0; rdIter < rawDigits.size(); ++rdIter) {
206 chnum = rawDigits[rdIter].Channel();
209 rawdigitMap[chnum] = &rawDigits[rdIter];
214 std::cout <<
" !!!!! Size of simChannelHandle: " << simChannelHandle->size() << std::endl;
216 if (simChannelHandle->size() > 0) {
220 for (
auto const& channel : (*simChannelHandle)) {
227 bool hasEnergyDeposit =
false;
230 auto const& timeSlices = channel.TDCIDEMap();
231 for (
auto const& [tpctime, energyDeposits] : timeSlices) {
233 unsigned int tdctick =
static_cast<unsigned int>(clockData.TPCTDC2Tick(
double(tpctime)));
234 if (tdctick < 0 || tdctick > (dataSize - 1))
continue;
237 for (
auto const& energyDeposit : energyDeposits) {
238 if ((energyDeposit.energy > 0) || (energyDeposit.numElectrons > 0)) {
239 hasEnergyDeposit =
true;
243 if (hasEnergyDeposit)
break;
245 if (hasEnergyDeposit) rawdigitMap.erase(ch1);
251 std::vector<raw::ChannelID_t> noisechannels;
253 iter != rawdigitMap.end();
255 noisechannels.push_back(iter->first);
258 std::cout <<
" !!!!! size of noisechannels: " << noisechannels.size() << std::endl;
259 if (!noisechannels.size())
return;
262 int noisechancount = 0;
265 auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
266 std::vector<size_t> randigitmap;
267 for (
size_t i = 0; i < noisechannels.size(); ++i)
268 randigitmap.push_back(i);
269 std::shuffle(randigitmap.begin(), randigitmap.end(), std::mt19937(
seed));
271 std::string dummystr6 =
"none ";
272 std::string dummystr7 =
"none ";
274 for (
size_t rdIter = 0; rdIter < noisechannels.size(); ++rdIter) {
278 size_t ranIdx = randigitmap[rdIter];
279 auto digitVec = rawdigitMap[noisechannels[ranIdx]];
281 std::vector<short> rawadc(dataSize);
282 std::vector<short> adcvec(dataSize);
283 raw::Uncompress(digitVec->ADCs(), rawadc, digitVec->GetPedestal(), digitVec->Compression());
284 for (
size_t j = 0; j < rawadc.size(); ++j) {
285 adcvec[j] = rawadc[j] - digitVec->GetPedestal();
292 for (
unsigned int i = 0; i < 5; ++i) {
304 for (
unsigned int itck = 0; itck < dataSize; ++itck) {
310 for (
unsigned int itck = start_tick; itck < (start_tick +
fShortWaveformSize); ++itck) {
317 std::cout <<
"Total number of noise channels " << noisechancount << std::endl;
int c2numpy_init(c2numpy_writer *writer, const std::string outputFilePrefix, int32_t numRowsPerFile)
base_engine_t & createEngine(seed_t seed)
int c2numpy_int32(c2numpy_writer *writer, int32_t data)
static std::string ViewName(geo::View_t view)
Returns the name of the specified view.
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
Collection of charge vs time digitized from a single readout channel.
Definition of basic raw digits.
EDAnalyzer(fhicl::ParameterSet const &pset)
int c2numpy_close(c2numpy_writer *writer)
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
int c2numpy_addcolumn(c2numpy_writer *writer, const std::string name, c2numpy_type type)
#define DEFINE_ART_MODULE(klass)
Collect all the RawData header files together.
int c2numpy_uint32(c2numpy_writer *writer, uint32_t data)
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
int c2numpy_float32(c2numpy_writer *writer, float data)
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Encapsulate the construction of a single detector plane.
View_t View(PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
int c2numpy_uint16(c2numpy_writer *writer, uint16_t data)
object containing MC truth information necessary for making RawDigits and doing back tracking ...
int c2numpy_int16(c2numpy_writer *writer, int16_t data)
EventNumber_t event() const
unsigned int ChannelID_t
Type representing the ID of a readout channel.
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
SubRunNumber_t subRun() const
int c2numpy_string(c2numpy_writer *writer, const char *data)
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception