-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Move CLUE algo in external library #17
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2712e17
First step to create clue lib (CPU only)
ebrondol 71e67f2
Include GPU version in clue lib
ebrondol c0e88fd
Adapt ClueGaudiAlgorithmWrapper to use clue lib
ebrondol 1c980b8
Clean up of .h and .cc files related to CLUE algo
ebrondol 0c1487c
Clean up everything that is already in standalone repo and not necessary
ebrondol 835e0a3
Update readme accordingly
ebrondol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,174 @@ | ||
// STL | ||
#include <vector> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <exception> | ||
#include <cassert> | ||
|
||
// test data model | ||
#include "edm4hep/CalorimeterHitCollection.h" | ||
#include "edm4hep/ClusterCollection.h" | ||
|
||
// 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) { | ||
|
||
float r_tmp; | ||
float eta_tmp; | ||
float phi_tmp; | ||
|
||
for (const auto& ch : calo_coll) { | ||
const BitFieldCoder bf(cellIDstr); | ||
auto ch_layer = bf.get( ch.getCellID(), "layer"); | ||
auto ch_energy = ch.getEnergy(); | ||
|
||
//eta,phi | ||
r_tmp = sqrt(ch.getPosition().x*ch.getPosition().x + ch.getPosition().y*ch.getPosition().y); | ||
eta_tmp = - 1. * log(tan(atan2(r_tmp, ch.getPosition().z)/2.)); | ||
phi_tmp = atan2(ch.getPosition().y, ch.getPosition().x); | ||
|
||
x.push_back(eta_tmp); | ||
y.push_back(phi_tmp); | ||
layer.push_back(ch_layer); | ||
weight.push_back(ch_energy); | ||
//std::cout << eta_tmp << "," << phi_tmp << "," << ch_layer << "," << ch_energy << std::endl; | ||
} | ||
|
||
return; | ||
} | ||
|
||
void read_from_csv(const std::string& inputFileName, | ||
std::vector<float>& x, std::vector<float>& y, std::vector<int>& layer, std::vector<float>& weight) { | ||
|
||
std::cout<<"input csv file: "<<inputFileName<<std::endl; | ||
// open csv file | ||
std::ifstream iFile(inputFileName); | ||
if( !iFile.is_open() ){ | ||
std::cerr << "Failed to open the file" << std::endl; | ||
return; | ||
} | ||
|
||
// make dummy layers | ||
for (int l=0; l<10; l++){ | ||
std::string value = ""; | ||
// Iterate through each line and split the content using delimeter | ||
while (getline(iFile, value, ',')) { | ||
x.push_back(std::stof(value)) ; | ||
getline(iFile, value, ','); y.push_back(std::stof(value)); | ||
getline(iFile, value, ','); layer.push_back(std::stoi(value) + l); | ||
getline(iFile, value); weight.push_back(std::stof(value)); | ||
} | ||
} | ||
std::cout << "Finished loading input points" << std::endl; | ||
|
||
iFile.close(); | ||
return; | ||
} | ||
|
||
void computeClusters(const edm4hep::CalorimeterHitCollection& calo_coll, | ||
std::string cellIDstr, | ||
const std::map<int, std::vector<int> > clusterMap, | ||
edm4hep::ClusterCollection* clusters){ | ||
const BitFieldCoder bf(cellIDstr) ; | ||
|
||
for(auto cl : clusterMap){ | ||
//std::cout << cl.first << std::endl; | ||
std::map<int, std::vector<int> > clustersLayer; | ||
for(auto index : cl.second){ | ||
auto ch_layer = bf.get( calo_coll.at(index).getCellID(), "layer"); | ||
clustersLayer[ch_layer].push_back(index); | ||
} | ||
|
||
for(auto clLay : clustersLayer){ | ||
float energy = 0.f; | ||
float energyErr = 0.f; | ||
auto position = edm4hep::Vector3f({0,0,0}); | ||
|
||
unsigned int maxEnergyIndex = 0; | ||
float maxEnergyValue = 0.f; | ||
//std::cout << " layer = " << clLay.first << std::endl; | ||
for(auto index : clLay.second){ | ||
//std::cout << " " << index << std::endl; | ||
energy += calo_coll.at(index).getEnergy(); | ||
energyErr += sqrt(calo_coll.at(index).getEnergyError()*calo_coll.at(index).getEnergyError()); | ||
position.x += calo_coll.at(index).getPosition().x; | ||
position.y += calo_coll.at(index).getPosition().y; | ||
position.z += calo_coll.at(index).getPosition().z; | ||
|
||
if (calo_coll.at(index).getEnergy() > maxEnergyValue) { | ||
maxEnergyValue = calo_coll.at(index).getEnergy(); | ||
maxEnergyIndex = index; | ||
} | ||
} | ||
|
||
auto cluster = clusters->create(); | ||
cluster.setEnergy(energy); | ||
cluster.setEnergyError(energyErr); | ||
// one could (should?) re-weight the barycentre with energy | ||
cluster.setPosition({position.x/clLay.second.size(), position.y/clLay.second.size(), position.z/clLay.second.size()}); | ||
cluster.setType(calo_coll.at(maxEnergyIndex).getType()); | ||
} | ||
clustersLayer.clear(); | ||
|
||
} | ||
return; | ||
} | ||
|
||
void computeCaloHits(const edm4hep::CalorimeterHitCollection& calo_coll, | ||
std::string cellIDstr, | ||
const std::map<int, std::vector<int> > clusterMap, | ||
edm4hep::CalorimeterHitCollection* clusters){ | ||
|
||
const BitFieldCoder bf(cellIDstr) ; | ||
|
||
for(auto cl : clusterMap){ | ||
//std::cout << cl.first << std::endl; | ||
std::map<int, std::vector<int> > clustersLayer; | ||
for(auto index : cl.second){ | ||
auto ch_layer = bf.get( calo_coll.at(index).getCellID(), "layer"); | ||
clustersLayer[ch_layer].push_back(index); | ||
} | ||
|
||
for(auto clLay : clustersLayer){ | ||
float energy = 0.f; | ||
float energyErr = 0.f; | ||
float time = 0.f; | ||
auto position = edm4hep::Vector3f({0,0,0}); | ||
|
||
unsigned int maxEnergyIndex = 0; | ||
float maxEnergyValue = 0.f; | ||
//std::cout << " layer = " << clLay.first << std::endl; | ||
for(auto index : clLay.second){ | ||
//std::cout << " " << index << std::endl; | ||
energy += calo_coll.at(index).getEnergy(); | ||
energyErr += sqrt(calo_coll.at(index).getEnergyError()*calo_coll.at(index).getEnergyError()); | ||
position.x += calo_coll.at(index).getPosition().x; | ||
position.y += calo_coll.at(index).getPosition().y; | ||
position.z += calo_coll.at(index).getPosition().z; | ||
time += calo_coll.at(index).getTime(); | ||
|
||
if (calo_coll.at(index).getEnergy() > maxEnergyValue) { | ||
maxEnergyValue = calo_coll.at(index).getEnergy(); | ||
maxEnergyIndex = index; | ||
} | ||
} | ||
|
||
auto cluster = clusters->create(); | ||
cluster.setEnergy(energy); | ||
cluster.setEnergyError(energyErr); | ||
// one could (should?) re-weight the barycentre with energy | ||
cluster.setPosition({position.x/clLay.second.size(), position.y/clLay.second.size(), position.z/clLay.second.size()}); | ||
cluster.setCellID(calo_coll.at(maxEnergyIndex).getCellID()); | ||
cluster.setType(calo_coll.at(maxEnergyIndex).getType()); | ||
cluster.setTime(time/clLay.second.size()); | ||
} | ||
clustersLayer.clear(); | ||
|
||
} | ||
return; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 @@ | ||
header,target,directory |
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 @@ | ||
v2::libClueGaudiAlgorithmWrapper.so:ClueGaudiAlgorithmWrapper |
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,4 @@ | ||
## -*- ascii -*- | ||
# db file automatically generated by genconf on: Thu Jan 27 18:03:39 2022 | ||
k4clue.ClueGaudiAlgorithmWrapperConf ClueGaudiAlgorithmWrapper ClueGaudiAlgorithmWrapper | ||
## k4clue |
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove config generated files