26 #include "art_root_io/TFileService.h" 36 #include "CLHEP/Random/RandFlat.h" 50 template <
typename Hist>
51 void writeAndDelete(Hist*&
hist)
71 Comment(
"Text files with all needed data dumped.")};
74 Comment(
"Numpy files with patches.")};
78 Comment(
"Dump to ROOT histogram file (replaces the text files)")};
81 Comment(
"Dump to Numpy file (replaces the text files)")};
85 Comment(
"use selected views only, or all views if empty list")};
89 Comment(
"use selected tpc's only, or all tpc's if empty list")};
92 Comment(
"Crop the projection to the event region plus margin")};
107 Comment(
"Fraction of stopping Trk patches to keep")};
110 Comment(
"Fraction of clean track patches to keep")};
155 std::vector<double>
const&
x,
156 std::vector<double>
const&
y,
157 std::vector<double>
const&
w,
158 double* params)
const;
229 std::cout <<
"nEm = " <<
nEm << std::endl;
230 std::cout <<
"nTrk = " <<
nTrk << std::endl;
231 std::cout <<
"nMichel = " <<
nMichel << std::endl;
232 std::cout <<
"nNone = " <<
nNone << std::endl;
233 std::cout << std::endl;
234 std::cout <<
"nEm_sel = " <<
nEm_sel << std::endl;
235 std::cout <<
"nTrk_sel = " <<
nTrk_sel << std::endl;
236 std::cout <<
"nMichel_sel = " <<
nMichel_sel << std::endl;
237 std::cout <<
"nNone_sel = " <<
nNone_sel << std::endl;
238 std::cout <<
"nStopTrk_sel = " <<
nStopTrk_sel << std::endl;
239 std::cout <<
"nCleanTrk_sel = " <<
nCleanTrk_sel << std::endl;
246 fEvent =
event.id().event();
252 std::ostringstream os;
255 std::cout <<
"analyze " << os.str() << std::endl;
257 auto const clockData =
269 unsigned int w0, w1, d0, d1;
270 if (
fCrop && saveSim) {
272 std::cout <<
" crop: " << w0 <<
" " << w1 <<
" " << d0 <<
" " << d1 << std::endl;
288 std::ostringstream ss1;
289 ss1 <<
"raw_" << os.str() <<
"_tpc_" <<
fSelectedTPC[i] <<
"_view_" 294 tfs->make<TH2F>((ss1.str() +
"_raw").c_str(),
"ADC", w1 - w0, w0, w1, d1 - d0, d0, d1);
298 depHist = tfs->make<TH2F>(
299 (ss1.str() +
"_deposit").c_str(),
"Deposit", w1 - w0, w0, w1, d1 - d0, d0, d1);
300 pdgHist = tfs->make<TH2I>(
301 (ss1.str() +
"_pdg").c_str(),
"PDG", w1 - w0, w0, w1, d1 - d0, d0, d1);
304 for (
size_t w = w0;
w < w1; ++
w) {
306 for (
size_t d = d0;
d < d1; ++
d) {
307 rawHist->Fill(
w,
d,
raw[
d]);
312 for (
size_t d = d0;
d < d1; ++
d) {
317 for (
size_t d = d0;
d < d1; ++
d) {
318 pdgHist->Fill(
w,
d, pdg[
d]);
323 writeAndDelete(rawHist);
324 writeAndDelete(depHist);
325 writeAndDelete(pdgHist);
328 for (
size_t w = w0;
w < w1; ++
w) {
331 if (w_start <
int(w0) || w_start >
int(w1))
continue;
332 if (w_stop <
int(w0) || w_stop >
int(w1))
continue;
336 for (
size_t d = d0;
d < d1; ++
d) {
339 if (d_start <
int(d0) || d_start >
int(d1))
continue;
340 if (d_stop <
int(d0) || d_stop >
int(d1))
continue;
341 int y0 = 0,
y1 = 0,
y2 = 0,
y3 = 0;
342 if (deposit[
d] < 2
e-5 ||
raw[
d] < 0.05) {
345 if (flat.fire() >
fNone)
continue;
348 else if ((pdg[
d] & 0x0FFF) == 11) {
351 if ((pdg[
d] & 0xF000) == 0x2000) {
354 if (flat.fire() >
fMichel)
continue;
358 if (flat.fire() >
fEm)
continue;
366 int nPxlw0 = 0, nPxlw1 = 0, nPxld0 = 0, nPxld1 = 0;
368 std::vector<double> wfit, dfit, chgfit;
369 double total_trkchg = 0;
370 for (
int ww = w_start; ww < w_stop; ++ww) {
374 for (
int dd = d_start; dd < d_stop; ++dd) {
375 if (deposit1[dd] < 2
e-5 || raw1[dd] < 0.05)
continue;
376 if ((pdg1[dd] & 0x0FFF) != 11) {
379 chgfit.push_back(raw1[dd]);
380 total_trkchg += raw1[dd];
381 if (ww - w_start < 3) ++nPxlw0;
382 if (w_stop - ww - 1 < 3) ++nPxlw1;
383 if (dd - d_start < 3) ++nPxld0;
384 if (d_stop - dd - 1 < 3) ++nPxld1;
389 double fit_trkchg = 0;
392 if (!
WeightedFit(wfit.size(), wfit, dfit, chgfit, &parm[0])) {
393 for (
size_t j = 0; j < wfit.size(); ++j) {
394 if (
std::abs((dfit[j] - (parm[0] + wfit[j] * parm[1])) * cos(atan(parm[1]))) <
396 fit_trkchg += chgfit[j];
400 else if (!
WeightedFit(dfit.size(), dfit, wfit, chgfit, &parm[0])) {
401 for (
size_t j = 0; j < dfit.size(); ++j) {
402 if (
std::abs((wfit[j] - (parm[0] + dfit[j] * parm[1])) * cos(atan(parm[1]))) <
404 fit_trkchg += chgfit[j];
409 if (((nPxlw0) && (!nPxlw1) && (!nPxld0) && (!nPxld1)) ||
410 ((!nPxlw0) && (nPxlw1) && (!nPxld0) && (!nPxld1)) ||
411 ((!nPxlw0) && (!nPxlw1) && (nPxld0) && (!nPxld1)) ||
412 ((!nPxlw0) && (!nPxlw1) && (!nPxld0) && (nPxld1))) {
413 if (flat.fire() >
fStopTrk)
continue;
416 else if (total_trkchg && fit_trkchg / total_trkchg > 0.9) {
421 if (flat.fire() >
fTrk)
continue;
436 for (
int ww = w_start; ww < w_stop; ++ww) {
438 for (
int dd = d_start; dd < d_stop; ++dd) {
446 std::ostringstream ss1;
450 std::ofstream fout_raw, fout_deposit, fout_pdg;
452 fout_raw.open(ss1.str() +
".raw");
454 fout_deposit.open(ss1.str() +
".deposit");
455 fout_pdg.open(ss1.str() +
".pdg");
458 for (
size_t w = w0;
w < w1; ++
w) {
460 for (
size_t d = d0;
d < d1; ++
d) {
461 fout_raw <<
raw[
d] <<
" ";
463 fout_raw << std::endl;
467 for (
size_t d = d0;
d < d1; ++
d) {
468 fout_deposit <<
edep[
d] <<
" ";
470 fout_deposit << std::endl;
473 for (
size_t d = d0;
d < d1; ++
d) {
474 fout_pdg << pdg[
d] <<
" ";
476 fout_pdg << std::endl;
482 fout_deposit.close();
492 std::vector<double>
const&
x,
493 std::vector<double>
const&
y,
494 std::vector<double>
const&
w,
495 double* params)
const 503 Double_t eparams[2] = {};
505 for (Int_t i = 0; i <
n; i++) {
507 sumx2 += x[i] * x[i] * w[i];
509 sumy2 += y[i] * y[i] * w[i];
510 sumxy += x[i] * y[i] * w[i];
514 if (sumx2 * sumw - sumx * sumx == 0.)
return 1;
515 if (sumx2 - sumx * sumx / sumw == 0.)
return 1;
517 params[0] = (sumy * sumx2 - sumx * sumxy) / (sumx2 * sumw - sumx * sumx);
518 params[1] = (sumxy - sumx * sumy / sumw) / (sumx2 - sumx * sumx / sumw);
520 eparams[0] = sumx2 * (sumx2 * sumw - sumx * sumx);
521 eparams[1] = (sumx2 - sumx * sumx / sumw);
523 if (eparams[0] < 0. || eparams[1] < 0.)
return 1;
525 eparams[0] = sqrt(eparams[0]) / (sumx2 * sumw - sumx * sumx);
526 eparams[1] = sqrt(eparams[1]) / (sumx2 - sumx * sumx / sumw);
int c2numpy_init(c2numpy_writer *writer, const std::string outputFilePrefix, int32_t numRowsPerFile)
base_engine_t & createEngine(seed_t seed)
double fEm
patch size in drift dimension
unsigned int NTPC(CryostatID const &cryoid=cryostat_zero) const
Returns the total number of TPCs in the specified cryostat.
std::vector< float > const & wireEdep(size_t widx) const
Float_t y1[n_points_granero]
int WeightedFit(int n, std::vector< double > const &x, std::vector< double > const &y, std::vector< double > const &w, double *params) const
bool setEventData(const art::Event &event, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, unsigned int plane, unsigned int tpc, unsigned int cryo)
fhicl::Atom< double > None
int fPatch_size_d
patch size in wire dimension
fhicl::Sequence< int > SelectedTPC
constexpr auto abs(T v)
Returns the absolute value of the argument.
int c2numpy_uint8(c2numpy_writer *writer, uint8_t data)
fhicl::Atom< double > Michel
EDAnalyzer(fhicl::ParameterSet const &pset)
fhicl::Atom< bool > DumpToNumpy
Float_t y2[n_points_geant4]
int fRun
number of the event being processed
int c2numpy_close(c2numpy_writer *writer)
unsigned int NWires() const
geo::GeometryCore const * fGeometry
Access the description of detector geometry.
fhicl::Atom< int > Patch_size_d
unsigned int MaxPlanes() const
Returns the largest number of planes among all TPCs in this detector.
int c2numpy_addcolumn(c2numpy_writer *writer, const std::string name, c2numpy_type type)
#define DEFINE_ART_MODULE(klass)
fhicl::Atom< int > Patch_size_w
fhicl::Atom< double > StopTrk
fhicl::Atom< bool > DumpToRoot
int fPatch_size_w
crop data to event (set to false when dumping noise!)
std::vector< int > fSelectedTPC
fhicl::Atom< std::string > OutNumpyFileName
nnet::TrainingDataAlg fTrainingDataAlg
std::string fOutTextFilePath
bool fCrop
number of the sub-run being processed
bool findCrop(float max_e_cut, unsigned int &w0, unsigned int &w1, unsigned int &d0, unsigned int &d1) const
std::string fOutNumpyFileName
Description of geometry of one entire detector.
fhicl::Atom< std::string > OutTextFilePath
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)
fhicl::Sequence< int > SelectedView
int fSubRun
number of the run being processed
void analyze(const art::Event &event) override
fhicl::Atom< double > Trk
std::vector< int > fSelectedPlane
fhicl::Atom< double > CleanTrk
int c2numpy_uint16(c2numpy_writer *writer, uint16_t data)
PointIdTrainingData(Parameters const &config)
CLHEP::HepRandomEngine & fEngine
art-managed random-number engine
unsigned int NScaledDrifts() const
EventNumber_t event() const
std::vector< int > const & wirePdg(size_t widx) const
Float_t y3[n_points_geant4]
SubRunNumber_t subRun() const
art framework interface to geometry description
Event finding and building.
std::vector< float > const & wireData(size_t widx) const