Skip to content

Commit

Permalink
Enable the warnings coming from Key4hepConfig and fix them
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell committed Nov 8, 2024
1 parent 1d0e486 commit 810c339
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 41 deletions.
13 changes: 4 additions & 9 deletions include/CLUEAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@
#define CLUEAlgo_h

// C/C++ headers
#include <set>
#include <string>
#include <vector>
#include <map>
#include <iostream>
#include <fstream>
#include <sstream>
#include <functional>
#include <chrono>

#include "LayerTiles.h"
#include "Points.h"
Expand All @@ -54,7 +51,6 @@ class CLUEAlgo_T {
std::cout << "," << TILES::constants_type_t::nRows << " )" << std::endl;
}
}
~CLUEAlgo_T(){}

// public variables
float dc_, rhoc_, outlierDeltaFactor_;
Expand Down Expand Up @@ -138,8 +134,7 @@ class CLUEAlgo_T {
std::string getVerboseString_(unsigned it,
float x, float y, int layer, float weight,
float rho, float delta,
int nh, int isseed, float clusterid,
unsigned nVerbose) const {
int nh, int isseed, float clusterid) const {
std::stringstream s;
std::string sep = ",";
s << it << sep << x << sep << y << sep;
Expand All @@ -152,18 +147,18 @@ class CLUEAlgo_T {
return s.str();
}

void verboseResults(std::string outputFileName="cout", unsigned nVerbose=-1) const {
void verboseResults(std::string outputFileName="cout", int nVerbose=-1) const {
if(verbose_)
{
if (nVerbose==-1) nVerbose=points_.n;

std::string s;
s = "index,x,y,layer,weight,rho,delta,nh,isSeed,clusterId\n";
for(unsigned i=0; i<nVerbose; i++) {
for(int i=0; i<nVerbose; i++) {
s += getVerboseString_(i, points_.x[i], points_.y[i], points_.layer[i],
points_.weight[i], points_.rho[i], points_.delta[i],
points_.nearestHigher[i], points_.isSeed[i],
points_.clusterIndex[i], nVerbose);
points_.clusterIndex[i]);
}

if(outputFileName.compare("cout")==0) //verbose to screen
Expand Down
12 changes: 5 additions & 7 deletions include/CLUECalorimeterHit.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
#include "edm4hep/CalorimeterHit.h"
#include <GaudiKernel/DataObject.h>

using namespace edm4hep;

namespace clue {

class CLUECalorimeterHit : public CalorimeterHit, public DataObject {
class CLUECalorimeterHit : public edm4hep::CalorimeterHit, public DataObject {
public:
using CalorimeterHit::CalorimeterHit;

Expand Down Expand Up @@ -80,10 +78,10 @@ class CLUECalorimeterHit : public CalorimeterHit, public DataObject {
void setEta();
void setPhi();

void setRho( float rho ) { m_rho = rho; };
void setDelta( float delta ) { m_delta = delta; };
void setStatus( Status status ) { m_status = status; };
void setClusterIndex( int clIdx ) { m_clusterIndex = clIdx; };
void setRho( float rho ) { m_rho = rho; }
void setDelta( float delta ) { m_delta = delta; }
void setStatus( Status status ) { m_status = status; }
void setClusterIndex( int clIdx ) { m_clusterIndex = clIdx; }

private:
std::uint8_t m_detectorRegion{0};
Expand Down
5 changes: 1 addition & 4 deletions include/IO_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
// podio specific includes
#include "DDSegmentation/BitFieldCoder.h"

using namespace dd4hep ;
using namespace DDSegmentation ;

void read_EDM4HEP_event(const edm4hep::CalorimeterHitCollection& calo_coll, std::string cellIDstr,
std::vector<float>& x, std::vector<float>& y, std::vector<int>& layer, std::vector<float>& weight) {

Expand All @@ -42,7 +39,7 @@ void read_EDM4HEP_event(const edm4hep::CalorimeterHitCollection& calo_coll, std:
float phi_tmp;

for (const auto& ch : calo_coll) {
const BitFieldCoder bf(cellIDstr);
const dd4hep::DDSegmentation::BitFieldCoder bf(cellIDstr);
auto ch_layer = bf.get( ch.getCellID(), "layer");
auto ch_energy = ch.getEnergy();

Expand Down
2 changes: 1 addition & 1 deletion include/Points.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct Points {
// std::vector<bool> behaves similarly to std::vector, but in order to be space efficient, it:
// Does not necessarily store its elements as a contiguous array (so &v[0] + n != &v[n])

int n;
size_t n;

void clear() {
x.clear();
Expand Down
18 changes: 10 additions & 8 deletions src/CLUEAlgo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
* limitations under the License.
*/
#include "CLUEAlgo.h"

#include <array>
#include <chrono>

template <typename TILES>
void CLUEAlgo_T<TILES>::makeClusters(){
Expand Down Expand Up @@ -70,7 +72,7 @@ std::map<int, std::vector<int> > CLUEAlgo_T<TILES>::getClusters(){

template <typename TILES>
void CLUEAlgo_T<TILES>::prepareDataStructures(){
for (int i=0; i<points_.n; i++){
for (size_t i=0; i<points_.n; i++){
// push index of points into tiles
allLayerTiles_.fill( points_.layer[i], points_.x[i], points_.y[i], points_.x[i]/(1.*points_.r[i]), i );
}
Expand All @@ -83,7 +85,7 @@ void CLUEAlgo_T<TILES>::calculateLocalDensity(){
auto dc2 = dc_*dc_;

// loop over all points
for(unsigned i = 0; i < points_.n; i++) {
for(size_t i = 0; i < points_.n; i++) {
const auto& lt = allLayerTiles_[points_.layer[i]];
float ri = points_.r[i];
float inv_ri = 1.f/ri;
Expand All @@ -110,18 +112,18 @@ void CLUEAlgo_T<TILES>::calculateLocalDensity(){
binId = lt.getGlobalBinByBinPhi(phi, yBin);
}
// get the size of this bin
int binSize = lt[binId].size();
size_t binSize = lt[binId].size();
// std::cout << "binSize = " << binSize << " for [xBin,yBin] = [" << xBin << "," << yBin << "]" << std::endl;

// iterate inside this bin
for (unsigned int binIter = 0; binIter < binSize; binIter++) {
int j = lt[binId][binIter];
for (size_t binIter = 0; binIter < binSize; binIter++) {
auto j = lt[binId][binIter];
// query N_{dc_}(i)
float dist2_ij = TILES::constants_type_t::endcap ?
distance2(i, j) : distance2(i, j, true, ri);
if(dist2_ij <= dc2) {
// sum weights within N_{dc_}(i)
points_.rho[i] += (i == j ? 1.f : 0.5f) * points_.weight[j];
points_.rho[i] += (i == static_cast<unsigned int>(j) ? 1.f : 0.5f) * points_.weight[j];
}
} // end of interate inside this bin
}
Expand All @@ -135,7 +137,7 @@ template <typename TILES>
void CLUEAlgo_T<TILES>::calculateDistanceToHigher(){
// loop over all points
float dm = outlierDeltaFactor_ * dc_;
for(unsigned i = 0; i < points_.n; i++) {
for(size_t i = 0; i < points_.n; i++) {
// default values of delta and nearest higher for i
float delta_i = std::numeric_limits<float>::max();
int nearestHigher_i = -1;
Expand Down Expand Up @@ -172,7 +174,7 @@ void CLUEAlgo_T<TILES>::calculateDistanceToHigher(){
// query N'_{dm}(i)
bool foundHigher = (points_.rho[j] > rho_i);
// in the rare case where rho is the same, use detid
foundHigher = foundHigher || ((points_.rho[j] == rho_i) && (j>i) );
foundHigher = foundHigher || ((points_.rho[j] == rho_i) && (static_cast<unsigned int>(j)>i) );
float dist_ij = TILES::constants_type_t::endcap ?
distance(i, j) : distance(i, j, true, ri);
if(foundHigher && dist_ij <= dm) { // definition of N'_{dm}(i)
Expand Down
8 changes: 4 additions & 4 deletions src/CLUECalorimeterHit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ CLUECalorimeterHit::CLUECalorimeterHit(const CalorimeterHit& ch)

CLUECalorimeterHit::CLUECalorimeterHit(const CalorimeterHit& ch, const CLUECalorimeterHit::DetectorRegion detRegion, const int layer)
: CalorimeterHit(ch),
m_layer(layer),
m_detectorRegion(detRegion) {
m_detectorRegion(detRegion),
m_layer(layer) {
setR();
setEta();
setPhi();
Expand All @@ -43,9 +43,9 @@ CLUECalorimeterHit::CLUECalorimeterHit(const CalorimeterHit& ch, const CLUECalor
m_detectorRegion(detRegion),
m_layer(layer),
m_status(status),
m_clusterIndex(clusterIndex),
m_rho(rho),
m_delta(delta) {
m_delta(delta),
m_clusterIndex(clusterIndex) {
setR();
setEta();
setPhi();
Expand Down
4 changes: 2 additions & 2 deletions src/CLUENtuplizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ StatusCode CLUENtuplizer::execute(const EventContext&) const {
float totEnergy = 0;
float totEnergyHits = 0;
std::uint64_t totSize = 0;
bool foundInECAL = false;
// bool foundInECAL = false;

info() << ClusterCollectionName << " : Total number of clusters = " << int( cluster_coll->size() ) << endmsg;
for (const auto& cl : *cluster_coll) {
Expand All @@ -137,7 +137,7 @@ StatusCode CLUENtuplizer::execute(const EventContext&) const {
// Printout the hits that are in Ecal but not included in the clusters
int maxLayer = 0;
for (const auto& hit : cl.getHits()) {
foundInECAL = false;
// foundInECAL = false;
/*
for (const auto& clEB : *EB_calo_coll) {
if( clEB.getCellID() == hit.getCellID()){
Expand Down
2 changes: 0 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ limitations under the License.
# CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/include/modern/*.hpp")
set(GLOB HEADER_LIST CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/include/*.h")

set(CMAKE_CXX_FLAGS "-fPIC")

## Make an automatic library - will be static or dynamic based on user setting
add_library(CLUEAlgo_lib CLUEAlgo.cc ${HEADER_LIST})

Expand Down
10 changes: 6 additions & 4 deletions src/ClueGaudiAlgorithmWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ std::map<int, std::vector<int> > ClueGaudiAlgorithmWrapper::runAlgo(std::vector<
info() << "Finished running CLUE algorithm" << endmsg;

// Including CLUE info in cluePoints
for(int i = 0; i < cluePoints.n; i++){
for(size_t i = 0; i < cluePoints.n; i++){

clue_hits[i].setRho(cluePoints.rho[i]);
clue_hits[i].setDelta(cluePoints.delta[i]);
Expand Down Expand Up @@ -285,9 +285,7 @@ void ClueGaudiAlgorithmWrapper::calculatePosition(edm4hep::MutableCluster* clust
float z_log = 0.f;
double thresholdW0_ = 2.9; //Min percentage of energy to contribute to the log-reweight position

float maxEnergyValue = 0.f;
unsigned int maxEnergyIndex = 0;
for (int i = 0; i < cluster->hits_size(); i++) {
for (size_t i = 0; i < cluster->hits_size(); i++) {
float rhEnergy = cluster->getHits(i).getEnergy();
float Wi = std::max(thresholdW0_ - std::log(rhEnergy / total_weight), 0.);
x_log += cluster->getHits(i).getPosition().x * Wi;
Expand Down Expand Up @@ -417,6 +415,10 @@ StatusCode ClueGaudiAlgorithmWrapper::execute(const EventContext&) const {
// Save CLUE calo hits
auto pCHV = std::make_unique<clue::CLUECalorimeterHitCollection>(clue_hit_coll);
const StatusCode scStatusV = eventSvc()->registerObject("/Event/CLUECalorimeterHitCollection", pCHV.release());
if (scStatusV.isFailure()) {
error() << "Failed to register CLUECalorimeterHitCollection" << endmsg;
return StatusCode::FAILURE;
}
info() << "Saved " << clue_hit_coll.vect.size() << " CLUE calo hits in total. " << endmsg;

// Save clusters as calo hits and add cellID to them
Expand Down

0 comments on commit 810c339

Please sign in to comment.