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())
std::string fGeneratorTag
const simb::MCParticle * GetGeantGoodParticle(const simb::MCTruth &genTruth, const art::Event &evt) const
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
const simb::MCTrajectory & Trajectory() const
const value_type & at(const size_type i) const
std::string KeyToProcess(unsigned char const &key) const
TH1D * hInteractingKEInel
std::vector< const sim::IDE * > TrackIdToSimIDEs_Ps(int const &id) const
std::string Process() const
TH1D * h_UniformDistances
TH1D * hInteractingKEElDep
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
ProcessMap const & TrajectoryProcesses() const
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
const sim::ParticleList & ParticleList() const
ProtoDUNETruthUtils truthUtil
below are some addition to be able to use protodune utitilites
EventNumber_t event() const
second_as<> second
Type of time stored in seconds, in double precision.
QTextStream & endl(QTextStream &s)