Belle II Software light-2406-ragdoll
BeamParametersFitter Class Reference

Fitter calculating BeamParameters from CollisionBoostVector and CollisionInvariantMass. More...

#include <BeamParametersFitter.h>

Collaboration diagram for BeamParametersFitter:

Public Member Functions

 BeamParametersFitter ()
 Constructor.
 
 ~BeamParametersFitter ()
 Destructor.
 
void setIntervalOfValidity (const IntervalOfValidity &iov)
 Set interval of validity.
 
void setAngleHER (double angleHER)
 Set HER angle.
 
void setAngleLER (double angleLER)
 Set LER angle.
 
void setAngleError (double angleError)
 Set angle error.
 
void setBoostError (double boostError)
 Set boost error.
 
void setInvariantMassError (double invariantMassError)
 Set invariant-mass error.
 
void setVerbose (bool verbose)
 Set whether to be verbose (print Minuit output).
 
BeamParameters getBeamParameters () const
 Get beam parameters.
 
void setBeamParameters (const BeamParameters *beamParameters)
 Set beam parameters.
 
void fit ()
 Perform the fit.
 
void fillVertexData (double covarianceXX, double covarianceYY)
 Fill beam spot (vertex) data.
 
void importBeamParameters ()
 Import beam parameters.
 

Protected Member Functions

void setupDatabase ()
 Setup database.
 

Protected Attributes

IntervalOfValidity m_IntervalOfValidity
 Interval of validity.
 
double m_AngleHER = 0
 HER angle.
 
double m_AngleLER = 0
 LER angle.
 
double m_AngleError = 0
 Angle error.
 
double m_BoostError = 0.0001
 Boost error (use only if inverse error matrix is not available).
 
double m_InvariantMassError = 0.0001
 Invariant-mass error (use only if error is 0).
 
bool m_Verbose = false
 Whether to be verbose (print Minuit output).
 
BeamParameters m_BeamParameters
 Beam parameters.
 
DBObjPtr< BeamSpotm_BeamSpot
 Beam spot.
 
DBObjPtr< CollisionBoostVectorm_CollisionBoostVector
 Collision boost vector.
 
DBObjPtr< CollisionInvariantMassm_CollisionInvariantMass
 Collision invariant mass.
 

Detailed Description

Fitter calculating BeamParameters from CollisionBoostVector and CollisionInvariantMass.

Definition at line 31 of file BeamParametersFitter.h.

Constructor & Destructor Documentation

◆ BeamParametersFitter()

Constructor.

Definition at line 38 of file BeamParametersFitter.h.

39 {
40 }

◆ ~BeamParametersFitter()

~BeamParametersFitter ( )
inline

Destructor.

Definition at line 45 of file BeamParametersFitter.h.

46 {
47 }

Member Function Documentation

◆ fillVertexData()

void fillVertexData ( double  covarianceXX,
double  covarianceYY 
)

Fill beam spot (vertex) data.

The covariance matrix is rescaled to nominal XX and YY covariances. If covariances are negative, then no rescaling is performed.

Parameters
[in]covarianceXXCovariance-matrix XX element.
[in]covarianceYYCovariance-matrix YY element.

Definition at line 296 of file BeamParametersFitter.cc.

