2 #include "HepMC/GenEvent.h"
3 #include "HepMC/GenVertex.h"
4 #include "HepMC/GenParticle.h"
22 using namespace HepPDT;
35 nChargedParticleTracks(0),
122 const std::vector<SimVertex>& simVertices) {
129 unsigned nVtx = simVertices.size();
130 unsigned nTks = simTracks.size();
133 if ( nVtx == 0 )
return;
136 std::vector<int> myVertices(nVtx,-1);
137 std::vector<int> myTracks(nTks,-1);
142 std::map<unsigned, unsigned> geantToIndex;
143 for(
unsigned it=0; it<simTracks.size(); ++it ) {
144 geantToIndex[ simTracks[it].trackId() ] = it;
167 myFilter->setMainVertex(primaryVertex);
172 for(
unsigned trackId=0; trackId<nTks; ++trackId ) {
188 std::map<unsigned, unsigned >::iterator association
189 = geantToIndex.find( motherGeantId );
190 if(association != geantToIndex.end() )
191 motherId = association->second;
193 int originId = motherId == - 1 ? -1 : myTracks[motherId];
207 if ( myVertices[vertexId] == -1 )
215 int motherType = motherId == -1 ? 0 : simTracks[motherId].type();
217 bool notBremInDetector =
218 (
abs(motherType) != 11 &&
abs(motherType) != 13) ||
219 motherType != track.
type() ||
222 if ( notBremInDetector ) {
231 part.setID(track.
type());
237 if ( myTracks[trackId] >= 0 ) {
243 myTracks[trackId] = myTracks[motherId];
244 if ( myTracks[trackId] >= 0 ) {
253 for(
unsigned vertexId=0; vertexId<nVtx; ++vertexId ) {
256 if ( myVertices[vertexId] != -1 )
continue;
267 std::map<unsigned, unsigned >::iterator association
268 = geantToIndex.find( motherGeantId );
269 if(association != geantToIndex.end() )
270 motherId = association->second;
272 int originId = motherId == - 1 ? -1 : myTracks[motherId];
291 for(
int fsimi=0; fsimi < (int)
nTracks() ; ++fsimi) {
308 if ( mom.T() > 0. ) {
334 if ( myPart.
cos2ThetaV()>0.8 || mom.T() < 3. ) {
361 int genEventSize = myGenEvent.particles_size();
362 std::vector<int> myGenVertices(genEventSize, static_cast<int>(0));
365 if ( myGenEvent.particles_empty() )
return;
371 HepMC::GenVertex*
primaryVertex = *(myGenEvent.vertices_begin());
375 unsigned primaryMother = primaryVertex->particles_in_size();
376 if ( primaryMother ) {
377 unsigned partId = (*(primaryVertex->particles_in_const_begin()))->pdg_id();
378 if (
abs(partId) == 2212 ) primaryMother = 0;
383 primaryVertex->position().y()/10.,
384 primaryVertex->position().z()/10.,
385 primaryVertex->position().t()/10.);
387 primaryVertexPosition *= (1-primaryMother);
392 myFilter->setMainVertex(primaryVertexPosition);
397 HepMC::GenEvent::particle_const_iterator piter;
398 HepMC::GenEvent::particle_const_iterator pbegin = myGenEvent.particles_begin();
399 HepMC::GenEvent::particle_const_iterator pend = myGenEvent.particles_end();
401 int initialBarcode = 0;
402 if ( pbegin != pend ) initialBarcode = (*pbegin)->barcode();
404 for ( piter = pbegin; piter != pend; ++piter ) {
422 HepMC::GenVertex* productionVertex = p->production_vertex();
423 if ( productionVertex ) {
424 unsigned productionMother = productionVertex->particles_in_size();
425 if ( productionMother ) {
426 unsigned motherId = (*(productionVertex->particles_in_const_begin()))->pdg_id();
427 if (
abs(motherId) < 1000000 )
428 productionVertexPosition =
430 productionVertex->position().y()/10.,
431 productionVertex->position().z()/10.,
432 productionVertex->position().t()/10.);
435 if ( !
myFilter->accept(productionVertexPosition) )
continue;
437 int abspdgId =
abs(p->pdg_id());
438 HepMC::GenVertex* endVertex = p->end_vertex();
442 bool testStable = p->status()%1000==1;
445 if ( p->status() == 2 && abspdgId < 1000000) {
449 endVertex->position().y()/10.,
450 endVertex->position().z()/10.,
451 endVertex->position().t()/10.);
458 bool testDaugh =
false;
462 endVertex->particles_out_size() ) {
463 HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
464 endVertex->particles_out_const_begin();
465 HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
466 endVertex->particles_out_const_end();
467 for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
469 if ( daugh->status()%1000==1 ) {
471 if (abspdgId == 11 || abspdgId == 13) {
474 endVertex->position().y()/10.,
475 endVertex->position().z()/10.,
476 endVertex->position().t()/10.);
491 if ( !testStable && !testDaugh && p->production_vertex() ) {
493 productionVertexPosition(p->production_vertex()->position().x()/10.,
494 p->production_vertex()->position().y()/10.,
495 p->production_vertex()->position().z()/10.,
496 p->production_vertex()->position().t()/10.);
497 dist = (primaryVertexPosition-productionVertexPosition).Vect().Mag2();
499 bool testDecay = ( dist > 1
e-8 ) ?
true :
false;
502 if ( testStable || testDaugh || testDecay ) {
509 int motherBarcode = p->production_vertex() &&
510 p->production_vertex()->particles_in_const_begin() !=
511 p->production_vertex()->particles_in_const_end() ?
512 (*(p->production_vertex()->particles_in_const_begin()))->barcode() : 0;
515 motherBarcode && myGenVertices[motherBarcode-initialBarcode] ?
516 myGenVertices[motherBarcode-initialBarcode] : mainVertex;
523 part.setID(p->pdg_id());
527 int theTrack = testStable && p->end_vertex() ?
538 ( testStable && p->end_vertex() && !p->end_vertex()->particles_out_size() )
545 p->end_vertex()->position().y()/10.,
546 p->end_vertex()->position().z()/10.,
547 p->end_vertex()->position().t()/10.);
551 if ( theVertex != -1 ) myGenVertices[p->barcode()-initialBarcode] = theVertex;
563 unsigned int nParticles = myGenParticles.size();
566 if ( !nParticles )
return;
569 std::map<const reco::Candidate*,int> myGenVertices;
577 if ( nParticles > 1 &&
578 myGenParticles[0].
pdgId() == 2212 &&
579 myGenParticles[1].
pdgId() == 2212 ) {
586 myGenParticles[ip].vy(),
587 myGenParticles[ip].vz(),
591 myFilter->setMainVertex(primaryVertex);
597 for ( ; ip<nParticles; ++ip ) {
609 if ( productionMother ) {
610 unsigned motherId = productionMother->
pdgId();
611 if (
abs(motherId) < 1000000 )
614 if ( !
myFilter->accept(productionVertexPosition) )
continue;
618 bool testStable = p.
status()%1000==1;
633 bool testDaugh =
false;
638 for (
unsigned iDaughter=0; iDaughter<nDaughters; ++iDaughter ) {
640 if ( daughter->
status()%1000==1 ) {
649 if ( !testStable && !testDaugh ) {
651 dist = (primaryVertex-productionVertex).Vect().Mag2();
653 bool testDecay = ( dist > 1
e-8 ) ?
true :
false;
656 if ( testStable || testDaugh || testDecay ) {
662 myGenVertices.find(mother) != myGenVertices.
end() ?
663 myGenVertices[mother] : mainVertex;
667 part.setID(p.
pdgId());
673 if ( !nDaughters )
continue;
682 if ( theVertex != -1 ) myGenVertices[&
p] = theVertex;
695 const HepMC::GenVertex*
ev) {
699 if ( !
myFilter->accept(p) && ig >= -1 )
return -1;
710 if ( !
vertex(iv).noParent() ) {
715 if ( motherId < -1 ) ig = motherId;
720 (*theSimTracks)[trackId] = ev ?
723 ev->position().
t()/10.
727 FSimTrack(p,iv,ig,trackId,
this);
737 if ( !
myFilter->accept(v) )
return -1;
751 (*theSimVertices)[vertexId] =
FSimVertex(v,im,vertexId,
this);
762 std::cout <<
"Id Gen Name eta phi pT E Vtx1 "
764 <<
"Moth Vtx2 eta phi R Z Da1 Da2 Ecal?" << std::endl;
766 for ( HepMC::GenEvent::particle_const_iterator
767 piter = myGenEvent.particles_begin();
768 piter != myGenEvent.particles_end();
773 int partId = p->pdg_id();
789 if ( !p->production_vertex() )
continue;
791 XYZVector vertex1 (p->production_vertex()->position().x()/10.,
792 p->production_vertex()->position().y()/10.,
793 p->production_vertex()->position().z()/10.);
794 vertexId1 = p->production_vertex()->barcode();
796 std::cout.setf(std::ios::fixed, std::ios::floatfield);
797 std::cout.setf(std::ios::right, std::ios::adjustfield);
799 std::cout << std::setw(4) << p->barcode() <<
" "
802 for(
unsigned int k=0;
k<11-name.length() &&
k<12;
k++)
std::cout <<
" ";
804 double eta = momentum1.eta();
805 if ( eta > +10. ) eta = +10.;
806 if ( eta < -10. ) eta = -10.;
807 std::cout << std::setw(6) << std::setprecision(2) << eta <<
" "
808 << std::setw(6) << std::setprecision(2) << momentum1.phi() <<
" "
809 << std::setw(7) << std::setprecision(2) << momentum1.pt() <<
" "
810 << std::setw(7) << std::setprecision(2) << momentum1.e() <<
" "
811 << std::setw(4) << vertexId1 <<
" "
812 << std::setw(6) << std::setprecision(1) << vertex1.x() <<
" "
813 << std::setw(6) << std::setprecision(1) << vertex1.y() <<
" "
814 << std::setw(6) << std::setprecision(1) << vertex1.z() <<
" ";
817 *(p->production_vertex()->particles_in_const_begin());
820 std::cout << std::setw(4) << mother->barcode() <<
" ";
824 if ( p->end_vertex() ) {
826 p->end_vertex()->position().y()/10.,
827 p->end_vertex()->position().z()/10.,
828 p->end_vertex()->position().t()/10.);
829 int vertexId2 = p->end_vertex()->barcode();
831 std::vector<const HepMC::GenParticle*> children;
832 HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
833 p->end_vertex()->particles_out_const_begin();
834 HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
835 p->end_vertex()->particles_out_const_end();
836 for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
837 children.push_back(*firstDaughterIt);
840 std::cout << std::setw(4) << vertexId2 <<
" "
841 << std::setw(6) << std::setprecision(2) << vertex2.eta() <<
" "
842 << std::setw(6) << std::setprecision(2) << vertex2.phi() <<
" "
843 << std::setw(5) << std::setprecision(1) << vertex2.pt() <<
" "
844 << std::setw(6) << std::setprecision(1) << vertex2.z() <<
" ";
845 for (
unsigned id=0;
id<children.size(); ++id )
846 std::cout << std::setw(4) << children[id]->barcode() <<
" ";
857 std::cout <<
" Id Gen Name eta phi pT E Vtx1 "
859 <<
"Moth Vtx2 eta phi R Z Daughters Ecal?" << std::endl;
const ParticleDataTable * pdt
double lateVertexPosition
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
const math::XYZVectorD & trackerSurfacePosition() const
void setCharge(float q)
set the MEASURED charge
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.
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
bool notYetToEndVertex(const XYZTLorentzVector &pos) const
Compare the end vertex position with another position.
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.
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.
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)
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 double px() const
x coordinate of momentum vector
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 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
static int position[264][3]
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) ...
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