Skip to content

Commit

Permalink
Merge pull request #34612 from namapane/DTVDriftFormat2_120X
Browse files Browse the repository at this point in the history
Update DT DQM, calibration scripts, and local reco code to allow using "new" DB format
  • Loading branch information
cmsbuild committed Aug 12, 2021
2 parents ac8d8f2 + 8fa7b72 commit efd0017
Show file tree
Hide file tree
Showing 24 changed files with 348 additions and 103 deletions.
35 changes: 28 additions & 7 deletions CalibMuon/DTCalibration/plugins/DTTTrigResidualCorrection.cc
Expand Up @@ -15,6 +15,8 @@
#include "CondFormats/DataRecord/interface/DTTtrigRcd.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"

Expand Down Expand Up @@ -48,6 +50,7 @@ namespace dtCalibration {
//useConstantvDrift_ = pset.getParameter<bool>("useConstantDriftVelocity");
dbLabel_ = pset.getUntrackedParameter<string>("dbLabel", "");
useSlopesCalib_ = pset.getUntrackedParameter<bool>("useSlopesCalib", false);
readLegacyVDriftDB = pset.getParameter<bool>("readLegacyVDriftDB");

// Load external slopes
if (useSlopesCalib_) {
Expand Down Expand Up @@ -83,9 +86,22 @@ namespace dtCalibration {
tTrigMap_ = &*tTrig;

// Get vDrift record
ESHandle<DTMtime> mTimeHandle;
setup.get<DTMtimeRcd>().get(mTimeHandle);
mTimeMap_ = &*mTimeHandle;
if (readLegacyVDriftDB) {
ESHandle<DTMtime> mTimeHandle;
setup.get<DTMtimeRcd>().get(mTimeHandle);
mTimeMap_ = &*mTimeHandle;
vDriftMap_ = nullptr;
} else {
ESHandle<DTRecoConditions> hVdrift;
setup.get<DTRecoConditionsVdriftRcd>().get(hVdrift);
vDriftMap_ = &*hVdrift;
mTimeMap_ = nullptr;
// 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";
}
}
}

DTTTrigData DTTTrigResidualCorrection::correction(const DTSuperLayerId& slId) {
Expand All @@ -94,10 +110,15 @@ namespace dtCalibration {
if (status != 0)
throw cms::Exception("[DTTTrigResidualCorrection]") << "Could not find tTrig entry in DB for" << slId << endl;

float vDrift, hitResolution;
status = mTimeMap_->get(slId, vDrift, hitResolution, DTVelocityUnits::cm_per_ns);
if (status != 0)
throw cms::Exception("[DTTTrigResidualCorrection]") << "Could not find vDrift entry in DB for" << slId << endl;
float vDrift, hitResolution = 0.;
if (readLegacyVDriftDB) { // Legacy format
status = mTimeMap_->get(slId, vDrift, hitResolution, DTVelocityUnits::cm_per_ns);
if (status != 0)
throw cms::Exception("[DTTTrigResidualCorrection]") << "Could not find vDrift entry in DB for" << slId << endl;
} else {
vDrift = vDriftMap_->get(DTWireId(slId.rawId()));
}

TH1F residualHisto = *(getHisto(slId));
LogTrace("Calibration") << "[DTTTrigResidualCorrection]: \n"
<< " Mean, RMS = " << residualHisto.GetMean() << ", " << residualHisto.GetRMS();
Expand Down
6 changes: 5 additions & 1 deletion CalibMuon/DTCalibration/plugins/DTTTrigResidualCorrection.h
Expand Up @@ -18,6 +18,7 @@ namespace edm {

class DTTtrig;
class DTMtime;
class DTRecoConditions;
class DTResidualFitter;

class TH1F;
Expand Down Expand Up @@ -50,7 +51,10 @@ namespace dtCalibration {
double vDriftEff_[5][14][4][3];

const DTTtrig* tTrigMap_;
const DTMtime* mTimeMap_;
const DTMtime* mTimeMap_; // legacy vdrift DB object
const DTRecoConditions* vDriftMap_; // vdrift DB object in new format
bool readLegacyVDriftDB; // which one to use

DTResidualFitter* fitter_;
};

Expand Down
29 changes: 25 additions & 4 deletions CalibMuon/DTCalibration/plugins/DTVDriftCalibration.cc
Expand Up @@ -20,6 +20,7 @@
#include "CalibMuon/DTDigiSync/interface/DTTTrigBaseSync.h"

#include "CondFormats/DTObjects/interface/DTMtime.h"
#include "CondFormats/DTObjects/interface/DTRecoConditions.h"

#include "CondFormats/DataRecord/interface/DTStatusFlagRcd.h"
#include "CondFormats/DTObjects/interface/DTStatusFlag.h"
Expand Down Expand Up @@ -82,6 +83,8 @@ DTVDriftCalibration::DTVDriftCalibration(const ParameterSet& pset)
// the granularity to be used for tMax
string tMaxGranularity = pset.getUntrackedParameter<string>("tMaxGranularity", "bySL");

writeLegacyVDriftDB = pset.getParameter<bool>("writeLegacyVDriftDB");

// Enforce it to be by SL since rest is not implemented
if (tMaxGranularity != "bySL") {
LogError("Calibration") << "[DTVDriftCalibration] tMaxGranularity will be fixed to bySL.";
Expand Down Expand Up @@ -281,7 +284,16 @@ void DTVDriftCalibration::endJob() {
// Instantiate a DTCalibrationMap object if you want to calculate the calibration constants
DTCalibrationMap calibValuesFile(theCalibFilePar);
// Create the object to be written to DB
DTMtime* mTime = new DTMtime();
DTMtime* mTime = nullptr;
DTRecoConditions* vDrift = nullptr;
if (writeLegacyVDriftDB) {
mTime = new DTMtime();
} else {
vDrift = new DTRecoConditions();
vDrift->setFormulaExpr("[0]");
//vDriftNewMap->setFormulaExpr("[0]*(1-[1]*x)"); // add parametrization for dependency along Y
vDrift->setVersion(1);
}

// write the TMax histograms of each SL to the root file
if (theGranularity == bySL) {
Expand Down Expand Up @@ -322,7 +334,12 @@ void DTVDriftCalibration::endJob() {
calibValuesFile.addCell(calibValuesFile.getKey(wireId), newConstants);

// vdrift is cm/ns , resolution is cm
mTime->set((wireId.layerId()).superlayerId(), vDriftAndReso[0], vDriftAndReso[1], DTVelocityUnits::cm_per_ns);
if (writeLegacyVDriftDB) {
mTime->set((wireId.layerId()).superlayerId(), vDriftAndReso[0], vDriftAndReso[1], DTVelocityUnits::cm_per_ns);
} else {
vector<double> params = {vDriftAndReso[0]};
vDrift->set(wireId, params);
}
LogTrace("Calibration") << " SL: " << (wireId.layerId()).superlayerId() << " vDrift = " << vDriftAndReso[0]
<< " reso = " << vDriftAndReso[1];
}
Expand Down Expand Up @@ -366,8 +383,12 @@ void DTVDriftCalibration::endJob() {
LogVerbatim("Calibration") << "[DTVDriftCalibration]Writing vdrift object to DB!";

// Write the vdrift object to DB
string record = "DTMtimeRcd";
DTCalibDBUtils::writeToDB<DTMtime>(record, mTime);
if (writeLegacyVDriftDB) {
string record = "DTMtimeRcd";
DTCalibDBUtils::writeToDB<DTMtime>(record, mTime);
} else {
DTCalibDBUtils::writeToDB<DTRecoConditions>("DTRecoConditionsVdriftRcd", vDrift);
}
}

// to be implemented: granularity different from bySL
Expand Down
3 changes: 3 additions & 0 deletions CalibMuon/DTCalibration/plugins/DTVDriftCalibration.h
Expand Up @@ -129,5 +129,8 @@ class DTVDriftCalibration : public edm::EDAnalyzer {

// Choose the chamber you want to calibrate
std::string theCalibChamber;

// which format to be created
bool writeLegacyVDriftDB;
};
#endif
Expand Up @@ -8,6 +8,7 @@
#rootBaseDir = cms.untracked.string('/DQMData/DT/DTCalibValidation'),
rootBaseDir = cms.untracked.string('DTResiduals'),
dbLabel = cms.untracked.string(''),
useFitToResiduals = cms.bool(True)
)
useFitToResiduals = cms.bool(True),
readLegacyVDriftDB =cms.bool(True)
),
)
3 changes: 2 additions & 1 deletion CalibMuon/DTCalibration/python/dtVDriftAnalyzer_cfg.py
Expand Up @@ -14,7 +14,8 @@
)

process.dtVDriftAnalyzer = cms.EDAnalyzer("DTVDriftAnalyzer",
rootFileName = cms.untracked.string('')
rootFileName = cms.untracked.string(''),
readLegacyVDriftDB =cms.bool(True),
)

process.p = cms.Path(process.dtVDriftAnalyzer)
Expand Up @@ -39,5 +39,9 @@
calibConstFileName = cms.untracked.string('vDriftAndReso.txt')
),
# Name of the txt file which will contain the calibrated v_drift
vDriftFileName = cms.untracked.string('vDriftFromMtime.txt')
vDriftFileName = cms.untracked.string('vDriftFromMtime.txt'),

# Use legacy DB format
writeLegacyVDriftDB =cms.bool(True),

)
Expand Up @@ -39,5 +39,8 @@
calibConstFileName = cms.untracked.string('vDriftAndReso.txt')
),
# Name of the txt file which will contain the calibrated v_drift
vDriftFileName = cms.untracked.string('vDriftFromMtime.txt')
vDriftFileName = cms.untracked.string('vDriftFromMtime.txt'),

