Commit 9a0f4b7a authored by Antonio Manuel Mendes Jacques Da Costa's avatar Antonio Manuel Mendes Jacques Da Costa Committed by Vakhtang Tsulaia
Browse files

Changes on energy encoding scheme

parent 852d2ef1
......@@ -22,22 +22,30 @@ This simple utility class contains 3 functions:
- Compress: encodes a signed integer MeV value
- Expand: decodes a 10 bit unsigned int into a signed integer MeV value
- Threshold: applies a threshold (in MeV) to the compressed code, zeroing if below
- NoiseCut: applies a noise cut per layer
- Linearize: decodes a 10 bit unsigned int into the unsigned 16 bit eFEX ET with
least count of 25 MeV. A user-defined threshold (in MeV) can be
applied, but as the eFEX ET is positive a negative threshold is
equivalent to a threshold of 0.
- Decode: encodes a signed integer MeV value, checks is noise cut is passed,
and then decodes a 10 bit unsigned int into the unsigned 16 bit eFEX ET
with least count of 25 MeV.
*/
class eFEXCompression {
public:
/** Compress data */
static unsigned int Compress(int Et);
static unsigned int compress(int Et);
/** Uncompress data */
static int Expand(unsigned int code);
static int expand(unsigned int code);
/** Apply threshold to compressed data */
static unsigned int Threshold(unsigned int code, int threshold = -800);
static unsigned int threshold(unsigned int code, int threshold = -800);
/** Apply supercell noise cut **/
static bool noiseCut(unsigned int code, int layer);
/** Linearize LAr code to eFEX internal format */
static unsigned int Linearize(unsigned int code, int threshold = 0);
static unsigned int linearize(unsigned int code, int threshold = 0);
/** Full sequence **/
static unsigned int decode(int EtVal, int layer);
private:
/** Maximum ET value that can be encoded */
......@@ -70,6 +78,12 @@ private:
static const unsigned int s_eFEXOverflow = 0xffff;
/** Error return value */
static const int s_error = -999;
/** Noise Cuts per layer **/
static const unsigned int m_noisecutPS = 36; // corresponds to 100 MeV
static const unsigned int m_noisecutL1 = 36;
static const unsigned int m_noisecutL2 = 36;
static const unsigned int m_noisecutL3 = 36;
static const unsigned int m_noisecutHad = 36;
};
......
......@@ -77,22 +77,22 @@ namespace LVL1 {
float constid() const {return m_tower_id;};
/** Get ET of a specified cell in MeV */
int getET(unsigned int layer, int cell = 0) const;
unsigned int getET(unsigned int layer, int cell = 0) const;
/** Get ET sum of all cells in the eTower in MeV */
int getTotalET() const;
unsigned int getTotalET() const;
/** Get total ET sum of all cells in a given layer in MeV */
int getLayerTotalET(unsigned int layer) const;
unsigned int getLayerTotalET(unsigned int layer) const;
/** Get vector of ET values for a given layer in MeV */
std::vector<int> getLayerETvec(unsigned int layer) const;
std::vector<unsigned int> getLayerETvec(unsigned int layer) const;
/** Get vector of all ET values in MeV */
std::vector<int> getETs() const {return m_et;};
std::vector<unsigned int> getETs() const {return m_et;};
/** Get vector of INT which describe whether a slot shared split ET from two different supercells - required information for production of CSV input files */
std::vector<int> getETSplits() const {return m_etSplits;};
std::vector<unsigned int> getETSplits() const {return m_etSplits;};
/** Get ET of a specified cell in MeV FLOAT VERSION */
float getET_float(unsigned int layer, int cell = 0) const;
......@@ -120,9 +120,6 @@ namespace LVL1 {
std::vector<Identifier> getLayerSCIDs(unsigned int layer) const;
/** Apply supercell noise cut **/
bool noiseCut(int et, int layer) const;
void setPosNeg(int posneg);
inline int getPosNeg() const {return m_posneg;}
......@@ -132,16 +129,11 @@ namespace LVL1 {
float m_eta;
float m_phi;
std::vector<Identifier> m_scID;
std::vector<int> m_et;
std::vector<unsigned int> m_et;
std::vector<float> m_et_float;
std::vector<int> m_etSplits;
std::vector<unsigned int> m_etSplits;
int m_tower_id;
int m_posneg = 0;
int m_noisecutPS = 100;
int m_noisecutL1 = 100;
int m_noisecutL2 = 100;
int m_noisecutL3 = 100;
int m_noisecutHad = 100;
};
......
......@@ -16,7 +16,7 @@ const int eFEXCompression::s_steps[] = {25, 50, 100, 200, 400, 102400};
const int eFEXCompression::s_minET[] = {-750, 1600, 6400, 25600, 102400, 200000};
const int eFEXCompression::s_minCode[] = {2, 96, 192, 384, 768, 1012};
unsigned int eFEXCompression::Compress(int Et) {
unsigned int eFEXCompression::compress(int Et) {
// Check for overflow
if (Et >= s_maxET) return s_LArOverflow;
......@@ -44,7 +44,7 @@ unsigned int eFEXCompression::Compress(int Et) {
return code;
}
int eFEXCompression::Expand(unsigned int code) {
int eFEXCompression::expand(unsigned int code) {
// Deal with special codes first:
if (code == s_NoData) return 0;
......@@ -64,11 +64,39 @@ int eFEXCompression::Expand(unsigned int code) {
return Et;
}
bool eFEXCompression::noiseCut(unsigned int code, int layer) {
// Check if noise cut is passed - one cut per layer
bool pass=true;
switch(layer){
case 0:
if(code<m_noisecutPS){ pass = false; }
break;
case 1:
if(code<m_noisecutL1){ pass = false; }
break;
case 2:
if(code<m_noisecutL2){ pass = false; }
break;
case 3:
if(code<m_noisecutL3){ pass = false; }
break;
case 4:
if(code<m_noisecutHad){ pass = false; }
break;
default:
pass = false;
break;
}
return pass;
}
unsigned int eFEXCompression::Threshold(unsigned int code, int threshold) {
unsigned int eFEXCompression::threshold(unsigned int code, int threshold) {
/// Convert threshold into a compressed code
unsigned int cut = eFEXCompression::Compress(threshold);
unsigned int cut = eFEXCompression::compress(threshold);
/// Zero code if < threshold
if (code < cut) code = 0;
......@@ -77,14 +105,14 @@ unsigned int eFEXCompression::Threshold(unsigned int code, int threshold) {
}
unsigned int eFEXCompression::Linearize(unsigned int code, int threshold) {
unsigned int eFEXCompression::linearize(unsigned int code, int threshold) {
/// Apply the threshold. Since eFEX ET is positive, minimum threshold is 0.
if (threshold < 0) threshold = 0;
code = eFEXCompression::Threshold(code, threshold);
code = eFEXCompression::threshold(code, threshold);
/// Expand the ET value
int Et = eFEXCompression::Expand(code);
int Et = eFEXCompression::expand(code);
// Check for overflow
if (Et >= s_maxET) return s_eFEXOverflow;
......@@ -94,4 +122,27 @@ unsigned int eFEXCompression::Linearize(unsigned int code, int threshold) {
return eFexET;
}
unsigned int eFEXCompression::decode(int EtVal, int layer) {
// Calculate code
unsigned int tcode = eFEXCompression::compress(EtVal);
/// Check if noise cut is passed
unsigned int code = 0; // corresponds to 0 GeV
if (eFEXCompression::noiseCut(tcode,layer)) {
code = tcode;
}
/// Expand the ET value
int Et = eFEXCompression::expand(code);
// Check for overflow
if (Et >= s_maxET) return s_eFEXOverflow;
/// Convert to eFEX digit scale: 25 MeV
unsigned int eFexET = Et/s_eFEXstep;
return eFexET;
}
} // end of namespace bracket
......@@ -142,7 +142,7 @@ StatusCode eFEXDriver::finalize()
int slotcount = 0;
for (int layer = 0; layer<=4; layer++){
std::vector<Identifier> scIDs = (*thistower)->getLayerSCIDs(layer);
std::vector<int> splits = (*thistower)->getETSplits();
std::vector<unsigned int> splits = (*thistower)->getETSplits();
for (long unsigned int ncell = 0; ncell < scIDs.size(); ncell++){
sc_tower_map << (*thistower)->id() << "," << scIDs[ncell] << "," << slotcount << "," << splits[slotcount] << "\n";
slotcount++;
......
......@@ -95,6 +95,7 @@ StatusCode eFEXFPGA::execute(eFEXOutputCollection* inputOutputCollection){
auto & thr_eEM = l1Menu->thrExtraInfo().eEM();
const unsigned int eFexstep = 25;
const unsigned int eFexTobstep = 100;
for(int ieta = 1; ieta < 5; ieta++) {
......@@ -119,12 +120,13 @@ StatusCode eFEXFPGA::execute(eFEXOutputCollection* inputOutputCollection){
unsigned int ptMinToTopoCounts = 0;
ptMinToTopoCounts = thr_eEM.ptMinToTopoCounts();
//returns a unsigned integer et value corresponding to the... eFEX EM cluster? in MeV?
//returns a unsigned integer et value corresponding to the... eFEX EM cluster? in 1 MeV scale
unsigned int eEMTobEt = 0;
eEMTobEt = m_eFEXegAlgoTool->getET();
unsigned int eEMTobEtCounts = 0;
eEMTobEtCounts = eEMTobEt/eFexTobstep;//steps of 100 MeV for the TOB
eEMTobEtCounts = eEMTobEt*eFexstep/eFexTobstep; //rescale from 25 MeV eFEX steps to 100 MeV for the TOB
// thresholds from Trigger menu
auto iso_loose = thr_eEM.isolation(TrigConf::Selection::WP::LOOSE, ieta);
auto iso_medium = thr_eEM.isolation(TrigConf::Selection::WP::MEDIUM, ieta);
......
......@@ -232,7 +232,7 @@ std::vector<int>* LVL1::eFakeTower::loadBlock(std::string inputfile, int eventnu
if (eventnumber == 0) {
output->push_back(std::stoi(temvalue));
} else {
int et = eFEXCompression::Expand(int(strtoull(temvalue.c_str(), nullptr, 16)));
int et = eFEXCompression::expand(int(strtoull(temvalue.c_str(), nullptr, 16)));
output->push_back(et);
}
}
......
......@@ -101,13 +101,8 @@ namespace LVL1 {
addET(et, cell);
//multi linear digitisation encoding
unsigned int ecode = eFEXCompression::Compress(m_et_float[cell]);
int outET = eFEXCompression::Expand(ecode);
//noise cut
const bool SCpass = noiseCut(outET,layer);
if (SCpass){ m_et[cell] = outET;}
else{ m_et[cell] = 0; }
unsigned int outET = eFEXCompression::decode((unsigned int)m_et_float[cell],layer);
m_et[cell] = outET;
}
/** Set supercell position ID and ET**/
......@@ -122,16 +117,10 @@ namespace LVL1 {
addET(et, cell);
m_scID[cell] = ID;
//multi linear digitisation encoding
unsigned int ecode = eFEXCompression::Compress(m_et_float[cell]);
int outET = eFEXCompression::Expand(ecode);
//noise cut
const bool SCpass = noiseCut(outET,layer);
if (SCpass){ m_et[cell] = outET;}
else{ m_et[cell] = 0; }
unsigned int outET = eFEXCompression::decode((unsigned int)m_et_float[cell],layer);
m_et[cell] = outET;
}
else{
......@@ -142,51 +131,17 @@ namespace LVL1 {
m_etSplits[cell] = 1;
m_etSplits[cell+1] = 1;
unsigned int ecode1 = eFEXCompression::Compress(m_et_float[cell]);
int outET1 = eFEXCompression::Expand(ecode1);
unsigned int ecode2 = eFEXCompression::Compress(m_et_float[cell+1]);
int outET2 = eFEXCompression::Expand(ecode2);
//noise cuts
const bool SCpass1 = noiseCut(outET1,layer);
if (SCpass1){ m_et[cell] = outET1;}
else{ m_et[cell] = 0; }
const bool SCpass2 = noiseCut(outET2,layer);
if (SCpass2){ m_et[cell+1] = outET2;}
else{ m_et[cell+1] = 0; }
unsigned int outET1 = eFEXCompression::decode((unsigned int)m_et_float[cell],layer);
unsigned int outET2 = eFEXCompression::decode((unsigned int)m_et_float[cell+1],layer);
m_et[cell] = outET1;
m_et[cell+1] = outET2;
}
return;
}
/** Apply noise cut per layer **/
bool eTower::noiseCut(int et, int layer) const
{
bool pass=true;
if(layer==0) {
if(et<m_noisecutPS){ pass = false; }
}
else if (layer==1) {
if(et<m_noisecutL1){ pass = false; }
}
else if (layer==2) {
if(et<m_noisecutL2){ pass = false; }
}
else if (layer==3) {
if(et<m_noisecutL3){ pass = false; }
}
else if (layer==4) {
if(et<m_noisecutHad){ pass = false; }
}
else { pass = false; }
return pass;
}
/** Return global eta index.
Should be derived from tower ID, should be corrected in the future.
Need to also think what index range should be (thinking ahead to Run2) */
......@@ -203,7 +158,7 @@ namespace LVL1 {
}
/** Return ET of specified supercell */
int eTower::getET(unsigned int layer, int cell) const {
unsigned int eTower::getET(unsigned int layer, int cell) const {
/// Check cell index in range for layer
if (layer > 5 || cell < 0 || cell >= s_cells[layer]) return 0;
......@@ -225,9 +180,9 @@ namespace LVL1 {
}
/** Return ET of all supercells together*/
int eTower::getTotalET() const{
unsigned int eTower::getTotalET() const{
int tmp = 0;
unsigned int tmp = 0;
for (unsigned int i=0; i<m_et.size(); i++){
tmp += m_et[i];
}
......@@ -250,10 +205,10 @@ namespace LVL1 {
/** Return supercell ET values for specified layer */
std::vector<int> eTower::getLayerETvec(unsigned int layer) const {
std::vector<unsigned int> eTower::getLayerETvec(unsigned int layer) const {
/// Create empty vector of data
std::vector<int> cells;
std::vector<unsigned int> cells;
/// Check cell index in range for layer
if (layer > 5) return cells;
......@@ -282,7 +237,7 @@ namespace LVL1 {
/** Return supercell ET values for specified layer */
int eTower::getLayerTotalET(unsigned int layer) const {
unsigned int eTower::getLayerTotalET(unsigned int layer) const {
if (layer == 0){
return m_et[0];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment