21 #include "art_root_io/TFileService.h" 22 #include "art_root_io/TFileDirectory.h" 24 #include "canvas/Persistency/Common/FindManyP.h" 121 std::vector<art::Ptr<recob::Hit> >
fHits;
171 fHits.push_back(hit);
202 void MakeDataProducts();
203 void FillData(
const std::map<
int,std::shared_ptr<ShowerParticle> >& particles);
204 void FillPi0Data(
const std::map<
int,std::shared_ptr<ShowerParticle> >& particles,
const std::vector<int>& pi0Decays);
228 TH1D *hShowerCompleteness, *hLargestShowerCompleteness, *
hShowerPurity, *hLargestShowerPurity;
229 TH2D *
hShowerCompletenessEnergy, *hLargestShowerCompletenessEnergy, *hShowerCompletenessDirection, *hLargestShowerCompletenessDirection;
230 TH1D *hShowerEnergy, *hShowerDepositedEnergy, *hShowerDirection, *hShowerdEdx, *
hShowerStart, *hShowerReconstructed, *hNumShowersReconstructed, *hNumShowersReconstructedNonZero;
232 TProfile *hShowerReconstructedEnergy, *hShowerdEdxEnergyProfile, *hNumShowersReconstructedEnergyProfile, *hShowerEnergyCompleteness, *
hShowerStartEnergy;
260 std::vector<art::Ptr<recob::Shower> >
showers;
266 std::vector<art::Ptr<recob::Cluster> > clusters;
272 std::vector<art::Ptr<recob::Hit> > hits;
278 std::vector<art::Ptr<recob::SpacePoint> > spacePoints;
280 if (spacePointHandle)
289 std::map<int,std::shared_ptr<ShowerParticle> > particles;
293 std::vector<int> pi0Decays;
300 int mother = trueParticle->
Mother();
301 if (mother != 0 and trueParticles.at(mother)->PdgCode() == 111) {
303 pi0Decays.push_back(particleIt->first);
306 std::map<int,double> depositedEnergy;
309 int plane =
geom->
View((*channelIt)->Channel());
310 auto const & tdcidemap = (*channelIt)->TDCIDEMap();
311 for (
auto const& tdcIt : tdcidemap) {
312 auto const& idevec = tdcIt.second;
313 for (
auto const& ideIt : idevec) {
314 if (TMath::Abs(ideIt.trackID) != trueParticle->
TrackId())
316 depositedEnergy[plane] += ideIt.energy / 1000;
321 std::shared_ptr<ShowerParticle> particle = std::make_shared<ShowerParticle>(trueParticle->
TrackId());
322 particle->SetEnergy(trueParticle->
E());
323 particle->SetDepositedEnergy(depositedEnergy);
324 particle->SetDirection(trueParticle->
Momentum().Vect().Unit());
325 particle->SetStart(trueParticle->
Position().Vect());
326 particle->SetEnd(trueParticle->
EndPosition().Vect());
327 particle->SetPDG(trueParticle->
PdgCode());
329 particles[particleIt->first] =
std::move(particle);
336 if (particles.count(trueParticle))
337 particles[trueParticle]->AddAssociatedHit(*hitIt);
341 std::vector<art::Ptr<recob::Hit> > hits = fmhc.at(clusterIt->key());
343 std::vector<art::Ptr<recob::Hit> > trueHits =
FindTrueHits(clockData, hits, trueParticle);
344 if (particles.count(trueParticle))
345 particles[trueParticle]->AddAssociatedCluster(*clusterIt, hits, trueHits);
349 std::vector<art::Ptr<recob::Hit> > hits = fmhs.at(showerIt->key());
351 std::vector<art::Ptr<recob::Hit> > trueHits =
FindTrueHits(clockData, hits, trueParticle);
352 if (particles.count(trueParticle))
353 particles[trueParticle]->AddAssociatedShower(*showerIt, hits, trueHits);
358 if (isPi0 and pi0Decays.size() == 2)
368 for (std::map<
int,std::shared_ptr<ShowerParticle> >::
const_iterator particleIt = particles.begin(); particleIt != particles.end(); ++particleIt) {
370 std::shared_ptr<ShowerParticle> particle = particleIt->second;
373 if (TMath::Abs(particle->PDG()) != 11 and TMath::Abs(particle->PDG()) != 22)
382 if (particle->LargestCluster(
cluster)) {
396 if (particle->LargestShower(
shower)) {
401 hShowerEnergy ->Fill(particle->ShowerEnergy() / particle->Energy());
404 hShowerDirection ->Fill(particle->Direction().Dot(particle->ShowerDirection()));
406 if (particle->PDG() == 22) {
407 hShowerStart ->Fill((particle->End() - particle->ShowerStart()).Mag());
408 hShowerStartEnergy ->Fill(particle->Energy(), (particle->End() - particle->ShowerStart()).Mag());
411 hShowerStart ->Fill((particle->Start() - particle->ShowerStart()).Mag());
412 hShowerStartEnergy ->Fill(particle->Energy(), (particle->Start() - particle->ShowerStart()).Mag());
422 if (particle->NumShowers()) {
441 std::shared_ptr<ShowerParticle> photon1 = particles.at(pi0Decays.at(0));
442 std::shared_ptr<ShowerParticle> photon2 = particles.at(pi0Decays.at(1));
445 if (photon1->NumShowers() == 0 or photon2->NumShowers() == 0 or
446 photon1->ShowerStart() == TVector3(0,0,0) or photon2->ShowerStart() == TVector3(0,0,0)) {
447 std::cout <<
"Event doesn't have enough info for pi0 mass determination" <<
std::endl;
451 double reconOpeningAngle = TMath::ASin(TMath::Sin(photon1->ShowerDirection().Angle(photon2->ShowerDirection())));
452 double trueOpeningAngle = photon1->Direction().Angle(photon2->Direction());
455 double massReconEnergyReconAngle = TMath::Sqrt(4 * photon1->ShowerEnergy() * photon2->ShowerEnergy() * TMath::Power(TMath::Sin(reconOpeningAngle/2),2));
456 double massReconEnergyTrueAngle = TMath::Sqrt(4 * photon1->ShowerEnergy() * photon2->ShowerEnergy() * TMath::Power(TMath::Sin(trueOpeningAngle/2),2));
457 double massTrueEnergyReconAngle = TMath::Sqrt(4 * photon1->Energy() * photon2->Energy() * TMath::Power(TMath::Sin(reconOpeningAngle/2),2));
458 double massTrueEnergyTrueAngle = TMath::Sqrt(4 * photon1->Energy() * photon2->Energy() * TMath::Power(TMath::Sin(trueOpeningAngle/2),2));
475 std::map<int,double> trackMap;
479 trackMap[trackID] += hit->
Integral();
483 double highestCharge = 0;
486 if (trackIt->second > highestCharge) {
487 highestCharge = trackIt->second;
488 showerTrack = trackIt->first;
501 double particleEnergy = 0;
502 int likelyTrackID = 0;
504 for (
unsigned int idIt = 0; idIt < trackIDs.size(); ++idIt) {
505 if (trackIDs.at(idIt).energy > particleEnergy) {
506 particleEnergy = trackIDs.at(idIt).energy;
507 likelyTrackID = TMath::Abs(trackIDs.at(idIt).trackID);
511 return likelyTrackID;
518 std::vector<art::Ptr<recob::Hit> > trueHits;
521 trueHits.push_back(*hitIt);
529 fTree =
tfs->make<TTree>(
"ShowerAnalysis",
"ShowerAnalysis");
532 hClusterCompleteness =
tfs->make<TH1D>(
"ClusterCompleteness",
"Completeness of all clusters;Completeness;",101,0,1.01);
534 hClusterPurity =
tfs->make<TH1D>(
"ClusterPurity",
"Purity of all clusters;Purity;",101,0,1.01);
536 hClusterCompletenessEnergy =
tfs->make<TH2D>(
"ClusterCompletenessEnergy",
"Completeness of all clusters vs Energy;Energy (GeV);Completeness;",100,0,10,101,0,1.01);
537 hLargestClusterCompletenessEnergy =
tfs->make<TH2D>(
"LargestClusterCompletenessEnergy",
"Completeness of largest cluster vs Energy;Energy (GeV);Completeness;",100,0,10,101,0,1.01);
538 hClusterCompletenessDirection =
tfs->make<TH2D>(
"ClusterCompletenessDirection",
"Completeness of all clusters vs Direction;Direction;Completeness;",100,0,5,101,0,1.01);
542 hShowerCompleteness =
tfs->make<TH1D>(
"ShowerCompleteness",
"Completeness of all showers;Completeness;",101,0,1.01);
544 hShowerPurity =
tfs->make<TH1D>(
"ShowerPurity",
"Purity of all showers;Purity;",101,0,1.01);
546 hShowerCompletenessEnergy =
tfs->make<TH2D>(
"ShowerCompletenessEnergy",
"Completeness of all showers vs Energy;Energy (GeV);Completeness;",100,0,10,101,0,1.01);
547 hLargestShowerCompletenessEnergy =
tfs->make<TH2D>(
"LargestShowerCompletenessEnergy",
"Completeness of largest shower vs Energy;Energy (GeV);Completeness;",100,0,10,101,0,1.01);
548 hShowerCompletenessDirection =
tfs->make<TH2D>(
"ShowerCompletenessDirection",
"Completeness of all showers vs Direction;Direction;Completeness;",100,0,5,101,0,1.01);
550 hShowerEnergy =
tfs->make<TH1D>(
"ShowerEnergy",
"Shower energy;Recon Energy/True Energy;",120,0,1.2);
551 hShowerDepositedEnergy =
tfs->make<TH1D>(
"ShowerDepositedEnergy",
"Shower deposited energy;Recon Energy/True (Deposited) Energy;",120,0,1.2);
552 hShowerDirection =
tfs->make<TH1D>(
"ShowerDirection",
"Shower direction;True Direction.(Recon Direction);",202,-1.01,1.01);
553 hShowerdEdx =
tfs->make<TH1D>(
"ShowerdEdx",
"dEdx of Shower;dE/dx (MeV/cm)",50,0,10);
554 hShowerStart =
tfs->make<TH1D>(
"ShowerStart",
"Distance from reconstructed shower start to true shower start;True Start - Recon Start (cm);",100,0,20);
555 hShowerReconstructed =
tfs->make<TH1D>(
"ShowerReconstructed",
"% of showering particles with reconstructed shower",101,0,1.01);
556 hShowerEnergyCompleteness =
tfs->make<TProfile>(
"ShowerEnergyCompleteness",
"Shower energy completeness vs true deposited energy;True (Deposited) Energy (GeV);Energy Completeness;",100,0,5);
557 hShowerStartEnergy =
tfs->make<TProfile>(
"ShowerStartEnergy",
"Shower start distance vs true deposited energy;True (Deposited) Energy (GeV);True Start - Recon Start (cm);",100,0,5);
558 hNumShowersReconstructed =
tfs->make<TH1D>(
"NumShowersReconstructed",
"Number of showers reconstructed for each showering particle;Number of Showers",10,0,10);
559 hNumShowersReconstructedNonZero =
tfs->make<TH1D>(
"NumShowersReconstructedNonZero",
"Number of showers reconstructed for each showering particle;Number of Showers",9,1,10);
560 for (
int n_showers = 0; n_showers < 9; ++n_showers) {
561 hNumShowersReconstructed->GetXaxis()->SetBinLabel(n_showers+1,
std::to_string(n_showers).c_str());
562 hNumShowersReconstructedNonZero->GetXaxis()->SetBinLabel(n_showers+1,
std::to_string(n_showers+1).c_str());
564 hNumShowersReconstructed->GetXaxis()->SetBinLabel(10,
"9 or more");
565 hNumShowersReconstructedNonZero->GetXaxis()->SetBinLabel(9,
"9 or more");
566 hShowerReconstructedEnergy =
tfs->make<TProfile>(
"ShowerReconstructedEnergyProfile",
"% of showering particles with reconstructed shower vs true energy;True Energy (GeV);Fraction of particles with reconstructed shower;",100,0,5);
567 hNumShowersReconstructedEnergy =
tfs->make<TH2D>(
"NumShowersReconstructedEnergy",
"Number of showers reconstructed per showering particle vs true energy;True Energy (GeV);Average Number of Showers;",100,0,5,10,0,10);
569 hShowerdEdxEnergy =
tfs->make<TH2D>(
"ShowerdEdxEnergy",
"Shower dE/dx vs true energy;True Energy (GeV);dE/dx (MeV/cm);",100,0,5,50,0,10);
571 hElectronPull =
tfs->make<TH1D>(
"ElectronPull",
"Electron pull;Electron pull;",100,-10,10);
572 hPhotonPull =
tfs->make<TH1D>(
"PhotonPull",
"Photon pull;Photon pull;",100,-10,10);
def analyze(root, level, gtrees, gbranches, doprint)
double E(const int i=0) const
TH1D * hLargestShowerPurity
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
double ShowerdEdx() const
const TLorentzVector & Position(const int i=0) const
art::ServiceHandle< cheat::ParticleInventoryService > pi_serv
double ClusterCompleteness(int cluster) const
TH1D * hNumShowersReconstructed
void cluster(In first, In last, Out result, Pred *pred)
TProfile * hShowerEnergyCompleteness
void SetStart(TVector3 start)
const TLorentzVector & EndPosition() const
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
TProfile * hShowerdEdxEnergyProfile
TVector3 Direction() const
Handle< PROD > getHandle(SelectorBase const &) const
int LargestShower() const
TVector3 ShowerStart() const
const std::vector< double > & Energy() const
int FindParticleID(detinfo::DetectorClocksData const &clockData, const art::Ptr< recob::Hit > &hit)
double ShowerEnergy(int shower) const
std::vector< art::Ptr< recob::Cluster > > fClusters
TH1D * hPi0MassPeakReconEnergyReconAngle
void FillData(const std::map< int, std::shared_ptr< ShowerParticle > > &particles)
int FindTrueParticle(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits)
void SetDirection(TVector3 direction)
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
art::ServiceHandle< art::TFileService > tfs
bool LargestCluster(int cluster) const
Cluster finding and building.
art::ServiceHandle< cheat::BackTrackerService > bt_serv
TH2D * hLargestClusterCompletenessDirection
art framework interface to geometry description
TH2D * hLargestShowerCompletenessEnergy
std::string fShowerModuleLabel
TH1D * hLargestClusterCompleteness
std::string fClusterModuleLabel
double fElectrondEdxWidth
bool LargestShower(int shower) const
void SetEnergy(double energy)
TH2D * hClusterCompletenessDirection
const std::vector< double > & dEdx() const
#define DEFINE_ART_MODULE(klass)
TH2D * hNumShowersReconstructedEnergy
TH1D * hPi0MassPeakReconEnergyTrueAngle
TH1D * hShowerReconstructed
TProfile * hNumShowersReconstructedEnergyProfile
double ShowerPurity(int shower) const
int LargestCluster() const
std::vector< std::vector< art::Ptr< recob::Hit > > > fClusterHits
void AddAssociatedCluster(const art::Ptr< recob::Cluster > &cluster, const std::vector< art::Ptr< recob::Hit > > &hits, const std::vector< art::Ptr< recob::Hit > > &trueHits)
T get(std::string const &key) const
std::vector< std::vector< art::Ptr< recob::Hit > > > fShowerHits
ShowerAnalysis(const fhicl::ParameterSet &pset)
TVector3 ShowerDirection(int shower) const
TH2D * hShowerCompletenessEnergy
TH1D * hLargestClusterPurity
TH1D * hNumShowersReconstructedNonZero
std::vector< std::vector< art::Ptr< recob::Hit > > > fClusterTrueHits
art::ServiceHandle< geo::Geometry > geom
TVector3 ShowerStart(int shower) const
double DepositedEnergy(int plane) const
std::vector< art::Ptr< recob::Shower > > fShowers
TH1D * hPi0MassPeakTrueEnergyReconAngle
double DepositedEnergy() const
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
void SetDepositedEnergy(std::map< int, double > depositedEnergy)
Detector simulation of raw signals on wires.
TH1D * hShowerCompleteness
const sim::ParticleList & ParticleList() const
std::vector< art::Ptr< recob::Hit > > fHits
Encapsulate the geometry of a wire.
std::vector< art::Ptr< recob::Hit > > FindTrueHits(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, int trueParticle)
TH1D * hShowerDepositedEnergy
TH2D * hLargestClusterCompletenessEnergy
Declaration of signal hit object.
TH1D * hPi0MassPeakTrueEnergyTrueAngle
void AddAssociatedHit(const art::Ptr< recob::Hit > &hit)
Encapsulate the construction of a single detector plane.
double ShowerEnergy() const
Contains all timing reference information for the detector.
TVector3 ShowerDirection() const
TH1D * hClusterCompleteness
const TLorentzVector & Momentum(const int i=0) const
Provides recob::Track data product.
TProfile * hShowerReconstructedEnergy
void SetEnd(TVector3 end)
void FillPi0Data(const std::map< int, std::shared_ptr< ShowerParticle > > &particles, const std::vector< int > &pi0Decays)
const std::vector< art::Ptr< sim::SimChannel > > & SimChannels() const
double ShowerCompleteness(int shower) const
TH2D * hShowerCompletenessDirection
double ClusterPurity(int cluster) const
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
std::vector< std::vector< art::Ptr< recob::Hit > > > fShowerTrueHits
TProfile * hShowerStartEnergy
std::string fHitsModuleLabel
double ShowerdEdx(int shower) const
void analyze(const art::Event &evt)
std::map< int, double > fDepositedEnergy
std::string to_string(ModuleType const mt)
TH2D * hLargestShowerCompletenessDirection
TH1D * hLargestShowerCompleteness
TH2D * hClusterCompletenessEnergy
QTextStream & endl(QTextStream &s)
void AddAssociatedShower(const art::Ptr< recob::Shower > &shower, const std::vector< art::Ptr< recob::Hit > > &hits, const std::vector< art::Ptr< recob::Hit > > &trueHits)