Skip to content

Commit

Permalink
Merge pull request cms-sw#196 from cerminar/gc_dev_tt_algo_101p3
Browse files Browse the repository at this point in the history
Flexible mapping of TCs to Trigger Towers
  • Loading branch information
jbsauvan committed Jun 7, 2018
2 parents 937fdfd + 3cca63a commit 9191d39
Show file tree
Hide file tree
Showing 18 changed files with 1,940,770 additions and 438 deletions.
80 changes: 48 additions & 32 deletions DataFormats/L1THGCal/interface/HGCalTower.h
Expand Up @@ -4,59 +4,75 @@

#include "DataFormats/L1Trigger/interface/L1Candidate.h"
#include "DataFormats/L1Trigger/interface/BXVector.h"
#include "DataFormats/L1THGCal/interface/HGCalTowerID.h"

namespace l1t {

class HGCalTower;
typedef BXVector<HGCalTower> HGCalTowerBxCollection;

class HGCalTower : public L1Candidate {

public:

HGCalTower(): etEm_(0.),etHad_(0.),hwEtEm_(0),hwEtHad_(0),hwEtRatio_(0) {}

HGCalTower( const LorentzVector& p4,
double etEm=0.,
double etHad=0.,
int pt=0,
int eta=0,
int phi=0,
int qual=0,
int hwEtEm=0,
int hwEtHad=0,
int hwEtRatio=0);


HGCalTower(): etEm_(0.),
etHad_(0.),
id_(0),
hwEtEm_(0),
hwEtHad_(0),
hwEtRatio_(0) {}

HGCalTower(double etEm,
double etHad,
double eta,
double phi,
unsigned short id,
int hwpt=0,
int hweta=0,
int hwphi=0,
int qual=0,
int hwEtEm=0,
int hwEtHad=0,
int hwEtRatio=0);

~HGCalTower() override;

void setEtEm( double et );
void setEtHad( double et );

void setHwEtEm( int et );
void setHwEtHad( int et );
void setHwEtRatio( int ratio );

double etEm()const;
double etHad()const;
void addEtEm(double et);
void addEtHad(double et);

double etEm()const { return etEm_; };
double etHad()const { return etHad_; };

int hwEtEm()const;
int hwEtHad()const;
int hwEtRatio()const;
const HGCalTower& operator+=(const HGCalTower& tower);

HGCalTower& operator+=(const HGCalTower& tower);
HGCalTowerID id() const { return id_;}
short zside() const { return id_.zside(); }

void setHwEtEm(int et) { hwEtEm_ = et; }
void setHwEtHad(int et) { hwEtHad_ = et; }
void setHwEtRatio(int ratio) { hwEtRatio_ = ratio; }

int hwEtEm() const { return hwEtEm_; }
int hwEtHad() const { return hwEtHad_; }
int hwEtRatio() const { return hwEtRatio_; }

private:


void addEt(double et);

// additional hardware quantities
double etEm_;
double etHad_;

HGCalTowerID id_;

int hwEtEm_;
int hwEtHad_;
int hwEtRatio_;

};

}

#endif
54 changes: 54 additions & 0 deletions DataFormats/L1THGCal/interface/HGCalTowerID.h
@@ -0,0 +1,54 @@
#ifndef DataFormats_L1TCalorimeter_HGCalTowerID_h
#define DataFormats_L1TCalorimeter_HGCalTowerID_h

// NOTE: in the current implementation HGCalTowerID can only
// accomodate 127 bins per coordinate x2 zsides

namespace l1t {
class HGCalTowerID {
public:
HGCalTowerID(unsigned short rawId): rawId_(rawId) {}

HGCalTowerID(short zside, unsigned short coord1, unsigned short coord2) {
rawId_ = ((coord1 & coordMask) << coord1Shift) | ((coord2 & coordMask) << coord2Shift) | (((zside > 0) & zsideMask) << zsideShift);
}

short zside() const { return ((rawId_ >> zsideShift) & zsideMask) ? 1 : -1;}

unsigned short iEta() const { return (rawId_ >> coord1Shift) & coordMask; }

unsigned short iPhi() const { return (rawId_ >> coord2Shift) & coordMask;}

unsigned short rawId() const {return rawId_;}


private:

unsigned short rawId_;
static const int zsideMask = 0x1;
static const int zsideShift = 15;
static const int coordMask = 0x007F;
static const int coord1Shift = 7;
static const int coord2Shift = 0;
};


struct HGCalTowerCoord {
HGCalTowerCoord(unsigned short rawId, float eta, float phi): rawId(rawId),
eta(eta),
phi(phi) {}

const unsigned short rawId;
const float eta;
const float phi;

};


}





#endif
47 changes: 14 additions & 33 deletions DataFormats/L1THGCal/interface/HGCalTowerMap.h
Expand Up @@ -7,60 +7,41 @@
#include <unordered_map>

