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

Fixes and enhancements on HCAL rechit dumper #16089

Merged
merged 17 commits into from Oct 13, 2016
50 changes: 50 additions & 0 deletions DataFormats/HcalRecHit/src/HcalRecHitDump_cfg.py
@@ -0,0 +1,50 @@
# Run with something like the following:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not have py files in /src directories
there is a /python directory for that
... _cfg files usually live in /test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, this file looks like a duplicate

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was me putting the updated file (at my post-PR update) to "src" instead of "test". Old file removed, new file moved to correct location.

# cmsRun HcalRecHitDump_cfg.py |& grep ^++HBHE++ | sed 's/to -120 ns/to 0 ns/g' > dump.log

import os
import FWCore.ParameterSet.Config as cms

# Get the input file from the environment
inputfile = os.environ['INPUTFILE']

process = cms.Process('Test')

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(10)
)

process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring('file:' + inputfile)
)

# Settings for rechits reconstructed by HBHEPhase1Reconstructor
process.dumpPhase1 = cms.EDAnalyzer(
'HcalRecHitDump',
hbhePrefix = cms.untracked.string("++HBHE++ "),
# hfPrefix = cms.untracked.string("++HF++ "),
# hfprePrefix = cms.untracked.string("++HFPre++ "),
tagHBHE = cms.InputTag("hbheprereco"),
tagPreHF = cms.InputTag("hfprereco"),
tagHF = cms.InputTag("hfreco"),
bits = cms.untracked.vint32(0,11,12,13,15,27,29,30,-1,\
38,37,36,35,34,33,32,-1,46,45,44,43,42,41,40,-1,54,53,52,51,50,49,48,-1,62,61,60,59,58,57,56,-1,\
70,69,68,67,66,65,64,-1,78,77,76,75,74,73,72,-1,86,85,84,83,82,81,80,-1,94,93,92,91,90,89,88,-1,\
121,120)
)

# Settings for rechits reconstructed by HcalHitReconstructor
process.dumpLegacy = cms.EDAnalyzer(
'HcalRecHitDump',
hbhePrefix = cms.untracked.string("++HBHE++ "),
# hfPrefix = cms.untracked.string("++HF++ "),
# hfprePrefix = cms.untracked.string("++HFPre++ "),
tagHBHE = cms.InputTag("hbheprereco"),
tagPreHF = cms.InputTag("hfprereco"),
tagHF = cms.InputTag("hfreco"),
bits = cms.untracked.vint32(0,11,12,13,15,27,29,30,-1,\
70,69,68,67,66,65,64,-1,77,76,75,74,73,72,71,-1,84,83,82,81,80,79,78,-1,91,90,89,88,87,86,85,-1,\
38,37,36,35,34,33,32,-1,45,44,43,42,41,40,39,-1,52,51,50,49,48,47,46,-1,59,58,57,56,55,54,53,-1,\
61,60)
)

process.p = cms.Path(process.dumpPhase1)
216 changes: 149 additions & 67 deletions DataFormats/HcalRecHit/test/HcalRecHitDump.cc
@@ -1,87 +1,169 @@
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include <string>
#include <iostream>
#include <vector>
#include <array>
#include <cstdint>

#include "FWCore/Framework/interface/stream/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/GetterOfProducts.h"
#include "FWCore/Framework/interface/ProcessMatch.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
#include "DataFormats/HcalRecHit/interface/HcalSourcePositionData.h"

