Skip to content
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

Bug fix for compatible mode in UETableProducer. (Same as #12227) #12239

Merged
merged 4 commits into from Nov 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
152 changes: 78 additions & 74 deletions RecoHI/HiJetAlgos/plugins/UETableProducer.cc
Expand Up @@ -32,36 +32,39 @@ using namespace std;
// class decleration
//

class UETableProducer : public edm::EDAnalyzer {
public:
explicit UETableProducer(const edm::ParameterSet&);
~UETableProducer();
namespace {
class UETableProducer : public edm::one::EDAnalyzer<> {
public:
explicit UETableProducer(const edm::ParameterSet&);
~UETableProducer();

private:
virtual void beginRun(const edm::EventSetup&) ;
virtual void analyze(const edm::Event&, const edm::EventSetup&);
virtual void endJob() ;
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
virtual void beginJob() override {}
virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
virtual void endJob() override;

// ----------member data ---------------------------
// ----------member data ---------------------------

bool debug_;
bool jetCorrectorFormat_;
bool debug_;
bool jetCorrectorFormat_;

string calibrationFile_;
unsigned int runnum_;
string calibrationFile_;
unsigned int runnum_;

unsigned int index = 0,
np[5],
ni0[2],
ni1[2],
ni2[2];
unsigned int index = 0,
np[5],
ni0[2],
ni1[2],
ni2[2];

// ue_interpolation_pf0[15][344],
// ue_interpolation_pf1[15][344],
// ue_interpolation_pf2[15][82];

};
// ue_interpolation_pf0[15][344],
// ue_interpolation_pf1[15][344],
// ue_interpolation_pf2[15][82];

};
}
//
// constants, enums and typedefs
//
Expand Down Expand Up @@ -118,23 +121,17 @@ UETableProducer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup

}

// ------------ method called once each job just before starting event loop ------------
void
UETableProducer::beginRun(const edm::EventSetup& iSetup)
{
}

