17 #include "art_root_io/TFileService.h" 23 #include "canvas/Persistency/Common/FindManyP.h" 24 #include "canvas/Persistency/Common/FindMany.h" 25 #include "canvas/Persistency/Common/FindOne.h" 26 #include "canvas/Persistency/Common/FindOneP.h" 43 #include "TEfficiency.h" 253 WindowSize = detProp.NumberTimeSamples() * clockData.TPCClock().TickPeriod() * 1e3;
256 for (
const auto &
s : flt)
262 else { std::cout <<
"unsupported filter name: " <<
s <<
std::endl; }
282 fEventTree = tfs->make<TTree>(
"events",
"summary tree");
283 fEventTree->Branch(
"fRun", &
fRun,
"fRun/I");
284 fEventTree->Branch(
"fEvent", &
fEvent,
"fEvent/I");
285 fEventTree->Branch(
"fEnGen", &
fEnGen,
"fEnGen/F");
286 fEventTree->Branch(
"fEkGen", &
fEkGen,
"fEkGen/F");
287 fEventTree->Branch(
"fT0", &
fT0,
"fT0/F");
288 fEventTree->Branch(
"fNRecoTracks", &
fNRecoTracks,
"fNRecoTracks/S");
289 fEventTree->Branch(
"fReconstructable", &
fReconstructable,
"fReconstructable/S");
290 fEventTree->Branch(
"fMatched", &
fMatched,
"fMatched/S");
292 fTrkTree = tfs->make<TTree>(
"tracks",
"track metrics");
328 fTrkIDETree = tfs->make<TTree>(
"trackIDEs",
"trackIDE metrics");
353 fHitDist3D = tfs->make<TH1D>(
"HitD3D",
"MC-reco 3D distance", 400, 0., 10.0);
354 fHitDx = tfs->make<TH1D>(
"HitDx",
"MC-reco X distance", 400, 0., 10.0);
355 fHitDy = tfs->make<TH1D>(
"HitDy",
"MC-reco Y distance", 400, 0., 10.0);
356 fHitDz = tfs->make<TH1D>(
"HitDz",
"MC-reco Z distance", 400, 0., 10.0);
373 std::cout <<
"nhits: " << i <<
" nom:" << nom <<
" den:" << den <<
std::endl;
379 std::cout <<
"Efficiency created: " << fEfficiency->GetTitle() <<
" " << fEnergyEfficiency->GetTitle() <<
std::endl;
381 std::cout <<
"Efficiency created: " << fEfficiency->GetTitle() <<
" " << fLengthEfficiency->GetTitle() <<
std::endl;
383 std::cout <<
"Efficiency created: " << fEfficiency->GetTitle() <<
" " << fDepEfficiency->GetTitle() <<
std::endl;
402 const sim::ParticleList& plist = pi_serv->
ParticleList();
426 std::unordered_map<int, std::vector<recob::Hit> > mapTrackIDtoHits;
427 std::unordered_map<int, double> mapTrackIDtoHitsEnergyPerPlane[3];
428 std::unordered_map<int, double> mapTrackIDtoHitsEnergy;
430 std::unordered_map<int, double> mapTrackIDtoLength;
432 for (
auto const &
h : *hitListHandle)
434 std::unordered_map<int, double> particleID_E;
442 particleID_E[
id.trackID] +=
id.energy;
444 mapTrackIDtoLength[
id.trackID] =
GetLengthInTPC(clockData, *part);
450 for (
auto const & contrib : particleID_E)
452 if (contrib.second > max_e)
454 max_e = contrib.second;
455 best_id = contrib.first;
461 mapTrackIDtoHits[best_id].push_back(
h);
462 mapTrackIDtoHitsEnergyPerPlane[
h.WireID().Plane][best_id] += max_e;
463 mapTrackIDtoHitsEnergy[best_id] += max_e;
472 std::unordered_map<int, std::vector< recob::Hit >> mapTrackIDtoHits_filtered;
473 for (
auto const &
p : mapTrackIDtoHits)
492 if ((mother == 0) || (mother->
Process() !=
"primary")) { skip =
true; }
499 if (skip) {
continue; }
505 if (skip) {
continue; }
508 std::unordered_map<geo::View_t, size_t> hit_count;
509 for (
auto const &
h :
p.second) { hit_count[
h.View()]++; }
516 mapTrackIDtoHits_filtered.emplace(
p);
522 for (
auto const &
p : mapTrackIDtoHits_filtered)
528 double this_length = mapTrackIDtoLength[
p.first];
530 std::cout <<
" : id " <<
p.first <<
" size " <<
p.second.size() <<
" en: " << mapTrackIDtoHitsEnergy[
p.first] <<
" init en: " << this_energy <<
" PDG: " << this_code <<
" Length: " << this_length <<
std::endl;
551 std::unordered_map<int, int> mapIDEtoRecoTrack;
552 std::unordered_map<int, double> mapIDEtoRecoEnergy;
553 std::unordered_map<int, std::vector< std::pair<int, double > > > mapIDEtoTrackContribs;
555 for (
size_t t = 0;
t < trkHandle->size(); ++
t)
561 std::unordered_map<int, double> trkID_E_perPlane[3];
562 std::unordered_map<int, double> trkID_E;
563 double totE_anyMC_inPlane[3] = { 0, 0, 0 };
564 double totE_anyMC = 0;
565 const auto & hits = hitsFromTracks.at(
t);
566 for (
const auto &
h : hits)
568 size_t plane =
h->WireID().Plane;
571 if (mapTrackIDtoHits_filtered.find(ide.trackID) != mapTrackIDtoHits_filtered.end())
573 trkID_E_perPlane[plane][ide.trackID] += ide.energy;
574 trkID_E[ide.trackID] += ide.energy;
576 totE_anyMC_inPlane[plane] += ide.energy;
577 totE_anyMC += ide.energy;
584 std::array< double, 3 > e_inPlane = {{ 0, 0, 0 }};
585 for (
auto const &
entry : trkID_E)
587 mapIDEtoTrackContribs[
entry.
first].push_back(std::make_pair(
t,
entry.second));
590 if (
entry.second > max_e)
592 max_e =
entry.second;
595 for (
size_t i = 0; i < 3; ++i)
597 e_inPlane[i] = trkID_E_perPlane[i][
entry.
first];
603 mapIDEtoRecoTrack[best_id] = -1;
606 mapIDEtoRecoTrack[best_id] =
t;
608 mapIDEtoRecoEnergy[best_id] = max_e;
611 if ((max_e > 0.5 * totE_anyMC) &&
612 (max_e > 0.5 * mapTrackIDtoHitsEnergy[best_id]))
616 double this_length = mapTrackIDtoLength[best_id];
619 std::cout <<
" id: " << best_id <<
" init energy: " << pi_serv->
TrackIdToParticle_P(best_id)->
E(0) <<
" Length: " << this_length <<
std::endl;
629 for (
size_t i = 0; i < 3; ++i)
631 if (totE_anyMC_inPlane[i] > 0) {
fTrkPurityPerPlane[i] = e_inPlane[i] / totE_anyMC_inPlane[i]; }
634 if (mapTrackIDtoHitsEnergyPerPlane[i][best_id] > 0) {
fTrkCompletnessPerPlane[i] = e_inPlane[i] / mapTrackIDtoHitsEnergyPerPlane[i][best_id]; }
638 fTrkPid = (*trkHandle)[
t].ParticleId();
646 std::vector<const anab::T0*> T0s;
655 std::cout <<
"No T0s found" <<
std::endl;
662 for(
auto const &
pos : (((*trkHandle)[
t].Trajectory()).Trajectory()).Positions()){
663 if (track_step > 9999)
break;
666 double t0Correction = detProp.ConvertTicksToX(
TickT0, this_wire.Plane, this_wire.TPC, this_wire.Cryostat );
677 for(
int track_step = 0; track_step < 10000; ++
track_step){
689 for (
const auto &
h : hits)
691 const auto & sps = spFromHits.at(
h.key());
692 if (sps.empty()) {
continue; }
693 const auto & sp = *sps.front();
697 std::array< double, 3 > hitpos = {{0, 0, 0}};
699 for (
auto const & ide : ides)
701 if (ide.trackID == best_id)
703 hitpos[0] += ide.x * ide.energy;
704 hitpos[1] += ide.y * ide.energy;
705 hitpos[2] += ide.z * ide.energy;
711 hitpos[0] /= hitE; hitpos[1] /= hitE; hitpos[2] /= hitE;
713 double dy = sp.XYZ()[1] - hitpos[1];
714 double dz = sp.XYZ()[2] - hitpos[2];
718 fHitDist3D->Fill(sqrt(dx*dx + dy*dy + dz*dz));
730 for (
auto const &
p : mapTrackIDtoHits_filtered)
745 std::vector<std::pair<int, double>> TrackContribs;
746 TrackContribs = mapIDEtoTrackContribs[
p.first];
747 for (
auto const & tc : TrackContribs){
761 if( (pos != TVector3(-1,-1,-1)) && (pos != TVector3(0,0,0))){
801 std::cout <<
"------------ reconstructed: " << fNRecoTracks <<
" and then matched to MC particles: " <<
fMatched 813 for (
size_t i = 0; i < 3; ++i)
836 for(
size_t i = 0; i < 10000; ++i){
865 std::vector<double> TPCLengthHits(nTrajectoryPoints,0);
867 bool BeenInVolume =
false;
868 int FirstHit = 0, LastHit = 0;
869 double TPCLength = 0;
871 for(
unsigned int MCHit=0; MCHit < nTrajectoryPoints; ++MCHit) {
872 const TLorentzVector& tmpPosition = part.
Position(MCHit);
873 double const tmpPosArray[] = {tmpPosition[0], tmpPosition[1], tmpPosition[2]};
875 if (MCHit!=0) TPCLengthHits[MCHit] =
pow (
pow( (part.
Vx(MCHit-1)-part.
Vx(MCHit)),2)
876 +
pow( (part.
Vy(MCHit-1)-part.
Vy(MCHit)),2)
877 +
pow( (part.
Vz(MCHit-1)-part.
Vz(MCHit)),2)
885 double DriftTimeCorrection = fabs( tmpPosition[0] - XPlanePosition )/
XDriftVelocity;
886 double TimeAtPlane = part.
T() + DriftTimeCorrection;
897 for (
int Hit = FirstHit+1;
Hit <= LastHit; ++
Hit ) {
898 TPCLength += TPCLengthHits[
Hit];
906 const TLorentzVector& tmpPosition = part.
Position(MCHit);
907 double const tmpPosArray[] = {tmpPosition[0], tmpPosition[1], tmpPosition[2]};
915 double DriftTimeCorrection = fabs( tmpPosition[0] - XPlanePosition )/
XDriftVelocity;
916 double TimeAtPlane = part.
T() + DriftTimeCorrection;
918 return TVector3(-1,-1,-1);}
921 return TVector3(-1,-1,-1);
924 TVector3 posInTPC(tmpPosArray);
929 size_t prev_step = this_step - 1;
930 size_t next_step = this_step + 1;
932 double dE_prev = fabs( traj.
E(this_step) - traj.
E(prev_step) );
933 double dE_next = fabs( traj.
E(this_step) - traj.
E(next_step) );
935 double dX_prev = sqrt(
pow( (traj.
X(this_step) - traj.
X(prev_step)), 2 )
936 +
pow( (traj.
X(this_step) - traj.
X(prev_step)), 2 )
937 +
pow( (traj.
X(this_step) - traj.
X(prev_step)), 2 ));
939 double dX_next = sqrt(
pow( (traj.
X(this_step) - traj.
X(next_step)), 2 )
940 +
pow( (traj.
X(this_step) - traj.
X(next_step)), 2 )
941 +
pow( (traj.
X(this_step) - traj.
X(next_step)), 2 ));
942 return (dE_prev + dE_next)/(dX_prev + dX_next);
double E(const int i=0) const
unsigned int NumberTrajectoryPoints() const
const TLorentzVector & Position(const int i=0) const
double X(const size_type i) const
double GetLengthInTPC(detinfo::DetectorClocksData const &clockData, simb::MCParticle part)
fhicl::Atom< size_t > EnableIDETree
fhicl::Atom< size_t > EffDepBins
Encapsulate the construction of a single cyostat.
fhicl::Atom< size_t > EffLengthMax
double E(const size_type i) const
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
art::ServiceHandle< geo::Geometry > geom
const simb::MCTrajectory & Trajectory() const
const simb::MCParticle * TrackIdToParticle_P(int id) const
TH1D * fLengthNominatorHist
simb::Origin_t Origin() const
bool isValid
Whether this ID points to a valid element.
Geometry information for a single TPC.
ChannelGroupService::Name Name
fhicl::Atom< art::InputTag > SimulationLabel
CryostatID_t Cryostat
Index of cryostat.
std::vector< int > fTrueTrkRecos
fhicl::Atom< size_t > EffLengthBins
std::vector< int > fTrkIDEs
Geometry information for a single cryostat.
std::vector< EFilterMode > fFilters
EDAnalyzer(fhicl::ParameterSet const &pset)
std::string Process() const
fhicl::Atom< size_t > EffEBins
const art::Ptr< simb::MCTruth > & ParticleToMCTruth_P(const simb::MCParticle *p) const
std::vector< double > fTrueTrkContribs
TH1D * fEnergyDenominatorHist
art framework interface to geometry description
QCollection::Item first()
geo::TPCID FindTPCAtPosition(double const worldLoc[3]) const
Returns the ID of the TPC at specified location.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
fhicl::Atom< art::InputTag > TrackModuleLabel
int PdgCode(Resonance_t res, int Q)
(resonance id, charge) -> PDG code
#define DEFINE_ART_MODULE(klass)
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
std::string EndProcess() const
art::InputTag fSimulationLabel
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int id) const
RecoEff(Parameters const &config)
single particles thrown at the detector
fhicl::Atom< size_t > MinHitsPerPlane
RecoEff & operator=(RecoEff const &)=delete
float fTrkCompletnessPerPlane[3]
fhicl::Sequence< std::string > Filters
std::vector< double > fTrkContribs
double T(const int i=0) const
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
fhicl::Atom< size_t > EffHitMax
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
fhicl::Atom< art::InputTag > HitModuleLabel
CodeOutputInterface * code
The data type to uniquely identify a TPC.
double fTrueTrkEnergyGuess
art::InputTag fTempTrackModuleLabel
const sim::ParticleList & ParticleList() const
Encapsulate the geometry of a wire.
TVector3 GetPositionInTPC(detinfo::DetectorClocksData const &clockData, simb::MCParticle part, int MCHit)
void analyze(art::Event const &evt) override
double Vx(const int i=0) const
art::InputTag fHitModuleLabel
Declaration of signal hit object.
fhicl::Atom< size_t > EnableParticleTree
Encapsulate the construction of a single detector plane.
Contains all timing reference information for the detector.
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc'th TPC in the cryostat.
double TotalLength() const
std::vector< sim::IDE > HitToAvgSimIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
art::InputTag fTrackModuleLabel
Provides recob::Track data product.
double Vz(const int i=0) const
int trigger_offset(DetectorClocksData const &data)
EventNumber_t event() const
float fTrkPurityPerPlane[3]
double fTrueTrkdEdX[10000]
fhicl::Sequence< int > Pdg
TPCID_t TPC
Index of the TPC within its cryostat.
TH1D * fDepDenominatorHist
fhicl::Atom< size_t > EffEMax
TH1D * fLengthDenominatorHist
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
const double * PlaneLocation(unsigned int p) const
double Vy(const int i=0) const
constexpr Point origin()
Returns a origin position with a point of the specified type.
QTextStream & endl(QTextStream &s)
Encapsulate the construction of a single detector plane.
double fTrueTrkStepE[10000]
fhicl::Atom< size_t > EffDepMax
double GetdEdX(simb::MCTrajectory traj, size_t this_step)
fhicl::Atom< size_t > EffHitBins
TH1D * fEnergyNominatorHist