Skip to content

Commit

Permalink
fix: handle PID in ZVertexFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks committed Sep 26, 2024
1 parent 9f93f5c commit 4b0f5c9
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 68 deletions.
9 changes: 3 additions & 6 deletions examples/config/my_combined_config_file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ clas12::ZVertexFilter:

# default cuts
- default:
pids: [ 11 ]
cuts: [ -33.0, 11.0 ]
electron_vz: [ -33.0, 11.0 ]

#RG-A fall2018 inbending
- runs: [ 4760, 5419 ]
pids: [ 11 ]
cuts: [ -13.0, 12.0 ]
electron_vz: [ -13.0, 12.0 ]

#RG-A fall2018 outbending
- runs: [ 5420, 5674 ]
pids: [ 11 ]
cuts: [ -18.0, 10.0 ]
electron_vz: [ -18.0, 10.0 ]

another::Algorithm:
#Cuts below are just examples:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ clas12::ZVertexFilter:

# default cuts
- default:
pids: [ 11 ]
cuts: [ -15.0, 15.0 ]
electron_vz: [ -15.0, 15.0 ]

# RG-A fall2018 inbending
- runs: [ 4760, 5419 ]
pids: [ 11 ]
cuts: [ -5.0, 3.0 ]
electron_vz: [ -5.0, 3.0 ]

# RG-A fall2018 outbending
- runs: [ 5420, 5674 ]
pids: [ 11 ]
cuts: [ -8.0, 7.0 ]
electron_vz: [ -8.0, 7.0 ]
9 changes: 3 additions & 6 deletions examples/config/my_z_vertex_cuts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ clas12::ZVertexFilter:

# default cuts
- default:
pids: [ 11 ]
cuts: [ -1.5, 1.3 ]
electron_vz: [ -1.5, 1.3 ]

# RG-A fall2018 inbending
- runs: [ 4760, 5419 ]
pids: [ 11 ]
cuts: [ -0.5, 0.5 ]
electron_vz: [ -0.5, 0.5 ]

# RG-A fall2018 outbending
- runs: [ 5420, 5674 ]
pids: [ 11 ]
cuts: [ -0.8, 0.7 ]
electron_vz: [ -0.8, 0.7 ]
32 changes: 16 additions & 16 deletions examples/iguana_ex_cpp_config_files.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ int main(int argc, char** argv)
algo->Start();
auto key = algo->PrepareEvent(4800); // sets the run number and loads the cuts
assert((algo->GetRunNum(key) == 4800)); // pass the key into the 'Get*' methods
assert((algo->GetZcuts(key).at(0) == -13.0));
assert((algo->GetZcuts(key).at(1) == 12.0));
assert((algo->GetElectronZcuts(key).at(0) == -13.0));
assert((algo->GetElectronZcuts(key).at(1) == 12.0));
break;
}

case 2:
{
// Use `SetZcuts` to set the cuts
// Use `SetElectronZcuts` to set the cuts
// - note that this will OVERRIDE any value used in any configuration file
// - only use `SetZcuts` if for any reason you want to hard-code a specific value; usage
// - only use `SetElectronZcuts` if for any reason you want to hard-code a specific value; usage
// of configuration files is preferred in general
algo->Start();
iguana::concurrent_key_t const key = 0; // need the same key in `SetZcuts` and `GetZcuts`
algo->SetZcuts(-5.0, 3.0, key);
assert((algo->GetZcuts(key).at(0) == -5.0));
assert((algo->GetZcuts(key).at(1) == 3.0));
iguana::concurrent_key_t const key = 0; // need the same key in `SetElectronZcuts` and `GetElectronZcuts`
algo->SetElectronZcuts(-5.0, 3.0, key);
assert((algo->GetElectronZcuts(key).at(0) == -5.0));
assert((algo->GetElectronZcuts(key).at(1) == 3.0));
break;
}

