ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillMuons.cc
Revision: 1.3
Committed: Tue Jun 17 13:31:38 2008 UTC (16 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.2: +3 -3 lines
Log Message:
Use Array instead of Vector.

File Contents

# User Rev Content
1 loizides 1.3 // $Id: FillMuons.cc,v 1.2 2008/06/11 12:50:17 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    
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     void FillMuons::analyze(const edm::Event &theEvent,
35     const edm::EventSetup &iSetup)
36     {
37     muons_->Reset();
38    
39     Handle<reco::MuonCollection> theMuonProduct;
40     try {
41     theEvent.getByLabel(muonSource_, theMuonProduct);
42     } catch (cms::Exception& ex) {
43     edm::LogError("FillMuons") << "Error! Can not get collection with label "
44     << muonSource_ << endl;
45     throw edm::Exception(edm::errors::Configuration, "FillMuons:analyze()\n")
46     << "Error! Can not get collection with label " << muonSource_ << endl;
47     }
48    
49     const reco::MuonCollection Muons = *(theMuonProduct.product());
50    
51     int nMuons = 0;
52 loizides 1.2 for (reco::MuonCollection::const_iterator inMuon = Muons.begin();
53 bendavid 1.1 inMuon != Muons.end(); ++inMuon) {
54    
55     mithep::Muon* outMuon = new mithep::Muon(inMuon->px(),inMuon->py(),inMuon->pz(),inMuon->energy());
56    
57 loizides 1.2 //Fill muon track info using global (tracker+muon chambers) track fit if available,
58     //or standalone tracker or muon tracks otherwise
59 bendavid 1.1 const reco::Track* inMuonTrack = &*inMuon->combinedMuon().get();
60     if (!inMuonTrack)
61     inMuonTrack = &*inMuon->standAloneMuon().get();
62     if (!inMuonTrack)
63     inMuonTrack = &*inMuon->track().get();
64     if (inMuonTrack) {
65 loizides 1.2 outMuon->GetTrack()->SetHelix(inMuonTrack->phi(),
66     inMuonTrack->d0(),
67     inMuonTrack->pt(),
68     inMuonTrack->dz(),
69     inMuonTrack->theta());
70     outMuon->GetTrack()->SetErrors(inMuonTrack->phiError(),
71     inMuonTrack->d0Error(),
72     inMuonTrack->ptError(),
73     inMuonTrack->dzError(),
74     inMuonTrack->thetaError());
75 bendavid 1.1 outMuon->GetTrack()->SetCharge(inMuonTrack->charge());
76     }
77    
78 loizides 1.3 muons_->AddCopy(outMuon);
79 bendavid 1.1 nMuons++;
80     }
81    
82 loizides 1.2 muons_->Trim();
83 bendavid 1.1 }
84    
85     //-------------------------------------------------------------------------------------------------
86     void FillMuons::beginJob(edm::EventSetup const &iEvent)
87     {
88     Service<TreeService> ts;
89     TreeWriter *tws = ts->get();
90     if(!tws) {
91     throw edm::Exception(edm::errors::Configuration, "FillMuons::beginJob()\n")
92     << "Could not get pointer to Tree with name " << tws->GetName() << "\n";
93     return;
94     }
95    
96     tws->AddBranch(muonBranch_.c_str(),&muons_);
97     }
98    
99     //-------------------------------------------------------------------------------------------------
100     void FillMuons::endJob()
101     {
102     edm::LogInfo("FillMuons::endJob") << "Ending Job" << endl;
103     }