9 #include <b2bii/modules/B2BIIMdstInput/B2BIIConvertBeamParamsModule.h>
10 #include <belle_legacy/benergy/BeamEnergy.h>
11 #include <belle_legacy/ip/IpProfile.h>
12 #include <belle_legacy/panther/panther.h>
13 #include <belle_legacy/tables/belletdf.h>
15 #include <framework/database/Database.h>
16 #include <framework/database/EventDependency.h>
17 #include <framework/database/IntervalOfValidity.h>
18 #include <framework/dbobjects/BeamParameters.h>
19 #include <framework/utilities/FileSystem.h>
20 #include <mdst/dbobjects/BeamSpot.h>
21 #include <mdst/dbobjects/CollisionBoostVector.h>
22 #include <mdst/dbobjects/CollisionInvariantMass.h>
30 int check_beginrun(
bool) {
return 0; }
37 return TVector3(point.x(), point.y(), point.z());
40 TMatrixDSym CLHEPtoROOT(
const HepSymMatrix& matrix)
42 TMatrixDSym result(matrix.num_col());
43 for (
int i = 0; i < matrix.num_row(); ++i) {
44 for (
int j = 0; j < matrix.num_col(); ++j) {
45 result(i, j) = matrix(i + 1, j + 1);
87 Belle::Belle_runhead_Manager& runMgr = Belle::Belle_runhead_Manager::get_manager();
89 Belle::Belle_runhead& runhead = runMgr[0];
91 runhead.ExpNo(
m_event->getExperiment());
92 runhead.RunNo(
m_event->getRun());
93 B2INFO(
"Obtaining values for exp " <<
m_event->getExperiment() <<
", run " <<
m_event->getRun());
95 Belle::BeamEnergy::flag_database(0);
96 Belle::IpProfile::begin_run();
97 Belle::Ip_profile_general_Manager& ipMgr = Belle::Ip_profile_general_Manager::get_manager();
99 if (!Belle::BeamEnergy::usable()) {
102 B2ERROR(
"No BeamEnergy for exp " <<
m_event->getExperiment() <<
", run " <<
m_event->getRun());
105 file <<
m_event->getExperiment() <<
"," <<
m_event->getRun() << std::endl;
110 const double Eher = Belle::BeamEnergy::E_HER();
111 const double Eler = Belle::BeamEnergy::E_LER();
112 const double crossingAngle = Belle::BeamEnergy::Cross_angle();
113 const double angleLer = M_PI;
114 const double angleHer = crossingAngle;
121 std::vector<double> covarianceHer = {0.00513 * 0.00513};
122 std::vector<double> covarianceLer = {0.002375 * 0.002375};
127 beamParams.
setLER(Eler, angleLer, 0, covarianceLer);
128 beamParams.
setHER(Eher, angleHer, 0, covarianceHer);
144 TLorentzVector cms = beamParams.
getLER() + beamParams.
getHER();
145 collisionBoostVector.
setBoost(cms.BoostVector(), TMatrixTSym<double>(3));
147 collisionInvM.
setMass(cms.M(), 0.0 , 0.0);
156 if (!Belle::IpProfile::usable()) {
159 B2ERROR(
"No IpProfile for exp " <<
m_event->getExperiment() <<
", run " <<
m_event->getRun());
161 std::ofstream file(
m_missingIp.c_str(), std::ios::app);
162 file <<
m_event->getExperiment() <<
"," <<
m_event->getRun() << std::endl;
164 std::vector<double> covariance;
166 std::numeric_limits<double>::quiet_NaN(),
167 std::numeric_limits<double>::quiet_NaN(),
168 std::numeric_limits<double>::quiet_NaN()), covariance);
174 TVector3(std::numeric_limits<double>::quiet_NaN(),
175 std::numeric_limits<double>::quiet_NaN(),
176 std::numeric_limits<double>::quiet_NaN()
177 ), TMatrixTSym<double>(3)
181 B2INFO(
"No IpProfile, created BeamSpot Payload");
186 int nbins = std::max(ipMgr.count() - 1, 1);
187 B2INFO(
"exp " <<
m_event->getExperiment() <<
", run " <<
m_event->getRun() <<
": " << nbins <<
" IpProfile bins");
190 std::list<BeamParameters> beamparamsList;
191 std::list<BeamSpot> beamspotList;
193 std::unique_ptr<EventDependency> beamparams;
194 std::unique_ptr<EventDependency> beamspots;
196 Belle::Belle_event_Manager& evtMgr = Belle::Belle_event_Manager::get_manager();
197 if (!evtMgr.count()) evtMgr.add();
198 for (
int i = 0; i < nbins; ++i) {
199 int evtNr = i * BIN_EVENTS;
201 Belle::Belle_event& evt = evtMgr[0];
203 evt.ExpNo(
m_event->getExperiment());
206 Belle::IpProfile::set_evtbin_number();
207 B2ASSERT(
"something wrong: " << Belle::IpProfile::EvtBinNo() <<
"!=" << i, Belle::IpProfile::EvtBinNo() == i);
210 HepPoint3D ip = Belle::IpProfile::e_position();
211 HepSymMatrix ipErr = Belle::IpProfile::e_position_err();
215 beamparamsList.emplace_back(beamParams);
218 beamSpot.
setIP(CLHEPtoROOT(ip), CLHEPtoROOT(ipErr));
219 beamspotList.emplace_back(beamSpot);
222 beamparams = std::make_unique<EventDependency>(&beamparamsList.back(),
false);
223 beamspots = std::make_unique<EventDependency>(&beamspotList.back(),
false);
225 beamparams->add(evtNr, &beamparamsList.back());
226 beamspots->add(evtNr, &beamspotList.back());
229 if (beamparamsList.size() < 1) {
230 B2ERROR(
"Something is wrong with exp " <<
m_event->getExperiment() <<
", run " <<
m_event->getRun() <<
": no bins found");
233 if (beamparamsList.size() == 1) {
239 B2INFO(
"Created event independent payload");
246 B2INFO(
"Created event dependent payload with " << beamparamsList.size() <<
" entries");
bool m_SmearDirection
Smear beam direction when generating initial events.
std::string m_missingBenergy
Where to store information about runs without beam energy information.
std::string m_missingIp
Where to store information about runs without IP profile information.
bool m_storeCollisionInvariantMass
Store the CollisionInvariantMass payloads in the localDB.
StoreObjPtr< EventMetaData > m_event
Event metadata.
bool m_SmearVertex
Smear vertex position when generating initial events.
bool m_storeBeamParameters
Store the BeamParameters payloads in the localDB.
bool m_GenerateCMS
Generate events in CMS, not lab system.
bool m_storeBeamSpot
Store the BeamSpot payloads in the localDB.
bool m_SmearEnergy
Smear energy when generating initial events.
bool m_storeCollisionBoostVector
Store the CollisionBoostVector payloads in the localDB.
int m_mcFlag
mcFlag to use when getting belle database content
This class contains the nominal beam parameters and the parameters used for smearing of the primary v...
void setHER(double energy, double angleX, double angleY, const std::vector< double > &cov)
Set the HER FourVector and error matrix from beam energy, angle and covariance entries.
void setLER(double energy, double angleX, double angleY, const std::vector< double > &cov)
Set the LER FourVector and error matrix from beam energy, angle and covariance entries.
void setVertex(const TVector3 &vertex, const std::vector< double > &cov)
Set the vertex position and error matrix.
void setCovVertex(const TMatrixDSym &cov)
Set the covariance matrix of the vertex position.
This class contains the beam spot position and size modeled as a gaussian distribution in space.
void setIP(const TVector3 &ipPosition, const TMatrixDSym &covariance)
Set the IP position and its error matrix.
This class contains the measured average boost vector vec(beta) = (beta_x, beta_y,...
void setBoost(const TVector3 &boost, const TMatrixDSym &covariance)
Set the boost vector and its error matrix.
This class contains the measured average center-of-mass energy, which is equal to the invariant mass ...
void setMass(double mass, double error, double spread)
Set the CMS energy and its uncertainty.
Helper class for locking a file.
bool lock(int timeout=300, bool ignoreErrors=false)
Try to lock the file.
A class that describes the interval of experiments/runs for which an object in the database is valid.
@ c_smearVertex
smear vertex
@ c_generateCMS
generate initial event in CMS instead of lab
@ c_smearBeamEnergy
smear energy of HER and LER (but not direction)
@ c_smearBeamDirection
smear direction of HER and LER (but not energy)
const TLorentzVector & getLER() const
Get 4vector of the low energy beam.
const TLorentzVector & getHER() const
Get 4vector of the high energy beam.
void setGenerationFlags(int flags)
Set the generation flags to be used for event generation (ORed combination of EGenerationFlags)
void initialize() override
Initialize phanter banks.
B2BIIConvertBeamParamsModule()
Create parameters.
void beginRun() override
Set run info in panther and load IPProfile/Benergy and convert the values to payloads.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
static Database & Instance()
Instance of a singleton Database.
bool storeData(const std::string &name, TObject *object, const IntervalOfValidity &iov)
Store an object in the database.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.