298{
300 m_BeamParameters.setVertex(ROOT::Math::XYZVector(m_BeamSpot->getIPPosition()));
301 TMatrixDSym beamSize = m_BeamSpot->getSizeCovMatrix();
302 double xScale, yScale;
303 if (covarianceXX < 0)
304 xScale = 1;
305 else
306 xScale = sqrt(covarianceXX / beamSize[0][0]);
307 if (covarianceYY < 0)
308 yScale = 1;
309 else
310 yScale = sqrt(covarianceYY / beamSize[1][1]);
311 for (int i = 0; i < 3; ++i) {
312 beamSize[0][i] *= xScale;
313 beamSize[i][0] *= xScale;
314 beamSize[1][i] *= yScale;
315 beamSize[i][1] *= yScale;
316 }
318}
BeamParameters m_BeamParameters
Beam parameters.
void setupDatabase()
Setup database.
DBObjPtr< BeamSpot > m_BeamSpot
Beam spot.
void setVertex(const ROOT::Math::XYZVector &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.

◆ fit()

void fit ( )

Perform the fit.

Definition at line 190 of file BeamParametersFitter.cc.

191{
192 int minuitResult;
194 /* Get p_HER and p_LER from a fit. */
195 double herMomentum, herThetaX, herThetaY;
196 double lerMomentum, lerThetaX, lerThetaY;
197 s_BoostVector = m_CollisionBoostVector->getBoost();
198 s_BoostVectorInverseCovariance = m_CollisionBoostVector->getBoostCovariance();
199 if (s_BoostVectorInverseCovariance.Determinant() == 0) {
200 B2WARNING("Determinant of boost covariance matrix is 0, "
201 "using generic inverse covariance matrix for fit.");
202 s_BoostVectorInverseCovariance[0][0] = 1.0 / (m_BoostError * m_BoostError);
203 s_BoostVectorInverseCovariance[0][1] = 0;
204 s_BoostVectorInverseCovariance[0][2] = 0;
205 s_BoostVectorInverseCovariance[1][0] = 0;
206 s_BoostVectorInverseCovariance[1][1] = 1.0 / (m_BoostError * m_BoostError);
207 s_BoostVectorInverseCovariance[1][2] = 0;
208 s_BoostVectorInverseCovariance[2][0] = 0;
209 s_BoostVectorInverseCovariance[2][1] = 0;
210 s_BoostVectorInverseCovariance[2][2] = 1.0 / (m_BoostError * m_BoostError);
211 } else {
212 s_BoostVectorInverseCovariance.Invert();
213 }
214 s_InvariantMass = m_CollisionInvariantMass->getMass();
215 s_InvariantMassError = m_CollisionInvariantMass->getMassError();
216 if (s_InvariantMassError == 0) {
217 B2WARNING("Invariant-mass errror is 0, using generic error for fit.");
218 s_InvariantMassError = m_InvariantMassError;
219 }
220 s_DirectionHER.SetX(0);
221 s_DirectionHER.SetY(0);
222 s_DirectionHER.SetZ(1);
223 s_DirectionHER.RotateY(m_AngleHER);
224 s_DirectionLER.SetX(0);
225 s_DirectionLER.SetY(0);
226 s_DirectionLER.SetZ(1);
227 s_DirectionLER.RotateY(m_AngleLER + M_PI);
228 s_AngleError = m_AngleError;
229 TMinuit minuit(6);
230 if (!m_Verbose)
231 minuit.SetPrintLevel(-1);
232 minuit.SetFCN(fcn);
233 minuit.mnparm(0, "PHER_E", 7, 0.01, 0, 0, minuitResult);
234 minuit.mnparm(1, "PHER_TX", 0, 0.01, 0, 0, minuitResult);
235 minuit.mnparm(2, "PHER_TY", 0, 0.01, 0, 0, minuitResult);
236 minuit.mnparm(3, "PLER_E", 4, 0.01, 0, 0, minuitResult);
237 minuit.mnparm(4, "PLER_TX", 0, 0.01, 0, 0, minuitResult);
238 minuit.mnparm(5, "PLER_TY", 0, 0.01, 0, 0, minuitResult);
239 minuit.mncomd("FIX 2 3 5 6", minuitResult);
240 minuit.mncomd("MIGRAD 10000", minuitResult);
241 minuit.mncomd("RELEASE 2 3 5 6", minuitResult);
242 minuit.mncomd("MIGRAD 10000", minuitResult);
243 double error;
244 minuit.GetParameter(0, herMomentum, error);
245 minuit.GetParameter(1, herThetaX, error);
246 minuit.GetParameter(2, herThetaY, error);
247 minuit.GetParameter(3, lerMomentum, error);
248 minuit.GetParameter(4, lerThetaX, error);
249 minuit.GetParameter(5, lerThetaY, error);
250 /* Calculate error. */
251 ROOT::Math::PxPyPzEVector pHER = getMomentum(herMomentum, herThetaX, herThetaY, false);
252 ROOT::Math::PxPyPzEVector pLER = getMomentum(lerMomentum, lerThetaX, lerThetaY, true);
253 ROOT::Math::PxPyPzEVector pBeam = pHER + pLER;
254 double fittedInvariantMass = pBeam.M();
255 B2RESULT("Initial invariant mass: " << s_InvariantMass <<
256 "; fitted invariant mass: " << fittedInvariantMass);
257 double cosThetaX = cos(herThetaX);
258 double sinThetaX = sin(herThetaX);
259 double cosThetaY = cos(herThetaY);
260 double sinThetaY = sin(herThetaY);
261 double herPartial =
262 (pBeam.E() - pHER.E() / pHER.P() *
263 (pBeam.Px() * cosThetaX * sinThetaY - pBeam.Py() * sinThetaX +
264 pBeam.Pz() * cosThetaX * cosThetaY)) / fittedInvariantMass;
265 cosThetaX = cos(lerThetaX);
266 sinThetaX = sin(lerThetaX);
267 cosThetaY = cos(lerThetaY + M_PI);
268 sinThetaY = sin(lerThetaY + M_PI);
269 double lerPartial =
270 (pBeam.E() - pLER.E() / pLER.P() *
271 (pBeam.Px() * cosThetaX * sinThetaY - pBeam.Py() * sinThetaX +
272 pBeam.Pz() * cosThetaX * cosThetaY)) / fittedInvariantMass;
273 double sigmaInvariantMass = m_CollisionInvariantMass->getMassSpread();
274 double k = sqrt(sigmaInvariantMass * sigmaInvariantMass /
275 (pow(herPartial * pHER.E(), 2) +
276 pow(lerPartial * pLER.E(), 2)));
277 double herSpread = k * pHER.E();
278 double lerSpread = k * pLER.E();
279 B2INFO("Invariant mass spread: " << sigmaInvariantMass);
280 B2RESULT("HER energy spread: " << herSpread <<
281 "; LER energy spread: " << lerSpread);
282 /* Fill beam parameters. */
285 TMatrixDSym covariance(3);
286 for (int i = 0; i < 3; ++i) {
287 for (int j = 0; j < 3; ++j)
288 covariance[i][j] = 0;
289 }
290 covariance[0][0] = herSpread * herSpread;
291 m_BeamParameters.setCovHER(covariance);
292 covariance[0][0] = lerSpread * lerSpread;
293 m_BeamParameters.setCovLER(covariance);
294}
double m_InvariantMassError
Invariant-mass error (use only if error is 0).
DBObjPtr< CollisionBoostVector > m_CollisionBoostVector
Collision boost vector.
bool m_Verbose
Whether to be verbose (print Minuit output).
DBObjPtr< CollisionInvariantMass > m_CollisionInvariantMass
Collision invariant mass.
double m_BoostError
Boost error (use only if inverse error matrix is not available).
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 setCovLER(const TMatrixDSym &cov)
Set the covariance matrix for LER (E, theta_x, theta_y) where E is the energy, theta_x is the horizon...
void setCovHER(const TMatrixDSym &cov)
Set the covariance matrix for HER (E, theta_x, theta_y) where E is the energy, theta_x is the horizon...

◆ getBeamParameters()

BeamParameters getBeamParameters ( ) const
inline

Get beam parameters.

Definition at line 108 of file BeamParametersFitter.h.

109 {
110 return m_BeamParameters;
111 }

◆ importBeamParameters()

void importBeamParameters ( )

Import beam parameters.

Definition at line 320 of file BeamParametersFitter.cc.

321{
322 DBImportObjPtr<BeamParameters> beamParametersImport;
323 beamParametersImport.construct(m_BeamParameters);
324 beamParametersImport.import(m_IntervalOfValidity);
325}
IntervalOfValidity m_IntervalOfValidity
Interval of validity.
bool import(const IntervalOfValidity &iov)
Import the object to database.
Definition: DBImportBase.cc:36
Class for importing a single object to the database.
void construct(Args &&... params)
Construct an object of type T in this DBImportObjPtr using the provided constructor arguments.

◆ setAngleError()

void setAngleError ( double  angleError)
inline

Set angle error.

Definition at line 76 of file BeamParametersFitter.h.

77 {
78 m_AngleError = angleError;
79 }

◆ setAngleHER()

void setAngleHER ( double  angleHER)
inline

Set HER angle.

Definition at line 60 of file BeamParametersFitter.h.

61 {
62 m_AngleHER = angleHER;
63 }

◆ setAngleLER()

void setAngleLER ( double  angleLER)
inline

Set LER angle.

Definition at line 68 of file BeamParametersFitter.h.

69 {
70 m_AngleLER = angleLER;
71 }

◆ setBeamParameters()

void setBeamParameters ( const BeamParameters beamParameters)
inline

Set beam parameters.

Definition at line 116 of file BeamParametersFitter.h.

117 {
118 m_BeamParameters = *beamParameters;
119 }

◆ setBoostError()

void setBoostError ( double  boostError)
inline

Set boost error.

Definition at line 84 of file BeamParametersFitter.h.

85 {
86 m_BoostError = boostError;
87 }

◆ setIntervalOfValidity()

void setIntervalOfValidity ( const IntervalOfValidity iov)
inline

Set interval of validity.

Definition at line 52 of file BeamParametersFitter.h.

53 {
55 }

◆ setInvariantMassError()

void setInvariantMassError ( double  invariantMassError)
inline

Set invariant-mass error.

Definition at line 92 of file BeamParametersFitter.h.

93 {
94 m_InvariantMassError = invariantMassError;
95 }

◆ setupDatabase()

void setupDatabase ( )
protected

Setup database.

Definition at line 97 of file BeamParametersFitter.cc.

98{
99 /* DataStore. */
101 StoreObjPtr<EventMetaData> eventMetaData;
102 eventMetaData.registerInDataStore();
104 /* Database. */
105 if (eventMetaData.isValid()) {
106 eventMetaData->setExperiment(m_IntervalOfValidity.getExperimentLow());
107 eventMetaData->setRun(m_IntervalOfValidity.getRunLow());
108 } else {
109 eventMetaData.construct(1, m_IntervalOfValidity.getRunLow(),
111 }
112 DBStore& dbStore = DBStore::Instance();
113 dbStore.update();
114 dbStore.updateEvent();
115}
Singleton class to cache database objects.
Definition: DBStore.h:31
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
void setInitializeActive(bool active)
Setter for m_initializeActive.
Definition: DataStore.cc:94
int getRunLow() const
Getter for lowest run number.
int getExperimentLow() const
Getter for lowest experiment number.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:111
bool construct(Args &&... params)
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments.
Definition: StoreObjPtr.h:119
static DBStore & Instance()
Instance of a singleton DBStore.
Definition: DBStore.cc:28
void updateEvent()
Updates all intra-run dependent objects.
Definition: DBStore.cc:142
void update()
Updates all objects that are outside their interval of validity.
Definition: DBStore.cc:79

◆ setVerbose()

void setVerbose ( bool  verbose)
inline

Set whether to be verbose (print Minuit output).

Definition at line 100 of file BeamParametersFitter.h.

101 {
102 m_Verbose = verbose;
103 }

Member Data Documentation

◆ m_AngleError

double m_AngleError = 0
protected

Angle error.

Definition at line 157 of file BeamParametersFitter.h.

◆ m_AngleHER

double m_AngleHER = 0
protected

HER angle.

Definition at line 151 of file BeamParametersFitter.h.

◆ m_AngleLER

double m_AngleLER = 0
protected

LER angle.

Definition at line 154 of file BeamParametersFitter.h.

◆ m_BeamParameters

BeamParameters m_BeamParameters
protected

Beam parameters.

Definition at line 169 of file BeamParametersFitter.h.

◆ m_BeamSpot

DBObjPtr<BeamSpot> m_BeamSpot
protected

Beam spot.

Definition at line 172 of file BeamParametersFitter.h.

◆ m_BoostError

double m_BoostError = 0.0001
protected

Boost error (use only if inverse error matrix is not available).

Definition at line 160 of file BeamParametersFitter.h.

◆ m_CollisionBoostVector

DBObjPtr<CollisionBoostVector> m_CollisionBoostVector
protected

Collision boost vector.

Definition at line 175 of file BeamParametersFitter.h.

◆ m_CollisionInvariantMass

DBObjPtr<CollisionInvariantMass> m_CollisionInvariantMass
protected

Collision invariant mass.

Definition at line 178 of file BeamParametersFitter.h.

◆ m_IntervalOfValidity

IntervalOfValidity m_IntervalOfValidity
protected

Interval of validity.

Definition at line 148 of file BeamParametersFitter.h.

◆ m_InvariantMassError

double m_InvariantMassError = 0.0001
protected

Invariant-mass error (use only if error is 0).

Definition at line 163 of file BeamParametersFitter.h.

◆ m_Verbose

bool m_Verbose = false
protected

Whether to be verbose (print Minuit output).

Definition at line 166 of file BeamParametersFitter.h.


The documentation for this class was generated from the following files: