1 |
bendavid |
1.1 |
// $Id$
|
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 |
|
|
|
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 |
|
|
#include "TLorentzVector.h"
|
17 |
|
|
|
18 |
|
|
using namespace std;
|
19 |
|
|
using namespace edm;
|
20 |
|
|
using namespace mithep;
|
21 |
|
|
|
22 |
|
|
//-------------------------------------------------------------------------------------------------
|
23 |
|
|
FillMuons::FillMuons(const edm::ParameterSet &iConfig)
|
24 |
|
|
: muonSource_(iConfig.getUntrackedParameter<string>("muonSource" , "muons")),
|
25 |
|
|
muonBranch_(iConfig.getUntrackedParameter<string>("muonBrname", Names::gkMuonBrn))
|
26 |
|
|
{
|
27 |
|
|
muons_ = new mithep::Vector<mithep::Muon>();
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
//-------------------------------------------------------------------------------------------------
|
31 |
|
|
FillMuons::~FillMuons()
|
32 |
|
|
{
|
33 |
|
|
cout << " Fillmuons done " <<endl;
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
//-------------------------------------------------------------------------------------------------
|
37 |
|
|
void FillMuons::analyze(const edm::Event &theEvent,
|
38 |
|
|
const edm::EventSetup &iSetup)
|
39 |
|
|
{
|
40 |
|
|
muons_->Reset();
|
41 |
|
|
|
42 |
|
|
Handle<reco::MuonCollection> theMuonProduct;
|
43 |
|
|
try {
|
44 |
|
|
theEvent.getByLabel(muonSource_, theMuonProduct);
|
45 |
|
|
} catch (cms::Exception& ex) {
|
46 |
|
|
edm::LogError("FillMuons") << "Error! Can not get collection with label "
|
47 |
|
|
<< muonSource_ << endl;
|
48 |
|
|
throw edm::Exception(edm::errors::Configuration, "FillMuons:analyze()\n")
|
49 |
|
|
<< "Error! Can not get collection with label " << muonSource_ << endl;
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
const reco::MuonCollection Muons = *(theMuonProduct.product());
|
53 |
|
|
|
54 |
|
|
int nMuons = 0;
|
55 |
|
|
for (reco::MuonCollection::const_iterator inMuon =
|
56 |
|
|
Muons.begin();
|
57 |
|
|
inMuon != Muons.end(); ++inMuon) {
|
58 |
|
|
|
59 |
|
|
mithep::Muon* outMuon = new mithep::Muon(inMuon->px(),inMuon->py(),inMuon->pz(),inMuon->energy());
|
60 |
|
|
|
61 |
|
|
//Fill muon track info using global (tracker+muon chambers) track fit if available, or standalone tracker or muon tracks otherwise
|
62 |
|
|
const reco::Track* inMuonTrack = &*inMuon->combinedMuon().get();
|
63 |
|
|
if (!inMuonTrack)
|
64 |
|
|
inMuonTrack = &*inMuon->standAloneMuon().get();
|
65 |
|
|
if (!inMuonTrack)
|
66 |
|
|
inMuonTrack = &*inMuon->track().get();
|
67 |
|
|
if (inMuonTrack) {
|
68 |
|
|
outMuon->GetTrack()->SetHelix(inMuonTrack->phi(),inMuonTrack->d0(),inMuonTrack->pt(),inMuonTrack->dz(),inMuonTrack->theta());
|
69 |
|
|
outMuon->GetTrack()->SetErrors(inMuonTrack->phiError(),inMuonTrack->d0Error(),inMuonTrack->ptError(),inMuonTrack->dzError(),inMuonTrack->thetaError());
|
70 |
|
|
outMuon->GetTrack()->SetCharge(inMuonTrack->charge());
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
muons_->Add(outMuon);
|
74 |
|
|
nMuons++;
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
//-------------------------------------------------------------------------------------------------
|
80 |
|
|
void FillMuons::beginJob(edm::EventSetup const &iEvent)
|
81 |
|
|
{
|
82 |
|
|
Service<TreeService> ts;
|
83 |
|
|
TreeWriter *tws = ts->get();
|
84 |
|
|
if(!tws) {
|
85 |
|
|
throw edm::Exception(edm::errors::Configuration, "FillMuons::beginJob()\n")
|
86 |
|
|
<< "Could not get pointer to Tree with name " << tws->GetName() << "\n";
|
87 |
|
|
return;
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
tws->AddBranch(muonBranch_.c_str(),&muons_);
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
//-------------------------------------------------------------------------------------------------
|
94 |
|
|
void FillMuons::endJob()
|
95 |
|
|
{
|
96 |
|
|
edm::LogInfo("FillMuons::endJob") << "Ending Job" << endl;
|
97 |
|
|
}
|