1 |
bbetchar |
1.1 |
#ifndef TUPLE_MET
|
2 |
|
|
#define TUPLE_MET
|
3 |
|
|
|
4 |
|
|
#include "FWCore/Framework/interface/EDProducer.h"
|
5 |
|
|
#include "FWCore/Framework/interface/Frameworkfwd.h"
|
6 |
|
|
#include "FWCore/Framework/interface/Event.h"
|
7 |
|
|
#include "FWCore/Framework/interface/ESHandle.h"
|
8 |
|
|
#include "FWCore/Utilities/interface/InputTag.h"
|
9 |
|
|
|
10 |
|
|
#include "DataFormats/METReco/interface/PFMET.h"
|
11 |
|
|
#include "DataFormats/METReco/interface/CaloMET.h"
|
12 |
|
|
#include "DataFormats/PatCandidates/interface/MET.h"
|
13 |
|
|
|
14 |
|
|
template< typename T >
|
15 |
|
|
class Tuple_MET : public edm::EDProducer {
|
16 |
|
|
public:
|
17 |
|
|
explicit Tuple_MET(const edm::ParameterSet&);
|
18 |
|
|
private:
|
19 |
|
|
void produce(edm::Event&, const edm::EventSetup& );
|
20 |
|
|
void produceSpecial(edm::Event&, const T* );
|
21 |
|
|
void produceCalo(edm::Event&, const T* );
|
22 |
|
|
void initSpecial();
|
23 |
|
|
void initCalo();
|
24 |
|
|
const edm::InputTag inputTag;
|
25 |
|
|
const bool special, caloSpecific;
|
26 |
|
|
const std::string Prefix,Suffix;
|
27 |
|
|
};
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
template< typename T >
|
31 |
|
|
Tuple_MET<T>::Tuple_MET(const edm::ParameterSet& cfg) :
|
32 |
|
|
inputTag(cfg.getParameter<edm::InputTag>("InputTag")),
|
33 |
|
|
special(cfg.getParameter<bool>("ProduceSpecial")),
|
34 |
|
|
caloSpecific(cfg.getParameter<bool>("Calo")),
|
35 |
|
|
Prefix(cfg.getParameter<std::string>("Prefix")),
|
36 |
|
|
Suffix(cfg.getParameter<std::string>("Suffix"))
|
37 |
|
|
{
|
38 |
|
|
produces <reco::Candidate::LorentzVector> ( Prefix + "P4" + Suffix );
|
39 |
|
|
produces <double> ( Prefix + "SumEt" + Suffix );
|
40 |
|
|
produces <bool> ( Prefix + "HandleValid" + Suffix );
|
41 |
|
|
produces <double> ( Prefix + "Significance" + Suffix );
|
42 |
|
|
produces <double> ( Prefix + "SigmaXX" + Suffix );
|
43 |
|
|
produces <double> ( Prefix + "SigmaYY" + Suffix );
|
44 |
|
|
produces <double> ( Prefix + "SigmaXY" + Suffix );
|
45 |
|
|
if(special) initSpecial();
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
template< typename T >
|
49 |
|
|
void Tuple_MET<T>::
|
50 |
|
|
produce(edm::Event& event, const edm::EventSetup& setup) {
|
51 |
|
|
edm::Handle<std::vector<T> > metcollection;
|
52 |
|
|
event.getByLabel(inputTag, metcollection);
|
53 |
|
|
|
54 |
|
|
const T* met = metcollection.isValid() ? &(metcollection->at(0)) : 0;
|
55 |
|
|
event.put(std::auto_ptr<bool>(new bool(met)), Prefix + "HandleValid" + Suffix);
|
56 |
|
|
event.put(std::auto_ptr<double>( new double( met ? met->sumEt() : 0 )), Prefix + "SumEt" +Suffix);
|
57 |
|
|
event.put(std::auto_ptr<reco::Candidate::LorentzVector>( met ?
|
58 |
|
|
new reco::Candidate::LorentzVector(met->p4() ) :
|
59 |
|
|
new reco::Candidate::LorentzVector(0,0,0,0)), Prefix+"P4"+Suffix);
|
60 |
|
|
double significance(0), sigmaXX(0), sigmaYY(0), sigmaXY(0);
|
61 |
|
|
try {
|
62 |
|
|
significance = !met ? 0 : met->significance();
|
63 |
|
|
if(significance) {
|
64 |
|
|
TMatrixD M = met->getSignificanceMatrix();
|
65 |
|
|
sigmaXX = M(0,0); sigmaXY = M(0,1); sigmaYY = M(1,1);
|
66 |
|
|
}
|
67 |
|
|
}
|
68 |
|
|
catch(...) { significance = -1; }
|
69 |
|
|
event.put(std::auto_ptr<double>( new double(significance)), Prefix+"Significance" +Suffix);
|
70 |
|
|
event.put(std::auto_ptr<double>( new double(sigmaXX)), Prefix+"SigmaXX" +Suffix);
|
71 |
|
|
event.put(std::auto_ptr<double>( new double(sigmaYY)), Prefix+"SigmaYY" +Suffix);
|
72 |
|
|
event.put(std::auto_ptr<double>( new double(sigmaXY)), Prefix+"SigmaXY" +Suffix);
|
73 |
|
|
|
74 |
|
|
if(special) produceSpecial(event, met);
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
template<> void Tuple_MET<reco::GenMET>::initSpecial() { }
|
78 |
|
|
template<> void Tuple_MET<reco::CaloMET>::initSpecial() { initCalo(); }
|
79 |
|
|
template<> void Tuple_MET<pat::MET>::initSpecial() { initCalo();}
|
80 |
|
|
|
81 |
|
|
template<> void Tuple_MET<reco::GenMET>::produceSpecial(edm::Event& event, const reco::GenMET* met) { }
|
82 |
|
|
template<> void Tuple_MET<reco::CaloMET>::produceSpecial(edm::Event& event, const reco::CaloMET* met) { produceCalo(event,met);}
|
83 |
|
|
template<> void Tuple_MET<pat::MET>::produceSpecial(edm::Event& event, const pat::MET* met) { produceCalo(event,met);}
|
84 |
|
|
|
85 |
|
|
template<> void Tuple_MET<reco::PFMET>::initSpecial() {
|
86 |
|
|
produces<double>( Prefix+ "PhotonEtFraction" + Suffix);
|
87 |
|
|
produces<double>( Prefix+ "ElectronEtFraction" + Suffix);
|
88 |
|
|
produces<double>( Prefix+ "NeutralHadronEtFraction" + Suffix);
|
89 |
|
|
produces<double>( Prefix+ "ChargedHadronEtFraction" + Suffix);
|
90 |
|
|
produces<double>( Prefix+ "MuonEtFraction" + Suffix);
|
91 |
|
|
produces<double>( Prefix+ "HFHadronEtFraction" + Suffix);
|
92 |
|
|
produces<double>( Prefix+ "HFEMEtFraction" + Suffix);
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
template<> void Tuple_MET<reco::PFMET>::produceSpecial(edm::Event& event, const reco::PFMET* met) {
|
96 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->photonEtFraction() )), Prefix + "PhotonEtFraction" + Suffix);
|
97 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->electronEtFraction() )), Prefix + "ElectronEtFraction" + Suffix);
|
98 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->neutralHadronEtFraction() )), Prefix + "NeutralHadronEtFraction" + Suffix);
|
99 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->chargedHadronEtFraction() )), Prefix + "ChargedHadronEtFraction" + Suffix);
|
100 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->muonEtFraction() )), Prefix + "MuonEtFraction" + Suffix);
|
101 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->HFHadronEtFraction() )), Prefix + "HFHadronEtFraction" + Suffix);
|
102 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->HFEMEtFraction() )), Prefix + "HFEMEtFraction" + Suffix);
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
template<class T>
|
107 |
|
|
void Tuple_MET<T>::
|
108 |
|
|
initCalo() {
|
109 |
|
|
if(!caloSpecific) return;
|
110 |
|
|
produces <double> ( Prefix + "CaloMETInmHF" + Suffix );
|
111 |
|
|
produces <double> ( Prefix + "CaloMETInpHF" + Suffix );
|
112 |
|
|
produces <double> ( Prefix + "CaloMETPhiInmHF" + Suffix );
|
113 |
|
|
produces <double> ( Prefix + "CaloMETPhiInpHF" + Suffix );
|
114 |
|
|
produces <double> ( Prefix + "CaloSETInmHF" + Suffix );
|
115 |
|
|
produces <double> ( Prefix + "CaloSETInpHF" + Suffix );
|
116 |
|
|
|
117 |
|
|
produces <double> ( Prefix + "EmEtFraction" + Suffix );
|
118 |
|
|
produces <double> ( Prefix + "EtFractionHadronic" + Suffix );
|
119 |
|
|
produces <double> ( Prefix + "MaxEtInEmTowers" + Suffix );
|
120 |
|
|
produces <double> ( Prefix + "MaxEtInHadTowers" + Suffix );
|
121 |
|
|
produces <double> ( Prefix + "EmEtInEB" + Suffix );
|
122 |
|
|
produces <double> ( Prefix + "EmEtInEE" + Suffix );
|
123 |
|
|
produces <double> ( Prefix + "EmEtInHF" + Suffix );
|
124 |
|
|
produces <double> ( Prefix + "HadEtInHB" + Suffix );
|
125 |
|
|
produces <double> ( Prefix + "HadEtInHE" + Suffix );
|
126 |
|
|
produces <double> ( Prefix + "HadEtInHF" + Suffix );
|
127 |
|
|
produces <double> ( Prefix + "HadEtInHO" + Suffix );
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
template< typename T>
|
131 |
|
|
void Tuple_MET<T>::
|
132 |
|
|
produceCalo(edm::Event& event, const T* met) {
|
133 |
|
|
if(!caloSpecific) return;
|
134 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->CaloMETInmHF())), Prefix+"CaloMETInmHF"+Suffix);
|
135 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->CaloMETInpHF())), Prefix+"CaloMETInpHF"+Suffix);
|
136 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->CaloMETPhiInmHF())), Prefix+"CaloMETPhiInmHF"+Suffix);
|
137 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->CaloMETPhiInpHF())), Prefix+"CaloMETPhiInpHF"+Suffix);
|
138 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->CaloSETInmHF())), Prefix+"CaloSETInmHF"+Suffix);
|
139 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->CaloSETInpHF())), Prefix+"CaloSETInpHF"+Suffix);
|
140 |
|
|
|
141 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->emEtFraction())), Prefix+"EmEtFraction"+Suffix);
|
142 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->etFractionHadronic())), Prefix+"EtFractionHadronic"+Suffix);
|
143 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->maxEtInEmTowers())), Prefix+"MaxEtInEmTowers"+Suffix);
|
144 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->maxEtInHadTowers())), Prefix+"MaxEtInHadTowers"+Suffix);
|
145 |
|
|
|
146 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->emEtInEB())), Prefix+"EmEtInEB"+Suffix);
|
147 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->emEtInEE())), Prefix+"EmEtInEE"+Suffix);
|
148 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->emEtInHF())), Prefix+"EmEtInHF"+Suffix);
|
149 |
|
|
|
150 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->hadEtInHB())), Prefix+"HadEtInHB"+Suffix);
|
151 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->hadEtInHE())), Prefix+"HadEtInHE"+Suffix);
|
152 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->hadEtInHF())), Prefix+"HadEtInHF"+Suffix);
|
153 |
|
|
event.put( std::auto_ptr<double>( new double(!met ? 0 : met->hadEtInHF())), Prefix+"HadEtInHO"+Suffix);
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
#endif
|