CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATPackedGenParticleProducer.cc
Go to the documentation of this file.
1 #include <string>
2 
3 
22 
26 
33 #include "CLHEP/Vector/ThreeVector.h"
34 #include "CLHEP/Vector/LorentzVector.h"
35 #include "CLHEP/Matrix/Vector.h"
36 #include <string>
37 
38 
39 namespace pat {
41  public:
44 
45  virtual void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const;
46 
47  private:
53  const double maxRapidity_;
54  };
55 }
56 
58  Cands_(consumes<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("inputCollection"))),
59  GenOrigs_(consumes<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("inputOriginal"))),
60  Asso_(consumes<edm::Association<reco::GenParticleCollection> >(iConfig.getParameter<edm::InputTag>("map"))),
61  AssoOriginal_(consumes<edm::Association<reco::GenParticleCollection> >(iConfig.getParameter<edm::InputTag>("inputCollection"))),
62  PVs_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("inputVertices"))),
63  maxRapidity_(iConfig.getParameter<double>("maxRapidity"))
64 {
65  produces< std::vector<pat::PackedGenParticle> > ();
66  produces< edm::Association< std::vector<pat::PackedGenParticle> > >();
67 }
68 
70 
72 
73 
75  iEvent.getByToken( Cands_, cands );
76  std::vector<reco::Candidate>::const_iterator cand;
77 
79  iEvent.getByToken( Asso_, asso );
80 
82  iEvent.getByToken( AssoOriginal_, assoOriginal);
83 
85  iEvent.getByToken( GenOrigs_, genOrigs);
86  std::vector<int> mapping(genOrigs->size(), -1);
87 
88 
90  iEvent.getByToken( PVs_, PVs );
91  reco::VertexRef PV(PVs.id());
92  math::XYZPoint PVpos;
93  if (!PVs->empty()) {
94  PV = reco::VertexRef(PVs, 0);
95  PVpos = PV->position();
96  }
97 
98  //invert the value map from Orig2New to New2Orig
99  std::map< edm::Ref<reco::GenParticleCollection> , edm::Ref<reco::GenParticleCollection> > reverseMap;
100  for(unsigned int ic=0, nc = genOrigs->size(); ic < nc; ++ic)
101  {
103  edm::Ref<reco::GenParticleCollection> newRef = (*assoOriginal)[originalRef];
104  reverseMap.insert(std::pair<edm::Ref<reco::GenParticleCollection>,edm::Ref<reco::GenParticleCollection>>(newRef,originalRef));
105  }
106 
107  std::auto_ptr< std::vector<pat::PackedGenParticle> > outPtrP( new std::vector<pat::PackedGenParticle> );
108 
109  unsigned int packed=0;
110  for(unsigned int ic=0, nc = cands->size(); ic < nc; ++ic) {
111  const reco::GenParticle &cand=(*cands)[ic];
112  if(cand.status() ==1 && std::abs(cand.y()) < maxRapidity_)
113  {
114  // Obtain original gen particle collection reference from input reference and map
116  edm::Ref<reco::GenParticleCollection> originalRef=reverseMap[inputRef];
117  mapping[originalRef.key()]=packed;
118  packed++;
119  if(cand.numberOfMothers() > 0) {
120  edm::Ref<reco::GenParticleCollection> newRef=(*asso)[cand.motherRef(0)];
121  outPtrP->push_back( pat::PackedGenParticle(cand,newRef));
122  } else {
124 
125  }
126 
127  }
128  }
129 
130 
132 
133  std::auto_ptr<edm::Association< std::vector<pat::PackedGenParticle> > > gp2pgp(new edm::Association< std::vector<pat::PackedGenParticle> > (oh ));
134  edm::Association< std::vector<pat::PackedGenParticle> >::Filler gp2pgpFiller(*gp2pgp);
135  gp2pgpFiller.insert(genOrigs, mapping.begin(), mapping.end());
136  gp2pgpFiller.fill();
137  iEvent.put(gp2pgp);
138 
139 
140 }
141 
142 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual int status() const
status word
PATPackedGenParticleProducer(const edm::ParameterSet &)
virtual double y() const
rapidity
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
key_type key() const
Accessor for product key.
Definition: Ref.h:266
virtual void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const
const edm::EDGetTokenT< reco::GenParticleCollection > Cands_
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
virtual size_t numberOfMothers() const
number of mothers
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
const edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > Asso_
daughters::value_type motherRef(size_type i=0) const
reference to mother at given position
const edm::EDGetTokenT< reco::VertexCollection > PVs_
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const edm::EDGetTokenT< reco::GenParticleCollection > GenOrigs_
const edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > AssoOriginal_