#include <string>
#include <iostream>
namespace {
std::ostream& operator<<(std::ostream& s, const HFQIE10Info& i)
{
s << i.id() << ": " << i.energy() << " GeV"
<< ", t= " << i.timeRising() << " to " << i.timeFalling() << " ns";
return s;
}

std::ostream& operator<<(std::ostream& s, const HFPreRecHit& hit)
{
s << "{ ";
const HFQIE10Info* i = hit.getHFQIE10Info(0);
if (i) {s << *i;}
s << " }, ";
s << "{ ";
i = hit.getHFQIE10Info(1);
if (i) {s << *i;}
s << " }";
return s;
}

template <std::size_t N>
void printBits(std::ostream& s, const std::array<uint32_t,N>& allbits,
const std::vector<int>& bits)
{
const int maxbit = N*32;
const unsigned len = bits.size();
for (unsigned i=0; i<len; ++i)
{
const int bitnum = bits[i];
if (bitnum >= 0 && bitnum < maxbit)
{
const unsigned ibit = bitnum % 32;
const bool bit = (allbits[bitnum / 32] & (1U << ibit)) >> ibit;
s << bit;
}
else
s << '-';
}
}

void printRecHitAuxInfo(std::ostream& s, const HFPreRecHit& i,
const std::vector<int>& bits)
{
}

void printRecHitAuxInfo(std::ostream& s, const HBHERecHit& i,
const std::vector<int>& bits)
{
if (!bits.empty())
{
std::array<uint32_t,4> allbits;
allbits[0] = i.flags();
allbits[1] = i.aux();
allbits[2] = i.auxHBHE();
allbits[3] = i.auxPhase1();
s << "; bits: ";
printBits(s, allbits, bits);
}
}

void printRecHitAuxInfo(std::ostream& s, const HFRecHit& i,
const std::vector<int>& bits)
{
if (!bits.empty())
{
std::array<uint32_t,3> allbits;
allbits[0] = i.flags();
allbits[1] = i.aux();
allbits[2] = i.getAuxHF();
s << "; bits: ";
printBits(s, allbits, bits);
}
}
}


using namespace std;

namespace cms {

/** \class HcalRecHitDump

\author J. Mans - Minnesota
*/
class HcalRecHitDump : public edm::EDAnalyzer
{
public:
class HcalRecHitDump : public edm::stream::EDAnalyzer<>
{
public:
explicit HcalRecHitDump(edm::ParameterSet const& conf);
virtual void analyze(edm::Event const& e, edm::EventSetup const& c);

private:
edm::GetterOfProducts<HcalSourcePositionData> getHcalSourcePositionData_;
virtual void analyze(edm::Event const& e, edm::EventSetup const& c) override;

private:
string hbhePrefix_;
string hoPrefix_;
string hfPrefix_;
};

HcalRecHitDump::HcalRecHitDump(edm::ParameterSet const& conf) :
getHcalSourcePositionData_(edm::ProcessMatch("*"), this),
hbhePrefix_(conf.getUntrackedParameter<string>("hbhePrefix", "")),
hoPrefix_(conf.getUntrackedParameter<string>("hoPrefix", "")),
hfPrefix_(conf.getUntrackedParameter<string>("hfPrefix", ""))
{
callWhenNewProductsRegistered(getHcalSourcePositionData_);
}

template<typename COLL>
static void analyzeT(edm::Event const& e, const char* name=0, const char* prefix=0)
{
const string marker(prefix ? prefix : "");
try {
vector<edm::Handle<COLL> > colls;
e.getManyByType(colls);
typename std::vector<edm::Handle<COLL> >::iterator i;
for (i=colls.begin(); i!=colls.end(); i++) {
for (typename COLL::const_iterator j=(*i)->begin(); j!=(*i)->end(); j++)
cout << marker << *j << endl;
}
} catch (...) {
if(name) cout << "No " << name << " RecHits." << endl;
string hfprePrefix_;
std::vector<int> bits_;

edm::EDGetTokenT<HBHERecHitCollection> tok_hbhe_;
edm::EDGetTokenT<HFRecHitCollection> tok_hf_;
edm::EDGetTokenT<HFPreRecHitCollection> tok_prehf_;

unsigned long long counter_;

template<class Collection, class Token>
void analyzeT(edm::Event const& e, const Token& tok,
const char* name, const string& prefix) const
{
cout << prefix << " rechit dump " << counter_ << endl;

edm::Handle<Collection> coll;
bool found = false;
try {
e.getByToken(tok, coll);
found = true;
} catch (...) {
cout << prefix << " Error: no " << name << " rechit data" << endl;
}
if (found)
{
for (typename Collection::const_iterator j = coll->begin(); j != coll->end(); ++j)
{
cout << prefix << *j;
printRecHitAuxInfo(cout, *j, bits_);
cout << endl;
}
}
}
}

void HcalRecHitDump::analyze(edm::Event const& e, edm::EventSetup const& c) {
analyzeT<HBHERecHitCollection>(e, "HB/HE", hbhePrefix_.c_str());
analyzeT<HFRecHitCollection>(e, "HF", hfPrefix_.c_str());
analyzeT<HORecHitCollection>(e, "HO", hoPrefix_.c_str());
analyzeT<HcalCalibRecHitCollection>(e);
analyzeT<ZDCRecHitCollection>(e);
analyzeT<CastorRecHitCollection>(e);

std::vector<edm::Handle<HcalSourcePositionData> > handles;
getHcalSourcePositionData_.fillHandles(e, handles);
for (auto const& spd : handles){
cout << *spd << endl;
}
cout << endl;
}
};

HcalRecHitDump::HcalRecHitDump(edm::ParameterSet const& conf)
: hbhePrefix_(conf.getUntrackedParameter<string>("hbhePrefix", "")),
hfPrefix_(conf.getUntrackedParameter<string>("hfPrefix", "")),
hfprePrefix_(conf.getUntrackedParameter<string>("hfprePrefix", "")),
bits_(conf.getUntrackedParameter<std::vector<int> >("bits")),
counter_(0)
{
if (!hbhePrefix_.empty())
tok_hbhe_ = consumes<HBHERecHitCollection>(
conf.getParameter<edm::InputTag>("tagHBHE"));
if (!hfPrefix_.empty())
tok_hf_ = consumes<HFRecHitCollection>(
conf.getParameter<edm::InputTag>("tagHF"));
if (!hfprePrefix_.empty())
tok_prehf_ = consumes<HFPreRecHitCollection>(
conf.getParameter<edm::InputTag>("tagPreHF"));
}

#include "FWCore/PluginManager/interface/ModuleDef.h"
#include "FWCore/Framework/interface/MakerMacros.h"

using namespace cms;

void HcalRecHitDump::analyze(edm::Event const& e, edm::EventSetup const& c)
{
if (!hbhePrefix_.empty())
analyzeT<HBHERecHitCollection>(e, tok_hbhe_, "HBHE", hbhePrefix_);
if (!hfPrefix_.empty())
analyzeT<HFRecHitCollection>(e, tok_hf_, "HF", hfPrefix_);
if (!hfprePrefix_.empty())
analyzeT<HFPreRecHitCollection>(e, tok_prehf_, "PreHF", hfprePrefix_);
++counter_;
}

DEFINE_FWK_MODULE(HcalRecHitDump);

48 changes: 48 additions & 0 deletions DataFormats/HcalRecHit/test/HcalRecHitDump_cfg.py
@@ -0,0 +1,48 @@
# Run with something like the following:
# cmsRun HcalRecHitDump_cfg.py |& grep ^++HBHE++ | sed 's/to -120 ns/to 0 ns/g' > dump.log

import FWCore.ParameterSet.Config as cms

process = cms.Process('Test')

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(10)
)

process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring('file:/afs/cern.ch/user/i/igv/CMSSW_8_1_X_2016-09-26-2300/src/25.0_TTbar+TTbar+DIGI+RECOAlCaCalo+HARVEST+ALCATT/step3.root')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

general preference is to have not dependence on private afs directories in the public release software

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afs file reference removed.

)

