Skip to content
Snippets Groups Projects
Unverified Commit eca85067 authored by lintao@ihep.ac.cn's avatar lintao@ihep.ac.cn Committed by GitHub
Browse files

Merge pull request #227 from mirguest/CEPCSW-bg-mixing

[WIP] Support GuineaPig Paris output in CEPCSW
parents 6c5ea786 371384fa
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,7 @@ gaudi_add_module(GenAlgo ...@@ -18,6 +18,7 @@ gaudi_add_module(GenAlgo
# ------- Beam Background ------- # ------- Beam Background -------
src/GtBeamBackgroundTool.cpp src/GtBeamBackgroundTool.cpp
src/BeamBackgroundFileParserV0.cpp src/BeamBackgroundFileParserV0.cpp
src/GuineaPigPairsFileParser.cpp
LINK ${ROOT_LIBRARIES} LINK ${ROOT_LIBRARIES}
k4FWCore::k4FWCore k4FWCore::k4FWCore
Gaudi::GaudiAlgLib Gaudi::GaudiAlgLib
......
#include "GtBeamBackgroundTool.h" #include "GtBeamBackgroundTool.h"
#include "IBeamBackgroundFileParser.h" #include "IBeamBackgroundFileParser.h"
#include "BeamBackgroundFileParserV0.h" #include "BeamBackgroundFileParserV0.h"
#include "GuineaPigPairsFileParser.h"
#include "TVector3.h" // for rotation #include "TVector3.h" // for rotation
DECLARE_COMPONENT(GtBeamBackgroundTool) DECLARE_COMPONENT(GtBeamBackgroundTool)
...@@ -11,17 +13,21 @@ StatusCode GtBeamBackgroundTool::initialize() { ...@@ -11,17 +13,21 @@ StatusCode GtBeamBackgroundTool::initialize() {
// create the instances of the background parsers // create the instances of the background parsers
for (auto& [label, inputfn]: m_inputmaps) { for (auto& [label, inputfn]: m_inputmaps) {
double beamE = 120.; std::string format = "BeamBackgroundFileParserV0";
auto itBeamE = m_Ebeammaps.find(label);
if (itBeamE != m_Ebeammaps.end()) { auto itFormat = m_formatmaps.find(label);
beamE = itBeamE->second; if (itFormat != m_formatmaps.end()) {
format = itFormat->second;
}
if (format == "BeamBackgroundFileParserV0") {
init_BeamBackgroundFileParserV0(label, inputfn);
} else if (format == "GuineaPigPairsFileParser") {
init_GuineaPigPairsFileParser(label, inputfn);
} else {
init_BeamBackgroundFileParserV0(label, inputfn);
} }
info() << "Initializing beam background ... "
<< label << " "
<< beamE << " "
<< inputfn
<< endmsg;
m_beaminputs[label] = std::make_shared<BeamBackgroundFileParserV0>(inputfn, 11, beamE);
} }
// check the size // check the size
...@@ -89,3 +95,28 @@ bool GtBeamBackgroundTool::configure_gentool() { ...@@ -89,3 +95,28 @@ bool GtBeamBackgroundTool::configure_gentool() {
return true; return true;
} }
bool GtBeamBackgroundTool::init_BeamBackgroundFileParserV0(const std::string& label,
const std::string& inputfn) {
double beamE = 120.;
auto itBeamE = m_Ebeammaps.find(label);
if (itBeamE != m_Ebeammaps.end()) {
beamE = itBeamE->second;
}
info() << "Initializing beam background ... "
<< label << " "
<< beamE << " "
<< inputfn
<< endmsg;
m_beaminputs[label] = std::make_shared<BeamBackgroundFileParserV0>(inputfn, 11, beamE);
return true;
}
bool GtBeamBackgroundTool::init_GuineaPigPairsFileParser(const std::string& label,
const std::string& inputfn) {
m_beaminputs[label] = std::make_shared<GuineaPigPairsFileParser>(inputfn);
return true;
}
...@@ -46,9 +46,14 @@ public: ...@@ -46,9 +46,14 @@ public:
bool finish() override; bool finish() override;
bool configure_gentool() override; bool configure_gentool() override;
private:
bool init_BeamBackgroundFileParserV0(const std::string& label, const std::string& inputfn);
bool init_GuineaPigPairsFileParser(const std::string& label, const std::string& inputfn);
private: private:
Gaudi::Property<std::map<std::string, std::string>> m_inputmaps{this, "InputFileMap"}; Gaudi::Property<std::map<std::string, std::string>> m_inputmaps{this, "InputFileMap"};
Gaudi::Property<std::map<std::string, std::string>> m_fomatmaps{this, "InputFormatMap"}; Gaudi::Property<std::map<std::string, std::string>> m_formatmaps{this, "InputFormatMap"};
Gaudi::Property<std::map<std::string, double>> m_ratemaps {this, "InputRateMap"}; Gaudi::Property<std::map<std::string, double>> m_ratemaps {this, "InputRateMap"};
// unit of beam energy: GeV // unit of beam energy: GeV
......
#include "GuineaPigPairsFileParser.h"
#include <sstream>
#include <cmath>
GuineaPigPairsFileParser::GuineaPigPairsFileParser(const std::string& filename) {
m_input.open(filename.c_str());
}
bool GuineaPigPairsFileParser::load(IBeamBackgroundFileParser::BeamBackgroundData& result) {
if (not m_input.good()) {
return false;
}
// read one record
std::string tmpline;
// the format
double energy; // unit: GeV
double vx; // unit: c
double vy; // unit: c
double vz; // unit: c
double x; // unit: nm
double y; // unit: nm
double z; // unit: nm
int process;
while(m_input.good()) {
std::getline(m_input, tmpline);
std::stringstream ss;
ss << tmpline;
ss >> energy; if (ss.fail()) { continue; }
ss >> vx; if (ss.fail()) { continue; }
ss >> vy; if (ss.fail()) { continue; }
ss >> vz; if (ss.fail()) { continue; }
ss >> x; if (ss.fail()) { continue; }
ss >> y; if (ss.fail()) { continue; }
ss >> z; if (ss.fail()) { continue; }
ss >> process; if (ss.fail()) { continue; }
int pdgid = 11; // 11: electron; -11: positron
if (energy<0) pdgid = -11;
double p = std::fabs(energy);
double v = sqrt(vx*vx+vy*vy+vz*vz);
// Now, we get a almost valid data
const double nm2mm = 1e-6; // convert from nm to mm
result.pdgid = pdgid;
result.x = x * nm2mm;
result.y = y * nm2mm;
result.z = z * nm2mm;
result.px = p * vx/v;
result.py = p * vy/v;
result.pz = p * vz/v;
result.mass = 0.000511; // assume e-/e+, mass is 0.511 MeV
return true;
}
return false;
}
#ifndef GuineaPigPairsFileParser_h
#define GuineaPigPairsFileParser_h
#include "IBeamBackgroundFileParser.h"
#include <fstream>
/* Format of Guinea-Pig Pairs:
*
* E vx vy vz x y z process
*
* Notes:
* - E (GeV). If E>0, it is electron. If E<0, it is positron
* - vx/vy/vz (speed of light)
* - x/y/z (nm)
* - process
* - 0: Breit-Wheeler
* - 1: Bethe-Heitler
* - 2: Landau-Lifschitz
*
*/
class GuineaPigPairsFileParser: public IBeamBackgroundFileParser {
public:
GuineaPigPairsFileParser(const std::string& filename);
bool load(IBeamBackgroundFileParser::BeamBackgroundData&);
private:
std::ifstream m_input;
};
#endif
...@@ -67,7 +67,7 @@ function run-job() { ...@@ -67,7 +67,7 @@ function run-job() {
# The current default platform # The current default platform
lcg_platform=x86_64-centos7-gcc8-opt lcg_platform=x86_64-centos7-gcc8-opt
lcg_version=101.0.0 lcg_version=101.0.1
bldtool=${CEPCSW_BLDTOOL} # make, ninja # set in env var bldtool=${CEPCSW_BLDTOOL} # make, ninja # set in env var
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment