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  auto outPtrP = std::make_unique<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  auto gp2pgp = std::make_unique<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(std::move(gp2pgp));
138 
139 
140 }
141 
142 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
PATPackedGenParticleProducer(const edm::ParameterSet &)
virtual double y() const final
rapidity
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
key_type key() const
Accessor for product key.
Definition: Ref.h:264
virtual void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const
virtual int status() const final
status word
const edm::EDGetTokenT< reco::GenParticleCollection > Cands_
int iEvent
Definition: GenABIO.cc:230
virtual size_t numberOfMothers() const
number of mothers
def move
Definition: eostools.py:510
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_