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

Feature Bits for 2017 HCAL HF TP #16156

Merged
merged 11 commits into from Oct 18, 2016
18 changes: 16 additions & 2 deletions SimCalorimetry/HcalTrigPrimAlgos/interface/HcalFeatureBit.h
Expand Up @@ -2,14 +2,28 @@
#define SimCalorimetry_HcalTPGAlgos_interface_HcalFeatureBit_h_included 1

#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "DataFormats/HcalDigi/interface/HFDataFrame.h"
#include "DataFormats/HcalDigi/interface/QIE10DataFrame.h"

class HcalFeatureBit {
public:
HcalFeatureBit(){}
virtual ~HcalFeatureBit(){} //the virutal function is responcible for applying a cut based on a linear relationship of the energy
//deposited in the short vers long fibers.
virtual bool fineGrainbit(int ADCShort, HcalDetId Sid, int CapIdS, int ADCLong, HcalDetId Lid, int CapIdL) const {return false;}

virtual bool fineGrainbit(
const QIE10DataFrame& short1,
const QIE10DataFrame& short2,
const QIE10DataFrame& long1,
const QIE10DataFrame& long2,
bool validShort1,
bool validShort2,
bool validLong1,
bool validLong2,
int idx) const = 0;
virtual bool fineGrainbit(
const HFDataFrame& shortDigi,
const HFDataFrame& longDigi,
int idx) const = 0;
};
#endif

55 changes: 46 additions & 9 deletions SimCalorimetry/HcalTrigPrimAlgos/interface/HcalFeatureHFEMBit.h
@@ -1,18 +1,55 @@
#ifndef SimCalorimetry_HcalTPGAlgos_interface_HcalFeatureHFEMBit_h_included
#define SimCalorimetry_HcalTPGAlgos_interface_HcalFeatureHFEMBit_h_included 1


#include "SimCalorimetry/HcalTrigPrimAlgos/interface/HcalFeatureBit.h"
#include "CalibFormats/HcalObjects/interface/HcalDbService.h"
#include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"

class HcalFeatureHFEMBit : public HcalFeatureBit {
public:
HcalFeatureHFEMBit(double ShortMinE, double LongMinE, double ShortLongCutSlope, double ShortLongCutOffset, const HcalDbService& conditions);
~HcalFeatureHFEMBit();
virtual bool fineGrainbit(int ADCShort, HcalDetId Sid, int CapIdS, int ADCLong, HcalDetId Lid, int CapIdL) const;//cuts based on energy
//depoisted in the long and short fibers
private:
double ShortMinE_, LongMinE_, ShortLongCutSlope_, ShortLongCutOffset_;
const HcalDbService& conditions_;
public:
HcalFeatureHFEMBit(double ShortMinE, double LongMinE, double ShortLongCutSlope, double ShortLongCutOffset, const HcalDbService& conditions);
~HcalFeatureHFEMBit();

// Provides FG bit based on energy cuts in long & short fibers.
virtual bool fineGrainbit(
const QIE10DataFrame& short1,
const QIE10DataFrame& short2,
const QIE10DataFrame& long1,
const QIE10DataFrame& long2,
bool validShort1,
bool validShort2,
bool validLong1,
bool validLong2,
int idx) const override;
virtual bool fineGrainbit(
const HFDataFrame& shortDigi,
const HFDataFrame& longDigi,
int idx) const override;
private:
template<typename T>
float getE(const T& f, int idx) const;

double ShortMinE_, LongMinE_, ShortLongCutSlope_, ShortLongCutOffset_;
const HcalDbService& conditions_;
};

template<typename T>
float
HcalFeatureHFEMBit::getE(const T& f, int idx) const
{
const HcalDetId id(f.id());
const HcalCalibrations& calibrations = conditions_.getHcalCalibrations(id);
const auto* coder = conditions_.getHcalCoder(id);
const auto* shape = conditions_.getHcalShape(coder);

HcalCoderDb db(*coder, *shape);
CaloSamples samples;
db.adc2fC(f, samples);

auto ped = calibrations.pedestal(f[idx].capid());
auto corr = calibrations.respcorrgain(f[idx].capid());

return (samples[idx] - ped) * corr;
}

#endif
Expand Up @@ -3,15 +3,17 @@

#include "DataFormats/HcalDetId/interface/HcalTrigTowerDetId.h"
#include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
#include "Geometry/HcalTowerAlgo/interface/HcalTrigTowerGeometry.h"
#include "CalibFormats/CaloObjects/interface/CaloSamples.h"
#include "CalibFormats/CaloObjects/interface/IntegerCaloSamples.h"

#include "CalibCalorimetry/HcalTPGAlgos/interface/HcaluLUTTPGCoder.h"
#include "CalibFormats/CaloTPG/interface/HcalTPGCompressor.h"
#include "CalibFormats/HcalObjects/interface/HcalDbService.h"
#include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"

#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
#include "SimCalorimetry/HcalTrigPrimAlgos/interface/HcalFeatureHFEMBit.h"//cuts based on short and long energy deposited.

