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 <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);
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
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
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:22
TestResolution::resolutionFunction_
std::unique_ptr< ResolutionFunction > resolutionFunction_
Definition: TestResolution.h:94
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
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:65
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
edm::ParameterSet
Definition: ParameterSet.h:47
tracks
const uint32_t *__restrict__ const HitContainer *__restrict__ TkSoA *__restrict__ tracks
Definition: CAHitNtupletGeneratorKernelsImpl.h:159
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:58
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:40
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