ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Betchart/TopRefTuple/interface/Tuple_MET.h
Revision: 1.2
Committed: Tue Nov 13 23:57:42 2012 UTC (12 years, 5 months ago) by bbetchar
Content type: text/plain
Branch: MAIN
CVS Tags: V00-03-02, V00-03-01, V00-02-02, V00-02-01, V00-02-00, V00-01-05, V00-01-04, V00-01-03, V00-01-02, V00-01-01, V00-01-00, HEAD
Changes since 1.1: +37 -117 lines
Log Message:
revise MET

File Contents

# User Rev Content
1 bbetchar 1.1 #ifndef TUPLE_MET
2     #define TUPLE_MET
3    
4 bbetchar 1.2 #include "TopQuarkAnalysis/TopRefTuple/interface/fTypes.h"
5 bbetchar 1.1 #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 bbetchar 1.2 #include "DataFormats/Candidate/interface/Candidate.h"
13 bbetchar 1.1
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 bbetchar 1.2 const edm::InputTag metTag,particlesTag;
21     const std::string prefix,particlesPrefix;
22 bbetchar 1.1 };
23    
24     template< typename T >
25 bbetchar 1.2 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 bbetchar 1.1 {
31 bbetchar 1.2 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 bbetchar 1.1 }
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 bbetchar 1.2 event.getByLabel(metTag, metcollection);
46 bbetchar 1.1
47     const T* met = metcollection.isValid() ? &(metcollection->at(0)) : 0;
48 bbetchar 1.2 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 bbetchar 1.1 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 bbetchar 1.2 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 bbetchar 1.1 }
76    
77     #endif