test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 {
46  //now do what ever other initialization is needed
47 
48  input_AssociationType_ = iConfig.getParameter<InputTag>("AssociationType");
49 
50  token_PFCandToVertexAssMap_ = mayConsume<PFCandToVertexAssMap>(iConfig.getParameter<InputTag>("VertexPFCandAssociationMap"));
51  token_VertexToPFCandAssMap_ = mayConsume<VertexToPFCandAssMap>(iConfig.getParameter<InputTag>("VertexPFCandAssociationMap"));
52 
53  token_VertexCollection_ = mayConsume<VertexCollection>(iConfig.getParameter<InputTag>("VertexCollection"));
54 
55  input_MinQuality_ = iConfig.getParameter<int>("MinQuality");
56 
57  //register your products
58 
59  if ( input_AssociationType_.label() == "PFCandsToVertex" ) {
60  produces<PFCandidateCollection>("P2V");
61  } else {
62  if ( input_AssociationType_.label() == "VertexToPFCands" ) {
63  produces<PFCandidateCollection>("V2P");
64  } else {
65  if ( input_AssociationType_.label() == "Both" ) {
66  produces<PFCandidateCollection>("P2V");
67  produces<PFCandidateCollection>("V2P");
68  } else {
69  cout << "No correct InputTag for AssociationType!" << endl;
70  cout << "Won't produce any PFCandiateCollection!" << endl;
71  }
72  }
73  }
74 
75 }
76 
77 
79 {
80 
81  // do anything here that needs to be done at desctruction time
82  // (e.g. close files, deallocate resources etc.)
83 
84 }
85 
86 //
87 // member functions
88 //
89 
90 // ------------ method called to produce the data ------------
91 void
93 {
94 
95  auto_ptr<PFCandidateCollection> p2v_firstvertex(new PFCandidateCollection() );
96  auto_ptr<PFCandidateCollection> v2p_firstvertex(new PFCandidateCollection() );
97 
98  bool p2vassmap = false;
99  bool v2passmap = false;
100 
101  //get the input vertex<->pf-candidate association map
104 
105  string asstype = input_AssociationType_.label();
106 
107  if ( ( asstype == "PFCandsToVertex" ) || ( asstype == "Both" ) ) {
108  if ( iEvent.getByToken(token_PFCandToVertexAssMap_, p2vAM ) ) {
109  p2vassmap = true;
110  }
111  }
112 
113  if ( ( asstype == "VertexToPFCands" ) || ( asstype == "Both" ) ) {
114  if ( iEvent.getByToken(token_VertexToPFCandAssMap_, v2pAM ) ) {
115  v2passmap = true;
116  }
117  }
118 
119  if ( !p2vassmap && !v2passmap ) {
120  cout << "No input collection could be found" << endl;
121  return;
122  }
123 
124  int negativeQuality = 0;
125  if ( input_MinQuality_ >= 2) {
126  negativeQuality = -1;
127  } else {
128  if ( input_MinQuality_ == 1) {
129  negativeQuality = -2;
130  } else{
131  negativeQuality = -3;
132  }
133  }
134 
135  if ( p2vassmap ){
136 
137  const PFCandQualityPairVector pfccoll = p2vAM->begin()->val;
138 
139  //get the candidates associated to the first vertex and store them in a pf-candidate collection
140  for (unsigned int pfccoll_ite = 0; pfccoll_ite < pfccoll.size(); pfccoll_ite++){
141 
142  PFCandidateRef pfcand = pfccoll[pfccoll_ite].first;
143  int quality = pfccoll[pfccoll_ite].second;
144 
145  if ( (quality>=input_MinQuality_) || ( (quality<0) && (quality>=negativeQuality) ) ) {
146  p2v_firstvertex->push_back(*pfcand);
147 
148  }
149 
150  }
151 
152  iEvent.put( p2v_firstvertex, "P2V" );
153 
154  }
155 
156  if ( v2passmap ) {
157 
158  //get the input vertex collection
159  Handle<VertexCollection> input_vtxcollH;
160  iEvent.getByToken(token_VertexCollection_,input_vtxcollH);
161 
162  VertexRef firstVertexRef(input_vtxcollH,0);
163 
165 
166  for(v2p_ite=v2pAM->begin(); v2p_ite!=v2pAM->end(); v2p_ite++){
167 
168  PFCandidateRef pfcand = v2p_ite->key;
169 
170  for(unsigned v_ite = 0; v_ite<(v2p_ite->val).size(); v_ite++){
171 
172  VertexRef vtxref = (v2p_ite->val)[v_ite].first;
173  int quality = (v2p_ite->val)[v_ite].second;
174 
175  if ( (vtxref==firstVertexRef) && ( (quality>=input_MinQuality_) || ( (quality<0) && (quality>=negativeQuality) ) ) ) {
176  v2p_firstvertex->push_back(*pfcand);
177  }
178 
179  }
180 
181  }
182 
183  iEvent.put( v2p_firstvertex, "V2P" );
184 
185  }
186 }
187 
188 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
189 void
191  //The following says we do not know what parameters are allowed so do no validation
192  // Please change this to state exactly what you do use, even if it is no parameters
194  desc.setUnknown();
195  descriptions.addDefault(desc);
196 }
197 
198 //define this as a plug-in
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
std::vector< PFCandQualityPair > PFCandQualityPairVector
virtual void produce(edm::Event &, const edm::EventSetup &)
PFCand_NoPU_WithAM(const edm::ParameterSet &)
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
tuple cout
Definition: gather_cfg.py:145
T first(std::pair< T, U > const &p)
tuple size
Write out results.