1 |
// $Id: FillerPFMet.cc,v 1.7 2011/10/03 16:15:50 ksung Exp $
|
2 |
|
3 |
#include "MitProd/TreeFiller/interface/FillerPFMet.h"
|
4 |
#include "DataFormats/METReco/interface/PFMET.h"
|
5 |
#include "DataFormats/METReco/interface/PFMETCollection.h"
|
6 |
#include "MitAna/DataTree/interface/Names.h"
|
7 |
#include "MitAna/DataTree/interface/PFMetCol.h"
|
8 |
#include "MitProd/ObjectService/interface/ObjectService.h"
|
9 |
|
10 |
using namespace std;
|
11 |
using namespace edm;
|
12 |
using namespace mithep;
|
13 |
|
14 |
//--------------------------------------------------------------------------------------------------
|
15 |
FillerPFMet::FillerPFMet(const ParameterSet &cfg, const char *name, bool active) :
|
16 |
BaseFiller(cfg,name,active),
|
17 |
edmName_(Conf().getUntrackedParameter<edm::InputTag>("edmName")),
|
18 |
mitName_(Conf().getUntrackedParameter<string>("mitName",Names::gkCaloMetBrn)),
|
19 |
pfMets_(new mithep::PFMetArr)
|
20 |
{
|
21 |
// Constructor.
|
22 |
}
|
23 |
|
24 |
//--------------------------------------------------------------------------------------------------
|
25 |
FillerPFMet::~FillerPFMet()
|
26 |
{
|
27 |
// Destructor.
|
28 |
|
29 |
delete pfMets_;
|
30 |
}
|
31 |
|
32 |
//--------------------------------------------------------------------------------------------------
|
33 |
void FillerPFMet::BookDataBlock(TreeWriter &tws)
|
34 |
{
|
35 |
// Add mets branch to tree.
|
36 |
|
37 |
tws.AddBranch(mitName_,&pfMets_);
|
38 |
OS()->add<mithep::PFMetArr>(pfMets_,mitName_);
|
39 |
}
|
40 |
|
41 |
//--------------------------------------------------------------------------------------------------
|
42 |
void FillerPFMet::FillDataBlock(const edm::Event &event,
|
43 |
const edm::EventSetup &setup)
|
44 |
{
|
45 |
// Fill missing energy from edm collection into our collection.
|
46 |
|
47 |
pfMets_->Delete();
|
48 |
|
49 |
reco::PFMETCollection inPFMets;
|
50 |
|
51 |
Handle<reco::PFMETCollection> hCaloMetProduct;
|
52 |
//GetProduct(edmName_, hCaloMetProduct, event);
|
53 |
event.getByLabel(edmName_,hCaloMetProduct);
|
54 |
if(hCaloMetProduct.isValid()) {
|
55 |
inPFMets = *(hCaloMetProduct.product());
|
56 |
} else {
|
57 |
Handle<reco::PFMET> hSingleMetProduct;
|
58 |
event.getByLabel(edmName_, hSingleMetProduct);
|
59 |
inPFMets.push_back(*hSingleMetProduct.product());
|
60 |
}
|
61 |
// loop through all mets
|
62 |
for (reco::PFMETCollection::const_iterator inPFMet = inPFMets.begin();
|
63 |
inPFMet != inPFMets.end(); ++inPFMet) {
|
64 |
|
65 |
mithep::PFMet *pfMet = pfMets_->Allocate();
|
66 |
new (pfMet) mithep::PFMet(inPFMet->px(), inPFMet->py());
|
67 |
|
68 |
// fill Met base class data
|
69 |
pfMet->SetSumEt(inPFMet->sumEt());
|
70 |
pfMet->SetElongitudinal(inPFMet->e_longitudinal());
|
71 |
for(unsigned i=0; i<inPFMet->mEtCorr().size(); i++) {
|
72 |
pfMet->PushCorrectionX(inPFMet->mEtCorr()[i].mex);
|
73 |
pfMet->PushCorrectionY(inPFMet->mEtCorr()[i].mey);
|
74 |
pfMet->PushCorrectionSumEt(inPFMet->mEtCorr()[i].sumet);
|
75 |
}
|
76 |
// fill PFMet class data
|
77 |
pfMet->SetPFMetSig(inPFMet->significance());
|
78 |
pfMet->SetNeutralEMFraction(inPFMet->NeutralEMFraction());
|
79 |
pfMet->SetNeutralHadFraction(inPFMet->NeutralHadFraction());
|
80 |
pfMet->SetChargedEMFraction(inPFMet->ChargedEMFraction());
|
81 |
pfMet->SetChargedHadFraction(inPFMet->ChargedHadFraction());
|
82 |
pfMet->SetMuonFraction(inPFMet->MuonFraction());
|
83 |
|
84 |
}
|
85 |
pfMets_->Trim();
|
86 |
}
|