CMS 3D CMS Logo

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 () override
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase &&)=default
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const * > *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

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

Private Attributes

int eventCounter_
 
edm::EDGetTokenT< reco::MuonCollectionglbMuonsToken_
 
TFile * outputFile_
 
std::unique_ptr< ResolutionFunctionresolutionFunction_
 
edm::EDGetTokenT< reco::TrackCollectionsaMuonsToken_
 
TProfile * sigmaPt_
 
edm::InputTag theMuonLabel_
 
int theMuonType_
 
std::string theRootFileName_
 
edm::EDGetTokenT< reco::TrackCollectiontracksToken_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsInputProcessBlocks ()
 
static bool wantsProcessBlocks ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< B > consumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes () noexcept
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag) noexcept
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (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::TestResolution ( const edm::ParameterSet iConfig)
explicit

Definition at line 22 of file TestResolution.cc.

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 }

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

◆ ~TestResolution()

TestResolution::~TestResolution ( )
override

Definition at line 40 of file TestResolution.cc.

40  {
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 }

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

Member Function Documentation

◆ analyze()

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

Implements edm::EDAnalyzer.

Definition at line 65 of file TestResolution.cc.

65  {
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 }

References gather_cfg::cout, eventCounter_, fillMuonCollection(), glbMuonsToken_, iEvent, PDWG_BPHSkim_cff::muons, resolutionFunction_, saMuonsToken_, sigmaPt_, theMuonType_, tracks, and tracksToken_.

◆ endJob()

void TestResolution::endJob ( void  )
inlineoverrideprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 60 of file TestResolution.h.

60 {};

◆ fillMuonCollection()

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

Definition at line 62 of file TestResolution.h.

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.
68  track->px(), track->py(), track->pz(), 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  }

References amptDefaultParameters_cff::mu, HLT_FULL_cff::muon, PDWG_BPHSkim_cff::muons, mathSSE::sqrt(), HLT_FULL_cff::track, and tracks.

Referenced by analyze().

Member Data Documentation

◆ eventCounter_

int TestResolution::eventCounter_
private

Definition at line 92 of file TestResolution.h.

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

◆ glbMuonsToken_

edm::EDGetTokenT<reco::MuonCollection> TestResolution::glbMuonsToken_
private

Definition at line 82 of file TestResolution.h.

Referenced by analyze().

◆ outputFile_

TFile* TestResolution::outputFile_
private

Definition at line 88 of file TestResolution.h.

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

◆ resolutionFunction_

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

Definition at line 94 of file TestResolution.h.

Referenced by analyze(), and TestResolution().

◆ saMuonsToken_

edm::EDGetTokenT<reco::TrackCollection> TestResolution::saMuonsToken_
private

Definition at line 83 of file TestResolution.h.

Referenced by analyze().

◆ sigmaPt_

TProfile* TestResolution::sigmaPt_
private

Definition at line 90 of file TestResolution.h.

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

◆ theMuonLabel_

edm::InputTag TestResolution::theMuonLabel_
private

Definition at line 81 of file TestResolution.h.

◆ theMuonType_

int TestResolution::theMuonType_
private

Definition at line 86 of file TestResolution.h.

Referenced by analyze().

◆ theRootFileName_

std::string TestResolution::theRootFileName_
private

Definition at line 87 of file TestResolution.h.

Referenced by TestResolution().

◆ tracksToken_

edm::EDGetTokenT<reco::TrackCollection> TestResolution::tracksToken_
private

Definition at line 84 of file TestResolution.h.

Referenced by analyze().

svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
muon
Definition: MuonCocktails.h:17
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
edm
HLT enums.
Definition: AlignableModifier.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
TestResolution::resolutionFunction_
std::unique_ptr< ResolutionFunction > resolutionFunction_
Definition: TestResolution.h:94
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::Handle< reco::MuonCollection >
reco::Particle::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
TestResolution::fillMuonCollection
std::vector< reco::LeafCandidate > fillMuonCollection(const std::vector< T > &tracks)
Definition: TestResolution.h:62
HLT_FULL_cff.muon
muon
Definition: HLT_FULL_cff.py:11710
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
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
tracks
const uint32_t *__restrict__ const HitContainer *__restrict__ TkSoA *__restrict__ tracks
Definition: CAHitNtupletGeneratorKernelsImpl.h:159
iEvent
int iEvent
Definition: GenABIO.cc:224
TestResolution::theMuonLabel_
edm::InputTag theMuonLabel_
Definition: TestResolution.h:81
TestResolution::saMuonsToken_
edm::EDGetTokenT< reco::TrackCollection > saMuonsToken_
Definition: TestResolution.h:83
TestResolution::theRootFileName_
std::string theRootFileName_
Definition: TestResolution.h:87
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
reco::LeafCandidate
Definition: LeafCandidate.h:16
TestResolution::outputFile_
TFile * outputFile_
Definition: TestResolution.h:88
edm::InputTag
Definition: InputTag.h:15
TestResolution::tracksToken_
edm::EDGetTokenT< reco::TrackCollection > tracksToken_
Definition: TestResolution.h:84
TestResolution::theMuonType_
int theMuonType_
Definition: TestResolution.h:86