14#include <TTreeReader.h>
15#include <TTreeReaderValue.h>
35 mNumberOfClusterChainROFs(0),
36 mNumberOfTrackChainROFs(0),
37 mCounterLocalEquationFailed(0),
38 mCounterSkippedTracks(0),
39 mCounterUsedTracks(0),
40 mGlobalDerivatives(
std::vector<double>(mNumberOfGlobalParam)),
41 mLocalDerivatives(
std::vector<double>(mNumberOfTrackParam)),
42 mMinNumberClusterCut(6),
47 mNEntriesAutoSave(10000),
48 mRecordWriter(new
o2::fwdalign::MilleRecordWriter()),
49 mWithConstraintsRecWriter(false),
50 mConstraintsRecWriter(nullptr),
51 mMillepede(new
o2::fwdalign::MillePede2())
59 LOGF(
debug,
"TracksToRecords instantiated");
80 LOGF(
debug,
"TracksToRecords destroyed");
90 LOGF(fatal,
"TracksToRecords::init() failed because no cluster dictionary is defined");
113 LOG(info) <<
"-------------- TracksToRecords configured with -----------------";
116 LOGF(info,
"ResidualCut = %.3f",
mResCut);
118 LOGF(info,
"mStartFac = %.3f",
mStartFac);
120 "Allowed variation: dx = %.3f, dy = %.3f, dz = %.3f, dRz = %.4f",
122 LOG(info) <<
"-----------------------------------------------------------";
137 LOGF(info,
"TracksToRecords init done");
163 LOGF(fatal,
"TracksToRecords::processRecoTracks() aborted because init was not done !");
167 LOGF(fatal,
"TracksToRecords::processRecoTracks() aborted because uninitialised mRecordWriter !");
171 LOG(info) <<
"TracksToRecords::processRecoTracks() - start";
173 int nCounterAllTracks = 0;
177 LOGF(
debug,
"Processing track # %5d", nCounterAllTracks);
180 auto ncls = oneTrack.getNumberOfPoints();
188 if (!oneTrack.isLTF()) {
194 auto offset = oneTrack.getExternalClusterIndexOffset();
199 auto track = oneTrack;
203 bool isTrackUsed =
true;
205 for (
int icls = 0; icls < ncls; ++icls) {
215 LOGF(warning,
"TracksToRecords::processRecoTracks() - will not use track # %5d with at least a bad cluster", nCounterAllTracks);
240 isTrackUsed &= success;
245 LOGF(error,
"TracksToRecords::processRecoTracks() - track %i h %d d %d l %d s %4d lMpos x %.2e y %.2e z %.2e gMpos x %.2e y %.2e z %.2e gRpos x %.2e y %.2e z %.2e",
257 const bool doPrint =
false;
263 LOG(info) <<
"TracksToRecords::processRecoTracks() - end";
270 LOGF(fatal,
"TracksToRecords::processROFs() aborted because init was not done !");
275 LOGF(fatal,
"TracksToRecords::processROFs() aborted because uninitialised mRecordWriter !");
279 LOG(info) <<
"TracksToRecords::processROFs() - start";
281 TTreeReader mftTrackChainReader(mfttrackChain);
282 TTreeReader mftClusterChainReader(mftclusterChain);
283 std::vector<unsigned char>::iterator pattIterator;
285 TTreeReaderValue<std::vector<o2::mft::TrackMFT>> mftTracks =
286 {mftTrackChainReader,
"MFTTrack"};
287 TTreeReaderValue<std::vector<o2::itsmft::ROFRecord>> mftTracksROF =
288 {mftTrackChainReader,
"MFTTracksROF"};
289 TTreeReaderValue<std::vector<int>> mftTrackClusIdx =
290 {mftTrackChainReader,
"MFTTrackClusIdx"};
292 TTreeReaderValue<std::vector<o2::itsmft::CompClusterExt>> mftClusters =
293 {mftClusterChainReader,
"MFTClusterComp"};
294 TTreeReaderValue<std::vector<o2::itsmft::ROFRecord>> mftClustersROF =
295 {mftClusterChainReader,
"MFTClustersROF"};
296 TTreeReaderValue<std::vector<unsigned char>> mftClusterPatterns =
297 {mftClusterChainReader,
"MFTClusterPatt"};
299 int nCounterAllTracks = 0;
301 while (mftTrackChainReader.Next() && mftClusterChainReader.Next()) {
307 pattIterator = (*mftClusterPatterns).begin();
312 for (
auto& oneTrack : *mftTracks) {
314 LOGF(
debug,
"Processing track # %5d", nCounterAllTracks);
317 auto ncls = oneTrack.getNumberOfPoints();
325 if (!oneTrack.isLTF()) {
331 auto offset = oneTrack.getExternalClusterIndexOffset();
339 bool isTrackUsed =
true;
341 for (
int icls = 0; icls < ncls; ++icls) {
346 auto clsEntry = (*mftTrackClusIdx)[
offset + icls];
351 LOGF(warning,
"TracksToRecords::processROFs() - will not use track # %5d with at least a bad cluster", nCounterAllTracks);
376 isTrackUsed &= success;
381 LOGF(error,
"TracksToRecords::processROFs() - track %i h %d d %d l %d s %4d lMpos x %.2e y %.2e z %.2e gMpos x %.2e y %.2e z %.2e gRpos x %.2e y %.2e z %.2e",
394 const bool doPrint =
false;
403 LOG(info) <<
"TracksToRecords::processROFs() - end";
409 LOGF(info,
"TracksToRecords processRecoTracks() summary: ");
412 "n ROFs = %d, used tracks = %d, skipped tracks = %d, local equations failed = %d",
417 "n TFs = %d, used tracks = %d, skipped tracks = %d, local equations failed = %d",
474 bool success =
false;
480 "AlignHelper::setLocalDerivative() - index %d >= %d",
491 bool success =
false;
497 "AlignHelper::setGlobalDerivative() - index %d >= %d",
506 bool success =
false;
515 bool success =
false;
527 "TracksToRecords::setLocalEquationX() - no align point coordinates set !");
564 "TracksToRecords::setLocalEquationX(): track %i sr %4d local %.3e %.3e %.3e %.3e, global %.3e %.3e %.3e %.3e X %.3e sigma %.3e",
591 "TracksToRecords::setLocalEquationY() - no align point coordinates set !");
628 "TracksToRecords::setLocalEquationY(): track %i sr %4d local %.3e %.3e %.3e %.3e, global %.3e %.3e %.3e %.3e Y %.3e sigma %.3e",
655 "TracksToRecords::setLocalEquationZ() - no align point coordinates set !");
692 "TracksToRecords::setLocalEquationZ(): track %i sr %4d local %.3e %.3e %.3e %.3e, global %.3e %.3e %.3e %.3e Z %.3e sigma %.3e",
Class handling both virtual segmentation and real volumes.
Class to store the data of single track processing.
ClassImp(o2::mft::TracksToRecords)
Class responsible to create records from tracks (and attached clusters) to feed alignment.
InputRecord & inputs()
The inputs associated with this processing context.
int InitMille(int nGlo, const int nLoc, const int lNStdDev=-1, const double lResCut=-1., const double lResCutInit=-1., const std::vector< int > ®roup={})
init all
void SetParSigma(int i, double par)
void SetConstraintsRecWriter(o2::fwdalign::MilleRecordWriter *myP)
void SetLocalEquation(std::vector< double > &dergb, std::vector< double > &derlc, const double lMeas, const double lSigma)
assing derivs of loc.eq.
int SetIterations(const double lChi2CutFac)
Number of iterations is calculated from lChi2CutFac.
void SetRecordWriter(o2::fwdalign::MilleRecordWriter *myP)
void setCyclicAutoSave(const long nEntries)
Set the number of entries to be used by TTree::AutoSave()
bool isInitOk() const
check if init went well
void setDataFileName(TString fname)
choose data records filename
void init()
init output file and tree
void setRecordRun(int run)
assign run
void terminate()
write tree and close output file
void changeDataBranchName(const bool isConstraintsRec=true)
choose data records filename
void setRecordWeight(double wgh)
assign weight
void fillRecordTree(const bool doPrint=false)
fill tree
o2::fwdalign::MillePedeRecord * getRecord()
return the record
void setCyclicAutoSave(const long nEntries)
Set the number of entries to be used by TTree::AutoSave()
void init()
init output file and tree
void fill(o2::mft::AlignPointHelper *aPoint, const int iTrack=0, const bool doPrint=false)
fill the tree from an align point
void terminate()
write tree and close output file
Container of a single alignment point and methods to fill it.
o2::math_utils::Point3D< double > getLocalMeasuredPositionSigma() const
GlobalDerivative globalDerivativeX() const
void recordTrackInitialParam(o2::mft::TrackMFT &mftTrack)
store the track parameters at the initial z0 plane
GlobalDerivative globalDerivativeZ() const
o2::math_utils::Point3D< double > getLocalResidual() const
void setClusterDictionary(const o2::itsmft::TopologyDictionary *d)
set cluster pattern dictionary (needed to compute cluster coordinates)
bool isLocalDerivativeDone() const
o2::math_utils::Point3D< double > getLocalMeasuredPosition() const
o2::math_utils::Point3D< double > getGlobalRecoPosition() const
LocalDerivative localDerivativeY() const
UShort_t getSensorId() const
void setGlobalRecoPosition(o2::mft::TrackMFT &mftTrack)
LocalDerivative localDerivativeZ() const
void convertCompactClusters(gsl::span< const itsmft::CompClusterExt > clusters, gsl::span< const unsigned char >::iterator &pattIt, std::vector< o2::BaseCluster< double > > &outputLocalClusters, std::vector< o2::BaseCluster< double > > &outputGlobalClusters)
convert compact clusters (pixel coordinates in row, col) from workflow to base clusters with 3D posit...
void setMeasuredPosition(const o2::BaseCluster< double > &localCluster, const o2::BaseCluster< double > &globalCluster)
void computeGlobalDerivatives()
method to call the computation of all three components of the global derivative
void resetAlignPoint()
reset all quantities that define an alignment point to their default value
void computeLocalDerivatives()
method to call the computation of all three compnonents of the local derivative
o2::math_utils::Point3D< double > getGlobalMeasuredPosition() const
bool isAlignPointSet() const
LocalDerivative localDerivativeX() const
void resetTrackInitialParam()
reset all track parameters to their default value (zero)
GlobalDerivative globalDerivativeY() const
bool isGlobalDerivativeDone() const
TString mMilleRecordsFileName
output file name when saving the Mille records
double mResCutInitial
Cut on residual on first iteration.
static constexpr int mNumberOfSensors
Total number of sensors (detection elements) in the MFT.
TString mMilleConstraintsRecFileName
output file name when saving the records of the constraints
static constexpr int mNDofPerSensor
translation in global x, y, z, and rotation Rz around global z-axis
double mResCut
Cut on residual for other iterations.
bool mIsInitDone
boolean to follow the initialisation status
double mStartFac
Initial value for chi2 cut, used to reject outliers i.e. bad tracks with sum(chi2) > Chi2DoFLim(fNStd...
static constexpr int mNumberOfGlobalParam
Number of alignment (= global) parameters.
std::array< double, mNDofPerSensor > mAllowVar
"Encouraged" variation for degrees of freedom {dx, dy, dRz, dz}
static constexpr int mNumberOfTrackParam
Number of track (= local) parameters (X0, Tx, Y0, Ty)
int mChi2CutNStdDev
Number of standard deviations for chi2 cut.
bool setGlobalDerivative(Int_t index, Double_t value)
set array of global derivatives
void processRecoTracks()
use valid tracks (and associated clusters) from the workflow to build Mille records
o2::fwdalign::MilleRecordWriter * mRecordWriter
utility that handles the writing of the data records to a ROOT file
void startConstraintsRecWriter()
init the utility needed to write constraints records
o2::mft::AlignPointHelper * mAlignPoint
Alignment point helper.
o2::fwdalign::MilleRecordWriter * mConstraintsRecWriter
utility that handles the writing of the constraints records
gsl::span< const int > mMFTTrackClusIdx
std::vector< double > mGlobalDerivatives
vector of global derivatives {dDeltaX, dDeltaY, dDeltaRz, dDeltaZ}
long mNEntriesAutoSave
number of entries needed to call AutoSave for the output TTrees
void printProcessTrackSummary()
print a summary status of what happened in processRecoTracks() or processROFs()
bool mWithConstraintsRecWriter
boolean to be set to true if one wants to also write constaints records
bool setLocalEquationY()
set the 2nd component of the local equation vector for a given alignment point
int mCounterSkippedTracks
count how many tracks did not met the cut on the min. nb of clusters
int mNumberOfTrackChainROFs
number of ROFs in the track chain
gsl::span< const o2::mft::TrackMFT > mMFTTracks
void processTimeFrame(o2::framework::ProcessingContext &ctx)
access mft tracks and clusters in the timeframe provided by the workflow
TracksToRecords()
construtor
void processROFs(TChain *mfttrackChain, TChain *mftclusterChain)
use mft tracks and clusters provided by ROOT files accessed via TChain to build Mille records
bool resetLocalDerivative()
reset the array of the Local derivative
int mMinNumberClusterCut
Minimum number of clusters in the track to be used for alignment.
std::vector< o2::BaseCluster< double > > mMFTClustersGlobal
MFT clusters in global coordinate system.
bool mWithControl
boolean to set the use of the control tree
void endConstraintsRecWriter()
end the utility used to write constraints records
int mCounterUsedTracks
count how many tracks were used to make Mille records
gsl::span< constunsignedchar >::iterator mPattIt
std::vector< o2::BaseCluster< double > > mMFTClustersLocal
MFT clusters in local coordinate system.
bool setLocalEquationZ()
set the last component of the local equation vector for a given alignment point
gsl::span< const unsigned char > mMFTClusterPatterns
int mNumberTFs
number of timeframes processed
gsl::span< const o2::itsmft::ROFRecord > mMFTClustersROF
gsl::span< const o2::itsmft::CompClusterExt > mMFTClusters
int mNumberOfClusterChainROFs
number of ROFs in the cluster chain
double mWeightRecord
the weight given to a single Mille record in Millepede algorithm
const o2::itsmft::TopologyDictionary * mDictionary
cluster patterns dictionary
void init() override
init Millipede and AlignPointHelper
bool resetGlocalDerivative()
reset the array of the Global derivative
void endRecordWriter()
end the utility used to write data records and its control tree
gsl::span< const o2::itsmft::ROFRecord > mMFTTracksROF
o2::fwdalign::MillePede2 * mMillepede
Millepede2 implementation copied from AliROOT.
~TracksToRecords() override
destructor
void startRecordWriter()
init the utility needed to write data records and its control tree
int mCounterLocalEquationFailed
count how many times we failed to set a local equation
o2::mft::AlignPointControl mPointControl
AlignPointControl handles the control tree.
bool setLocalEquationX()
set the first component of the local equation vector for a given alignment point
bool setLocalDerivative(Int_t index, Double_t value)
set array of local derivatives
std::vector< double > mLocalDerivatives
vector of local derivatives {dX0, dTx, dY0, dTz}
GLsizei const GLfloat * value
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"