forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from amarini/topic_simclustering_cmssw90
Sim Clustering
- Loading branch information
Showing
19 changed files
with
901 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#ifndef CLUSTER_SHAPES_H | ||
#define CLUSTER_SHAPES_H | ||
#include <vector> | ||
#include <cmath> | ||
|
||
namespace l1t{ | ||
// this class is design to contain and compute | ||
// efficiently the cluster shapes | ||
// running only once on the cluster members. | ||
class ClusterShapes{ | ||
private: | ||
float sum_e = 0.0; | ||
float sum_e2 = 0.0; | ||
float sum_logE = 0.0; | ||
int n=0.0; | ||
|
||
float emax = 0.0; | ||
|
||
float sum_w =0.0; // just here for clarity | ||
float sum_eta = 0.0; | ||
float sum_r = 0.0; | ||
// i will discriminate using the rms in -pi,pi or in 0,pi | ||
float sum_phi_0 = 0.0; // computed in -pi,pi | ||
float sum_phi_1 = 0.0; // computed in 0, 2pi | ||
|
||
float sum_eta2=0.0; | ||
float sum_r2 = 0.0; | ||
float sum_phi2_0=0.0; //computed in -pi,pi | ||
float sum_phi2_1=0.0; //computed in 0,2pi | ||
|
||
// off diagonal element of the tensor | ||
float sum_eta_r =0.0; | ||
float sum_r_phi_0 = 0.0; | ||
float sum_r_phi_1 = 0.0; | ||
float sum_eta_phi_0 = 0.0; | ||
float sum_eta_phi_1 = 0.0; | ||
|
||
// caching of informations | ||
mutable bool isPhi0 = true; | ||
mutable bool modified_ = false; // check wheneever i need | ||
public: | ||
ClusterShapes(){} | ||
ClusterShapes(float e, float eta, float phi, float r) { Init(e,eta,phi,r);} | ||
~ClusterShapes(){} | ||
ClusterShapes(const ClusterShapes&x)= default; | ||
//init an empty cluster | ||
void Init(float e, float eta, float phi, float r=0.); | ||
inline void Add(float e, float eta, float phi, float r=0.0) | ||
{ (*this) += ClusterShapes(e,eta,phi,r);} | ||
|
||
|
||
// --- this is what I want out: | ||
float SigmaEtaEta() const ; | ||
float SigmaPhiPhi() const ; | ||
float SigmaRR() const ; | ||
// ---- | ||
float Phi() const ; | ||
float R() const ; | ||
float Eta() const ; | ||
inline int N()const {return n;} | ||
// -- | ||
float SigmaEtaR()const ; | ||
float SigmaEtaPhi() const ; | ||
float SigmaRPhi() const ; | ||
// -- | ||
float LogEoverE() const { return sum_logE/sum_e;} | ||
float eD() const { return std::sqrt(sum_e2)/sum_e;} | ||
|
||
ClusterShapes operator+(const ClusterShapes &); | ||
void operator+=(const ClusterShapes &); | ||
ClusterShapes& operator=(const ClusterShapes &) = default; | ||
}; | ||
|
||
}; // end namespace | ||
|
||
#endif | ||
|
||
// ----------------------------------- | ||
// Local Variables: | ||
// mode:c++ | ||
// indent-tabs-mode:nil | ||
// tab-width:4 | ||
// c-basic-offset:4 | ||
// End: | ||
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
#include "DataFormats/L1THGCal/interface/ClusterShapes.h" | ||
#include <cmath> | ||
|
||
using namespace l1t; | ||
|
||
ClusterShapes ClusterShapes::operator+(const ClusterShapes& x) | ||
{ | ||
ClusterShapes cs(*this); // copy constructor | ||
cs += x; | ||
return cs; | ||
} | ||
|
||
|
||
void ClusterShapes::operator +=(const ClusterShapes &x){ | ||
|
||
sum_e += x.sum_e; | ||
sum_e2 += x.sum_e2; | ||
sum_logE += x.sum_logE; | ||
n += x.n; | ||
|
||
sum_w += x.sum_w; | ||
|
||
emax = (emax> x.emax) ? emax: x.emax; | ||
|
||
// mid-point | ||
sum_eta += x.sum_eta; | ||
sum_phi_0 += x.sum_phi_0; // | ||
sum_phi_1 += x.sum_phi_1; // | ||
sum_r += x.sum_r; | ||
|
||
// square | ||
sum_eta2 += x.sum_eta2; | ||
sum_phi2_0 += x.sum_phi2_0; | ||
sum_phi2_1 += x.sum_phi2_1; | ||
sum_r2 += x.sum_r2; | ||
|
||
// off diagonal | ||
sum_eta_r += x.sum_eta_r ; | ||
sum_r_phi_0 += x.sum_r_phi_0 ; | ||
sum_r_phi_1 += x.sum_r_phi_1 ; | ||
sum_eta_phi_0 += x.sum_eta_phi_0; | ||
sum_eta_phi_1 += x.sum_eta_phi_1; | ||
|
||
} | ||
|
||
|
||
// -------------- CLUSTER SHAPES --------------- | ||
void ClusterShapes::Init(float e ,float eta, float phi, float r){ | ||
if (e<=0 ) return; | ||
sum_e = e; | ||
sum_e2 = e*e; | ||
sum_logE = std::log(e); | ||
|
||
float w = e; | ||
|
||
n=1; | ||
|
||
sum_w = w; | ||
|
||
sum_phi_0 = w *( phi ); | ||
sum_phi_1 = w* (phi + M_PI); | ||
sum_r = w * r; | ||
sum_eta = w * eta; | ||
|
||
//-- | ||
sum_r2 += w * (r*r); | ||
sum_eta2 += w * (eta*eta); | ||
sum_phi2_0 += w * (phi*phi); | ||
sum_phi2_1 += w * (phi+M_PI)*(phi+M_PI); | ||
|
||
// -- off diagonal | ||
sum_eta_r += w * (r*eta); | ||
sum_r_phi_0 += w* (r *phi); | ||
sum_r_phi_1 += w* r *(phi + M_PI); | ||
sum_eta_phi_0 += w* (eta *phi); | ||
sum_eta_phi_1 += w* eta * (phi+M_PI); | ||
|
||
} | ||
// ------ | ||
float ClusterShapes::Eta()const { return sum_eta/sum_w;} | ||
float ClusterShapes::R() const { return sum_r/sum_w;} | ||
|
||
float ClusterShapes::SigmaEtaEta()const {return sum_eta2/sum_w - Eta()*Eta();} | ||
|
||
float ClusterShapes::SigmaRR()const { return sum_r2/sum_w - R() *R();} | ||
|
||
|
||
float ClusterShapes::SigmaPhiPhi()const { | ||
float phi_0 = (sum_phi_0 / sum_w); | ||
float phi_1 = (sum_phi_1 / sum_w); | ||
float spp_0 = sum_phi2_0 / sum_w - phi_0*phi_0; | ||
float spp_1 = sum_phi2_1 / sum_w - phi_1*phi_1; | ||
|
||
if (spp_0 < spp_1 ) | ||
{ | ||
float phi = phi_0; | ||
isPhi0=true; | ||
while (phi < - M_PI) phi += 2*M_PI; | ||
while (phi > M_PI) phi -= 2*M_PI; | ||
return spp_0; | ||
} | ||
else | ||
{ | ||
float phi = phi_1 ; | ||
isPhi0=false; | ||
while (phi < - M_PI) phi += 2*M_PI; | ||
while (phi > M_PI) phi -= 2*M_PI; | ||
return spp_1; | ||
} | ||
} | ||
|
||
float ClusterShapes::Phi()const { | ||
SigmaPhiPhi(); //update phi | ||
if (isPhi0) return (sum_phi_0 / sum_w); | ||
else return (sum_phi_1 / sum_w); | ||
} | ||
|
||
|
||
// off - diagonal | ||
float ClusterShapes::SigmaEtaR() const { return -(sum_eta_r / sum_w - Eta() *R()) ;} | ||
|
||
float ClusterShapes::SigmaEtaPhi()const { | ||
SigmaPhiPhi() ; // decide which phi use, update phi | ||
|
||
if (isPhi0) | ||
return -(sum_eta_phi_0 /sum_w - Eta()*(sum_phi_0 / sum_w)); | ||
else | ||
return -(sum_eta_phi_1 / sum_w - Eta()*(sum_phi_1 / sum_w)); | ||
} | ||
|
||
float ClusterShapes::SigmaRPhi()const { | ||
SigmaPhiPhi() ; // decide which phi use, update phi | ||
if (isPhi0) | ||
return -(sum_r_phi_0 / sum_w - R() *(sum_phi_0 / sum_w)); | ||
else | ||
return -(sum_r_phi_1 / sum_w - R() * (sum_phi_1 / sum_w)); | ||
} | ||
|
||
// ----------------------------------- | ||
// Local Variables: | ||
// mode:c++ | ||
// indent-tabs-mode:nil | ||
// tab-width:4 | ||
// c-basic-offset:4 | ||
// End: | ||
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,4 @@ bool HGCalCluster::operator<(const HGCalCluster& cl) const | |
} | ||
return res; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ struct HGCalBestChoiceDataPayload | |
{ | ||
payload.fill(0); | ||
} | ||
|
||
}; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.