ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillGenParts.cc
Revision: 1.9
Committed: Tue Jul 1 11:31:43 2008 UTC (16 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +1 -1 lines
State: FILE REMOVED
Error occurred while calculating annotation data.
Log Message:
Old fillers removed

File Contents

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