ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerAODMCParticles.cc
Revision: 1.2
Committed: Thu Feb 26 17:04:03 2009 UTC (16 years, 2 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_008pre1
Changes since 1.1: +2 -2 lines
Log Message:
Switch from Reset to Delete calls on arrays, since we now use some heap

File Contents

# User Rev Content
1 bendavid 1.2 // $Id: FillerAODMCParticles.cc,v 1.1 2009/02/23 20:53:35 bendavid Exp $
2 bendavid 1.1
3     #include "MitProd/TreeFiller/interface/FillerAODMCParticles.h"
4     #include "FWCore/MessageLogger/interface/MessageLogger.h"
5     #include "DataFormats/Common/interface/Handle.h"
6     #include "DataFormats/Common/interface/RefToPtr.h"
7     #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
8     #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
9     #include "MitAna/DataTree/interface/Names.h"
10    
11     using namespace std;
12     using namespace edm;
13     using namespace mithep;
14    
15     //--------------------------------------------------------------------------------------------------
16     FillerAODMCParticles::FillerAODMCParticles(const ParameterSet &cfg, const char *name, bool active) :
17     BaseFiller(cfg, name, active),
18     genEdmName_(Conf().getUntrackedParameter<string>("genEdmName","genParticles")),
19     genMapName_(Conf().getUntrackedParameter<string>("genMapName","AODGenMap")),
20     mitName_(Conf().getUntrackedParameter<string>("mitName",Names::gkMCPartBrn)),
21     mcParticles_(new mithep::MCParticleArr(250)),
22     genMap_(new mithep::AODGenParticleMap)
23     {
24     // Constructor.
25     }
26    
27     //--------------------------------------------------------------------------------------------------
28     FillerAODMCParticles::~FillerAODMCParticles()
29     {
30     // Destructor.
31    
32     delete mcParticles_;
33     delete genMap_;
34     }
35    
36     //--------------------------------------------------------------------------------------------------
37     void FillerAODMCParticles::BookDataBlock(TreeWriter &tws)
38     {
39     // Add branch to tree and publish our maps.
40    
41     tws.AddBranch(mitName_.c_str(),&mcParticles_);
42    
43     OS()->add(genMap_,genMapName_.c_str());
44    
45     }
46    
47     //--------------------------------------------------------------------------------------------------
48     void FillerAODMCParticles::FillDataBlock(const edm::Event &event,
49     const edm::EventSetup &setup)
50     {
51     // Loop over HepMC particle and fill their information.
52    
53 bendavid 1.2 mcParticles_->Delete();
54 bendavid 1.1 genMap_->Reset();
55    
56     Handle<reco::GenParticleCollection> hGenPProduct;
57     GetProduct(genEdmName_, hGenPProduct, event);
58    
59     const reco::GenParticleCollection genParticles = *(hGenPProduct.product());
60    
61     //loop over all genparticles and copy their information
62     for (reco::GenParticleCollection::const_iterator pgen = genParticles.begin();
63     pgen != genParticles.end(); ++pgen) {
64    
65     mithep::MCParticle *mcPart = mcParticles_->Allocate();
66     new (mcPart) mithep::MCParticle(pgen->px(),pgen->py(),
67     pgen->pz(),pgen->energy(),
68     pgen->pdgId(),
69     pgen->status());
70    
71     mcPart->SetIsGenerated();
72    
73     edm::Ptr<reco::GenParticle> thePtr(hGenPProduct, pgen - genParticles.begin());
74     genMap_->Add(thePtr, mcPart);
75    
76     }
77    
78     mcParticles_->Trim();
79     }
80    
81     //--------------------------------------------------------------------------------------------------
82     void FillerAODMCParticles::ResolveLinks(const edm::Event &event,
83     const edm::EventSetup &setup)
84     {
85     // Loop over HepMC particle and resolve their links.
86    
87    
88    
89     Handle<reco::GenParticleCollection> hGenPProduct;
90     GetProduct(genEdmName_, hGenPProduct, event);
91    
92     const reco::GenParticleCollection genParticles = *(hGenPProduct.product());
93    
94     //loop over all genparticles and copy their information
95     for (reco::GenParticleCollection::const_iterator pgen = genParticles.begin();
96     pgen != genParticles.end(); ++pgen) {
97    
98     int nDaughters = pgen->numberOfDaughters();
99    
100     if (nDaughters>0) {
101    
102     edm::Ptr<reco::GenParticle> thePtr(hGenPProduct, pgen - genParticles.begin());
103     MCParticle *mcMother = genMap_->GetMit(thePtr);
104     for (int i=0; i<nDaughters; ++i) {
105     const reco::Candidate *genDaughter = pgen->daughter(i);
106     MCParticle *mcDaughter = genMap_->GetMit(refToPtr(pgen->daughterRef(i)));
107     //set mother decay vertex
108     if (i==0)
109     mcMother->SetVertex(genDaughter->vx(),genDaughter->vy(),genDaughter->vz());
110    
111     //set mother-daughter links
112     mcMother->AddDaughter(mcDaughter);
113     if (!mcDaughter->HasMother())
114     mcDaughter->SetMother(mcMother);
115    
116     }
117     }
118     }
119     }