2 #include "HepMC/GenEvent.h" 3 #include "HepMC/GenVertex.h" 4 #include "HepMC/GenParticle.h" 37 nChargedParticleTracks(0),
116 unsigned nVtx = simVertices.size();
117 unsigned nTks = simTracks.size();
120 if ( nVtx == 0 )
return;
123 std::vector<int> myVertices(nVtx,-1);
124 std::vector<int> myTracks(nTks,-1);
129 std::map<unsigned, unsigned> geantToIndex;
130 for(
unsigned it=0; it<simTracks.size(); ++it ) {
131 geantToIndex[ simTracks[it].trackId() ] = it;
159 for(
unsigned trackId=0; trackId<nTks; ++trackId ) {
175 std::map<unsigned, unsigned >::iterator
association 176 = geantToIndex.find( motherGeantId );
177 if(association != geantToIndex.end() )
178 motherId = association->second;
180 int originId = motherId == - 1 ? -1 : myTracks[
motherId];
194 if ( myVertices[vertexId] == -1 )
202 int motherType = motherId == -1 ? 0 : simTracks[
motherId].type();
204 bool notBremInDetector =
205 (
abs(motherType) != 11 &&
std::abs(motherType) != 13) ||
206 motherType != track.
type() ||
209 if ( notBremInDetector ) {
223 if ( myTracks[trackId] >= 0 ) {
229 myTracks[trackId] = myTracks[
motherId];
230 if ( myTracks[trackId] >= 0 ) {
239 for(
unsigned vertexId=0; vertexId<nVtx; ++vertexId ) {
242 if ( myVertices[vertexId] != -1 )
continue;
253 std::map<unsigned, unsigned >::iterator
association 254 = geantToIndex.find( motherGeantId );
255 if(association != geantToIndex.end() )
256 motherId = association->second;
258 int originId = motherId == - 1 ? -1 : myTracks[
motherId];
277 for(
int fsimi=0; fsimi < (
int)
nTracks() ; ++fsimi) {
294 if ( mom.T() > 0. ) {
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.);
366 int initialBarcode = 0;
367 if ( myGenEvent.particles_begin() != myGenEvent.particles_end() )
369 initialBarcode = (*myGenEvent.particles_begin())->barcode();
373 for (
auto piter = myGenEvent.particles_begin(); piter != myGenEvent.particles_end(); ++piter )
392 HepMC::GenVertex* productionVertex = p->production_vertex();
393 if ( productionVertex ) {
394 unsigned productionMother = productionVertex->particles_in_size();
395 if ( productionMother ) {
396 unsigned motherId = (*(productionVertex->particles_in_const_begin()))->pdg_id();
397 if ( motherId < 1000000 )
398 productionVertexPosition =
400 productionVertex->position().y()/10.,
401 productionVertex->position().z()/10.,
402 productionVertex->position().t()/10.);
405 if ( !
myFilter->acceptVertex(productionVertexPosition) )
continue;
407 int abspdgId =
std::abs(p->pdg_id());
408 HepMC::GenVertex* endVertex = p->end_vertex();
412 bool testStable = p->status()%1000==1;
415 if ( p->status() == 2 && abspdgId < 1000000) {
419 endVertex->position().y()/10.,
420 endVertex->position().z()/10.,
421 endVertex->position().t()/10.);
428 bool testDaugh =
false;
432 endVertex->particles_out_size() ) {
433 HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
434 endVertex->particles_out_const_begin();
435 HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
436 endVertex->particles_out_const_end();
437 for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
439 if ( daugh->status()%1000==1 ) {
441 if (abspdgId == 11 || abspdgId == 13) {
444 endVertex->position().y()/10.,
445 endVertex->position().z()/10.,
446 endVertex->position().t()/10.);
461 if ( !testStable && !testDaugh && p->production_vertex() ) {
463 productionVertexPosition(p->production_vertex()->position().x()/10.,
464 p->production_vertex()->position().y()/10.,
465 p->production_vertex()->position().z()/10.,
466 p->production_vertex()->position().t()/10.);
467 dist = (primaryVertexPosition-productionVertexPosition).Vect().Mag2();
469 bool testDecay = ( dist > 1
e-8 ) ?
true :
false;
472 if ( testStable || testDaugh || testDecay ) {
479 int motherBarcode = p->production_vertex() &&
480 p->production_vertex()->particles_in_const_begin() !=
481 p->production_vertex()->particles_in_const_end() ?
482 (*(p->production_vertex()->particles_in_const_begin()))->barcode() : 0;
485 motherBarcode && myGenVertices[motherBarcode-initialBarcode] ?
486 myGenVertices[motherBarcode-initialBarcode] : mainVertex;
496 int theTrack = testStable && p->end_vertex() ?
507 ( testStable && p->end_vertex() && !p->end_vertex()->particles_out_size() )
514 p->end_vertex()->position().y()/10.,
515 p->end_vertex()->position().z()/10.,
516 p->end_vertex()->position().t()/10.);
520 if ( theVertex != -1 ) myGenVertices[p->barcode()-initialBarcode] = theVertex;
530 const HepMC::GenVertex*
ev) {
534 if ( !
myFilter->acceptParticle(*p) && ig >= -1 )
return -1;
545 if ( !
vertex(iv).noParent() ) {
555 (*theSimTracks)[trackId] = ev ?
558 ev->position().
t()/10.
562 FSimTrack(p,iv,ig,trackId,
this);
572 if ( !
myFilter->acceptVertex(v) )
return -1;
586 (*theSimVertices)[vertexId] =
FSimVertex(v,im,vertexId,
this);
597 std::cout <<
"Id Gen Name eta phi pT E Vtx1 " 599 <<
"Moth Vtx2 eta phi R Z Da1 Da2 Ecal?" << std::endl;
601 for ( HepMC::GenEvent::particle_const_iterator
602 piter = myGenEvent.particles_begin();
603 piter != myGenEvent.particles_end();
608 int partId = p->pdg_id();
624 if ( !p->production_vertex() )
continue;
626 XYZVector vertex1 (p->production_vertex()->position().x()/10.,
627 p->production_vertex()->position().y()/10.,
628 p->production_vertex()->position().z()/10.);
629 vertexId1 = p->production_vertex()->barcode();
632 std::cout.setf(std::ios::right, std::ios::adjustfield);
634 std::cout << std::setw(4) << p->barcode() <<
" " 637 for(
unsigned int k=0;
k<11-name.length() &&
k<12;
k++)
std::cout <<
" ";
639 double eta = momentum1.eta();
640 if ( eta > +10. ) eta = +10.;
641 if ( eta < -10. ) eta = -10.;
642 std::cout << std::setw(6) << std::setprecision(2) << eta <<
" " 643 << std::setw(6) << std::setprecision(2) << momentum1.phi() <<
" " 644 << std::setw(7) << std::setprecision(2) << momentum1.pt() <<
" " 645 << std::setw(7) << std::setprecision(2) << momentum1.e() <<
" " 646 << std::setw(4) << vertexId1 <<
" " 647 << std::setw(6) << std::setprecision(1) << vertex1.x() <<
" " 648 << std::setw(6) << std::setprecision(1) << vertex1.y() <<
" " 649 << std::setw(6) << std::setprecision(1) << vertex1.z() <<
" ";
652 *(p->production_vertex()->particles_in_const_begin());
655 std::cout << std::setw(4) << mother->barcode() <<
" ";
659 if ( p->end_vertex() ) {
661 p->end_vertex()->position().y()/10.,
662 p->end_vertex()->position().z()/10.,
663 p->end_vertex()->position().t()/10.);
664 int vertexId2 = p->end_vertex()->barcode();
666 std::vector<const HepMC::GenParticle*>
children;
667 HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
668 p->end_vertex()->particles_out_const_begin();
669 HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
670 p->end_vertex()->particles_out_const_end();
671 for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
672 children.push_back(*firstDaughterIt);
675 std::cout << std::setw(4) << vertexId2 <<
" " 676 << std::setw(6) << std::setprecision(2) << vertex2.eta() <<
" " 677 << std::setw(6) << std::setprecision(2) << vertex2.phi() <<
" " 678 << std::setw(5) << std::setprecision(1) << vertex2.pt() <<
" " 679 << std::setw(6) << std::setprecision(1) << vertex2.z() <<
" ";
680 for (
unsigned id=0;
id<children.size(); ++
id )
681 std::cout << std::setw(4) << children[
id]->barcode() <<
" ";
692 std::cout <<
" Id Gen Name eta phi pT E Vtx1 " 694 <<
"Moth Vtx2 eta phi R Z Daughters Ecal?" << std::endl;
const ParticleDataTable * pdt
double lateVertexPosition
const math::XYZVectorD & trackerSurfacePosition() 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.
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
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.
const HepPDT::ParticleDataTable * theTable() const
Get the pointer to the particle data table.
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.
int pid() const
get the HEP particle ID number
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.
RawParticle const & particle() const
The particle being propagated.
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.
RawParticle makeParticle(HepPDT::ParticleDataTable const *, int id, const math::XYZTLorentzVector &p)
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
~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
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]
double mass(int pdgID, const HepPDT::ParticleDataTable *pdt)
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.
const FSimVertex vertex() const
Origin vertex.
void printMCTruth(const HepMC::GenEvent &hev)
print the original MCTruth event
std::vector< HepMC::GenParticle * > * theGenParticles
math::XYZVector XYZVector
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