ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillMuons.cc
Revision: 1.5
Committed: Wed Jun 18 14:10:45 2008 UTC (16 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.4: +2 -2 lines
Log Message:
Use Array

File Contents

# User Rev Content
1 loizides 1.5 // $Id: FillMuons.cc,v 1.4 2008/06/18 13:23:22 paus Exp $
2 bendavid 1.1
3     #include "MitProd/TreeFiller/interface/FillMuons.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     #include "DataFormats/MuonReco/interface/MuonFwd.h"
11     #include "DataFormats/MuonReco/interface/Muon.h"
12     #include "DataFormats/TrackReco/interface/Track.h"
13     #include "MitAna/DataTree/interface/Particle.h"
14     #include "MitAna/DataTree/interface/Names.h"
15    
16     using namespace std;
17     using namespace edm;
18     using namespace mithep;
19    
20     //-------------------------------------------------------------------------------------------------
21 loizides 1.2 FillMuons::FillMuons(const edm::ParameterSet &iConfig) :
22 loizides 1.3 muons_(new mithep::Array<mithep::Muon>()),
23 loizides 1.2 muonSource_(iConfig.getUntrackedParameter<string>("muonSource" , "muons")),
24     muonBranch_(iConfig.getUntrackedParameter<string>("muonBrname", Names::gkMuonBrn))
25 bendavid 1.1 {
26     }
27    
28     //-------------------------------------------------------------------------------------------------
29     FillMuons::~FillMuons()
30     {
31     }
32    
33     //-------------------------------------------------------------------------------------------------
34 paus 1.4 void FillMuons::analyze(const edm::Event &event,
35     const edm::EventSetup &iSetup)
36 bendavid 1.1 {
37 paus 1.4 // Fill muon track info using global (tracker+muon chambers) track fit if available, or standalone
38     // muon or tracker tracks otherwise
39 bendavid 1.1 muons_->Reset();
40    
41 paus 1.4 Handle<reco::MuonCollection> muonProduct;
42 bendavid 1.1 try {
43 paus 1.4 event.getByLabel(muonSource_, muonProduct);
44 bendavid 1.1 } catch (cms::Exception& ex) {
45     edm::LogError("FillMuons") << "Error! Can not get collection with label "
46     << muonSource_ << endl;
47     throw edm::Exception(edm::errors::Configuration, "FillMuons:analyze()\n")
48     << "Error! Can not get collection with label " << muonSource_ << endl;
49     }
50    
51 paus 1.4 const reco::MuonCollection Muons = *(muonProduct.product());
52 bendavid 1.1
53 paus 1.4 // Loop through all muons
54     for (reco::MuonCollection::const_iterator iM = Muons.begin(); iM != Muons.end(); ++iM) {
55     // Here we are interested in the standalone muon information only
56     const reco::Track* muonTrk = &*iM->standAloneMuon().get();
57     if (! muonTrk)
58     cout << "Error - no muon track in the global muon. Filling nothing!\n";
59     else {
60     // Initialize a new MitDataObject
61     mithep::Muon* outMuon = new mithep::Muon(iM->px(),iM->py(),iM->pz(),iM->energy());
62     // Fill the information
63     outMuon->GetTrack()->SetHelix (muonTrk->phi(),muonTrk->d0(),muonTrk->pt(),
64     muonTrk->dz(), muonTrk->theta());
65     outMuon->GetTrack()->SetErrors(muonTrk->phiError(),muonTrk->d0Error(),muonTrk->ptError(),
66     muonTrk->dzError(), muonTrk->thetaError());
67     outMuon->GetTrack()->SetCharge(muonTrk->charge());
68     // Add the muon to the collection
69 loizides 1.5 muons_->AddCopy(outMuon);
70 bendavid 1.1 }
71     }
72 loizides 1.2 muons_->Trim();
73 bendavid 1.1 }
74    
75     //-------------------------------------------------------------------------------------------------
76     void FillMuons::beginJob(edm::EventSetup const &iEvent)
77     {
78     Service<TreeService> ts;
79     TreeWriter *tws = ts->get();
80 paus 1.4 if (! tws) {
81 bendavid 1.1 throw edm::Exception(edm::errors::Configuration, "FillMuons::beginJob()\n")
82 paus 1.4 << "Could not get pointer to Tree\n";
83 bendavid 1.1 return;
84     }
85    
86     tws->AddBranch(muonBranch_.c_str(),&muons_);
87     }
88    
89     //-------------------------------------------------------------------------------------------------
90     void FillMuons::endJob()
91     {
92     edm::LogInfo("FillMuons::endJob") << "Ending Job" << endl;
93     }