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

bsunanda:Run2-hcx78 Correct access of HcalTopology #14313

Merged
merged 3 commits into from May 12, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion CalibCalorimetry/HcalTPGEventSetup/src/HcalTPGCoderULUT.cc
Expand Up @@ -139,7 +139,9 @@ HcalTPGCoderULUT::produce(const HcalTPGRecord& iRecord)
void HcalTPGCoderULUT::dbRecordCallback(const HcalDbRecord& theRec) {
edm::ESHandle<HcalDbService> conditions;
theRec.get(conditions);
const HcalTopology* topo=conditions->getTopologyUsed();
edm::ESHandle<HcalTopology> htopo;
theRec.getRecord<HcalRecNumberingRecord>().get(htopo);
const HcalTopology* topo=&(*htopo);

if (theCoder_==0) {
buildCoder(topo);
Expand Down
3 changes: 2 additions & 1 deletion CalibFormats/HcalObjects/interface/HcalDbRecord.h
Expand Up @@ -23,11 +23,12 @@

#include "CondFormats/DataRecord/interface/HcalAllRcds.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "Geometry/Records/interface/HcalRecNumberingRecord.h"

// class HcalDbRecord : public edm::eventsetup::EventSetupRecordImplementation<HcalDbRecord> {};

class HcalDbRecord : public edm::eventsetup::DependentRecordImplementation <HcalDbRecord,
boost::mpl::vector<IdealGeometryRecord, HcalPedestalsRcd, HcalPedestalWidthsRcd, HcalGainsRcd, HcalGainWidthsRcd,
boost::mpl::vector<HcalRecNumberingRecord, IdealGeometryRecord, HcalPedestalsRcd, HcalPedestalWidthsRcd, HcalGainsRcd, HcalGainWidthsRcd,
HcalQIEDataRcd, HcalQIETypesRcd, HcalChannelQualityRcd, HcalZSThresholdsRcd, HcalRespCorrsRcd,
HcalL1TriggerObjectsRcd, HcalElectronicsMapRcd, HcalTimeCorrsRcd, HcalLUTCorrsRcd, HcalPFCorrsRcd,
HcalLutMetadataRcd > > {};
Expand Down
1 change: 1 addition & 0 deletions CaloOnlineTools/HcalOnlineDb/BuildFile.xml
Expand Up @@ -13,6 +13,7 @@
<use name="CalibCalorimetry/CaloTPG"/>
<use name="CalibCalorimetry/HcalAlgos"/>
<use name="CalibCalorimetry/HcalTPGAlgos"/>
<use name="Geometry/CaloTopology"/>
<use name="CondTools/Hcal"/>
<use name="OnlineDB/Oracle"/>
<export>
Expand Down
114 changes: 62 additions & 52 deletions CaloOnlineTools/HcalOnlineDb/src/WriteL1TriggerObjetsXml.cc
Expand Up @@ -37,24 +37,25 @@
#include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "Geometry/CaloTopology/interface/HcalTopology.h"
#include "Geometry/HcalCommonData/interface/HcalDDDRecConstants.h"
XERCES_CPP_NAMESPACE_USE
//
// class decleration
//

class WriteL1TriggerObjetsXml : public edm::EDAnalyzer {
Copy link
Contributor

Choose a reason for hiding this comment

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

@bsunanda - please, use thread safe analyser

public:
explicit WriteL1TriggerObjetsXml(const edm::ParameterSet&);
~WriteL1TriggerObjetsXml();
public:
explicit WriteL1TriggerObjetsXml(const edm::ParameterSet&);
~WriteL1TriggerObjetsXml();


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

// ----------member data ---------------------------
std::string tagname_;
// ----------member data ---------------------------
std::string tagname_;
};

//
Expand All @@ -70,16 +71,16 @@ class WriteL1TriggerObjetsXml : public edm::EDAnalyzer {
//
WriteL1TriggerObjetsXml::WriteL1TriggerObjetsXml(const edm::ParameterSet& iConfig) : tagname_(iConfig.getParameter<std::string>("TagName"))
{
//now do what ever initialization is needed

//now do what ever initialization is needed
}


WriteL1TriggerObjetsXml::~WriteL1TriggerObjetsXml()
{

// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)
// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)

}

Expand All @@ -92,45 +93,54 @@ WriteL1TriggerObjetsXml::~WriteL1TriggerObjetsXml()
void
WriteL1TriggerObjetsXml::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
{
using namespace edm;
edm::ESHandle<HcalDbService> conditions;
iSetup.get<HcalDbRecord>().get(conditions);
const HcalTopology* topo=conditions->getTopologyUsed();

HcalSubdetector subDet[3] = {HcalBarrel, HcalEndcap, HcalForward};
std::string subDetName[3] = {"HB", "HE", "HF"};

HcalL1TriggerObjectsXml xml(tagname_);
for (int isub = 0; isub < 3; ++isub){
for (int ieta = -41; ieta <= 41; ++ieta){
for (int iphi = 1; iphi <=72; ++iphi){
for (int depth = 1; depth <= 3; ++depth){
HcalDetId id(subDet[isub], ieta, iphi, depth);

if (!topo->valid(id)) continue;
HcalCalibrations calibrations = conditions->getHcalCalibrations(id);
const HcalChannelStatus* channelStatus = conditions->getHcalChannelStatus(id);
uint32_t status = channelStatus->getValue();

double gain = 0.0;
double ped = 0.0;

for (int i=0; i<4; ++i) {
gain += calibrations.LUTrespcorrgain(i);
ped += calibrations.pedestal(i);
}
gain /= 4.;
ped /= 4.;

xml.add_hcal_channel_dataset(ieta, iphi, depth, subDetName[isub], ped, gain, status);
}// for depth
}// for iphi
}// for ieta
}// for subdet

std::string xmlOutputFileName(tagname_);
xmlOutputFileName += ".xml";
xml.write(xmlOutputFileName);
edm::ESHandle<HcalTopology> htopo;
iSetup.get<HcalRecNumberingRecord>().get(htopo);
const HcalTopology* topo = htopo.product();
edm::ESHandle<HcalDbService> conditions;
iSetup.get<HcalDbRecord>().get(conditions);

HcalSubdetector subDet[3] = {HcalBarrel, HcalEndcap, HcalForward};
std::string subDetName[3] = {"HB", "HE", "HF"};
int maxEta(0), maxPhi(72), maxDepth(0);
const HcalDDDRecConstants* hcons = topo->dddConstants();
for (int isub=0; isub<3; ++isub) {
if (hcons->getMaxDepth(isub) > maxDepth) maxDepth = hcons->getMaxDepth(isub);
if (hcons->getEtaRange(isub).second > maxEta)
maxEta = hcons->getEtaRange(isub).second;
if (hcons->getNPhi(isub) > maxPhi) maxPhi = hcons->getNPhi(isub);
}

HcalL1TriggerObjectsXml xml(tagname_);
for (int isub = 0; isub < 3; ++isub){
for (int ieta = -maxEta; ieta <= maxEta; ++ieta){
for (int iphi = 1; iphi <=maxPhi; ++iphi){
for (int depth = 1; depth <= maxDepth; ++depth){
HcalDetId id(subDet[isub], ieta, iphi, depth);

if (!topo->valid(id)) continue;
HcalCalibrations calibrations = conditions->getHcalCalibrations(id);
const HcalChannelStatus* channelStatus = conditions->getHcalChannelStatus(id);
uint32_t status = channelStatus->getValue();

double gain = 0.0;
double ped = 0.0;

for (int i=0; i<4; ++i) {
gain += calibrations.LUTrespcorrgain(i);
ped += calibrations.pedestal(i);
}
gain /= 4.;
ped /= 4.;

xml.add_hcal_channel_dataset(ieta, iphi, depth, subDetName[isub], ped, gain, status);
}// for depth
}// for iphi
}// for ieta
}// for subdet

std::string xmlOutputFileName(tagname_);
xmlOutputFileName += ".xml";
xml.write(xmlOutputFileName);
}

// ------------ method called once each job just before starting event loop ------------
Expand Down
4 changes: 3 additions & 1 deletion Geometry/CaloTopology/interface/HcalTopology.h
Expand Up @@ -145,7 +145,9 @@ class HcalTopology : public CaloSubdetectorTopology {
unsigned int detId2denseIdCALIB(const DetId& id) const;

unsigned int getNumberOfShapes() const { return numberOfShapes_; }


const HcalDDDRecConstants* dddConstants () const {return hcons_;}

private:
/** Get the neighbors of the given cell with higher absolute ieta */
int incAIEta(const HcalDetId& id, HcalDetId neighbors[2]) const;
Expand Down
2 changes: 2 additions & 0 deletions Geometry/HcalCommonData/interface/HcalDDDRecConstants.h
Expand Up @@ -76,6 +76,7 @@ class HcalDDDRecConstants {
int getMaxDepth(const int itype, const int ieta) const;
int getNEta() const {return hpar->etagroup.size();}
int getNoff(const int i) const {return hpar->noff[i];}
int getNPhi(const int type) const {return nPhiBins[type];}
double getPhiBin(const int i) const {return phibin[i];}
double getPhiOff(const int i) const {return hpar->phioff[i];}
const std::vector<double> & getPhiOffs() const {return hpar->phioff;}
Expand Down Expand Up @@ -103,6 +104,7 @@ class HcalDDDRecConstants {
std::vector<int> ietaMap; // Map Sim level ieta to Rec level ieta
std::vector<int> iEtaMin, iEtaMax; // Minimum and maximum eta
std::vector<int> maxDepth; // Maximum depth in HB/HE/HF/HO
std::vector<int> nPhiBins; // Number of phi bis for HB/HE/HF/HO
std::vector<double> phibin; // Phi step for all eta bins (HB, HE, HO)
std::vector<int> phiUnitS; // Phi unit at SIM stage
std::vector<std::pair<double,double> > gconsHB; // Geometry constatnts HB
Expand Down
20 changes: 18 additions & 2 deletions Geometry/HcalCommonData/src/HcalDDDRecConstants.cc
Expand Up @@ -6,7 +6,7 @@
#include "CLHEP/Units/GlobalPhysicalConstants.h"
#include "CLHEP/Units/GlobalSystemOfUnits.h"

//#define DebugLog
#define DebugLog
Copy link
Contributor

Choose a reason for hiding this comment

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

@bsunanda - please, disable debug messages for code which goes into release.


enum {kHOSizePreLS1 = 2160, kHFSizePreLS1 = 1728} ;

Expand Down Expand Up @@ -467,18 +467,30 @@ void HcalDDDRecConstants::initialize(void) {
iEtaMax[1] = ietaHEM;

// Then Phi bins
nPhiBins.clear();
for (unsigned int k=0; k<4; ++k) nPhiBins.push_back(0);
ieta = 0;
phibin.clear(); phiUnitS.clear();
for (int i=0; i<nEta; ++i) {
double dphi = (hpar->phigroup[i])*(hpar->phibin[ieta]);
phibin.push_back(dphi);
int nphi = (int)((CLHEP::twopi + 0.001)/dphi);
if (ieta <= iEtaMax[0]) {
if (nphi > nPhiBins[0]) nPhiBins[3] = nPhiBins[0] = nphi;
}
if (ieta >= iEtaMin[1]) {
if (nphi > nPhiBins[1]) nPhiBins[1] = nphi;
}
ieta += (hpar->etagroup[i]);
}
for (unsigned int i=1; i<hpar->etaTable.size(); ++i) {
int unit = hcons.unitPhi(hpar->phibin[i-1]);
phiUnitS.push_back(unit);
}

for (unsigned int i=0; i<hpar->phitable.size(); ++i) {
int nphi = (int)((CLHEP::twopi + 0.001)/hpar->phitable[i]);
if (nphi > nPhiBins[2]) nPhiBins[2] = nphi;
}
#ifdef DebugLog
std::cout << "Modified eta/deltaphi table for " << nEta << " bins" << std::endl;
for (int i=0; i<nEta; ++i)
Expand All @@ -489,6 +501,10 @@ void HcalDDDRecConstants::initialize(void) {
for (unsigned int i=0; i<phiUnitS.size(); ++i)
std::cout << " [" << i << "] = " << phiUnitS[i];
std::cout << std::endl;
std::cout << "nPhiBins";
for (unsigned int i=0; i<nPhiBins.size(); ++i)
std::cout << " [" << i << "] = " << nPhiBins[i];
std::cout << std::endl;
std::cout << "EtaTableHF";
for (unsigned int i=0; i<hpar->etaTableHF.size(); ++i)
std::cout << " [" << i << "] = " << hpar->etaTableHF[i];
Expand Down