Skip to content

Commit

Permalink
Merge pull request #25837 from makortel/pluginFactoryCalibMuon
Browse files Browse the repository at this point in the history
Manage PluginFactory plugins with unique_ptr in CalibMuon/DTCalibration
  • Loading branch information
cmsbuild committed Feb 4, 2019
2 parents a94dbd1 + 09c1364 commit d287d10
Show file tree
Hide file tree
Showing 21 changed files with 64 additions and 80 deletions.
4 changes: 2 additions & 2 deletions CalibMuon/DTCalibration/interface/DTTMax.h
Expand Up @@ -37,7 +37,7 @@ class DTTMax {

/// Constructor
DTTMax(const std::vector<DTRecHit1D> & hits, const DTSuperLayer & isl, GlobalVector dir,
GlobalPoint pos, DTTTrigBaseSync* sync);
GlobalPoint pos, const DTTTrigBaseSync& sync);

/// Destructor
virtual ~DTTMax();
Expand All @@ -60,7 +60,7 @@ class DTTMax {
// All information on one of the layers crossed by the segment
struct InfoLayer {
InfoLayer(const DTRecHit1D& rh_, const DTSuperLayer & isl, GlobalVector dir,
GlobalPoint pos, DTTTrigBaseSync* sync);
GlobalPoint pos, const DTTTrigBaseSync& sync);
DTRecHit1D rh;
DTWireId idWire;
DTEnums::DTCellSide lr;
Expand Down
11 changes: 4 additions & 7 deletions CalibMuon/DTCalibration/plugins/DTT0Correction.cc
Expand Up @@ -27,18 +27,15 @@
using namespace edm;
using namespace std;

DTT0Correction::DTT0Correction(const ParameterSet& pset){

DTT0Correction::DTT0Correction(const ParameterSet& pset):
correctionAlgo_{DTT0CorrectionFactory::get()->create(pset.getParameter<string>("correctionAlgo"),
pset.getParameter<ParameterSet>("correctionAlgoConfig"))}
{
LogVerbatim("Calibration") << "[DTT0Correction] Constructor called" << endl;

// Get the concrete algo from the factory
string theAlgoName = pset.getParameter<string>("correctionAlgo");
correctionAlgo_ = DTT0CorrectionFactory::get()->create(theAlgoName,pset.getParameter<ParameterSet>("correctionAlgoConfig"));
}

DTT0Correction::~DTT0Correction(){
LogVerbatim("Calibration") << "[DTT0Correction] Destructor called" << endl;
delete correctionAlgo_;
}

void DTT0Correction::beginRun( const edm::Run& run, const edm::EventSetup& setup ) {
Expand Down
2 changes: 1 addition & 1 deletion CalibMuon/DTCalibration/plugins/DTT0Correction.h
Expand Up @@ -39,6 +39,6 @@ class DTT0Correction : public edm::EDAnalyzer {
const DTT0* t0Map_;
edm::ESHandle<DTGeometry> muonGeom_;

dtCalibration::DTT0BaseCorrection* correctionAlgo_;
std::unique_ptr<dtCalibration::DTT0BaseCorrection> correctionAlgo_;
};
#endif
9 changes: 4 additions & 5 deletions CalibMuon/DTCalibration/plugins/DTTPAnalyzer.cc
Expand Up @@ -36,7 +36,7 @@ class DTTPAnalyzer : public edm::EDAnalyzer {
TFile* rootFile_;
//const DTT0* tZeroMap_;
edm::ESHandle<DTGeometry> dtGeom_;
DTTTrigBaseSync* tTrigSync_;
std::unique_ptr<DTTTrigBaseSync> tTrigSync_;

// Map of the t0 and sigma histos by layer
std::map<DTWireId, int> nDigisPerWire_;
Expand Down Expand Up @@ -67,16 +67,15 @@ class DTTPAnalyzer : public edm::EDAnalyzer {

DTTPAnalyzer::DTTPAnalyzer(const edm::ParameterSet& pset):
subtractT0_(pset.getParameter<bool>("subtractT0")),
digiLabel_(pset.getParameter<edm::InputTag>("digiLabel")),
tTrigSync_(nullptr) {
digiLabel_(pset.getParameter<edm::InputTag>("digiLabel")) {

std::string rootFileName = pset.getUntrackedParameter<std::string>("rootFileName");
rootFile_ = new TFile(rootFileName.c_str(), "RECREATE");
rootFile_->cd();

if(subtractT0_)
tTrigSync_ = DTTTrigSyncFactory::get()->create(pset.getParameter<std::string>("tTrigMode"),
pset.getParameter<edm::ParameterSet>("tTrigModeConfig"));
tTrigSync_ = std::unique_ptr<DTTTrigBaseSync>{DTTTrigSyncFactory::get()->create(pset.getParameter<std::string>("tTrigMode"),
pset.getParameter<edm::ParameterSet>("tTrigModeConfig"))};

}

Expand Down
9 changes: 3 additions & 6 deletions CalibMuon/DTCalibration/plugins/DTTTrigCalibration.cc
Expand Up @@ -60,7 +60,7 @@ DTTTrigCalibration::DTTTrigCalibration(const edm::ParameterSet& pset) {
string rootFileName = pset.getUntrackedParameter<string>("rootFileName");
theFile = new TFile(rootFileName.c_str(), "RECREATE");
theFile->cd();
theFitter = new DTTimeBoxFitter();
theFitter = std::make_unique<DTTimeBoxFitter>();
if(debug)
theFitter->setVerbosity(1);

Expand All @@ -70,10 +70,8 @@ DTTTrigCalibration::DTTTrigCalibration(const edm::ParameterSet& pset) {
doSubtractT0 = pset.getUntrackedParameter<bool>("doSubtractT0","false");
// Get the synchronizer
if(doSubtractT0) {
theSync = DTTTrigSyncFactory::get()->create(pset.getUntrackedParameter<string>("tTrigMode"),
pset.getUntrackedParameter<ParameterSet>("tTrigModeConfig"));
} else {
theSync = nullptr;
theSync = std::unique_ptr<DTTTrigBaseSync>{DTTTrigSyncFactory::get()->create(pset.getUntrackedParameter<string>("tTrigMode"),
pset.getUntrackedParameter<ParameterSet>("tTrigModeConfig"))};
}

checkNoisyChannels = pset.getUntrackedParameter<bool>("checkNoisyChannels","false");
Expand All @@ -100,7 +98,6 @@ DTTTrigCalibration::~DTTTrigCalibration(){
// }

theFile->Close();
delete theFitter;
}


Expand Down
4 changes: 2 additions & 2 deletions CalibMuon/DTCalibration/plugins/DTTTrigCalibration.h
Expand Up @@ -88,9 +88,9 @@ class DTTTrigCalibration : public edm::EDAnalyzer {
double kFactor;

// The fitter
DTTimeBoxFitter *theFitter;
std::unique_ptr<DTTimeBoxFitter> theFitter;
// The module for t0 subtraction
DTTTrigBaseSync *theSync;//FIXME: should be const
std::unique_ptr<DTTTrigBaseSync> theSync;//FIXME: should be const

};
#endif
Expand Down
11 changes: 4 additions & 7 deletions CalibMuon/DTCalibration/plugins/DTTTrigCorrection.cc
Expand Up @@ -33,18 +33,15 @@ using namespace edm;
using namespace std;

DTTTrigCorrection::DTTTrigCorrection(const ParameterSet& pset):
dbLabel_( pset.getUntrackedParameter<string>("dbLabel", "") ) {

dbLabel_( pset.getUntrackedParameter<string>("dbLabel", "") ),
correctionAlgo_{DTTTrigCorrectionFactory::get()->create(pset.getParameter<string>("correctionAlgo"),
pset.getParameter<ParameterSet>("correctionAlgoConfig"))}
{
LogVerbatim("Calibration") << "[DTTTrigCorrection] Constructor called" << endl;

// Get the concrete algo from the factory
string theAlgoName = pset.getParameter<string>("correctionAlgo");
correctionAlgo_ = DTTTrigCorrectionFactory::get()->create(theAlgoName,pset.getParameter<ParameterSet>("correctionAlgoConfig"));
}

DTTTrigCorrection::~DTTTrigCorrection(){
LogVerbatim("Calibration") << "[DTTTrigCorrection] Destructor called" << endl;
delete correctionAlgo_;
}

void DTTTrigCorrection::beginRun( const edm::Run& run, const edm::EventSetup& setup ) {
Expand Down
2 changes: 1 addition & 1 deletion CalibMuon/DTCalibration/plugins/DTTTrigCorrection.h
Expand Up @@ -43,7 +43,7 @@ class DTTTrigCorrection : public edm::EDAnalyzer {
const DTTtrig* tTrigMap_;
edm::ESHandle<DTGeometry> muonGeom_;

dtCalibration::DTTTrigBaseCorrection* correctionAlgo_;
std::unique_ptr<dtCalibration::DTTTrigBaseCorrection> correctionAlgo_;
};
#endif

16 changes: 8 additions & 8 deletions CalibMuon/DTCalibration/plugins/DTVDriftCalibration.cc
Expand Up @@ -45,7 +45,12 @@ using namespace edm;
using namespace dttmaxenums;


DTVDriftCalibration::DTVDriftCalibration(const ParameterSet& pset): select_(pset) {
DTVDriftCalibration::DTVDriftCalibration(const ParameterSet& pset):
select_(pset),
// Get the synchronizer
theSync{DTTTrigSyncFactory::get()->create(pset.getParameter<string>("tTrigMode"),
pset.getParameter<ParameterSet>("tTrigModeConfig"))}
{

// The name of the 4D rec hits collection
theRecHits4DLabel = pset.getParameter<InputTag>("recHits4DLabel");
Expand All @@ -57,7 +62,7 @@ DTVDriftCalibration::DTVDriftCalibration(const ParameterSet& pset): select_(pset

debug = pset.getUntrackedParameter<bool>("debug", false);

theFitter = new DTMeanTimerFitter(theFile);
theFitter = std::make_unique<DTMeanTimerFitter>(theFile);
if(debug)
theFitter->setVerbosity(1);

Expand All @@ -75,10 +80,6 @@ DTVDriftCalibration::DTVDriftCalibration(const ParameterSet& pset): select_(pset
// the txt file which will contain the calibrated constants
theVDriftOutputFile = pset.getUntrackedParameter<string>("vDriftFileName");

// Get the synchronizer
theSync = DTTTrigSyncFactory::get()->create(pset.getParameter<string>("tTrigMode"),
pset.getParameter<ParameterSet>("tTrigModeConfig"));

// get parameter set for DTCalibrationMap constructor
theCalibFilePar = pset.getUntrackedParameter<ParameterSet>("calibFileConfig");

Expand Down Expand Up @@ -106,7 +107,6 @@ DTVDriftCalibration::DTVDriftCalibration(const ParameterSet& pset): select_(pset

DTVDriftCalibration::~DTVDriftCalibration(){
theFile->Close();
delete theFitter;
LogVerbatim("Calibration") << "[DTVDriftCalibration]Destructor called!";
}

Expand Down Expand Up @@ -227,7 +227,7 @@ void DTVDriftCalibration::analyze(const Event & event, const EventSetup& eventSe
DTSuperLayerId slId = slIdAndHits->first;

// Create the DTTMax, that computes the 4 TMax
DTTMax slSeg(slIdAndHits->second, *(chamber->superLayer(slIdAndHits->first)),chamber->toGlobal((*segment).localDirection()), chamber->toGlobal((*segment).localPosition()), theSync);
DTTMax slSeg(slIdAndHits->second, *(chamber->superLayer(slIdAndHits->first)),chamber->toGlobal((*segment).localDirection()), chamber->toGlobal((*segment).localPosition()), *theSync);

if(theGranularity == bySL) {
vector<const TMax*> tMaxes = slSeg.getTMax(slId);
Expand Down
4 changes: 2 additions & 2 deletions CalibMuon/DTCalibration/plugins/DTVDriftCalibration.h
Expand Up @@ -100,7 +100,7 @@ class DTVDriftCalibration : public edm::EDAnalyzer {
TFile *theFile;

// The fitter
DTMeanTimerFitter *theFitter;
std::unique_ptr<DTMeanTimerFitter> theFitter;

// Perform the vDrift and t0 evaluation or just fill the
// tMaxHists (if you read the dataset in different jobs)
Expand All @@ -116,7 +116,7 @@ class DTVDriftCalibration : public edm::EDAnalyzer {
//bool checkNoisyChannels;

// The module for t0 subtraction
DTTTrigBaseSync *theSync;//FIXME: should be const
std::unique_ptr<DTTTrigBaseSync> theSync;//FIXME: should be const

// parameter set for DTCalibrationMap constructor
edm::ParameterSet theCalibFilePar;
Expand Down
11 changes: 4 additions & 7 deletions CalibMuon/DTCalibration/plugins/DTVDriftWriter.cc
Expand Up @@ -31,22 +31,19 @@ using namespace std;
using namespace edm;

DTVDriftWriter::DTVDriftWriter(const ParameterSet& pset):
granularity_( pset.getUntrackedParameter<string>("calibGranularity","bySL") ) {
granularity_( pset.getUntrackedParameter<string>("calibGranularity","bySL") ),
vDriftAlgo_{DTVDriftPluginFactory::get()->create(pset.getParameter<string>("vDriftAlgo"),
pset.getParameter<ParameterSet>("vDriftAlgoConfig"))}
{

LogVerbatim("Calibration") << "[DTVDriftWriter]Constructor called!";

if(granularity_ != "bySL")
throw cms::Exception("Configuration") << "[DTVDriftWriter] Check parameter calibGranularity: " << granularity_ << " option not available.";

// Get the concrete algo from the factory
string algoName = pset.getParameter<string>("vDriftAlgo");
ParameterSet algoPSet = pset.getParameter<ParameterSet>("vDriftAlgoConfig");
vDriftAlgo_ = DTVDriftPluginFactory::get()->create(algoName,algoPSet);
}

DTVDriftWriter::~DTVDriftWriter(){
LogVerbatim("Calibration") << "[DTVDriftWriter]Destructor called!";
delete vDriftAlgo_;
}

void DTVDriftWriter::beginRun(const edm::Run& run, const edm::EventSetup& setup) {
Expand Down
2 changes: 1 addition & 1 deletion CalibMuon/DTCalibration/plugins/DTVDriftWriter.h
Expand Up @@ -37,7 +37,7 @@ class DTVDriftWriter : public edm::EDAnalyzer {
const DTMtime* mTimeMap_;
edm::ESHandle<DTGeometry> dtGeom_;

dtCalibration::DTVDriftBaseAlgo* vDriftAlgo_;
std::unique_ptr<dtCalibration::DTVDriftBaseAlgo> vDriftAlgo_;
};
#endif

6 changes: 3 additions & 3 deletions CalibMuon/DTCalibration/src/DTTMax.cc
Expand Up @@ -19,7 +19,7 @@ using namespace dttmaxenums;
using namespace DTEnums;

DTTMax::InfoLayer::InfoLayer(const DTRecHit1D& rh_, const DTSuperLayer & isl, GlobalVector dir,
GlobalPoint pos, DTTTrigBaseSync* sync):
GlobalPoint pos, const DTTTrigBaseSync& sync):
rh(rh_), idWire(rh.wireId()), lr(rh.lrSide()) {
const DTLayer* layer = isl.layer(idWire.layerId());
LocalPoint wirePosInLayer(layer->specificTopology().wirePosition(idWire.wire()), 0, 0);
Expand All @@ -31,7 +31,7 @@ DTTMax::InfoLayer::InfoLayer(const DTRecHit1D& rh_, const DTSuperLayer & isl, Gl
LocalPoint segPos = layer->toLocal(pos);
LocalPoint segPosAtLayer = segPos + segDir*(-segPos.z())/cos(segDir.theta());
LocalPoint hitPos(rh.localPosition().x() ,segPosAtLayer.y(),0.);
time = rh.digiTime() - sync->offset(layer, idWire, layer->toGlobal(hitPos));
time = rh.digiTime() - sync.offset(layer, idWire, layer->toGlobal(hitPos));

if (time < 0. || time > 415.) {
// FIXME introduce time window to reject "out-of-time" digis
Expand All @@ -41,7 +41,7 @@ DTTMax::InfoLayer::InfoLayer(const DTRecHit1D& rh_, const DTSuperLayer & isl, Gl


DTTMax::DTTMax(const vector<DTRecHit1D>& hits, const DTSuperLayer & isl, GlobalVector dir,
GlobalPoint pos, DTTTrigBaseSync* sync):
GlobalPoint pos, const DTTTrigBaseSync& sync):
theInfoLayers(4,(InfoLayer*)nullptr), //FIXME
theTMaxes(4,(TMax*)nullptr)
{
Expand Down
10 changes: 5 additions & 5 deletions CalibMuon/DTDigiSync/interface/DTTTrigBaseSync.h
Expand Up @@ -38,11 +38,11 @@ class DTTTrigBaseSync {
/// the 3D hit position (globPos)
double offset(const DTLayer* layer,
const DTWireId& wireId,
const GlobalPoint& globalPos);
const GlobalPoint& globalPos) const;

/// Time (ns) to be subtracted to the digi time.
/// It does not take into account TOF and signal propagation along the wire
virtual double offset(const DTWireId& wireId) = 0 ;
virtual double offset(const DTWireId& wireId) const = 0 ;


/// Time to be subtracted to the digi time,
Expand All @@ -58,12 +58,12 @@ class DTTTrigBaseSync {
const GlobalPoint& globalPos,
double &tTrig,
double& wirePropCorr,
double& tofCorr) = 0;
double& tofCorr) const = 0;


/// Time (ns) to be subtracted to the digi time for emulation purposes
/// It does not take into account TOF and signal propagation along the wire
virtual double emulatorOffset(const DTWireId& wireId);
virtual double emulatorOffset(const DTWireId& wireId) const;

/// Time (ns) to be subtracted to the digi time for emulation purposes
/// It does not take into account TOF and signal propagation along the wire
Expand All @@ -72,7 +72,7 @@ class DTTTrigBaseSync {
/// - t0cell is the t0 from pulses
virtual double emulatorOffset(const DTWireId& wireId,
double &tTrig,
double &t0cell) = 0;
double &t0cell) const = 0;


};
Expand Down
4 changes: 2 additions & 2 deletions CalibMuon/DTDigiSync/src/DTTTrigBaseSync.cc
Expand Up @@ -17,7 +17,7 @@ DTTTrigBaseSync::~DTTTrigBaseSync(){}

double DTTTrigBaseSync::offset(const DTLayer* layer,
const DTWireId& wireId,
const GlobalPoint& globalPos) {
const GlobalPoint& globalPos) const {
double tTrig = 0;
double wireProp = 0;
double tof = 0;
Expand All @@ -26,7 +26,7 @@ double DTTTrigBaseSync::offset(const DTLayer* layer,



double DTTTrigBaseSync::emulatorOffset(const DTWireId& wireId) {
double DTTTrigBaseSync::emulatorOffset(const DTWireId& wireId) const {

double tTrig = 0.;
double t0cell = 0.;
Expand Down
6 changes: 3 additions & 3 deletions CalibMuon/DTDigiSync/src/DTTTrigSyncFromDB.cc
Expand Up @@ -75,7 +75,7 @@ double DTTTrigSyncFromDB::offset(const DTLayer* layer,
const GlobalPoint& globPos,
double& tTrig,
double& wirePropCorr,
double& tofCorr) {
double& tofCorr) const {
// Correction for the float to int conversion while writeing the ttrig in ns into an int variable
// (half a bin on average)
// FIXME: this should disappear as soon as the ttrig object will become a float
Expand Down Expand Up @@ -167,7 +167,7 @@ double DTTTrigSyncFromDB::offset(const DTLayer* layer,
return tTrig + wirePropCorr - tofCorr;
}

double DTTTrigSyncFromDB::offset(const DTWireId& wireId) {
double DTTTrigSyncFromDB::offset(const DTWireId& wireId) const {
float t0 = 0;
float t0rms = 0;
if(doT0Correction)
Expand Down Expand Up @@ -200,7 +200,7 @@ double DTTTrigSyncFromDB::offset(const DTWireId& wireId) {

double DTTTrigSyncFromDB::emulatorOffset(const DTWireId& wireId,
double &tTrig,
double &t0cell) {
double &t0cell) const {
float t0 = 0;
float t0rms = 0;
if(doT0Correction)
Expand Down
6 changes: 3 additions & 3 deletions CalibMuon/DTDigiSync/src/DTTTrigSyncFromDB.h
Expand Up @@ -74,11 +74,11 @@ class DTTTrigSyncFromDB : public DTTTrigBaseSync {
const GlobalPoint& globPos,
double& tTrig,
double& wirePropCorr,
double& tofCorr) override;
double& tofCorr) const override;

/// Time (ns) to be subtracted to the digi time.
/// It does not take into account TOF and signal propagation along the wire
double offset(const DTWireId& wireId) override;
double offset(const DTWireId& wireId) const override;


/// Time (ns) to be subtracted to the digi time for emulation purposes
Expand All @@ -88,7 +88,7 @@ class DTTTrigSyncFromDB : public DTTTrigBaseSync {
/// - t0cell is the t0 from pulses
double emulatorOffset(const DTWireId& wireId,
double &tTrig,
double &t0cell) override;
double &t0cell) const override;


private:
Expand Down

0 comments on commit d287d10

Please sign in to comment.