diff --git a/MuonAnalysis/MomentumScaleCalibration/plugins/DBReader.cc b/MuonAnalysis/MomentumScaleCalibration/plugins/DBReader.cc index b1570cd6b72ea..3982db4ba43de 100644 --- a/MuonAnalysis/MomentumScaleCalibration/plugins/DBReader.cc +++ b/MuonAnalysis/MomentumScaleCalibration/plugins/DBReader.cc @@ -1,44 +1,92 @@ -// #include "CondFormats/PhysicsToolsObjects/interface/Histogram2D.h" -#include "CondFormats/RecoMuonObjects/interface/MuScleFitDBobject.h" +// system include files +#include +#include +#include +#include +#include + +// user include files #include "CondFormats/DataRecord/interface/MuScleFitDBobjectRcd.h" +#include "CondFormats/RecoMuonObjects/interface/MuScleFitDBobject.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "MuonAnalysis/MomentumScaleCalibration/interface/BackgroundFunction.h" +#include "MuonAnalysis/MomentumScaleCalibration/interface/MomentumScaleCorrector.h" +#include "MuonAnalysis/MomentumScaleCalibration/interface/ResolutionFunction.h" -#include "DBReader.h" +class DBReader : public edm::one::EDAnalyzer<> { +public: + explicit DBReader(const edm::ParameterSet&); + ~DBReader() override; + void initialize(const edm::EventSetup& iSetup); + void analyze(const edm::Event&, const edm::EventSetup&) override; -#include -#include -#include -#include +private: + template + void printParameters(const T& functionPtr) { + // Looping directly on it does not work, because it is returned by value + // and the iterator gets invalidated on the next line. Save it to a temporary object + // and iterate on it. + std::vector parVecVec(functionPtr->parameters()); + std::vector::const_iterator parVec = parVecVec.begin(); + std::vector functionId(functionPtr->identifiers()); + std::vector::const_iterator id = functionId.begin(); + edm::LogPrint("DBReader") << "total number of parameters read from database = parVecVec.size() = " + << parVecVec.size() << std::endl; + int iFunc = 0; + for (; id != functionId.end(); ++id, ++iFunc) { + int parNum = functionPtr->function(iFunc)->parNum(); + edm::LogPrint("DBReader") << "For function id = " << *id << ", with " << parNum << " parameters: " << std::endl; + for (int par = 0; par < parNum; ++par) { + edm::LogPrint("DBReader") << "par[" << par << "] = " << *parVec << std::endl; + ++parVec; + } + } + } -DBReader::DBReader(const edm::ParameterSet& iConfig) : type_(iConfig.getUntrackedParameter("Type")) {} + // uint32_t printdebug_; + const edm::ESGetToken muToken_; + const std::string type_; + //std::unique_ptr corrector_; + std::shared_ptr corrector_; + std::shared_ptr resolution_; + std::shared_ptr background_; +}; + +DBReader::DBReader(const edm::ParameterSet& iConfig) + : muToken_(esConsumes()), type_(iConfig.getUntrackedParameter("Type")) {} void DBReader::initialize(const edm::EventSetup& iSetup) { - edm::ESHandle dbObject; - iSetup.get().get(dbObject); + const MuScleFitDBobject* dbObject = &iSetup.getData(muToken_); edm::LogInfo("DBReader") << "[DBReader::analyze] End Reading MuScleFitDBobjectRcd" << std::endl; - - std::cout << "identifiers size from dbObject = " << dbObject->identifiers.size() << std::endl; - std::cout << "parameters size from dbObject = " << dbObject->parameters.size() << std::endl; - ; + edm::LogPrint("DBReader") << "identifiers size from dbObject = " << dbObject->identifiers.size() << std::endl; + edm::LogPrint("DBReader") << "parameters size from dbObject = " << dbObject->parameters.size() << std::endl; // This string is one of: scale, resolution, background. // Create the corrector and set the parameters if (type_ == "scale") - corrector_.reset(new MomentumScaleCorrector(dbObject.product())); + corrector_.reset(new MomentumScaleCorrector(dbObject)); else if (type_ == "resolution") - resolution_.reset(new ResolutionFunction(dbObject.product())); + resolution_.reset(new ResolutionFunction(dbObject)); else if (type_ == "background") - background_.reset(new BackgroundFunction(dbObject.product())); + background_.reset(new BackgroundFunction(dbObject)); else { - std::cout << "Error: unrecognized type. Use one of those: 'scale', 'resolution', 'background'" << std::endl; + edm::LogPrint("DBReader") << "Error: unrecognized type. Use one of those: 'scale', 'resolution', 'background'" + << std::endl; exit(1); } - // cout << "pointer = " << corrector_.get() << endl; } //: printdebug_(iConfig.getUntrackedParameter("printDebug",1)){} -DBReader::~DBReader() {} +DBReader::~DBReader() = default; void DBReader::analyze(const edm::Event& e, const edm::EventSetup& iSetup) { initialize(iSetup); diff --git a/MuonAnalysis/MomentumScaleCalibration/plugins/DBReader.h b/MuonAnalysis/MomentumScaleCalibration/plugins/DBReader.h deleted file mode 100644 index 838ec9dbc069a..0000000000000 --- a/MuonAnalysis/MomentumScaleCalibration/plugins/DBReader.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef DBReader_H -#define DBReader_H - -// system include files -//#include - -#include -#include - -// user include files -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDAnalyzer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/EventSetup.h" -#include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/ServiceRegistry/interface/Service.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include "MuonAnalysis/MomentumScaleCalibration/interface/MomentumScaleCorrector.h" -#include "MuonAnalysis/MomentumScaleCalibration/interface/ResolutionFunction.h" -#include "MuonAnalysis/MomentumScaleCalibration/interface/BackgroundFunction.h" - -class DBReader : public edm::EDAnalyzer { -public: - explicit DBReader(const edm::ParameterSet&); - ~DBReader() override; - - void initialize(const edm::EventSetup& iSetup); - - void analyze(const edm::Event&, const edm::EventSetup&) override; - -private: - template - void printParameters(const T& functionPtr) { - // Looping directly on it does not work, because it is returned by value - // and the iterator gets invalidated on the next line. Save it to a temporary object - // and iterate on it. - std::vector parVecVec(functionPtr->parameters()); - std::vector::const_iterator parVec = parVecVec.begin(); - std::vector functionId(functionPtr->identifiers()); - std::vector::const_iterator id = functionId.begin(); - std::cout << "total number of parameters read from database = parVecVec.size() = " << parVecVec.size() << std::endl; - int iFunc = 0; - for (; id != functionId.end(); ++id, ++iFunc) { - int parNum = functionPtr->function(iFunc)->parNum(); - std::cout << "For function id = " << *id << ", with " << parNum << " parameters: " << std::endl; - for (int par = 0; par < parNum; ++par) { - std::cout << "par[" << par << "] = " << *parVec << std::endl; - ++parVec; - } - } - } - - // uint32_t printdebug_; - std::string type_; - //std::unique_ptr corrector_; - std::shared_ptr corrector_; - std::shared_ptr resolution_; - std::shared_ptr background_; -}; -#endif diff --git a/MuonAnalysis/MomentumScaleCalibration/plugins/DBWriter.cc b/MuonAnalysis/MomentumScaleCalibration/plugins/DBWriter.cc index 9c48e06b49ecd..c5c703bc82e64 100644 --- a/MuonAnalysis/MomentumScaleCalibration/plugins/DBWriter.cc +++ b/MuonAnalysis/MomentumScaleCalibration/plugins/DBWriter.cc @@ -1,19 +1,29 @@ // system include files #include +#include // user include files -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDAnalyzer.h" +#include "CondCore/DBOutputService/interface/PoolDBOutputService.h" +#include "CondFormats/RecoMuonObjects/interface/MuScleFitDBobject.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" #include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" #include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" - -// Conditions database #include "FWCore/ServiceRegistry/interface/Service.h" -#include "CondCore/DBOutputService/interface/PoolDBOutputService.h" +#include "MuonAnalysis/MomentumScaleCalibration/interface/BackgroundFunction.h" +#include "MuonAnalysis/MomentumScaleCalibration/interface/MomentumScaleCorrector.h" +#include "MuonAnalysis/MomentumScaleCalibration/interface/ResolutionFunction.h" -#include "DBWriter.h" -#include "CondFormats/RecoMuonObjects/interface/MuScleFitDBobject.h" +class DBWriter : public edm::one::EDAnalyzer<> { +public: + explicit DBWriter(const edm::ParameterSet&); + ~DBWriter() override = default; + +private: + void analyze(const edm::Event&, const edm::EventSetup&) override; + std::unique_ptr corrector_; +}; DBWriter::DBWriter(const edm::ParameterSet& ps) { // This string is one of: scale, resolution, background. @@ -27,16 +37,12 @@ DBWriter::DBWriter(const edm::ParameterSet& ps) { else if (type == "background") corrector_ = std::make_unique(ps.getUntrackedParameter("CorrectionsIdentifier")); else { - std::cout << "Error: unrecognized type. Use one of those: 'scale', 'resolution', 'background'" << std::endl; + edm::LogPrint("DBWriter") << "Error: unrecognized type. Use one of those: 'scale', 'resolution', 'background'" + << std::endl; exit(1); } } -DBWriter::~DBWriter() { - // do anything here that needs to be done at desctruction time - // (e.g. close files, deallocate resources etc.) -} - // ------------ method called to for each event ------------ void DBWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { MuScleFitDBobject dbObject; @@ -45,18 +51,18 @@ void DBWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) dbObject.parameters = corrector_->parameters(); // if( dbObject->identifiers.size() != dbObject->parameters.size() ) { - // std::cout << "Error: size of parameters("<parameters.size()<<") and identifiers("<identifiers.size()<<") don't match" << std::endl; + // edm::LogPrint("DBWriter") << "Error: size of parameters("<parameters.size()<<") and identifiers("<identifiers.size()<<") don't match" << std::endl; // exit(1); // } // std::vector >::const_iterator parVec = dbObject->parameters.begin(); // std::vector::const_iterator id = dbObject->identifiers.begin(); // for( ; id != dbObject->identifiers.end(); ++id, ++parVec ) { - // std::cout << "id = " << *id << std::endl; + // edm::LogPrint("DBWriter") << "id = " << *id << std::endl; // std::vector::const_iterator par = parVec->begin(); // int i=0; // for( ; par != parVec->end(); ++par, ++i ) { - // std::cout << "par["< -#include - -class DBWriter : public edm::EDAnalyzer { -public: - explicit DBWriter(const edm::ParameterSet&); - ~DBWriter() override; - -private: - void analyze(const edm::Event&, const edm::EventSetup&) override; - void endJob() override{}; - - std::unique_ptr corrector_; -}; diff --git a/MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsAnalyzer.cc b/MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsAnalyzer.cc index d48e8cc687cb8..16514bf73bd1b 100644 --- a/MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsAnalyzer.cc +++ b/MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsAnalyzer.cc @@ -1,7 +1,98 @@ -#ifndef ERRORSANALYZER_CC -#define ERRORSANALYZER_CC - -#include "ErrorsAnalyzer.h" +// -*- C++ -*- +// +// Package: ErrorsAnalyzer +// Class: ErrorsAnalyzer +// +/**\class ErrorsAnalyzer ErrorsAnalyzer.cc MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsAnalyzer.cc + + Description: + + Implementation: + +*/ +// +// Original Author: Marco De Mattia +// Created: Thu Sep 11 12:16:00 CEST 2008 +// +// + +// system include files +#include +#include +#include + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include +#include +#include +#include +#include +#include + +#include "MuonAnalysis/MomentumScaleCalibration/interface/Functions.h" +#include "MuonAnalysis/MomentumScaleCalibration/interface/RootTreeHandler.h" +#include "MuScleFitUtils.h" + +// +// class declaration +// + +class ErrorsAnalyzer : public edm::one::EDAnalyzer<> { +public: + explicit ErrorsAnalyzer(const edm::ParameterSet&); + ~ErrorsAnalyzer() override; + +private: + void analyze(const edm::Event&, const edm::EventSetup&) override; + void fillHistograms(); + void drawHistograms(const TProfile* histo, + const TProfile* histoPlusErr, + const TProfile* histoMinusErr, + const TString& type); + void fillValueError(); + void endJob() override{}; + + TString treeFileName_; + int resolFitType_; + uint32_t maxEvents_; + TString outputFileName_; + int ptBins_; + double ptMin_; + double ptMax_; + int etaBins_; + double etaMin_; + double etaMax_; + bool debug_; + + std::vector parameters_; + std::vector errors_; + std::vector errorFactors_; + + std::vector valuePlusError_; + std::vector valueMinusError_; + + TProfile* sigmaPtVsEta_; + TProfile* sigmaPtVsEtaPlusErr_; + TProfile* sigmaPtVsEtaMinusErr_; + + TProfile* sigmaPtVsPt_; + TProfile* sigmaPtVsPtPlusErr_; + TProfile* sigmaPtVsPtMinusErr_; + + // Mass resolution + TProfile* sigmaMassVsEta_; + TProfile* sigmaMassVsEtaPlusErr_; + TProfile* sigmaMassVsEtaMinusErr_; + + TProfile* sigmaMassVsPt_; + TProfile* sigmaMassVsPtPlusErr_; + TProfile* sigmaMassVsPtMinusErr_; +}; ErrorsAnalyzer::ErrorsAnalyzer(const edm::ParameterSet& iConfig) : treeFileName_(iConfig.getParameter("InputFileName")), @@ -309,5 +400,3 @@ void ErrorsAnalyzer::fillHistograms() { //define this as a plug-in DEFINE_FWK_MODULE(ErrorsAnalyzer); - -#endif diff --git a/MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsAnalyzer.h b/MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsAnalyzer.h deleted file mode 100644 index 2fd6a1d3a4cc9..0000000000000 --- a/MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsAnalyzer.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef ERRORSANALYZER_HH -#define ERRORSANALYZER_HH - -// -*- C++ -*- -// -// Package: ErrorsAnalyzer -// Class: ErrorsAnalyzer -// -/**\class ErrorsAnalyzer ErrorsAnalyzer.cc MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsAnalyzer.cc - - Description: - - Implementation: - -*/ -// -// Original Author: Marco De Mattia -// Created: Thu Sep 11 12:16:00 CEST 2008 -// -// - -// system include files -#include -#include -#include - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDAnalyzer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include -#include -#include -#include -#include -#include - -#include "MuonAnalysis/MomentumScaleCalibration/interface/Functions.h" -#include "MuonAnalysis/MomentumScaleCalibration/interface/RootTreeHandler.h" -#include "MuScleFitUtils.h" - -// -// class declaration -// - -class ErrorsAnalyzer : public edm::EDAnalyzer { -public: - explicit ErrorsAnalyzer(const edm::ParameterSet&); - ~ErrorsAnalyzer() override; - -private: - void analyze(const edm::Event&, const edm::EventSetup&) override; - void fillHistograms(); - void drawHistograms(const TProfile* histo, - const TProfile* histoPlusErr, - const TProfile* histoMinusErr, - const TString& type); - void fillValueError(); - void endJob() override{}; - - TString treeFileName_; - int resolFitType_; - uint32_t maxEvents_; - TString outputFileName_; - int ptBins_; - double ptMin_; - double ptMax_; - int etaBins_; - double etaMin_; - double etaMax_; - bool debug_; - - std::vector parameters_; - std::vector errors_; - std::vector errorFactors_; - - std::vector valuePlusError_; - std::vector valueMinusError_; - - TProfile* sigmaPtVsEta_; - TProfile* sigmaPtVsEtaPlusErr_; - TProfile* sigmaPtVsEtaMinusErr_; - - TProfile* sigmaPtVsPt_; - TProfile* sigmaPtVsPtPlusErr_; - TProfile* sigmaPtVsPtMinusErr_; - - // Mass resolution - TProfile* sigmaMassVsEta_; - TProfile* sigmaMassVsEtaPlusErr_; - TProfile* sigmaMassVsEtaMinusErr_; - - TProfile* sigmaMassVsPt_; - TProfile* sigmaMassVsPtPlusErr_; - TProfile* sigmaMassVsPtMinusErr_; -}; - -#endif // RESOLUTIONANALYZER_HH diff --git a/MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsPropagationAnalyzer.cc b/MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsPropagationAnalyzer.cc index a518dac8593dc..1b0ff970536c0 100644 --- a/MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsPropagationAnalyzer.cc +++ b/MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsPropagationAnalyzer.cc @@ -1,7 +1,124 @@ -#ifndef ERRORSANALYZER_CC -#define ERRORSANALYZER_CC - -#include "ErrorsPropagationAnalyzer.h" +// -*- C++ -*- +// +// Package: ErrorsPropagationAnalyzer +// Class: ErrorsPropagationAnalyzer +// +/**\class ErrorsPropagationAnalyzer ErrorsPropagationAnalyzer.cc MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsPropagationAnalyzer.cc + + Description: + + Implementation: + +*/ +// +// Original Author: Marco De Mattia +// Created: Thu Sep 11 12:16:00 CEST 2008 +// +// + +// system include files +#include +#include +#include + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include +#include +#include +#include +#include +#include + +#include "MuonAnalysis/MomentumScaleCalibration/interface/Functions.h" +#include "MuonAnalysis/MomentumScaleCalibration/interface/RootTreeHandler.h" +#include "MuScleFitUtils.h" +#include "MuonAnalysis/MomentumScaleCalibration/interface/SigmaPtDiff.h" + +// +// class declaration +// + +class ErrorsPropagationAnalyzer : public edm::one::EDAnalyzer<> { +public: + explicit ErrorsPropagationAnalyzer(const edm::ParameterSet&); + ~ErrorsPropagationAnalyzer() override; + +private: + void analyze(const edm::Event&, const edm::EventSetup&) override; + void fillHistograms(); + void drawHistograms(const TProfile* histo, + const TProfile* histoPlusErr, + const TProfile* histoMinusErr, + const TString& type, + const TString& yLabel); + void fillValueError(); + void endJob() override{}; + /// Modified method to take into account the error + double massResolution(const lorentzVector& mu1, + const lorentzVector& mu2, + const std::vector& parval, + const double& sigmaPt1, + const double& sigmaPt2); + double massResolution(const lorentzVector& mu1, + const lorentzVector& mu2, + double* parval, + const double& sigmaPt1, + const double& sigmaPt2); + + TString treeFileName_; + int resolFitType_; + uint32_t maxEvents_; + TString outputFileName_; + int ptBins_; + double ptMin_; + double ptMax_; + int etaBins_; + double etaMin_; + double etaMax_; + bool debug_; + + double ptMinCut_, ptMaxCut_, etaMinCut_, etaMaxCut_; + + std::vector parameters_; + std::vector errors_; + std::vector errorFactors_; + + std::vector valuePlusError_; + std::vector valueMinusError_; + + TProfile* sigmaPtVsEta_; + TProfile* sigmaPtVsEtaPlusErr_; + TProfile* sigmaPtVsEtaMinusErr_; + + TProfile* sigmaPtVsPt_; + TProfile* sigmaPtVsPtPlusErr_; + TProfile* sigmaPtVsPtMinusErr_; + + TProfile* sigmaPtVsEtaDiff_; + TProfile* sigmaPtVsPtDiff_; + + // Mass resolution + TProfile* sigmaMassVsEta_; + TProfile* sigmaMassVsEtaPlusErr_; + TProfile* sigmaMassVsEtaMinusErr_; + + TProfile* sigmaMassVsPt_; + TProfile* sigmaMassVsPtPlusErr_; + TProfile* sigmaMassVsPtMinusErr_; + + TProfile* sigmaMassOverMassVsEta_; + TProfile* sigmaMassOverMassVsEtaPlusErr_; + TProfile* sigmaMassOverMassVsEtaMinusErr_; + + TProfile* sigmaMassOverMassVsPt_; + TProfile* sigmaMassOverMassVsPtPlusErr_; + TProfile* sigmaMassOverMassVsPtMinusErr_; +}; ErrorsPropagationAnalyzer::ErrorsPropagationAnalyzer(const edm::ParameterSet& iConfig) : treeFileName_(iConfig.getParameter("InputFileName")), @@ -483,5 +600,3 @@ void ErrorsPropagationAnalyzer::fillHistograms() { //define this as a plug-in DEFINE_FWK_MODULE(ErrorsPropagationAnalyzer); - -#endif diff --git a/MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsPropagationAnalyzer.h b/MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsPropagationAnalyzer.h deleted file mode 100644 index 00e8998b54d79..0000000000000 --- a/MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsPropagationAnalyzer.h +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef ERRORSANALYZER_HH -#define ERRORSANALYZER_HH - -// -*- C++ -*- -// -// Package: ErrorsPropagationAnalyzer -// Class: ErrorsPropagationAnalyzer -// -/**\class ErrorsPropagationAnalyzer ErrorsPropagationAnalyzer.cc MuonAnalysis/MomentumScaleCalibration/plugins/ErrorsPropagationAnalyzer.cc - - Description: - - Implementation: - -*/ -// -// Original Author: Marco De Mattia -// Created: Thu Sep 11 12:16:00 CEST 2008 -// -// - -// system include files -#include -#include -#include - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDAnalyzer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include -#include -#include -#include -#include -#include - -#include "MuonAnalysis/MomentumScaleCalibration/interface/Functions.h" -#include "MuonAnalysis/MomentumScaleCalibration/interface/RootTreeHandler.h" -#include "MuScleFitUtils.h" -#include "MuonAnalysis/MomentumScaleCalibration/interface/SigmaPtDiff.h" - -// -// class declaration -// - -class ErrorsPropagationAnalyzer : public edm::EDAnalyzer { -public: - explicit ErrorsPropagationAnalyzer(const edm::ParameterSet&); - ~ErrorsPropagationAnalyzer() override; - -private: - void analyze(const edm::Event&, const edm::EventSetup&) override; - void fillHistograms(); - void drawHistograms(const TProfile* histo, - const TProfile* histoPlusErr, - const TProfile* histoMinusErr, - const TString& type, - const TString& yLabel); - void fillValueError(); - void endJob() override{}; - /// Modified method to take into account the error - double massResolution(const lorentzVector& mu1, - const lorentzVector& mu2, - const std::vector& parval, - const double& sigmaPt1, - const double& sigmaPt2); - double massResolution(const lorentzVector& mu1, - const lorentzVector& mu2, - double* parval, - const double& sigmaPt1, - const double& sigmaPt2); - - TString treeFileName_; - int resolFitType_; - uint32_t maxEvents_; - TString outputFileName_; - int ptBins_; - double ptMin_; - double ptMax_; - int etaBins_; - double etaMin_; - double etaMax_; - bool debug_; - - double ptMinCut_, ptMaxCut_, etaMinCut_, etaMaxCut_; - - std::vector parameters_; - std::vector errors_; - std::vector errorFactors_; - - std::vector valuePlusError_; - std::vector valueMinusError_; - - TProfile* sigmaPtVsEta_; - TProfile* sigmaPtVsEtaPlusErr_; - TProfile* sigmaPtVsEtaMinusErr_; - - TProfile* sigmaPtVsPt_; - TProfile* sigmaPtVsPtPlusErr_; - TProfile* sigmaPtVsPtMinusErr_; - - TProfile* sigmaPtVsEtaDiff_; - TProfile* sigmaPtVsPtDiff_; - - // Mass resolution - TProfile* sigmaMassVsEta_; - TProfile* sigmaMassVsEtaPlusErr_; - TProfile* sigmaMassVsEtaMinusErr_; - - TProfile* sigmaMassVsPt_; - TProfile* sigmaMassVsPtPlusErr_; - TProfile* sigmaMassVsPtMinusErr_; - - TProfile* sigmaMassOverMassVsEta_; - TProfile* sigmaMassOverMassVsEtaPlusErr_; - TProfile* sigmaMassOverMassVsEtaMinusErr_; - - TProfile* sigmaMassOverMassVsPt_; - TProfile* sigmaMassOverMassVsPtPlusErr_; - TProfile* sigmaMassOverMassVsPtMinusErr_; -}; - -#endif // RESOLUTIONANALYZER_HH diff --git a/MuonAnalysis/MomentumScaleCalibration/plugins/MuScleFitFilter.cc b/MuonAnalysis/MomentumScaleCalibration/plugins/MuScleFitFilter.cc index 617e2256eb96b..8cf6e88f93d06 100644 --- a/MuonAnalysis/MomentumScaleCalibration/plugins/MuScleFitFilter.cc +++ b/MuonAnalysis/MomentumScaleCalibration/plugins/MuScleFitFilter.cc @@ -5,7 +5,7 @@ // User include files // ------------------ #include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDFilter.h" +#include "FWCore/Framework/interface/stream/EDFilter.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/Utilities/interface/InputTag.h" @@ -33,14 +33,13 @@ // Class declaration // ----------------- -class MuScleFitFilter : public edm::EDFilter { +class MuScleFitFilter : public edm::stream::EDFilter<> { public: explicit MuScleFitFilter(const edm::ParameterSet&); ~MuScleFitFilter() override; private: bool filter(edm::Event&, const edm::EventSetup&) override; - void endJob() override{}; // Member data // ----------- @@ -71,7 +70,7 @@ MuScleFitFilter::MuScleFitFilter(const edm::ParameterSet& iConfig) { debug = iConfig.getUntrackedParameter("debug", false); if (debug) - std::cout << "Constructor" << std::endl; + edm::LogPrint("MuScleFitFilter") << "Constructor" << std::endl; // Parameters // ---------- @@ -102,8 +101,8 @@ MuScleFitFilter::MuScleFitFilter(const edm::ParameterSet& iConfig) { // Destructor // ---------- MuScleFitFilter::~MuScleFitFilter() { - std::cout << "Total number of events read = " << eventsRead << std::endl; - std::cout << "Total number of events written = " << eventsWritten << std::endl; + edm::LogPrint("MuScleFitFilter") << "Total number of events read = " << eventsRead << std::endl; + edm::LogPrint("MuScleFitFilter") << "Total number of events written = " << eventsWritten << std::endl; } // Member functions @@ -122,7 +121,7 @@ bool MuScleFitFilter::filter(edm::Event& event, const edm::EventSetup& iSetup) { std::unique_ptr muons(new reco::MuonCollection()); if (debug) - std::cout << "Looking for muons of the right kind" << std::endl; + edm::LogPrint("MuScleFitFilter") << "Looking for muons of the right kind" << std::endl; if (theMuonType == 1) { // GlobalMuons @@ -130,10 +129,10 @@ bool MuScleFitFilter::filter(edm::Event& event, const edm::EventSetup& iSetup) { // ------------- edm::Handle glbMuons; if (debug) - std::cout << "Handle defined" << std::endl; + edm::LogPrint("MuScleFitFilter") << "Handle defined" << std::endl; event.getByToken(theGlbMuonsToken, glbMuons); if (debug) - std::cout << "Global muons: " << glbMuons->size() << std::endl; + edm::LogPrint("MuScleFitFilter") << "Global muons: " << glbMuons->size() << std::endl; // Store the muon // -------------- @@ -141,8 +140,8 @@ bool MuScleFitFilter::filter(edm::Event& event, const edm::EventSetup& iSetup) { for (glbMuon = glbMuons->begin(); glbMuon != glbMuons->end(); ++glbMuon) { muons->push_back(*glbMuon); if (debug) { - std::cout << " Reconstructed muon: pT = " << glbMuon->p4().Pt() << " Eta = " << glbMuon->p4().Eta() - << std::endl; + edm::LogPrint("MuScleFitFilter") << " Reconstructed muon: pT = " << glbMuon->p4().Pt() + << " Eta = " << glbMuon->p4().Eta() << std::endl; } } } else if (theMuonType == 2) { // StandaloneMuons @@ -152,7 +151,7 @@ bool MuScleFitFilter::filter(edm::Event& event, const edm::EventSetup& iSetup) { edm::Handle saMuons; event.getByToken(theSaMuonsToken, saMuons); if (debug) - std::cout << "Standalone muons: " << saMuons->size() << std::endl; + edm::LogPrint("MuScleFitFilter") << "Standalone muons: " << saMuons->size() << std::endl; // Store the muon // -------------- @@ -172,7 +171,7 @@ bool MuScleFitFilter::filter(edm::Event& event, const edm::EventSetup& iSetup) { edm::Handle tracks; event.getByToken(theTracksToken, tracks); if (debug) - std::cout << "Tracker tracks: " << tracks->size() << std::endl; + edm::LogPrint("MuScleFitFilter") << "Tracker tracks: " << tracks->size() << std::endl; // Store the muon // ------------- @@ -186,7 +185,7 @@ bool MuScleFitFilter::filter(edm::Event& event, const edm::EventSetup& iSetup) { muons->push_back(muon); } } else { - std::cout << "Wrong muon type! Aborting." << std::endl; + edm::LogPrint("MuScleFitFilter") << "Wrong muon type! Aborting." << std::endl; abort(); } @@ -201,7 +200,8 @@ bool MuScleFitFilter::filter(edm::Event& event, const edm::EventSetup& iSetup) { if (muons->size() >= minimumMuonsNumber) { for (muon1 = muons->begin(); muon1 != muons->end(); ++muon1) { if (debug) { - std::cout << " Reconstructed muon: pT = " << muon1->p4().Pt() << " Eta = " << muon1->p4().Eta() << std::endl; + edm::LogPrint("MuScleFitFilter") << " Reconstructed muon: pT = " << muon1->p4().Pt() + << " Eta = " << muon1->p4().Eta() << std::endl; } // Recombine all the possible Z from reconstructed muons @@ -221,25 +221,25 @@ bool MuScleFitFilter::filter(edm::Event& event, const edm::EventSetup& iSetup) { if (*mMinCut == *mMaxCut && *mMaxCut == -1) { resfound = true; if (debug) { - std::cout << "Acceptiong event because mMinCut = " << *mMinCut << " = mMaxCut = " << *mMaxCut - << std::endl; + edm::LogPrint("MuScleFitFilter") + << "Acceptiong event because mMinCut = " << *mMinCut << " = mMaxCut = " << *mMaxCut << std::endl; } } else if (Z.mass() > *mMinCut && Z.mass() < *mMaxCut) { resfound = true; if (debug) { - std::cout << "One particle found with mass = " << Z.mass() << std::endl; + edm::LogPrint("MuScleFitFilter") << "One particle found with mass = " << Z.mass() << std::endl; } } } } } } else if (debug) { - std::cout << "Not enough reconstructed muons to make a resonance" << std::endl; + edm::LogPrint("MuScleFitFilter") << "Not enough reconstructed muons to make a resonance" << std::endl; } } } else if (debug) { - std::cout << "Skipping event because muons = " << muons->size() << " < " - << "minimumMuonsNumber(" << minimumMuonsNumber << ")" << std::endl; + edm::LogPrint("MuScleFitFilter") << "Skipping event because muons = " << muons->size() << " < " + << "minimumMuonsNumber(" << minimumMuonsNumber << ")" << std::endl; } // Store the event if it has a dimuon pair with mass within defined boundaries diff --git a/MuonAnalysis/MomentumScaleCalibration/plugins/MuScleFitGenFilter.cc b/MuonAnalysis/MomentumScaleCalibration/plugins/MuScleFitGenFilter.cc index 105b36c6d13e2..0e18fc1e0f481 100644 --- a/MuonAnalysis/MomentumScaleCalibration/plugins/MuScleFitGenFilter.cc +++ b/MuonAnalysis/MomentumScaleCalibration/plugins/MuScleFitGenFilter.cc @@ -8,7 +8,7 @@ // User include files // ------------------ #include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDFilter.h" +#include "FWCore/Framework/interface/stream/EDFilter.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" @@ -29,14 +29,13 @@ // Class declaration // ----------------- -class MuScleFitGenFilter : public edm::EDFilter { +class MuScleFitGenFilter : public edm::stream::EDFilter<> { public: explicit MuScleFitGenFilter(const edm::ParameterSet&); ~MuScleFitGenFilter() override; private: bool filter(edm::Event&, const edm::EventSetup&) override; - void endJob() override{}; std::string genParticlesName_; edm::EDGetTokenT evtMCToken_; @@ -59,8 +58,8 @@ MuScleFitGenFilter::MuScleFitGenFilter(const edm::ParameterSet& iConfig) // Destructor // ---------- MuScleFitGenFilter::~MuScleFitGenFilter() { - std::cout << "Total number of events = " << totalEvents_ << std::endl; - std::cout << "Events passing the filter = " << eventsPassingTheFilter_ << std::endl; + edm::LogPrint("MuScleFitGenFilter") << "Total number of events = " << totalEvents_ << std::endl; + edm::LogPrint("MuScleFitGenFilter") << "Events passing the filter = " << eventsPassingTheFilter_ << std::endl; } // Method called for each event @@ -81,7 +80,7 @@ bool MuScleFitGenFilter::filter(edm::Event& event, const edm::EventSetup& iSetup if (genParticles.isValid()) { genPair = MuScleFitUtils::findGenMuFromRes(genParticles.product()); } else { - std::cout << "ERROR: no generator info found" << std::endl; + edm::LogPrint("MuScleFitGenFilter") << "ERROR: no generator info found" << std::endl; return false; } } diff --git a/MuonAnalysis/MomentumScaleCalibration/plugins/MuScleFitMuonProducer.cc b/MuonAnalysis/MomentumScaleCalibration/plugins/MuScleFitMuonProducer.cc index 8384eb6766350..ed6e61e80fad3 100644 --- a/MuonAnalysis/MomentumScaleCalibration/plugins/MuScleFitMuonProducer.cc +++ b/MuonAnalysis/MomentumScaleCalibration/plugins/MuScleFitMuonProducer.cc @@ -18,60 +18,51 @@ #include // user include files -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDProducer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/Utilities/interface/InputTag.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - +#include "CondFormats/DataRecord/interface/MuScleFitDBobjectRcd.h" +#include "CondFormats/RecoMuonObjects/interface/MuScleFitDBobject.h" +#include "DataFormats/Candidate/interface/LeafCandidate.h" #include "DataFormats/MuonReco/interface/Muon.h" #include "DataFormats/MuonReco/interface/MuonFwd.h" -#include "DataFormats/Candidate/interface/LeafCandidate.h" - -#include "DataFormats/TrackReco/interface/Track.h" -#include "DataFormats/PatCandidates/interface/Muon.h" #include "DataFormats/PatCandidates/interface/CompositeCandidate.h" - -#include "MuonAnalysis/MomentumScaleCalibration/interface/Functions.h" - -#include "CondFormats/RecoMuonObjects/interface/MuScleFitDBobject.h" -#include "CondFormats/DataRecord/interface/MuScleFitDBobjectRcd.h" - -#include "FWCore/Framework/interface/EventSetup.h" +#include "DataFormats/PatCandidates/interface/Muon.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" #include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/InputTag.h" +#include "MuonAnalysis/MomentumScaleCalibration/interface/Functions.h" #include "MuonAnalysis/MomentumScaleCalibration/interface/MomentumScaleCorrector.h" -class MuScleFitMuonProducer : public edm::EDProducer { +class MuScleFitMuonProducer : public edm::stream::EDProducer<> { public: explicit MuScleFitMuonProducer(const edm::ParameterSet&); ~MuScleFitMuonProducer() override; private: - void beginJob() override; void produce(edm::Event&, const edm::EventSetup&) override; - void endJob() override; template std::unique_ptr applyCorrection(const edm::Handle& allMuons); + const edm::ESGetToken muToken_; + const edm::InputTag theMuonLabel_; + const edm::EDGetTokenT thePatMuonToken_; + const edm::EDGetTokenT theRecoMuonToken_; + const bool patMuons_; - edm::InputTag theMuonLabel_; - edm::EDGetTokenT thePatMuonToken_; - edm::EDGetTokenT theRecoMuonToken_; - bool patMuons_; edm::ESHandle dbObject_; - std::string dbObjectLabel_; unsigned long long dbObjectCacheId_; std::shared_ptr corrector_; }; MuScleFitMuonProducer::MuScleFitMuonProducer(const edm::ParameterSet& iConfig) - : theMuonLabel_(iConfig.getParameter("MuonLabel")), + : muToken_(esConsumes(edm::ESInputTag("", iConfig.getUntrackedParameter("DbObjectLabel", "")))), + theMuonLabel_(iConfig.getParameter("MuonLabel")), thePatMuonToken_(mayConsume(theMuonLabel_)), theRecoMuonToken_(mayConsume(theMuonLabel_)), patMuons_(iConfig.getParameter("PatMuons")), - dbObjectLabel_(iConfig.getUntrackedParameter("DbObjectLabel", "")), dbObjectCacheId_(0) { if (patMuons_ == true) { produces(); @@ -80,7 +71,7 @@ MuScleFitMuonProducer::MuScleFitMuonProducer(const edm::ParameterSet& iConfig) } } -MuScleFitMuonProducer::~MuScleFitMuonProducer() {} +MuScleFitMuonProducer::~MuScleFitMuonProducer() = default; template std::unique_ptr MuScleFitMuonProducer::applyCorrection(const edm::Handle& allMuons) { @@ -106,11 +97,7 @@ std::unique_ptr MuScleFitMuonProducer::applyCorrection(const edm::Handle& void MuScleFitMuonProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { unsigned long long dbObjectCacheId = iSetup.get().cacheIdentifier(); if (dbObjectCacheId != dbObjectCacheId_) { - if (!dbObjectLabel_.empty()) { - iSetup.get().get(dbObjectLabel_, dbObject_); - } else { - iSetup.get().get(dbObject_); - } + dbObject_ = iSetup.getHandle(muToken_); } //std::cout << "identifiers size from dbObject = " << dbObject_->identifiers.size() << std::endl; @@ -150,11 +137,5 @@ void MuScleFitMuonProducer::produce(edm::Event& iEvent, const edm::EventSetup& i */ } -// ------------ method called once each job just before starting event loop ------------ -void MuScleFitMuonProducer::beginJob() {} - -// ------------ method called once each job just after ending the event loop ------------ -void MuScleFitMuonProducer::endJob() {} - //define this as a plug-in DEFINE_FWK_MODULE(MuScleFitMuonProducer); diff --git a/MuonAnalysis/MomentumScaleCalibration/plugins/ResolutionAnalyzer.cc b/MuonAnalysis/MomentumScaleCalibration/plugins/ResolutionAnalyzer.cc index a890add1fd6a8..af87d09702c55 100644 --- a/MuonAnalysis/MomentumScaleCalibration/plugins/ResolutionAnalyzer.cc +++ b/MuonAnalysis/MomentumScaleCalibration/plugins/ResolutionAnalyzer.cc @@ -1,18 +1,123 @@ -#ifndef RESOLUTIONANALYZER_CC -#define RESOLUTIONANALYZER_CC +// -*- C++ -*- +// +// Package: ResolutionAnalyzer +// Class: ResolutionAnalyzer +// +/**\class ResolutionAnalyzer ResolutionAnalyzer.cc MuonAnalysis/MomentumScaleCalibration/plugins/ResolutionAnalyzer.cc -#include "ResolutionAnalyzer.h" -#include "MuonAnalysis/MomentumScaleCalibration/interface/Functions.h" -#include "MuonAnalysis/MomentumScaleCalibration/interface/RootTreeHandler.h" + Description: + Implementation: + +*/ +// +// Original Author: Marco De Mattia +// Created: Thu Sep 11 12:16:00 CEST 2008 // -// constants, enums and typedefs // +// system include files +#include +#include +#include +#include + +// user include files +#include "DataFormats/Candidate/interface/Candidate.h" +#include "DataFormats/Candidate/interface/LeafCandidate.h" +#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" +#include "DataFormats/MuonReco/interface/Muon.h" +#include "DataFormats/MuonReco/interface/MuonFwd.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "HepMC/GenEvent.h" +#include "HepMC/GenParticle.h" +#include "HepPDT/ParticleDataTable.hh" +#include "HepPDT/TableBuilder.hh" +#include "HepPDT/defs.h" +#include "MuonAnalysis/MomentumScaleCalibration/interface/Functions.h" +#include "MuonAnalysis/MomentumScaleCalibration/interface/RootTreeHandler.h" +#include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h" +#include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h" +#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" +#include "SimDataFormats/Track/interface/SimTrackContainer.h" +#include "SimDataFormats/Vertex/interface/SimVertexContainer.h" +#include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h" + +#include "Histograms.h" +#include "MuScleFitUtils.h" // -// static data member definitions +// class decleration // +class ResolutionAnalyzer : public edm::one::EDAnalyzer<> { +public: + explicit ResolutionAnalyzer(const edm::ParameterSet&); + ~ResolutionAnalyzer() override; + +private: + void analyze(const edm::Event&, const edm::EventSetup&) override; + void endJob() override{}; + + template + std::vector fillMuonCollection(const std::vector& tracks) { + std::vector muons; + typename std::vector::const_iterator track; + for (track = tracks.begin(); track != tracks.end(); ++track) { + reco::Particle::LorentzVector mu( + track->px(), track->py(), track->pz(), sqrt(track->p() * track->p() + MuScleFitUtils::mMu2)); + MuScleFitUtils::goodmuon++; + if (debug_ > 0) + std::cout << std::setprecision(9) << "Muon #" << MuScleFitUtils::goodmuon + << ": initial value Pt = " << mu.Pt() << std::endl; + reco::LeafCandidate muon(track->charge(), mu); + // Store muon + // ---------- + muons.push_back(muon); + } + return muons; + } + + /// Used to fill the map with the histograms needed + void fillHistoMap(); + /// Writes the histograms in the map + void writeHistoMap(); + /// Returns true if the two particles have DeltaR < cut + bool checkDeltaR(const reco::Particle::LorentzVector& genMu, const reco::Particle::LorentzVector& recMu); + + // ----------member data --------------------------- + + // Collections labels + // ------------------ + edm::InputTag theMuonLabel_; + + int theMuonType_; + std::string theRootFileName_; + std::string theCovariancesRootFileName_; + bool debug_; + std::map mapHisto_; + TFile* outputFile_; + + int eventCounter_; + bool resonance_; + bool readCovariances_; + + TString treeFileName_; + int32_t maxEvents_; + + double ptMax_; + + HCovarianceVSxy* massResolutionVsPtEta_; + TH2D* recoPtVsgenPt_; + TH2D* recoPtVsgenPtEta12_; + TH1D* deltaPtOverPt_; + TH1D* deltaPtOverPtForEta12_; +}; + // // constructors and destructor // @@ -592,5 +697,3 @@ bool ResolutionAnalyzer::checkDeltaR(const reco::Particle::LorentzVector& genMu, //define this as a plug-in DEFINE_FWK_MODULE(ResolutionAnalyzer); - -#endif // RESOLUTIONANALYZER_CC diff --git a/MuonAnalysis/MomentumScaleCalibration/plugins/ResolutionAnalyzer.h b/MuonAnalysis/MomentumScaleCalibration/plugins/ResolutionAnalyzer.h deleted file mode 100644 index e7fe40d2e6aea..0000000000000 --- a/MuonAnalysis/MomentumScaleCalibration/plugins/ResolutionAnalyzer.h +++ /dev/null @@ -1,129 +0,0 @@ -#ifndef RESOLUTIONANALYZER_HH -#define RESOLUTIONANALYZER_HH - -// -*- C++ -*- -// -// Package: ResolutionAnalyzer -// Class: ResolutionAnalyzer -// -/**\class ResolutionAnalyzer ResolutionAnalyzer.cc MuonAnalysis/MomentumScaleCalibration/plugins/ResolutionAnalyzer.cc - - Description: - - Implementation: - -*/ -// -// Original Author: Marco De Mattia -// Created: Thu Sep 11 12:16:00 CEST 2008 -// -// - -// system include files -#include -#include -#include - -// user include files -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDAnalyzer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include "DataFormats/TrackReco/interface/Track.h" -#include "DataFormats/MuonReco/interface/Muon.h" -#include "DataFormats/MuonReco/interface/MuonFwd.h" -#include "DataFormats/Candidate/interface/Candidate.h" -#include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h" -#include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h" - -#include "HepPDT/defs.h" -#include "HepPDT/TableBuilder.hh" -#include "HepPDT/ParticleDataTable.hh" - -#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" -#include "HepMC/GenParticle.h" -#include "HepMC/GenEvent.h" -// #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h" -#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" - -#include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h" -#include "SimDataFormats/Track/interface/SimTrackContainer.h" -#include "SimDataFormats/Vertex/interface/SimVertexContainer.h" - -#include - -#include "DataFormats/Candidate/interface/LeafCandidate.h" - -#include "Histograms.h" -#include "MuScleFitUtils.h" -// -// class decleration -// - -class ResolutionAnalyzer : public edm::EDAnalyzer { -public: - explicit ResolutionAnalyzer(const edm::ParameterSet&); - ~ResolutionAnalyzer() override; - -private: - void analyze(const edm::Event&, const edm::EventSetup&) override; - void endJob() override{}; - - template - std::vector fillMuonCollection(const std::vector& tracks) { - std::vector muons; - typename std::vector::const_iterator track; - for (track = tracks.begin(); track != tracks.end(); ++track) { - reco::Particle::LorentzVector mu( - track->px(), track->py(), track->pz(), sqrt(track->p() * track->p() + MuScleFitUtils::mMu2)); - MuScleFitUtils::goodmuon++; - if (debug_ > 0) - std::cout << std::setprecision(9) << "Muon #" << MuScleFitUtils::goodmuon - << ": initial value Pt = " << mu.Pt() << std::endl; - reco::LeafCandidate muon(track->charge(), mu); - // Store muon - // ---------- - muons.push_back(muon); - } - return muons; - } - - /// Used to fill the map with the histograms needed - void fillHistoMap(); - /// Writes the histograms in the map - void writeHistoMap(); - /// Returns true if the two particles have DeltaR < cut - bool checkDeltaR(const reco::Particle::LorentzVector& genMu, const reco::Particle::LorentzVector& recMu); - - // ----------member data --------------------------- - - // Collections labels - // ------------------ - edm::InputTag theMuonLabel_; - - int theMuonType_; - std::string theRootFileName_; - std::string theCovariancesRootFileName_; - bool debug_; - std::map mapHisto_; - TFile* outputFile_; - - int eventCounter_; - bool resonance_; - bool readCovariances_; - - TString treeFileName_; - int32_t maxEvents_; - - double ptMax_; - - HCovarianceVSxy* massResolutionVsPtEta_; - TH2D* recoPtVsgenPt_; - TH2D* recoPtVsgenPtEta12_; - TH1D* deltaPtOverPt_; - TH1D* deltaPtOverPtForEta12_; -}; - -#endif // RESOLUTIONANALYZER_HH diff --git a/MuonAnalysis/MomentumScaleCalibration/plugins/TestCorrection.cc b/MuonAnalysis/MomentumScaleCalibration/plugins/TestCorrection.cc index 1c4805a9e8f3a..ab4ea1896d316 100644 --- a/MuonAnalysis/MomentumScaleCalibration/plugins/TestCorrection.cc +++ b/MuonAnalysis/MomentumScaleCalibration/plugins/TestCorrection.cc @@ -26,7 +26,7 @@ // user include files #include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDAnalyzer.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" @@ -57,7 +57,7 @@ // class decleration // -class TestCorrection : public edm::EDAnalyzer, MuScleFitBase { +class TestCorrection : public edm::one::EDAnalyzer<>, MuScleFitBase { public: explicit TestCorrection(const edm::ParameterSet&); ~TestCorrection() override; @@ -93,8 +93,9 @@ class TestCorrection : public edm::EDAnalyzer, MuScleFitBase { MuScleFitMuon muon(mu, track->charge(), ptError, hitsTk, hitsMuon); if (debug_ > 0) { - std::cout << "[TestCorrection::fillMuonCollection] after MuScleFitMuon initialization" << std::endl; - std::cout << " muon = " << muon << std::endl; + edm::LogPrint("TestCorrection") << "[TestCorrection::fillMuonCollection] after MuScleFitMuon initialization" + << std::endl; + edm::LogPrint("TestCorrection") << " muon = " << muon << std::endl; } muons.push_back(muon); @@ -125,13 +126,6 @@ class TestCorrection : public edm::EDAnalyzer, MuScleFitBase { }; #endif // TESTCORRECTION_HH -// -// constants, enums and typedefs -// - -// -// static data member definitions -// // // constructors and destructor @@ -157,10 +151,10 @@ TestCorrection::TestCorrection(const edm::ParameterSet& iConfig) // Create the corrector and set the parameters corrector_ = std::make_unique(iConfig.getUntrackedParameter("CorrectionsIdentifier")); - std::cout << "corrector_ = " << &*corrector_ << std::endl; + edm::LogPrint("TestCorrection") << "corrector_ = " << &*corrector_ << std::endl; resolution_ = std::make_unique(iConfig.getUntrackedParameter("ResolutionsIdentifier")); - std::cout << "resolution_ = " << &*resolution_ << std::endl; + edm::LogPrint("TestCorrection") << "resolution_ = " << &*resolution_ << std::endl; background_ = std::make_unique(iConfig.getUntrackedParameter("BackgroundIdentifier")); @@ -196,7 +190,7 @@ TestCorrection::~TestCorrection() { writeHistoMap(0); theFiles_[0]->Close(); - std::cout << "Total analyzed events = " << eventCounter_ << std::endl; + edm::LogPrint("TestCorrection") << "Total analyzed events = " << eventCounter_ << std::endl; } // @@ -211,7 +205,7 @@ void TestCorrection::analyze(const edm::Event& iEvent, const edm::EventSetup& iS ++eventCounter_; if (eventCounter_ % 100 == 0) { - std::cout << "Event number " << eventCounter_ << std::endl; + edm::LogPrint("TestCorrection") << "Event number " << eventCounter_ << std::endl; } // Take the reco-muons, depending on the type selected in the cfg @@ -289,9 +283,9 @@ void TestCorrection::analyze(const edm::Event& iEvent, const edm::EventSetup& iS uncorrectedPtVsEta_->Fill(recMuon->pt(), recMuon->eta()); // Fill the histogram with corrected pt values - std::cout << "correcting muon[" << muonCount << "] with pt = " << recMuon->pt() << std::endl; + edm::LogPrint("TestCorrection") << "correcting muon[" << muonCount << "] with pt = " << recMuon->pt() << std::endl; double corrPt = (*corrector_)(*recMuon); - std::cout << "to pt = " << corrPt << std::endl; + edm::LogPrint("TestCorrection") << "to pt = " << corrPt << std::endl; correctedPt_->Fill(corrPt); correctedPtVsEta_->Fill(corrPt, recMuon->eta()); // correctedPt_->Fill(recMuon->pt()); diff --git a/MuonAnalysis/MomentumScaleCalibration/plugins/TestCorrection.h b/MuonAnalysis/MomentumScaleCalibration/plugins/TestCorrection.h deleted file mode 100644 index bf6aa2c6cdea5..0000000000000 --- a/MuonAnalysis/MomentumScaleCalibration/plugins/TestCorrection.h +++ /dev/null @@ -1,127 +0,0 @@ -#ifndef TESTCORRECTION_HH -#define TESTCORRECTION_HH - -// -*- C++ -*- -// -// Package: TestCorrection -// Class: TestCorrection -// -/**\class TestCorrection TestCorrection.cc MuonAnalysis/MomentumScaleCalibration/plugins/TestCorrection.cc - - Description: - - Implementation: - -*/ -// -// Original Author: Marco De Mattia -// Created: Thu Sep 11 12:16:00 CEST 2008 -// -// - -// system include files -#include -#include -#include - -// user include files -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDAnalyzer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include "DataFormats/TrackReco/interface/Track.h" -#include "DataFormats/MuonReco/interface/Muon.h" -#include "DataFormats/MuonReco/interface/MuonFwd.h" -#include "DataFormats/Candidate/interface/Candidate.h" -#include "DataFormats/PatCandidates/interface/CompositeCandidate.h" -#include "DataFormats/PatCandidates/interface/Muon.h" -#include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h" -#include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h" - -#include "DataFormats/Candidate/interface/LeafCandidate.h" - -// For the momentum scale correction -#include "MuonAnalysis/MomentumScaleCalibration/interface/MomentumScaleCorrector.h" -#include "MuonAnalysis/MomentumScaleCalibration/interface/ResolutionFunction.h" -#include "MuonAnalysis/MomentumScaleCalibration/interface/BackgroundFunction.h" -#include "MuonAnalysis/MomentumScaleCalibration/interface/Muon.h" - -#include "TFile.h" -#include "TProfile.h" -#include "TH1F.h" - -#include "MuScleFitBase.h" - -// -// class decleration -// - -class TestCorrection : public edm::EDAnalyzer, MuScleFitBase { -public: - explicit TestCorrection(const edm::ParameterSet&); - ~TestCorrection(); - -private: - virtual void initialize(const edm::EventSetup&); - virtual void analyze(const edm::Event&, const edm::EventSetup&); - virtual void endJob() {}; - template - std::vector fillMuonCollection( const std::vector& tracks ) - { - std::vector muons; - typename std::vector::const_iterator track; - for( track = tracks.begin(); track != tracks.end(); ++track ) { - reco::Particle::LorentzVector mu; - mu = reco::Particle::LorentzVector(track->px(),track->py(),track->pz(), - sqrt(track->p()*track->p() + + 0.011163612)); - - Double_t hitsTk(0), hitsMuon(0), ptError(0); - if ( const reco::Muon* myMu = dynamic_cast(&(*track)) ){ - hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits(); - hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits(); - ptError = myMu->innerTrack()->ptError(); - } - else if ( const pat::Muon* myMu = dynamic_cast(&(*track)) ) { - hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits(); - hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits(); - ptError = myMu->innerTrack()->ptError(); - } - else if (const reco::Track* myMu = dynamic_cast(&(*track))){ - hitsTk = myMu->hitPattern().numberOfValidTrackerHits(); - hitsMuon = myMu->hitPattern().numberOfValidMuonHits(); - ptError = myMu->ptError(); - } - - MuScleFitMuon muon(mu,track->charge(),ptError,hitsTk,hitsMuon,false); - - if (debug_>0) { - std::cout<<"[TestCorrection::fillMuonCollection] after MuScleFitMuon initialization"< -#include + Implementation: + +*/ +// +// Original Author: Marco De Mattia +// Created: Thu Sep 11 12:16:00 CEST 2008 +// +// +// system include files +#include +#include +#include + +// user include files +#include "DataFormats/Candidate/interface/Candidate.h" +#include "DataFormats/Candidate/interface/LeafCandidate.h" +#include "DataFormats/MuonReco/interface/Muon.h" +#include "DataFormats/MuonReco/interface/MuonFwd.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h" +#include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h" + +// For the momentum scale resolution +#include "MuonAnalysis/MomentumScaleCalibration/interface/ResolutionFunction.h" + +// ROOT includes #include "TCanvas.h" #include "TLegend.h" +#include "TFile.h" +#include "TProfile.h" // -// constants, enums and typedefs +// class decleration // -// -// static data member definitions -// +class TestResolution : public edm::one::EDAnalyzer<> { +public: + explicit TestResolution(const edm::ParameterSet&); + ~TestResolution() override; + +private: + void analyze(const edm::Event&, const edm::EventSetup&) override; + template + std::vector fillMuonCollection(const std::vector& tracks) { + std::vector muons; + typename std::vector::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 --------------------------- + + // Collections labels + // ------------------ + edm::InputTag theMuonLabel_; + edm::EDGetTokenT glbMuonsToken_; + edm::EDGetTokenT saMuonsToken_; + edm::EDGetTokenT tracksToken_; + + int theMuonType_; + std::string theRootFileName_; + TFile* outputFile_; + + TProfile* sigmaPt_; + + int eventCounter_; + + std::unique_ptr resolutionFunction_; +}; // // constructors and destructor @@ -99,5 +174,3 @@ void TestResolution::analyze(const edm::Event& iEvent, const edm::EventSetup& iS //define this as a plug-in DEFINE_FWK_MODULE(TestResolution); - -#endif // TESTRESOLUTION_CC diff --git a/MuonAnalysis/MomentumScaleCalibration/plugins/TestResolution.h b/MuonAnalysis/MomentumScaleCalibration/plugins/TestResolution.h deleted file mode 100644 index 669d36e2ca45a..0000000000000 --- a/MuonAnalysis/MomentumScaleCalibration/plugins/TestResolution.h +++ /dev/null @@ -1,97 +0,0 @@ -#ifndef TESTRESOLUTION_HH -#define TESTRESOLUTION_HH - -// -*- C++ -*- -// -// Package: TestResolution -// Class: TestResolution -// -/**\class TestResolution TestResolution.cc MuonAnalysis/MomentumScaleCalibration/plugins/TestResolution.cc - - Description: - - Implementation: - -*/ -// -// Original Author: Marco De Mattia -// Created: Thu Sep 11 12:16:00 CEST 2008 -// -// - -// system include files -#include -#include -#include - -// user include files -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDAnalyzer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include "DataFormats/TrackReco/interface/Track.h" -#include "DataFormats/MuonReco/interface/Muon.h" -#include "DataFormats/MuonReco/interface/MuonFwd.h" -#include "DataFormats/Candidate/interface/Candidate.h" -#include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h" -#include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h" - -#include "DataFormats/Candidate/interface/LeafCandidate.h" - -// For the momentum scale resolution -#include "MuonAnalysis/MomentumScaleCalibration/interface/ResolutionFunction.h" - -#include "TFile.h" -#include "TProfile.h" - -// -// class decleration -// - -class TestResolution : public edm::EDAnalyzer { -public: - explicit TestResolution(const edm::ParameterSet&); - ~TestResolution() override; - -private: - void analyze(const edm::Event&, const edm::EventSetup&) override; - void endJob() override{}; - template - std::vector fillMuonCollection(const std::vector& tracks) { - std::vector muons; - typename std::vector::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 --------------------------- - - // Collections labels - // ------------------ - edm::InputTag theMuonLabel_; - edm::EDGetTokenT glbMuonsToken_; - edm::EDGetTokenT saMuonsToken_; - edm::EDGetTokenT tracksToken_; - - int theMuonType_; - std::string theRootFileName_; - TFile* outputFile_; - - TProfile* sigmaPt_; - - int eventCounter_; - - std::unique_ptr resolutionFunction_; -}; - -#endif // TESTRESOLUTION_HH diff --git a/MuonAnalysis/MomentumScaleCalibration/plugins/TreeSplitter.cc b/MuonAnalysis/MomentumScaleCalibration/plugins/TreeSplitter.cc index a5bdb40ab61dd..4fbb8fe792a65 100644 --- a/MuonAnalysis/MomentumScaleCalibration/plugins/TreeSplitter.cc +++ b/MuonAnalysis/MomentumScaleCalibration/plugins/TreeSplitter.cc @@ -1,7 +1,42 @@ -#ifndef TREESPLITTER_CC -#define TREESPLITTER_CC +// -*- C++ -*- +// +// Package: TreeSplitter +// Class: TreeSplitter +// +/**\class TreeSplitter TreeSplitter.cc MuonAnalysis/MomentumScaleCalibration/plugins/TreeSplitter.cc -#include "TreeSplitter.h" + Description: + + Implementation: + +*/ +// +// Original Author: Marco De Mattia +// Created: Thu Sep 11 12:16:00 CEST 2008 +// + +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include + +class TreeSplitter : public edm::one::EDAnalyzer<> { +public: + explicit TreeSplitter(const edm::ParameterSet&); + ~TreeSplitter() override; + +private: + void analyze(const edm::Event&, const edm::EventSetup&) override{}; + void endJob() override; + + TString treeFileName_; + TString outputFileName_; + int32_t maxEvents_; + uint32_t subSampleFirstEvent_; + uint32_t subSampleMaxEvents_; +}; TreeSplitter::TreeSplitter(const edm::ParameterSet& iConfig) : treeFileName_(iConfig.getParameter("InputFileName")), @@ -41,5 +76,3 @@ void TreeSplitter::endJob() { //define this as a plug-in DEFINE_FWK_MODULE(TreeSplitter); - -#endif diff --git a/MuonAnalysis/MomentumScaleCalibration/plugins/TreeSplitter.h b/MuonAnalysis/MomentumScaleCalibration/plugins/TreeSplitter.h deleted file mode 100644 index b8f5c778549d9..0000000000000 --- a/MuonAnalysis/MomentumScaleCalibration/plugins/TreeSplitter.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef TreeSplitter_HH -#define TreeSplitter_HH - -// -*- C++ -*- -// -// Package: TreeSplitter -// Class: TreeSplitter -// -/**\class TreeSplitter TreeSplitter.cc MuonAnalysis/MomentumScaleCalibration/plugins/TreeSplitter.cc - - Description: - - Implementation: - -*/ -// -// Original Author: Marco De Mattia -// Created: Thu Sep 11 12:16:00 CEST 2008 -// - -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDAnalyzer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include - -class TreeSplitter : public edm::EDAnalyzer { -public: - explicit TreeSplitter(const edm::ParameterSet&); - ~TreeSplitter() override; - -private: - void analyze(const edm::Event&, const edm::EventSetup&) override{}; - void endJob() override; - - TString treeFileName_; - TString outputFileName_; - int32_t maxEvents_; - uint32_t subSampleFirstEvent_; - uint32_t subSampleMaxEvents_; -}; - -#endif // TREESPLITTER_HH