9#include <top/modules/collectors/TOPAlignmentCollectorModule.h>
10#include <top/geometry/TOPGeometryPar.h>
11#include <top/reconstruction_cpp/TOPTrack.h>
14#include <framework/logging/Logger.h>
45 setDescription(
"A collector for geometrical alignment of a TOP module with dimuons or Bhabhas. Iterative alignment procedure (NIMA 876 (2017) 260-264) is run here, algorithm just collects the results.");
50 "Module to be aligned. Must be 1 <= Mid <= 16.");
52 "Maximum number of consecutive failed iterations before resetting the procedure", 100);
54 "sample type: one of dimuon or bhabha", std::string(
"dimuon"));
56 "c.m.s energy window (half size) if sample is dimuon or bhabha", 0.1);
59 addParam(
"minZ",
m_minZ,
"minimal local z of extrapolated hit", -130.0);
60 addParam(
"maxZ",
m_maxZ,
"maximal local z of extrapolated hit", 130.0);
66 for (
const auto& parName : align.getParameterNames()) names += parName +
", ";
70 "initial parameter values in the order [" + names +
"]. "
71 "If list is too short, the missing ones are set to 0.",
m_parInit);
74 "Valid names are: " + names, parFixed);
92 B2FATAL(
"Target module ID = " <<
m_targetMid <<
" is invalid. Exiting...");
103 B2ERROR(
"Invalid sample type '" <<
m_sample <<
"'");
108 for (
int set = 0; set <
c_numSets; set++) {
114 align.fixParameter(parName);
122 int numModules = geo->getNumModules();
123 auto h1 =
new TH2F(
"tracks_per_slot",
"Number of tracks per slot and sample",
125 h1->SetXTitle(
"slot number");
126 h1->SetYTitle(
"sample number");
127 registerObject<TH2F>(
"tracks_per_slot", h1);
129 for (
int slot = 1; slot <= numModules; slot++) {
130 std::string slotName =
"_s" + to_string(slot);
131 std::string slotTitle =
"(slot " + to_string(slot) +
")";
133 std::string hname =
"local_z" + slotName;
134 std::string title =
"Distribution of tracks along bar " + slotTitle;
135 auto h2 =
new TH1F(hname.c_str(), title.c_str(), 100, -150.0, 150.0);
136 h2->SetXTitle(
"local z [cm]");
137 registerObject<TH1F>(hname, h2);
139 hname =
"cth_vs_p" + slotName;
140 title =
"Track momentum " + slotTitle;
141 auto h3 =
new TH2F(hname.c_str(), title.c_str(), 100, 0.0, 7.0, 100, -1.0, 1.0);
142 h3->SetXTitle(
"p [GeV/c]");
143 h3->SetYTitle(
"cos #theta");
144 registerObject<TH2F>(hname, h3);
146 hname =
"poca_xy" + slotName;
147 title =
"Track POCA in x-y " + slotTitle;
148 auto h4 =
new TH2F(hname.c_str(), title.c_str(), 100, -
m_dr,
m_dr, 100, -
m_dr,
m_dr);
149 h4->SetXTitle(
"x [cm]");
150 h4->SetYTitle(
"y [cm]");
151 registerObject<TH2F>(hname, h4);
153 hname =
"poca_z" + slotName;
154 title =
"Track POCA in z " + slotTitle;
155 auto h5 =
new TH1F(hname.c_str(), title.c_str(), 100, -
m_dz,
m_dz);
156 h5->SetXTitle(
"z [cm]");
157 registerObject<TH1F>(hname, h5);
159 hname =
"Ecms" + slotName;
160 title =
"Track c.m.s. energy " + slotTitle;
161 auto h6 =
new TH1F(hname.c_str(), title.c_str(), 100, 5.1, 5.4);
162 h6->SetXTitle(
"E_{cms} [GeV]");
163 registerObject<TH1F>(hname, h6);
165 hname =
"charge" + slotName;
166 title =
"Charge of track " + slotTitle;
167 auto h7 =
new TH1F(hname.c_str(), title.c_str(), 3, -1.5, 1.5);
168 h7->SetXTitle(
"charge");
169 registerObject<TH1F>(hname, h7);
171 hname =
"timeHits" + slotName;
172 title =
"Photon time distribution " + slotTitle;
173 auto h8 =
new TH2F(hname.c_str(), title.c_str(), 512, 0, 512, 200, 0, 50);
174 h8->SetXTitle(
"channel number");
175 h8->SetYTitle(
"time [ns]");
176 registerObject<TH2F>(hname, h8);
178 hname =
"numPhot" + slotName;
179 title =
"Number of photons " + slotTitle;
180 auto h9 =
new TH1F(hname.c_str(), title.c_str(), 100, 0, 100);
181 h9->SetXTitle(
"photons per track");
182 registerObject<TH1F>(hname, h9);
185 for (
int set = 0; set <
c_numSets; set++) {
186 std::string name =
"alignTree" + to_string(set);
188 auto alignTree =
new TTree(name.c_str(),
"TOP alignment results");
190 alignTree->Branch(
"iter", &
m_iter);
191 alignTree->Branch(
"ntrk", &
m_ntrk);
195 alignTree->Branch(
"valid", &
m_valid);
196 alignTree->Branch(
"numPhot", &
m_numPhot);
197 alignTree->Branch(
"x", &
m_x);
198 alignTree->Branch(
"y", &
m_y);
199 alignTree->Branch(
"z", &
m_z);
200 alignTree->Branch(
"p", &
m_p);
201 alignTree->Branch(
"theta", &
m_theta);
202 alignTree->Branch(
"phi", &
m_phi);
203 alignTree->Branch(
"r_poca", &
m_pocaR);
204 alignTree->Branch(
"z_poca", &
m_pocaZ);
205 alignTree->Branch(
"x_poca", &
m_pocaX);
206 alignTree->Branch(
"y_poca", &
m_pocaY);
207 alignTree->Branch(
"Ecms", &
m_cmsE);
208 alignTree->Branch(
"charge", &
m_charge);
209 alignTree->Branch(
"PDG", &
m_PDG);
210 registerObject<TTree>(name, alignTree);
221 if (not
m_recBunch->isReconstructed())
return;
225 for (
const auto& track :
m_tracks) {
229 if (not trk.
isValid())
continue;
242 auto h1 = getObjectPtr<TH2F>(
"tracks_per_slot");
255 B2INFO(
"Reached maximum allowed number of failed iterations. "
256 "Resetting TOPalign object of set = " << sub <<
" at iter = " <<
m_iter);
264 m_ntrk = align.getNumUsedTracks();
271 m_x = localPosition.X();
272 m_y = localPosition.Y();
273 m_z = localPosition.Z();
275 m_p = localMomentum.R();
276 m_theta = localMomentum.Theta();
277 m_phi = localMomentum.Phi();
288 auto alignTree = getObjectPtr<TTree>(name);
292 std::string slotName =
"_s" + to_string(
m_targetMid);
293 auto h2 = getObjectPtr<TH1F>(
"local_z" + slotName);
295 auto h3 = getObjectPtr<TH2F>(
"cth_vs_p" + slotName);
297 auto h4 = getObjectPtr<TH2F>(
"poca_xy" + slotName);
299 auto h5 = getObjectPtr<TH1F>(
"poca_z" + slotName);
301 auto h6 = getObjectPtr<TH1F>(
"Ecms" + slotName);
303 auto h7 = getObjectPtr<TH1F>(
"charge" + slotName);
305 auto h8 = getObjectPtr<TH2F>(
"timeHits" + slotName);
306 for (
const auto& digit :
m_digits) {
307 if (digit.getHitQuality() != TOPDigit::c_Good)
continue;
309 h8->Fill(digit.getChannel(), digit.getTime());
311 auto h9 = getObjectPtr<TH1F>(
"numPhot" + slotName);
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
std::vector< float > m_vAlignParsErr
error on alignment parameters
std::vector< TOP::ModuleAlignment > m_align
alignment objects
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
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
std::vector< int > m_countFails
counters for failed iterations
int m_targetMid
target module to align.
std::vector< std::string > m_treeNames
tree names
double m_maxZ
maximal local z of extrapolated hit
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
@ c_numSets
number of statistically independent subsamples
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
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
Alignment of a TOP module.
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 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.
const Const::ChargedStable & getChargedStable() const
Returns track hypothesis.
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.
virtual void collect() final
Replacement for event().
TOPAlignmentCollectorModule()
Constructor.
virtual void prepare() final
Replacement for initialize().
Abstract base class for different kinds of events.