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