2 #include "HepMC/GenEvent.h"
3 #include "HepMC/GenVertex.h"
4 #include "HepMC/GenParticle.h"
22 using namespace HepPDT;
35 nChargedParticleTracks(0),
107 const std::vector<SimVertex>& simVertices) {
114 unsigned nVtx = simVertices.size();
115 unsigned nTks = simTracks.size();
118 if ( nVtx == 0 )
return;
121 std::vector<int> myVertices(nVtx,-1);
122 std::vector<int> myTracks(nTks,-1);
127 std::map<unsigned, unsigned> geantToIndex;
128 for(
unsigned it=0; it<simTracks.size(); ++it ) {
129 geantToIndex[ simTracks[it].trackId() ] = it;
152 myFilter->setMainVertex(primaryVertex);
157 for(
unsigned trackId=0; trackId<nTks; ++trackId ) {
173 std::map<unsigned, unsigned >::iterator association
174 = geantToIndex.find( motherGeantId );
175 if(association != geantToIndex.end() )
176 motherId = association->second;
178 int originId = motherId == - 1 ? -1 : myTracks[motherId];
192 if ( myVertices[vertexId] == -1 )
200 int motherType = motherId == -1 ? 0 : simTracks[motherId].type();
202 bool notBremInDetector =
203 (
abs(motherType) != 11 &&
abs(motherType) != 13) ||
204 motherType != track.
type() ||
207 if ( notBremInDetector ) {
216 part.setID(track.
type());
222 if ( myTracks[trackId] >= 0 ) {
228 myTracks[trackId] = myTracks[motherId];
229 if ( myTracks[trackId] >= 0 ) {
238 for(
unsigned vertexId=0; vertexId<nVtx; ++vertexId ) {
241 if ( myVertices[vertexId] != -1 )
continue;
252 std::map<unsigned, unsigned >::iterator association
253 = geantToIndex.find( motherGeantId );
254 if(association != geantToIndex.end() )
255 motherId = association->second;
257 int originId = motherId == - 1 ? -1 : myTracks[motherId];
276 for(
int fsimi=0; fsimi < (int)
nTracks() ; ++fsimi) {
293 if ( mom.T() > 0. ) {
319 if ( myPart.
cos2ThetaV()>0.8 || mom.T() < 3. ) {
345 int genEventSize = myGenEvent.particles_size();
346 std::vector<int> myGenVertices(genEventSize, static_cast<int>(0));
349 if ( myGenEvent.particles_empty() )
return;
355 HepMC::GenVertex*
primaryVertex = *(myGenEvent.vertices_begin());
359 primaryVertex->position().y()/10.,
360 primaryVertex->position().z()/10.,
361 primaryVertex->position().t()/10.);
364 myFilter->setMainVertex(primaryVertexPosition);
369 HepMC::GenEvent::particle_const_iterator piter;
370 HepMC::GenEvent::particle_const_iterator pbegin = myGenEvent.particles_begin();
371 HepMC::GenEvent::particle_const_iterator pend = myGenEvent.particles_end();
373 int initialBarcode = 0;
374 if ( pbegin != pend ) initialBarcode = (*pbegin)->barcode();
376 for ( piter = pbegin; piter != pend; ++piter ) {
394 HepMC::GenVertex* productionVertex = p->production_vertex();
395 if ( productionVertex ) {
396 unsigned productionMother = productionVertex->particles_in_size();
397 if ( productionMother ) {
398 unsigned motherId = (*(productionVertex->particles_in_const_begin()))->pdg_id();
399 if (
abs(motherId) < 1000000 )
400 productionVertexPosition =
402 productionVertex->position().y()/10.,
403 productionVertex->position().z()/10.,
404 productionVertex->position().t()/10.);
407 if ( !
myFilter->accept(productionVertexPosition) )
continue;
409 int abspdgId =
abs(p->pdg_id());
410 HepMC::GenVertex* endVertex = p->end_vertex();
414 bool testStable = p->status()%1000==1;
417 if ( p->status() == 2 && abspdgId < 1000000) {
421 endVertex->position().y()/10.,
422 endVertex->position().z()/10.,
423 endVertex->position().t()/10.);
430 bool testDaugh =
false;
434 endVertex->particles_out_size() ) {
435 HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
436 endVertex->particles_out_const_begin();
437 HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
438 endVertex->particles_out_const_end();
439 for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
441 if ( daugh->status()%1000==1 ) {
443 if (abspdgId == 11 || abspdgId == 13) {
446 endVertex->position().y()/10.,
447 endVertex->position().z()/10.,
448 endVertex->position().t()/10.);
463 if ( !testStable && !testDaugh && p->production_vertex() ) {
465 productionVertexPosition(p->production_vertex()->position().x()/10.,
466 p->production_vertex()->position().y()/10.,
467 p->production_vertex()->position().z()/10.,
468 p->production_vertex()->position().t()/10.);
469 dist = (primaryVertexPosition-productionVertexPosition).Vect().Mag2();
471 bool testDecay = ( dist > 1
e-8 ) ?
true :
false;
474 if ( testStable || testDaugh || testDecay ) {
481 int motherBarcode = p->production_vertex() &&
482 p->production_vertex()->particles_in_const_begin() !=
483 p->production_vertex()->particles_in_const_end() ?
484 (*(p->production_vertex()->particles_in_const_begin()))->barcode() : 0;
487 motherBarcode && myGenVertices[motherBarcode-initialBarcode] ?
488 myGenVertices[motherBarcode-initialBarcode] : mainVertex;
495 part.setID(p->pdg_id());
499 int theTrack = testStable && p->end_vertex() ?
510 ( testStable && p->end_vertex() && !p->end_vertex()->particles_out_size() )
517 p->end_vertex()->position().y()/10.,
518 p->end_vertex()->position().z()/10.,
519 p->end_vertex()->position().t()/10.);
523 if ( theVertex != -1 ) myGenVertices[p->barcode()-initialBarcode] = theVertex;
534 const HepMC::GenVertex*
ev) {
538 if ( !
myFilter->accept(p) && ig >= -1 )
return -1;
549 if ( !
vertex(iv).noParent() ) {
554 if ( motherId < -1 ) ig = motherId;
559 (*theSimTracks)[trackId] = ev ?
562 ev->position().
t()/10.
566 FSimTrack(p,iv,ig,trackId,
this);
576 if ( !
myFilter->accept(v) )
return -1;
590 (*theSimVertices)[vertexId] =
FSimVertex(v,im,vertexId,
this);
601 std::cout <<
"Id Gen Name eta phi pT E Vtx1 "
603 <<
"Moth Vtx2 eta phi R Z Da1 Da2 Ecal?" << std::endl;
605 for ( HepMC::GenEvent::particle_const_iterator
606 piter = myGenEvent.particles_begin();
607 piter != myGenEvent.particles_end();
612 int partId = p->pdg_id();
615 if (
pdt->particle(ParticleID(partId)) !=0 ) {
616 name = (
pdt->particle(ParticleID(partId)))->
name();
628 if ( !p->production_vertex() )
continue;
630 XYZVector vertex1 (p->production_vertex()->position().x()/10.,
631 p->production_vertex()->position().y()/10.,
632 p->production_vertex()->position().z()/10.);
633 vertexId1 = p->production_vertex()->barcode();
635 std::cout.setf(std::ios::fixed, std::ios::floatfield);
636 std::cout.setf(std::ios::right, std::ios::adjustfield);
638 std::cout << std::setw(4) << p->barcode() <<
" "
641 for(
unsigned int k=0;
k<11-name.length() &&
k<12;
k++)
std::cout <<
" ";
643 double eta = momentum1.eta();
644 if ( eta > +10. ) eta = +10.;
645 if ( eta < -10. ) eta = -10.;
646 std::cout << std::setw(6) << std::setprecision(2) << eta <<
" "
647 << std::setw(6) << std::setprecision(2) << momentum1.phi() <<
" "
648 << std::setw(7) << std::setprecision(2) << momentum1.pt() <<
" "
649 << std::setw(7) << std::setprecision(2) << momentum1.e() <<
" "
650 << std::setw(4) << vertexId1 <<
" "
651 << std::setw(6) << std::setprecision(1) << vertex1.x() <<
" "
652 << std::setw(6) << std::setprecision(1) << vertex1.y() <<
" "
653 << std::setw(6) << std::setprecision(1) << vertex1.z() <<
" ";
656 *(p->production_vertex()->particles_in_const_begin());
659 std::cout << std::setw(4) << mother->barcode() <<
" ";
663 if ( p->end_vertex() ) {
665 p->end_vertex()->position().y()/10.,
666 p->end_vertex()->position().z()/10.,
667 p->end_vertex()->position().t()/10.);
668 int vertexId2 = p->end_vertex()->barcode();
670 std::vector<const HepMC::GenParticle*> children;
671 HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
672 p->end_vertex()->particles_out_const_begin();
673 HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
674 p->end_vertex()->particles_out_const_end();
675 for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
676 children.push_back(*firstDaughterIt);
679 std::cout << std::setw(4) << vertexId2 <<
" "
680 << std::setw(6) << std::setprecision(2) << vertex2.eta() <<
" "
681 << std::setw(6) << std::setprecision(2) << vertex2.phi() <<
" "
682 << std::setw(5) << std::setprecision(1) << vertex2.pt() <<
" "
683 << std::setw(6) << std::setprecision(1) << vertex2.z() <<
" ";
684 for (
unsigned id=0;
id<children.size(); ++id )
685 std::cout << std::setw(4) << children[id]->barcode() <<
" ";
696 std::cout <<
" Id Gen Name eta phi pT E Vtx1 "
698 <<
"Moth Vtx2 eta phi R Z Daughters Ecal?" << std::endl;
const ParticleDataTable * pdt
double lateVertexPosition
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.
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
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
KineParticleFilter * myFilter
The particle filter.
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.
bool notYetToEndVertex(const XYZTLorentzVector &pos) const
Compare the end vertex position with another 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
~FBaseSimEvent()
usual virtual destructor
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)
unsigned int nSimVertices
int genpartIndex() const
index of the corresponding Generator particle in the Event container (-1 if no Genpart) ...
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
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)
const XYZTLorentzVector & vertex() const
the vertex fourvector
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.
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.
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)
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