2 #include "HepMC/GenEvent.h"
3 #include "HepMC/GenVertex.h"
4 #include "HepMC/GenParticle.h"
26 using namespace HepPDT;
39 nChargedParticleTracks(0),
79 nChargedParticleTracks(0),
81 theVertexGenerator(0),
87 if ( vtxType ==
"Gaussian" )
89 else if ( vtxType ==
"Flat" )
91 else if ( vtxType ==
"BetaFunc" )
193 const std::vector<SimVertex>& simVertices) {
200 unsigned nVtx = simVertices.size();
201 unsigned nTks = simTracks.size();
204 if ( nVtx == 0 )
return;
207 std::vector<int> myVertices(nVtx,-1);
208 std::vector<int> myTracks(nTks,-1);
213 std::map<unsigned, unsigned> geantToIndex;
214 for(
unsigned it=0; it<simTracks.size(); ++it ) {
215 geantToIndex[ simTracks[it].trackId() ] = it;
238 myFilter->setMainVertex(primaryVertex);
243 for(
unsigned trackId=0; trackId<nTks; ++trackId ) {
259 std::map<unsigned, unsigned >::iterator association
260 = geantToIndex.find( motherGeantId );
261 if(association != geantToIndex.end() )
262 motherId = association->second;
264 int originId = motherId == - 1 ? -1 : myTracks[motherId];
278 if ( myVertices[vertexId] == -1 )
286 int motherType = motherId == -1 ? 0 : simTracks[motherId].type();
288 bool notBremInDetector =
289 (
abs(motherType) != 11 &&
abs(motherType) != 13) ||
290 motherType != track.
type() ||
293 if ( notBremInDetector ) {
302 part.setID(track.
type());
308 if ( myTracks[trackId] >= 0 ) {
314 myTracks[trackId] = myTracks[motherId];
315 if ( myTracks[trackId] >= 0 ) {
324 for(
unsigned vertexId=0; vertexId<nVtx; ++vertexId ) {
327 if ( myVertices[vertexId] != -1 )
continue;
338 std::map<unsigned, unsigned >::iterator association
339 = geantToIndex.find( motherGeantId );
340 if(association != geantToIndex.end() )
341 motherId = association->second;
343 int originId = motherId == - 1 ? -1 : myTracks[motherId];
362 for(
int fsimi=0; fsimi < (int)
nTracks() ; ++fsimi) {
379 if ( mom.T() > 0. ) {
405 if ( myPart.
cos2ThetaV()>0.8 || mom.T() < 3. ) {
432 int genEventSize = myGenEvent.particles_size();
433 std::vector<int> myGenVertices(genEventSize, static_cast<int>(0));
436 if ( myGenEvent.particles_empty() )
return;
442 HepMC::GenVertex* primaryVertex = *(myGenEvent.vertices_begin());
445 unsigned primaryMother = primaryVertex->particles_in_size();
446 if ( primaryMother ) {
447 unsigned partId = (*(primaryVertex->particles_in_const_begin()))->pdg_id();
448 if (
abs(partId) == 2212 ) primaryMother = 0;
453 primaryVertex->position().y()/10.,
454 primaryVertex->position().z()/10.,
455 primaryVertex->position().t()/10.);
457 primaryVertexPosition *= (1-primaryMother);
463 if ( primaryVertexPosition.Vect().Mag2() < 1E-16 ) {
473 myFilter->setMainVertex(primaryVertexPosition+smearedVertex);
478 HepMC::GenEvent::particle_const_iterator piter;
479 HepMC::GenEvent::particle_const_iterator pbegin = myGenEvent.particles_begin();
480 HepMC::GenEvent::particle_const_iterator pend = myGenEvent.particles_end();
482 int initialBarcode = 0;
483 if ( pbegin != pend ) initialBarcode = (*pbegin)->barcode();
485 for ( piter = pbegin; piter != pend; ++piter ) {
503 HepMC::GenVertex* productionVertex = p->production_vertex();
504 if ( productionVertex ) {
505 unsigned productionMother = productionVertex->particles_in_size();
506 if ( productionMother ) {
507 unsigned motherId = (*(productionVertex->particles_in_const_begin()))->pdg_id();
508 if (
abs(motherId) < 1000000 )
509 productionVertexPosition =
511 productionVertex->position().y()/10.,
512 productionVertex->position().z()/10.,
513 productionVertex->position().t()/10.) + smearedVertex;
516 if ( !
myFilter->accept(productionVertexPosition) )
continue;
518 int abspdgId =
abs(p->pdg_id());
519 HepMC::GenVertex* endVertex = p->end_vertex();
523 bool testStable = p->status()%1000==1;
526 if ( p->status() == 2 && abspdgId < 1000000) {
530 endVertex->position().y()/10.,
531 endVertex->position().z()/10.,
532 endVertex->position().t()/10.) + smearedVertex;
539 bool testDaugh =
false;
543 endVertex->particles_out_size() ) {
544 HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
545 endVertex->particles_out_const_begin();
546 HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
547 endVertex->particles_out_const_end();
548 for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
550 if ( daugh->status()%1000==1 ) {
552 if (abspdgId == 11 || abspdgId == 13) {
555 endVertex->position().y()/10.,
556 endVertex->position().z()/10.,
557 endVertex->position().t()/10.);
572 if ( !testStable && !testDaugh && p->production_vertex() ) {
574 productionVertexPosition(p->production_vertex()->position().x()/10.,
575 p->production_vertex()->position().y()/10.,
576 p->production_vertex()->position().z()/10.,
577 p->production_vertex()->position().t()/10.);
578 dist = (primaryVertexPosition-productionVertexPosition).Vect().Mag2();
580 bool testDecay = ( dist > 1
e-8 ) ?
true :
false;
583 if ( testStable || testDaugh || testDecay ) {
590 int motherBarcode = p->production_vertex() &&
591 p->production_vertex()->particles_in_const_begin() !=
592 p->production_vertex()->particles_in_const_end() ?
593 (*(p->production_vertex()->particles_in_const_begin()))->barcode() : 0;
596 motherBarcode && myGenVertices[motherBarcode-initialBarcode] ?
597 myGenVertices[motherBarcode-initialBarcode] : mainVertex;
604 part.setID(p->pdg_id());
608 int theTrack = testStable && p->end_vertex() ?
619 ( testStable && p->end_vertex() && !p->end_vertex()->particles_out_size() )
626 p->end_vertex()->position().y()/10.,
627 p->end_vertex()->position().z()/10.,
628 p->end_vertex()->position().t()/10.) +
633 if ( theVertex != -1 ) myGenVertices[p->barcode()-initialBarcode] = theVertex;
645 unsigned int nParticles = myGenParticles.size();
648 if ( !nParticles )
return;
651 std::map<const reco::Candidate*,int> myGenVertices;
659 if ( nParticles > 1 &&
660 myGenParticles[0].
pdgId() == 2212 &&
661 myGenParticles[1].
pdgId() == 2212 ) {
668 myGenParticles[ip].vy(),
669 myGenParticles[ip].vz(),
674 if ( primaryVertex.mag() < 1E-8 ) {
684 myFilter->setMainVertex(primaryVertex+smearedVertex);
702 if ( productionMother ) {
703 unsigned motherId = productionMother->
pdgId();
704 if (
abs(motherId) < 1000000 )
707 if ( !
myFilter->accept(productionVertexPosition) )
continue;
711 bool testStable = p.
status()%1000==1;
726 bool testDaugh =
false;
731 for (
unsigned iDaughter=0; iDaughter<nDaughters; ++iDaughter ) {
733 if ( daughter->
status()%1000==1 ) {
742 if ( !testStable && !testDaugh ) {
744 dist = (primaryVertex-productionVertex).Vect().Mag2();
746 bool testDecay = ( dist > 1
e-8 ) ?
true :
false;
749 if ( testStable || testDaugh || testDecay ) {
755 myGenVertices.find(mother) != myGenVertices.
end() ?
756 myGenVertices[mother] : mainVertex;
760 part.setID(p.
pdgId());
766 if ( !nDaughters )
continue;
772 daughter->
vz(), 0.) + smearedVertex;
775 if ( theVertex != -1 ) myGenVertices[&
p] = theVertex;
788 const HepMC::GenVertex* ev) {
792 if ( !
myFilter->accept(p) && ig >= -1 )
return -1;
803 if ( !
vertex(iv).noParent() ) {
808 if ( motherId < -1 ) ig = motherId;
813 (*theSimTracks)[trackId] = ev ?
816 ev->position().
t()/10.
820 FSimTrack(p,iv,ig,trackId,
this);
830 if ( !
myFilter->accept(v) )
return -1;
844 (*theSimVertices)[vertexId] =
FSimVertex(v,im,vertexId,
this);
855 std::cout <<
"Id Gen Name eta phi pT E Vtx1 "
857 <<
"Moth Vtx2 eta phi R Z Da1 Da2 Ecal?" << std::endl;
859 for ( HepMC::GenEvent::particle_const_iterator
860 piter = myGenEvent.particles_begin();
861 piter != myGenEvent.particles_end();
866 int partId = p->pdg_id();
882 if ( !p->production_vertex() )
continue;
884 XYZVector vertex1 (p->production_vertex()->position().x()/10.,
885 p->production_vertex()->position().y()/10.,
886 p->production_vertex()->position().z()/10.);
887 vertexId1 = p->production_vertex()->barcode();
889 std::cout.setf(std::ios::fixed, std::ios::floatfield);
890 std::cout.setf(std::ios::right, std::ios::adjustfield);
892 std::cout << std::setw(4) << p->barcode() <<
" "
895 for(
unsigned int k=0;
k<11-name.length() &&
k<12;
k++)
std::cout <<
" ";
897 double eta = momentum1.eta();
898 if ( eta > +10. ) eta = +10.;
899 if ( eta < -10. ) eta = -10.;
900 std::cout << std::setw(6) << std::setprecision(2) << eta <<
" "
901 << std::setw(6) << std::setprecision(2) << momentum1.phi() <<
" "
902 << std::setw(7) << std::setprecision(2) << momentum1.pt() <<
" "
903 << std::setw(7) << std::setprecision(2) << momentum1.e() <<
" "
904 << std::setw(4) << vertexId1 <<
" "
905 << std::setw(6) << std::setprecision(1) << vertex1.x() <<
" "
906 << std::setw(6) << std::setprecision(1) << vertex1.y() <<
" "
907 << std::setw(6) << std::setprecision(1) << vertex1.z() <<
" ";
910 *(p->production_vertex()->particles_in_const_begin());
913 std::cout << std::setw(4) << mother->barcode() <<
" ";
917 if ( p->end_vertex() ) {
919 p->end_vertex()->position().y()/10.,
920 p->end_vertex()->position().z()/10.,
921 p->end_vertex()->position().t()/10.);
922 int vertexId2 = p->end_vertex()->barcode();
924 std::vector<const HepMC::GenParticle*> children;
925 HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
926 p->end_vertex()->particles_out_const_begin();
927 HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
928 p->end_vertex()->particles_out_const_end();
929 for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
930 children.push_back(*firstDaughterIt);
933 std::cout << std::setw(4) << vertexId2 <<
" "
934 << std::setw(6) << std::setprecision(2) << vertex2.eta() <<
" "
935 << std::setw(6) << std::setprecision(2) << vertex2.phi() <<
" "
936 << std::setw(5) << std::setprecision(1) << vertex2.pt() <<
" "
937 << std::setw(6) << std::setprecision(1) << vertex2.z() <<
" ";
938 for (
unsigned id=0;
id<children.size(); ++id )
939 std::cout << std::setw(4) << children[id]->barcode() <<
" ";
950 std::cout <<
" Id Gen Name eta phi pT E Vtx1 "
952 <<
"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 addParticles(const HepMC::GenEvent &hev)
Add the particles and their vertices to the list.
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
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.
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.
virtual double px() const GCC11_FINAL
x coordinate of momentum vector
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)
void fill(const HepMC::GenEvent &hev)
fill the FBaseSimEvent from the current HepMC::GenEvent
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
virtual void generate()=0
Generation process (to be implemented)
const RandomEngine * random
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