Skip to content

Commit

Permalink
Merge pull request #5977 from namapane/DTRecoConditions
Browse files Browse the repository at this point in the history
New flexyble payloads for DT ttrig, vdrift and uncertainties
  • Loading branch information
cmsbuild committed Oct 30, 2014
2 parents 3f7f7ae + 76691bf commit 1c012b7
Show file tree
Hide file tree
Showing 21 changed files with 375 additions and 53 deletions.
2 changes: 1 addition & 1 deletion CalibMuon/DTCalibration/plugins/DTCalibrationMap.cc
Expand Up @@ -191,7 +191,7 @@ void DTCalibrationMap::readConsts(const string& inputFileName) {
istream_iterator<float>(),
back_inserter(wireCalib.second));

if(wireCalib.second.size() != nFields){
if(wireCalib.second.size() < nFields){
cout << "[DTCalibrationMap]***Warning: the CalibConstFile is not consistent with the number of fields!" << endl;
}

Expand Down
17 changes: 15 additions & 2 deletions CalibMuon/DTCalibration/plugins/DTCalibrationMap.h
Expand Up @@ -3,10 +3,23 @@

/** \class DTCalibrationMap
* Allow saving and retrieving of calibration constants to/from txt file.
* This is mainly provided for backward compatibility with the ORCA MuBarDigiParameters file.
* This was originally provided for backward compatibility with the ORCA MuBarDigiParameters file.
* Can be used to save an arbitrary number of constants with the
* needed granularity and to retrieve them back using the wireId.
* The first 5 fields for each key are allocated to ttri, sigma_ttrig, kfactor, vdrift and sigma_vdrift.
* Current field allocation: fields for each key are allocated to:
* --First block: legacy descriptors--
* [0] ttrig
* [1] sigma_ttrig (obsolete)
* [2] kfactor (obsolete)
* [3] vdrift
* [4] sigma_vdrift (obsolete, was formerly hacked to include reoslution)
* [5] t0
* [6] t0rms
* [7] noisy or dead flag
* [8-9] left for future usage
* --Second block (optional): free fields
* [10] Encoded information of free fields: (1000*version)+(100*type)+(number of fields); type is: ttrig=0, vdrift=1, uncertainties=3
* [11-end] free fields
*
* \author G. Cerminara - INFN Torino
*/
Expand Down
96 changes: 66 additions & 30 deletions CalibMuon/DTCalibration/test/DBTools/DumpDBToFile.cc
Expand Up @@ -28,7 +28,10 @@
#include "CondFormats/DTObjects/interface/DTReadOutMapping.h"
#include "CondFormats/DataRecord/interface/DTRecoUncertaintiesRcd.h"
#include "CondFormats/DTObjects/interface/DTRecoUncertainties.h"

#include "CondFormats/DTObjects/interface/DTRecoConditions.h"
#include "CondFormats/DataRecord/interface/DTRecoConditionsTtrigRcd.h"
#include "CondFormats/DataRecord/interface/DTRecoConditionsVdriftRcd.h"
#include "CondFormats/DataRecord/interface/DTRecoConditionsUncertRcd.h"
#include <iostream>
#include <fstream>
#include <algorithm>
Expand All @@ -43,10 +46,16 @@ DumpDBToFile::DumpDBToFile(const ParameterSet& pset) {

dbToDump = pset.getUntrackedParameter<string>("dbToDump", "TTrigDB");
dbLabel = pset.getUntrackedParameter<string>("dbLabel", "");
format = pset.getUntrackedParameter<string>("dbFormat", "Legacy");

if(dbToDump != "VDriftDB" && dbToDump != "TTrigDB" && dbToDump != "TZeroDB"
&& dbToDump != "NoiseDB" && dbToDump != "DeadDB" && dbToDump != "ChannelsDB" && dbToDump != "RecoUncertDB")
cout << "[DumpDBToFile] *** Error: parameter dbToDump is not valid, check the cfg file" << endl;

if (format != "Legacy" &&
format != "DTRecoConditions")
cout << "[DumpFileToDB] *** Error: parameter format is not valid, check the cfg file" << endl;

}

DumpDBToFile::~DumpDBToFile(){}
Expand All @@ -55,10 +64,18 @@ DumpDBToFile::~DumpDBToFile(){}
void DumpDBToFile::beginRun(const edm::Run&, const EventSetup& setup) {
// Read the right DB accordingly to the parameter dbToDump
if(dbToDump == "VDriftDB") {
ESHandle<DTMtime> mTime;
setup.get<DTMtimeRcd>().get(mTime);
mTimeMap = &*mTime;
cout << "[DumpDBToFile] MTime version: " << mTime->version() << endl;
if (format=="Legacy") {
ESHandle<DTMtime> mTime;
setup.get<DTMtimeRcd>().get(mTime);
mTimeMap = &*mTime;
cout << "[DumpDBToFile] MTime version: " << mTime->version() << endl;
} else if (format=="DTRecoConditions"){
ESHandle<DTRecoConditions> h_rconds;
setup.get<DTRecoConditionsVdriftRcd>().get(h_rconds);
rconds = &*h_rconds;
cout << "[DumpDBToFile] DTRecoConditions (vdrift) version: " << rconds->version()
<< " expression: " << rconds->getFormulaExpr() << endl;
}
} else if(dbToDump == "TTrigDB") {
ESHandle<DTTtrig> tTrig;
setup.get<DTTtrigRcd>().get(dbLabel,tTrig);
Expand All @@ -85,7 +102,6 @@ void DumpDBToFile::beginRun(const edm::Run&, const EventSetup& setup) {
ESHandle<DTRecoUncertainties> uncerts;
setup.get<DTRecoUncertaintiesRcd>().get(uncerts);
uncertMap = &*uncerts;

}
}

Expand All @@ -94,31 +110,51 @@ void DumpDBToFile::endJob() {

if (dbToDump != "ChannelsDB") {
if(dbToDump == "VDriftDB") {
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);
cout << "Wh: " << (*mtime).first.wheelId
<< " St: " << (*mtime).first.stationId
<< " Sc: " << (*mtime).first.sectorId
<< " Sl: " << (*mtime).first.slId
<< " VDrift (cm/ns): " << vdrift
<< " Hit reso (cm): " << reso << endl;
vector<float> consts;
consts.push_back(-1);
consts.push_back(-1);
consts.push_back(-1);
consts.push_back(vdrift);
consts.push_back(reso);
if (format=="Legacy") {
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);
cout << "Wh: " << (*mtime).first.wheelId
<< " St: " << (*mtime).first.stationId
<< " Sc: " << (*mtime).first.sectorId
<< " Sl: " << (*mtime).first.slId
<< " VDrift (cm/ns): " << vdrift
<< " Hit reso (cm): " << reso << endl;
int version = 1;
int type =1;
int nfields=1;
vector<float> consts = {-1, -1, -1, vdrift, reso, -1, -1, -1, -1, -1, float(version*1000+type*100+nfields), vdrift};
theCalibFile->addCell(wireId, consts);
}
} else if (format=="DTRecoConditions") {
for(DTRecoConditions::const_iterator irc = rconds->begin(); irc != rconds->end(); ++irc) {
DTWireId wireId(irc->first);
const vector<double>& data = irc->second;

theCalibFile->addCell(wireId, consts);
int version = rconds->version();
int type =1;
int nfields = data.size();

// FIXME check size
float vdrift = data[0];
float reso = 0;


vector<float> consts(11+nfields,-1);
consts[3] = vdrift;
consts[4] = reso;
consts[10] = float(version*1000+type*100+nfields);
std::copy(data.begin(),data.end(),consts.begin()+11);
theCalibFile->addCell(wireId, consts);
}
}
} else if(dbToDump == "TTrigDB") {
for(DTTtrig::const_iterator ttrig = tTrigMap->begin();
Expand Down
3 changes: 3 additions & 0 deletions CalibMuon/DTCalibration/test/DBTools/DumpDBToFile.h
Expand Up @@ -22,6 +22,7 @@ class DTDeadFlag;
class DTCalibrationMap;
class DTReadOutMapping;
class DTRecoUncertainties;
class DTRecoConditions;

class DumpDBToFile : public edm::EDAnalyzer {
public:
Expand All @@ -48,13 +49,15 @@ class DumpDBToFile : public edm::EDAnalyzer {
const DTDeadFlag *deadMap;
const DTReadOutMapping *channelsMap;
const DTRecoUncertainties *uncertMap;
const DTRecoConditions *rconds;

DTCalibrationMap *theCalibFile;

std::string theOutputFileName;

std::string dbToDump;
std::string dbLabel;
std::string format;

};
#endif
Expand Down
89 changes: 70 additions & 19 deletions CalibMuon/DTCalibration/test/DBTools/DumpFileToDB.cc
Expand Up @@ -24,6 +24,10 @@
#include "CondFormats/DTObjects/interface/DTDeadFlag.h"
#include "CondFormats/DTObjects/interface/DTReadOutMapping.h"
#include "CondFormats/DTObjects/interface/DTRecoUncertainties.h"
#include "CondFormats/DTObjects/interface/DTRecoConditions.h"
#include "CondFormats/DataRecord/interface/DTRecoConditionsTtrigRcd.h"
#include "CondFormats/DataRecord/interface/DTRecoConditionsVdriftRcd.h"
#include "CondFormats/DataRecord/interface/DTRecoConditionsUncertRcd.h"
#include "CalibMuon/DTCalibration/interface/DTCalibDBUtils.h"

using namespace edm;
Expand All @@ -32,6 +36,7 @@ using namespace std;
DumpFileToDB::DumpFileToDB(const ParameterSet& pset) {

dbToDump = pset.getUntrackedParameter<string>("dbToDump", "TTrigDB");
format = pset.getUntrackedParameter<string>("dbFormat", "Legacy");

if(dbToDump != "ChannelsDB")
theCalibFile = new DTCalibrationMap(pset.getUntrackedParameter<ParameterSet>("calibFileConfig"));
Expand All @@ -47,10 +52,20 @@ DumpFileToDB::DumpFileToDB(const ParameterSet& pset) {
dbToDump != "RecoUncertDB")
cout << "[DumpFileToDB] *** Error: parameter dbToDump is not valid, check the cfg file" << endl;

if (format != "Legacy" &&
format != "DTRecoConditions")
cout << "[DumpFileToDB] *** Error: parameter format is not valid, check the cfg file" << endl;

if (format == "DTRecoConditions" &&
(dbToDump != "VDriftDB" &&
dbToDump != "TTrigDB" &&
dbToDump != "RecoUncertDB"))
cout << "[DumpFileToDB] ***Error: DTRecoConditions currently implemented for ttrig, vdrift, uncertainties only" << endl;

diffMode = pset.getUntrackedParameter<bool>("differentialMode", false);
if(diffMode) {
if(dbToDump != "TTrigDB") {
cout << "***Error: differential mode currentl implemented for ttrig only" << endl;
cout << "[DumpFileToDB] ***Error: differential mode currently implemented for ttrig only" << endl;
abort();
}
cout << "Using differential mode: mean value of txt table will be added to the current DB value" << endl;
Expand All @@ -64,27 +79,63 @@ DumpFileToDB::~DumpFileToDB(){}
void DumpFileToDB::endJob() {
if(dbToDump == "VDriftDB") { // Write the Vdrift

// Create the object to be written to DB
DTMtime* mtime = new DTMtime();
if (format=="Legacy") {
// Create the object to be written to DB
DTMtime* mtime = new DTMtime();

// Loop over file entries
for(DTCalibrationMap::const_iterator keyAndCalibs = theCalibFile->keyAndConsts_begin();
keyAndCalibs != theCalibFile->keyAndConsts_end();
++keyAndCalibs) {
cout << "key: " << (*keyAndCalibs).first
<< " vdrift (cm/ns): " << theCalibFile->meanVDrift((*keyAndCalibs).first)
<< " hit reso (cm): " << theCalibFile->sigma_meanVDrift((*keyAndCalibs).first) << endl;
// vdrift is cm/ns , resolution is cm
mtime->set((*keyAndCalibs).first.superlayerId(),
theCalibFile->meanVDrift((*keyAndCalibs).first),
theCalibFile->sigma_meanVDrift((*keyAndCalibs).first),
DTVelocityUnits::cm_per_ns);
}
// Loop over file entries
for(DTCalibrationMap::const_iterator keyAndCalibs = theCalibFile->keyAndConsts_begin();
keyAndCalibs != theCalibFile->keyAndConsts_end();
++keyAndCalibs) {
cout << "key: " << (*keyAndCalibs).first
<< " vdrift (cm/ns): " << theCalibFile->meanVDrift((*keyAndCalibs).first)
<< " hit reso (cm): " << theCalibFile->sigma_meanVDrift((*keyAndCalibs).first) << endl;
// vdrift is cm/ns , resolution is cm
mtime->set((*keyAndCalibs).first.superlayerId(),
theCalibFile->meanVDrift((*keyAndCalibs).first),
theCalibFile->sigma_meanVDrift((*keyAndCalibs).first),
DTVelocityUnits::cm_per_ns);
}

cout << "[DumpFileToDB]Writing mtime object to DB!" << endl;
string record = "DTMtimeRcd";
DTCalibDBUtils::writeToDB<DTMtime>(record, mtime);
} else if (format=="DTRecoConditions") {
DTRecoConditions* conds = new DTRecoConditions();
conds->setFormulaExpr("[0]*(1-[1]*x)");
for(DTCalibrationMap::const_iterator keyAndCalibs = theCalibFile->keyAndConsts_begin();
keyAndCalibs != theCalibFile->keyAndConsts_end();
++keyAndCalibs) {

vector<float> values = (*keyAndCalibs).second;
if (values.size()<11) {
cout << "[DumpFileToDB] ***Error: Incorrect file format for VDriftDB to be stored in DTRecoConditions" << endl;
abort();
}
int version = int(values[10]/1000);
int type = (int(values[10])%1000)/100;
int nfields = int(values[10])%100;

if (type !=1) {
cout << "[DumpFileToDB] ***Error: input file is not for VDriftDB" << endl;
abort();
}
conds->setVersion(version);

if(values.size()!=unsigned(nfields+11)) {
cout << "[DumpFileToDB] ***Error: Inconsistent number of fields" << endl;
abort();
}

vector<double> params(values.begin()+11, values.begin()+11+nfields);

cout << "[DumpFileToDB]Writing mtime object to DB!" << endl;
string record = "DTMtimeRcd";
DTCalibDBUtils::writeToDB<DTMtime>(record, mtime);
conds->set((*keyAndCalibs).first, params);
}

cout << "[DumpFileToDB]Writing DTRecoConditions object to DB!" << endl;
DTCalibDBUtils::writeToDB<DTRecoConditions>("DTRecoConditionsVdriftRcd", conds);
}

} else if(dbToDump == "TTrigDB") { // Write the TTrig

// Create the object to be written to DB
Expand Down
2 changes: 2 additions & 0 deletions CalibMuon/DTCalibration/test/DBTools/DumpFileToDB.h
Expand Up @@ -44,6 +44,8 @@ class DumpFileToDB : public edm::EDAnalyzer {
std::string mapFileName;

std::string dbToDump;
std::string format;

// sum the correction in the txt file (for the mean value) to what is input DB
bool diffMode;
const DTTtrig *tTrigMapOrig;
Expand Down
9 changes: 8 additions & 1 deletion CondCore/DTPlugins/src/plugin.cc
Expand Up @@ -40,6 +40,10 @@
#include "CondCore/CondDB/interface/KeyListProxy.h"
#include "CondFormats/DTObjects/interface/DTRecoUncertainties.h"
#include "CondFormats/DataRecord/interface/DTRecoUncertaintiesRcd.h"
#include "CondFormats/DTObjects/interface/DTRecoConditions.h"
#include "CondFormats/DataRecord/interface/DTRecoConditionsTtrigRcd.h"
#include "CondFormats/DataRecord/interface/DTRecoConditionsVdriftRcd.h"
#include "CondFormats/DataRecord/interface/DTRecoConditionsUncertRcd.h"

//
#include "CondCore/CondDB/interface/Serialization.h"
Expand Down Expand Up @@ -116,6 +120,9 @@ REGISTER_PLUGIN_INIT(DTLVStatusRcd,DTLVStatus,InitDTLVStatus);
REGISTER_PLUGIN(DTKeyedConfigContainerRcd, cond::BaseKeyed);
REGISTER_KEYLIST_PLUGIN(DTKeyedConfigListRcd,cond::persistency::KeyList,DTKeyedConfigContainerRcd);
REGISTER_PLUGIN(DTRecoUncertaintiesRcd, DTRecoUncertainties);

//New flexyble payloads for ttrig, vdrift, uncertainty
REGISTER_PLUGIN(DTRecoConditionsTtrigRcd, DTRecoConditions);
REGISTER_PLUGIN(DTRecoConditionsVdriftRcd, DTRecoConditions);
REGISTER_PLUGIN(DTRecoConditionsUncertRcd, DTRecoConditions);


1 change: 1 addition & 0 deletions CondFormats/DTObjects/BuildFile.xml
Expand Up @@ -6,6 +6,7 @@
<use name="CondCore/DBCommon"/>
<use name="boost_serialization"/>
<use name="rootrflx"/>
<use name="root"/>
<export>
<lib name="1"/>
</export>

0 comments on commit 1c012b7

Please sign in to comment.