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);
87  muons = fillMuonCollection(*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
T getUntrackedParameter(std::string const &, T const &) const
TestResolution(const edm::ParameterSet &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
edm::EDGetTokenT< reco::TrackCollection > saMuonsToken_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::string theRootFileName_
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
edm::EDGetTokenT< reco::TrackCollection > tracksToken_
TFile * outputFile_
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
~TestResolution() override
std::vector< reco::LeafCandidate > fillMuonCollection(const std::vector< T > &tracks)
TProfile * sigmaPt_
fixed size matrix
HLT enums.
edm::EDGetTokenT< reco::MuonCollection > glbMuonsToken_
def canvas(sub, attr)
Definition: svgfig.py:482
void analyze(const edm::Event &, const edm::EventSetup &) override
std::unique_ptr< ResolutionFunction > resolutionFunction_