Skip to content

Commit

Permalink
preliminary base class for hcal
Browse files Browse the repository at this point in the history
  • Loading branch information
therwig committed Jul 16, 2023
1 parent 95d5d21 commit a4f476e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
2 changes: 2 additions & 0 deletions Recon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ if(BUILD_EVENT_ONLY)

register_event_object(module_path "Recon/Event" namespace "ldmx"
class "CalorimeterHit" type "collection" )
register_event_object(module_path "Recon/Event" namespace "ldmx"
class "CaloCluster" type "collection" )
register_event_object( module_path "Recon/Event" namespace "ldmx"
class "TriggerResult" )
register_event_object( module_path "Recon/Event" namespace "ldmx"
Expand Down
7 changes: 4 additions & 3 deletions Recon/include/Recon/DBScanClusterBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
/* #include "Hcal/Event/HcalHit.h" */
/* #include "Hcal/Event/HcalCluster.h" */
#include "Recon/Event/CalorimeterHit.h"
#include "Recon/Event/CaloCluster.h"
/* #include "Ecal/MyClusterWeight.h" */
/* #include "Ecal/TemplatedClusterFinder.h" */
/* #include "Ecal/WorkingCluster.h" */
Expand All @@ -43,9 +44,9 @@ class DBScanClusterBuilder {
std::vector<std::vector<const ldmx::CalorimeterHit*> > runDBSCAN(
const std::vector<const ldmx::CalorimeterHit*> &hits, bool debug);

template <class C>
void fillClusterInfoFromHits(C &cl, std::vector<const ldmx::CalorimeterHit*> hits,
float minHitEnergy, bool logEnergyWeight);
void fillClusterInfoFromHits(ldmx::CaloCluster *cl,
std::vector<const ldmx::CalorimeterHit*> hits,
float minHitEnergy, bool logEnergyWeight);

void setMinHitEnergy(float x){minHitEnergy_=x;}

Expand Down
27 changes: 13 additions & 14 deletions Recon/src/Recon/DBScanClusterBuilder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ namespace recon {

}

template <class C>
void DBScanClusterBuilder::fillClusterInfoFromHits(C &cl,
void DBScanClusterBuilder::fillClusterInfoFromHits(ldmx::CaloCluster *cl,
std::vector<const ldmx::CalorimeterHit*> hits,
float minHitEnergy, bool logEnergyWeight){

Expand Down Expand Up @@ -120,14 +119,14 @@ void DBScanClusterBuilder::fillClusterInfoFromHits(C &cl,
xx = sqrt(xx - x * x); //now is sqrt(<x^2>-<x>^2)
yy = sqrt(yy - y * y);
zz = sqrt(zz - z * z);
cl.setEnergy(e);
cl.setNHits(n);
cl.setCentroidXYZ(x,y,z);
cl.setRMSXYZ(xx,yy,zz);
cl.setHitValsX(raw_xvals);
cl.setHitValsY(raw_yvals);
cl.setHitValsZ(raw_zvals);
cl.setHitValsE(raw_evals);
cl->setEnergy(e);
cl->setNHits(n);
cl->setCentroidXYZ(x,y,z);
cl->setRMSXYZ(xx,yy,zz);
cl->setHitValsX(raw_xvals);
cl->setHitValsY(raw_yvals);
cl->setHitValsZ(raw_zvals);
cl->setHitValsE(raw_evals);

if (xvals.size()>2){
for(int i=0; i<xvals.size();i++){ // mean subtract
Expand All @@ -137,12 +136,12 @@ void DBScanClusterBuilder::fillClusterInfoFromHits(C &cl,
}
TGraph gxz(zvals.size(), zvals.data(), xvals.data());
auto r_xz = gxz.Fit("pol1","SQ"); // p0 + x*p1
cl.setDXDZ( r_xz->Value(1) );
cl.setEDXDZ( r_xz->ParError(1) );
cl->setDXDZ( r_xz->Value(1) );
cl->setEDXDZ( r_xz->ParError(1) );
TGraph gyz(zvals.size(), zvals.data(), yvals.data());
auto r_yz = gyz.Fit("pol1","SQ"); // p0 + x*p1
cl.setDYDZ( r_yz->Value(1) );
cl.setEDYDZ( r_yz->ParError(1) );
cl->setDYDZ( r_yz->Value(1) );
cl->setEDYDZ( r_yz->ParError(1) );
}
return;
}
Expand Down
20 changes: 12 additions & 8 deletions Recon/src/Recon/PFHcalClusterProducer.cxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "Recon/PFHcalClusterProducer.h"
#include "Recon/DBScanClusterBuilder.h"

#include "Recon/Event/CalorimeterHit.h"
#include "Recon/Event/CaloCluster.h"
#include "Hcal/Event/HcalHit.h"
#include "Hcal/Event/HcalCluster.h"
#include "TGraph.h"
Expand Down Expand Up @@ -232,7 +234,8 @@ void PFHcalClusterProducer::produce(framework::Event& event) {
const auto hcalRecHits = event.getCollection<ldmx::HcalHit>(hitCollName_);
//std::cout << "found " << hcalRecHits.size() << " hits" << std::endl;

std::vector<ldmx::HcalCluster> pfClusters;
// std::vector<ldmx::HcalCluster> pfClusters;
std::vector<ldmx::CaloCluster> pfClusters;
float eTotal=0;
if(!singleCluster_){
DBScanClusterBuilder cb;
Expand All @@ -241,27 +244,28 @@ void PFHcalClusterProducer::produce(framework::Event& event) {
std::vector<std::vector<const ldmx::CalorimeterHit*> > all_hit_ptrs = cb.runDBSCAN(ptrs,false);
//cout << all_hit_ptrs.size() << endl;
for(const auto hit_ptrs : all_hit_ptrs){
ldmx::HcalCluster cl;
//cb.fillClusterInfoFromHits<ldmx::HcalCluster>(cl, hit_ptrs, minHitEnergy_, logEnergyWeight_);
ldmx::CaloCluster cl;
cb.fillClusterInfoFromHits(&cl, hit_ptrs, minHitEnergy_, logEnergyWeight_);
pfClusters.push_back(cl);
}
for (const auto &h : hcalRecHits) eTotal += h.getEnergy();
} else {
ldmx::HcalCluster cl;
DBScanClusterBuilder dummy;
ldmx::CaloCluster cl;
// fillClusterInfo(cl,hcalRecHits);
std::vector<const ldmx::HcalHit*> ptrs;
std::vector<const ldmx::CalorimeterHit*> ptrs;
ptrs.reserve(hcalRecHits.size());
for (const auto &h : hcalRecHits) {
ptrs.push_back(&h);
eTotal += h.getEnergy();
}
//cb.fillClusterInfoFromHits(cl, ptrs, minHitEnergy_, logEnergyWeight_);
fillClusterInfoFromHits2(cl, ptrs, minHitEnergy_, logEnergyWeight_);
dummy.fillClusterInfoFromHits(&cl, ptrs, minHitEnergy_, logEnergyWeight_);
//fillClusterInfoFromHits2(cl, ptrs, minHitEnergy_, logEnergyWeight_);
pfClusters.push_back(cl);
}
// sort
std::sort(pfClusters.begin(), pfClusters.end(),
[](ldmx::HcalCluster a, ldmx::HcalCluster b) {
[](ldmx::CaloCluster a, ldmx::CaloCluster b) {
return a.getEnergy() > b.getEnergy();
});
event.add(clusterCollName_, pfClusters);
Expand Down
4 changes: 3 additions & 1 deletion Recon/src/Recon/ParticleFlow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "SimCore/Event/SimParticle.h"
#include "SimCore/Event/SimTrackerHit.h"
#include "Recon/Event/CaloCluster.h"
#include "Ecal/Event/EcalCluster.h"
#include "Hcal/Event/HcalCluster.h"
#include "Recon/Event/PFCandidate.h"
Expand Down Expand Up @@ -29,7 +30,8 @@ void ParticleFlow::produce(framework::Event& event) {
if (!event.exists(inputEcalCollName_)) return;
if (!event.exists(inputHcalCollName_)) return;
const auto ecalClusters = event.getCollection<ldmx::EcalCluster>(inputEcalCollName_);
const auto hcalClusters = event.getCollection<ldmx::HcalCluster>(inputHcalCollName_);
const auto hcalClusters = event.getCollection<ldmx::CaloCluster>(inputHcalCollName_);
// const auto hcalClusters = event.getCollection<ldmx::HcalCluster>(inputHcalCollName_);
const auto tracks = event.getCollection<ldmx::SimTrackerHit>(inputTrackCollName_);

//std::cout << ecalClusters.size() << " " << hcalClusters.size() << " " << tracks.size() << std::endl;
Expand Down

0 comments on commit a4f476e

Please sign in to comment.