127 const sim::ParticleList & plist = pi_serv->
ParticleList();
133 auto mcTruths =
evt.getValidHandle<std::vector<simb::MCTruth>>(
fGeneratorTag);
138 bool keepInteraction =
false;
140 if(geantGoodParticle != 0x0){
141 std::cout <<
"Found GEANT particle corresponding to the good particle with pdg = " << geantGoodParticle->PdgCode() <<
std::endl;
142 std::cout <<
"ID: " << geantGoodParticle->TrackId() <<
std::endl;
143 std::cout <<
"Mother: " << geantGoodParticle->Mother() <<
std::endl;
145 if(geantGoodParticle->PdgCode()==211 && geantGoodParticle->Process()==
"primary" && geantGoodParticle->NumberDaughters()!=0){
146 std::cout<<
"Track ID of the geantGoodParticle "<<geantGoodParticle->TrackId()<<
std::endl;
147 std::cout<<
"Process:"<<geantGoodParticle->Process()<<
std::endl;
154 std::map<double, sim::IDE> orderedSimIDE;
155 for (
auto& ide : simIDE_prim) orderedSimIDE[ide->z]= *ide;
158 double mass=geantGoodParticle->Mass();
160 auto inTPCPoint = truetraj.
begin();
166 for (
auto t = truetraj.
begin();
t!= std::prev(truetraj.
end());
t++){
177 if (inTPCPoint !=truetraj.
begin()) {
180 auto finTPCPoint = std::prev(truetraj.
end());
186 std::cout<<
"thisTrajectoryProcessMap size: "<<thisTracjectoryProcessMap.size()<<
std::endl;
189 for(
auto const& couple: thisTracjectoryProcessMap) {
191 if ((truetraj.
KeyToProcess(couple.second)).find(
"CoulombScat")!= std::string::npos)
continue;
194 auto interactionPos4D = (truetraj.
at(couple.first)).first ;
195 if (interactionPos4D.Z() <
minZ || interactionPos4D.Z() >
maxZ )
continue;
196 else if (interactionPos4D.X() <
minX || interactionPos4D.X() >
maxX )
continue;
197 else if (interactionPos4D.Y() <
minY || interactionPos4D.Y() >
maxY )
continue;
198 if ((truetraj.
KeyToProcess(couple.second)).find(
"InElastic")!= std::string::npos) inel++;
202 std::cout <<
"key: " << size_t(couple.second) <<
std::endl;
203 interactionLabel = truetraj.
KeyToProcess(couple.second);
204 std::cout<<
"interaction Label "<<interactionLabel<<
" EndProcess "<<geantGoodParticle->EndProcess()<<
std::endl;
205 finTPCPoint = truetraj.
begin() + couple.first;
206 keepInteraction=
true;
213 if (!keepInteraction) {
215 for(
size_t iPart1=0;(iPart1<plist.size()) && (plist.begin()!=plist.end());++iPart1){
219 if (pPart->
Mother() != 1 )
continue;
221 if ((pPart->
Process()).find(
"astic")!= std::string::npos)
continue;
222 if ((pPart->
Process()).find(
"CoulombScat")!= std::string::npos)
continue;
225 if (trueDaugthTraj.
begin()->first.Z() <
minZ || trueDaugthTraj.
begin()->first.Z() >
maxZ)
continue;
226 else if (trueDaugthTraj.
begin()->first.X() <
minX || trueDaugthTraj.
begin()->first.X() >
maxX )
continue;
227 else if (trueDaugthTraj.
begin()->first.Y() <
minY || trueDaugthTraj.
begin()->first.Y() >
maxY )
continue;
229 interactionLabel = pPart->
Process();
234 for (
auto t = std::prev(truetraj.
end());
t!= truetraj.
begin();
t--){
247 if (finTPCPoint != inTPCPoint){
248 auto posFin = finTPCPoint->first;
249 auto posIni = inTPCPoint->first;
252 auto totLength =
distance(posFin.X(), posFin.Y(), posFin.Z(),posIni.X(), posIni.Y(), posIni.Z() );
258 std::map<double, TVector3> orderedUniformTrjPts;
261 auto positionVector0 = (inTPCPoint ->first).Vect();
262 auto positionVector1 = (finTPCPoint->first).Vect();
263 orderedUniformTrjPts[positionVector0.Z()] = positionVector0;
264 orderedUniformTrjPts[positionVector1.Z()] = positionVector1;
266 const double trackPitch = 0.4792;
269 int nPts = (
int) (totLength/trackPitch);
270 for (
int iPt = 1; iPt <= nPts; iPt++ ){
271 auto newPoint = positionVector0 + iPt*(trackPitch/totLength) * (positionVector1 - positionVector0);
272 orderedUniformTrjPts[newPoint.Z()] = newPoint;
277 auto lastPt = (orderedUniformTrjPts.rbegin())->
second;
278 auto secondtoLastPt = (std::next(orderedUniformTrjPts.rbegin()))->second;
279 double lastDist =
distance(lastPt.X(),lastPt.Y(),lastPt.Z(),secondtoLastPt.X(),secondtoLastPt.Y(),secondtoLastPt.Z());
280 if (lastDist < 0.240){
281 orderedUniformTrjPts.erase((std::next(orderedUniformTrjPts.rbegin()))->first );
285 auto initialMom = inTPCPoint->second;
286 double initialKE = 1000*(TMath::Sqrt(initialMom.X()*initialMom.X() + initialMom.Y()*initialMom.Y() + initialMom.Z()*initialMom.Z() + mass*mass ) - mass);
287 double kineticEnergy = initialKE;
288 auto old_it = orderedUniformTrjPts.begin();
289 for (
auto it = std::next(orderedUniformTrjPts.begin()); it != orderedUniformTrjPts.end(); it++, old_it++ ){
291 auto oldPos = old_it->second;
292 auto currentPos = it->second;
294 double uniformDist = (currentPos - oldPos).Mag();
297 auto old_iter = orderedSimIDE.begin();
298 double currentDepEnergy = 0.;
299 for (
auto iter= orderedSimIDE.begin(); iter!= orderedSimIDE.end(); iter++,old_iter++){
300 auto currentIde = iter->second;
302 if ( currentIde.z < oldPos.Z())
continue;
303 if ( currentIde.z > currentPos.Z())
continue;
304 currentDepEnergy += currentIde.energy;
308 if (currentDepEnergy/uniformDist < 0.1 )
continue;
311 kineticEnergy -= currentDepEnergy;
315 if(interactionLabel.find(
"Inelastic")!= std::string::npos ){
318 int nPiPlus_truth = 0;
319 int nPiMinus_truth = 0;
321 int nProton_truth = 0;
322 int nNeutron_truth = 0;
325 std::cout <<
"NDaughters: " << geantGoodParticle->NumberDaughters() <<
std::endl;
326 for(
int i = 0; i < geantGoodParticle->NumberDaughters(); ++i ){
327 std::cout <<
"Checking " << i <<
std::endl;
328 int daughterID = geantGoodParticle->Daughter(i);
330 std::cout <<
"Daughter " << i <<
" ID: " << daughterID <<
std::endl;
332 if( plist[ daughterID ]->
PdgCode() == 22 || plist[ daughterID ]->
PdgCode() > 1000000000 )
continue;
334 auto part = plist[ daughterID ];
335 int pid = part->PdgCode();
336 std::cout <<
"PID: " << pid <<
std::endl;
337 std::cout <<
"Process: " << part->Process() <<
std::endl;
339 if( pid == 211 ) nPiPlus_truth++;
340 else if( pid == -211 ) nPiMinus_truth++;
341 else if( pid == 111 ) nPi0_truth++;
342 else if( pid == 2212 ) nProton_truth++;
343 else if( pid == 2112 ) nNeutron_truth++;
347 if( nPiPlus_truth == 1 && nPiMinus_truth == 0 && nPi0_truth == 0 ){
351 else if( nPiPlus_truth == 0 && nPiMinus_truth == 0 && nPi0_truth == 0 ){
355 else if( nPiPlus_truth == 0 && nPiMinus_truth == 0 && nPi0_truth == 1 ){
359 else if( nPiPlus_truth == 0 && nPiMinus_truth == 1 && nPi0_truth == 0 ){
360 std::cout <<
"Filling DCex" <<
std::endl;
364 std::cout <<
"Filling Prod" <<
std::endl;
369 keepInteraction =
false;
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
std::vector< const sim::IDE * > TrackIdToSimIDEs_Ps(int const &id) const
std::string Process() const
int PdgCode(Resonance_t res, int Q)
(resonance id, charge) -> PDG code
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
TH1D * hInteractingKEDCex
TH1D * hInteractingKEProd
TH1D * hInteractingKEInel
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
second_as<> second
Type of time stored in seconds, in double precision.
QTextStream & endl(QTextStream &s)