CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

TestResolution Class Reference

#include <MuonAnalysis/MomentumScaleCalibration/plugins/TestResolution.cc>

Inheritance diagram for TestResolution:
edm::EDAnalyzer

List of all members.

Public Member Functions

 TestResolution (const edm::ParameterSet &)
 ~TestResolution ()

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
virtual void endJob ()
template<typename T >
std::vector< reco::LeafCandidatefillMuonCollection (const std::vector< T > &tracks)

Private Attributes

int eventCounter_
TFile * outputFile_
std::auto_ptr< ResolutionFunctionresolutionFunction_
TProfile * sigmaPt_
edm::InputTag theMuonLabel_
int theMuonType_
std::string theRootFileName_

Detailed Description

Description: <one line="" class="" summary>="">

Implementation: <Notes on="" implementation>="">

Definition at line 54 of file TestResolution.h.


Constructor & Destructor Documentation

TestResolution::TestResolution ( const edm::ParameterSet iConfig) [explicit]

Definition at line 20 of file TestResolution.cc.

References gather_cfg::cout, eventCounter_, edm::ParameterSet::getUntrackedParameter(), outputFile_, resolutionFunction_, sigmaPt_, and theRootFileName_.

                                                             :
  theMuonLabel_( iConfig.getParameter<edm::InputTag>( "MuonLabel" ) ),
  theMuonType_( iConfig.getParameter<int>( "MuonType" ) ),
  theRootFileName_( iConfig.getUntrackedParameter<std::string>("OutputFileName") )
{
  //now do what ever initialization is needed
  outputFile_ = new TFile(theRootFileName_.c_str(), "RECREATE");
  outputFile_->cd();
  sigmaPt_ = new TProfile("sigmaPtOverPt", "sigmaPt/Pt vs muon Pt", 1000, 0, 100);
  eventCounter_ = 0;
  // Create the corrector and set the parameters
  resolutionFunction_.reset(new ResolutionFunction( iConfig.getUntrackedParameter<std::string>("ResolutionsIdentifier") ) );
  std::cout << "resolutionFunction_ = " << &*resolutionFunction_ << std::endl;
}
TestResolution::~TestResolution ( )

Definition at line 36 of file TestResolution.cc.

References svgfig::canvas(), gather_cfg::cout, eventCounter_, outputFile_, and sigmaPt_.

{
  outputFile_->cd();
  TCanvas canvas("sigmaPtOverPt","sigmaPt/Pt vs muon Pt", 1000, 800);
  canvas.cd();
  sigmaPt_->GetXaxis()->SetTitle("Pt(GeV)");
//   TLegend * legend = new TLegend(0.7,0.71,0.98,1.);
//   legend->SetTextSize(0.02);
//   legend->SetFillColor(0); // Have a white background
//   legend->AddEntry(uncorrectedPt_, "original pt");
//   legend->AddEntry(correctedPt_, "corrected pt");
  sigmaPt_->Draw();
//   legend->Draw("same");

  canvas.Write();
  sigmaPt_->Write();
  outputFile_->Close();

  std::cout << "Total analyzed events = " << eventCounter_ << std::endl;
}

Member Function Documentation

void TestResolution::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
) [private, virtual]

Implements edm::EDAnalyzer.

Definition at line 63 of file TestResolution.cc.

References gather_cfg::cout, eventCounter_, fillMuonCollection(), edm::Event::getByLabel(), patZpeak::muons, resolutionFunction_, sigmaPt_, theMuonLabel_, theMuonType_, and testEve_cfg::tracks.

                                                                                {
  using namespace edm;

  ++eventCounter_;
  if ( eventCounter_%100 == 0 ) {
    std::cout << "Event number " << eventCounter_ << std::endl;
  }

  // Take the reco-muons, depending on the type selected in the cfg
  // --------------------------------------------------------------

  std::vector<reco::LeafCandidate> muons;

  if (theMuonType_==1) { // GlobalMuons
    Handle<reco::MuonCollection> glbMuons;
    iEvent.getByLabel (theMuonLabel_, glbMuons);
    muons = fillMuonCollection(*glbMuons);
  }
  else if (theMuonType_==2) { // StandaloneMuons
    Handle<reco::TrackCollection> saMuons;
    iEvent.getByLabel (theMuonLabel_, saMuons);
    muons = fillMuonCollection(*saMuons);
  }
  else if (theMuonType_==3) { // Tracker tracks
    Handle<reco::TrackCollection> tracks;
    iEvent.getByLabel (theMuonLabel_, tracks);
    muons = fillMuonCollection(*tracks);
  }

  // Loop on the recMuons
  std::vector<reco::LeafCandidate>::const_iterator recMuon = muons.begin();
  for ( ; recMuon!=muons.end(); ++recMuon ) {  

    // Fill the histogram with uncorrected pt values
    sigmaPt_->Fill(resolutionFunction_->sigmaPt(*recMuon, 0), recMuon->pt());

  }
}
virtual void TestResolution::endJob ( void  ) [inline, private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 61 of file TestResolution.h.

{};
template<typename T >
std::vector<reco::LeafCandidate> TestResolution::fillMuonCollection ( const std::vector< T > &  tracks) [inline, private]

Definition at line 63 of file TestResolution.h.

References RPCpg::mu, metsig::muon, patZpeak::muons, and mathSSE::sqrt().

Referenced by analyze().

                                                                               {
    std::vector<reco::LeafCandidate> muons;
    typename std::vector<T>::const_iterator track;
    for (track = tracks.begin(); track != tracks.end(); ++track){
      // Where 0.011163612 is the squared muon mass.
      reco::Particle::LorentzVector mu(track->px(),track->py(),track->pz(),
                                       sqrt(track->p()*track->p() + 0.011163612));
      reco::LeafCandidate muon(track->charge(),mu);
      // Store muon
      // ----------
      muons.push_back (muon);
    }
    return muons;
  } 

Member Data Documentation

Definition at line 90 of file TestResolution.h.

Referenced by analyze(), TestResolution(), and ~TestResolution().

TFile* TestResolution::outputFile_ [private]

Definition at line 86 of file TestResolution.h.

Referenced by TestResolution(), and ~TestResolution().

Definition at line 92 of file TestResolution.h.

Referenced by analyze(), and TestResolution().

TProfile* TestResolution::sigmaPt_ [private]

Definition at line 88 of file TestResolution.h.

Referenced by analyze(), TestResolution(), and ~TestResolution().

Definition at line 82 of file TestResolution.h.

Referenced by analyze().

Definition at line 84 of file TestResolution.h.

Referenced by analyze().

std::string TestResolution::theRootFileName_ [private]

Definition at line 85 of file TestResolution.h.

Referenced by TestResolution().