CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PFCand_NoPU_WithAM.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PFCand_NoPU_WithAM
4 // Class: PFCand_NoPU_WithAM
5 //
11 //
12 // Original Author: Matthias Geisler,32 4-B20,+41227676487,
13 // Created: Thu Dec 1 16:07:41 CET 2011
14 // $Id: PFCand_NoPU_WithAM.cc,v 1.5 2012/12/06 14:03:15 mgeisler Exp $
15 //
16 //
18 
19 // system include files
20 #include <memory>
21 #include <vector>
22 
23 // user include files
24 
28 
30 
32 
36 
37 using namespace edm;
38 using namespace std;
39 using namespace reco;
40 
41 //
42 // constructors and destructor
43 //
45  //now do what ever other initialization is needed
46 
47  input_AssociationType_ = iConfig.getParameter<InputTag>("AssociationType");
48 
49  token_PFCandToVertexAssMap_ =
50  mayConsume<PFCandToVertexAssMap>(iConfig.getParameter<InputTag>("VertexPFCandAssociationMap"));
51  token_VertexToPFCandAssMap_ =
52  mayConsume<VertexToPFCandAssMap>(iConfig.getParameter<InputTag>("VertexPFCandAssociationMap"));
53 
54  token_VertexCollection_ = mayConsume<VertexCollection>(iConfig.getParameter<InputTag>("VertexCollection"));
55 
56  input_MinQuality_ = iConfig.getParameter<int>("MinQuality");
57 
58  //register your products
59 
60  if (input_AssociationType_.label() == "PFCandsToVertex") {
61  produces<PFCandidateCollection>("P2V");
62  } else {
63  if (input_AssociationType_.label() == "VertexToPFCands") {
64  produces<PFCandidateCollection>("V2P");
65  } else {
66  if (input_AssociationType_.label() == "Both") {
67  produces<PFCandidateCollection>("P2V");
68  produces<PFCandidateCollection>("V2P");
69  } else {
70  cout << "No correct InputTag for AssociationType!" << endl;
71  cout << "Won't produce any PFCandiateCollection!" << endl;
72  }
73  }
74  }
75 }
76 
78  // do anything here that needs to be done at desctruction time
79  // (e.g. close files, deallocate resources etc.)
80 }
81 
82 //
83 // member functions
84 //
85 
86 // ------------ method called to produce the data ------------
88  unique_ptr<PFCandidateCollection> p2v_firstvertex(new PFCandidateCollection());
89  unique_ptr<PFCandidateCollection> v2p_firstvertex(new PFCandidateCollection());
90 
91  bool p2vassmap = false;
92  bool v2passmap = false;
93 
94  //get the input vertex<->pf-candidate association map
97 
98  string asstype = input_AssociationType_.label();
99 
100  if ((asstype == "PFCandsToVertex") || (asstype == "Both")) {
101  if (iEvent.getByToken(token_PFCandToVertexAssMap_, p2vAM)) {
102  p2vassmap = true;
103  }
104  }
105 
106  if ((asstype == "VertexToPFCands") || (asstype == "Both")) {
107  if (iEvent.getByToken(token_VertexToPFCandAssMap_, v2pAM)) {
108  v2passmap = true;
109  }
110  }
111 
112  if (!p2vassmap && !v2passmap) {
113  cout << "No input collection could be found" << endl;
114  return;
115  }
116 
117  int negativeQuality = 0;
118  if (input_MinQuality_ >= 2) {
119  negativeQuality = -1;
120  } else {
121  if (input_MinQuality_ == 1) {
122  negativeQuality = -2;
123  } else {
124  negativeQuality = -3;
125  }
126  }
127 
128  if (p2vassmap) {
129  const PFCandQualityPairVector pfccoll = p2vAM->begin()->val;
130 
131  //get the candidates associated to the first vertex and store them in a pf-candidate collection
132  for (unsigned int pfccoll_ite = 0; pfccoll_ite < pfccoll.size(); pfccoll_ite++) {
133  PFCandidateRef pfcand = pfccoll[pfccoll_ite].first;
134  int quality = pfccoll[pfccoll_ite].second;
135 
136  if ((quality >= input_MinQuality_) || ((quality < 0) && (quality >= negativeQuality))) {
137  p2v_firstvertex->push_back(*pfcand);
138  }
139  }
140 
141  iEvent.put(std::move(p2v_firstvertex), "P2V");
142  }
143 
144  if (v2passmap) {
145  //get the input vertex collection
146  Handle<VertexCollection> input_vtxcollH;
147  iEvent.getByToken(token_VertexCollection_, input_vtxcollH);
148 
149  VertexRef firstVertexRef(input_vtxcollH, 0);
150 
152 
153  for (v2p_ite = v2pAM->begin(); v2p_ite != v2pAM->end(); v2p_ite++) {
154  PFCandidateRef pfcand = v2p_ite->key;
155 
156  for (unsigned v_ite = 0; v_ite < (v2p_ite->val).size(); v_ite++) {
157  VertexRef vtxref = (v2p_ite->val)[v_ite].first;
158  int quality = (v2p_ite->val)[v_ite].second;
159 
160  if ((vtxref == firstVertexRef) &&
161  ((quality >= input_MinQuality_) || ((quality < 0) && (quality >= negativeQuality)))) {
162  v2p_firstvertex->push_back(*pfcand);
163  }
164  }
165  }
166 
167  iEvent.put(std::move(v2p_firstvertex), "V2P");
168  }
169 }
170 
171 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
173  //The following says we do not know what parameters are allowed so do no validation
174  // Please change this to state exactly what you do use, even if it is no parameters
176  desc.setUnknown();
177  descriptions.addDefault(desc);
178 }
179 
180 //define this as a plug-in
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< l1t::PFCandidate > PFCandidateCollection
Definition: PFCandidate.h:57
string quality
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
def move
Definition: eostools.py:511
~PFCand_NoPU_WithAM() override
void produce(edm::Event &, const edm::EventSetup &) override
PFCand_NoPU_WithAM(const edm::ParameterSet &)
std::vector< PFCandQualityPair > PFCandQualityPairVector
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
tuple cout
Definition: gather_cfg.py:144
T first(std::pair< T, U > const &p)
tuple size
Write out results.