ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerMuons.cc
Revision: 1.23
Committed: Fri Sep 25 08:42:51 2009 UTC (15 years, 7 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_013pre1, Mit_012i, Mit_012h, Mit_012g, Mit_012f, Mit_012e, Mit_012d, Mit_012c, Mit_012b, Mit_012a, Mit_012, Mit_011a
Changes since 1.22: +2 -2 lines
Log Message:
Extended interface of BookDataBlock to contain event setup.

File Contents

# User Rev Content
1 loizides 1.23 // $Id: FillerMuons.cc,v 1.22 2009/06/15 15:00:26 loizides Exp $
2 loizides 1.1
3     #include "MitProd/TreeFiller/interface/FillerMuons.h"
4     #include "DataFormats/MuonReco/interface/Muon.h"
5     #include "DataFormats/MuonReco/interface/MuonFwd.h"
6 bendavid 1.15 #include "DataFormats/Common/interface/RefToPtr.h"
7 loizides 1.22 #include "MitAna/DataTree/interface/Names.h"
8     #include "MitAna/DataTree/interface/MuonCol.h"
9 loizides 1.1 #include "MitAna/DataTree/interface/Track.h"
10 loizides 1.22 #include "MitProd/ObjectService/interface/ObjectService.h"
11 loizides 1.1
12     using namespace std;
13     using namespace edm;
14     using namespace mithep;
15    
16 loizides 1.4 //--------------------------------------------------------------------------------------------------
17 loizides 1.18 FillerMuons::FillerMuons(const edm::ParameterSet &cfg, const char *name, bool active) :
18     BaseFiller(cfg,name,active),
19 loizides 1.1 edmName_(Conf().getUntrackedParameter<string>("edmName","muons")),
20     mitName_(Conf().getUntrackedParameter<string>("mitName",Names::gkMuonBrn)),
21 loizides 1.9 globalTrackMapName_(Conf().getUntrackedParameter<string>("globalTrackMapName","")),
22     staTrackMapName_(Conf().getUntrackedParameter<string>("staTrackMapName","")),
23     staVtxTrackMapName_(Conf().getUntrackedParameter<string>("staVtxTrackMapName","")),
24     trackerTrackMapName_(Conf().getUntrackedParameter<string>("trackerTrackMapName","")),
25 bendavid 1.19 muonMapName_(Conf().getUntrackedParameter<string>("muonMapName","")),
26     globalTrackMap_(0),
27     standaloneTrackMap_(0),
28     standaloneVtxTrackMap_(0),
29 loizides 1.9 trackerTrackMap_(0),
30 bendavid 1.19 muonMap_(new mithep::MuonMap),
31 pharris 1.12 muons_(new mithep::MuonArr(16))
32 loizides 1.1 {
33     // Constructor.
34     }
35    
36 loizides 1.4 //--------------------------------------------------------------------------------------------------
37 loizides 1.20 FillerMuons::~FillerMuons()
38     {
39     // Destructor.
40    
41 loizides 1.5 delete muons_;
42 bendavid 1.19 delete muonMap_;
43 loizides 1.1 }
44    
45 loizides 1.4 //--------------------------------------------------------------------------------------------------
46 loizides 1.23 void FillerMuons::BookDataBlock(TreeWriter &tws, const edm::EventSetup &es)
47 loizides 1.20 {
48 loizides 1.9 // Add muons branch to tree and get pointers to maps.
49 loizides 1.1
50 loizides 1.20 tws.AddBranch(mitName_,&muons_);
51     OS()->add<mithep::MuonArr>(muons_,mitName_);
52 bendavid 1.19
53 loizides 1.20 if (!globalTrackMapName_.empty()) {
54     globalTrackMap_ = OS()->get<TrackMap>(globalTrackMapName_);
55     if (globalTrackMap_)
56     AddBranchDep(mitName_,globalTrackMap_->GetBrName());
57     }
58     if (!staTrackMapName_.empty()) {
59     standaloneTrackMap_ = OS()->get<TrackMap>(staTrackMapName_);
60     if (standaloneTrackMap_)
61     AddBranchDep(mitName_,standaloneTrackMap_->GetBrName());
62     }
63     if (!staVtxTrackMapName_.empty()) {
64     standaloneVtxTrackMap_ = OS()->get<TrackMap>(staVtxTrackMapName_);
65     if (standaloneVtxTrackMap_)
66     AddBranchDep(mitName_,standaloneVtxTrackMap_->GetBrName());
67     }
68     if (!trackerTrackMapName_.empty()) {
69     trackerTrackMap_ = OS()->get<TrackMap>(trackerTrackMapName_);
70     if (trackerTrackMap_)
71     AddBranchDep(mitName_,trackerTrackMap_->GetBrName());
72     }
73     if (!muonMapName_.empty()) {
74     muonMap_->SetBrName(mitName_);
75     OS()->add<MuonMap>(muonMap_,muonMapName_);
76     }
77 loizides 1.1 }
78    
79 loizides 1.4 //--------------------------------------------------------------------------------------------------
80 loizides 1.1 void FillerMuons::FillDataBlock(const edm::Event &event,
81 loizides 1.4 const edm::EventSetup &setup)
82 loizides 1.1 {
83     // Fill muon information.
84    
85 bendavid 1.16 muons_->Delete();
86 bendavid 1.19 muonMap_->Reset();
87 loizides 1.1
88 loizides 1.6 Handle<reco::MuonCollection> hMuonProduct;
89 sixie 1.10 GetProduct(edmName_, hMuonProduct, event);
90 loizides 1.6 const reco::MuonCollection inMuons = *(hMuonProduct.product());
91 loizides 1.1
92 sixie 1.10 for (reco::MuonCollection::const_iterator iM = inMuons.begin(); iM != inMuons.end(); ++iM) {
93     mithep::Muon* outMuon = muons_->AddNew();
94     outMuon->SetIsoR03SumPt(iM->isolationR03().sumPt);
95     outMuon->SetIsoR03EmEt(iM->isolationR03().emEt);
96     outMuon->SetIsoR03HadEt(iM->isolationR03().hadEt);
97     outMuon->SetIsoR03HoEt(iM->isolationR03().hoEt);
98     outMuon->SetIsoR03NTracks(iM->isolationR03().nTracks);
99     outMuon->SetIsoR03NJets(iM->isolationR03().nJets);
100     outMuon->SetIsoR05SumPt(iM->isolationR05().sumPt);
101     outMuon->SetIsoR05EmEt(iM->isolationR05().emEt);
102     outMuon->SetIsoR05HadEt(iM->isolationR05().hadEt);
103     outMuon->SetIsoR05HoEt(iM->isolationR05().hoEt);
104     outMuon->SetIsoR05NTracks(iM->isolationR05().nTracks);
105     outMuon->SetIsoR05NJets(iM->isolationR05().nJets);
106     outMuon->SetEmEnergy(iM->calEnergy().em);
107     outMuon->SetHadEnergy(iM->calEnergy().had);
108     outMuon->SetHoEnergy(iM->calEnergy().ho);
109     outMuon->SetEmS9Energy(iM->calEnergy().emS9);
110     outMuon->SetHadS9Energy(iM->calEnergy().hadS9);
111     outMuon->SetHoS9Energy(iM->calEnergy().hoS9);
112 bendavid 1.17 outMuon->SetIsGlobalMuon(iM->isGlobalMuon());
113     outMuon->SetIsTrackerMuon(iM->isTrackerMuon());
114     outMuon->SetIsStandaloneMuon(iM->isStandAloneMuon());
115     outMuon->SetIsCaloMuon(iM->isCaloMuon());
116 pharris 1.11
117 loizides 1.1 if (globalTrackMap_ && iM->combinedMuon().isNonnull())
118 bendavid 1.15 outMuon->SetGlobalTrk(globalTrackMap_->GetMit(refToPtr(iM->combinedMuon())));
119 loizides 1.1 if (standaloneTrackMap_ && standaloneVtxTrackMap_ && iM->standAloneMuon().isNonnull()) {
120     Int_t refProductId = iM->standAloneMuon().id().id();
121     if ( refProductId == standaloneVtxTrackMap_->GetEdmProductId())
122 bendavid 1.15 outMuon->SetStandaloneTrk(standaloneVtxTrackMap_->GetMit(refToPtr(iM->standAloneMuon())));
123 loizides 1.1 else if ( refProductId == standaloneTrackMap_->GetEdmProductId())
124 bendavid 1.15 outMuon->SetStandaloneTrk(standaloneTrackMap_->GetMit(refToPtr(iM->standAloneMuon())));
125 loizides 1.1 else throw edm::Exception(edm::errors::Configuration, "FillerMuons:FillDataBlock()\n")
126 loizides 1.14 << "Error! Track reference in unmapped collection " << edmName_ << endl;
127 loizides 1.1 }
128     if (trackerTrackMap_ && iM->track().isNonnull())
129 bendavid 1.15 outMuon->SetTrackerTrk(trackerTrackMap_->GetMit(refToPtr(iM->track())));
130 loizides 1.14
131     outMuon->SetNChambers (iM->numberOfChambers());
132 pharris 1.11 outMuon->SetStationMask(iM->stationMask(reco::Muon::SegmentAndTrackArbitration));
133 loizides 1.14 for(int i0 = 0; i0 < 4; i0++) {
134 loizides 1.20 // DTs
135 pharris 1.11 outMuon->SetDX(i0, iM->dX(i0+1,1));
136     outMuon->SetDY(i0, iM->dY(i0+1,1));
137     outMuon->SetPullX(i0, iM->pullX(i0+1,1));
138     outMuon->SetPullY(i0, iM->pullY(i0+1,1));
139     outMuon->SetTrackDist(i0, iM->trackDist(i0+1,1));
140     outMuon->SetTrackDistErr(i0, iM->trackDistErr(i0+1,1));
141 loizides 1.14 outMuon->SetNSegments(i0, iM->numberOfSegments(i0+1,1));
142 loizides 1.20 // CSCs
143 pharris 1.11 outMuon->SetDX(4+i0, iM->dX (i0+1,2));
144     outMuon->SetDY(4+i0, iM->dY (i0+1,2));
145     outMuon->SetPullX(4+i0, iM->pullX (i0+1,2));
146     outMuon->SetPullY(4+i0, iM->pullY (i0+1,2));
147     outMuon->SetTrackDist(4+i0, iM->trackDist(i0+1,2));
148     outMuon->SetTrackDistErr(4+i0,iM->trackDistErr(i0+1,2));
149     outMuon->SetNSegments(4+i0, iM->numberOfSegments(i0+1,2));
150     }
151 bendavid 1.19
152 loizides 1.20 // add muon to map
153 bendavid 1.19 edm::Ptr<reco::Muon> thePtr(hMuonProduct, iM - inMuons.begin());
154     muonMap_->Add(thePtr, outMuon);
155 bendavid 1.21
156     if (verbose_>1) {
157     if (!outMuon->HasGlobalTrk() && !outMuon->HasStandaloneTrk()) {
158     printf("mithep::Muon, pt=%5f, eta=%5f, phi=%5f, mass=%5f\n",outMuon->Pt(),outMuon->Eta(),outMuon->Phi(), outMuon->Mass());
159     printf(" reco::Muon, pt=%5f, eta=%5f, phi=%5f, mass=%5f\n",iM->pt(),iM->eta(),iM->phi(),iM->mass());
160     }
161     }
162 bendavid 1.19
163 pharris 1.11 }
164 loizides 1.1 muons_->Trim();
165     }