Skip to content

Commit

Permalink
[WIP] cleaned orbit collection, now an orbit buffer is directly passe…
Browse files Browse the repository at this point in the history
…d to it. Fixed bug in the bxOffset index
  • Loading branch information
Mmiglio committed Nov 21, 2023
1 parent 9029aab commit 1771948
Show file tree
Hide file tree
Showing 15 changed files with 521 additions and 636 deletions.
90 changes: 53 additions & 37 deletions DataFormats/L1Scouting/interface/L1ScoutingCalo.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace scoutingRun3 {
: hwEt_(0),
hwEta_(0),
hwPhi_(0),
iso_(0){}
hwIso_(0){}

ScCaloObject(
int hwEt,
Expand All @@ -22,44 +22,52 @@ namespace scoutingRun3 {
: hwEt_(hwEt),
hwEta_(hwEta),
hwPhi_(hwPhi),
iso_(iso) {}
hwIso_(iso) {}

ScCaloObject(const ScCaloObject& other) = default;
ScCaloObject(ScCaloObject&& other) = default;
ScCaloObject & operator=(const ScCaloObject& other) = default;
ScCaloObject & operator=(ScCaloObject&& other) = default;

void swap(ScCaloObject& other){
using std::swap;
swap(hwEt_, other.hwEt_);
swap(hwEta_, other.hwEta_);
swap(hwPhi_, other.hwPhi_);
swap(hwIso_, other.hwIso_);
}

inline void setHwEt(int hwEt) { hwEt_= hwEt;}
inline void setHwEta(int hwEta) { hwEta_= hwEta;}
inline void setHwPhi(int hwPhi) { hwPhi_= hwPhi;}
inline void setIso(int iso) { iso_= iso;}

inline int getHwEt() const {return hwEt_;}
inline int getHwEta() const {return hwEta_;}
inline int getHwPhi() const {return hwPhi_;}
inline int getIso() const {return iso_;}

inline float getEt() const {
return et_scale_* hwEt_;
}
inline float getEta()const {
return eta_scale_*hwEta_;
}
inline float getPhi() const {
float fPhi = phi_scale_*hwPhi_;
fPhi = fPhi>=2.*M_PI ? fPhi-2.*M_PI : fPhi;
return fPhi;
}
inline void setHwIso(int hwIso) { hwIso_= hwIso;}

inline int hwEt() const {return hwEt_;}
inline int hwEta() const {return hwEta_;}
inline int hwPhi() const {return hwPhi_;}
inline int hwIso() const {return hwIso_;}

// inline float Et() const {
// return et_scale_* hwEt_;
// }
// inline float eta()const {
// return eta_scale_*hwEta_;
// }
// inline float phi() const {
// float fPhi = phi_scale_*hwPhi_;
// fPhi = fPhi>=M_PI ? fPhi-2.*M_PI : fPhi;
// return fPhi;
// }

private:
int hwEt_;
int hwEta_;
int hwPhi_;
int iso_;
int hwIso_;

static constexpr float phi_scale_ = 2.*M_PI/144.;
static constexpr float eta_scale_ = 0.0435;
static constexpr float et_scale_ = 0.5;
// static constexpr float phi_scale_ = 2.*M_PI/144.;
// static constexpr float eta_scale_ = 0.0435;
// static constexpr float et_scale_ = 0.5;
};

class ScJet: public ScCaloObject {
Expand All @@ -72,6 +80,7 @@ namespace scoutingRun3 {
int hwPhi,
int iso)
: ScCaloObject(hwEt, hwEta ,hwPhi , iso) {}

};

class ScEGamma: public ScCaloObject {
Expand Down Expand Up @@ -119,30 +128,37 @@ namespace scoutingRun3 {
ScEtSum & operator=(const ScEtSum& other) = default;
ScEtSum & operator=(ScEtSum&& other) = default;

void swap(ScEtSum& other){
using std::swap;
swap(hwEt_, other.hwEt_);
swap(hwPhi_, other.hwPhi_);
swap(type_, other.type_);
}

inline void setHwEt(int hwEt) { hwEt_= hwEt;}
inline void setHwPhi(int hwPhi) { hwPhi_= hwPhi;}
inline void setType(l1t::EtSum::EtSumType type) { type_= type;}

inline int getHwEt() const {return hwEt_;}
inline int getHwPhi() const {return hwPhi_;}
inline l1t::EtSum::EtSumType getType() const {return type_;}
inline int hwEt() const {return hwEt_;}
inline int hwPhi() const {return hwPhi_;}
inline l1t::EtSum::EtSumType type() const {return type_;}

inline float getEt() const {
return et_scale_* hwEt_;
}
inline float getPhi() const {
float fPhi = phi_scale_*hwPhi_;
fPhi = fPhi>=2.*M_PI ? fPhi-2.*M_PI : fPhi;
return fPhi;
}
// inline float Et() const {
// return et_scale_* hwEt_;
// }
// inline float phi() const {
// float fPhi = phi_scale_*hwPhi_;
// fPhi = fPhi>=M_PI ? fPhi-2.*M_PI : fPhi;
// return fPhi;
// }

private:
int hwEt_;
int hwPhi_;
l1t::EtSum::EtSumType type_;

static constexpr float phi_scale_ = 2.*M_PI/144.;
static constexpr float et_scale_ = 0.5;
// static constexpr float phi_scale_ = 2.*M_PI/144.;
// static constexpr float et_scale_ = 0.5;
};

} // namespace scoutingRun3
Expand Down
88 changes: 53 additions & 35 deletions DataFormats/L1Scouting/interface/L1ScoutingMuon.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,50 +52,67 @@ namespace scoutingRun3 {
ScMuon & operator=(const ScMuon& other) = default;
ScMuon & operator=(ScMuon&& other) = default;

void swap(ScMuon& other){
using std::swap;
swap(hwPt_, other.hwPt_);
swap(hwEta_, other.hwEta_);
swap(hwPhi_, other.hwPhi_);
swap(hwQual_, other.hwQual_);
swap(hwChrg_, other.hwChrg_);
swap(hwChrgv_, other.hwChrgv_);
swap(hwIso_, other.hwIso_);
swap(tfIndex_, other.tfIndex_);
swap(hwEtaAtVtx_, other.hwEtaAtVtx_);
swap(hwPhiAtVtx_, other.hwPhiAtVtx_);
swap(hwPtUnconstrained_, other.hwPtUnconstrained_);
swap(hwDXY_, other.hwDXY_);
}

inline void setHwPt(int hwPt) { hwPt_= hwPt;}
inline void setHwEta(int hwEta) { hwEta_= hwEta;}
inline void setHwPhi(int hwPhi) { hwPhi_= hwPhi;}
inline void setHwQual(int hwQual) { hwQual_= hwQual;}
inline void setHwChrg(int hwChrg) { hwChrg_= hwChrg;}
inline void setHwChrgv(int hwChrgv) { hwChrgv_= hwChrgv;}
inline void setHwIso(int hwIso) { hwIso_= hwIso;}
inline void setHfIndex(int tfIndex) { tfIndex_= tfIndex;}
inline void setTfIndex(int tfIndex) { tfIndex_= tfIndex;}
inline void setHwEtaAtVtx(int hwEtaAtVtx) { hwEtaAtVtx_= hwEtaAtVtx;}
inline void setHwPhiAtVtx(int hwPhiAtVtx) { hwPhiAtVtx_= hwPhiAtVtx;}
inline void setHwPtUnconstrained(int hwPtUnconstrained) { hwPtUnconstrained_= hwPtUnconstrained;}
inline void setHwDXY(int hwDXY) { hwDXY_= hwDXY;}

inline int getHwPt() const {return hwPt_;}
inline int getHwEta() const {return hwEta_;}
inline int getHwPhi() const {return hwPhi_;}
inline int getHwQual() const {return hwQual_;}
inline int getHwChrg() const {return hwChrg_;}
inline int getHwChrgv() const {return hwChrgv_;}
inline int getHwIso() const {return hwIso_;}
inline int getHfIndex() const {return tfIndex_;}
inline int getHwEtaAtVtx() const {return hwEtaAtVtx_;}
inline int getHwPhiAtVtx() const {return hwPhiAtVtx_;}
inline int getHwPtUnconstrained() const {return hwPtUnconstrained_;}
inline int getHwDXY() const {return hwDXY_;}
inline int hwPt() const {return hwPt_;}
inline int hwEta() const {return hwEta_;}
inline int hwPhi() const {return hwPhi_;}
inline int hwQual() const {return hwQual_;}
inline int hwCharge() const {return hwChrg_;}
inline int hwChargeValid() const {return hwChrgv_;}
inline int hwIso() const {return hwIso_;}
inline int hwIndex() const {return tfIndex_;}
inline int hwEtaAtVtx() const {return hwEtaAtVtx_;}
inline int hwPhiAtVtx() const {return hwPhiAtVtx_;}
inline int hwPtUnconstrained() const {return hwPtUnconstrained_;}
inline int hwDXY() const {return hwDXY_;}
inline int tfMuonIndex() const {return tfIndex_;}

inline float getPt() const {
return pt_scale_*(hwPt_-1);
}
inline float getEta()const {
return eta_scale_*hwEta_;
}
inline float getPhi() const {
return phi_scale_*hwPhi_;
}
inline float getPtUnconstrained() const {
return pt_scale_*(hwPtUnconstrained_-1);
}
inline float getEtaAtVtx() const {
return eta_scale_*hwEtaAtVtx_;
}
inline float getPhiAtVtx() const {
return phi_scale_*hwPhiAtVtx_;
}
// inline float pt() const {
// return pt_scale_*(hwPt_-1);
// }
// inline float eta()const {
// return eta_scale_*hwEta_;
// }
// inline float phi() const {
// return phi_scale_*hwPhi_;
// }
// inline float ptUnconstrained() const {
// return pt_scale_*(hwPtUnconstrained_-1);
// }
// inline float etaAtVtx() const {
// return eta_scale_*hwEtaAtVtx_;
// }
// inline float phiAtVtx() const {
// return phi_scale_*hwPhiAtVtx_;
// }

private:
int hwPt_;
Expand All @@ -112,11 +129,12 @@ namespace scoutingRun3 {
int hwDXY_;

// constants to convert from harware to physical quantities
static constexpr float pt_scale_ = 0.5;
static constexpr float ptunconstrained_scale_ = 1.0;
static constexpr float phi_scale_ = 2.*M_PI/576.;
static constexpr float eta_scale_ = 0.0870/8;
// static constexpr float pt_scale_ = 0.5;
// static constexpr float ptunconstrained_scale_ = 1.0;
// static constexpr float phi_scale_ = 2.*M_PI/576.;
// static constexpr float eta_scale_ = 0.0870/8;
};

} // namespace scoutingRun3

#endif // DataFormats_L1Scouting_L1ScoutingMuon_h
83 changes: 51 additions & 32 deletions DataFormats/L1Scouting/interface/OrbitCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,64 @@ namespace scoutingRun3 {
template<class T>
class OrbitCollection {
public:
OrbitCollection(): bxOffsets_(3565, 0), bxData_(3565), nObjects_(0) {}
OrbitCollection(): bxOffsets_(3566, 0), data_(0) {}

// append one object to vector at bx
void addBxObject(int bx, T& object) {
assert(bx<=3564);
bxData_[bx].emplace_back(object);
nObjects_ ++;
}

// append objects to bx from an iterator
template <typename VI>
void addBxObjects(int bx, VI objectsBegin, VI objectsEnd){
assert(bx<=3564);
bxData_[bx].insert(bxData_[bx].end(), objectsBegin, objectsEnd);
nObjects_ += std::distance(objectsBegin, objectsEnd);
}

// flatten bxData_ vector. Must be called at the end of the orbit.
void flatten(){
data_.reserve(nObjects_);
// void addBxObject(int bx, T& object) {
// assert(bx<=3564);
// bxData_[bx].push_back(object);
// nObjects_ ++;
// }

// // append objects to bx from an iterator
// template <typename VI>
// void addBxObjects(int bx, VI objectsBegin, VI objectsEnd){
// assert(bx<=3564);
// bxData_[bx].insert(bxData_[bx].end(), objectsBegin, objectsEnd);
// nObjects_ += std::distance(objectsBegin, objectsEnd);
// }

// // flatten bxData_ vector. Must be called at the end of the orbit.
// void flatten(){
// data_.reserve(nObjects_);
// bxOffsets_[0] = 0;
// int bxIdx = 1;
// for (auto &bxVec: bxData_){
// data_.insert(data_.end(),
// std::make_move_iterator(bxVec.begin()),
// std::make_move_iterator(bxVec.end())
// );
// // increase offset by the currect vec size
// bxOffsets_[bxIdx] = bxOffsets_[bxIdx-1] + bxVec.size();
// bxIdx++;
// }

// bxData_.clear();
// }

// TEST
void fillAndClear(std::vector<std::vector<T>> &orbitBuffer, int nObjects=0){
data_.reserve(nObjects);
bxOffsets_[0] = 0;
int bxIdx = 1;
for (auto &bxVec: bxData_){
data_.insert(data_.end(),
std::make_move_iterator(bxVec.begin()),
std::make_move_iterator(bxVec.end())
);
for (auto &bxVec: orbitBuffer){
// increase offset by the currect vec size
bxOffsets_[bxIdx] = bxOffsets_[bxIdx-1] + bxVec.size();
// std::cout<<"IDX: " << bxIdx << ", size: "<< bxVec.size() << ", offset: "<<bxOffsets_[bxIdx]<<std::endl;

// if bxVec contains something, move it into the data_ vector
// and clear bxVec objects
if (bxVec.size()>0){
data_.insert(data_.end(),
std::make_move_iterator(bxVec.begin()),
std::make_move_iterator(bxVec.end())
);
bxVec.clear();
}

bxIdx++;
}

bxData_.clear();
}

// get number of objects stored in a BX
Expand Down Expand Up @@ -88,18 +113,12 @@ namespace scoutingRun3 {
// Transient container used while filling the orbit collection.
// Needed because data could be added to the collection with unsorted BX.
// This will not be persisted (transient="true")
mutable std::vector<std::vector<T>> bxData_;
// mutable std::vector<std::vector<T>> bxData_;

// count number of objects inserted into the collection
int nObjects_;
// int nObjects_;
};

typedef OrbitCollection<l1t::Muon> MuonOrbitCollection;
typedef OrbitCollection<l1t::Jet> JetOrbitCollection;
typedef OrbitCollection<l1t::EGamma> EGammaOrbitCollection;
typedef OrbitCollection<l1t::Tau> TauOrbitCollection;
typedef OrbitCollection<l1t::EtSum> EtSumOrbitCollection;

typedef OrbitCollection<scoutingRun3::ScMuon> ScMuonOrbitCollection;
typedef OrbitCollection<scoutingRun3::ScJet> ScJetOrbitCollection;
typedef OrbitCollection<scoutingRun3::ScEGamma> ScEGammaOrbitCollection;
Expand Down
16 changes: 5 additions & 11 deletions DataFormats/L1Scouting/src/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@
#include "DataFormats/L1Scouting/interface/L1ScoutingCalo.h"

namespace scoutingRun3 {
edm::Wrapper<scoutingRun3::OrbitCollection<l1t::Muon>> MuonOrbitCollectionWrapper;
edm::Wrapper<scoutingRun3::OrbitCollection<l1t::Jet>> JetOrbitCollectionWrapper;
edm::Wrapper<scoutingRun3::OrbitCollection<l1t::EGamma>> EGammaOrbitCollectionWrapper;
edm::Wrapper<scoutingRun3::OrbitCollection<l1t::Tau>> TauOrbitCollectionWrapper;
edm::Wrapper<scoutingRun3::OrbitCollection<l1t::EtSum>> EtSumOrbitCollectionWrapper;

edm::Wrapper<scoutingRun3::ScMuonOrbitCollection> ScMuonOrbitCollectionWrapper;
edm::Wrapper<scoutingRun3::ScJetOrbitCollection> ScJetOrbitCollectionWrapper;
edm::Wrapper<scoutingRun3::ScEGammaOrbitCollection> ScEGammaOrbitCollectionWrapper;
edm::Wrapper<scoutingRun3::ScTauOrbitCollection> ScTauOrbitCollectionWrapper;
edm::Wrapper<scoutingRun3::ScEtSumOrbitCollection> ScEtSumOrbitCollectionWrapper;
edm::Wrapper<scoutingRun3::ScMuonOrbitCollection> ScMuonOrbitCollectionWrapper;
edm::Wrapper<scoutingRun3::ScJetOrbitCollection> ScJetOrbitCollectionWrapper;
edm::Wrapper<scoutingRun3::ScEGammaOrbitCollection> ScEGammaOrbitCollectionWrapper;
edm::Wrapper<scoutingRun3::ScTauOrbitCollection> ScTauOrbitCollectionWrapper;
edm::Wrapper<scoutingRun3::ScEtSumOrbitCollection> ScEtSumOrbitCollectionWrapper;
}
Loading

0 comments on commit 1771948

Please sign in to comment.