CMS 3D CMS Logo

TestResolution.cc
Go to the documentation of this file.
1 #ifndef TESTRESOLUTION_CC
2 #define TESTRESOLUTION_CC
3 
4 #include "TestResolution.h"
5 
6 #include "TCanvas.h"
7 #include "TLegend.h"
8 
9 //
10 // constants, enums and typedefs
11 //
12 
13 //
14 // static data member definitions
15 //
16 
17 //
18 // constructors and destructor
19 //
21  : theMuonLabel_(iConfig.getParameter<edm::InputTag>("MuonLabel")),
22  glbMuonsToken_(mayConsume<reco::MuonCollection>(theMuonLabel_)),
23  saMuonsToken_(mayConsume<reco::TrackCollection>(theMuonLabel_)),
24  tracksToken_(mayConsume<reco::TrackCollection>(theMuonLabel_)),
25  theMuonType_(iConfig.getParameter<int>("MuonType")),
26  theRootFileName_(iConfig.getUntrackedParameter<std::string>("OutputFileName")) {
27  //now do what ever initialization is needed
28  outputFile_ = new TFile(theRootFileName_.c_str(), "RECREATE");
29  outputFile_->cd();
30  sigmaPt_ = new TProfile("sigmaPtOverPt", "sigmaPt/Pt vs muon Pt", 1000, 0, 100);
31  eventCounter_ = 0;
32  // Create the corrector and set the parameters
33  resolutionFunction_.reset(
34  new ResolutionFunction(iConfig.getUntrackedParameter<std::string>("ResolutionsIdentifier")));
35  std::cout << "resolutionFunction_ = " << &*resolutionFunction_ << std::endl;
36 }
37 
39  outputFile_->cd();
40  TCanvas canvas("sigmaPtOverPt", "sigmaPt/Pt vs muon Pt", 1000, 800);
41  canvas.cd();
42  sigmaPt_->GetXaxis()->SetTitle("Pt(GeV)");
43  // TLegend * legend = new TLegend(0.7,0.71,0.98,1.);
44  // legend->SetTextSize(0.02);
45  // legend->SetFillColor(0); // Have a white background
46  // legend->AddEntry(uncorrectedPt_, "original pt");
47  // legend->AddEntry(correctedPt_, "corrected pt");
48  sigmaPt_->Draw();
49  // legend->Draw("same");
50 
51  canvas.Write();
52  sigmaPt_->Write();
53  outputFile_->Close();
54 
55  std::cout << "Total analyzed events = " << eventCounter_ << std::endl;
56 }
57 
58 //
59 // member functions
60 //
61 
62 // ------------ method called to for each event ------------
64  using namespace edm;
65 
66  ++eventCounter_;
67  if (eventCounter_ % 100 == 0) {
68  std::cout << "Event number " << eventCounter_ << std::endl;
69  }
70 
71  // Take the reco-muons, depending on the type selected in the cfg
72  // --------------------------------------------------------------
73 
74  std::vector<reco::LeafCandidate> muons;
75 
76  if (theMuonType_ == 1) { // GlobalMuons
78  iEvent.getByToken(glbMuonsToken_, glbMuons);
79  muons = fillMuonCollection(*glbMuons);
80  } else if (theMuonType_ == 2) { // StandaloneMuons
82  iEvent.getByToken(saMuonsToken_, saMuons);
83  muons = fillMuonCollection(*saMuons);
84  } else if (theMuonType_ == 3) { // Tracker tracks
86  iEvent.getByToken(tracksToken_, tracks);
88  }
89 
90  // Loop on the recMuons
91  std::vector<reco::LeafCandidate>::const_iterator recMuon = muons.begin();
92  for (; recMuon != muons.end(); ++recMuon) {
93  // Fill the histogram with uncorrected pt values
94  sigmaPt_->Fill(resolutionFunction_->sigmaPt(*recMuon, 0), recMuon->pt());
95  }
96 }
97 
98 //define this as a plug-in
100 
101 #endif // TESTRESOLUTION_CC
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
edm
HLT enums.
Definition: AlignableModifier.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
TestResolution::TestResolution
TestResolution(const edm::ParameterSet &)
Definition: TestResolution.cc:20
TestResolution::resolutionFunction_
std::unique_ptr< ResolutionFunction > resolutionFunction_
Definition: TestResolution.h:94
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle< reco::MuonCollection >
TestResolution::fillMuonCollection
std::vector< reco::LeafCandidate > fillMuonCollection(const std::vector< T > &tracks)
Definition: TestResolution.h:62
TestResolution::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: TestResolution.cc:63
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
reco::MuonCollection
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
TestResolution
Definition: TestResolution.h:53
TestResolution::sigmaPt_
TProfile * sigmaPt_
Definition: TestResolution.h:90
TestResolution::eventCounter_
int eventCounter_
Definition: TestResolution.h:92
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TestResolution::glbMuonsToken_
edm::EDGetTokenT< reco::MuonCollection > glbMuonsToken_
Definition: TestResolution.h:82
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
ResolutionFunction
Definition: ResolutionFunction.h:15
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:57
TestResolution::saMuonsToken_
edm::EDGetTokenT< reco::TrackCollection > saMuonsToken_
Definition: TestResolution.h:83
std
Definition: JetResolutionObject.h:76
TestResolution::theRootFileName_
std::string theRootFileName_
Definition: TestResolution.h:87
TestResolution.h
TestResolution::outputFile_
TFile * outputFile_
Definition: TestResolution.h:88
edm::Event
Definition: Event.h:73
TestResolution::~TestResolution
~TestResolution() override
Definition: TestResolution.cc:38
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
TestResolution::tracksToken_
edm::EDGetTokenT< reco::TrackCollection > tracksToken_
Definition: TestResolution.h:84
TestResolution::theMuonType_
int theMuonType_
Definition: TestResolution.h:86