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 primaryVertex->position().y()/10.,
376 primaryVertex->position().z()/10.,
377 primaryVertex->position().t()/10.);
380 myFilter->setMainVertex(primaryVertexPosition);
385 HepMC::GenEvent::particle_const_iterator piter;
386 HepMC::GenEvent::particle_const_iterator pbegin = myGenEvent.particles_begin();
387 HepMC::GenEvent::particle_const_iterator pend = myGenEvent.particles_end();
389 int initialBarcode = 0;
390 if ( pbegin != pend ) initialBarcode = (*pbegin)->barcode();
392 for ( piter = pbegin; piter != pend; ++piter ) {
410 HepMC::GenVertex* productionVertex = p->production_vertex();
411 if ( productionVertex ) {
412 unsigned productionMother = productionVertex->particles_in_size();
413 if ( productionMother ) {
414 unsigned motherId = (*(productionVertex->particles_in_const_begin()))->pdg_id();
415 if (
abs(motherId) < 1000000 )
416 productionVertexPosition =
418 productionVertex->position().y()/10.,
419 productionVertex->position().z()/10.,
420 productionVertex->position().t()/10.);
423 if ( !
myFilter->accept(productionVertexPosition) )
continue;
425 int abspdgId =
abs(p->pdg_id());
426 HepMC::GenVertex* endVertex = p->end_vertex();
430 bool testStable = p->status()%1000==1;
433 if ( p->status() == 2 && abspdgId < 1000000) {
437 endVertex->position().y()/10.,
438 endVertex->position().z()/10.,
439 endVertex->position().t()/10.);
446 bool testDaugh =
false;
450 endVertex->particles_out_size() ) {
451 HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
452 endVertex->particles_out_const_begin();
453 HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
454 endVertex->particles_out_const_end();
455 for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
457 if ( daugh->status()%1000==1 ) {
459 if (abspdgId == 11 || abspdgId == 13) {
462 endVertex->position().y()/10.,
463 endVertex->position().z()/10.,
464 endVertex->position().t()/10.);
479 if ( !testStable && !testDaugh && p->production_vertex() ) {
481 productionVertexPosition(p->production_vertex()->position().x()/10.,
482 p->production_vertex()->position().y()/10.,
483 p->production_vertex()->position().z()/10.,
484 p->production_vertex()->position().t()/10.);
485 dist = (primaryVertexPosition-productionVertexPosition).Vect().Mag2();
487 bool testDecay = ( dist > 1
e-8 ) ?
true :
false;
490 if ( testStable || testDaugh || testDecay ) {
497 int motherBarcode = p->production_vertex() &&
498 p->production_vertex()->particles_in_const_begin() !=
499 p->production_vertex()->particles_in_const_end() ?
500 (*(p->production_vertex()->particles_in_const_begin()))->barcode() : 0;
503 motherBarcode && myGenVertices[motherBarcode-initialBarcode] ?
504 myGenVertices[motherBarcode-initialBarcode] : mainVertex;
511 part.setID(p->pdg_id());
515 int theTrack = testStable && p->end_vertex() ?
526 ( testStable && p->end_vertex() && !p->end_vertex()->particles_out_size() )
533 p->end_vertex()->position().y()/10.,
534 p->end_vertex()->position().z()/10.,
535 p->end_vertex()->position().t()/10.);
539 if ( theVertex != -1 ) myGenVertices[p->barcode()-initialBarcode] = theVertex;
551 unsigned int nParticles = myGenParticles.size();
554 if ( !nParticles )
return;
557 std::map<const reco::Candidate*,int> myGenVertices;
565 if ( nParticles > 1 &&
566 myGenParticles[0].
pdgId() == 2212 &&
567 myGenParticles[1].
pdgId() == 2212 ) {
574 myGenParticles[ip].vy(),
575 myGenParticles[ip].vz(),
579 myFilter->setMainVertex(primaryVertex);
585 for ( ; ip<nParticles; ++ip ) {
597 if ( productionMother ) {
598 unsigned motherId = productionMother->
pdgId();
599 if (
abs(motherId) < 1000000 )
602 if ( !
myFilter->accept(productionVertexPosition) )
continue;
606 bool testStable = p.
status()%1000==1;
621 bool testDaugh =
false;
626 for (
unsigned iDaughter=0; iDaughter<nDaughters; ++iDaughter ) {
628 if ( daughter->
status()%1000==1 ) {
637 if ( !testStable && !testDaugh ) {
639 dist = (primaryVertex-productionVertex).Vect().Mag2();
641 bool testDecay = ( dist > 1
e-8 ) ?
true :
false;
644 if ( testStable || testDaugh || testDecay ) {
650 myGenVertices.find(mother) != myGenVertices.
end() ?
651 myGenVertices[mother] : mainVertex;
655 part.setID(p.
pdgId());
661 if ( !nDaughters )
continue;
670 if ( theVertex != -1 ) myGenVertices[&
p] = theVertex;
683 const HepMC::GenVertex*
ev) {
687 if ( !
myFilter->accept(p) && ig >= -1 )
return -1;
698 if ( !
vertex(iv).noParent() ) {
703 if ( motherId < -1 ) ig = motherId;
708 (*theSimTracks)[trackId] = ev ?
711 ev->position().
t()/10.
715 FSimTrack(p,iv,ig,trackId,
this);
725 if ( !
myFilter->accept(v) )
return -1;
739 (*theSimVertices)[vertexId] =
FSimVertex(v,im,vertexId,
this);
750 std::cout <<
"Id Gen Name eta phi pT E Vtx1 "
752 <<
"Moth Vtx2 eta phi R Z Da1 Da2 Ecal?" << std::endl;
754 for ( HepMC::GenEvent::particle_const_iterator
755 piter = myGenEvent.particles_begin();
756 piter != myGenEvent.particles_end();
761 int partId = p->pdg_id();
777 if ( !p->production_vertex() )
continue;
779 XYZVector vertex1 (p->production_vertex()->position().x()/10.,
780 p->production_vertex()->position().y()/10.,
781 p->production_vertex()->position().z()/10.);
782 vertexId1 = p->production_vertex()->barcode();
784 std::cout.setf(std::ios::fixed, std::ios::floatfield);
785 std::cout.setf(std::ios::right, std::ios::adjustfield);
787 std::cout << std::setw(4) << p->barcode() <<
" "
790 for(
unsigned int k=0;
k<11-name.length() &&
k<12;
k++)
std::cout <<
" ";
792 double eta = momentum1.eta();
793 if ( eta > +10. ) eta = +10.;
794 if ( eta < -10. ) eta = -10.;
795 std::cout << std::setw(6) << std::setprecision(2) << eta <<
" "
796 << std::setw(6) << std::setprecision(2) << momentum1.phi() <<
" "
797 << std::setw(7) << std::setprecision(2) << momentum1.pt() <<
" "
798 << std::setw(7) << std::setprecision(2) << momentum1.e() <<
" "
799 << std::setw(4) << vertexId1 <<
" "
800 << std::setw(6) << std::setprecision(1) << vertex1.x() <<
" "
801 << std::setw(6) << std::setprecision(1) << vertex1.y() <<
" "
802 << std::setw(6) << std::setprecision(1) << vertex1.z() <<
" ";
805 *(p->production_vertex()->particles_in_const_begin());
808 std::cout << std::setw(4) << mother->barcode() <<
" ";
812 if ( p->end_vertex() ) {
814 p->end_vertex()->position().y()/10.,
815 p->end_vertex()->position().z()/10.,
816 p->end_vertex()->position().t()/10.);
817 int vertexId2 = p->end_vertex()->barcode();
819 std::vector<const HepMC::GenParticle*> children;
820 HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
821 p->end_vertex()->particles_out_const_begin();
822 HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
823 p->end_vertex()->particles_out_const_end();
824 for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
825 children.push_back(*firstDaughterIt);
828 std::cout << std::setw(4) << vertexId2 <<
" "
829 << std::setw(6) << std::setprecision(2) << vertex2.eta() <<
" "
830 << std::setw(6) << std::setprecision(2) << vertex2.phi() <<
" "
831 << std::setw(5) << std::setprecision(1) << vertex2.pt() <<
" "
832 << std::setw(6) << std::setprecision(1) << vertex2.z() <<
" ";
833 for (
unsigned id=0;
id<children.size(); ++id )
834 std::cout << std::setw(4) << children[id]->barcode() <<
" ";
845 std::cout <<
" Id Gen Name eta phi pT E Vtx1 "
847 <<
"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
~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)
const_iterator end() const
last daughter const_iterator
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
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