Project
Loading...
Searching...
No Matches
TopologyDictionary.cxx
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
16
21#include <TFile.h>
22#include <iostream>
23
24using std::cout;
25using std::endl;
26using std::unordered_map;
27using std::vector;
28
30
31namespace o2
32{
33namespace itsmft
34{
35
37{
38 memset(mSmallTopologiesLUT, -1, STopoSize * sizeof(int));
39}
40
41TopologyDictionary::TopologyDictionary(const std::string& fileName)
42{
43 readFromFile(fileName);
44}
45
46std::ostream& operator<<(std::ostream& os, const TopologyDictionary& dict)
47{
48 int ID = 0;
49 for (auto& p : dict.mVectorOfIDs) {
50 os << "ID: " << ID++ << " Hash: " << p.mHash << " ErrX: " << p.mErrX << " ErrZ : " << p.mErrZ << " xCOG: " << p.mXCOG << " zCOG: " << p.mZCOG << " Npixles: " << p.mNpixels << " Frequency: " << p.mFrequency << " isGroup : " << std::boolalpha << p.mIsGroup << std::endl
51 << p.mPattern << std::endl
52 << "*********************************************************" << std::endl
53 << std::endl;
54 }
55 return os;
56}
57
58void TopologyDictionary::writeBinaryFile(const std::string& outputfile)
59{
60 std::ofstream file_output(outputfile, std::ios::out | std::ios::binary);
61 for (auto& p : mVectorOfIDs) {
62 file_output.write(reinterpret_cast<char*>(&p.mHash), sizeof(unsigned long));
63 file_output.write(reinterpret_cast<char*>(&p.mErrX), sizeof(float));
64 file_output.write(reinterpret_cast<char*>(&p.mErrZ), sizeof(float));
65 file_output.write(reinterpret_cast<char*>(&p.mErr2X), sizeof(float));
66 file_output.write(reinterpret_cast<char*>(&p.mErr2Z), sizeof(float));
67 file_output.write(reinterpret_cast<char*>(&p.mXCOG), sizeof(float));
68 file_output.write(reinterpret_cast<char*>(&p.mZCOG), sizeof(float));
69 file_output.write(reinterpret_cast<char*>(&p.mNpixels), sizeof(int));
70 file_output.write(reinterpret_cast<char*>(&p.mFrequency), sizeof(double));
71 file_output.write(reinterpret_cast<char*>(&p.mIsGroup), sizeof(bool));
72 file_output.write(reinterpret_cast<char*>(&p.mPattern.mBitmap),
73 sizeof(unsigned char) * (ClusterPattern::kExtendedPatternBytes));
74 }
75 file_output.close();
76}
77
78int TopologyDictionary::readFromFile(const std::string& fname)
79{
80 if (o2::utils::Str::endsWith(fname, ".root")) {
81 std::unique_ptr<TopologyDictionary> d{loadFrom(fname)};
82 *this = *d;
83 } else if (o2::utils::Str::endsWith(fname, ".bin")) {
84 readBinaryFile(fname);
85 } else {
86 throw std::runtime_error(fmt::format("Unrecognized format {}", fname));
87 }
88 return 0;
89}
90
91int TopologyDictionary::readBinaryFile(const std::string& fname)
92{
93 mVectorOfIDs.clear();
94 mCommonMap.clear();
95 for (auto& p : mSmallTopologiesLUT) {
96 p = -1;
97 }
98 std::ifstream in(fname.data(), std::ios::in | std::ios::binary);
99 GroupStruct gr;
100 int groupID = 0;
101 if (!in.is_open()) {
102 LOG(error) << "The file " << fname << " coud not be opened";
103 throw std::runtime_error("The file coud not be opened");
104 } else {
105 while (in.read(reinterpret_cast<char*>(&gr.mHash), sizeof(unsigned long))) {
106 in.read(reinterpret_cast<char*>(&gr.mErrX), sizeof(float));
107 in.read(reinterpret_cast<char*>(&gr.mErrZ), sizeof(float));
108 in.read(reinterpret_cast<char*>(&gr.mErr2X), sizeof(float));
109 in.read(reinterpret_cast<char*>(&gr.mErr2Z), sizeof(float));
110 in.read(reinterpret_cast<char*>(&gr.mXCOG), sizeof(float));
111 in.read(reinterpret_cast<char*>(&gr.mZCOG), sizeof(float));
112 in.read(reinterpret_cast<char*>(&gr.mNpixels), sizeof(int));
113 in.read(reinterpret_cast<char*>(&gr.mFrequency), sizeof(double));
114 in.read(reinterpret_cast<char*>(&gr.mIsGroup), sizeof(bool));
115 in.read(reinterpret_cast<char*>(&gr.mPattern.mBitmap), sizeof(unsigned char) * (ClusterPattern::kExtendedPatternBytes));
116 mVectorOfIDs.push_back(gr);
117 if (!gr.mIsGroup) {
118 mCommonMap.insert(std::make_pair(gr.mHash, groupID));
119 if (gr.mPattern.getUsedBytes() == 1) {
120 mSmallTopologiesLUT[(gr.mPattern.getColumnSpan() - 1) * 255 + (int)gr.mPattern.mBitmap[2]] = groupID;
121 }
122 } else {
123 mGroupMap.insert(std::make_pair((int)(gr.mHash >> 32) & 0x00000000ffffffff, groupID));
124 }
125 groupID++;
126 }
127 }
128 in.close();
129 return 0;
130}
131
132void TopologyDictionary::getTopologyDistribution(const TopologyDictionary& dict, TH1F*& histo, const char* histName)
133{
134 int dictSize = (int)dict.getSize();
135 if (histo) {
136 delete histo;
137 }
138 histo = new TH1F(histName, ";Topology ID;Frequency", dictSize, -0.5, dictSize - 0.5);
139 histo->SetFillColor(kRed);
140 histo->SetFillStyle(3005);
141 histo->SetDrawOption("histo");
142 for (int i = 0; i < dictSize; i++) {
143 histo->Fill(i, dict.getFrequency(i));
144 }
145}
146
147template <typename T>
149{
150 std::array<T, 3> locCl;
152 locCl[0] += this->getXCOG(cl.getPatternID());
153 locCl[2] += this->getZCOG(cl.getPatternID());
154 return locCl;
155}
156
157template <typename T>
158math_utils::Point3D<T> TopologyDictionary::getClusterCoordinates(const CompCluster& cl) const
159{
160 math_utils::Point3D<T> locCl;
162 locCl.SetX(locCl.X() + this->getXCOG(cl.getPatternID()));
163 locCl.SetZ(locCl.Z() + this->getZCOG(cl.getPatternID()));
164 return locCl;
165}
166
167template <typename T>
168math_utils::Point3D<T> TopologyDictionary::getClusterCoordinates(const CompCluster& cl, const ClusterPattern& patt, bool isGroup)
169{
170 auto refRow = cl.getRow();
171 auto refCol = cl.getCol();
172 float xCOG = 0, zCOG = 0;
173 patt.getCOG(xCOG, zCOG);
174 if (isGroup) {
175 refRow -= round(xCOG);
176 refCol -= round(zCOG);
177 }
178 math_utils::Point3D<T> locCl;
179 o2::itsmft::SegmentationAlpide::detectorToLocalUnchecked(refRow + xCOG, refCol + zCOG, locCl);
180 return locCl;
181}
182
183template <typename T>
184std::array<T, 3> TopologyDictionary::getClusterCoordinatesA(const CompCluster& cl, const ClusterPattern& patt, bool isGroup)
185{
186 auto refRow = cl.getRow();
187 auto refCol = cl.getCol();
188 float xCOG = 0, zCOG = 0;
189 patt.getCOG(xCOG, zCOG);
190 if (isGroup) {
191 refRow -= round(xCOG);
192 refCol -= round(zCOG);
193 }
194 std::array<T, 3> locCl;
195 o2::itsmft::SegmentationAlpide::detectorToLocalUnchecked(refRow + xCOG, refCol + zCOG, locCl);
196 return locCl;
197}
198
199//_______________________________________________
200TopologyDictionary* TopologyDictionary::loadFrom(const std::string& fname, const std::string& objName)
201{
202 // load object from file
203 TFile fl(fname.c_str());
204 if (fl.IsZombie()) {
205 throw std::runtime_error(fmt::format("Failed to open {} file", fname));
206 }
207 auto dict = reinterpret_cast<o2::itsmft::TopologyDictionary*>(fl.GetObjectChecked(objName.c_str(), o2::itsmft::TopologyDictionary::Class()));
208 if (!dict) {
209 throw std::runtime_error(fmt::format("Failed to load {} from {}", objName, fname));
210 }
211 return dict;
212}
213
214template math_utils::Point3D<float> TopologyDictionary::getClusterCoordinates<float>(const CompCluster& cl) const;
215template math_utils::Point3D<double> TopologyDictionary::getClusterCoordinates<double>(const CompCluster& cl) const;
216template math_utils::Point3D<float> TopologyDictionary::getClusterCoordinates<float>(const CompCluster& cl, const ClusterPattern& patt, bool isGroup);
217template math_utils::Point3D<double> TopologyDictionary::getClusterCoordinates<double>(const CompCluster& cl, const ClusterPattern& patt, bool isGroup);
218
219template std::array<float, 3> TopologyDictionary::getClusterCoordinatesA<float>(const CompCluster& cl) const;
220template std::array<double, 3> TopologyDictionary::getClusterCoordinatesA<double>(const CompCluster& cl) const;
221template std::array<float, 3> TopologyDictionary::getClusterCoordinatesA<float>(const CompCluster& cl, const ClusterPattern& patt, bool isGroup);
222template std::array<double, 3> TopologyDictionary::getClusterCoordinatesA<double>(const CompCluster& cl, const ClusterPattern& patt, bool isGroup);
223
224} // namespace itsmft
225} // namespace o2
Definition of the ClusterTopology class.
Definition of the ClusterTopology class.
ClassImp(o2::itsmft::TopologyDictionary)
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events d
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc bool
configStandalone Reconstruction rec_tpc float
char error[CURL_ERROR_SIZE]
Definition of the SegmentationAlpide class.
int getColumnSpan() const
Returns the number of columns.
static int getCOG(int rowSpan, int colSpan, const unsigned char patt[MaxPatternBytes], float &xCOG, float &zCOG)
Static: Compute pattern's COG position. Returns the number of fired pixels.
static constexpr int kExtendedPatternBytes
Maximum number of bytes for the cluster puttern + 2 bytes respectively for the number of rows and col...
int getUsedBytes() const
Returns the number of bytes used for the pattern.
UShort_t getRow() const
Definition CompCluster.h:57
UShort_t getPatternID() const
Definition CompCluster.h:59
UShort_t getCol() const
Definition CompCluster.h:58
static void detectorToLocalUnchecked(L row, L col, T &xRow, T &zCol)
TopologyDictionary()
Default constructor.
int readBinaryFile(const std::string &fileName)
Reads the dictionary from a binary file.
std::array< T, 3 > getClusterCoordinatesA(const CompCluster &cl) const
Returns the local position of a compact cluster.
math_utils::Point3D< T > getClusterCoordinates(const CompCluster &cl) const
int getSize() const
Returns the number of elements in the dicionary;.
int readFromFile(const std::string &fileName)
static TopologyDictionary * loadFrom(const std::string &fileName="", const std::string &objName="ccdb_object")
void writeBinaryFile(const std::string &outputFile)
Prints the dictionary in a binary file.
double getFrequency(int n) const
Returns the frequency of the n_th element;.
static void getTopologyDistribution(const TopologyDictionary &dict, TH1F *&histo, const char *histName)
Fills a hostogram with the distribution of the IDs.
float getXCOG(int n) const
Returns the x position of the COG for the n_th element.
bool isGroup(int n) const
Returns true if the element corresponds to a group of rare topologies.
float getZCOG(int n) const
Returns the z position of the COG for the n_th element.
std::ostream & operator<<(std::ostream &os, const ClusterPattern &pattern)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Structure containing the most relevant pieces of information of a topology.
float mErrX
Error associated to the hit point in the x direction.
float mErr2X
Squared Error associated to the hit point in the x direction.
float mErrZ
Error associated to the hit point in the z direction.
unsigned long mHash
Hashcode.
float mXCOG
x position of the COG wrt the bottom left corner of the bounding box
int mNpixels
Number of fired pixels.
double mFrequency
Frequency of the topology.
bool mIsGroup
false: common topology; true: group of rare topologies
float mErr2Z
Squared Error associated to the hit point in the z direction.
float mZCOG
z position of the COG wrt the bottom left corner of the bounding box
static bool endsWith(const std::string &s, const std::string &ending)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"