CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
TestResolution Class Reference

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

Inheritance diagram for TestResolution:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

 TestResolution (const edm::ParameterSet &)
 
 ~TestResolution ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

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_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

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

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

Definition at line 53 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_, AlCaHLTBitMon_QueryRunRegistry::string, and theRootFileName_.

20  :
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 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::string theRootFileName_
TFile * outputFile_
std::auto_ptr< ResolutionFunction > resolutionFunction_
TProfile * sigmaPt_
tuple cout
Definition: gather_cfg.py:121
edm::InputTag theMuonLabel_
TestResolution::~TestResolution ( )

Definition at line 36 of file TestResolution.cc.

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

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 }
def canvas
Definition: svgfig.py:481
TFile * outputFile_
TProfile * sigmaPt_
tuple cout
Definition: gather_cfg.py:121

Member Function Documentation

void TestResolution::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
privatevirtual

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.

63  {
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 }
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_
virtual void TestResolution::endJob ( void  )
inlineprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 60 of file TestResolution.h.

60 {};
template<typename T >
std::vector<reco::LeafCandidate> TestResolution::fillMuonCollection ( const std::vector< T > &  tracks)
inlineprivate

Definition at line 62 of file TestResolution.h.

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

Referenced by analyze().

62  {
63  std::vector<reco::LeafCandidate> muons;
64  typename std::vector<T>::const_iterator track;
65  for (track = tracks.begin(); track != tracks.end(); ++track){
66  // Where 0.011163612 is the squared muon mass.
67  reco::Particle::LorentzVector mu(track->px(),track->py(),track->pz(),
68  sqrt(track->p()*track->p() + 0.011163612));
69  reco::LeafCandidate muon(track->charge(),mu);
70  // Store muon
71  // ----------
72  muons.push_back (muon);
73  }
74  return muons;
75  }
T sqrt(T t)
Definition: SSEVec.h:48
const int mu
Definition: Constants.h:22
tuple tracks
Definition: testEve_cfg.py:39
tuple muons
Definition: patZpeak.py:38
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:27

Member Data Documentation

int TestResolution::eventCounter_
private

Definition at line 89 of file TestResolution.h.

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

TFile* TestResolution::outputFile_
private

Definition at line 85 of file TestResolution.h.

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

std::auto_ptr<ResolutionFunction> TestResolution::resolutionFunction_
private

Definition at line 91 of file TestResolution.h.

Referenced by analyze(), and TestResolution().

TProfile* TestResolution::sigmaPt_
private

Definition at line 87 of file TestResolution.h.

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

edm::InputTag TestResolution::theMuonLabel_
private

Definition at line 81 of file TestResolution.h.

Referenced by analyze().

int TestResolution::theMuonType_
private

Definition at line 83 of file TestResolution.h.

Referenced by analyze().

std::string TestResolution::theRootFileName_
private

Definition at line 84 of file TestResolution.h.

Referenced by TestResolution().