CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 "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  theMuonType_( iConfig.getParameter<int>( "MuonType" ) ),
23  theRootFileName_( iConfig.getUntrackedParameter<std::string>("OutputFileName") )
24 {
25  //now do what ever initialization is needed
26  outputFile_ = new TFile(theRootFileName_.c_str(), "RECREATE");
27  outputFile_->cd();
28  sigmaPt_ = new TProfile("sigmaPtOverPt", "sigmaPt/Pt vs muon Pt", 1000, 0, 100);
29  eventCounter_ = 0;
30  // Create the corrector and set the parameters
31  resolutionFunction_.reset(new ResolutionFunction( iConfig.getUntrackedParameter<std::string>("ResolutionsIdentifier") ) );
32  std::cout << "resolutionFunction_ = " << &*resolutionFunction_ << std::endl;
33 }
34 
35 
37 {
38  outputFile_->cd();
39  TCanvas canvas("sigmaPtOverPt","sigmaPt/Pt vs muon Pt", 1000, 800);
40  canvas.cd();
41  sigmaPt_->GetXaxis()->SetTitle("Pt(GeV)");
42 // TLegend * legend = new TLegend(0.7,0.71,0.98,1.);
43 // legend->SetTextSize(0.02);
44 // legend->SetFillColor(0); // Have a white background
45 // legend->AddEntry(uncorrectedPt_, "original pt");
46 // legend->AddEntry(correctedPt_, "corrected pt");
47  sigmaPt_->Draw();
48 // legend->Draw("same");
49 
50  canvas.Write();
51  sigmaPt_->Write();
52  outputFile_->Close();
53 
54  std::cout << "Total analyzed events = " << eventCounter_ << std::endl;
55 }
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.getByLabel (theMuonLabel_, glbMuons);
79  muons = fillMuonCollection(*glbMuons);
80  }
81  else if (theMuonType_==2) { // StandaloneMuons
83  iEvent.getByLabel (theMuonLabel_, saMuons);
84  muons = fillMuonCollection(*saMuons);
85  }
86  else if (theMuonType_==3) { // Tracker tracks
88  iEvent.getByLabel (theMuonLabel_, 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 
96  // Fill the histogram with uncorrected pt values
97  sigmaPt_->Fill(resolutionFunction_->sigmaPt(*recMuon, 0), recMuon->pt());
98 
99  }
100 }
101 
102 //define this as a plug-in
104 
105 #endif // TESTRESOLUTION_CC
T getUntrackedParameter(std::string const &, T const &) const
TestResolution(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::string theRootFileName_
def canvas
Definition: svgfig.py:481
TFile * outputFile_
int iEvent
Definition: GenABIO.cc:243
virtual void analyze(const edm::Event &, const edm::EventSetup &)
std::auto_ptr< ResolutionFunction > resolutionFunction_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
std::vector< reco::LeafCandidate > fillMuonCollection(const std::vector< T > &tracks)
tuple tracks
Definition: testEve_cfg.py:39
TProfile * sigmaPt_
tuple muons
Definition: patZpeak.py:38
tuple cout
Definition: gather_cfg.py:121
edm::InputTag theMuonLabel_