// ------------ method called once each job just after ending the event loop ------------
void
UETableProducer::endJob() {
std::string qpDataName = calibrationFile_.c_str();
std::ifstream textTable_(qpDataName.c_str());

std::vector<float> ue_vec;
UETable *ue_predictor_pf = NULL;

std::unique_ptr<UETable> ue_predictor_pf;
if (!jetCorrectorFormat_) {
ue_predictor_pf = new UETable();
ue_predictor_pf = std::make_unique<UETable>();
}
// unsigned int Nnp_full = np[0] * np[1] * np[2] * np[3] * np[4];
unsigned int Nnp = np[0] * np[1] * (1 + (np[2] - 1) * np[3]) * np[4];
Expand All @@ -143,23 +140,23 @@ UETableProducer::endJob() {
unsigned int Nni2 = ni2[0]*ni2[1];

if (!jetCorrectorFormat_) {
ue_predictor_pf->np.resize(5);
ue_predictor_pf->ni0.resize(2);
ue_predictor_pf->ni1.resize(2);
ue_predictor_pf->ni2.resize(2);

std::copy(np, np + 5, ue_predictor_pf->np.begin());
std::copy(ni0, ni0 + 2, ue_predictor_pf->ni0.begin());
std::copy(ni1, ni1 + 2, ue_predictor_pf->ni1.begin());
std::copy(ni2, ni2 + 2, ue_predictor_pf->ni2.begin());

static const float edge_pseudorapidity[16] = {
-5.191, -2.650, -2.043, -1.740, -1.479, -1.131, -0.783, -0.522, 0.522, 0.783, 1.131, 1.479, 1.740, 2.043, 2.650, 5.191
};
ue_predictor_pf->np.resize(5);
ue_predictor_pf->ni0.resize(2);
ue_predictor_pf->ni1.resize(2);
ue_predictor_pf->ni2.resize(2);

ue_predictor_pf->edgeEta.resize(16);
std::copy(np, np + 5, ue_predictor_pf->np.begin());
std::copy(ni0, ni0 + 2, ue_predictor_pf->ni0.begin());
std::copy(ni1, ni1 + 2, ue_predictor_pf->ni1.begin());
std::copy(ni2, ni2 + 2, ue_predictor_pf->ni2.begin());

std::copy(edge_pseudorapidity, edge_pseudorapidity + 16, ue_predictor_pf->edgeEta.begin());
static const float edge_pseudorapidity[16] = {
-5.191, -2.650, -2.043, -1.740, -1.479, -1.131, -0.783, -0.522, 0.522, 0.783, 1.131, 1.479, 1.740, 2.043, 2.650, 5.191
};

ue_predictor_pf->edgeEta.resize(16);

std::copy(edge_pseudorapidity, edge_pseudorapidity + 16, ue_predictor_pf->edgeEta.begin());

}

Expand All @@ -175,16 +172,16 @@ UETableProducer::endJob() {
int bin0, bin1, bin2, bin3, bin4;
if(index < Nnp){
linestream>>bin0>>bin1>>bin2>>bin3>>bin4>>val;
ue_vec.push_back(val);
ue_vec.push_back(val);
}else if(index < Nnp + Nni0){
linestream>>bin0>>bin1>>val;
ue_vec.push_back(val);
ue_vec.push_back(val);
}else if(index < Nnp + Nni0 + Nni1){
linestream>>bin0>>bin1>>val;
ue_vec.push_back(val);
ue_vec.push_back(val);
}else if(index < Nnp + Nni0 + Nni1 + Nni2){
linestream>>bin0>>bin1>>val;
ue_vec.push_back(val);
ue_vec.push_back(val);
}
++index;

Expand All @@ -194,34 +191,41 @@ UETableProducer::endJob() {

if( pool.isAvailable() ){

if (jetCorrectorFormat_) {
// A minimal dummy line that satisfies the JME # token >= 6 requirement, and has the correct key type
JetCorrectorParameters::Definitions definition("1 0 0 0 Correction L1Offset");
std::vector<JetCorrectorParameters::Record> record(1, JetCorrectorParameters::Record(ue_vec.size(), std::vector<float>(ue_vec.size(), 0), std::vector<float>(ue_vec.size(), 0), ue_vec));
JetCorrectorParameters parameter(definition, record);

JetCorrectorParametersCollection *jme_payload = new JetCorrectorParametersCollection();

jme_payload->push_back(JetCorrectorParametersCollection::L1Offset, parameter);

if( pool->isNewTagRequest( "HeavyIonUERcd" ) ){
pool->createNewIOV<JetCorrectorParametersCollection>( jme_payload, pool->beginOfTime(), pool->endOfTime(), "HeavyIonUERcd" );
}else{
pool->appendSinceTime<JetCorrectorParametersCollection>( jme_payload, pool->currentTime(), "HeavyIonUERcd" );
if (jetCorrectorFormat_) {
// A minimal dummy line that satisfies the JME # token >= 6 requirement, and has the correct key type
JetCorrectorParameters::Definitions definition("1 0 0 0 Correction L1Offset");
std::vector<JetCorrectorParameters::Record> record(1, JetCorrectorParameters::Record(ue_vec.size(), std::vector<float>(ue_vec.size(), 0), std::vector<float>(ue_vec.size(), 0), ue_vec));
JetCorrectorParameters parameter(definition, record);

std::unique_ptr<JetCorrectorParametersCollection> jme_payload = std::make_unique<JetCorrectorParametersCollection>();

jme_payload->push_back(JetCorrectorParametersCollection::L1Offset, parameter);

if( pool->isNewTagRequest( "JetCorrectionsRecord" ) ){
pool->createNewIOV<JetCorrectorParametersCollection>( jme_payload.get(), pool->beginOfTime(), pool->endOfTime(), "JetCorrectionsRecord" );
}else{
pool->appendSinceTime<JetCorrectorParametersCollection>( jme_payload.get(), pool->currentTime(), "JetCorrectionsRecord" );
}
}
}
else {
ue_predictor_pf->values = ue_vec;

if( pool->isNewTagRequest( "HeavyIonUERcd" ) ){
pool->createNewIOV<UETable>( ue_predictor_pf, pool->beginOfTime(), pool->endOfTime(), "HeavyIonUERcd" );
}else{
pool->appendSinceTime<UETable>( ue_predictor_pf, pool->currentTime(), "HeavyIonUERcd" );
else {
ue_predictor_pf->values = ue_vec;

if( pool->isNewTagRequest( "HeavyIonUERcd" ) ){
pool->createNewIOV<UETable>( ue_predictor_pf.get(), pool->beginOfTime(), pool->endOfTime(), "HeavyIonUERcd" );
}else{
pool->appendSinceTime<UETable>( ue_predictor_pf.get(), pool->currentTime(), "HeavyIonUERcd" );
}
}
}
}
}

void UETableProducer::fillDescriptions(edm::ConfigurationDescriptions & descriptions) {
edm::ParameterSetDescription desc;
desc.add<std::string>("txtFile", "example");
desc.addUntracked<bool>("debug", false);
desc.addUntracked<bool>("jetCorrectorFormat", false);
descriptions.add("produceUETable", desc);
}

//define this as a plug-in
DEFINE_FWK_MODULE(UETableProducer);
6 changes: 4 additions & 2 deletions RecoHI/HiJetAlgos/test/make_db.sh
@@ -1,15 +1,17 @@
#!/bin/sh

py=`mktemp --tmpdir=. make_db_XXXXXXXXXX.py`
#py=`mktemp --tmpdir=. make_db_XXXXXXXXXX.py`

trap "rm -f \"$py\"" 1 2 3 15
#trap "rm -f \"$py\"" 1 2 3 15

o="./output.db"
v="00"

#eval `scramv1 runtime -sh`
rm -f "$o"
for f in ue_calibrations_pf_mc.txt ue_calibrations_calo_mc.txt ue_calibrations_pf_data.txt ue_calibrations_calo_data.txt; do
py=`mktemp --tmpdir=. make_db_XXXXXXXXXX.py`
trap "rm -f \"$py\"" 1 2 3 15
e="unknown"
d="unknown"
case "$f" in
Expand Down