Expand All @@ -72,8 +72,8 @@ int main(int argc, char** argv)
algo->SetConfigFile(configDir + "/my_z_vertex_cuts.yaml");
algo->Start();
auto key = algo->PrepareEvent(5500);
assert((algo->GetZcuts(key).at(0) == -0.8));
assert((algo->GetZcuts(key).at(1) == 0.7));
assert((algo->GetElectronZcuts(key).at(0) == -0.8));
assert((algo->GetElectronZcuts(key).at(1) == 0.7));
break;
}

Expand All @@ -85,8 +85,8 @@ int main(int argc, char** argv)
algo->SetConfigFile("my_z_vertex_cuts.yaml");
algo->Start();
auto key = algo->PrepareEvent(0); // run number "0" means "no run number"
assert((algo->GetZcuts(key).at(0) == -1.5));
assert((algo->GetZcuts(key).at(1) == 1.3));
assert((algo->GetElectronZcuts(key).at(0) == -1.5));
assert((algo->GetElectronZcuts(key).at(1) == 1.3));
break;
}

Expand All @@ -99,8 +99,8 @@ int main(int argc, char** argv)
algo->SetConfigDirectory(configDir + "/my_config_directory");
algo->Start();
auto key = algo->PrepareEvent(0); // run number "0" means "no run number"
assert((algo->GetZcuts(key).at(0) == -15.0));
assert((algo->GetZcuts(key).at(1) == 15.0));
assert((algo->GetElectronZcuts(key).at(0) == -15.0));
assert((algo->GetElectronZcuts(key).at(1) == 15.0));
break;
}

Expand All @@ -111,8 +111,8 @@ int main(int argc, char** argv)
algo->SetConfigFile("my_combined_config_file.yaml");
algo->Start();
auto key = algo->PrepareEvent(0); // run number "0" means "no run number"
assert((algo->GetZcuts(key).at(0) == -33.0));
assert((algo->GetZcuts(key).at(1) == 11.0));
assert((algo->GetElectronZcuts(key).at(0) == -33.0));
assert((algo->GetElectronZcuts(key).at(1) == 11.0));
break;
}

Expand Down
32 changes: 12 additions & 20 deletions src/iguana/algorithms/clas12/ZVertexFilter/Algorithm.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Algorithm.h"
#include "iguana/algorithms/TypeDefs.h"