# Use legacy DB format
writeLegacyVDriftDB =cms.bool(True),
)
Expand Up @@ -5,5 +5,7 @@
vDriftAlgoConfig = cms.PSet(
rootFileName = cms.string(''),
debug = cms.untracked.bool(False)
)
),
readLegacyVDriftDB = cms.bool(True),
writeLegacyVDriftDB = cms.bool(True)
)
64 changes: 51 additions & 13 deletions CalibMuon/DTCalibration/test/DBTools/DTVDriftAnalyzer.cc
Expand Up @@ -11,6 +11,9 @@
#include "FWCore/Framework/interface/EventSetup.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 "FWCore/MessageLogger/interface/MessageLogger.h"
#include <iostream>
#include "TFile.h"
#include "TH1D.h"
Expand All @@ -19,7 +22,8 @@
using namespace edm;
using namespace std;

DTVDriftAnalyzer::DTVDriftAnalyzer(const ParameterSet& pset) {
DTVDriftAnalyzer::DTVDriftAnalyzer(const ParameterSet& pset)
: readLegacyVDriftDB(pset.getParameter<bool>("readLegacyVDriftDB")) {
// The root file which will contain the histos
string rootFileName = pset.getUntrackedParameter<string>("rootFileName");
theFile = new TFile(rootFileName.c_str(), "RECREATE");
Expand All @@ -29,23 +33,57 @@ DTVDriftAnalyzer::DTVDriftAnalyzer(const ParameterSet& pset) {
DTVDriftAnalyzer::~DTVDriftAnalyzer() { theFile->Close(); }

void DTVDriftAnalyzer::beginRun(const edm::Run& run, const edm::EventSetup& eventSetup) {
ESHandle<DTMtime> mTime;
eventSetup.get<DTMtimeRcd>().get(mTime);
mTimeMap = &*mTime;
cout << "[DTVDriftAnalyzer] MTime version: " << mTime->version() << endl;
if (readLegacyVDriftDB) {
ESHandle<DTMtime> mTime;
eventSetup.get<DTMtimeRcd>().get(mTime);
mTimeMap = &*mTime;
vDriftMap_ = nullptr;
edm::LogVerbatim("DTVDriftAnalyzer") << "[DTVDriftAnalyzer] MTime version: " << mTime->version() << endl;
} else {
ESHandle<DTRecoConditions> hVdrift;
eventSetup.get<DTRecoConditionsVdriftRcd>().get(hVdrift);
vDriftMap_ = &*hVdrift;
mTimeMap = nullptr;
// 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";
}
}
}

void DTVDriftAnalyzer::endJob() {
// Loop over DB entries
for (DTMtime::const_iterator mtime = mTimeMap->begin(); mtime != mTimeMap->end(); ++mtime) {
DTWireId wireId(
(*mtime).first.wheelId, (*mtime).first.stationId, (*mtime).first.sectorId, (*mtime).first.slId, 0, 0);
float vdrift;
float reso;
DetId detId(wireId.rawId());

map<uint32_t, pair<float, float>> values;

if (readLegacyVDriftDB) {
for (DTMtime::const_iterator mtime = mTimeMap->begin(); mtime != mTimeMap->end(); ++mtime) {
DTWireId wireId(
(*mtime).first.wheelId, (*mtime).first.stationId, (*mtime).first.sectorId, (*mtime).first.slId, 0, 0);
float vdrift;
float reso;
DetId detId(wireId.rawId());
// vdrift is cm/ns , resolution is cm
mTimeMap->get(detId, vdrift, reso, DTVelocityUnits::cm_per_ns);
values[wireId.rawId()] = make_pair(vdrift, reso);
}
} else {
for (DTRecoConditions::const_iterator vd = vDriftMap_->begin(); vd != vDriftMap_->end(); ++vd) {
DTWireId wireId(vd->first);
float vdrift = vDriftMap_->get(wireId);
values[vd->first] = make_pair(vdrift, 0.f);
}
}

for (map<uint32_t, pair<float, float>>::const_iterator it = values.begin(); it != values.end(); ++it) {
float vdrift = it->second.first;
float reso = it->second.second;
DTWireId wireId(it->first);
// vdrift is cm/ns , resolution is cm
mTimeMap->get(detId, vdrift, reso, DTVelocityUnits::cm_per_ns);
cout << "Wire: " << wireId << endl << " vdrift (cm/ns): " << vdrift << endl << " reso (cm): " << reso << endl;
edm::LogVerbatim("DTVDriftAnalyzer") << "Wire: " << wireId << endl
<< " vdrift (cm/ns): " << vdrift << endl
<< " reso (cm): " << reso << endl;

//Define an histo for each wheel and each superlayer type
TH1D* hVDriftHisto = theVDriftHistoMap[make_pair(wireId.wheel(), wireId.superlayer())];
Expand Down
5 changes: 4 additions & 1 deletion CalibMuon/DTCalibration/test/DBTools/DTVDriftAnalyzer.h
Expand Up @@ -18,6 +18,7 @@
#include <vector>

class DTMtime;
class DTRecoConditions;
class TFile;
class TH1D;

Expand Down Expand Up @@ -45,7 +46,9 @@ class DTVDriftAnalyzer : public edm::EDAnalyzer {
TFile* theFile;

//The t0 map
const DTMtime* mTimeMap;
const DTMtime* mTimeMap; // legacy DB object
const DTRecoConditions* vDriftMap_; // DB object in new format
bool readLegacyVDriftDB; // which one to use

// Map of the vdrift, reso histos by wheel/sector/SL
std::map<std::pair<int, int>, TH1D*> theVDriftHistoMap;
Expand Down

0 comments on commit efd0017

Please sign in to comment.