2 #include "HepMC/GenEvent.h"
3 #include "HepMC/GenVertex.h"
4 #include "HepMC/GenParticle.h"
27 using namespace HepPDT;
40 nChargedParticleTracks(0),
80 nChargedParticleTracks(0),
82 theVertexGenerator(0),
87 std::string vtxType = vtx.
getParameter<std::string>(
"type");
88 if ( vtxType ==
"Gaussian" )
90 else if ( vtxType ==
"Flat" )
92 else if ( vtxType ==
"BetaFunc" )
206 const std::vector<SimVertex>& simVertices) {
213 unsigned nVtx = simVertices.size();
214 unsigned nTks = simTracks.size();
217 if ( nVtx == 0 )
return;
220 std::vector<int> myVertices(nVtx,-1);
221 std::vector<int> myTracks(nTks,-1);
226 std::map<unsigned, unsigned> geantToIndex;
227 for(
unsigned it=0; it<simTracks.size(); ++it ) {
228 geantToIndex[ simTracks[it].trackId() ] = it;
251 myFilter->setMainVertex(primaryVertex);
256 for(
unsigned trackId=0; trackId<nTks; ++trackId ) {
272 std::map<unsigned, unsigned >::iterator association
273 = geantToIndex.find( motherGeantId );
274 if(association != geantToIndex.end() )
275 motherId = association->second;
277 int originId = motherId == - 1 ? -1 : myTracks[motherId];
291 if ( myVertices[vertexId] == -1 )
299 int motherType = motherId == -1 ? 0 : simTracks[motherId].type();
301 bool notBremInDetector =
302 (
abs(motherType) != 11 &&
abs(motherType) != 13) ||
303 motherType != track.
type() ||
306 if ( notBremInDetector ) {
315 part.setID(track.
type());
321 if ( myTracks[trackId] >= 0 ) {
327 myTracks[trackId] = myTracks[motherId];
328 if ( myTracks[trackId] >= 0 ) {
337 for(
unsigned vertexId=0; vertexId<nVtx; ++vertexId ) {
340 if ( myVertices[vertexId] != -1 )
continue;
351 std::map<unsigned, unsigned >::iterator association
352 = geantToIndex.find( motherGeantId );
353 if(association != geantToIndex.end() )
354 motherId = association->second;
356 int originId = motherId == - 1 ? -1 : myTracks[motherId];
374 for(
int fsimi=0; fsimi < (int)
nTracks() ; ++fsimi) {
391 if ( mom.T() > 0. ) {
431 int genEventSize = myGenEvent.particles_size();
432 std::vector<int> myGenVertices(genEventSize, static_cast<int>(0));
435 if ( myGenEvent.particles_empty() )
return;
441 HepMC::GenVertex* primaryVertex = *(myGenEvent.vertices_begin());
444 unsigned primaryMother = primaryVertex->particles_in_size();
445 if ( primaryMother ) {
446 unsigned partId = (*(primaryVertex->particles_in_const_begin()))->pdg_id();
447 if (
abs(partId) == 2212 ) primaryMother = 0;
452 primaryVertex->position().y()/10.,
453 primaryVertex->position().z()/10.,
454 primaryVertex->position().t()/10.);
456 primaryVertexPosition *= (1-primaryMother);
462 if ( primaryVertexPosition.Vect().Mag2() < 1E-16 ) {
472 myFilter->setMainVertex(primaryVertexPosition+smearedVertex);
477 HepMC::GenEvent::particle_const_iterator piter;
478 HepMC::GenEvent::particle_const_iterator pbegin = myGenEvent.particles_begin();
479 HepMC::GenEvent::particle_const_iterator pend = myGenEvent.particles_end();
481 int initialBarcode = 0;
482 if ( pbegin != pend ) initialBarcode = (*pbegin)->barcode();
484 for ( piter = pbegin; piter != pend; ++piter ) {
502 HepMC::GenVertex* productionVertex = p->production_vertex();
503 if ( productionVertex ) {
504 unsigned productionMother = productionVertex->particles_in_size();
505 if ( productionMother ) {
506 unsigned motherId = (*(productionVertex->particles_in_const_begin()))->pdg_id();
507 if (
abs(motherId) < 1000000 )
508 productionVertexPosition =
510 productionVertex->position().y()/10.,
511 productionVertex->position().z()/10.,
512 productionVertex->position().t()/10.) + smearedVertex;
515 if ( !
myFilter->accept(productionVertexPosition) )
continue;
517 int abspdgId =
abs(p->pdg_id());
518 HepMC::GenVertex* endVertex = p->end_vertex();
522 bool testStable = p->status()%1000==1;
525 if ( p->status() == 2 && abspdgId < 1000000) {
529 endVertex->position().y()/10.,
530 endVertex->position().z()/10.,
531 endVertex->position().t()/10.) + smearedVertex;
538 bool testDaugh =
false;
542 endVertex->particles_out_size() ) {
543 HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
544 endVertex->particles_out_const_begin();
545 HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
546 endVertex->particles_out_const_end();
547 for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
549 if ( daugh->status()%1000==1 ) {
551 if (abspdgId == 11 || abspdgId == 13) {
554 endVertex->position().y()/10.,
555 endVertex->position().z()/10.,
556 endVertex->position().t()/10.);
571 if ( !testStable && !testDaugh && p->production_vertex() ) {
573 productionVertexPosition(p->production_vertex()->position().x()/10.,
574 p->production_vertex()->position().y()/10.,
575 p->production_vertex()->position().z()/10.,
576 p->production_vertex()->position().t()/10.);
577 dist = (primaryVertexPosition-productionVertexPosition).Vect().Mag2();
579 bool testDecay = ( dist > 1
e-8 ) ?
true :
false;
582 if ( testStable || testDaugh || testDecay ) {
589 int motherBarcode = p->production_vertex() &&
590 p->production_vertex()->particles_in_const_begin() !=
591 p->production_vertex()->particles_in_const_end() ?
592 (*(p->production_vertex()->particles_in_const_begin()))->barcode() : 0;
595 motherBarcode && myGenVertices[motherBarcode-initialBarcode] ?
596 myGenVertices[motherBarcode-initialBarcode] : mainVertex;
603 part.setID(p->pdg_id());
607 int theTrack = testStable && p->end_vertex() ?
618 ( testStable && p->end_vertex() && !p->end_vertex()->particles_out_size() )
625 p->end_vertex()->position().y()/10.,
626 p->end_vertex()->position().z()/10.,
627 p->end_vertex()->position().t()/10.) +
632 if ( theVertex != -1 ) myGenVertices[p->barcode()-initialBarcode] = theVertex;
644 unsigned int nParticles = myGenParticles.size();
647 if ( !nParticles )
return;
650 std::map<const reco::Candidate*,int> myGenVertices;
658 if ( nParticles > 1 &&
659 myGenParticles[0].
pdgId() == 2212 &&
660 myGenParticles[1].
pdgId() == 2212 ) {
667 myGenParticles[ip].vy(),
668 myGenParticles[ip].vz(),
673 if ( primaryVertex.mag() < 1E-8 ) {
683 myFilter->setMainVertex(primaryVertex+smearedVertex);
701 if ( productionMother ) {
702 unsigned motherId = productionMother->
pdgId();
703 if (
abs(motherId) < 1000000 )
706 if ( !
myFilter->accept(productionVertexPosition) )
continue;
710 bool testStable = p.
status()%1000==1;
725 bool testDaugh =
false;
730 for (
unsigned iDaughter=0; iDaughter<nDaughters; ++iDaughter ) {
732 if ( daughter->
status()%1000==1 ) {
741 if ( !testStable && !testDaugh ) {
743 dist = (primaryVertex-productionVertex).Vect().Mag2();
745 bool testDecay = ( dist > 1
e-8 ) ?
true :
false;
748 if ( testStable || testDaugh || testDecay ) {
754 myGenVertices.find(mother) != myGenVertices.
end() ?
755 myGenVertices[mother] : mainVertex;
759 part.setID(p.
pdgId());
765 if ( !nDaughters )
continue;
771 daughter->
vz(), 0.) + smearedVertex;
774 if ( theVertex != -1 ) myGenVertices[&
p] = theVertex;
787 const HepMC::GenVertex* ev) {
791 if ( !
myFilter->accept(p) && ig >= -1 )
return -1;
802 if ( !
vertex(iv).noParent() ) {
807 if ( motherId < -1 ) ig = motherId;
812 (*theSimTracks)[trackId] = ev ?
815 ev->position().
t()/10.
819 FSimTrack(p,iv,ig,trackId,
this);
829 if ( !
myFilter->accept(v) )
return -1;
843 (*theSimVertices)[vertexId] =
FSimVertex(v,im,vertexId,
this);
854 std::cout <<
"Id Gen Name eta phi pT E Vtx1 "
856 <<
"Moth Vtx2 eta phi R Z Da1 Da2 Ecal?" << std::endl;
858 for ( HepMC::GenEvent::particle_const_iterator
859 piter = myGenEvent.particles_begin();
860 piter != myGenEvent.particles_end();
865 int partId = p->pdg_id();
881 if ( !p->production_vertex() )
continue;
883 XYZVector vertex1 (p->production_vertex()->position().x()/10.,
884 p->production_vertex()->position().y()/10.,
885 p->production_vertex()->position().z()/10.);
886 vertexId1 = p->production_vertex()->barcode();
888 std::cout.setf(std::ios::fixed, std::ios::floatfield);
889 std::cout.setf(std::ios::right, std::ios::adjustfield);
891 std::cout << std::setw(4) << p->barcode() <<
" "
894 for(
unsigned int k=0;
k<11-name.length() &&
k<12;
k++)
std::cout <<
" ";
896 double eta = momentum1.eta();
897 if ( eta > +10. ) eta = +10.;
898 if ( eta < -10. ) eta = -10.;
899 std::cout << std::setw(6) << std::setprecision(2) << eta <<
" "
900 << std::setw(6) << std::setprecision(2) << momentum1.phi() <<
" "
901 << std::setw(7) << std::setprecision(2) << momentum1.pt() <<
" "
902 << std::setw(7) << std::setprecision(2) << momentum1.e() <<
" "
903 << std::setw(4) << vertexId1 <<
" "
904 << std::setw(6) << std::setprecision(1) << vertex1.x() <<
" "
905 << std::setw(6) << std::setprecision(1) << vertex1.y() <<
" "
906 << std::setw(6) << std::setprecision(1) << vertex1.z() <<
" ";
909 *(p->production_vertex()->particles_in_const_begin());
912 std::cout << std::setw(4) << mother->barcode() <<
" ";
916 if ( p->end_vertex() ) {
918 p->end_vertex()->position().y()/10.,
919 p->end_vertex()->position().z()/10.,
920 p->end_vertex()->position().t()/10.);
921 int vertexId2 = p->end_vertex()->barcode();
923 std::vector<const HepMC::GenParticle*> children;
924 HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
925 p->end_vertex()->particles_out_const_begin();
926 HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
927 p->end_vertex()->particles_out_const_end();
928 for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
929 children.push_back(*firstDaughterIt);
932 std::cout << std::setw(4) << vertexId2 <<
" "
933 << std::setw(6) << std::setprecision(2) << vertex2.eta() <<
" "
934 << std::setw(6) << std::setprecision(2) << vertex2.phi() <<
" "
935 << std::setw(5) << std::setprecision(1) << vertex2.pt() <<
" "
936 << std::setw(6) << std::setprecision(1) << vertex2.z() <<
" ";
937 for (
unsigned id=0;
id<children.size(); ++
id )
938 std::cout << std::setw(4) << children[
id]->barcode() <<
" ";
949 std::cout <<
" Id Gen Name eta phi pT E Vtx1 "
951 <<
"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
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.
virtual int pdgId() const
PDG identifier.
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 status() const
status word
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
virtual double vy() const
y coordinate of vertex position
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)
virtual double energy() const
energy
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
~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.
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) ...
A FSimVertexType hold the information on the vertex origine.
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
virtual double px() const
x coordinate of momentum vector
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.
virtual double pz() const
z coordinate of momentum vector
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.
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 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) ...
virtual double py() const
y coordinate of momentum vector
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