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_vecPileupSummaryInfoToken( consumes< std::vector<PileupSummaryInfo> >( iConfig.getParameter< edm::InputTag >( "pileupSummaryCollection" ) ) )
80  , m_hepMCProductToken( consumes< edm::HepMCProduct >( 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 
106  bool selected = true;
107 
108  double computed_weight(1);
109 
111  iEvent.getByToken( m_vecPileupSummaryInfoToken, pileupinfos );
112 
113 
114  // look for the intime PileupSummaryInfo
115 
116  std::vector<PileupSummaryInfo>::const_iterator pileupinfo;
117  for(pileupinfo = pileupinfos->begin(); pileupinfo != pileupinfos->end() ; ++pileupinfo) {
118  if(pileupinfo->getBunchCrossing()==0) break;
119  }
120 
121  //
122  if(pileupinfo->getBunchCrossing()!=0) {
123  edm::LogError("NoInTimePileUpInfo") << "Cannot find the in-time pileup info " << pileupinfo->getBunchCrossing();
124  }
125  else {
126 
127  // pileupinfo->getPU_NumInteractions();
128 
129  const std::vector<float>& zpositions = pileupinfo->getPU_zpositions();
130 
131  // for(std::vector<float>::const_iterator zpos = zpositions.begin() ; zpos != zpositions.end() ; ++zpos) {
132 
133  // }
134 
135  // main interaction part
136 
138  iEvent.getByToken( m_hepMCProductToken, EvtHandle );
139 
140  const HepMC::GenEvent* Evt = EvtHandle->GetEvent();
141 
142  // get the first vertex
143 
144  double zmain = 0.0;
145  if(Evt->vertices_begin() != Evt->vertices_end()) {
146  zmain = (*Evt->vertices_begin())->point3d().z()/10.;
147  }
148 
149  //
150 
151 
152  computed_weight = m_weighter.weight(zpositions,zmain);
153 
154  }
155 
156  std::auto_ptr<double> weight(new double(computed_weight));
157 
158  iEvent.put(weight);
159 
160  //
161 
162  return selected;
163 }
164 
165 // ------------ method called once each job just before starting event loop ------------
166 void
168 {
169 }
170 
171 // ------------ method called once each job just after ending the event loop ------------
172 void
174 }
175 
176 //define this as a plug-in
virtual void beginJob()
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void endJob()
MCVerticesWeight(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
virtual bool filter(edm::Event &, const edm::EventSetup &)
const VertexWeighter m_weighter
edm::EDGetTokenT< edm::HepMCProduct > m_hepMCProductToken
int weight
Definition: histoStyle.py:50
const double weight(const std::vector< float > &zpositions, const float &zmain) const
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > m_vecPileupSummaryInfoToken