8 #include "art/Framework/Core/EDAnalyzer.h"
9 #include "art/Framework/Core/ModuleMacros.h"
10 #include "art/Framework/Principal/Event.h"
11 #include "art/Framework/Principal/Handle.h"
12 #include "art/Framework/Services/Registry/ServiceHandle.h"
13 #include "art_root_io/TFileService.h"
14 #include "canvas/Persistency/Common/FindManyP.h"
15 #include "canvas/Utilities/InputTag.h"
16 #include "fhiclcpp/ParameterSet.h"
17 #include "messagefacility/MessageLogger/MessageLogger.h"
32 #include "TLorentzVector.h"
43 void Info(
const art::Event& evt);
163 art::ServiceHandle<geo::Geometry const> geom;
165 fMinx = geom->IterateTPCs().begin()->MinX();
166 fMiny = geom->IterateTPCs().begin()->MinY();
167 fMinz = geom->IterateTPCs().begin()->MinZ();
168 fMaxx = geom->IterateTPCs().begin()->MaxX();
169 fMaxy = geom->IterateTPCs().begin()->MaxY();
170 fMaxz = geom->IterateTPCs().begin()->MaxZ();
172 for (
const geo::TPCGeo& tpcg : geom->IterateTPCs()) {
173 if (tpcg.MinX() < fMinx) fMinx = tpcg.MinX();
174 if (tpcg.MaxX() > fMaxx) fMaxx = tpcg.MaxX();
175 if (tpcg.MinY() < fMiny) fMiny = tpcg.MinY();
176 if (tpcg.MaxY() > fMaxy) fMaxy = tpcg.MaxY();
177 if (tpcg.MinZ() < fMinz) fMinz = tpcg.MinZ();
178 if (tpcg.MaxZ() > fMaxz) fMaxz = tpcg.MaxZ();
186 fPi0pos.SetXYZ(0, 0, 0);
195 fConvgamma1.SetXYZ(0, 0, 0);
196 fConvgamma2.SetXYZ(0, 0, 0);
197 fDirgamma1.SetXYZ(0, 0, 0);
198 fDirgamma2.SetXYZ(0, 0, 0);
200 art::ServiceHandle<cheat::ParticleInventoryService const> pi_serv;
201 const sim::ParticleList& plist = pi_serv->ParticleList();
202 for (sim::ParticleList::const_iterator ipar = plist.begin(); ipar != plist.end(); ++ipar) {
203 const simb::MCParticle* particle = ipar->second;
205 if (particle->Process() !=
"primary")
continue;
207 TLorentzVector posvec = particle->Position();
208 TVector3 pose(posvec.X(), posvec.Y(), posvec.Z());
211 if (particle->PdgCode() == 111) {
212 fMompi0 = particle->P();
214 TLorentzVector posvec3 = particle->Position();
215 TVector3 pospi0(posvec3.X(), posvec3.Y(), posvec3.Z());
218 if (particle->NumberDaughters() != 2)
continue;
220 const simb::MCParticle* daughter1 = pi_serv->TrackIdToParticle_P(particle->Daughter(0));
221 if (daughter1->PdgCode() != 22)
continue;
223 const simb::MCParticle* daughter2 = pi_serv->TrackIdToParticle_P(particle->Daughter(1));
224 if (daughter2->PdgCode() != 22)
continue;
226 fNgammas = particle->NumberDaughters();
227 TLorentzVector mom1 = pi_serv->TrackIdToParticle_P(particle->Daughter(0))->Momentum();
228 TLorentzVector mom2 = pi_serv->TrackIdToParticle_P(particle->Daughter(1))->Momentum();
231 if (daughter1->EndProcess() ==
"phot") fCompton =
true;
232 if (daughter2->EndProcess() ==
"phot") fCompton =
true;
234 TVector3 mom1vec3(mom1.Px(), mom1.Py(), mom1.Pz());
235 fGammamom1 = pi_serv->TrackIdToParticle_P(particle->Daughter(0))->P();
236 TVector3 mom2vec3(mom2.Px(), mom2.Py(), mom2.Pz());
237 fGammamom2 = pi_serv->TrackIdToParticle_P(particle->Daughter(1))->P();
239 TLorentzVector pos1 = pi_serv->TrackIdToParticle_P(particle->Daughter(0))->EndPosition();
240 TLorentzVector pos2 = pi_serv->TrackIdToParticle_P(particle->Daughter(1))->EndPosition();
242 if (insideFidVol(pos1)) fInside1 =
true;
243 if (insideFidVol(pos2)) fInside2 =
true;
245 fConvgamma1.SetXYZ(pos1.X(), pos1.Y(), pos1.Z());
246 fConvgamma2.SetXYZ(pos2.X(), pos2.Y(), pos2.Z());
248 TVector3 vecnorm1 = mom1vec3.Unit();
249 fDirgamma1 = vecnorm1;
250 TVector3 vecnorm2 = mom2vec3.Unit();
251 fDirgamma2 = vecnorm2;
253 fCosine = fDirgamma1 * fDirgamma2;
256 fNgammas = particle->NumberDaughters();
267 double dista = fabs(fMinx - pvtx.X());
268 double distb = fabs(pvtx.X() - fMaxx);
269 if ((pvtx.X() > fMinx) && (pvtx.X() < fMaxx) && (dista > fFidVolCut) && (distb > fFidVolCut))
272 dista = fabs(fMaxy - pvtx.Y());
273 distb = fabs(pvtx.Y() - fMiny);
274 if (inside && (pvtx.Y() > fMiny) && (pvtx.Y() < fMaxy) && (dista > fFidVolCut) &&
275 (distb > fFidVolCut))
281 dista = fabs(fMaxz - pvtx.Z());
282 distb = fabs(pvtx.Z() - fMinz);
283 if (inside && (pvtx.Z() > fMinz) && (pvtx.Z() < fMaxz) && (dista > fFidVolCut) &&
284 (distb > fFidVolCut))
302 void beginJob()
override;
303 void endJob()
override;
305 void analyze(art::Event
const&
e)
override;
307 bool convCluster(art::Event
const&
evt);
310 TVector3
const& convmc,
395 art::ServiceHandle<art::TFileService const>
tfs;
397 fEvTree = tfs->make<TTree>(
"MultiShowers",
"showers3d");
398 fEvTree->Branch(
"fEvNumber", &fEvNumber,
"fEvNumber/I");
399 fEvTree->Branch(
"fNGroups", &fNGroups,
"fNGroups/I");
400 fEvTree->Branch(
"fPi0mom", &fPi0mom,
"fPi0mom/D");
401 fEvTree->Branch(
"fNgammas", &fNgammas,
"fNgammas/I");
402 fEvTree->Branch(
"fGmom1", &fGmom1,
"fGmom1/D");
403 fEvTree->Branch(
"fGmom2", &fGmom2,
"fGmom2/D");
404 fEvTree->Branch(
"fMcth", &fMcth,
"fMcth/D");
405 fEvTree->Branch(
"fRecth", &fRecth,
"fRecth/D");
406 fEvTree->Branch(
"fMCrecovtx", &fMCrecovtx,
"fMCrecovtx/D");
407 fEvTree->Branch(
"fMCrecoTh", &fMCrecoTh,
"fMCrecoTh/D");
408 fEvTree->Branch(
"fConvGood", &fConvGood,
"fConvGood/I");
409 fEvTree->Branch(
"fConvWrong", &fConvWrong,
"fConvWrong/I");
410 fEvTree->Branch(
"fConvBothGood", &fConvBothGood,
"fConvBothGood/I");
411 fEvTree->Branch(
"fGammasInside", &fGammasInside,
"fGammasInside/I");
412 fEvTree->Branch(
"fCountph", &fCountph,
"fCountph/I");
413 fEvTree->Branch(
"fCountreco", &fCountreco,
"fCountreco/I");
415 fRecoTree = tfs->make<TTree>(
"Cascades",
"conv points");
416 fRecoTree->Branch(
"fRecth", &fRecth,
"fRecth/D");
417 fRecoTree->Branch(
"fMCrecovtx", &fMCrecovtx,
"fMCrecovtx/D");
418 fRecoTree->Branch(
"fMCrecoTh", &fMCrecoTh,
"fMCrecoTh/D");
419 fRecoTree->Branch(
"fRecthgood", &fRecthgood,
"fRecthgood/D");
420 fRecoTree->Branch(
"fMCrecovtxgood", &fMCrecovtxgood,
"fMCrecovtxgood/D");
421 fRecoTree->Branch(
"fMCrecoThgood", &fMCrecoThgood,
"fMCrecoThgood/D");
422 fRecoTree->Branch(
"fGdirmcreco1", &fGdirmcreco1,
"fGdirmcreco1/D");
423 fRecoTree->Branch(
"fGdirmcreco2", &fGdirmcreco2,
"fGdirmcreco2/D");
424 fRecoTree->Branch(
"fGdirmcreco1good", &fGdirmcreco1good,
"fGdirmcreco1good/D");
425 fRecoTree->Branch(
"fGdirmcreco2good", &fGdirmcreco2good,
"fGdirmcreco2good/D");
427 fShTree = tfs->make<TTree>(
"Shower",
"conv point");
429 fShTree->Branch(
"fStartX", &fStartX,
"fStartX/D");
430 fShTree->Branch(
"fStartY", &fStartY,
"fStartY/D");
431 fShTree->Branch(
"fStartZ", &fStartZ,
"fStartZ/D");
432 fShTree->Branch(
"fDedxZ", &fDedxZ,
"fDedxZ/D");
433 fShTree->Branch(
"fDedxV", &fDedxV,
"fDedxV/D");
434 fShTree->Branch(
"fDedxU", &fDedxU,
"fDedxU/D");
440 mf::LogInfo log(
"MultiEMShower");
441 log <<
"******************** fEvFidVol = " << fEvFidVol <<
"\n";
442 log <<
"******************** fEvGMomCut = " << fEvGMomCut <<
"\n";
443 log <<
"******************** fEvComp = " << fEvComp <<
"\n";
444 log <<
"******************** fEvReco = " << fEvReco <<
"\n";
445 log <<
"******************** fEvInput = " << fEvInput <<
"\n";
446 log <<
"******************** fEv2Groups = " << fEv2Groups <<
"\n";
447 log <<
"******************** fEv2Good = " << fEv2Good <<
"\n";
449 log <<
"******************** reco % = " << double(fEvReco) / double(fEvInput) <<
"\n";
455 fEvNumber = e.id().event();
462 fDistConvrecomc1 = 0.0;
463 fDistConvrecomc2 = 0.0;
465 fMCrecovtxgood = -400.0;
469 fMCrecoThgood = -400.0;
475 fGdirmcreco1good = 0.0;
476 fGdirmcreco2good = 0.0;
492 fMcth = 180.0F * (std::acos(cosinemc)) / TMath::Pi();
496 const double maxdist = 2.0;
504 if ((fGmom1 > 0.1) && (fGmom2 > 0.1)) fEvGMomCut++;
508 art::Handle<std::vector<recob::Shower>> shsListHandle;
509 art::Handle<std::vector<recob::Track>> trkListHandle;
510 art::Handle<std::vector<recob::Vertex>> vtxListHandle;
511 art::Handle<std::vector<recob::Cluster>> cluListHandle;
512 art::Handle<std::vector<recob::Hit>> hitListHandle;
513 if (e.getByLabel(fShsModuleLabel, shsListHandle) &&
514 e.getByLabel(fTrk3DModuleLabel, trkListHandle) &&
515 e.getByLabel(fVtxModuleLabel, vtxListHandle) &&
516 e.getByLabel(fCluModuleLabel, cluListHandle) &&
517 e.getByLabel(fHitsModuleLabel, hitListHandle)) {
518 art::FindManyP<recob::Cluster> cluFromShs(shsListHandle, e, fShsModuleLabel);
519 art::FindManyP<recob::Cluster> cluFromTrk(trkListHandle, e, fTrk3DModuleLabel);
520 art::FindManyP<recob::Vertex> vtxFromTrk(trkListHandle, e, fVtxModuleLabel);
521 art::FindManyP<recob::Hit> hitFromClu(cluListHandle, e, fCluModuleLabel);
523 fNGroups = shsListHandle->size();
529 for (
size_t s = 0;
s < shsListHandle->size(); ++
s) {
531 double mindist = maxdist;
534 for (
int i = 0; i < fNgammas; ++i) {
536 if ((dist < mindist) && (idph != i)) {
550 if (fCountph == 2) fConvBothGood++;
554 for (
size_t s = 0;
s < shsListHandle->size(); ++
s) {
560 std::vector<double>
const& vecdedx = sh.
dEdx();
562 if (vecdedx.size() == 3) {
573 for (
size_t s = 0;
s < shsListHandle->size(); ++
s) {
575 double mindist = maxdist;
578 if (dist < mindist) {
583 std::vector<double> vecdedx = sh.
dEdx();
584 if (vecdedx.size() == 3) {
601 if (fNGroups == 2) fEv2Groups++;
602 if ((fNGroups == 2) && (fCountph == 2)) fEv2Good++;
606 std::vector<std::pair<TVector3, TVector3>> lines;
610 std::pair<TVector3, TVector3> frontback1(sh1.
ShowerStart(),
612 std::pair<TVector3, TVector3> frontback2(sh2.
ShowerStart(),
614 lines.push_back(frontback1);
615 lines.push_back(frontback2);
624 if ((dist1_0 > dist2_0) || (dist1_1 > dist2_1)) {}
626 fMCrecovtx = std::sqrt(
pma::Dist2(pospi0, result));
628 if (fCountph == 2) fMCrecovtxgood = fMCrecovtx;
631 fRecth = 180.0F * (std::acos(cosine_reco)) / TMath::Pi();
636 fGdirmcreco1good = fGdirmcreco1;
637 fGdirmcreco2good = fGdirmcreco2;
640 if (fCountph == 2) fRecthgood = fRecth;
642 fMCrecoTh = fRecth - fMcth;
644 if (fCountph == 2) fMCrecoThgood = fMCrecoTh;
667 double vtx[3] = {convp[0].X(), convp[0].Y(), convp[0].Z()};
669 art::ServiceHandle<geo::Geometry const> geom;
670 geo::TPCID idtpc = geom->FindTPCAtPosition(vtx);
671 size_t cryoid = geom->FindCryostatAtPosition(vtx);
673 art::Handle<std::vector<recob::Hit>> hitListHandle;
674 art::Handle<std::vector<recob::Cluster>> cluListHandle;
677 std::map<size_t, std::vector<size_t>> used;
679 art::FindManyP<recob::Hit> fbc(cluListHandle, evt, fCluModuleLabel);
681 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt);
682 double maxdist = 1.0;
683 if (geom->HasTPC(idtpc)) {
685 if (evt.getByLabel(fHitsModuleLabel, hitListHandle) &&
686 evt.getByLabel(fCluModuleLabel, cluListHandle)) {
689 for (
size_t view = 0; view < cryostat.
MaxPlanes(); view++) {
691 double mindist = maxdist;
693 for (
size_t c = 0; c < cluListHandle->size(); ++c) {
696 for (
auto const& ids : used)
697 for (
auto i : ids.second)
698 if (i == c) exist =
true;
701 std::vector<art::Ptr<recob::Hit>> hits = fbc.at(c);
702 if (hits.size() < 20)
continue;
703 if (hits[0]->
WireID().Plane != view)
continue;
705 double dist = getMinDist(
detProp, hits, convp[conv], view, idtpc.
TPC, cryoid);
706 if (dist < mindist) {
711 if (mindist < maxdist) used[conv].push_back(clid);
720 for (
auto const& ids : used) {
721 if (ids.second.size() > 1)
735 TVector3
const& convmc,
740 double mindist = 9999;
745 for (
size_t h = 0;
h < v.size(); ++
h) {
746 if ((v[
h]->
WireID().
Plane == view) && (v[
h]->WireID().TPC == tpc)) {
751 if (dist < mindist) { mindist =
dist; }
process_name opflashCryo1 flashfilter analyze
TVector3 const & GetDirgamma2() const
double SolveLeastSquares3D(const std::vector< std::pair< TVector3, TVector3 >> &lines, TVector3 &result)
BEGIN_PROLOG true icarus_rawdigitfilter FilterTools FilterPlane1 Plane
unsigned int MaxPlanes() const
Returns the largest number of planes among the TPCs in this cryostat.
double Dist2(const TVector2 &v1, const TVector2 &v2)
bool const & IsInside2() const
void Findtpcborders(const art::Event &evt)
MultiEMShowers(fhicl::ParameterSet const &p)
const TVector3 & Direction() const
Declaration of signal hit object.
art::InputTag fTrk3DModuleLabel
const std::vector< double > & dEdx() const
Geometry information for a single TPC.
void analyze(art::Event const &e) override
bool convCluster(art::Event const &evt)
TVector2 WireDriftToCm(detinfo::DetectorPropertiesData const &detProp, unsigned int wire, float drift, unsigned int plane, unsigned int tpc, unsigned int cryo)
Geometry information for a single cryostat.
bool const & IsCompton() const
double GetMomGamma2() const
double getMinDist(detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> const &v, TVector3 const &convmc, size_t view, size_t tpc, size_t cryo)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
art::InputTag fShsModuleLabel
art::InputTag fVtxModuleLabel
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
art::InputTag fHitsModuleLabel
TVector3 const & GetPosgamma1() const
The data type to uniquely identify a TPC.
Declaration of cluster object.
TVector3 const & GetPrimary() const
TVector3 const & GetDirgamma1() const
Provides recob::Track data product.
TVector3 const & GetPospi0() const
double GetMomGamma1() const
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
then echo File list $list not found else cat $list while read file do echo $file sed s
MCinfo(const art::Event &evt)
TVector2 GetProjectionToPlane(const TVector3 &p, unsigned int plane, unsigned int tpc, unsigned int cryo)
art::InputTag fCluModuleLabel
bool const & IsInside1() const
const TVector3 & ShowerStart() const
art::ServiceHandle< art::TFileService > tfs
TPCID_t TPC
Index of the TPC within its cryostat.
void Info(const art::Event &evt)
TVector3 const & GetPosgamma2() const
art framework interface to geometry description
bool insideFidVol(const TLorentzVector &pvtx) const