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::one::EDAnalyzer<> edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

 TestResolution (const edm::ParameterSet &)
 
 ~TestResolution () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer<>
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () 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 const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > 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
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) 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::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

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

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

Definition at line 51 of file TestResolution.cc.

Constructor & Destructor Documentation

◆ TestResolution()

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

Definition at line 97 of file TestResolution.cc.

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

98  : theMuonLabel_(iConfig.getParameter<edm::InputTag>("MuonLabel")),
99  glbMuonsToken_(mayConsume<reco::MuonCollection>(theMuonLabel_)),
100  saMuonsToken_(mayConsume<reco::TrackCollection>(theMuonLabel_)),
101  tracksToken_(mayConsume<reco::TrackCollection>(theMuonLabel_)),
102  theMuonType_(iConfig.getParameter<int>("MuonType")),
103  theRootFileName_(iConfig.getUntrackedParameter<std::string>("OutputFileName")) {
104  //now do what ever initialization is needed
105  outputFile_ = new TFile(theRootFileName_.c_str(), "RECREATE");
106  outputFile_->cd();
107  sigmaPt_ = new TProfile("sigmaPtOverPt", "sigmaPt/Pt vs muon Pt", 1000, 0, 100);
108  eventCounter_ = 0;
109  // Create the corrector and set the parameters
111  std::make_unique<ResolutionFunction>(iConfig.getUntrackedParameter<std::string>("ResolutionsIdentifier"));
112  std::cout << "resolutionFunction_ = " << &*resolutionFunction_ << std::endl;
113 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::EDGetTokenT< reco::TrackCollection > saMuonsToken_
std::string theRootFileName_
edm::EDGetTokenT< reco::TrackCollection > tracksToken_
T getUntrackedParameter(std::string const &, T const &) const
TProfile * sigmaPt_
edm::EDGetTokenT< reco::MuonCollection > glbMuonsToken_
std::unique_ptr< ResolutionFunction > resolutionFunction_
edm::InputTag theMuonLabel_

◆ ~TestResolution()

TestResolution::~TestResolution ( )
override

Definition at line 115 of file TestResolution.cc.

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

115  {
116  outputFile_->cd();
117  TCanvas canvas("sigmaPtOverPt", "sigmaPt/Pt vs muon Pt", 1000, 800);
118  canvas.cd();
119  sigmaPt_->GetXaxis()->SetTitle("Pt(GeV)");
120  // TLegend * legend = new TLegend(0.7,0.71,0.98,1.);
121  // legend->SetTextSize(0.02);
122  // legend->SetFillColor(0); // Have a white background
123  // legend->AddEntry(uncorrectedPt_, "original pt");
124  // legend->AddEntry(correctedPt_, "corrected pt");
125  sigmaPt_->Draw();
126  // legend->Draw("same");
127 
128  canvas.Write();
129  sigmaPt_->Write();
130  outputFile_->Close();
131 
132  std::cout << "Total analyzed events = " << eventCounter_ << std::endl;
133 }
TProfile * sigmaPt_
def canvas(sub, attr)
Definition: svgfig.py:482

Member Function Documentation

◆ analyze()

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

Implements edm::one::EDAnalyzerBase.

Definition at line 140 of file TestResolution.cc.

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

140  {
141  using namespace edm;
142 
143  ++eventCounter_;
144  if (eventCounter_ % 100 == 0) {
145  std::cout << "Event number " << eventCounter_ << std::endl;
146  }
147 
148  // Take the reco-muons, depending on the type selected in the cfg
149  // --------------------------------------------------------------
150 
151  std::vector<reco::LeafCandidate> muons;
152 
153  if (theMuonType_ == 1) { // GlobalMuons
155  iEvent.getByToken(glbMuonsToken_, glbMuons);
156  muons = fillMuonCollection(*glbMuons);
157  } else if (theMuonType_ == 2) { // StandaloneMuons
159  iEvent.getByToken(saMuonsToken_, saMuons);
160  muons = fillMuonCollection(*saMuons);
161  } else if (theMuonType_ == 3) { // Tracker tracks
163  iEvent.getByToken(tracksToken_, tracks);
165  }
166 
167  // Loop on the recMuons
168  std::vector<reco::LeafCandidate>::const_iterator recMuon = muons.begin();
169  for (; recMuon != muons.end(); ++recMuon) {
170  // Fill the histogram with uncorrected pt values
171  sigmaPt_->Fill(resolutionFunction_->sigmaPt(*recMuon, 0), recMuon->pt());
172  }
173 }
edm::EDGetTokenT< reco::TrackCollection > saMuonsToken_
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:212
edm::EDGetTokenT< reco::TrackCollection > tracksToken_
int iEvent
Definition: GenABIO.cc:224
std::vector< reco::LeafCandidate > fillMuonCollection(const std::vector< T > &tracks)
TProfile * sigmaPt_
HLT enums.
edm::EDGetTokenT< reco::MuonCollection > glbMuonsToken_
std::unique_ptr< ResolutionFunction > resolutionFunction_

◆ fillMuonCollection()

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

Definition at line 59 of file TestResolution.cc.

References amptDefaultParameters_cff::mu, HLT_2023v12_cff::muon, DiMuonV_cfg::muons, mathSSE::sqrt(), HLT_2023v12_cff::track, and DiMuonV_cfg::tracks.

Referenced by analyze().

59  {
60  std::vector<reco::LeafCandidate> muons;
61  typename std::vector<T>::const_iterator track;
62  for (track = tracks.begin(); track != tracks.end(); ++track) {
63  // Where 0.011163612 is the squared muon mass.
65  track->px(), track->py(), track->pz(), sqrt(track->p() * track->p() + 0.011163612));
66  reco::LeafCandidate muon(track->charge(), mu);
67  // Store muon
68  // ----------
69  muons.push_back(muon);
70  }
71  return muons;
72  }
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:212
T sqrt(T t)
Definition: SSEVec.h:19
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21

Member Data Documentation

◆ eventCounter_

int TestResolution::eventCounter_
private

Definition at line 89 of file TestResolution.cc.

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

◆ glbMuonsToken_

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

Definition at line 79 of file TestResolution.cc.

Referenced by analyze().

◆ outputFile_

TFile* TestResolution::outputFile_
private

Definition at line 85 of file TestResolution.cc.

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

◆ resolutionFunction_

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

Definition at line 91 of file TestResolution.cc.

Referenced by analyze(), and TestResolution().

◆ saMuonsToken_

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

Definition at line 80 of file TestResolution.cc.

Referenced by analyze().

◆ sigmaPt_

TProfile* TestResolution::sigmaPt_
private

Definition at line 87 of file TestResolution.cc.

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

◆ theMuonLabel_

edm::InputTag TestResolution::theMuonLabel_
private

Definition at line 78 of file TestResolution.cc.

◆ theMuonType_

int TestResolution::theMuonType_
private

Definition at line 83 of file TestResolution.cc.

Referenced by analyze().

◆ theRootFileName_

std::string TestResolution::theRootFileName_
private

Definition at line 84 of file TestResolution.cc.

Referenced by TestResolution().

◆ tracksToken_

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

Definition at line 81 of file TestResolution.cc.

Referenced by analyze().