ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillGenParts.cc
Revision: 1.4
Committed: Thu Jun 5 07:57:49 2008 UTC (16 years, 11 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.3: +33 -37 lines
Log Message:
Updated the genfiller. Use the Logfile, throw in case of problems and trim the output container.

File Contents

# User Rev Content
1 loizides 1.4 // $Id: FillGenParts.cc,v 1.3 2008/06/03 07:21:45 paus Exp $
2 loizides 1.1
3     #include "MitProd/TreeFiller/interface/FillGenParts.h"
4     #include "FWCore/MessageLogger/interface/MessageLogger.h"
5     #include "FWCore/Framework/interface/ESHandle.h"
6     #include "DataFormats/Common/interface/Handle.h"
7     #include "FWCore/ServiceRegistry/interface/Service.h"
8    
9     #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
10 loizides 1.4 #include "MitAna/DataTree/interface/Names.h"
11     #include "MitAna/DataTree/interface/GenParticle.h"
12 loizides 1.1
13     using namespace std;
14     using namespace edm;
15     using namespace mithep;
16    
17     //-------------------------------------------------------------------------------------------------
18     FillGenParts::FillGenParts(const edm::ParameterSet &iConfig)
19 loizides 1.4 : genParticles_(new mithep::Vector<mithep::GenParticle>()),
20     mcSource_(iConfig.getUntrackedParameter<string>("source", "source")),
21     genPartBrn_(iConfig.getUntrackedParameter<string>("brname", Names::gkGenPartBrn))
22 loizides 1.1 {
23     }
24    
25     //-------------------------------------------------------------------------------------------------
26     FillGenParts::~FillGenParts()
27     {
28     }
29    
30     //-------------------------------------------------------------------------------------------------
31 loizides 1.4 void FillGenParts::analyze(const edm::Event &theEvent, const edm::EventSetup &iSetup)
32 loizides 1.1 {
33 loizides 1.4 // Analyzer called on every entry.
34    
35 loizides 1.1 genParticles_->Reset();
36    
37     Handle<HepMCProduct> theMCProduct;
38     try {
39 loizides 1.4 theEvent.getByLabel(mcSource_, theMCProduct);
40 loizides 1.1 } catch (cms::Exception& ex) {
41 loizides 1.4 edm::LogError("FillGenParts") << "Error! Can not get collection with label "
42     << mcSource_ << endl;
43     throw edm::Exception(edm::errors::Configuration, "FillGenParts::analyze()\n")
44     << "Error! Can not get collection with label " << mcSource_ << endl;
45 loizides 1.1 }
46    
47     const HepMC::GenEvent GenEvent = theMCProduct->getHepMCData();
48    
49     int nGen = 0;
50 loizides 1.4 for (HepMC::GenEvent::particle_const_iterator pgen = GenEvent.particles_begin();
51 loizides 1.1 pgen != GenEvent.particles_end(); ++pgen) {
52    
53     HepMC::GenParticle* mcPart = (*pgen);
54     if(!mcPart) continue;
55    
56 loizides 1.4 Short_t moind = -1;
57     HepMC::GenVertex * momVert = mcPart->production_vertex();
58 paus 1.3 if (momVert) {
59     if (momVert->particles_in_size() == 1) {
60 loizides 1.4 HepMC::GenVertex::particles_in_const_iterator mom =
61     momVert->particles_in_const_begin();
62     moind = (*mom)->barcode() - 1;
63     }
64     }
65    
66     mithep::GenParticle genParticle(mcPart->momentum().x(),mcPart->momentum().y(),
67     mcPart->momentum().z(),mcPart->momentum().e(),
68     mcPart->pdg_id(),
69     mcPart->status(),
70     moind);
71 loizides 1.1 genParticles_->Add(genParticle);
72     nGen++;
73     }
74    
75 loizides 1.4 genParticles_->Trim();
76 loizides 1.1 }
77    
78     //-------------------------------------------------------------------------------------------------
79     void FillGenParts::beginJob(edm::EventSetup const &iEvent)
80     {
81     Service<TreeService> ts;
82     TreeWriter *tws = ts->get();
83     if(!tws) {
84 loizides 1.4 throw edm::Exception(edm::errors::Configuration, "FillGenParts::beginJob()\n")
85     << "Could not get pointer to Tree with name " << tws->GetName() << "\n";
86 loizides 1.1 return;
87     }
88    
89 loizides 1.4 //tws->AddBranch(genPartBrn_.c_str(), genParticles_->ClassName(), &genParticles_, 32*1024, 2);
90     tws->AddBranch(genPartBrn_.c_str(), &genParticles_, 32*1024, 99);
91 loizides 1.1 }
92    
93     //-------------------------------------------------------------------------------------------------
94     void FillGenParts::endJob()
95     {
96     edm::LogInfo("FillGenParts::endJob") << "Ending Job" << endl;
97     }