namespace l1t {

class HGCalTowerMap;
class HGCalTowerCoord;
typedef BXVector<HGCalTowerMap> HGCalTowerMapBxCollection;

class HGCalTowerMap {

public:

HGCalTowerMap(): nEtaBins_(0), nPhiBins_(0), layer_(0) {}
HGCalTowerMap( int nEtaBins, int nPhiBins );
HGCalTowerMap(): layer_(0) {}

HGCalTowerMap(const std::vector<l1t::HGCalTowerCoord>& tower_ids, const int layer);

HGCalTowerMap( const std::vector<double>& etaBins, const std::vector<double>& phiBins );
// ~HGCalTowerMap();

~HGCalTowerMap();
// const l1t::HGCalTower& tower(int iX, int iY) const;

void setLayer( const unsigned layer ) { layer_ = layer; }
int layer() const { return layer_; }

const HGCalTowerMap& operator+=(const HGCalTowerMap& map);

int nEtaBins() const { return nEtaBins_; }
int nPhiBins() const { return nPhiBins_; }
const vector<double>& etaBins() const { return etaBins_; }
const vector<double>& phiBins() const { return phiBins_; }
const l1t::HGCalTower& tower(int iEta, int iPhi) const { return towerMap_.at(bin_id(iEta,iPhi)); }
// bool addEt(short iX, short iY, float etEm, float etHad);
bool addEt(short bin_id, float etEm, float etHad);

int iEta(const double eta) const;
int iPhi(const double phi) const;
int layer() const { return layer_;}
unsigned nTowers() const { return towerMap_.size(); }
const std::unordered_map<unsigned short, l1t::HGCalTower>& towers() const { return towerMap_; }

HGCalTowerMap& operator+=(const HGCalTowerMap& map);
void addTower(int iEta, int iPhi, const l1t::HGCalTower& tower) { towerMap_[bin_id(iEta,iPhi)] += tower; }

private:

static constexpr double kEtaMin_ = 1.479;
static constexpr double kEtaMax_ = 3.;
static constexpr double kEtaMinLoose_ = 1.401; //BH has some TC below 1.479
static constexpr double kEtaMaxLoose_ = 3.085; //FH has some TC above 3.0
static constexpr double kPhiMin_ = -M_PI;
static constexpr double kPhiMax_ = +M_PI;

int nEtaBins_;
int nPhiBins_;
vector<double> etaBins_;
vector<double> phiBins_;
std::unordered_map<int,l1t::HGCalTower> towerMap_;
std::unordered_map<unsigned short, l1t::HGCalTower> towerMap_;
unsigned layer_;

int bin_id(int iEta,int iPhi) const;

};

}

#endif


109 changes: 33 additions & 76 deletions DataFormats/L1THGCal/src/HGCalTower.cc
@@ -1,100 +1,57 @@
#include "DataFormats/L1THGCal/interface/HGCalTower.h"
#include "FWCore/Utilities/interface/EDMException.h"

using namespace l1t;
using l1t::L1Candidate;
using l1t::HGCalTower;

HGCalTower::HGCalTower( const LorentzVector& p4,
double etEm,
HGCalTower::HGCalTower(double etEm,
double etHad,
int pt,
int eta,
int phi,
double eta,
double phi,
unsigned short id,
int hwpt,
int hweta,
int hwphi,
int qual,
int hwEtEm,
int hwEtHad,
int hwEtRatio)
: L1Candidate(p4, pt, eta, phi, qual),
etEm_(etEm),
etHad_(etHad),
hwEtEm_(hwEtEm),
hwEtHad_(hwEtHad),
hwEtRatio_(hwEtRatio)
{

}

HGCalTower::~HGCalTower()
{

}

void HGCalTower::setEtEm(double et)
{
etEm_ = et;
}

void HGCalTower::setEtHad(double et)
{
etHad_ = et;
}

void HGCalTower::setHwEtEm(int et)
{
hwEtEm_ = et;
}
int hwEtRatio) : L1Candidate(PolarLorentzVector(etEm+etHad, eta, phi, 0.), hwpt, hweta, hwphi, qual),
etEm_(etEm),
etHad_(etHad),
id_(id),
hwEtEm_(hwEtEm),
hwEtHad_(hwEtHad),
hwEtRatio_(hwEtRatio) {}

void HGCalTower::setHwEtHad(int et)
{
hwEtHad_ = et;
}

void HGCalTower::setHwEtRatio(int ratio)
{
hwEtRatio_ = ratio;
}
HGCalTower::~HGCalTower() {}

double HGCalTower::etEm()const
{
return etEm_;
}

double HGCalTower::etHad()const
{
return etHad_;
}

int HGCalTower::hwEtEm()const
{
return hwEtEm_;
void HGCalTower::addEtEm(double et) {
etEm_+=et;
addEt(et);
}

int HGCalTower::hwEtHad()const
{
return hwEtHad_;
void HGCalTower::addEtHad(double et) {
etHad_+=et;
addEt(et);
}

int HGCalTower::hwEtRatio()const
{
return hwEtRatio_;
void HGCalTower::addEt(double et) {
this->setP4(PolarLorentzVector(this->pt()+et, this->eta(), this->phi(), 0.));
}




HGCalTower& HGCalTower::operator+=(const HGCalTower& tower){

if(this->hwEta()!= tower.hwEta() || this->hwPhi()!= tower.hwPhi()){
const HGCalTower& HGCalTower::operator+=(const HGCalTower& tower){
// NOTE: assume same eta and phi -> need an explicit check on the ID
if(id().rawId() != tower.id().rawId()) {
throw edm::Exception(edm::errors::StdException, "StdException")
<< "HGCalTower: Trying to add HGCalTowers with different coordinates"<<endl;
<< "HGCalTower: adding to this tower with ID: " << id().rawId()
<< " one with different ID: " << tower.id().rawId() << std::endl;
}

this->setP4(this->p4() + tower.p4());
this->setEtEm(this->etEm() + tower.etEm());
this->setEtHad(this->etHad() + tower.etHad());

this->setHwPt(this->hwPt() + tower.hwPt());
this->setHwEtEm(this->hwEtEm() + tower.hwEtEm());
this->setHwEtHad(this->hwEtHad() + tower.hwEtHad());
this->setP4(PolarLorentzVector(this->pt()+tower.pt(), this->eta(), this->phi(), 0.));
etEm_+=tower.etEm();
etHad_+=tower.etHad();

return *this;

Expand Down

0 comments on commit 9191d39

Please sign in to comment.