CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MultShiftMETcorrInputProducer.cc
Go to the documentation of this file.
2 
4 
9 
10 #include <TString.h>
11 
13  switch( type ) {
14  case reco::PFCandidate::ParticleType::h: return 211; // pi+
15  case reco::PFCandidate::ParticleType::e: return 11;
17  case reco::PFCandidate::ParticleType::gamma: return 22;
18  case reco::PFCandidate::ParticleType::h0: return 130; // K_L0
19  case reco::PFCandidate::ParticleType::h_HF: return 1; // dummy pdg code
20  case reco::PFCandidate::ParticleType::egamma_HF: return 2; // dummy pdg code
22  default: return 0;
23  }
24 }
25 
26 
28  moduleLabel_(cfg.getParameter<std::string>("@module_label"))
29 {
30 
31  pflow_ = consumes<edm::View<reco::Candidate> >(cfg.getParameter< edm::InputTag >("srcPFlow") );
32  vertices_ = consumes<edm::View<reco::Vertex> >( cfg.getParameter< edm::InputTag >("vertexCollection") );
33 
34  cfgCorrParameters_ = cfg.getParameter<std::vector<edm::ParameterSet> >("parameters");
35  etaMin_.clear();
36  etaMax_.clear();
37  type_.clear();
38  varType_.clear();
39 
40  produces<CorrMETData>();
41 
42  for (std::vector<edm::ParameterSet>::const_iterator v = cfgCorrParameters_.begin(); v!=cfgCorrParameters_.end(); v++) {
43  TString corrPxFormula = v->getParameter<std::string>("fx");
44  TString corrPyFormula = v->getParameter<std::string>("fy");
45  std::vector<double> corrPxParams = v->getParameter<std::vector<double> >("px");
46  std::vector<double> corrPyParams = v->getParameter<std::vector<double> >("py");
47 
48  formula_x_.push_back( std::unique_ptr<TF1>(new TF1(std::string(moduleLabel_).append("_").append(v->getParameter<std::string>("name")).append("_corrPx").c_str(), v->getParameter<std::string>("fx").c_str()) ) );
49  formula_y_.push_back( std::unique_ptr<TF1>(new TF1(std::string(moduleLabel_).append("_").append(v->getParameter<std::string>("name")).append("_corrPy").c_str(), v->getParameter<std::string>("fy").c_str()) ) );
50 
51  for (unsigned i=0; i<corrPxParams.size();i++) formula_x_.back()->SetParameter(i, corrPxParams[i]);
52  for (unsigned i=0; i<corrPyParams.size();i++) formula_y_.back()->SetParameter(i, corrPyParams[i]);
53 
54  counts_.push_back(0);
55  sumPt_.push_back(0.);
56  etaMin_.push_back(v->getParameter<double>("etaMin"));
57  etaMax_.push_back(v->getParameter<double>("etaMax"));
58  type_.push_back(v->getParameter<int>("type"));
59  varType_.push_back(v->getParameter<int>("varType"));
60  }
61 }
62 
64 {
65 }
66 
68 {
69  //get primary vertices
71  evt.getByToken( vertices_, hpv );
72  if(!hpv.isValid()) {
73  edm::LogError("MultShiftMETcorrInputProducer::produce") << "could not find vertex collection ";
74  }
75  std::vector<reco::Vertex> goodVertices;
76  for (unsigned i = 0; i < hpv->size(); i++) {
77  if ( (*hpv)[i].ndof() > 4 &&
78  ( fabs((*hpv)[i].z()) <= 24. ) &&
79  ( fabs((*hpv)[i].position().rho()) <= 2.0 ) )
80  goodVertices.push_back((*hpv)[i]);
81  }
82  int ngoodVertices = goodVertices.size();
83 
84  for (unsigned i=0;i<counts_.size();i++) counts_[i]=0;
85  for (unsigned i=0;i<sumPt_.size();i++) sumPt_[i]=0.;
86 
88  evt.getByToken(pflow_, particleFlow);
89  for (unsigned i = 0; i < particleFlow->size(); ++i) {
90  const reco::Candidate& c = particleFlow->at(i);
91  for (unsigned j=0; j<type_.size(); j++) {
92 
94  if ((c.eta()>etaMin_[j]) and (c.eta()<etaMax_[j])) {
95  counts_[j]+=1;
96  sumPt_[j]+=c.pt();
97  continue;
98  }
99  }
100  }
101  }
102 
103  //MM: loop over all constituent types and sum each correction
104  std::auto_ptr<CorrMETData> metCorr(new CorrMETData());
105 
106  double corx=0.;
107  double cory=0.;
108 
109  for (std::vector<edm::ParameterSet>::const_iterator v = cfgCorrParameters_.begin(); v!=cfgCorrParameters_.end(); v++) {
110  unsigned j=v-cfgCorrParameters_.begin();
111 
112  double val(0.);
113  if (varType_[j]==0) {
114  val = counts_[j];
115  }
116  if (varType_[j]==1) {
117  val = ngoodVertices;
118  }
119  if (varType_[j]==2) {
120  val = sumPt_[j];
121  }
122 
123  corx -= formula_x_[j]->Eval(val);
124  cory -= formula_y_[j]->Eval(val);
125 
126  } //end loop over corrections
127 
128  metCorr->mex = corx;
129  metCorr->mey = cory;
130  evt.put(metCorr, "");
131 
132 }
133 
135 
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
edm::EDGetTokenT< edm::View< reco::Vertex > > vertices_
ParticleType
particle types
Definition: PFCandidate.h:44
tuple cfg
Definition: looper.py:293
std::vector< edm::ParameterSet > cfgCorrParameters_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
virtual double pt() const =0
transverse momentum
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
#define X(str)
Definition: MuonsGrabber.cc:48
tuple particleFlow
Definition: pfLinker_cff.py:5
static int translateTypeToAbsPdgId(reco::PFCandidate::ParticleType type)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
const int mu
Definition: Constants.h:22
tuple goodVertices
The Good vertices collection needed by the tracking failure filter ________||.
bool isValid() const
Definition: HandleBase.h:75
virtual int pdgId() const =0
PDG identifier.
void produce(edm::Event &, const edm::EventSetup &) override
MultShiftMETcorrInputProducer(const edm::ParameterSet &)
a MET correction term
Definition: CorrMETData.h:14
static int position[264][3]
Definition: ReadPGInfo.cc:509
std::vector< std::unique_ptr< TF1 > > formula_x_
moduleLabel_(iConfig.getParameter< string >("@module_label"))
std::vector< std::unique_ptr< TF1 > > formula_y_
virtual double eta() const =0
momentum pseudorapidity
edm::EDGetTokenT< edm::View< reco::Candidate > > pflow_