1 |
// $Id: FillMuons.cc,v 1.7 2008/06/20 17:52:57 loizides Exp $
|
2 |
|
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 |
#include "MitProd/TreeService/interface/TreeService.h"
|
13 |
#include "MitAna/DataUtil/interface/TreeWriter.h"
|
14 |
|
15 |
using namespace std;
|
16 |
using namespace edm;
|
17 |
using namespace mithep;
|
18 |
|
19 |
//-------------------------------------------------------------------------------------------------
|
20 |
FillMuons::FillMuons(const edm::ParameterSet &cfg) :
|
21 |
muons_(new mithep::Array<mithep::Muon>()),
|
22 |
muonSource_(cfg.getUntrackedParameter<string>("muonSource", "muons")),
|
23 |
muonBranch_(cfg.getUntrackedParameter<string>("muonBrname", Names::gkMuonBrn))
|
24 |
{
|
25 |
}
|
26 |
|
27 |
//-------------------------------------------------------------------------------------------------
|
28 |
FillMuons::~FillMuons()
|
29 |
{
|
30 |
}
|
31 |
|
32 |
//-------------------------------------------------------------------------------------------------
|
33 |
void FillMuons::analyze(const edm::Event &event,
|
34 |
const edm::EventSetup &setup)
|
35 |
{
|
36 |
// Fill muon track info using global (tracker+muon chambers) track fit if available, or standalone
|
37 |
// muon or tracker tracks otherwise
|
38 |
muons_->Reset();
|
39 |
|
40 |
Handle<reco::MuonCollection> muonProduct;
|
41 |
try {
|
42 |
event.getByLabel(muonSource_, muonProduct);
|
43 |
} 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 |
const reco::MuonCollection Muons = *(muonProduct.product());
|
51 |
|
52 |
// 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 |
muons_->AddCopy(outMuon);
|
69 |
}
|
70 |
}
|
71 |
muons_->Trim();
|
72 |
}
|
73 |
|
74 |
//-------------------------------------------------------------------------------------------------
|
75 |
void FillMuons::beginJob(const edm::EventSetup &setup)
|
76 |
{
|
77 |
Service<TreeService> ts;
|
78 |
TreeWriter *tws = ts->get();
|
79 |
if (! tws) {
|
80 |
throw edm::Exception(edm::errors::Configuration, "FillMuons::beginJob()\n")
|
81 |
<< "Could not get pointer to Tree\n";
|
82 |
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 |
}
|