300 auto mctruthHandles =
event.getMany<std::vector<simb::MCTruth> >();
302 if (mctruthHandles.size()!=1) {
303 throw cet::exception(
"MomentumPerformance") <<
" Need just 1 simb::MCTruth" 304 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
307 auto MCPHandle =
event.getHandle< std::vector<simb::MCParticle> >(
fGeantLabel);
309 throw cet::exception(
"MomentumPerformance") <<
" No simb::MCParticle" 310 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
314 art::FindOneP<rec::TrackIoniz>* findIonization = NULL;
316 auto TrackHandle =
event.getHandle< std::vector<rec::Track> >(
fTrackLabel);
319 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
322 auto TrackIonHandle =
event.getHandle< std::vector<rec::TrackIoniz> >(
fTrackLabel);
323 if (!TrackIonHandle) {
324 throw cet::exception(
"MomentumPerformance") <<
" No rec::TrackIoniz" 325 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
327 findIonization =
new art::FindOneP<rec::TrackIoniz>(TrackHandle,
event,
fTrackLabel);
336 fEvent =
event.id().event();
342 if (!mct.NeutrinoSet())
return;
354 std::unordered_map<TrkId, Int_t> TrackIdToIndex;
356 for (
auto const& mcp : *MCPHandle ) {
357 int TrackId = mcp.TrackId();
358 TrackIdToIndex[TrackId] = index++;
365 TrkId momTrkId = mcp.Mother();
368 if(TrackIdToIndex.find(momTrkId) != TrackIdToIndex.end()){
369 Int_t momIndex = TrackIdToIndex[momTrkId];
370 momPDG = (*MCPHandle).at(momIndex).PdgCode();
373 << mcp.TrackId() <<
" pdg code " << mcp.PdgCode()
374 <<
" could not find mother trk id " << momTrkId
375 <<
" in the TrackIdToIndex map; creating process is " 376 << mcp.Process() <<
"\nLine " << __LINE__ <<
" in file " 380 if (momPDG != 0)
continue;
385 int thisPDG = mcp.PdgCode();
387 abs(thisPDG)==13 ||
abs(thisPDG)==11 ||
abs(thisPDG)==211 ||
abs(thisPDG)==2212;
388 if (!isTrackable)
continue;
390 const TLorentzVector& positionMCP = mcp.Position(0);
391 const TLorentzVector& momentumMCP = mcp.Momentum(0);
396 std::vector<art::Ptr<rec::Track>> allTracks;
398 for (
size_t iTrack=0; iTrack<TrackHandle->size(); ++iTrack ) {
399 allTracks.push_back( trackPtrMaker(iTrack) );
402 std::vector<art::Ptr<rec::Track>> matchedTracks;
409 int pickedTrack = -1;
412 for (iTrack=0; iTrack<matchedTracks.size(); ++iTrack) {
414 float distStart =
std::hypot(track.Vertex()[0] -positionMCP[0],
415 track.Vertex()[1] -positionMCP[1],
416 track.Vertex()[2] -positionMCP[2]);
417 float distEnd =
std::hypot(track.End()[0] -positionMCP[0],
418 track.End()[1] -positionMCP[1],
419 track.End()[2] -positionMCP[2]);
420 if (distStart<distEnd) {
421 if (distStart<minDist) {
422 pickedTrack = iTrack;
427 if (distEnd<minDist) {
428 pickedTrack = iTrack;
434 if (pickedTrack == -1)
continue;
440 fMCP_X.push_back(positionMCP.X());
441 fMCP_Y.push_back(positionMCP.Y());
442 fMCP_Z.push_back(positionMCP.Z());
443 fMCP_PX.push_back(momentumMCP.Px());
444 fMCP_PY.push_back(momentumMCP.Py());
445 fMCP_PZ.push_back(momentumMCP.Pz());
449 rec::Track theTrack = *(matchedTracks[pickedTrack]);
452 TVector3* trackInPhase; TVector3* trackInSpace;
455 fTrackX.push_back (theTrack.Vertex()[0]);
456 fTrackY.push_back (theTrack.Vertex()[1]);
457 fTrackZ.push_back (theTrack.Vertex()[2]);
458 fTrackPX.push_back (theTrack.Momentum_beg()*theTrack.VtxDir()[0]);
459 fTrackPY.push_back (theTrack.Momentum_beg()*theTrack.VtxDir()[1]);
460 fTrackPZ.push_back (theTrack.Momentum_beg()*theTrack.VtxDir()[2]);
461 fTrackQ.push_back (theTrack.ChargeBeg());
462 fTrackLen.push_back(theTrack.LengthBackward());
463 trackInPhase =
new TVector3( theTrack.VtxDir() );
464 trackInSpace =
new TVector3( theTrack.Vertex() );
466 fTrackX.push_back (theTrack.End()[0]);
467 fTrackY.push_back (theTrack.End()[1]);
468 fTrackZ.push_back (theTrack.End()[2]);
469 fTrackPX.push_back (theTrack.Momentum_end()*theTrack.EndDir()[0]);
470 fTrackPY.push_back (theTrack.Momentum_end()*theTrack.EndDir()[1]);
471 fTrackPZ.push_back (theTrack.Momentum_end()*theTrack.EndDir()[2]);
472 fTrackQ.push_back (theTrack.ChargeEnd());
473 fTrackLen.push_back(theTrack.LengthForward());
474 trackInPhase =
new TVector3( theTrack.EndDir() );
475 trackInSpace =
new TVector3( theTrack.End() );
482 int num, den; num = den = 0;
483 for (
int iTrack_local=0; iTrack_local<(
int)matchedTracks.size(); ++iTrack_local) {
484 rec::Track thisTrack = *(matchedTracks[iTrack_local]);
486 den += umlazi.size();
487 if (iTrack_local == pickedTrack) num += umlazi.size();
493 float cosT = (*trackInPhase)[0]*momentumMCP.Px()
494 +(*trackInPhase)[1]*momentumMCP.Py()
495 +(*trackInPhase)[2]*momentumMCP.Pz();
496 cosT /= momentumMCP.P();
499 TVector3 vecX( (*trackInSpace)[0] -positionMCP.X(),
500 (*trackInSpace)[1] -positionMCP.Y(),
501 (*trackInSpace)[2] -positionMCP.Z() );
502 float delX = vecX.Cross(*trackInPhase).Mag();
509 int iPickedTrack = -1;
510 for (
size_t iTrack_local=0; iTrack_local<TrackHandle->size(); ++iTrack_local ) {
511 if ( allTracks[iTrack_local]->getIDNumber() == theTrack.getIDNumber() ) {
512 iPickedTrack = iTrack_local;
516 if (iPickedTrack>=0 && findIonization->isValid()) {
518 rec::TrackIoniz ionization = *(findIonization->at(iPickedTrack));
519 float avgIonF, avgIonB;
std::vector< art::Ptr< rec::Track > > MCParticleToTracks(simb::MCParticle *const p, std::vector< art::Ptr< rec::Track >> const &tracks)
std::vector< art::Ptr< rec::Hit > > const TrackToHits(rec::Track *const t)
const simb::MCParticle & Nu() const
TrackEnd const TrackEndEnd
std::enable_if_t< std::is_arithmetic_v< T >, T > hypot(T x, T y)
int InteractionType() const
TrackEnd const TrackEndBeg
TrackCollectionProxyElement< TrackCollProxy > Track
Proxy to an element of a proxy collection of recob::Track objects.
Event generator information.
Event generator information.
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)