ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerGenJets.cc
Revision: 1.1
Committed: Tue Sep 16 18:17:46 2008 UTC (16 years, 7 months ago) by sixie
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_006b, Mit_006a, Mit_006, Mit_005, Mit_004
Log Message:
Add Gen Jets Filler

File Contents

# User Rev Content
1 sixie 1.1 // $Id: FillerGenJets.cc,v 1.10 2008/09/11 10:00:35 sixie Exp $
2    
3     #include "MitProd/TreeFiller/interface/FillerGenJets.h"
4     #include "FWCore/MessageLogger/interface/MessageLogger.h"
5     #include "DataFormats/Common/interface/Handle.h"
6     #include "MitAna/DataTree/interface/Names.h"
7     #include "DataFormats/JetReco/interface/GenJet.h"
8     #include "SimDataFormats/JetMatching/interface/JetFlavour.h"
9     #include "SimDataFormats/JetMatching/interface/JetFlavourMatching.h"
10     #include "SimDataFormats/JetMatching/interface/MatchedPartons.h"
11     #include "SimDataFormats/JetMatching/interface/JetMatchedPartons.h"
12    
13     using namespace std;
14     using namespace edm;
15     using namespace mithep;
16    
17     //--------------------------------------------------------------------------------------------------
18     FillerGenJets::FillerGenJets(const ParameterSet &cfg, const char *name, bool active) :
19     BaseFiller(cfg,name,active),
20     flavorMatchingActive_(Conf().getUntrackedParameter<bool>("flavorMatchingActive",true)),
21     edmName_(Conf().getUntrackedParameter<string>("edmName","genjets")),
22     mitName_(Conf().getUntrackedParameter<string>("mitName","GenJets")),
23     flavorMatchingByReferenceName_(Conf().getUntrackedParameter<string>
24     ("flavorMatchingByReferenceName","srcByReference")),
25     flavorMatchingDefinition_(Conf().getUntrackedParameter<string>
26     ("flavorMatchingDefinition","Algorithmic")),
27     genjets_(new mithep::GenJetArr(16))
28     {
29     // Constructor.
30     }
31    
32     //--------------------------------------------------------------------------------------------------
33     FillerGenJets::~FillerGenJets()
34     {
35     // Destructor.
36    
37     delete genjets_;
38     }
39    
40     //--------------------------------------------------------------------------------------------------
41     void FillerGenJets::BookDataBlock(TreeWriter &tws)
42     {
43     // Add jets branch to tree.
44    
45     tws.AddBranch(mitName_.c_str(),&genjets_);
46    
47     }
48    
49     //--------------------------------------------------------------------------------------------------
50     void FillerGenJets::FillDataBlock(const edm::Event &event,
51     const edm::EventSetup &setup)
52     {
53     // Fill jets from edm collection into our collection.
54    
55     genjets_->Reset();
56    
57     //Handle for the Jet Collection
58     Handle<reco::GenJetCollection> hGenJetProduct;
59     GetProduct(edmName_, hGenJetProduct, event);
60    
61     //Handles for jet flavour matching
62     Handle<reco::JetMatchedPartonsCollection> hPartonMatchingProduct;
63     if (flavorMatchingActive_)
64     GetProduct(flavorMatchingByReferenceName_, hPartonMatchingProduct, event);
65    
66     const reco::GenJetCollection inJets = *(hGenJetProduct.product());
67    
68     // loop through all jets
69     for (reco::GenJetCollection::const_iterator inJet = inJets.begin();
70     inJet != inJets.end(); ++inJet) {
71    
72     reco::GenJetRef jetRef(hGenJetProduct, inJet - inJets.begin());
73    
74     mithep::GenJet *jet = genjets_->Allocate();
75     new (jet) mithep::GenJet(inJet->p4().x(),
76     inJet->p4().y(),
77     inJet->p4().z(),
78     inJet->p4().e());
79    
80     jet->SetHadEnergy (inJet->hadEnergy());
81     jet->SetEmEnergy (inJet->emEnergy());
82     jet->SetInvisibleEnergy (inJet->invisibleEnergy());
83     jet->SetAuxiliaryEnergy (inJet->auxiliaryEnergy());
84    
85     if (flavorMatchingActive_) {
86     unsigned int iJet = inJet - inJets.begin();
87     const reco::JetMatchedPartonsCollection *matchedPartons = hPartonMatchingProduct.product();
88     reco::MatchedPartons matchedParton = (*matchedPartons)[matchedPartons->key(iJet)];
89     int flavorPhysDef = (matchedParton.physicsDefinitionParton().isNonnull())?
90     matchedParton.physicsDefinitionParton()->pdgId():0;
91     int flavorAlgDef = (matchedParton.algoDefinitionParton().isNonnull())?
92     matchedParton.algoDefinitionParton()->pdgId():0;
93    
94     if (flavorMatchingDefinition_ == "Algorithmic") {
95     jet->SetMatchedMCFlavor(flavorAlgDef);
96     } else if(flavorMatchingDefinition_ == "Physics") {
97     jet->SetMatchedMCFlavor(flavorPhysDef);
98     } else {
99     jet->SetMatchedMCFlavor(0);
100     }
101     }
102     }
103     genjets_->Trim();
104     }