Project
Loading...
Searching...
No Matches
MatchGlobalFwd.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
16#ifndef ALICEO2_GLOBTRACKING_MATCHGLOBALFWD_
17#define ALICEO2_GLOBTRACKING_MATCHGLOBALFWD_
18
19#include <Rtypes.h>
20#include <array>
21#include <vector>
22#include <string>
23#include <gsl/span>
24#include <TStopwatch.h>
31#include "MFTTracking/IOUtils.h"
32#include "MFTBase/Constants.h"
46#include "TGeoManager.h"
47
48namespace o2
49{
50
51namespace mft
52{
53class TrackMFT;
54}
55
56namespace mch
57{
58class TrackMCH;
59}
60
61namespace globaltracking
62{
63
73
81
84typedef std::function<double(const GlobalFwdTrack& mchtrack, const TrackParCovFwd& mfttrack)> MatchingFunc_t;
85typedef std::function<bool(const GlobalFwdTrack& mchtrack, const TrackParCovFwd& mfttrack)> CutFunc_t;
86
91
95
102
104{
105 public:
111
113
115 ~MatchGlobalFwd() = default;
116
117 void run(const o2::globaltracking::RecoContainer& inp);
118 void init();
119 void finalize();
120 void clear();
121 void setBz(float bz) { mBz = bz; }
122
123 void setMFTDictionary(const o2::itsmft::TopologyDictionary* d) { mMFTDict = d; }
124 void setMatchingPlaneZ(float z) { mMatchingPlaneZ = z; };
125
127 void setBunchFilling(const o2::BunchFilling& bf);
129 void setMFTTriggered(bool v) { mMFTTriggered = v; }
130 bool isMFTTriggered() const { return mMFTTriggered; }
131
132 void setMCTruthOn(bool v) { mMCTruthON = v; }
134 void setMFTROFrameLengthMUS(float fums);
136 void setMFTROFrameLengthInBC(int nbc);
138 void setMFTROFrameBiasInBC(int nbc);
139
140 const std::vector<o2::dataformats::GlobalFwdTrack>& getMatchedFwdTracks() const { return mMatchedTracks; }
141 const std::vector<o2::mft::TrackMFT>& getMFTMatchingPlaneParams() const { return mMFTMatchPlaneParams; }
142 const std::vector<o2::track::TrackParCovFwd>& getMCHMatchingPlaneParams() const { return mMCHMatchPlaneParams; }
143 const std::vector<o2::dataformats::MatchInfoFwd>& getMFTMCHMatchInfo() const { return mMatchingInfo; }
144 const std::vector<o2::MCCompLabel>& getMatchLabels() const { return mMatchLabels; }
145
150
151 private:
152 void updateTimeDependentParams();
153 void fillBuiltinFunctions();
154
155 bool prepareMCHData();
156 bool prepareMFTData();
157 bool processMCHMIDMatches();
158
159 template <int saveMode>
160 void doMatching();
161 void doMCMatching();
162 void loadMatches();
163
164 o2::MCCompLabel computeLabel(const int MCHId, const int MFTid);
165
167 template <int saveMode>
168 void ROFMatch(int MFTROFId, int firstMCHROFId, int lastMCHROFId);
169
170 void fitTracks();
171 void fitGlobalMuonTrack(o2::dataformats::GlobalFwdTrack&);
172 bool computeCluster(o2::dataformats::GlobalFwdTrack& track, const MFTCluster& cluster, int& startingLayerID);
173
174 void setMFTRadLength(float MFT_x2X0) { mMFTDiskThicknessInX0 = MFT_x2X0 / 5.0; }
175 void setAlignResiduals(Float_t res) { mAlignResidual = res; }
176
177 template <typename T>
178 bool propagateToNextClusterWithMCS(T& track, double z, int& startingLayerID, const int& newLayerID)
179 {
180 // Propagate track to the next cluster z position, adding angular MCS effects at the center of
181 // each disk crossed by the track. This method is valid only for track propagation between
182 // clusters at MFT layers positions. The startingLayerID is updated.
183
184 if (startingLayerID == newLayerID) { // Same layer, nothing to do.
185 LOG(debug) << " => Propagate to next cluster with MCS : startingLayerID = " << startingLayerID << " = > "
186 << " newLayerID = " << newLayerID << " (NLayers = " << std::abs(newLayerID - startingLayerID)
187 << ") ; track.getZ() = " << track.getZ() << " => "
188 << "destination cluster z = " << z << " ; => Same layer: no MCS effects.";
189
190 if (z != track.getZ()) {
191 track.propagateToZ(z, mBz);
192 }
193 return true;
194 }
195
197 auto startingZ = track.getZ();
198
199 // https://stackoverflow.com/questions/1903954/is-there-a-standard-sign-function-signum-sgn-in-c-c
200 auto signum = [](auto a) {
201 return (0 < a) - (a < 0);
202 };
203 int direction = signum(newLayerID - startingLayerID); // takes values +1, 0, -1
204 auto currentLayer = startingLayerID;
205
206 LOG(debug) << " => Propagate to next cluster with MCS : startingLayerID = " << startingLayerID << " = > "
207 << " newLayerID = " << newLayerID << " (NLayers = " << std::abs(newLayerID - startingLayerID)
208 << ") ; track.getZ() = " << track.getZ() << " => "
209 << "destination cluster z = " << z << " ; ";
210
211 // Number of disks crossed by this track segment
212 while (currentLayer != newLayerID) {
213 auto nextlayer = currentLayer + direction;
214 auto nextZ = LayerZPosition[nextlayer];
215
216 int NDisksMS;
217 if (nextZ - track.getZ() > 0) {
218 NDisksMS = (currentLayer % 2 == 0) ? (currentLayer - nextlayer) / 2 : (currentLayer - nextlayer + 1) / 2;
219 } else {
220 NDisksMS = (currentLayer % 2 == 0) ? (nextlayer - currentLayer + 1) / 2 : (nextlayer - currentLayer) / 2;
221 }
222
223 LOG(debug) << "currentLayer = " << currentLayer << " ; "
224 << "nextlayer = " << nextlayer << " ; "
225 << "track.getZ() = " << track.getZ() << " ; "
226 << "nextZ = " << nextZ << " ; "
227 << "NDisksMS = " << NDisksMS;
228
229 if ((NDisksMS * mMFTDiskThicknessInX0) != 0) {
230 track.addMCSEffect(NDisksMS * mMFTDiskThicknessInX0);
231 LOG(debug) << "Track covariances after MCS effects:";
232 LOG(debug) << track.getCovariances() << std::endl;
233 }
234
235 LOG(debug) << " BeforeExtrap: X = " << track.getX() << " Y = " << track.getY() << " Z = " << track.getZ() << " Tgl = " << track.getTanl() << " Phi = " << track.getPhi() << " pz = " << track.getPz() << " q/pt = " << track.getInvQPt() << std::endl;
236
237 track.propagateToZ(nextZ, mBz);
238
239 currentLayer = nextlayer;
240 }
241 if (z != track.getZ()) {
242 track.propagateToZ(z, mBz);
243 }
244 startingLayerID = newLayerID;
245 return true;
246 }
247
248 MatchingFunc_t mMatchFunc = [](const GlobalFwdTrack& mchtrack, const TrackParCovFwd& mfttrack) -> double {
249 throw std::runtime_error("MatchGlobalFwd: matching function not configured!");
250 };
251
252 CutFunc_t mCutFunc = [](const GlobalFwdTrack& mchtrack, const TrackParCovFwd& mfttrack) -> bool {
253 throw std::runtime_error("MatchGlobalFwd: track pair candidate cut function not configured!");
254 };
255
256 bool loadExternalMatchingFunction()
257 {
258 // Loads MFTMCH Matching function from external file
259
260 auto& matchingParam = GlobalFwdMatchingParam::Instance();
261
262 const auto& extFuncMacroFile = matchingParam.extMatchFuncFile;
263 const auto& extFuncName = matchingParam.extMatchFuncName;
264
265 LOG(info) << "Loading external MFTMCH matching function: function name = " << extFuncName << " ; Filename = " << extFuncMacroFile;
266
267 auto func = o2::conf::GetFromMacro<MatchingFunc_t*>(extFuncMacroFile.c_str(), extFuncName.c_str(), "o2::globaltracking::MatchingFunc_t*", "mtcFcn");
268 mMatchFunc = (*func);
269 return true;
270 }
271
272 bool loadExternalCutFunction()
273 {
274 // Loads MFTMCH cut function from external file
275
276 auto& matchingParam = GlobalFwdMatchingParam::Instance();
277
278 const auto& extFuncMacroFile = matchingParam.extMatchFuncFile;
279 const auto& extFuncName = matchingParam.extCutFuncName;
280
281 LOG(info) << "Loading external MFTMCH cut function: function name = " << extFuncName << " ; Filename = " << extFuncMacroFile;
282
283 auto func = o2::conf::GetFromMacro<CutFunc_t*>(extFuncMacroFile.c_str(), extFuncName.c_str(), "o2::globaltracking::CutFunc_t*", "cutFcn");
284 mCutFunc = (*func);
285 return true;
286 }
287
288 float mBz = -5.f;
289 float mMatchingPlaneZ = sLastMFTPlaneZ;
290 Float_t mMFTDiskThicknessInX0 = 0.042 / 5;
291 Float_t mAlignResidual = 1;
292 o2::InteractionRecord mStartIR{0, 0};
293 int mMFTROFrameLengthInBC = 0;
294 float mMFTROFrameLengthMUS = -1.;
295 float mMFTROFrameLengthMUSInv = -1.;
296 int mMFTROFrameBiasInBC = 0;
297 float mMFTROFrameBiasMUS = -1.;
298 float mMFTROFrameBiasMUSInv = -1.;
299
300 std::map<std::string, MatchingFunc_t> mMatchingFunctionMap;
301 std::map<std::string, CutFunc_t> mCutFunctionMap;
302
303 o2::BunchFilling mBunchFilling;
304 std::array<int16_t, o2::constants::lhc::LHCMaxBunches> mClosestBunchAbove; // closest filled bunch from above
305 std::array<int16_t, o2::constants::lhc::LHCMaxBunches> mClosestBunchBelow; // closest filled bunch from below
306
307 bool mMFTTriggered = false;
308
310 std::vector<int> mMFTTrackROFContMapping;
311
312 const o2::globaltracking::RecoContainer* mRecoCont = nullptr;
313 gsl::span<const o2::mch::TrackMCH> mMCHTracks;
314 gsl::span<const o2::mch::ROFRecord> mMCHTrackROFRec;
315 gsl::span<const o2::mft::TrackMFT> mMFTTracks;
316 gsl::span<const o2::itsmft::ROFRecord> mMFTTrackROFRec;
317 gsl::span<const o2::dataformats::TrackMCHMID> mMCHMIDMatches;
318 gsl::span<const int> mMFTTrackClusIdx;
319 gsl::span<const o2::itsmft::ROFRecord> mMFTClusterROFRec;
320 gsl::span<const o2::dataformats::MatchInfoFwd> mMatchingInfoUpstream;
321 gsl::span<const o2::MCCompLabel> mMFTTrkLabels;
322 gsl::span<const o2::MCCompLabel> mMCHTrkLabels;
323
324 std::vector<BracketF> mMCHROFTimes;
325 std::vector<TrackLocMCH> mMCHWork;
326 std::vector<int> mMCHID2Work;
327 std::vector<BracketF> mMFTROFTimes;
328 std::vector<TrackLocMFT> mMFTWork;
329 std::vector<MFTCluster> mMFTClusters;
330 std::vector<o2::dataformats::GlobalFwdTrack> mMatchedTracks;
331 std::vector<o2::MCCompLabel> mMatchLabels;
332 std::vector<o2::dataformats::MatchInfoFwd> mMatchingInfo;
333 std::vector<o2::mft::TrackMFT> mMFTMatchPlaneParams;
334 std::vector<o2::track::TrackParCovFwd> mMCHMatchPlaneParams;
335
336 std::map<int, std::vector<std::pair<float, int>>> mCandidates;
337
338 const o2::itsmft::TopologyDictionary* mMFTDict{nullptr}; // cluster patterns dictionary
339 o2::itsmft::ChipMappingMFT mMFTMapping;
340 bool mMCTruthON = false;
341 bool mUseMIDMCHMatch = false;
342 bool mUseTrackTime = false;
343 int mSaveMode = 0;
344 int mNCandidates = 5;
345 MatchingType mMatchingType = MATCHINGUNDEFINED;
346 TGeoManager* mGeoManager;
347};
348
349} // namespace globaltracking
350} // namespace o2
351
352#endif
Wrapper container for different reconstructed object types.
Definition of the ClusterTopology class.
Definition of the GeometryManager class.
Constants for the MFT; distance unit is cm.
Global Forward Muon tracks.
Global index for barrel track: provides provenance (detectors combination), index in respective array...
Load pulled clusters, for a given read-out-frame, in a dedicated container.
Definition of the ITSMFT ROFrame (trigger) record.
Header to collect LHC related constants.
Definition of the MCH ROFrame record.
uint32_t res
Definition RawData.h:0
Definition of tools for track extrapolation.
Definition of the MUON track.
Definition of the MCH track.
Definition of the MCH track parameters for internal use.
std::ostringstream debug
void setMFTDictionary(const o2::itsmft::TopologyDictionary *d)
const std::vector< o2::dataformats::MatchInfoFwd > & getMFTMCHMatchInfo() const
void setBunchFilling(const o2::BunchFilling &bf)
set Bunch filling and init helpers for validation by BCs
const std::vector< o2::mft::TrackMFT > & getMFTMatchingPlaneParams() const
const std::vector< o2::track::TrackParCovFwd > & getMCHMatchingPlaneParams() const
void setMCTruthOn(bool v)
set MFT ROFrame duration in microseconds
void setMFTROFrameLengthMUS(float fums)
set MFT ROFrame duration in BC (continuous mode only)
void setMFTROFrameLengthInBC(int nbc)
set MFT ROFrame bias in BC (continuous mode only) or time shift applied already as MFTAlpideParam....
static constexpr Double_t sLastMFTPlaneZ
const std::vector< o2::dataformats::GlobalFwdTrack > & getMatchedFwdTracks() const
void run(const o2::globaltracking::RecoContainer &inp)
const std::vector< o2::MCCompLabel > & getMatchLabels() const
@ MATCHINGFUNC
MFT-MCH matching modes.
@ MATCHINGUPSTREAM
MFT-MCH track matching loaded from input file.
o2::mch::TrackParam FwdtoMCH(const o2::dataformats::GlobalFwdTrack &fwdtrack)
Converts FwdTrack parameters to MCH coordinate system.
o2::dataformats::GlobalFwdTrack MCHtoFwd(const o2::mch::TrackParam &mchTrack)
Converts mchTrack parameters to Forward coordinate system.
track parameters for internal use
Definition TrackParam.h:34
GLenum func
Definition glcorearb.h:778
const GLdouble * v
Definition glcorearb.h:832
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
std::function< double(const GlobalFwdTrack &mchtrack, const TrackParCovFwd &mfttrack)> MatchingFunc_t
std::function< bool(const GlobalFwdTrack &mchtrack, const TrackParCovFwd &mfttrack)> CutFunc_t
constexpr std::array< Float_t, LayersNumber > LayerZCoordinate()
Definition Constants.h:44
constexpr Double_t LayerZPosition[]
layer Z position to the middle of the CMOS sensor
Definition Constants.h:32
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
o2::math_utils::Bracketf_t tBracket
bracketing time in \mus
o2::math_utils::Bracketf_t tBracket
bracketing time in \mus
int roFrame
MFT readout frame assigned to this track.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"