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),
86 std::string vtxType = vtx.
getParameter<std::string>(
"type");
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];
361 for(
int fsimi=0; fsimi < (int)
nTracks() ; ++fsimi) {
378 if ( mom.T() > 0. ) {
418 int genEventSize = myGenEvent.particles_size();
419 std::vector<int> myGenVertices(genEventSize, static_cast<int>(0));
422 if ( myGenEvent.particles_empty() )
return;
428 HepMC::GenVertex* primaryVertex = *(myGenEvent.vertices_begin());
431 unsigned primaryMother = primaryVertex->particles_in_size();
432 if ( primaryMother ) {
433 unsigned partId = (*(primaryVertex->particles_in_const_begin()))->pdg_id();
434 if (
abs(partId) == 2212 ) primaryMother = 0;
439 primaryVertex->position().y()/10.,
440 primaryVertex->position().z()/10.,
441 primaryVertex->position().t()/10.);
443 primaryVertexPosition *= (1-primaryMother);
449 if ( primaryVertexPosition.Vect().Mag2() < 1E-16 ) {
459 myFilter->setMainVertex(primaryVertexPosition+smearedVertex);
464 HepMC::GenEvent::particle_const_iterator piter;
465 HepMC::GenEvent::particle_const_iterator pbegin = myGenEvent.particles_begin();
466 HepMC::GenEvent::particle_const_iterator pend = myGenEvent.particles_end();
468 int initialBarcode = 0;
469 if ( pbegin != pend ) initialBarcode = (*pbegin)->barcode();
471 for ( piter = pbegin; piter != pend; ++piter ) {
489 HepMC::GenVertex* productionVertex = p->production_vertex();
490 if ( productionVertex ) {
491 unsigned productionMother = productionVertex->particles_in_size();
492 if ( productionMother ) {
493 unsigned motherId = (*(productionVertex->particles_in_const_begin()))->pdg_id();
494 if (
abs(motherId) < 1000000 )
495 productionVertexPosition =
497 productionVertex->position().y()/10.,
498 productionVertex->position().z()/10.,
499 productionVertex->position().t()/10.) + smearedVertex;
502 if ( !
myFilter->accept(productionVertexPosition) )
continue;
504 int abspdgId =
abs(p->pdg_id());
505 HepMC::GenVertex* endVertex = p->end_vertex();
509 bool testStable = p->status()%1000==1;
512 if ( p->status() == 2 && abspdgId < 1000000) {
516 endVertex->position().y()/10.,
517 endVertex->position().z()/10.,
518 endVertex->position().t()/10.) + smearedVertex;
525 bool testDaugh =
false;
529 endVertex->particles_out_size() ) {
530 HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
531 endVertex->particles_out_const_begin();
532 HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
533 endVertex->particles_out_const_end();
534 for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
536 if ( daugh->status()%1000==1 ) {
538 if (abspdgId == 11 || abspdgId == 13) {
541 endVertex->position().y()/10.,
542 endVertex->position().z()/10.,
543 endVertex->position().t()/10.);
558 if ( !testStable && !testDaugh && p->production_vertex() ) {
560 productionVertexPosition(p->production_vertex()->position().x()/10.,
561 p->production_vertex()->position().y()/10.,
562 p->production_vertex()->position().z()/10.,
563 p->production_vertex()->position().t()/10.);
564 dist = (primaryVertexPosition-productionVertexPosition).Vect().Mag2();
566 bool testDecay = ( dist > 1e-8 ) ?
true :
false;
569 if ( testStable || testDaugh || testDecay ) {
576 int motherBarcode = p->production_vertex() &&
577 p->production_vertex()->particles_in_const_begin() !=
578 p->production_vertex()->particles_in_const_end() ?
579 (*(p->production_vertex()->particles_in_const_begin()))->barcode() : 0;
582 motherBarcode && myGenVertices[motherBarcode-initialBarcode] ?
583 myGenVertices[motherBarcode-initialBarcode] : mainVertex;
590 part.setID(p->pdg_id());
594 int theTrack = testStable && p->end_vertex() ?
605 ( testStable && p->end_vertex() && !p->end_vertex()->particles_out_size() )
612 p->end_vertex()->position().y()/10.,
613 p->end_vertex()->position().z()/10.,
614 p->end_vertex()->position().t()/10.) +
619 if ( theVertex != -1 ) myGenVertices[p->barcode()-initialBarcode] = theVertex;
631 unsigned int nParticles = myGenParticles.size();
634 if ( !nParticles )
return;
637 std::map<const reco::Candidate*,int> myGenVertices;
645 if ( nParticles > 1 &&
646 myGenParticles[0].
pdgId() == 2212 &&
647 myGenParticles[1].
pdgId() == 2212 ) {
654 myGenParticles[ip].vy(),
655 myGenParticles[ip].vz(),
660 if ( primaryVertex.mag() < 1E-8 ) {
670 myFilter->setMainVertex(primaryVertex+smearedVertex);
688 if ( productionMother ) {
689 unsigned motherId = productionMother->
pdgId();
690 if (
abs(motherId) < 1000000 )
693 if ( !
myFilter->accept(productionVertexPosition) )
continue;
697 bool testStable = p.
status()%1000==1;
712 bool testDaugh =
false;
717 for (
unsigned iDaughter=0; iDaughter<nDaughters; ++iDaughter ) {
719 if ( daughter->
status()%1000==1 ) {
728 if ( !testStable && !testDaugh ) {
730 dist = (primaryVertex-productionVertex).Vect().Mag2();
732 bool testDecay = ( dist > 1e-8 ) ?
true :
false;
735 if ( testStable || testDaugh || testDecay ) {
741 myGenVertices.find(mother) != myGenVertices.
end() ?
742 myGenVertices[mother] : mainVertex;
746 part.setID(p.
pdgId());
752 if ( !nDaughters )
continue;
758 daughter->
vz(), 0.) + smearedVertex;
761 if ( theVertex != -1 ) myGenVertices[&
p] = theVertex;
774 const HepMC::GenVertex* ev) {
778 if ( !
myFilter->accept(p) && ig >= -1 )
return -1;
789 if ( !
vertex(iv).noParent() ) {
794 if ( motherId < -1 ) ig = motherId;
799 (*theSimTracks)[trackId] = ev ?
802 ev->position().
t()/10.
806 FSimTrack(p,iv,ig,trackId,
this);
816 if ( !
myFilter->accept(v) )
return -1;
830 (*theSimVertices)[vertexId] =
FSimVertex(v,im,vertexId,
this);
841 std::cout <<
"Id Gen Name eta phi pT E Vtx1 "
843 <<
"Moth Vtx2 eta phi R Z Da1 Da2 Ecal?" << std::endl;
845 for ( HepMC::GenEvent::particle_const_iterator
846 piter = myGenEvent.particles_begin();
847 piter != myGenEvent.particles_end();
852 int partId = p->pdg_id();
868 if ( !p->production_vertex() )
continue;
870 XYZVector vertex1 (p->production_vertex()->position().x()/10.,
871 p->production_vertex()->position().y()/10.,
872 p->production_vertex()->position().z()/10.);
873 vertexId1 = p->production_vertex()->barcode();
875 std::cout.setf(std::ios::fixed, std::ios::floatfield);
876 std::cout.setf(std::ios::right, std::ios::adjustfield);
878 std::cout << std::setw(4) << p->barcode() <<
" "
881 for(
unsigned int k=0;
k<11-name.length() &&
k<12;
k++)
std::cout <<
" ";
883 double eta = momentum1.eta();
884 if ( eta > +10. ) eta = +10.;
885 if ( eta < -10. ) eta = -10.;
886 std::cout << std::setw(6) << std::setprecision(2) << eta <<
" "
887 << std::setw(6) << std::setprecision(2) << momentum1.phi() <<
" "
888 << std::setw(7) << std::setprecision(2) << momentum1.pt() <<
" "
889 << std::setw(7) << std::setprecision(2) << momentum1.e() <<
" "
890 << std::setw(4) << vertexId1 <<
" "
891 << std::setw(6) << std::setprecision(1) << vertex1.x() <<
" "
892 << std::setw(6) << std::setprecision(1) << vertex1.y() <<
" "
893 << std::setw(6) << std::setprecision(1) << vertex1.z() <<
" ";
896 *(p->production_vertex()->particles_in_const_begin());
899 std::cout << std::setw(4) << mother->barcode() <<
" ";
903 if ( p->end_vertex() ) {
905 p->end_vertex()->position().y()/10.,
906 p->end_vertex()->position().z()/10.,
907 p->end_vertex()->position().t()/10.);
908 int vertexId2 = p->end_vertex()->barcode();
910 std::vector<const HepMC::GenParticle*> children;
911 HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
912 p->end_vertex()->particles_out_const_begin();
913 HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
914 p->end_vertex()->particles_out_const_end();
915 for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
916 children.push_back(*firstDaughterIt);
919 std::cout << std::setw(4) << vertexId2 <<
" "
920 << std::setw(6) << std::setprecision(2) << vertex2.eta() <<
" "
921 << std::setw(6) << std::setprecision(2) << vertex2.phi() <<
" "
922 << std::setw(5) << std::setprecision(1) << vertex2.pt() <<
" "
923 << std::setw(6) << std::setprecision(1) << vertex2.z() <<
" ";
924 for (
unsigned id=0;
id<children.size(); ++id )
925 std::cout << std::setw(4) << children[id]->barcode() <<
" ";
936 std::cout <<
" Id Gen Name eta phi pT E Vtx1 "
938 <<
"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