1 |
paus |
1.1 |
// $Id: FillGlobalMuons.cc,v 1.2 2008/06/11 12:50:17 loizides Exp $
|
2 |
|
|
|
3 |
|
|
#include "FWCore/MessageLogger/interface/MessageLogger.h"
|
4 |
|
|
#include "FWCore/Framework/interface/ESHandle.h"
|
5 |
|
|
#include "DataFormats/Common/interface/Handle.h"
|
6 |
|
|
#include "FWCore/ServiceRegistry/interface/Service.h"
|
7 |
|
|
#include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
|
8 |
|
|
#include "DataFormats/MuonReco/interface/MuonFwd.h"
|
9 |
|
|
#include "DataFormats/MuonReco/interface/Muon.h"
|
10 |
|
|
#include "DataFormats/TrackReco/interface/Track.h"
|
11 |
|
|
|
12 |
|
|
#include "MitAna/DataTree/interface/Particle.h"
|
13 |
|
|
#include "MitAna/DataTree/interface/Names.h"
|
14 |
|
|
#include "MitProd/TreeFiller/interface/FillGlobalMuons.h"
|
15 |
|
|
|
16 |
|
|
using namespace std;
|
17 |
|
|
using namespace edm;
|
18 |
|
|
using namespace mithep;
|
19 |
|
|
|
20 |
|
|
//-------------------------------------------------------------------------------------------------
|
21 |
|
|
FillGlobalMuons::FillGlobalMuons(const edm::ParameterSet &iConfig) :
|
22 |
|
|
muons_(new mithep::Vector<mithep::GlobalMuon>()),
|
23 |
|
|
muonSource_(iConfig.getUntrackedParameter<string>("muonSource", "muons")),
|
24 |
|
|
muonBranch_(iConfig.getUntrackedParameter<string>("globalMuonBrname", Names::gkGlobalMuonBrn))
|
25 |
|
|
{
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
//-------------------------------------------------------------------------------------------------
|
29 |
|
|
FillGlobalMuons::~FillGlobalMuons()
|
30 |
|
|
{
|
31 |
|
|
}
|
32 |
|
|
|
33 |
|
|
//-------------------------------------------------------------------------------------------------
|
34 |
|
|
void FillGlobalMuons::analyze(const edm::Event &event,
|
35 |
|
|
const edm::EventSetup &iSetup)
|
36 |
|
|
{
|
37 |
|
|
// Fill muon track info using global (tracker+muon chambers) track fit if available, or standalone
|
38 |
|
|
// muon or tracker tracks otherwise
|
39 |
|
|
muons_->Reset();
|
40 |
|
|
|
41 |
|
|
Handle<reco::MuonCollection> muonProduct;
|
42 |
|
|
try {
|
43 |
|
|
event.getByLabel(muonSource_, muonProduct);
|
44 |
|
|
} catch (cms::Exception& ex) {
|
45 |
|
|
edm::LogError("FillGlobalMuons") << "Error! Can not get collection with label "
|
46 |
|
|
<< muonSource_ << endl;
|
47 |
|
|
throw edm::Exception(edm::errors::Configuration, "FillGlobalMuons:analyze()\n")
|
48 |
|
|
<< "Error! Can not get collection with label " << muonSource_ << endl;
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
const reco::MuonCollection Muons = *(muonProduct.product());
|
52 |
|
|
|
53 |
|
|
// 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->combinedMuon().get();
|
57 |
|
|
if (! muonTrk)
|
58 |
|
|
cout << "Error - no combined muon track in the global muon. Filling nothing!\n";
|
59 |
|
|
else {
|
60 |
|
|
// Initialize a new MitDataObject
|
61 |
|
|
mithep::GlobalMuon* outMuon = new mithep::GlobalMuon(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 |
|
|
muons_->Add(outMuon);
|
70 |
|
|
}
|
71 |
|
|
}
|
72 |
|
|
muons_->Trim();
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
//-------------------------------------------------------------------------------------------------
|
76 |
|
|
void FillGlobalMuons::beginJob(edm::EventSetup const &iEvent)
|
77 |
|
|
{
|
78 |
|
|
Service<TreeService> ts;
|
79 |
|
|
TreeWriter *tws = ts->get();
|
80 |
|
|
if (!tws) {
|
81 |
|
|
throw edm::Exception(edm::errors::Configuration, "FillGlobalMuons::beginJob()\n")
|
82 |
|
|
<< "Could not get pointer to Tree with name " << tws->GetName() << "\n";
|
83 |
|
|
return;
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
tws->AddBranch(muonBranch_.c_str(),&muons_);
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
//-------------------------------------------------------------------------------------------------
|
90 |
|
|
void FillGlobalMuons::endJob()
|
91 |
|
|
{
|
92 |
|
|
edm::LogInfo("FillGlobalMuons::endJob") << "Ending Job" << endl;
|
93 |
|
|
}
|