ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillMuons.cc
Revision: 1.7
Committed: Fri Jun 20 17:52:57 2008 UTC (16 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.6: +3 -4 lines
Log Message:
First proof-of-principle implementation of MetaInfo.

File Contents

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