Go to the documentation of this file.00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <memory>
00022 #include <string>
00023
00024
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDFilter.h"
00027
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 #include "FWCore/Framework/interface/ESHandle.h"
00031 #include "FWCore/Framework/interface/ESWatcher.h"
00032
00033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00034
00035 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00036
00037 #include "FWCore/Utilities/interface/InputTag.h"
00038
00039 #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
00040 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00041 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
00042
00043 #include "Validation/RecoVertex/interface/VertexWeighter.h"
00044
00045
00046
00047
00048
00049 class MCVerticesWeight : public edm::EDFilter {
00050 public:
00051 explicit MCVerticesWeight(const edm::ParameterSet&);
00052 ~MCVerticesWeight();
00053
00054 private:
00055 virtual void beginJob() ;
00056 virtual bool filter(edm::Event&, const edm::EventSetup&);
00057 virtual void endJob() ;
00058
00059
00060
00061 edm::InputTag m_pileupcollection;
00062 edm::InputTag m_mctruthcollection;
00063 const VertexWeighter m_weighter;
00064
00065 };
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 MCVerticesWeight::MCVerticesWeight(const edm::ParameterSet& iConfig):
00079 m_pileupcollection(iConfig.getParameter<edm::InputTag>("pileupSummaryCollection")),
00080 m_mctruthcollection(iConfig.getParameter<edm::InputTag>("mcTruthCollection")),
00081 m_weighter(iConfig.getParameter<edm::ParameterSet>("weighterConfig"))
00082 {
00083
00084 produces<double>();
00085
00086 }
00087
00088 MCVerticesWeight::~MCVerticesWeight()
00089 {
00090
00091
00092
00093
00094 }
00095
00096
00097
00098
00099
00100
00101
00102 bool
00103 MCVerticesWeight::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00104 {
00105 using namespace edm;
00106
00107 bool selected = true;
00108
00109 double computed_weight(1);
00110
00111 Handle<std::vector<PileupSummaryInfo> > pileupinfos;
00112 iEvent.getByLabel(m_pileupcollection,pileupinfos);
00113
00114
00115
00116
00117 std::vector<PileupSummaryInfo>::const_iterator pileupinfo;
00118 for(pileupinfo = pileupinfos->begin(); pileupinfo != pileupinfos->end() ; ++pileupinfo) {
00119 if(pileupinfo->getBunchCrossing()==0) break;
00120 }
00121
00122
00123 if(pileupinfo->getBunchCrossing()!=0) {
00124 edm::LogError("NoInTimePileUpInfo") << "Cannot find the in-time pileup info " << pileupinfo->getBunchCrossing();
00125 }
00126 else {
00127
00128
00129
00130 const std::vector<float>& zpositions = pileupinfo->getPU_zpositions();
00131
00132
00133
00134
00135
00136
00137
00138 Handle< HepMCProduct > EvtHandle ;
00139 iEvent.getByLabel(m_mctruthcollection, EvtHandle ) ;
00140
00141 const HepMC::GenEvent* Evt = EvtHandle->GetEvent();
00142
00143
00144
00145 double zmain = 0.0;
00146 if(Evt->vertices_begin() != Evt->vertices_end()) {
00147 zmain = (*Evt->vertices_begin())->point3d().z()/10.;
00148 }
00149
00150
00151
00152
00153 computed_weight = m_weighter.weight(zpositions,zmain);
00154
00155 }
00156
00157 std::auto_ptr<double> weight(new double(computed_weight));
00158
00159 iEvent.put(weight);
00160
00161
00162
00163 return selected;
00164 }
00165
00166
00167 void
00168 MCVerticesWeight::beginJob()
00169 {
00170 }
00171
00172
00173 void
00174 MCVerticesWeight::endJob() {
00175 }
00176
00177
00178 DEFINE_FWK_MODULE(MCVerticesWeight);