17 #include "canvas/Persistency/Common/FindManyP.h" 22 #include "art_root_io/TFileService.h" 30 #include "TEfficiency.h" 108 names[1] =
"piminus";
127 std::vector<art::Ptr<simb::MCTruth>> MCtruthlist;
131 MCtruth = MCtruthlist[0];
138 const TLorentzVector& nu_momentum = nu.
Nu().
Momentum(0);
148 if( !isFiducial )
return;
151 std::vector<art::Ptr<recob::Hit> > hitlist;
152 auto hitListHandle =
event.getHandle< std::vector<recob::Hit> >(
fHitModuleLabel);
156 std::vector < art::Ptr < recob::PFParticle > > pfpList;
157 auto pfpListHandle =
event.getHandle < std::vector < recob::PFParticle > >(
fPFPModuleLabel);
163 std::vector < art::Ptr < recob::Cluster > > cluList;
164 auto cluListHandle =
event.getHandle < std::vector < recob::Cluster > >(
fPFPModuleLabel);
170 art::FindManyP<recob::Cluster> fmcpfp(pfpListHandle, event,
fPFPModuleLabel);
173 art::FindManyP<recob::Hit> fmhc(cluListHandle, event,
fPFPModuleLabel);
178 std::map<int, int> hitmap;
180 for (
auto const&
hit : hitlist){
181 if (
hit->WireID().Plane!=2)
continue;
182 std::map<int,double> trkide;
184 for(
size_t e = 0;
e < TrackIDs.size(); ++
e){
185 trkide[TrackIDs[
e].trackID] += TrackIDs[
e].energy;
192 if ((ii->second)>maxe){
203 std::map<int, float> completeness;
204 std::map<int, float> purity;
206 for (
size_t i = 0; i<pfpList.size(); ++i){
207 std::map<int, int> hitmap0;
208 if (fmcpfp.isValid()){
210 auto const& clusters = fmcpfp.at(i);
211 for (
auto const &
cluster : clusters){
214 auto const& hits = fmhc.at(
cluster.key());
217 for (
auto const&
hit : hits){
218 if (
hit->WireID().Plane!=2)
continue;
219 std::map<int,double> trkide;
221 for(
size_t e = 0;
e < TrackIDs.size(); ++
e){
222 trkide[TrackIDs[
e].trackID] += TrackIDs[
e].energy;
229 if ((ii->second)>maxe){
246 tothits += ii->second;
247 if ((ii->second)>maxhits){
248 maxhits = ii->second;
253 double new_completeness = 1.0*maxhits/hitmap[
TrackID];
254 double new_purity = 1.0*maxhits/tothits;
257 if (new_completeness*new_purity > completeness[TrackID]*purity[TrackID]){
258 completeness[
TrackID] = new_completeness;
264 const sim::ParticleList& plist = pi_serv->
ParticleList();
267 if (particle->
Mother() == 0){
268 for (
int i = 0; i<6; ++i){
270 h_den[i]->Fill(particle->
P());
271 if (completeness[particle->
TrackId()]>0){
272 h_num[i]->Fill(particle->
P());
274 if (completeness[particle->
TrackId()]>0.5&&
275 purity[particle->
TrackId()]>0.5){
287 auto const*
geo = lar::providerFrom<geo::Geometry>();
296 for (
size_t i = 0; i<
geo->NTPC(); ++i){
297 double local[3] = {0.,0.,0.};
298 double world[3] = {0.,0.,0.};
301 if (minx>world[0]-
geo->DetHalfWidth(i))
302 minx = world[0]-
geo->DetHalfWidth(i);
303 if (maxx<world[0]+
geo->DetHalfWidth(i))
304 maxx = world[0]+
geo->DetHalfWidth(i);
305 if (miny>world[1]-
geo->DetHalfHeight(i))
306 miny = world[1]-
geo->DetHalfHeight(i);
307 if (maxy<world[1]+
geo->DetHalfHeight(i))
308 maxy = world[1]+
geo->DetHalfHeight(i);
309 if (minz>world[2]-
geo->DetLength(i)/2.)
310 minz = world[2]-
geo->DetLength(i)/2.;
311 if (maxz<world[2]+
geo->DetLength(i)/2.)
312 maxz = world[2]+
geo->DetLength(i)/2.;
322 std::cout<<
"Fiducial volume:"<<
"\n" 329 for (
int i = 0; i<6; ++i){
330 h_den[i] = tfs->make<TH1D>(Form(
"h_den_%s",
names[i].c_str()), Form(
"%s;Momentum (GeV/c)",
names[i].c_str()), 40, 0, 20);
331 h_num[i] = tfs->make<TH1D>(Form(
"h_num_%s",
names[i].c_str()), Form(
"%s;Momentum (GeV/c)",
names[i].c_str()), 40, 0, 20);
332 h_num_good[i] = tfs->make<TH1D>(Form(
"h_num_good_%s",
names[i].c_str()), Form(
"%s;Momentum (GeV/c)",
names[i].c_str()), 40, 0, 20);
335 h_num_good[i]->Sumw2();
343 for (
int i = 0; i<6; ++i){
344 if (TEfficiency::CheckConsistency(*
h_num[i], *
h_den[i])){
347 eff[i]->Write(Form(
"eff_%s",
names[i].c_str()));
351 eff_good[i]->SetTitle((
names[i]+
", completeness>0.5, purity>0.5").c_str());
358 double x = vertex[0];
359 double y = vertex[1];
360 double z = vertex[2];
const TLorentzVector & Position(const int i=0) const
const simb::MCNeutrino & GetNeutrino() const
double MC_lepton_startMomentum[4]
std::vector< TrackID > TrackIDs
const simb::MCParticle * TrackIdToParticle_P(int id) const
const simb::MCParticle & Nu() const
Geometry information for a single TPC.
Cluster finding and building.
EDAnalyzer(fhicl::ParameterSet const &pset)
TEfficiency * eff_good[6]
art framework interface to geometry description
#define DEFINE_ART_MODULE(klass)
std::string fPFPModuleLabel
double P(const int i=0) const
PFPEfficiency & operator=(PFPEfficiency const &)=delete
std::string fHitModuleLabel
PFPEfficiency(fhicl::ParameterSet const &p)
Detector simulation of raw signals on wires.
const sim::ParticleList & ParticleList() const
Declaration of signal hit object.
void analyze(art::Event const &e) override
std::vector< sim::TrackIDE > HitToEveTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
const TLorentzVector & Momentum(const int i=0) const
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
std::string fMCTruthModuleLabel
Event generator information.
LArSoft geometry interface.
void LocalToWorld(const double *tpc, double *world) const
Transform point from local TPC frame to world frame.
Event finding and building.
bool insideFV(double vertex[4])