#include "Geometry/HcalTowerAlgo/interface/HcalTrigTowerGeometry.h"

#include "SimCalorimetry/HcalTrigPrimAlgos/interface/HcalFeatureHFEMBit.h"
#include "SimCalorimetry/HcalTrigPrimAlgos/interface/HcalFinegrainBit.h"

#include <map>
Expand All @@ -22,12 +24,6 @@ class IntegerCaloSamples;

class HcalTriggerPrimitiveAlgo {
public:
struct TPParameters {
uint64_t hf_tdc_mask;
uint32_t hf_adc_threshold;
uint32_t hf_fg_threshold;
};

HcalTriggerPrimitiveAlgo(bool pf, const std::vector<double>& w, int latency,
uint32_t FG_threshold, uint32_t FG_HF_threshold, uint32_t ZS_threshold,
int numberOfSamples, int numberOfPresamples,
Expand All @@ -38,6 +34,7 @@ class HcalTriggerPrimitiveAlgo {
template<typename... Digis>
void run(const HcalTPGCoder* incoder,
const HcalTPGCompressor* outcoder,
const HcalDbService* conditions,
HcalTrigPrimDigiCollection& result,
const HcalTrigTowerGeometry* trigTowerGeometry,
float rctlsb, const HcalFeatureBit* LongvrsShortCut,
Expand Down Expand Up @@ -73,9 +70,7 @@ class HcalTriggerPrimitiveAlgo {
void setRCTScaleShift(int);

void setUpgradeFlags(bool hb, bool he, bool hf);
void overrideParameters(unsigned int hf_tdc_mask,
unsigned int hf_adc_threshold,
unsigned int hf_fg_threshold);
void overrideParameters(const edm::ParameterSet& ps);

private:

Expand All @@ -89,6 +84,7 @@ class HcalTriggerPrimitiveAlgo {
void addUpgradeFG(const HcalTrigTowerDetId& id, int depth, const std::vector<std::bitset<2>>& bits);

bool validUpgradeFG(const HcalTrigTowerDetId& id, int depth) const;
bool validChannel(const QIE10DataFrame& digi, int ts) const;

/// adds the actual RecHits
void analyze(IntegerCaloSamples & samples, HcalTriggerPrimitiveDigi & result);
Expand All @@ -114,6 +110,7 @@ class HcalTriggerPrimitiveAlgo {
// Member initialized by constructor
const HcaluLUTTPGCoder* incoder_;
const HcalTPGCompressor* outcoder_;
const HcalDbService* conditions_;
double theThreshold;
bool peakfind_;
std::vector<double> weights_;
Expand Down Expand Up @@ -157,6 +154,7 @@ class HcalTriggerPrimitiveAlgo {
struct HFUpgradeDetails {
IntegerCaloSamples samples;
QIE10DataFrame digi;
std::vector<bool> validity;
};
typedef std::map<HcalTrigTowerDetId, std::map<uint32_t, std::array<HFUpgradeDetails, 4>>> HFUpgradeDetailMap;
HFUpgradeDetailMap theHFUpgradeDetailMap;
Expand Down Expand Up @@ -189,12 +187,21 @@ class HcalTriggerPrimitiveAlgo {
bool upgrade_he_ = false;
bool upgrade_hf_ = false;

std::unique_ptr<const TPParameters> override_parameters_;
edm::ParameterSet override_parameters_;

bool override_adc_hf_ = false;
uint32_t override_adc_hf_value_;
bool override_tdc_hf_ = false;
unsigned long long override_tdc_hf_value_;

// HE constants
static const int HBHE_OVERLAP_TOWER = 16;
static const int LAST_FINEGRAIN_DEPTH = 6;
static const int LAST_FINEGRAIN_TOWER = 28;

// Fine-grain in HF ignores tower 29, and starts with 30
static const int FIRST_FINEGRAIN_TOWER = 30;

static const int QIE8_LINEARIZATION_ET = HcaluLUTTPGCoder::QIE8_LUT_BITMASK;
static const int QIE10_LINEARIZATION_ET = HcaluLUTTPGCoder::QIE10_LUT_BITMASK;
static const int QIE11_LINEARIZATION_ET = HcaluLUTTPGCoder::QIE11_LUT_BITMASK;
Expand All @@ -206,14 +213,16 @@ class HcalTriggerPrimitiveAlgo {
template<typename... Digis>
void HcalTriggerPrimitiveAlgo::run(const HcalTPGCoder* incoder,
const HcalTPGCompressor* outcoder,
const HcalDbService* conditions,
HcalTrigPrimDigiCollection& result,
const HcalTrigTowerGeometry* trigTowerGeometry,
float rctlsb, const HcalFeatureBit* LongvrsShortCut,
const Digis&... digis) {
theTrigTowerGeometry = trigTowerGeometry;

incoder_=dynamic_cast<const HcaluLUTTPGCoder*>(incoder);
outcoder_=outcoder;

incoder_ = dynamic_cast<const HcaluLUTTPGCoder*>(incoder);
outcoder_ = outcoder;
conditions_ = conditions;

theSumMap.clear();
theTowerMapFGSum.clear();
Expand All @@ -228,6 +237,10 @@ void HcalTriggerPrimitiveAlgo::run(const HcalTPGCoder* incoder,

// Prepare the fine-grain calculation algorithm for HB/HE
int version = 0;
if (upgrade_he_ or upgrade_hb_)
version = conditions_->getHcalTPParameters()->getFGVersionHBHE();
if (override_parameters_.exists("FGVersionHBHE"))
version = override_parameters_.getParameter<uint32_t>("FGVersionHBHE");
HcalFinegrainBit fg_algo(version);

// VME produces additional bits on the front used by lumi but not the
Expand Down
87 changes: 46 additions & 41 deletions SimCalorimetry/HcalTrigPrimAlgos/src/HcalFeatureHFEMBit.cc
Expand Up @@ -4,7 +4,6 @@

#include "SimCalorimetry/HcalTrigPrimAlgos/interface/HcalFeatureHFEMBit.h"
#include "CondFormats/HcalObjects/interface/HcalQIECoder.h"
#include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"


HcalFeatureHFEMBit::HcalFeatureHFEMBit(double ShortMinE, double LongMinE,
Expand All @@ -21,48 +20,54 @@ HcalFeatureHFEMBit::HcalFeatureHFEMBit(double ShortMinE, double LongMinE,

HcalFeatureHFEMBit::~HcalFeatureHFEMBit() { }

bool HcalFeatureHFEMBit::fineGrainbit(int ADCShort, HcalDetId Sid, int CapIdS, int ADCLong, HcalDetId Lid, int CapIdL) const//pass det id
bool
HcalFeatureHFEMBit::fineGrainbit(
const HFDataFrame& shortDigi,
const HFDataFrame& longDigi,
int idx) const
{
float shortE = getE(shortDigi, idx);
float longE = getE(longDigi, idx);

float ShortE = 0; //holds deposited energy
float LongE = 0;
if (shortE < ShortMinE_)
return false;
if (longE < LongMinE_)
return false;


HcalQIESample sQIESample(ADCShort, CapIdS, 1, 1);
//makes a QIE sample for the short fiber.
HFDataFrame shortf(Sid);
shortf.setSize(1); //not planning on there being anything else here at this point in time so setting the size to 1 shouldn't matter
shortf.setSample(0, sQIESample); //inputs data into digi.
const HcalCalibrations& calibrations = conditions_.getHcalCalibrations(Sid);
const HcalQIECoder* channelCoderS = conditions_.getHcalCoder(Sid);
const HcalQIEShape* shapeS = conditions_.getHcalShape(channelCoderS);

HcalCoderDb coders(*channelCoderS, *shapeS);

CaloSamples tools;
coders.adc2fC(shortf, tools);
ShortE = (tools[0] - calibrations.pedestal(CapIdS)) * calibrations.respcorrgain(CapIdS);

HcalQIESample lQIESample(ADCLong, CapIdL, 1, 1);
HFDataFrame longf(Lid);
longf.setSize(1);
longf.setSample(0, lQIESample);
const HcalCalibrations& calibrationL = conditions_.getHcalCalibrations(Lid);

CaloSamples tool_l;

const HcalQIECoder* channelCoderL = conditions_.getHcalCoder(Lid);
const HcalQIEShape* shapeL = conditions_.getHcalShape(channelCoderL);

HcalCoderDb coderL(*channelCoderL, *shapeL);

coderL.adc2fC(longf, tool_l); // this fills tool_l[0] with linearized adc
LongE = (tool_l[0] - calibrationL.pedestal(CapIdL)) * calibrationL.respcorrgain(CapIdL);


// this actually does the cut
if((ShortE < ((LongE)-(ShortLongCutOffset_)) * ShortLongCutSlope_) && LongE > LongMinE_ && ShortE > ShortMinE_) return true;
else return false;
return (shortE < (longE - ShortLongCutOffset_) * ShortLongCutSlope_);
}


bool HcalFeatureHFEMBit::fineGrainbit(
const QIE10DataFrame& short1,
const QIE10DataFrame& short2,
const QIE10DataFrame& long1,
const QIE10DataFrame& long2,
bool validShort1,
bool validShort2,
bool validLong1,
bool validLong2,
int idx) const
{
float shortE = 0;
if (validShort1)
shortE += getE(short1, idx);
if (validShort2)
shortE += getE(short2, idx);
if (validShort1 and validShort2)
shortE *= .5;

float longE = 0;
if (validLong1)
longE += getE(long1, idx);
if (validLong2)
longE += getE(long2, idx);
if (validLong1 and validLong2)
longE *= .5;

if (shortE < ShortMinE_)
return false;
if (longE < LongMinE_)
return false;

return (shortE < (longE - ShortLongCutOffset_) * ShortLongCutSlope_);
}