-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update DT vdrift calibration code to allow using "new" DB format #31808
Changes from all commits
1e51878
26d2d4e
24255c2
9c4588d
15bd931
227b975
2750f94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
#include "Geometry/Records/interface/MuonGeometryRecord.h" | ||
#include "CondFormats/DTObjects/interface/DTMtime.h" | ||
#include "CondFormats/DataRecord/interface/DTMtimeRcd.h" | ||
#include "CondFormats/DTObjects/interface/DTRecoConditions.h" | ||
#include "CondFormats/DataRecord/interface/DTRecoConditionsVdriftRcd.h" | ||
|
||
#include "CalibMuon/DTCalibration/interface/DTResidualFitter.h" | ||
#include "CalibMuon/DTCalibration/interface/DTCalibDBUtils.h" | ||
|
@@ -32,14 +34,17 @@ using namespace edm; | |
namespace dtCalibration { | ||
|
||
DTVDriftSegment::DTVDriftSegment(const ParameterSet& pset) | ||
: nSigmas_(pset.getUntrackedParameter<unsigned int>("nSigmasFitRange", 1)) { | ||
: nSigmas_(pset.getUntrackedParameter<unsigned int>("nSigmasFitRange", 1)), | ||
mTimeMap_(nullptr), | ||
vDriftMap_(nullptr) { | ||
string rootFileName = pset.getParameter<string>("rootFileName"); | ||
rootFile_ = new TFile(rootFileName.c_str(), "READ"); | ||
|
||
bool debug = pset.getUntrackedParameter<bool>("debug", false); | ||
fitter_ = new DTResidualFitter(debug); | ||
//bool debug = pset.getUntrackedParameter<bool>("debug", false); | ||
//if(debug) fitter_->setVerbosity(1); | ||
|
||
readLegacyVDriftDB = pset.getParameter<bool>("readLegacyVDriftDB"); | ||
} | ||
|
||
DTVDriftSegment::~DTVDriftSegment() { | ||
|
@@ -49,18 +54,34 @@ namespace dtCalibration { | |
|
||
void DTVDriftSegment::setES(const edm::EventSetup& setup) { | ||
// Get the map of vdrift from the setup | ||
ESHandle<DTMtime> mTime; | ||
setup.get<DTMtimeRcd>().get(mTime); | ||
mTimeMap_ = &*mTime; | ||
if (readLegacyVDriftDB) { | ||
ESHandle<DTMtime> mTime; | ||
setup.get<DTMtimeRcd>().get(mTime); | ||
mTimeMap_ = &*mTime; | ||
} else { | ||
ESHandle<DTRecoConditions> hVdrift; | ||
setup.get<DTRecoConditionsVdriftRcd>().get(hVdrift); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
vDriftMap_ = &*hVdrift; | ||
// Consistency check: no parametrization is implemented for the time being | ||
int version = vDriftMap_->version(); | ||
if (version != 1) { | ||
throw cms::Exception("Configuration") << "only version 1 is presently supported for VDriftDB"; | ||
} | ||
} | ||
} | ||
|
||
DTVDriftData DTVDriftSegment::compute(DTSuperLayerId const& slId) { | ||
// Get original value from DB; vdrift is cm/ns , resolution is cm | ||
float vDrift = 0., resolution = 0.; | ||
int status = mTimeMap_->get(slId, vDrift, resolution, DTVelocityUnits::cm_per_ns); | ||
// Note that resolution is irrelevant as it is no longer used anywhere in reconstruction. | ||
|
||
if (status != 0) | ||
throw cms::Exception("DTCalibration") << "Could not find vDrift entry in DB for" << slId << endl; | ||
float vDrift = 0., resolution = 0.; | ||
if (readLegacyVDriftDB) { // Legacy format | ||
int status = mTimeMap_->get(slId, vDrift, resolution, DTVelocityUnits::cm_per_ns); | ||
if (status != 0) | ||
throw cms::Exception("DTCalibration") << "Could not find vDrift entry in DB for" << slId << endl; | ||
} else { // New DB format | ||
vDrift = vDriftMap_->get(DTWireId(slId.rawId())); | ||
} | ||
|
||
// For RZ superlayers use original value | ||
if (slId.superLayer() == 2) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
|
||
#include "CondFormats/DTObjects/interface/DTMtime.h" | ||
#include "CondFormats/DataRecord/interface/DTMtimeRcd.h" | ||
#include "CondFormats/DTObjects/interface/DTRecoConditions.h" | ||
#include "CondFormats/DataRecord/interface/DTRecoConditionsVdriftRcd.h" | ||
|
||
#include "CalibMuon/DTCalibration/interface/DTCalibDBUtils.h" | ||
#include "CalibMuon/DTCalibration/interface/DTVDriftPluginFactory.h" | ||
|
@@ -32,22 +34,38 @@ using namespace edm; | |
|
||
DTVDriftWriter::DTVDriftWriter(const ParameterSet& pset) | ||
: granularity_(pset.getUntrackedParameter<string>("calibGranularity", "bySL")), | ||
mTimeMap_(nullptr), | ||
vDriftMap_(nullptr), | ||
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."; | ||
|
||
readLegacyVDriftDB = pset.getParameter<bool>("readLegacyVDriftDB"); | ||
writeLegacyVDriftDB = pset.getParameter<bool>("writeLegacyVDriftDB"); | ||
} | ||
|
||
DTVDriftWriter::~DTVDriftWriter() { LogVerbatim("Calibration") << "[DTVDriftWriter]Destructor called!"; } | ||
|
||
void DTVDriftWriter::beginRun(const edm::Run& run, const edm::EventSetup& setup) { | ||
// Get the map of ttrig from the Setup | ||
ESHandle<DTMtime> mTime; | ||
setup.get<DTMtimeRcd>().get(mTime); | ||
mTimeMap_ = &*mTime; | ||
// Get the map of vdrift from the Setup | ||
if (readLegacyVDriftDB) { | ||
ESHandle<DTMtime> mTime; | ||
setup.get<DTMtimeRcd>().get(mTime); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here |
||
mTimeMap_ = &*mTime; | ||
} else { | ||
ESHandle<DTRecoConditions> hVdrift; | ||
setup.get<DTRecoConditionsVdriftRcd>().get(hVdrift); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here |
||
vDriftMap_ = &*hVdrift; | ||
// Consistency check: no parametrization is implemented for the time being | ||
int version = vDriftMap_->version(); | ||
if (version != 1) { | ||
throw cms::Exception("Configuration") << "only version 1 is presently supported for VDriftDB"; | ||
} | ||
} | ||
|
||
// Get geometry from Event Setup | ||
setup.get<MuonGeometryRecord>().get(dtGeom_); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Besides, the same migration would have to be done everywhere in the package; for example. also in |
||
|
@@ -57,7 +75,16 @@ void DTVDriftWriter::beginRun(const edm::Run& run, const edm::EventSetup& setup) | |
|
||
void DTVDriftWriter::endJob() { | ||
// Create the object to be written to DB | ||
DTMtime* mTimeNewMap = new DTMtime(); | ||
DTMtime* mTimeNewMap = nullptr; | ||
DTRecoConditions* vDriftNewMap = nullptr; | ||
if (writeLegacyVDriftDB) { | ||
mTimeNewMap = new DTMtime(); | ||
} else { | ||
vDriftNewMap = new DTRecoConditions(); | ||
vDriftNewMap->setFormulaExpr("[0]"); | ||
//vDriftNewMap->setFormulaExpr("[0]*(1-[1]*x)"); // add parametrization for dependency along Y | ||
vDriftNewMap->setVersion(1); | ||
} | ||
|
||
if (granularity_ == "bySL") { | ||
// Get all the sls from the geometry | ||
|
@@ -66,34 +93,51 @@ void DTVDriftWriter::endJob() { | |
auto sl_end = superLayers.end(); | ||
for (; sl != sl_end; ++sl) { | ||
DTSuperLayerId slId = (*sl)->id(); | ||
// Get original value from DB | ||
float vDrift = 0., resolution = 0.; | ||
// vdrift is cm/ns , resolution is cm | ||
int status = mTimeMap_->get(slId, vDrift, resolution, DTVelocityUnits::cm_per_ns); | ||
|
||
// Compute vDrift | ||
float vDriftNew = -1.; | ||
float resolutionNew = -1; | ||
try { | ||
dtCalibration::DTVDriftData vDriftData = vDriftAlgo_->compute(slId); | ||
float vDriftNew = vDriftData.vdrift; | ||
float resolutionNew = vDriftData.resolution; | ||
// vdrift is cm/ns , resolution is cm | ||
mTimeNewMap->set(slId, vDriftNew, resolutionNew, DTVelocityUnits::cm_per_ns); | ||
vDriftNew = vDriftData.vdrift; | ||
resolutionNew = vDriftData.resolution; | ||
LogVerbatim("Calibration") << "vDrift for: " << slId << " Mean " << vDriftNew << " Resolution " | ||
<< resolutionNew; | ||
} catch (cms::Exception& e) { | ||
} catch (cms::Exception& e) { // Failure to compute new value, fall back to old table | ||
LogError("Calibration") << e.explainSelf(); | ||
// Go back to original value in case of error | ||
if (!status) { | ||
mTimeNewMap->set(slId, vDrift, resolution, DTVelocityUnits::cm_per_ns); | ||
LogVerbatim("Calibration") << "Keep original vDrift for: " << slId << " Mean " << vDrift << " Resolution " | ||
<< resolution; | ||
if (readLegacyVDriftDB) { //...reading old db format... | ||
int status = mTimeMap_->get(slId, vDriftNew, resolutionNew, DTVelocityUnits::cm_per_ns); | ||
if (status == 0) { // not found; silently skip this SL | ||
continue; | ||
} | ||
} else { //...reading new db format | ||
try { | ||
vDriftNew = vDriftMap_->get(DTWireId(slId.rawId())); | ||
} catch (cms::Exception& e2) { | ||
// not found; silently skip this SL | ||
continue; | ||
} | ||
} | ||
LogVerbatim("Calibration") << "Keep original vDrift for: " << slId << " Mean " << vDriftNew << " Resolution " | ||
<< resolutionNew; | ||
} | ||
|
||
// Add value to the vdrift table | ||
if (writeLegacyVDriftDB) { | ||
mTimeNewMap->set(slId, vDriftNew, resolutionNew, DTVelocityUnits::cm_per_ns); | ||
} else { | ||
vector<double> params = {vDriftNew}; | ||
vDriftNewMap->set(DTWireId(slId.rawId()), params); | ||
} | ||
} // End of loop on superlayers | ||
} | ||
|
||
// Write the vDrift object to DB | ||
LogVerbatim("Calibration") << "[DTVDriftWriter]Writing vdrift object to DB!"; | ||
string record = "DTMtimeRcd"; | ||
DTCalibDBUtils::writeToDB<DTMtime>(record, mTimeNewMap); | ||
if (writeLegacyVDriftDB) { | ||
string record = "DTMtimeRcd"; | ||
DTCalibDBUtils::writeToDB<DTMtime>(record, mTimeNewMap); | ||
} else { | ||
DTCalibDBUtils::writeToDB<DTRecoConditions>("DTRecoConditionsVdriftRcd", vDriftNewMap); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move from
edm::EventSetup::get
toedm::EventSetup::getData
https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideHowToGetDataFromES#Getting_data_from_EventSetup_wit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, but this migration has to be done on these classes anyhow, it is not needed as a consequence of this PR.
Therefore it would make more sense to make it in its own PR, after this one is merged.
I can make a new PR for the migration right away after this one is merged; this is my preference given that this PR is by now tested and fully signed.