5 #include "art_root_io/TFileService.h" 6 #include "art_root_io/TFileDirectory.h" 9 #include "canvas/Persistency/Common/FindManyP.h" 53 #include "dune/DuneObj/ProtoDUNEBeamEvent.h" 60 #include "dune/Protodune/singlephase/DataUtils/ProtoDUNEDataUtils.h" 64 #include "TDirectory.h" 72 #include "TGraphErrors.h" 75 #include "TTimeStamp.h" 81 #include "TTimeStamp.h" 86 #include "TPaveStats.h" 217 double distance(
double x1,
double y1,
double z1,
double x2,
double y2,
double z2)
219 double d = TMath::Sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
229 fEventTree = tfs->make<TTree>(
"Event",
"Event Tree from Reco");
237 h_DEUniform = tfs->make<TH1D>(
"h_DEUniform",
"h_DE; Energy Deposited [MeV]",200, 0,100);
238 h_DXUniform = tfs->make<TH1D>(
"h_DXUniform",
"h_DX; Distance between points [cm]",400, 0,20);
239 h_DEDXUniform = tfs->make<TH1D>(
"h_DEDEXUniform",
"h_DEDX; dE/dX [MeV/cm]",500, 0,50);
240 h_DeltaE = tfs->make<TH1D>(
"h_DeltaE",
"h_DeltaE; dEDep - TrjDE [MeV/cm]",500, -1000,1000);
243 h_UniformDistances = tfs->make<TH1D>(
"h_UniformDistances",
"h_UniformDistances; Distance between uniform points [cm]",500, 0,5);
244 hInitialPz = tfs->make<TH1D>(
"hInitialPz" ,
"Initial Pz [MeV/c]" , 42, -100, 2000);
245 hInitialKE = tfs->make<TH1D>(
"hInitialKE" ,
"Initial Kinetic Energy [MeV]" , 42, -100, 2000);
246 hKEAtTPCFF = tfs->make<TH1D>(
"hKEAtTPCFF" ,
"Kinetic Energy @ TPC FF [MeV]" , 42, -100, 2000);
247 hIncidentKE = tfs->make<TH1D>(
"hIncidentKE" ,
"Incident Kinetic Energy [MeV]" , 42, -100, 2000);
249 processtot=tfs->make<TH1D>(
"processtot",
"Total number of interaction for each particle;number of interaction;number of entries",50,0,50);
250 processEl=tfs->make<TH1D>(
"processEl",
"Total number of Elastic interaction for each particle;number of interaction;number of entries",50,0,50);
251 processInel=tfs->make<TH1D>(
"processInel",
"Total number of InElastic interaction for each particle;number of interaction;number of entries",50,0,50);
252 hInteractingKE = tfs->make<TH1D>(
"hInteractingKE",
"Interacting Kinetic Energy [MeV]", 42, -100, 2000);
253 hInteractingKEEl = tfs->make<TH1D>(
"hInteractingKEEl",
"Elastic Interacting Kinetic Energy [MeV]", 42, -100, 2000);
254 hInteractingKEElDep = tfs->make<TH1D>(
"hInteractingKEElDep",
"Dep Elastic Interacting Kinetic Energy [MeV]", 42, -100, 2000);
255 hInteractingKEInel = tfs->make<TH1D>(
"hInteractingKEInel",
"Inelastic Interacting Kinetic Energy [MeV]", 42, -100, 2000);
256 hCrossSection = tfs->make<TH1D>(
"hCrossSection" ,
"Cross-Section [barn]" , 42, -100, 2000);
257 hCrossSectionEl = tfs->make<TH1D>(
"hCrossSectionEl" ,
"Elastic Cross-Section [barn]" , 42, -100, 2000);
258 hCrossSectionInel = tfs->make<TH1D>(
"hCrossSectionInel" ,
"Inelastic Cross-Section [barn]" , 42, -100, 2000);
259 hXZ = tfs->make<TH2D>(
"hXZ" ,
"hXZ" , 895, -200, 695 , 720, -360, 360);
260 hYZ = tfs->make<TH2D>(
"hYZ" ,
"hYZ" , 895, -200, 695 , 600, 0, 600);
261 hXZPre = tfs->make<TH2D>(
"hXZPre" ,
"hXZPre", 200, -100, 100 , 200, -100, 100);
262 hYZPre = tfs->make<TH2D>(
"hYZPre" ,
"hYZPre", 200, -100, 100 , 200, 300, 500);
263 hdEVsdX = tfs->make<TH2D>(
"hdEVsdX" ,
"hdEVsdX" , 504, -1, 50, 1100, -10, 100);
264 hdEVsKE = tfs->make<TH2D>(
"hdEVsKE" ,
"hdEVsKE" , 504, -1, 50, 220, -10, 1000);
299 bool keepInteraction=
false;
307 std::cout<<
"particle pdg code is "<<particle->PdgCode()<<
std::endl;
308 if(particle->PdgCode()==211 && particle->Process()==
"primary"){
314 std::map<double, sim::IDE> orderedSimIDE;
315 for (
auto& ide : simIDE_prim) orderedSimIDE[ide->z]= *ide;
317 double mass=particle->Mass();
318 if(verbose) std::cout<<
"mass "<<mass<<
"\n";
320 auto inTPCPoint = truetraj.
begin();
321 auto Momentum0 = inTPCPoint->second;
322 double KE0 = 1000*(TMath::Sqrt(Momentum0.X()*Momentum0.X() + Momentum0.Y()*Momentum0.Y() + Momentum0.Z()*Momentum0.Z() + mass*mass ) - mass);
325 if(verbose) std::cout<<KE0;
331 for (
auto t = truetraj.
begin();
t!= std::prev(truetraj.
end());
t++)
343 hXZPre->Fill((inTPCPoint->first).Z(), (inTPCPoint->first).
X());
344 hYZPre->Fill((inTPCPoint->first).Z(), (inTPCPoint->first).
Y());
345 if (inTPCPoint !=truetraj.
begin()){
347 hXZ ->Fill((inTPCPoint->first).Z(), (inTPCPoint->first).
X());
348 hYZ ->Fill((inTPCPoint->first).Z(), (inTPCPoint->first).
Y());
351 auto finTPCPoint = std::prev(truetraj.
end());
361 if (thisTracjectoryProcessMap.size())
363 for(
auto const& couple: thisTracjectoryProcessMap)
367 if(!verbose) std::cout<<(truetraj.
KeyToProcess(couple.second))<<
" Position "<<((truetraj.
at(couple.first)).first).Z()<<
" Momentum "<<((truetraj.
at(couple.first)).
second).Z()<<
std::endl;
368 if ((truetraj.
KeyToProcess(couple.second)).find(
"CoulombScat")!= std::string::npos)
continue;
371 auto interactionPos4D = (truetraj.
at(couple.first)).first ;
372 if (interactionPos4D.Z() <
minZ || interactionPos4D.Z() >
maxZ )
continue;
373 else if (interactionPos4D.X() <
minX || interactionPos4D.X() >
maxX )
continue;
374 else if (interactionPos4D.Y() <
minY || interactionPos4D.Y() >
maxY )
continue;
375 if ((truetraj.
KeyToProcess(couple.second)).find(
"hadElastic")!= std::string::npos) el++;
376 if ((truetraj.
KeyToProcess(couple.second)).find(
"pi+InElastic")!= std::string::npos) inel++;
380 interactionLabel = truetraj.
KeyToProcess(couple.second);
381 std::cout<<
"interaction Label "<<interactionLabel<<
" EndProcess "<<particle->EndProcess()<<
std::endl;
382 finTPCPoint = truetraj.
begin() + couple.first;
383 keepInteraction=
true;
389 std::cout<<
"this trjectory size "<<thisTracjectoryProcessMap.size()<<
std::endl;
398 if (!keepInteraction)
401 for(
size_t iPart1=0;(iPart1<plist.size()) && (plist.begin()!=plist.end());++iPart1)
406 if (pPart->
Mother() != 1 )
continue;
408 if ((pPart->
Process()).find(
"astic")!= std::string::npos)
continue;
409 if ((pPart->
Process()).find(
"CoulombScat")!= std::string::npos)
continue;
412 if (trueDaugthTraj.
begin()->first.Z() <
minZ || trueDaugthTraj.
begin()->first.Z() >
maxZ)
continue;
413 else if (trueDaugthTraj.
begin()->first.X() <
minX || trueDaugthTraj.
begin()->first.X() >
maxX )
continue;
414 else if (trueDaugthTraj.
begin()->first.Y() <
minY || trueDaugthTraj.
begin()->first.Y() >
maxY )
continue;
416 interactionLabel = pPart->
Process();
421 for (
auto t = std::prev(truetraj.
end());
t!= truetraj.
begin();
t--)
436 if (finTPCPoint != inTPCPoint){
437 auto posFin = finTPCPoint->first;
438 auto posIni = inTPCPoint->first;
447 auto totLength =
distance(posFin.X(), posFin.Y(), posFin.Z(),posIni.X(), posIni.Y(), posIni.Z() );
453 std::map<double, TVector3> orderedUniformTrjPts;
456 auto positionVector0 = (inTPCPoint ->first).Vect();
457 auto positionVector1 = (finTPCPoint->first).Vect();
458 orderedUniformTrjPts[positionVector0.Z()] = positionVector0;
459 orderedUniformTrjPts[positionVector1.Z()] = positionVector1;
461 const double trackPitch = 0.4792;
464 int nPts = (
int) (totLength/trackPitch);
465 for (
int iPt = 1; iPt <= nPts; iPt++ )
467 auto newPoint = positionVector0 + iPt*(trackPitch/totLength) * (positionVector1 - positionVector0);
468 orderedUniformTrjPts[newPoint.Z()] = newPoint;
472 auto lastPt = (orderedUniformTrjPts.rbegin())->
second;
473 auto secondtoLastPt = (std::next(orderedUniformTrjPts.rbegin()))->second;
474 double lastDist =
distance(lastPt.X(),lastPt.Y(),lastPt.Z(),secondtoLastPt.X(),secondtoLastPt.Y(),secondtoLastPt.Z());
475 if (lastDist < 0.240)
477 orderedUniformTrjPts.erase((std::next(orderedUniformTrjPts.rbegin()))->first );
481 auto initialMom = inTPCPoint->second;
482 double initialKE = 1000*(TMath::Sqrt(initialMom.X()*initialMom.X() + initialMom.Y()*initialMom.Y() + initialMom.Z()*initialMom.Z() + mass*mass ) - mass);
484 double kineticEnergy = initialKE;
485 auto old_it = orderedUniformTrjPts.begin();
486 for (
auto it = std::next(orderedUniformTrjPts.begin()); it != orderedUniformTrjPts.end(); it++, old_it++ )
489 if (verbose) std::cout << it->first<<
" : " << (it->second).
Z() <<
std::endl ;
490 auto oldPos = old_it->second;
491 auto currentPos = it->second;
493 double uniformDist = (currentPos - oldPos).Mag();
497 auto old_iter = orderedSimIDE.begin();
498 double currentDepEnergy = 0.;
499 for (
auto iter= orderedSimIDE.begin(); iter!= orderedSimIDE.end(); iter++,old_iter++)
501 auto currentIde = iter->second;
503 if ( currentIde.z < oldPos.Z())
continue;
504 if ( currentIde.z > currentPos.Z())
continue;
505 currentDepEnergy += currentIde.energy;
508 if (currentDepEnergy/uniformDist < 0.1 )
continue;
510 kineticEnergy -= currentDepEnergy;
511 hdEVsdX->Fill(currentDepEnergy,(currentPos.Z()-oldPos.Z()) );
512 hdEVsKE->Fill(currentDepEnergy,kineticEnergy);
520 if(interactionLabel.find(
"Inelastic")!= std::string::npos )
531 if ( interactionLabel.find(
"Elastic")!= std::string::npos )
536 h_DeltaE ->Fill(kineticEnergy - 1000*((finTPCPoint->second).E() - mass) );
546 keepInteraction =
false;
547 if (!interactionLabel.size())
569 std::cout<<
"-------------------------------------------"<<
std::endl;
575 std::cout<<
"-------------------------------------------"<<
std::endl;
577 float molar_mass = 39.95;
578 float g_per_kg = 1000;
579 float avogadro = 6.022e+23;
580 float number_density = rho*g_per_kg/molar_mass*avogadro;
582 float slab_width = 0.004792;
590 if(
hIncidentKE->GetBinContent(iBin) == 0 )
continue;
593 float TempCrossSection = (
hInteractingKE->GetBinContent(iBin)/
hIncidentKE->GetBinContent(iBin)) * (1/number_density) * (1/slab_width);
595 float elCrossSection = ((
hInteractingKEEl->GetBinContent(iBin)/
hIncidentKE->GetBinContent(iBin)) * (1/number_density) * (1/slab_width) ) * (1/1
e-28);
596 float inelCrossSection = ((
hInteractingKEInel->GetBinContent(iBin)/
hIncidentKE->GetBinContent(iBin)) * (1/number_density) * (1/slab_width) ) * (1/1
e-28);
598 float crossSection = TempCrossSection * (1/1
e-28);
609 if(denom == 0)
continue;
610 float term2 = denomError/denom;
620 float term1 = numError/
num;
621 float totalError = (TempCrossSection) * (
pow( ( (term1*term1) + (term2*term2) ),0.5)) * (1/number_density) * (1/slab_width) * (1/1
e-28) *(1e26);
626 float term1 = numErrorEl/numEl;
627 float totalError = (elCrossSection) * (
pow( ( (term1*term1) + (term2*term2) ),0.5)) * (1/number_density) * (1/slab_width) *(1e26);
632 float term1 = numErrorInel/numInel;
633 float totalError = (inelCrossSection) * (
pow( ( (term1*term1) + (term2*term2) ),0.5)) * (1/number_density) * (1/slab_width) *(1e26);
std::string fGeneratorTag
std::string fCalorimetryTag
const simb::MCParticle * GetGeantGoodParticle(const simb::MCTruth &genTruth, const art::Event &evt) const
std::string fCalorimetryModuleLabel
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
const simb::MCTrajectory & Trajectory() const
std::string fTrackModuleLabel
const value_type & at(const size_type i) const
virtual ~truepionXsection()
std::string KeyToProcess(unsigned char const &key) const
TH1D * hInteractingKEInel
std::vector< const sim::IDE * > TrackIdToSimIDEs_Ps(int const &id) const
EDAnalyzer(fhicl::ParameterSet const &pset)
std::string Process() const
std::string fPFParticleTag
object containing MC flux information
art framework interface to geometry description
truepionXsection(fhicl::ParameterSet const &pset)
TH1D * h_UniformDistances
#define DEFINE_ART_MODULE(klass)
TH1D * hInteractingKEElDep
std::string fHitsModuleLabel
const art::InputTag fBeamModuleLabel
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
SubRunNumber_t subRun() const
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
std::vector< std::string > G4Process
void analyze(const art::Event &evt)
void beginRun(const art::Run &run)
ProcessMap const & TrajectoryProcesses() const
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
Definition of data types for geometry description.
const sim::ParticleList & ParticleList() const
Declaration of signal hit object.
ProtoDUNETruthUtils truthUtil
below are some addition to be able to use protodune utitilites
Provides recob::Track data product.
EventNumber_t event() const
Declaration of basic channel signal object.
auto const & get(AssnsNode< L, R, D > const &r)
second_as<> second
Type of time stored in seconds, in double precision.
Utility functions to extract information from recob::Track
QTextStream & endl(QTextStream &s)
Event finding and building.