14 #ifndef SPMultiTpcDump_Module 15 #define SPMultiTpcDump_Module 35 #include "art_root_io/TFileService.h" 93 bool InsideFidVol(TVector3
const & pvtx)
const;
99 TVector3
const &
vtx3d,
const size_t cryo,
const size_t tpc,
const size_t plane)
const;
126 fGenieGenLabel(config().GenModuleLabel()),
127 fSaveDepositMap(config().SaveDepositMap()),
128 fSavePdgMap(config().SavePdgMap()),
129 fFidVolCut(config().FidVolCut())
139 fTree = tfs->make<TTree>(
"event",
"Event level info");
147 fTree2D = tfs->make<TTree>(
"plane",
"Vertex 2D info");
161 auto mctruthHandle =
event.getHandle< std::vector<simb::MCTruth> >(
fGenieGenLabel);
162 if (!mctruthHandle) {
return false; }
164 for (
auto const & mc : (*mctruthHandle))
168 const TLorentzVector& pvtx = mc.GetNeutrino().Nu().Position();
169 TVector3 vtx(pvtx.X(), pvtx.Y(), pvtx.Z());
171 CorrOffset(detProp, vtx, mc.GetNeutrino().Nu());
179 double v[3] = {vtx.X(), vtx.Y(), vtx.Z()};
183 for (
size_t i = 0; i < 3; ++i)
214 fEvent =
event.id().event();
223 std::ostringstream os;
225 std::cout <<
"analyze " << os.str() <<
std::endl;
228 size_t plane_align0[3] = { 1, 0, 2 };
229 size_t plane_align1[3] = { 2, 1, 0 };
230 size_t max_align = 0;
231 for (
size_t i = 0; i < 3; ++i)
233 if (plane_align0[i] > max_align) max_align = plane_align0[i];
234 if (plane_align1[i] > max_align) max_align = plane_align1[i];
237 size_t weff[3] = { 404, 404, 485 };
238 size_t tpcs[3] = { 2, 2, 6 };
242 bool goodEvent =
false;
243 unsigned int gd0 = 0, gd1 = 0;
244 for (
int p = 2;
p >= 0; --
p)
248 size_t max_offset = (
p < 2) ? 752 : 0;
250 size_t ntotw = (tpcs[2] - 1) * weff[
p] + wire_size + tpcs[1] * max_offset;
251 size_t ntotd = tpcs[0] * drift_size + (apa_gap + max_align) * (tpcs[0] / 2);
253 std::cout <<
"Plane: " <<
p <<
", wires: " << ntotw <<
" drift: " << ntotd <<
std::endl;
256 size_t a, maxArea = 0;
259 size_t tpc_z =
t / (tpcs[0] * tpcs[1]);
260 size_t tpc_y = (
t / tpcs[0]) % tpcs[1];
261 size_t tpc_x =
t % tpcs[0];
264 bool flip_d = (dir > 0);
273 if ((
t % 4 == 0) || (
t % 4 == 2))
275 eff_p = (
p == 1) ? 0 : 1;
278 if ((
t % 4 == 0) || (
t % 4 == 1))
280 flip_w = (dir > 0) ? (eff_p == 1) : (eff_p == 0);
284 flip_w = (dir < 0) ? (eff_p == 1) : (eff_p == 0);
287 offset = (
p == 0) ? 48 : 752;
290 if ((
t % 4 == 0) || (
t % 4 == 2))
292 p_align = plane_align0[
p];
296 p_align = plane_align1[
p];
299 size_t gw = tpc_z * weff[
p] + tpc_y * offset;
300 size_t gd = tpc_x * drift_size + apa_gap * (1 + tpc_x) / 2 + p_align;
317 std::cout <<
" find crop..." <<
std::endl;
318 unsigned int w0, w1, d0, d1;
319 if (fullimg.
findCrop(80, w0, w1, d0, d1))
330 std::cout <<
" crop: " << w0 <<
" " << w1 <<
" " << d0 <<
" " << d1 <<
std::endl;
332 else { std::cout <<
" skip empty event" <<
std::endl;
break; }
334 std::ostringstream ss1;
335 ss1 << os.str() <<
"_plane_" <<
p;
338 TH2C* rawHist = tfs->make<TH2C>((ss1.str() +
"_raw").c_str(),
"ADC",
339 (
int)(w1 - w0), (double)w0, (
double)w1, (
int)(d1 - d0), (double)d0, (
double)d1);
342 for (
size_t w = w0;
w < w1; ++
w)
345 for (
size_t d = d0;
d < d1; ++
d)
347 rawHist->Fill(
w,
d, (
char)(
raw[
d] + zero));
353 TH2F* depHist = tfs->make<TH2F>((ss1.str() +
"_deposit").c_str(),
"Deposit",
354 (
int)(w1 - w0), (double)w0, (
double)w1, (
int)(d1 - d0), (double)d0, (
double)d1);
355 for (
size_t w = w0;
w < w1; ++
w)
357 auto const & edep = fullimg.
wireDep(
w);
358 for (
size_t d = d0;
d < d1; ++
d) { depHist->Fill(
w,
d, edep[
d]); }
364 TH2I* pdgHist = tfs->make<TH2I>((ss1.str() +
"_pdg").c_str(),
"PDG",
365 (
int)(w1 - w0), (double)w0, (
double)w1, (
int)(d1 - d0), (double)d0, (
double)d1);
366 for (
size_t w = w0;
w < w1; ++
w)
369 for (
size_t d = d0;
d < d1; ++
d) { pdgHist->Fill(
w,
d,
pdg[
d]); }
384 std::cout <<
" *** w0:" << w0 <<
", w1:" << w1 <<
std::endl;
385 std::cout <<
" *** d0:" << d0 <<
", d1:" << d1 <<
std::endl;
388 std::cout <<
" *** zero:" << zero <<
std::endl;
405 double vtx[3] = {vec.X(), vec.Y(), vec.Z()};
413 vtx[0] = vec.X() + corrt0x;
422 double vtx[3] = {pvtx.X(), pvtx.Y(), pvtx.Z()};
432 double minx = tpcgeo.
MinX();
double maxx = tpcgeo.
MaxX();
433 double miny = tpcgeo.
MinY();
double maxy = tpcgeo.
MaxY();
434 double minz = tpcgeo.
MinZ();
double maxz = tpcgeo.
MaxZ();
437 double dista = fabs(minx - pvtx.X());
438 double distb = fabs(pvtx.X() - maxx);
440 if ((pvtx.X() > minx) && (pvtx.X() < maxx) &&
445 else { inside =
false; }
448 dista = fabs(maxy - pvtx.Y());
449 distb = fabs(pvtx.Y() - miny);
450 if (inside && (pvtx.Y() > miny) && (pvtx.Y() < maxy) &&
455 dista = fabs(maxz - pvtx.Z());
456 distb = fabs(pvtx.Z() - minz);
457 if (inside && (pvtx.Z() > minz) && (pvtx.Z() < maxz) &&
467 TVector3
const & vtx3d,
const size_t cryo,
const size_t tpc,
const size_t plane)
const 493 #endif // SPMultiTpcDump_Module def analyze(root, level, gtrees, gbranches, doprint)
int fEvent
number of the event being processed
bool HasPlane(unsigned int iplane) const
Returns whether a plane with index iplane is present in this TPC.
geo::GeometryCore const * fGeometry
CryostatGeo const & GetElement(geo::CryostatID const &cryoid) const
const std::vector< float > & wireDep(size_t widx) const
SPMultiTpcDump(Parameters const &config)
bool setEventData(const art::Event &event, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, unsigned int plane, unsigned int tpc, unsigned int cryo)
float getProjX(void) const
double MinX() const
Returns the world x coordinate of the start of the box.
bool isValid
Whether this ID points to a valid element.
Geometry information for a single TPC.
unsigned int DriftWindow() const
bool InsideFidVol(TVector3 const &pvtx) const
ChannelGroupService::Name Name
float getProjY(void) const
bool findCrop(size_t max_area_cut, unsigned int &w0, unsigned int &w1, unsigned int &d0, unsigned int &d1) const
double MaxX() const
Returns the world x coordinate of the end of the box.
unsigned int Nwires(unsigned int p, unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wires in the specified plane.
nnet::TrainingDataAlg fTrainingDataAlg
art framework interface to geometry description
geo::TPCID FindTPCAtPosition(double const worldLoc[3]) const
Returns the ID of the TPC at specified location.
unsigned int NWires() const
art::InputTag fGenieGenLabel
void CorrOffset(detinfo::DetectorPropertiesData const &detProp, TVector3 &vec, const simb::MCParticle &particle)
#define DEFINE_ART_MODULE(klass)
const std::vector< int > & wirePdg(size_t widx) const
double T(const int i=0) const
double MinZ() const
Returns the world z coordinate of the start of the box.
bool prepareEv(const art::Event &event, detinfo::DetectorPropertiesData const &detProp)
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
The data type to uniquely identify a TPC.
Description of geometry of one entire detector.
Definition of data types for geometry description.
double MaxY() const
Returns the world y coordinate of the end of the box.
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
int fSubRun
number of the sub-run being processed
bool HasTPC(geo::TPCID const &tpcid) const
Returns whether we have the specified TPC.
void setProjXY(const TrainingDataAlg &dataAlg, float x, float y, size_t gw, bool flipw, size_t gd, bool flipd)
Implementation of the Projection Matching Algorithm.
short int DetectDriftDirection() const
Returns the expected drift direction based on geometry.
int fRun
number of the run being processed
double MaxZ() const
Returns the world z coordinate of the end of the box.
void addTpc(const TrainingDataAlg &dataAlg, size_t gw, bool flipw, size_t gd, bool flipd)
TVector2 GetProjectionToPlane(const TVector3 &p, unsigned int plane, unsigned int tpc, unsigned int cryo)
TVector2 CmToWireDrift(detinfo::DetectorPropertiesData const &detProp, float xw, float yd, unsigned int plane, unsigned int tpc, unsigned int cryo)
Access the description of detector geometry.
float ZeroLevel() const
Level of zero ADC after scaling.
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
TPCID_t TPC
Index of the TPC within its cryostat.
const std::vector< float > & wireAdc(size_t widx) const
size_t getAdcArea() const
double MinY() const
Returns the world y coordinate of the start of the box.
geo::CryostatID::CryostatID_t FindCryostatAtPosition(geo::Point_t const &worldLoc) const
Returns the index of the cryostat at specified location.
TVector2 GetProjVtx(detinfo::DetectorPropertiesData const &detProp, TVector3 const &vtx3d, const size_t cryo, const size_t tpc, const size_t plane) const
void analyze(const art::Event &event) override
QTextStream & endl(QTextStream &s)
Event finding and building.