CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MCVerticesWeight.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PileUp
4 // Class: MCVerticesWeight
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Tue Oct 21 20:55:22 CEST 2008
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 #include <string>
23 
24 // user include files
27 
32 
34 
36 
38 
42 
44 
45 //
46 // class declaration
47 //
48 
50  public:
51  explicit MCVerticesWeight(const edm::ParameterSet&);
53 
54  private:
55  virtual void beginJob() ;
56  virtual bool filter(edm::Event&, const edm::EventSetup&);
57  virtual void endJob() ;
58 
59  // ----------member data ---------------------------
60 
64 
65 };
66 
67 //
68 // constants, enums and typedefs
69 //
70 
71 //
72 // static data member definitions
73 //
74 
75 //
76 // constructors and destructor
77 //
79  m_pileupcollection(iConfig.getParameter<edm::InputTag>("pileupSummaryCollection")),
80  m_mctruthcollection(iConfig.getParameter<edm::InputTag>("mcTruthCollection")),
81  m_weighter(iConfig.getParameter<edm::ParameterSet>("weighterConfig"))
82 {
83 
84  produces<double>();
85 
86 }
87 
89 {
90 
91  // do anything here that needs to be done at desctruction time
92  // (e.g. close files, deallocate resources etc.)
93 
94 }
95 
96 
97 //
98 // member functions
99 //
100 
101 // ------------ method called on each new Event ------------
102 bool
104 {
105  using namespace edm;
106 
107  bool selected = true;
108 
109  double computed_weight(1);
110 
112  iEvent.getByLabel(m_pileupcollection,pileupinfos);
113 
114 
115  // look for the intime PileupSummaryInfo
116 
117  std::vector<PileupSummaryInfo>::const_iterator pileupinfo;
118  for(pileupinfo = pileupinfos->begin(); pileupinfo != pileupinfos->end() ; ++pileupinfo) {
119  if(pileupinfo->getBunchCrossing()==0) break;
120  }
121 
122  //
123  if(pileupinfo->getBunchCrossing()!=0) {
124  edm::LogError("NoInTimePileUpInfo") << "Cannot find the in-time pileup info " << pileupinfo->getBunchCrossing();
125  }
126  else {
127 
128  // pileupinfo->getPU_NumInteractions();
129 
130  const std::vector<float>& zpositions = pileupinfo->getPU_zpositions();
131 
132  // for(std::vector<float>::const_iterator zpos = zpositions.begin() ; zpos != zpositions.end() ; ++zpos) {
133 
134  // }
135 
136  // main interaction part
137 
138  Handle< HepMCProduct > EvtHandle ;
139  iEvent.getByLabel(m_mctruthcollection, EvtHandle ) ;
140 
141  const HepMC::GenEvent* Evt = EvtHandle->GetEvent();
142 
143  // get the first vertex
144 
145  double zmain = 0.0;
146  if(Evt->vertices_begin() != Evt->vertices_end()) {
147  zmain = (*Evt->vertices_begin())->point3d().z()/10.;
148  }
149 
150  //
151 
152 
153  computed_weight = m_weighter.weight(zpositions,zmain);
154 
155  }
156 
157  std::auto_ptr<double> weight(new double(computed_weight));
158 
159  iEvent.put(weight);
160 
161  //
162 
163  return selected;
164 }
165 
166 // ------------ method called once each job just before starting event loop ------------
167 void
169 {
170 }
171 
172 // ------------ method called once each job just after ending the event loop ------------
173 void
175 }
176 
177 //define this as a plug-in
virtual void beginJob()
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void endJob()
edm::InputTag m_mctruthcollection
MCVerticesWeight(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
virtual bool filter(edm::Event &, const edm::EventSetup &)
edm::InputTag m_pileupcollection
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
const VertexWeighter m_weighter
int weight
Definition: histoStyle.py:50
const double weight(const std::vector< float > &zpositions, const float &zmain) const