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/geometry/B2Vector3.h>
20 #include <framework/utilities/FileSystem.h>
21 #include <mdst/dbobjects/BeamSpot.h>
22 #include <mdst/dbobjects/CollisionBoostVector.h>
23 #include <mdst/dbobjects/CollisionInvariantMass.h>
31 int check_beginrun(
bool) {
return 0; }
38 return TVector3(point.x(), point.y(), point.z());
41 TMatrixDSym CLHEPtoROOT(
const HepSymMatrix& matrix)
43 TMatrixDSym result(matrix.num_col());
44 for (
int i = 0; i < matrix.num_row(); ++i) {
45 for (
int j = 0; j < matrix.num_col(); ++j) {
46 result(i, j) = matrix(i + 1, j + 1);
88 Belle::Belle_runhead_Manager& runMgr = Belle::Belle_runhead_Manager::get_manager();
90 Belle::Belle_runhead& runhead = runMgr[0];
92 runhead.ExpNo(
m_event->getExperiment());
93 runhead.RunNo(
m_event->getRun());
94 B2INFO(
"Obtaining values for exp " <<
m_event->getExperiment() <<
", run " <<
m_event->getRun());
96 Belle::BeamEnergy::flag_database(0);
97 Belle::IpProfile::begin_run();
98 Belle::Ip_profile_general_Manager& ipMgr = Belle::Ip_profile_general_Manager::get_manager();
100 if (!Belle::BeamEnergy::usable()) {
103 B2ERROR(
"No BeamEnergy for exp " <<
m_event->getExperiment() <<
", run " <<
m_event->getRun());
106 file <<
m_event->getExperiment() <<
"," <<
m_event->getRun() << std::endl;
111 const double Eher = Belle::BeamEnergy::E_HER();
112 const double Eler = Belle::BeamEnergy::E_LER();
113 const double crossingAngle = Belle::BeamEnergy::Cross_angle();
114 const double angleLer = M_PI;
115 const double angleHer = crossingAngle;
122 std::vector<double> covarianceHer = {0.00513 * 0.00513};
123 std::vector<double> covarianceLer = {0.002375 * 0.002375};
128 beamParams.
setLER(Eler, angleLer, 0, covarianceLer);
129 beamParams.
setHER(Eher, angleHer, 0, covarianceHer);
145 ROOT::Math::PxPyPzEVector cms = beamParams.
getLER() + beamParams.
getHER();
148 collisionInvM.
setMass(cms.M(), 0.0, 0.0);
157 if (!Belle::IpProfile::usable()) {
160 B2ERROR(
"No IpProfile for exp " <<
m_event->getExperiment() <<
", run " <<
m_event->getRun());
162 std::ofstream file(
m_missingIp.c_str(), std::ios::app);
163 file <<
m_event->getExperiment() <<
"," <<
m_event->getRun() << std::endl;
165 std::vector<double> covariance;
166 beamParams.
setVertex(ROOT::Math::XYZVector(
167 std::numeric_limits<double>::quiet_NaN(),
168 std::numeric_limits<double>::quiet_NaN(),
169 std::numeric_limits<double>::quiet_NaN()), covariance);
175 TVector3(std::numeric_limits<double>::quiet_NaN(),
176 std::numeric_limits<double>::quiet_NaN(),
177 std::numeric_limits<double>::quiet_NaN()
178 ), TMatrixTSym<double>(3)
182 B2INFO(
"No IpProfile, created BeamSpot Payload");
187 int nbins = std::max(ipMgr.count() - 1, 1);
188 B2INFO(
"exp " <<
m_event->getExperiment() <<
", run " <<
m_event->getRun() <<
": " << nbins <<
" IpProfile bins");
191 std::list<BeamParameters> beamparamsList;
192 std::list<BeamSpot> beamspotList;
194 std::unique_ptr<EventDependency> beamparams;
195 std::unique_ptr<EventDependency> beamspots;
197 Belle::Belle_event_Manager& evtMgr = Belle::Belle_event_Manager::get_manager();
198 if (!evtMgr.count()) evtMgr.add();
199 for (
int i = 0; i < nbins; ++i) {
200 int evtNr = i * BIN_EVENTS;
202 Belle::Belle_event& evt = evtMgr[0];
204 evt.ExpNo(
m_event->getExperiment());
207 Belle::IpProfile::set_evtbin_number();
208 B2ASSERT(
"something wrong: " << Belle::IpProfile::EvtBinNo() <<
"!=" << i, Belle::IpProfile::EvtBinNo() == i);
211 HepPoint3D ip = Belle::IpProfile::e_position();
212 HepSymMatrix ipErr = Belle::IpProfile::e_position_err();
214 beamParams.
setVertex(ROOT::Math::XYZVector(ip.x(), ip.y(), ip.z()));
216 beamparamsList.emplace_back(beamParams);
219 beamSpot.
setIP(CLHEPtoROOT(ip), CLHEPtoROOT(ipErr));
220 beamspotList.emplace_back(beamSpot);
223 beamparams = std::make_unique<EventDependency>(&beamparamsList.back(),
false);
224 beamspots = std::make_unique<EventDependency>(&beamspotList.back(),
false);
226 beamparams->add(evtNr, &beamparamsList.back());
227 beamspots->add(evtNr, &beamspotList.back());
230 if (beamparamsList.size() < 1) {
231 B2ERROR(
"Something is wrong with exp " <<
m_event->getExperiment() <<
", run " <<
m_event->getRun() <<
": no bins found");
234 if (beamparamsList.size() == 1) {
240 B2INFO(
"Created event independent payload");
247 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 ROOT::Math::XYZVector &vertex, const std::vector< double > &cov)
Set the vertex position and error matrix.
void setGenerationFlags(int flags) override
Set the generation flags to be used for event generation (ORed combination of EGenerationFlags).
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.
const ROOT::Math::PxPyPzEVector & getLER() const
Get 4vector of the low energy beam.
const ROOT::Math::PxPyPzEVector & getHER() const
Get 4vector of the high energy beam.
@ 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)
REG_MODULE(arichBtest)
Register the Module.
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.
B2Vector3< double > B2Vector3D
typedef for common usage with double
Abstract base class for different kinds of events.