22 #include "art_root_io/TFileService.h" 27 #include "canvas/Persistency/Common/FindOne.h" 28 #include "canvas/Persistency/Common/FindOneP.h" 29 #include "canvas/Persistency/Common/FindMany.h" 30 #include "canvas/Persistency/Common/FindManyP.h" 34 #include "MCCheater/BackTracker.h" 39 #include "TDatabasePDG.h" 40 #include "TParticlePDG.h" 44 #include <unordered_map> 74 float& forwardIonVal,
float& backwardIonVal);
76 float ionizeTruncate);
79 {
return a.first < b.first;}
166 consumesMany<std::vector<simb::MCTruth> >();
167 consumes<std::vector<simb::MCParticle> >(
fGeantLabel);
172 consumes<std::vector<rec::TrackIoniz>>(
fTrackLabel);
173 consumes<art::Assns<rec::TrackIoniz, rec::Track>>(
fTrackLabel);
190 fTree = tfs->make<TTree>(
"GArAnaTree",
"GArAnaTree");
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) {
415 track.
Vertex()[1] -positionMCP[1],
416 track.
Vertex()[2] -positionMCP[2]);
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;
463 trackInPhase =
new TVector3( theTrack.
VtxDir() );
464 trackInSpace =
new TVector3( theTrack.
Vertex() );
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()) {
519 float avgIonF, avgIonB;
542 float& forwardIonVal,
float& backwardIonVal) {
546 std::vector<std::pair<float,float>> SigData = ion.
getFWD_dSigdXs();
559 std::vector<std::pair<float,float>> dEvsX;
567 if (SigData.size()==0)
return 0.0;
568 float distAlongTrack = 0;
569 std::vector<std::pair<float,float>>
::iterator littlebit = SigData.begin();
570 for (; littlebit<(SigData.end()-1); ++littlebit) {
571 float dE = std::get<0>(*littlebit);
574 float dX = std::get<1>(*littlebit);
575 distAlongTrack += dX;
577 dX += std::get<1>(*(littlebit+1));
578 float dEdX = dE/(0.5*dX);
580 std::pair pushme = std::make_pair(dEdX,distAlongTrack);
581 dEvsX.push_back( pushme );
588 int goUpTo = ionizeTruncate * dEvsX.size() +0.5;
589 if (goUpTo > (
int)dEvsX.size()) goUpTo = dEvsX.size();
590 int i = 1;
float returnvalue = 0;
591 littlebit = dEvsX.begin();
592 for (; littlebit<dEvsX.end(); ++littlebit) {
593 returnvalue += std::get<0>(*littlebit);
597 returnvalue /= goUpTo;
float const & Momentum_beg() const
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
float const & LengthBackward() const
TrackEnd const TrackEndEnd
EDAnalyzer(fhicl::ParameterSet const &pset)
double dEdX(double KE, const simb::MCParticle *part)
std::enable_if_t< std::is_arithmetic_v< T >, T > hypot(T x, T y)
const float * VtxDir() const
int InteractionType() const
float const & LengthForward() const
const float * Vertex() const
#define DEFINE_ART_MODULE(klass)
T get(std::string const &key) const
const float * End() const
General GArSoft Utilities.
TrackEnd const TrackEndBeg
float const & Momentum_end() const
size_t const & NHits() const
gar::rec::IDNumber getIDNumber() const
Event generator information.
const std::vector< std::pair< float, float > > getBAK_dSigdXs() const
const std::vector< std::pair< float, float > > getFWD_dSigdXs() const
Event generator information.
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
Event finding and building.
const float * EndDir() const