CMS 3D CMS Logo

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