Skip to content
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

Total four momentum #1504

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/algorithms/reco/CalorimeterTotalFourMomentum.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2024 Sebouh Pual
#include "CalorimeterTotalFourMomentum.h"
#include <edm4eic/ClusterCollection.h>
#include <edm4hep/Vector4f.h>
#include <math.h>
#include <gsl/pointers>

/**
Creates a pseudo particle containing the momenta and energies from all clusters in a given ClusterCollection.
The 3-momentum for each cluster is the energy of that cluster, in the direction from the origin to the
cluster position. These 3-momenta, along with the energies of the clusters, are added together to form
the total four-momentum in the calorimeter system.

*/

namespace eicrecon {

void CalorimeterTotalFourMomentum::init() { }

void CalorimeterTotalFourMomentum::process(const CalorimeterTotalFourMomentum::Input& input,
const CalorimeterTotalFourMomentum::Output& output) const {

const auto [clusters] = input;
auto [hadronic_final_state] = output;

double Etot=0;
double pxtot=0;
double pytot=0;
double pztot=0;
for (const auto& cluster : *clusters) {
double E = cluster.getEnergy();
Etot+=E;
double x= cluster.getPosition().x;
double y= cluster.getPosition().y;
double z= cluster.getPosition().z;
double r=sqrt(x*x+y*y+z*z);
pxtot+=E*x/r;
pytot+=E*y/r;
pztot+=E*z/r;
}
auto hfs = hadronic_final_state->create();
hfs.setMomentum({(float)pxtot, (float)pytot, (float)pztot});
hfs.setEnergy((float)Etot);
}
}
42 changes: 42 additions & 0 deletions src/algorithms/reco/CalorimeterTotalFourMomentum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2024 Sebouh Paul

#pragma once

#include <edm4eic/ClusterCollection.h>
#include <edm4hep/Vector4f.h>
#include <edm4eic/ReconstructedParticleCollection.h>
#include <spdlog/logger.h>
#include <memory>
#include <string> // for basic_string
#include <string_view> // for string_view
#include <algorithms/algorithm.h>
#include "algorithms/interfaces/WithPodConfig.h"


namespace eicrecon {

using CalorimeterTotalFourMomentumAlgorithm = algorithms::Algorithm<
algorithms::Input<
const edm4eic::ClusterCollection
>,
algorithms::Output<
edm4eic::ReconstructedParticleCollection
>
>;
class CalorimeterTotalFourMomentum :
public CalorimeterTotalFourMomentumAlgorithm,
public WithPodConfig<NoConfig> {
public:
CalorimeterTotalFourMomentum(std::string_view name)
: CalorimeterTotalFourMomentumAlgorithm{name,
{"inputClusters"},
{"totalFourMomentum"},
"Merges all clusters in a collection into a total 4-vector of momentum and energy"} {}

void init() final;
void process(const Input&, const Output&) const final;
private:
std::shared_ptr<spdlog::logger> m_log;
};
} // namespace eicrecon
13 changes: 13 additions & 0 deletions src/detectors/FHCAL/FHCAL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "factories/calorimetry/CalorimeterTruthClustering_factory.h"
#include "factories/calorimetry/HEXPLIT_factory.h"
#include "factories/calorimetry/ImagingTopoCluster_factory.h"
#include "factories/reco/CalorimeterTotalFourMomentum_factory.h"

extern "C" {
void InitPlugin(JApplication *app) {
Expand Down Expand Up @@ -138,6 +139,18 @@ extern "C" {
)
);

app->Add(
new JOmniFactoryGeneratorT<CalorimeterTotalFourMomentum_factory>(
"HcalEndcapPInsertTotalFourMomentum",
{"HcalEndcapPInsertClusters"}, // edm4eic::Cluster
{"HcalEndcapPInsertTotalFourMomentum"}, // edm4eic::ReconstructedParticle
{

},
app // TODO: Remove me once fixed
)
);

// Make sure digi and reco use the same value
decltype(CalorimeterHitDigiConfig::capADC) LFHCAL_capADC = 65536;
decltype(CalorimeterHitDigiConfig::dyRangeADC) LFHCAL_dyRangeADC = 1 * dd4hep::GeV;
Expand Down
39 changes: 39 additions & 0 deletions src/factories/reco/CalorimeterTotalFourMomentum_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2024 Sebouh Paul

#pragma once

#include "algorithms/reco/CalorimeterTotalFourMomentum.h"
#include "services/algorithms_init/AlgorithmsInit_service.h"
#include "extensions/jana/JOmniFactory.h"


namespace eicrecon {

class CalorimeterTotalFourMomentum_factory : public JOmniFactory<CalorimeterTotalFourMomentum_factory,NoConfig> {

using AlgoT = eicrecon::CalorimeterTotalFourMomentum;
private:
std::unique_ptr<AlgoT> m_algo;
PodioInput<edm4eic::Cluster> m_clusters_input {this};
PodioOutput<edm4eic::ReconstructedParticle> m_four_momentum_output {this};

Service<AlgorithmsInit_service> m_algorithmsInit {this};

public:
void Configure() {
m_algo = std::make_unique<AlgoT>(GetPrefix());
m_algo->level((algorithms::LogLevel)logger()->level());
m_algo->applyConfig(config());
m_algo->init();
}

void ChangeRun(int64_t run_number) {
}

void Process(int64_t run_number, uint64_t event_number) {
m_algo->process({m_clusters_input()},{m_four_momentum_output().get()});
}
};

} // eicrecon
2 changes: 1 addition & 1 deletion src/services/io/podio/JEventProcessorPODIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ JEventProcessorPODIO::JEventProcessorPODIO() {
#if EDM4EIC_VERSION_MAJOR >= 6
"HadronicFinalState",
#endif

"HcalEndcapPInsertTotalFourMomentum",
// Track projections
"CalorimeterTrackProjections",

Expand Down
Loading