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