1 |
#ifndef TUPLE_MET
|
2 |
#define TUPLE_MET
|
3 |
|
4 |
#include "TopQuarkAnalysis/TopRefTuple/interface/fTypes.h"
|
5 |
#include "FWCore/Framework/interface/EDProducer.h"
|
6 |
#include "FWCore/Framework/interface/Frameworkfwd.h"
|
7 |
#include "FWCore/Framework/interface/Event.h"
|
8 |
#include "FWCore/Framework/interface/ESHandle.h"
|
9 |
#include "FWCore/Utilities/interface/InputTag.h"
|
10 |
|
11 |
#include "DataFormats/PatCandidates/interface/MET.h"
|
12 |
#include "DataFormats/Candidate/interface/Candidate.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 |
const edm::InputTag metTag,particlesTag;
|
21 |
const std::string prefix,particlesPrefix;
|
22 |
};
|
23 |
|
24 |
template< typename T >
|
25 |
Tuple_MET<T>::Tuple_MET(const edm::ParameterSet& cfg)
|
26 |
: metTag(cfg.getParameter<edm::InputTag>("metTag"))
|
27 |
, particlesTag(cfg.getParameter<edm::InputTag>("particlesTag"))
|
28 |
, prefix(cfg.getParameter<std::string>("prefix"))
|
29 |
, particlesPrefix(cfg.getParameter<std::string>("particlesPrefix"))
|
30 |
{
|
31 |
produces <fTypes::dPolarLorentzV> ( prefix + "P4" );
|
32 |
produces <fTypes::dPolarLorentzV> ( particlesPrefix + "SumP4" );
|
33 |
produces <float> ( prefix + "SumEt" );
|
34 |
produces <bool> ( prefix + "HandleValid" );
|
35 |
produces <float> ( prefix + "Significance" );
|
36 |
produces <float> ( prefix + "SigmaXX" );
|
37 |
produces <float> ( prefix + "SigmaYY" );
|
38 |
produces <float> ( prefix + "SigmaXY" );
|
39 |
}
|
40 |
|
41 |
template< typename T >
|
42 |
void Tuple_MET<T>::
|
43 |
produce(edm::Event& event, const edm::EventSetup& setup) {
|
44 |
edm::Handle<std::vector<T> > metcollection;
|
45 |
event.getByLabel(metTag, metcollection);
|
46 |
|
47 |
const T* met = metcollection.isValid() ? &(metcollection->at(0)) : 0;
|
48 |
event.put(std::auto_ptr<bool>(new bool(met)), prefix + "HandleValid" );
|
49 |
event.put(std::auto_ptr<float>( new float( met ? met->sumEt() : 0 )), prefix + "SumEt");
|
50 |
event.put(std::auto_ptr<fTypes::dPolarLorentzV>( met ?
|
51 |
new fTypes::dPolarLorentzV(met->p4().pt(), met->p4().eta(), met->p4().phi(), met->p4().mass() ) :
|
52 |
new fTypes::dPolarLorentzV(0,0,0,0)), prefix+"P4");
|
53 |
float significance(0), sigmaXX(0), sigmaYY(0), sigmaXY(0);
|
54 |
try {
|
55 |
significance = !met ? 0 : met->significance();
|
56 |
if(significance) {
|
57 |
TMatrixD M = met->getSignificanceMatrix();
|
58 |
sigmaXX = M(0,0); sigmaXY = M(0,1); sigmaYY = M(1,1);
|
59 |
}
|
60 |
}
|
61 |
catch(...) { significance = -1; }
|
62 |
event.put(std::auto_ptr<float>( new float(significance)), prefix+"Significance");
|
63 |
event.put(std::auto_ptr<float>( new float(sigmaXX)), prefix+"SigmaXX" );
|
64 |
event.put(std::auto_ptr<float>( new float(sigmaYY)), prefix+"SigmaYY" );
|
65 |
event.put(std::auto_ptr<float>( new float(sigmaXY)), prefix+"SigmaXY" );
|
66 |
|
67 |
reco::Candidate::LorentzVector sumP4(0,0,0,0);
|
68 |
if( met ) {
|
69 |
edm::Handle<edm::View<reco::Candidate> > candidates;
|
70 |
event.getByLabel(particlesTag,candidates);
|
71 |
for(edm::View<reco::Candidate>::const_iterator it = candidates->begin(); it != candidates->end() ; ++it)
|
72 |
sumP4 += it->p4();
|
73 |
}
|
74 |
event.put(std::auto_ptr<fTypes::dPolarLorentzV>( new fTypes::dPolarLorentzV(sumP4.pt(), sumP4.eta(), sumP4.phi(), sumP4.mass()) ), particlesPrefix+"SumP4");
|
75 |
}
|
76 |
|
77 |
#endif
|