# Settings for rechits reconstructed by HBHEPhase1Reconstructor
process.dumpPhase1 = cms.EDAnalyzer(
'HcalRecHitDump',
hbhePrefix = cms.untracked.string("++HBHE++ "),
# hfPrefix = cms.untracked.string("++HF++ "),
# hfprePrefix = cms.untracked.string("++HFPre++ "),
tagHBHE = cms.InputTag("hbheprereco"),
tagPreHF = cms.InputTag("hfprereco"),
tagHF = cms.InputTag("hfreco"),
bits = cms.untracked.vint32(0,11,12,13,15,27,29,30,-1,\
32,33,34,35,36,37,38,40,41,42,43,44,45,46,48,49,50,51,52,53,54,56,57,58,59,60,61,62,-1,\
64,65,66,67,68,69,70,72,73,74,75,76,77,78,80,81,82,83,84,85,86,88,89,90,91,92,93,94,-1,\
120,121)
)

# Settings for rechits reconstructed by HcalHitReconstructor
process.dumpLegacy = cms.EDAnalyzer(
'HcalRecHitDump',
hbhePrefix = cms.untracked.string("++HBHE++ "),
# hfPrefix = cms.untracked.string("++HF++ "),
# hfprePrefix = cms.untracked.string("++HFPre++ "),
tagHBHE = cms.InputTag("hbheprereco"),
tagPreHF = cms.InputTag("hfprereco"),
tagHF = cms.InputTag("hfreco"),
bits = cms.untracked.vint32(0,11,12,13,15,27,29,30,-1,\
64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,-1,\
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,-1,\
60,61)
)

# Change the path to "process.dumpLegacy" for dumping rechits produced by
# HcalHitReconstructor
process.p = cms.Path(process.dumpPhase1)