Go to the documentation of this file.00001 #ifndef TESTRESOLUTION_CC
00002 #define TESTRESOLUTION_CC
00003
00004 #include "TestResolution.h"
00005
00006 #include "TCanvas.h"
00007 #include "TLegend.h"
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 TestResolution::TestResolution(const edm::ParameterSet& iConfig) :
00021 theMuonLabel_( iConfig.getParameter<edm::InputTag>( "MuonLabel" ) ),
00022 theMuonType_( iConfig.getParameter<int>( "MuonType" ) ),
00023 theRootFileName_( iConfig.getUntrackedParameter<std::string>("OutputFileName") )
00024 {
00025
00026 outputFile_ = new TFile(theRootFileName_.c_str(), "RECREATE");
00027 outputFile_->cd();
00028 sigmaPt_ = new TProfile("sigmaPtOverPt", "sigmaPt/Pt vs muon Pt", 1000, 0, 100);
00029 eventCounter_ = 0;
00030
00031 resolutionFunction_.reset(new ResolutionFunction( iConfig.getUntrackedParameter<std::string>("ResolutionsIdentifier") ) );
00032 std::cout << "resolutionFunction_ = " << &*resolutionFunction_ << std::endl;
00033 }
00034
00035
00036 TestResolution::~TestResolution()
00037 {
00038 outputFile_->cd();
00039 TCanvas canvas("sigmaPtOverPt","sigmaPt/Pt vs muon Pt", 1000, 800);
00040 canvas.cd();
00041 sigmaPt_->GetXaxis()->SetTitle("Pt(GeV)");
00042
00043
00044
00045
00046
00047 sigmaPt_->Draw();
00048
00049
00050 canvas.Write();
00051 sigmaPt_->Write();
00052 outputFile_->Close();
00053
00054 std::cout << "Total analyzed events = " << eventCounter_ << std::endl;
00055 }
00056
00057
00058
00059
00060
00061
00062
00063 void TestResolution::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00064 using namespace edm;
00065
00066 ++eventCounter_;
00067 if ( eventCounter_%100 == 0 ) {
00068 std::cout << "Event number " << eventCounter_ << std::endl;
00069 }
00070
00071
00072
00073
00074 std::vector<reco::LeafCandidate> muons;
00075
00076 if (theMuonType_==1) {
00077 Handle<reco::MuonCollection> glbMuons;
00078 iEvent.getByLabel (theMuonLabel_, glbMuons);
00079 muons = fillMuonCollection(*glbMuons);
00080 }
00081 else if (theMuonType_==2) {
00082 Handle<reco::TrackCollection> saMuons;
00083 iEvent.getByLabel (theMuonLabel_, saMuons);
00084 muons = fillMuonCollection(*saMuons);
00085 }
00086 else if (theMuonType_==3) {
00087 Handle<reco::TrackCollection> tracks;
00088 iEvent.getByLabel (theMuonLabel_, tracks);
00089 muons = fillMuonCollection(*tracks);
00090 }
00091
00092
00093 std::vector<reco::LeafCandidate>::const_iterator recMuon = muons.begin();
00094 for ( ; recMuon!=muons.end(); ++recMuon ) {
00095
00096
00097 sigmaPt_->Fill(resolutionFunction_->sigmaPt(*recMuon), recMuon->pt());
00098
00099 }
00100 }
00101
00102
00103 DEFINE_FWK_MODULE(TestResolution);
00104
00105 #endif // TESTRESOLUTION_CC