10#include <top/modules/TOPAligner/TOPAlignerModule.h>
13#include <top/geometry/TOPGeometryPar.h>
14#include <top/reconstruction_cpp/TOPTrack.h>
17#include <framework/logging/Logger.h>
53 "Module to be aligned. Must be 1 <= Mid <= 16.", 1);
55 "Maximum number of consecutive failed iterations before resetting the procedure", 100);
57 "sample type: one of dimuon, bhabha or cosmics", std::string(
"dimuon"));
59 "minimal track momentum if sample is cosmics", 1.0);
61 "c.m.s energy window (half size) if sample is dimuon or bhabha", 0.1);
65 "minimal local z of extrapolated hit", -130.0);
67 "maximal local z of extrapolated hit", 130.0);
69 "Root output file name containing alignment results",
70 std::string(
"TopAlignPars.root"));
79 "initial parameter values in the order [" + names +
"]. "
80 "If list is too short, the missing ones are set to 0.",
m_parInit);
83 "Valid names are: " + names, parFixed);
93 B2ERROR(
"Target module ID = " <<
m_targetMid <<
" is invalid.");
99 B2ERROR(
"Invalid sample type '" <<
m_sample <<
"'");
131 B2FATAL(
"Couldn't open file '" <<
m_outFileName <<
"' for writing!");
137 m_alignTree =
new TTree(
"alignTree",
"TOP alignment results");
170 if (not
m_recBunch->isReconstructed())
return;
175 for (
const auto& track :
m_tracks) {
179 if (not trk.
isValid())
continue;
197 B2INFO(
"Reached maximum allowed number of failed iterations. "
198 "Resetting TOPalign object");
213 m_x = localPosition.X();
214 m_y = localPosition.Y();
215 m_z = localPosition.Z();
217 m_p = localMomentum.R();
218 m_theta = localMomentum.Theta();
219 m_phi = localMomentum.Phi();
233 TString resMsg =
"M= ";
258 TH1F valid(
"valid",
"status valid", 16, 0.5, 16.5);
259 valid.SetXTitle(
"slot ID");
263 TH1F ntrk(
"ntrk",
"number of tracks", 16, 0.5, 16.5);
264 ntrk.SetXTitle(
"slot ID");
268 std::string name, title;
270 title =
"alignment parameters, slot " + to_string(
m_targetMid);
272 TH1F h0(name.c_str(), title.c_str(), npar, 0, npar);
275 for (
int i = 0; i < npar; i++) {
276 h0.SetBinContent(i + 1, par[i]);
277 h0.SetBinError(i + 1, err[i]);
282 title =
"error matrix, slot " + to_string(
m_targetMid);
283 TH2F h1(name.c_str(), title.c_str(), npar, 0, npar, npar, 0, npar);
285 for (
int i = 0; i < npar; i++) {
286 for (
int k = 0; k < npar; k++) {
287 h1.SetBinContent(i + 1, k + 1, errMatrix[i][k]);
293 title =
"correlation matrix, slot " + to_string(
m_targetMid);
294 TH2F h2(name.c_str(), title.c_str(), npar, 0, npar, npar, 0, npar);
295 std::vector<double> diag;
296 for (
int i = 0; i < npar; i++) {
297 double d = errMatrix[i][i];
298 if (d != 0) d = 1.0 /
sqrt(d);
301 for (
int i = 0; i < npar; i++) {
302 for (
int k = 0; k < npar; k++) {
303 h2.SetBinContent(i + 1, k + 1, diag[i] * diag[k] * errMatrix[i][k]);
311 B2RESULT(
"TOPAligner: slot = " <<
m_targetMid <<
", status = successful, "
312 <<
"iterations = " <<
m_iter <<
", tracks used = " <<
m_ntrk);
314 B2RESULT(
"TOPAligner: slot = " <<
m_targetMid <<
", status = failed, "
316 <<
", iterations = " <<
m_iter <<
", tracks used = " <<
m_ntrk);
static const ChargedStable electron
electron particle
void setDescription(const std::string &description)
Sets the description of the module.
std::vector< float > m_vAlignParsErr
error on alignment parameters
Const::ChargedStable m_chargedStable
track hypothesis
StoreObjPtr< TOPRecBunch > m_recBunch
reconstructed bunch
TOP::TrackSelector m_selector
track selection utility
int m_PDG
track MC truth (simulated data only)
float m_phi
track: extrapolated hit momentum in local (module) frame
double m_minMomentum
minimal track momentum if sample is "cosmics"
std::vector< float > m_vAlignPars
alignment parameters
double m_dz
cut on POCA in z
std::vector< std::string > m_parFixed
names of parameters to be fixed
double m_stepTime
step size for t0
int m_targetMid
target module to align.
TOP::ModuleAlignment m_align
alignment object
double m_maxZ
maximal local z of extrapolated hit
int m_countFails
counter for failed iterations
int m_iter
iteration counter
double m_stepPosition
step size for translations
double m_minZ
minimal local z of extrapolated hit
float m_p
track: extrapolated hit momentum in local (module) frame
bool m_valid
true if alignment parameters are valid
double m_dr
cut on POCA in r
StoreArray< Track > m_tracks
collection of tracks
int m_errorCode
error code of the alignment procedure
double m_stepAngle
step size for rotations
std::vector< double > m_parInit
initial parameter values
double m_deltaEcms
c.m.s energy window if sample is "dimuon" or "bhabha"
int m_maxFails
maximum allowed number of failed iterations
int m_numPhot
number of photons used for log likelihood in this iteration
float m_y
track: extrapolated hit coordinate in local (module) frame
StoreArray< TOPDigit > m_digits
collection of digits
StoreArray< ExtHit > m_extHits
collection of extrapolated hits
TTree * m_alignTree
TTree containing alignment parameters.
std::string m_outFileName
Root output file name containing results.
float m_z
track: extrapolated hit coordinate in local (module) frame
float m_x
track: extrapolated hit coordinate in local (module) frame
std::string m_sample
sample type
int m_ntrk
number of tracks used
float m_theta
track: extrapolated hit momentum in local (module) frame
int getNumUsedTracks() const
Returns number of tracks used in current result.
const std::vector< double > & getParams() const
Returns alignment parameters.
void setModuleID(int moduleID)
Sets module ID.
bool isValid() const
Checks if the results are valid.
void fixParameter(const std::string &name)
Fixes parameter with its name given as argument.
void setParameters(const std::vector< double > &parInit)
Sets initial values of parameters (overwrites current parameters!) Order is: translations in x,...
std::vector< float > getParameters() const
Returns alignment parameters.
int getModuleID() const
Returns module ID.
const std::vector< std::string > & getParameterNames() const
Returns alignment parameter names.
void setSteps(double position, double angle, double time)
Sets steps for numerical calculation of derivatives.
const TMatrixDSym & getErrorMatrix() const
Returns error matrix of alignment parameters Order is: translations in x, y, z, rotation angles aroun...
int iterate(TOPTrack &track, const Const::ChargedStable &hypothesis)
Run a single alignment iteration, on success update alignment parameters.
std::vector< float > getErrors() const
Returns errors on alignment parameters.
void reset()
Reset the object.
int getNumOfPhotons() const
Returns number of photons used for log likelihood calculation.
const TOPGeometry * getGeometry() const
Returns pointer to geometry object using basf2 units.
static TOPGeometryPar * Instance()
Static method to obtain the pointer to its instance.
Reconstructed track at TOP.
int getPDGCode() const
Returns PDG code of associated MCParticle (returns 0 if none)
double getCharge() const
Returns charge.
bool isValid() const
Checks if track is successfully constructed.
int getModuleID() const
Returns slot ID.
Utility for the track selection - used in various calibration modules.
double getCMSEnergy() const
Returns c.m.s energy of the track in last isSelected call.
const ROOT::Math::XYZPoint & getLocalPosition() const
Returns position at TOP in local frame of the track in last isSelected call.
void setDeltaEcms(double deltaEcms)
Sets cut on c.m.s.
void setMinMomentum(double minMomentum)
Sets momentum cut (used for "cosmics" only)
void setCutOnPOCA(double dr, double dz)
Sets cut on point of closest approach to (0, 0, 0)
const ROOT::Math::XYZVector & getPOCAPosition() const
Returns position of POCA of the track in last isSelected call.
bool isSelected(const TOPTrack &track) const
Returns selection status.
const ROOT::Math::XYZVector & getLocalMomentum() const
Returns momentum at TOP in local frame of the track in last isSelected call.
void setCutOnLocalZ(double minZ, double maxZ)
Sets cut on local z coordinate (module frame) of the track extrapolated to TOP.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
double sqrt(double a)
sqrt for double
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
virtual void terminate() override
Termination action.
TOPAlignerModule()
Constructor.
Abstract base class for different kinds of events.