Skip to content

Commit

Permalink
Merge pull request #30782 from cms-sw/apply-new-ct-checks-for-analysis
Browse files Browse the repository at this point in the history
[Clang tidy] Apply checks for analysis
  • Loading branch information
cmsbuild authored Jul 19, 2020
2 parents cd5b24f + 60f0c9c commit 344c09f
Show file tree
Hide file tree
Showing 34 changed files with 108 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ bool ByMultiplicityEventFilter<T>::filter(edm::Event& iEvent, const edm::EventSe
m_multiplicities.getEvent(iEvent, iSetup);

bool value = m_selector(m_multiplicities);
iEvent.put(std::unique_ptr<bool>(new bool(value)));
iEvent.put(std::make_unique<bool>(value));

if (m_taggedMode)
return m_forcedValue;
Expand Down
4 changes: 2 additions & 2 deletions DPGAnalysis/SiStripTools/plugins/TrackerDpgAnalysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1508,12 +1508,12 @@ std::map<uint32_t, float> TrackerDpgAnalysis::delay(const std::vector<std::strin
// one line containing dcuid
if (pos != std::string::npos) {
// decode dcuid
std::string dcuids = line.substr(pos + 7, line.find(" ", pos) - pos - 8);
std::string dcuids = line.substr(pos + 7, line.find(' ', pos) - pos - 8);
std::istringstream dcuidstr(dcuids);
dcuidstr >> std::hex >> dcuid;
// decode delay
pos = line.find("difpll");
std::string diffs = line.substr(pos + 8, line.find(" ", pos) - pos - 9);
std::string diffs = line.substr(pos + 8, line.find(' ', pos) - pos - 9);
std::istringstream diffstr(diffs);
diffstr >> delay;
// fill the map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
#include "EgammaAnalysis/ElectronTools/interface/EpCombinationTool.h"
#include "EgammaAnalysis/ElectronTools/interface/ElectronEnergyCalibratorRun2.h"

#include <vector>
#include <random>
#include <memory>

#include <TRandom2.h>
#include <random>
#include <vector>

template <typename T>
class CalibratedElectronProducerRun2T : public edm::stream::EDProducer<> {
Expand Down Expand Up @@ -47,7 +49,7 @@ CalibratedElectronProducerRun2T<T>::CalibratedElectronProducerRun2T(const edm::P
conf.getParameter<bool>("isSynchronization"),
conf.getParameter<std::string>("correctionFile")) {
if (conf.existsAs<bool>("semiDeterministic") && conf.getParameter<bool>("semiDeterministic")) {
theSemiDeterministicRng.reset(new TRandom2());
theSemiDeterministicRng = std::make_unique<TRandom2>();
theEnCorrectorRun2.initPrivateRng(theSemiDeterministicRng.get());
}
produces<std::vector<T> >();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
#include "DataFormats/PatCandidates/interface/Photon.h"
#include "EgammaAnalysis/ElectronTools/interface/PhotonEnergyCalibratorRun2.h"

#include <vector>
#include <random>
#include <memory>

#include <TRandom2.h>
#include <random>
#include <vector>

template <typename T>
class CalibratedPhotonProducerRun2T : public edm::stream::EDProducer<> {
Expand All @@ -36,7 +38,7 @@ CalibratedPhotonProducerRun2T<T>::CalibratedPhotonProducerRun2T(const edm::Param
conf.getParameter<bool>("isSynchronization"),
conf.getParameter<std::string>("correctionFile")) {
if (conf.existsAs<bool>("semiDeterministic") && conf.getParameter<bool>("semiDeterministic")) {
theSemiDeterministicRng.reset(new TRandom2());
theSemiDeterministicRng = std::make_unique<TRandom2>();
theEnCorrectorRun2.initPrivateRng(theSemiDeterministicRng.get());
}
produces<std::vector<T> >();
Expand Down
12 changes: 6 additions & 6 deletions EgammaAnalysis/ElectronTools/src/EnergyScaleCorrection_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,11 @@ correctionCategory_class::correctionCategory_class(TString category_) {
etamax = 3;
} else {
if (p1 != std::string::npos) {
p1 = category.find("_", p1);
p2 = category.find("_", p1 + 1);
p1 = category.find('_', p1);
p2 = category.find('_', p1 + 1);
etamin = TString(category.substr(p1 + 1, p2 - p1 - 1)).Atof();
p1 = p2;
p2 = category.find("-", p1);
p2 = category.find('-', p1);
etamax = TString(category.substr(p1 + 1, p2 - p1 - 1)).Atof();
}
}
Expand Down Expand Up @@ -477,11 +477,11 @@ correctionCategory_class::correctionCategory_class(TString category_) {
// std::cout << "p1 = " << p1 << "\t" << std::string::npos << "\t" << category.size() << std::endl;
//std::cout << etmin << "\t" << etmax << "\t" << category.substr(p1+1, p2-p1-1) << "\t" << p1 << "\t" << p2 << std::endl;
if (p1 != std::string::npos) {
p1 = category.find("_", p1);
p2 = category.find("_", p1 + 1);
p1 = category.find('_', p1);
p2 = category.find('_', p1 + 1);
etmin = TString(category.substr(p1 + 1, p2 - p1 - 1)).Atof();
p1 = p2;
p2 = category.find("-", p1);
p2 = category.find('-', p1);
etmax = TString(category.substr(p1 + 1, p2 - p1 - 1)).Atof();
// std::cout << etmin << "\t" << etmax << "\t" << category.substr(p1 + 1, p2 - p1 - 1) << std::endl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ DistortedMuonProducerFromDB::~DistortedMuonProducerFromDB() {}
void DistortedMuonProducerFromDB::beginRun(const edm::Run&, const edm::EventSetup& iSetup) {
edm::ESHandle<MuScleFitDBobject> dbObject1;
iSetup.get<MuScleFitDBobjectRcd>().get(dbScaleLabel_, dbObject1);
momCorrector_.reset(new MomentumScaleCorrector(dbObject1.product()));
momCorrector_ = std::make_unique<MomentumScaleCorrector>(dbObject1.product());

LogTrace("") << ">>> Using database for momentum scale corrections !!";

edm::ESHandle<MuScleFitDBobject> dbObject2;
iSetup.get<MuScleFitDBobjectRcd>().get(dbDataResolutionLabel_, dbObject2);
momResolutionData_.reset(new ResolutionFunction(dbObject2.product()));
momResolutionData_ = std::make_unique<ResolutionFunction>(dbObject2.product());

edm::ESHandle<MuScleFitDBobject> dbObject3;
iSetup.get<MuScleFitDBobjectRcd>().get(dbMCResolutionLabel_, dbObject3);
momResolutionMC_.reset(new ResolutionFunction(dbObject3.product()));
momResolutionMC_ = std::make_unique<ResolutionFunction>(dbObject3.product());

LogTrace("") << ">>> Using database for momentum resolution corrections !!";
}
Expand Down
2 changes: 2 additions & 0 deletions ElectroWeakAnalysis/ZMuMu/plugins/dimuonHLTFilterCheck.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ vector<int> dimuonHLTFilterCheck::nDimuonsByType(const Handle<CandidateView> d)
int nCat =
10; // number of dimuon categories (0 = glb-glb, 1 = glb-trkSta, 2 = glb-sta, 3 = glb-trk, 4 = trkSta-trkSta, 5 = trkSta-sta, 6 = trkSta-trk, 7 = sta-sta, 8 = sta-trk, 9 trk-trk)
// reset vector
n_.reserve(nCat);
for (int i = 0; i < nCat; i++)
n_.push_back(0);
for (unsigned int i = 0; i < d->size(); ++i) { //loop on candidates
Expand Down Expand Up @@ -259,6 +260,7 @@ vector<int> dimuonHLTFilterCheck::nMuonsByType(const Handle<CandidateView> d) {
vector<int> n_;
int nCat = 4; // number of muon categories (0 = glb, 1 = trkSta, 2 = sta, 3 = trk)
// reset vector
n_.reserve(nCat);
for (int i = 0; i < nCat; i++)
n_.push_back(0);
for (unsigned int i = 0; i < d->size(); ++i) { //loop on candidates
Expand Down
16 changes: 9 additions & 7 deletions HeavyFlavorAnalysis/Onia2MuMu/src/OniaVtxReProducer.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include "HeavyFlavorAnalysis/Onia2MuMu/interface/OniaVtxReProducer.h"
#include <memory>

#include "DataFormats/Provenance/interface/ProductProvenance.h"
#include "FWCore/Common/interface/Provenance.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/Registry.h"
#include "HeavyFlavorAnalysis/Onia2MuMu/interface/OniaVtxReProducer.h"
#include "TrackingTools/Records/interface/TransientTrackRecord.h"
#include "TrackingTools/TransientTrack/interface/TransientTrack.h"
#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
#include "TrackingTools/Records/interface/TransientTrackRecord.h"
#include "FWCore/ParameterSet/interface/Registry.h"
#include "FWCore/Common/interface/Provenance.h"
#include "DataFormats/Provenance/interface/ProductProvenance.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

OniaVtxReProducer::OniaVtxReProducer(const edm::Handle<reco::VertexCollection> &handle, const edm::Event &iEvent) {
const edm::Provenance *prov = handle.provenance();
Expand Down Expand Up @@ -66,7 +68,7 @@ void OniaVtxReProducer::configure(const edm::ParameterSet &iConfig) {
config_ = iConfig;
tracksTag_ = iConfig.getParameter<edm::InputTag>("TrackLabel");
beamSpotTag_ = iConfig.getParameter<edm::InputTag>("beamSpotLabel");
algo_.reset(new PrimaryVertexProducerAlgorithm(iConfig));
algo_ = std::make_unique<PrimaryVertexProducerAlgorithm>(iConfig);
}

std::vector<TransientVertex> OniaVtxReProducer::makeVertices(const reco::TrackCollection &tracks,
Expand Down
4 changes: 2 additions & 2 deletions HeavyFlavorAnalysis/RecoDecay/src/BPHDecayMomentum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const vector<BPHRecoConstCandPtr>& BPHDecayMomentum::daughComp() const {
const reco::Candidate* BPHDecayMomentum::getDaug(const string& name) const {
// return a simple particle from the name
// return null pointer if not found
string::size_type pos = name.find("/");
string::size_type pos = name.find('/');
if (pos != string::npos) {
const BPHRecoCandidate* comp = getComp(name.substr(0, pos)).get();
return (comp == nullptr ? nullptr : comp->getDaug(name.substr(pos + 1)));
Expand All @@ -106,7 +106,7 @@ const reco::Candidate* BPHDecayMomentum::getDaug(const string& name) const {
BPHRecoConstCandPtr BPHDecayMomentum::getComp(const string& name) const {
// return a previously reconstructed particle from the name
// return null pointer if not found
string::size_type pos = name.find("/");
string::size_type pos = name.find('/');
if (pos != string::npos) {
const BPHRecoCandidate* comp = getComp(name.substr(0, pos)).get();
return (comp == nullptr ? nullptr : comp->getComp(name.substr(pos + 1)));
Expand Down
6 changes: 3 additions & 3 deletions HeavyFlavorAnalysis/RecoDecay/src/BPHKinematicFit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ double BPHKinematicFit::constrSigma() const { return massSigma; }

/// set a decaying daughter as an unique particle fitted independently
void BPHKinematicFit::setIndependentFit(const string& name, bool flag, double mass, double sigma) {
string::size_type pos = name.find("/");
string::size_type pos = name.find('/');
if (pos != string::npos) {
edm::LogPrint("WrongRequest") << "BPHKinematicFit::setIndependentFit: "
<< "cascade decay specification not admitted " << name;
Expand Down Expand Up @@ -147,7 +147,7 @@ vector<RefCountedKinematicParticle> BPHKinematicFit::kinParticles(const vector<s
insertParticle(allParticles[--j], plist, pset);
break;
}
string::size_type pos = pname.find("/");
string::size_type pos = pname.find('/');
if (pos != string::npos)
getParticles(pname.substr(0, pos), pname.substr(pos + 1), plist, pset);
else
Expand Down Expand Up @@ -449,7 +449,7 @@ void BPHKinematicFit::getParticles(const string& moth,
int n = daug.size();
for (i = 0; i < n; ++i) {
const string& name = daug[i];
string::size_type pos = name.find("/");
string::size_type pos = name.find('/');
if (pos != string::npos)
getParticles(moth + "/" + name.substr(0, pos), name.substr(pos + 1), kl, ks);
else
Expand Down
6 changes: 4 additions & 2 deletions JetMETCorrections/Algorithms/src/L1FastjetCorrectorImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
// 08/09/2009 Philipp Schieferdecker <[email protected]>
////////////////////////////////////////////////////////////////////////////////

#include "JetMETCorrections/Algorithms/interface/L1FastjetCorrectorImpl.h"
#include <memory>

#include "CondFormats/JetMETObjects/interface/JetCorrectorParameters.h"
#include "JetMETCorrections/Algorithms/interface/L1FastjetCorrectorImpl.h"
#include "JetMETCorrections/Objects/interface/JetCorrectionsRecord.h"

#include "FWCore/Utilities/interface/Exception.h"
Expand Down Expand Up @@ -39,7 +41,7 @@ std::unique_ptr<reco::JetCorrectorImpl> L1FastjetCorrectorImplMaker::make(edm::E

edm::Handle<double> hRho;
fEvent.getByToken(rhoToken_, hRho);
return std::unique_ptr<L1FastjetCorrectorImpl>(new L1FastjetCorrectorImpl(corrector, *hRho));
return std::make_unique<L1FastjetCorrectorImpl>(corrector, *hRho);
}

void L1FastjetCorrectorImplMaker::fillDescriptions(edm::ConfigurationDescriptions& iDescriptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ int main(int argc, char* argv[]) {
MuonPair(fromPtEtaPhiToPxPyPz(muon1), fromPtEtaPhiToPxPyPz(muon2), MuScleFitEvent(0, 0, 0, 0, 0, 0)));
}
}
size_t namePos = fileName.find_last_of("/");
size_t namePos = fileName.find_last_of('/');
treeHandler.writeTree(("tree_" + fileName.substr(namePos + 1, fileName.size())).c_str(), &pairVector);

// close input file
Expand Down
7 changes: 4 additions & 3 deletions MuonAnalysis/MomentumScaleCalibration/plugins/DBWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ DBWriter::DBWriter(const edm::ParameterSet& ps) {
std::string type(ps.getUntrackedParameter<std::string>("Type"));
// Create the corrector and set the parameters
if (type == "scale")
corrector_.reset(new MomentumScaleCorrector(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier")));
corrector_ =
std::make_unique<MomentumScaleCorrector>(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier"));
else if (type == "resolution")
corrector_.reset(new ResolutionFunction(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier")));
corrector_ = std::make_unique<ResolutionFunction>(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier"));
else if (type == "background")
corrector_.reset(new BackgroundFunction(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier")));
corrector_ = std::make_unique<BackgroundFunction>(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier"));
else {
std::cout << "Error: unrecognized type. Use one of those: 'scale', 'resolution', 'background'" << std::endl;
exit(1);
Expand Down
23 changes: 13 additions & 10 deletions MuonAnalysis/MomentumScaleCalibration/plugins/MuScleFit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include <CLHEP/Vector/LorentzVector.h>
#include <memory>

#include <vector>

#include "FWCore/Framework/interface/EventSetup.h"
Expand Down Expand Up @@ -556,16 +558,16 @@ MuScleFit::MuScleFit(const edm::ParameterSet& pset) : MuScleFitBase(pset), total
MuScleFitUtils::massWindowHalfWidth[2][4] = 0.2;
MuScleFitUtils::massWindowHalfWidth[2][5] = 0.2;

muonSelector_.reset(new MuScleFitMuonSelector(theMuonLabel_,
theMuonType_,
PATmuons_,
MuScleFitUtils::resfind,
MuScleFitUtils::speedup,
genParticlesName_,
compareToSimTracks_,
simTracksCollection_,
MuScleFitUtils::sherpa_,
debug_));
muonSelector_ = std::make_unique<MuScleFitMuonSelector>(theMuonLabel_,
theMuonType_,
PATmuons_,
MuScleFitUtils::resfind,
MuScleFitUtils::speedup,
genParticlesName_,
compareToSimTracks_,
simTracksCollection_,
MuScleFitUtils::sherpa_,
debug_);

MuScleFitUtils::backgroundHandler =
new BackgroundHandler(pset.getParameter<std::vector<int> >("BgrFitType"),
Expand Down Expand Up @@ -1219,6 +1221,7 @@ void MuScleFit::duringFastLoop() {
double deltalike;
if (loopCounter == 0) {
std::vector<double> initpar;
initpar.reserve((int)(MuScleFitUtils::parResol.size()));
for (int i = 0; i < (int)(MuScleFitUtils::parResol.size()); i++) {
initpar.push_back(MuScleFitUtils::parResol[i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,14 @@ TestCorrection::TestCorrection(const edm::ParameterSet& iConfig)
correctedPtVsEta_ = new TProfile("correctedPtVsEta", "corrected pt vs eta", 1000, 0, 100, -3., 3.);
eventCounter_ = 0;
// Create the corrector and set the parameters
corrector_.reset(new MomentumScaleCorrector(iConfig.getUntrackedParameter<std::string>("CorrectionsIdentifier")));
corrector_ =
std::make_unique<MomentumScaleCorrector>(iConfig.getUntrackedParameter<std::string>("CorrectionsIdentifier"));
std::cout << "corrector_ = " << &*corrector_ << std::endl;
resolution_.reset(new ResolutionFunction(iConfig.getUntrackedParameter<std::string>("ResolutionsIdentifier")));
resolution_ =
std::make_unique<ResolutionFunction>(iConfig.getUntrackedParameter<std::string>("ResolutionsIdentifier"));
std::cout << "resolution_ = " << &*resolution_ << std::endl;
background_.reset(new BackgroundFunction(iConfig.getUntrackedParameter<std::string>("BackgroundIdentifier")));
background_ =
std::make_unique<BackgroundFunction>(iConfig.getUntrackedParameter<std::string>("BackgroundIdentifier"));

// Initialize the parameters of MuScleFitUtils from those saved in the functions.
// MuScleFitUtils::parScale = corrector_.getFunction(0)->parameters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "TestResolution.h"

#include <memory>

#include "TCanvas.h"
#include "TLegend.h"

Expand Down Expand Up @@ -30,8 +32,8 @@ TestResolution::TestResolution(const edm::ParameterSet& iConfig)
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")));
resolutionFunction_ =
std::make_unique<ResolutionFunction>(iConfig.getUntrackedParameter<std::string>("ResolutionsIdentifier"));
std::cout << "resolutionFunction_ = " << &*resolutionFunction_ << std::endl;
}

Expand Down
2 changes: 1 addition & 1 deletion MuonAnalysis/MuonAssociators/plugins/MuonFSRProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ double MuonFSRProducer::computeRelativeIsolation(const pat::PackedCandidate& pho
const double& isoConeMin) const {
double ptsum = 0;

for (auto pfcand : pfcands) {
for (const auto& pfcand : pfcands) {
// Isolation cone requirement
double dRIsoCone = deltaR(photon.eta(), photon.phi(), pfcand.eta(), pfcand.phi());
if (dRIsoCone > isoConeMax)
Expand Down
2 changes: 1 addition & 1 deletion MuonAnalysis/MuonAssociators/plugins/MuonMCClassifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void MuonMCClassifier::produce(edm::Event &iEvent, const edm::EventSetup &iSetup
std::map<TrackingParticleRef, int> tpToSecondaries; // map from tp to (index+1) in output collection
std::vector<int> muToPrimary(nmu, -1), muToSecondary(nmu, -1); // map from input into (index) in output, -1 for null
if (linkToGenParticles_)
secondaries.reset(new reco::GenParticleCollection());
secondaries = std::make_unique<reco::GenParticleCollection>();

// loop on reco muons
for (size_t i = 0; i < nmu; ++i) {
Expand Down
8 changes: 4 additions & 4 deletions PhysicsTools/FWLite/src/CommandLineParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void CommandLineParser::parseArguments(int argc, char **argv, bool returnArgs) {
for (int loop = 1; loop < argc; ++loop) {
string arg = argv[loop];
m_fullArgVec.push_back(arg);
string::size_type where = arg.find_first_of("=");
string::size_type where = arg.find_first_of('=');
if (string::npos != where) {
if (_setVariableFromString(arg)) {
continue;
Expand All @@ -62,7 +62,7 @@ void CommandLineParser::parseArguments(int argc, char **argv, bool returnArgs) {
exit(0);
} // tag=value strings
else if (arg.at(0) == '-') {
string::size_type where = arg.find_first_not_of("-");
string::size_type where = arg.find_first_not_of('-');
if (string::npos == where) {
// a poorly formed option
cerr << "Don't understand: " << arg << endl;
Expand Down Expand Up @@ -147,7 +147,7 @@ void CommandLineParser::split(SVec &retval, string line, string match, bool igno
}

void CommandLineParser::removeComment(string &line) {
string::size_type location = line.find("#");
string::size_type location = line.find('#');
if (string::npos != location) {
// we've got a comment. Strip it out
line = line.substr(0, location - 1);
Expand Down Expand Up @@ -311,7 +311,7 @@ void CommandLineParser::printOptionValues() {
}

bool CommandLineParser::_setVariableFromString(const string &arg, bool dontOverrideChange, int offset) {
string::size_type where = arg.find_first_of("=", offset + 1);
string::size_type where = arg.find_first_of('=', offset + 1);
string varname = arg.substr(offset, where - offset);
string value = arg.substr(where + 1);
lowercaseString(varname);
Expand Down
Loading

0 comments on commit 344c09f

Please sign in to comment.