namespace iguana::clas12 {

Expand All @@ -10,7 +11,7 @@ namespace iguana::clas12 {
// get configuration
ParseYAMLConfig();
o_runnum = ConcurrentParamFactory::Create<int>();
o_zcuts = ConcurrentParamFactory::Create<std::vector<double>>();
o_electron_vz_cuts = ConcurrentParamFactory::Create<std::vector<double>>();

// get expected bank indices
b_particle = GetBankIndex(banks, "REC::Particle");
Expand Down Expand Up @@ -63,40 +64,31 @@ namespace iguana::clas12 {
std::lock_guard<std::mutex> const lock(m_mutex); // NOTE: be sure to lock successive `ConcurrentParam::Save` calls !!!
m_log->Trace("-> calling Reload({}, {})", runnum, key);
o_runnum->Save(runnum, key);
o_zcuts->Save(GetOptionVector<double>("cuts", {GetConfig()->InRange("runs", runnum), "cuts"}), key);
// FIXME: handle PIDs
o_electron_vz_cuts->Save(GetOptionVector<double>("electron_vz", {GetConfig()->InRange("runs", runnum), "electron_vz"}), key);
}

bool ZVertexFilter::Filter(double const zvertex, int const pid, int const status, concurrent_key_t key) const
{
auto zcuts = GetZcuts(key);
return zvertex > zcuts.at(0) && zvertex < zcuts.at(1);

// FIXME
// FIXME
// FIXME
// //only apply filter if particle pid is in list of pids
// //and particles not in FT (ie FD or CD)
// if(o_pids.find(pid) != o_pids.end() && abs(status)>=2000) {
// return zvertex > GetZcutLower() && zvertex < GetZcutUpper();
// } else {
// return true;
// }
if(pid == particle::PDG::electron && abs(status) >= 2000) {
auto zcuts = GetElectronZcuts(key);
return zvertex > zcuts.at(0) && zvertex < zcuts.at(1);
}
return true; // cuts don't apply
}

int ZVertexFilter::GetRunNum(concurrent_key_t const key) const
{
return o_runnum->Load(key);
}

std::vector<double> ZVertexFilter::GetZcuts(concurrent_key_t const key) const
std::vector<double> ZVertexFilter::GetElectronZcuts(concurrent_key_t const key) const
{
return o_zcuts->Load(key);
return o_electron_vz_cuts->Load(key);
}

void ZVertexFilter::SetZcuts(double zcut_lower, double zcut_upper, concurrent_key_t const key)
void ZVertexFilter::SetElectronZcuts(double zcut_lower, double zcut_upper, concurrent_key_t const key)
{
o_zcuts->Save({zcut_lower, zcut_upper}, key);
o_electron_vz_cuts->Save({zcut_lower, zcut_upper}, key);
}

void ZVertexFilter::Stop()
Expand Down
14 changes: 6 additions & 8 deletions src/iguana/algorithms/clas12/ZVertexFilter/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace iguana::clas12 {
/// @end_doc
///
/// @begin_doc_config
/// @config_param{cuts | list[double] | lower and upper @f$z@f$-vertex cuts; run-range dependent}
/// @config_param{electron_vz | list[double] | lower and upper electron @f$z@f$-vertex cuts; run-range dependent; cuts are not applied to FT electrons (FD and CD only)}
/// @end_doc
class ZVertexFilter : public Algorithm
{
Expand Down Expand Up @@ -48,15 +48,15 @@ namespace iguana::clas12 {

/// @param key the return value of `::PrepareEvent`
/// @returns the current z-vertex cuts
std::vector<double> GetZcuts(concurrent_key_t const key) const;
std::vector<double> GetElectronZcuts(concurrent_key_t const key) const;

/// @brief sets the z-vertex cuts
/// @warning this method is not thread safe; instead, for thread safety,
/// use `::PrepareEvent` and a custom configuration file.
/// @param zcut_lower the lower bound of the cut
/// @param zcut_upper the upper bound of the cut
/// @param key the, for `::GetZcuts`
void SetZcuts(double zcut_lower, double zcut_upper, concurrent_key_t const key);
/// @param key the, for `::GetElectronZcuts`
void SetElectronZcuts(double zcut_lower, double zcut_upper, concurrent_key_t const key);

private:
hipo::banklist::size_type b_particle, b_config;
Expand All @@ -67,11 +67,9 @@ namespace iguana::clas12 {
/// Run number
mutable std::unique_ptr<ConcurrentParam<int>> o_runnum;

/// Z-vertex cut
mutable std::unique_ptr<ConcurrentParam<std::vector<double>>> o_zcuts;
/// Electron Z-vertex cuts
mutable std::unique_ptr<ConcurrentParam<std::vector<double>>> o_electron_vz_cuts;

/// pids to apply ZVertexFilter to
std::set<int> o_pids;
};

}
9 changes: 3 additions & 6 deletions src/iguana/algorithms/clas12/ZVertexFilter/Config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ clas12::ZVertexFilter:

# default cuts
- default:
pids: [ 11 ]
cuts: [ -20.0, 20.0 ]
electron_vz: [ -20.0, 20.0 ]

# RG-A fall2018 inbending
- runs: [ 4760, 5419 ]
pids: [ 11 ]
cuts: [ -13.0, 12.0 ]
electron_vz: [ -13.0, 12.0 ]

# RG-A fall2018 outbending
- runs: [ 5420, 5674 ]
pids: [ 11 ]
cuts: [ -18.0, 10.0 ]
electron_vz: [ -18.0, 10.0 ]

0 comments on commit 4b0f5c9

Please sign in to comment.