2 #include "HepMC/GenEvent.h"
3 #include "HepMC/GenVertex.h"
4 #include "HepMC/GenParticle.h"
26 using namespace HepPDT;
39 nChargedParticleTracks(0),
77 nChargedParticleTracks(0),
84 if ( vtxType ==
"Gaussian" )
86 else if ( vtxType ==
"Flat" )
88 else if ( vtxType ==
"BetaFunc" )
190 const std::vector<SimVertex>& simVertices) {
197 unsigned nVtx = simVertices.size();
198 unsigned nTks = simTracks.size();
201 if ( nVtx == 0 )
return;
204 std::vector<int> myVertices(nVtx,-1);
205 std::vector<int> myTracks(nTks,-1);
210 std::map<unsigned, unsigned> geantToIndex;
211 for(
unsigned it=0; it<simTracks.size(); ++it ) {
212 geantToIndex[ simTracks[it].trackId() ] = it;
235 myFilter->setMainVertex(primaryVertex);
240 for(
unsigned trackId=0; trackId<nTks; ++trackId ) {
256 std::map<unsigned, unsigned >::iterator association
257 = geantToIndex.find( motherGeantId );
258 if(association != geantToIndex.end() )
259 motherId = association->second;
261 int originId = motherId == - 1 ? -1 : myTracks[motherId];
275 if ( myVertices[vertexId] == -1 )
283 int motherType = motherId == -1 ? 0 : simTracks[motherId].type();
285 bool notBremInDetector =
286 (
abs(motherType) != 11 &&
abs(motherType) != 13) ||
287 motherType != track.
type() ||
290 if ( notBremInDetector ) {
299 part.setID(track.
type());
305 if ( myTracks[trackId] >= 0 ) {
311 myTracks[trackId] = myTracks[motherId];
312 if ( myTracks[trackId] >= 0 ) {
321 for(
unsigned vertexId=0; vertexId<nVtx; ++vertexId ) {
324 if ( myVertices[vertexId] != -1 )
continue;
335 std::map<unsigned, unsigned >::iterator association
336 = geantToIndex.find( motherGeantId );
337 if(association != geantToIndex.end() )
338 motherId = association->second;
340 int originId = motherId == - 1 ? -1 : myTracks[motherId];
359 for(
int fsimi=0; fsimi < (int)
nTracks() ; ++fsimi) {
376 if ( mom.T() > 0. ) {
402 if ( myPart.
cos2ThetaV()>0.8 || mom.T() < 3. ) {
429 int genEventSize = myGenEvent.particles_size();
430 std::vector<int> myGenVertices(genEventSize, static_cast<int>(0));
433 if ( myGenEvent.particles_empty() )
return;
439 HepMC::GenVertex* primaryVertex = *(myGenEvent.vertices_begin());
442 unsigned primaryMother = primaryVertex->particles_in_size();
443 if ( primaryMother ) {
444 unsigned partId = (*(primaryVertex->particles_in_const_begin()))->pdg_id();
445 if (
abs(partId) == 2212 ) primaryMother = 0;
450 primaryVertex->position().y()/10.,
451 primaryVertex->position().z()/10.,
452 primaryVertex->position().t()/10.);
454 primaryVertexPosition *= (1-primaryMother);
460 if ( primaryVertexPosition.Vect().Mag2() < 1E-16 ) {
470 myFilter->setMainVertex(primaryVertexPosition+smearedVertex);
475 HepMC::GenEvent::particle_const_iterator piter;
476 HepMC::GenEvent::particle_const_iterator pbegin = myGenEvent.particles_begin();
477 HepMC::GenEvent::particle_const_iterator pend = myGenEvent.particles_end();
479 int initialBarcode = 0;
480 if ( pbegin != pend ) initialBarcode = (*pbegin)->barcode();
482 for ( piter = pbegin; piter != pend; ++piter ) {
500 HepMC::GenVertex* productionVertex = p->production_vertex();
501 if ( productionVertex ) {
502 unsigned productionMother = productionVertex->particles_in_size();
503 if ( productionMother ) {
504 unsigned motherId = (*(productionVertex->particles_in_const_begin()))->pdg_id();
505 if (
abs(motherId) < 1000000 )
506 productionVertexPosition =
508 productionVertex->position().y()/10.,
509 productionVertex->position().z()/10.,
510 productionVertex->position().t()/10.) + smearedVertex;
513 if ( !
myFilter->accept(productionVertexPosition) )
continue;
515 int abspdgId =
abs(p->pdg_id());
516 HepMC::GenVertex* endVertex = p->end_vertex();
520 bool testStable = p->status()%1000==1;
523 if ( p->status() == 2 && abspdgId < 1000000) {
527 endVertex->position().y()/10.,
528 endVertex->position().z()/10.,
529 endVertex->position().t()/10.) + smearedVertex;
536 bool testDaugh =
false;
540 endVertex->particles_out_size() ) {
541 HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
542 endVertex->particles_out_const_begin();
543 HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
544 endVertex->particles_out_const_end();
545 for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
547 if ( daugh->status()%1000==1 ) {
549 if (abspdgId == 11 || abspdgId == 13) {
552 endVertex->position().y()/10.,
553 endVertex->position().z()/10.,
554 endVertex->position().t()/10.);
569 if ( !testStable && !testDaugh && p->production_vertex() ) {
571 productionVertexPosition(p->production_vertex()->position().x()/10.,
572 p->production_vertex()->position().y()/10.,
573 p->production_vertex()->position().z()/10.,
574 p->production_vertex()->position().t()/10.);
575 dist = (primaryVertexPosition-productionVertexPosition).Vect().Mag2();
577 bool testDecay = ( dist > 1
e-8 ) ?
true :
false;
580 if ( testStable || testDaugh || testDecay ) {
587 int motherBarcode = p->production_vertex() &&
588 p->production_vertex()->particles_in_const_begin() !=
589 p->production_vertex()->particles_in_const_end() ?
590 (*(p->production_vertex()->particles_in_const_begin()))->barcode() : 0;
593 motherBarcode && myGenVertices[motherBarcode-initialBarcode] ?
594 myGenVertices[motherBarcode-initialBarcode] : mainVertex;
601 part.setID(p->pdg_id());
605 int theTrack = testStable && p->end_vertex() ?
616 ( testStable && p->end_vertex() && !p->end_vertex()->particles_out_size() )
623 p->end_vertex()->position().y()/10.,
624 p->end_vertex()->position().z()/10.,
625 p->end_vertex()->position().t()/10.) +
630 if ( theVertex != -1 ) myGenVertices[p->barcode()-initialBarcode] = theVertex;
642 unsigned int nParticles = myGenParticles.size();
645 if ( !nParticles )
return;
648 std::map<const reco::Candidate*,int> myGenVertices;
656 if ( nParticles > 1 &&
657 myGenParticles[0].
pdgId() == 2212 &&
658 myGenParticles[1].
pdgId() == 2212 ) {
665 myGenParticles[ip].vy(),
666 myGenParticles[ip].vz(),
671 if ( primaryVertex.mag() < 1E-8 ) {
681 myFilter->setMainVertex(primaryVertex+smearedVertex);
687 for ( ; ip<nParticles; ++ip ) {
699 if ( productionMother ) {
700 unsigned motherId = productionMother->
pdgId();
701 if (
abs(motherId) < 1000000 )
704 if ( !
myFilter->accept(productionVertexPosition) )
continue;
708 bool testStable = p.
status()%1000==1;
723 bool testDaugh =
false;
728 for (
unsigned iDaughter=0; iDaughter<nDaughters; ++iDaughter ) {
730 if ( daughter->
status()%1000==1 ) {
739 if ( !testStable && !testDaugh ) {
741 dist = (primaryVertex-productionVertex).Vect().Mag2();
743 bool testDecay = ( dist > 1
e-8 ) ?
true :
false;
746 if ( testStable || testDaugh || testDecay ) {
752 myGenVertices.find(mother) != myGenVertices.
end() ?
753 myGenVertices[mother] : mainVertex;
757 part.setID(p.
pdgId());
763 if ( !nDaughters )
continue;
769 daughter->
vz(), 0.) + smearedVertex;
772 if ( theVertex != -1 ) myGenVertices[&
p] = theVertex;
785 const HepMC::GenVertex* ev) {
789 if ( !
myFilter->accept(p) && ig >= -1 )
return -1;
800 if ( !
vertex(iv).noParent() ) {
805 if ( motherId < -1 ) ig = motherId;
810 (*theSimTracks)[trackId] = ev ?
813 ev->position().
t()/10.
817 FSimTrack(p,iv,ig,trackId,
this);
827 if ( !
myFilter->accept(v) )
return -1;
841 (*theSimVertices)[vertexId] =
FSimVertex(v,im,vertexId,
this);
852 std::cout <<
"Id Gen Name eta phi pT E Vtx1 "
854 <<
"Moth Vtx2 eta phi R Z Da1 Da2 Ecal?" << std::endl;
856 for ( HepMC::GenEvent::particle_const_iterator
857 piter = myGenEvent.particles_begin();
858 piter != myGenEvent.particles_end();
863 int partId = p->pdg_id();
879 if ( !p->production_vertex() )
continue;
881 XYZVector vertex1 (p->production_vertex()->position().x()/10.,
882 p->production_vertex()->position().y()/10.,
883 p->production_vertex()->position().z()/10.);
884 vertexId1 = p->production_vertex()->barcode();
886 std::cout.setf(std::ios::fixed, std::ios::floatfield);
887 std::cout.setf(std::ios::right, std::ios::adjustfield);
889 std::cout << std::setw(4) << p->barcode() <<
" "
892 for(
unsigned int k=0;
k<11-name.length() &&
k<12;
k++)
std::cout <<
" ";
894 double eta = momentum1.eta();
895 if ( eta > +10. ) eta = +10.;
896 if ( eta < -10. ) eta = -10.;
897 std::cout << std::setw(6) << std::setprecision(2) << eta <<
" "
898 << std::setw(6) << std::setprecision(2) << momentum1.phi() <<
" "
899 << std::setw(7) << std::setprecision(2) << momentum1.pt() <<
" "
900 << std::setw(7) << std::setprecision(2) << momentum1.e() <<
" "
901 << std::setw(4) << vertexId1 <<
" "
902 << std::setw(6) << std::setprecision(1) << vertex1.x() <<
" "
903 << std::setw(6) << std::setprecision(1) << vertex1.y() <<
" "
904 << std::setw(6) << std::setprecision(1) << vertex1.z() <<
" ";
907 *(p->production_vertex()->particles_in_const_begin());
910 std::cout << std::setw(4) << mother->barcode() <<
" ";
914 if ( p->end_vertex() ) {
916 p->end_vertex()->position().y()/10.,
917 p->end_vertex()->position().z()/10.,
918 p->end_vertex()->position().t()/10.);
919 int vertexId2 = p->end_vertex()->barcode();
921 std::vector<const HepMC::GenParticle*> children;
922 HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
923 p->end_vertex()->particles_out_const_begin();
924 HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
925 p->end_vertex()->particles_out_const_end();
926 for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
927 children.push_back(*firstDaughterIt);
930 std::cout << std::setw(4) << vertexId2 <<
" "
931 << std::setw(6) << std::setprecision(2) << vertex2.eta() <<
" "
932 << std::setw(6) << std::setprecision(2) << vertex2.phi() <<
" "
933 << std::setw(5) << std::setprecision(1) << vertex2.pt() <<
" "
934 << std::setw(6) << std::setprecision(1) << vertex2.z() <<
" ";
935 for (
unsigned id=0;
id<children.size(); ++id )
936 std::cout << std::setw(4) << children[id]->barcode() <<
" ";
947 std::cout <<
" Id Gen Name eta phi pT E Vtx1 "
949 <<
"Moth Vtx2 eta phi R Z Daughters Ecal?" << std::endl;
const ParticleDataTable * pdt
double lateVertexPosition
PrimaryVertexGenerator * theVertexGenerator
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
const math::XYZVectorD & trackerSurfacePosition() const
virtual double energy() const GCC11_FINAL
energy
void setCharge(float q)
set the MEASURED charge
T getParameter(std::string const &) const
int addSimVertex(const XYZTLorentzVector &decayVertex, int im=-1, FSimVertexType::VertexType type=FSimVertexType::ANY)
Add a new vertex to the Event and to the various lists.
float charge() const
charge
int addSimTrack(const RawParticle *p, int iv, int ig=-1, const HepMC::GenVertex *ev=0)
Add a new track to the Event and to the various lists.
bool propagateToPreshowerLayer1(bool first=true)
const HepMC::GenParticle * embdGenpart(int i) const
return MC track with a given id
HepPDT::ParticleDataTable ParticleDataTable
std::vector< FSimTrack > * theSimTracks
virtual int pdgId() const GCC11_FINAL
PDG identifier.
double PDGmass() const
get the THEORETICAL mass
std::vector< unsigned > * theChargedTracks
FBaseSimEvent(const edm::ParameterSet &kine)
Default constructor.
const XYZTLorentzVector & momentum() const
Temporary (until move of SimTrack to Mathcore) - No! Actually very useful.
unsigned int theTrackSize
unsigned int theVertexSize
virtual int status() const =0
status word
KineParticleFilter * myFilter
The particle filter.
math::XYZPoint theBeamSpot
virtual double vx() const =0
x coordinate of vertex position
void setEcal(const RawParticle &pp, int success)
Set the ecal variables.
int getSuccess() const
Has propagation been performed and was barrel or endcap reached ?
void setLayer2(const RawParticle &pp, int success)
Set the preshower layer2 variables.
void clear()
clear the FBaseSimEvent content before the next event
void setMagneticField(double b)
Set the magnetic field.
virtual double vy() const
y coordinate of vertex position
virtual double pz() const GCC11_FINAL
z coordinate of momentum vector
virtual double py() const GCC11_FINAL
y coordinate of momentum vector
bool notYetToEndVertex(const XYZTLorentzVector &pos) const
Compare the end vertex position with another position.
static int position[TOTALCHAMBERS][3]
virtual double vy() const =0
y coordinate of vertex position
virtual void generate(RandomEngineAndDistribution const *)=0
Generation process (to be implemented)
FSimVertex & vertex(int id) const
Return vertex with given Id.
unsigned int nVertices() const
Number of vertices.
FSimVertexType & vertexType(int id) const
Return vertex with given Id.
bool propagateToVFcalEntrance(bool first=true)
void setLayer1(const RawParticle &pp, int success)
Set the preshower layer1 variables.
void addParticles(const HepMC::GenEvent &hev, RandomEngineAndDistribution const *)
Add the particles and their vertices to the list.
const XYZTLorentzVector & momentum() const
the momentum fourvector
double t() const
vertex time
math::XYZVector XYZVector
virtual const_iterator end() const =0
last daughter const_iterator
virtual int status() const GCC11_FINAL
status word
~FBaseSimEvent()
usual virtual destructor
virtual size_t numberOfMothers() const
number of mothers
const math::XYZTLorentzVector & position() const
Temporary (until CMSSW moves to Mathcore) - No ! Actually very useful.
unsigned int nTracks() const
Number of tracks.
bool propagateToHcalExit(bool first=true)
virtual size_t numberOfDaughters() const
number of daughters
unsigned int nSimVertices
int genpartIndex() const
index of the corresponding Generator particle in the Event container (-1 if no Genpart) ...
virtual const Candidate * daughter(size_type) const
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
double cos2ThetaV() const
A FSimVertexType hold the information on the vertex origine.
void fill(const HepMC::GenEvent &hev, RandomEngineAndDistribution const *)
fill the FBaseSimEvent from the current HepMC::GenEvent
virtual double px() const GCC11_FINAL
x coordinate of momentum vector
Abs< T >::type abs(const T &t)
const math::XYZTLorentzVectorD & position() const
std::vector< FSimVertexType > FSimVertexTypeCollection
collection of FSimVertexType objects
const FSimVertex & vertex() const
Origin vertex.
unsigned int nGenParticles
std::vector< FSimVertex > * theSimVertices
unsigned int offset(bool)
virtual double vz() const
z coordinate of vertex position
bool propagateToEcalEntrance(bool first=true)
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
virtual int pdgId() const =0
PDG identifier.
const XYZTLorentzVector & vertex() const
the vertex fourvector
XYZPointD XYZPoint
point in space with cartesian internal representation
unsigned int theChargedSize
const math::XYZTLorentzVectorD & trackerSurfaceMomentum() const
void addChargedTrack(int id)
Add an id in the vector of charged tracks id's.
void setHcalExit(const RawParticle &pp, int success)
Set the hcal exit variables.
virtual double vz() const =0
z coordinate of vertex position
unsigned int nChargedParticleTracks
int type() const
particle type (HEP PDT convension)
bool propagateToHcalEntrance(bool first=true)
void initializePdt(const HepPDT::ParticleDataTable *aPdt)
Initialize the particle data table.
void setEndVertex(int endv)
Set the end vertex.
unsigned int nGenParts() const
Number of generator particles.
const math::XYZTLorentzVectorD & momentum() const
particle info...
const math::XYZPoint & beamSpot() const
Return x0, y0, z0.
void addDaughter(int i)
Add a RecHit for a track on a layer.
void setHO(const RawParticle &pp, int success)
Set the ho variables.
int chargedTrack(int id) const
return "reconstructed" charged tracks index.
virtual double vx() const
x coordinate of vertex position
void setVFcal(const RawParticle &pp, int success)
Set the hcal variables.
void setHcal(const RawParticle &pp, int success)
Set the hcal variables.
void printMCTruth(const HepMC::GenEvent &hev)
print the original MCTruth event
std::vector< HepMC::GenParticle * > * theGenParticles
bool propagateToHOLayer(bool first=true)
bool propagateToPreshowerLayer2(bool first=true)
virtual const Candidate * mother(size_type=0) const
return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode) ...
math::XYZTLorentzVector XYZTLorentzVector
void print() const
print the FBaseSimEvent in an intelligible way
FSimTrack & track(int id) const
Return track with given Id.
FSimVertexTypeCollection * theFSimVerticesType