test
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 bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
56 
57  // ----------member data ---------------------------
58 
62 
63 };
64 
65 //
66 // constructors and destructor
67 //
69  : m_vecPileupSummaryInfoToken( consumes< std::vector<PileupSummaryInfo> >( iConfig.getParameter< edm::InputTag >( "pileupSummaryCollection" ) ) )
70  , m_hepMCProductToken( consumes< edm::HepMCProduct >( iConfig.getParameter< edm::InputTag >( "mcTruthCollection" ) ) )
71  , m_weighter( iConfig.getParameter<edm::ParameterSet>( "weighterConfig" ) )
72 {
73 
74  produces<double>();
75 
76 }
77 
79 {
80 }
81 
82 
83 //
84 // member functions
85 //
86 
87 // ------------ method called on each new Event ------------
88 bool
90 {
91 
92  bool selected = true;
93 
94  double computed_weight(1);
95 
97  iEvent.getByToken( m_vecPileupSummaryInfoToken, pileupinfos );
98 
99 
100  // look for the intime PileupSummaryInfo
101 
102  std::vector<PileupSummaryInfo>::const_iterator pileupinfo;
103  for(pileupinfo = pileupinfos->begin(); pileupinfo != pileupinfos->end() ; ++pileupinfo) {
104  if(pileupinfo->getBunchCrossing()==0) break;
105  }
106 
107  //
108  if(pileupinfo->getBunchCrossing()!=0) {
109  edm::LogError("NoInTimePileUpInfo") << "Cannot find the in-time pileup info " << pileupinfo->getBunchCrossing();
110  }
111  else {
112 
113  // pileupinfo->getPU_NumInteractions();
114 
115  const std::vector<float>& zpositions = pileupinfo->getPU_zpositions();
116 
117  // for(std::vector<float>::const_iterator zpos = zpositions.begin() ; zpos != zpositions.end() ; ++zpos) {
118 
119  // }
120 
121  // main interaction part
122 
124  iEvent.getByToken( m_hepMCProductToken, EvtHandle );
125 
126  const HepMC::GenEvent* Evt = EvtHandle->GetEvent();
127 
128  // get the first vertex
129 
130  double zmain = 0.0;
131  if(Evt->vertices_begin() != Evt->vertices_end()) {
132  zmain = (*Evt->vertices_begin())->point3d().z()/10.;
133  }
134 
135  //
136 
137 
138  computed_weight = m_weighter.weight(zpositions,zmain);
139 
140  }
141 
142  std::auto_ptr<double> weight(new double(computed_weight));
143 
144  iEvent.put(weight);
145 
146  //
147 
148  return selected;
149 }
150 
151 //define this as a plug-in
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
MCVerticesWeight(const edm::ParameterSet &)
virtual bool filter(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
const VertexWeighter m_weighter
edm::EDGetTokenT< edm::HepMCProduct > m_hepMCProductToken
const double weight(const std::vector< float > &zpositions, const float &zmain) const
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > m_vecPileupSummaryInfoToken