Project
Loading...
Searching...
No Matches
Clusterer.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
14#include <algorithm>
15#include "FairLogger.h" // for LOG
16#include "Framework/Logger.h"
17#include "HMPIDBase/Param.h"
22#include <TStopwatch.h>
23
24using namespace o2::hmpid;
25
26//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27/*Clusterer::Clusterer()
28{
29 // mDigs = {nullptr};
30 // mClus = {nullptr};
31}*/
32//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33void Clusterer::Dig2Clu(gsl::span<const o2::hmpid::Digit> digs, std::vector<o2::hmpid::Cluster>& clus, float* pUserCut, bool isUnfold)
34{
35 // Finds all clusters for a given digits list provided not empty. Currently digits list is a list of all digits for a single chamber.
36 // Puts all found clusters in separate lists, one per clusters.
37 // Arguments: pDigAll - list of digits for all chambers
38 // pCluAll - list of clusters for all chambers
39 // isTryUnfold - flag to choose between CoG and Mathieson fitting
40 // Returns: none
41
42 struct Pad {
43 int x, y, m;
44 };
45
46 TMatrixF padMap(Param::kMinPx, Param::kMaxPcx, Param::kMinPy, Param::kMaxPcy); // pads map for single chamber 0..159 x 0..143
47
48 int pUsedDig = -1;
49 int padChX = 0, padChY = 0, module = 0;
50 std::vector<Pad> vPad;
51 std::vector<const Digit*> digVec;
52 for (int iCh = Param::kMinCh; iCh <= Param::kMaxCh; iCh++) { // chambers loop
53 padMap = (Float_t)-1; // reset map to -1 (means no digit for this pad)
54 for (size_t iDig = 0; iDig < digs.size(); iDig++) {
55 o2::hmpid::Digit::pad2Absolute(digs[iDig].getPadID(), &module, &padChX, &padChY);
56 vPad.push_back({padChX, padChY, module});
57 if (module == iCh) {
58 padMap(padChX, padChY) = iDig; // fill the map for the given chamber, (padx,pady) cell takes digit index
59 }
60 } // digits loop for current chamber
61
62 for (size_t iDig = 0; iDig < digs.size(); iDig++) { // digits loop for current chamber
63 // o2::hmpid::Digit::pad2Absolute(digs[iDig].getPadID(), &module, &padChX, &padChY);
64 if (vPad.at(iDig).m != iCh || (pUsedDig = UseDig(vPad.at(iDig).x, vPad.at(iDig).y, padMap)) == -1) { // this digit is from other module or already taken in FormClu(), go after next digit
65 continue;
66 }
67 digVec.clear();
69 clu.setDigits(&digVec);
70 clu.setCh(iCh);
71 FormClu(clu, pUsedDig, digs, padMap); // form cluster starting from this digit by recursion
72 clu.solve(&clus, pUserCut, isUnfold); // solve this cluster and add all unfolded clusters to provided list
73 } // digits loop for current chamber
74 vPad.clear();
75 } // chambers loop
76 return;
77} // Dig2Clu()
78//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
79/*void Clusterer::Dig2Clu(gsl::span<const o2::hmpid::Digit> digs, std::vector<o2::hmpid::Cluster>& clus, float* pUserCut, bool isUnfold)
80{
81 // Finds all clusters for a given digits list provided not empty. Currently digits list is a list of all digits for a single chamber.
82 // Puts all found clusters in separate lists, one per clusters.
83 // Arguments: pDigAll - list of digits for all chambers
84 // pCluAll - list of clusters for all chambers
85 // isTryUnfold - flag to choose between CoG and Mathieson fitting
86 // Returns: none
87
88 TMatrixF padMap(Param::kMinPx, Param::kMaxPcx, Param::kMinPy, Param::kMaxPcy); // pads map for single chamber 0..159 x 0..143
89
90 int pUsedDig = -1;
91 int padChX = 0, padChY = 0, module = 0;
92
93 for (int iCh = Param::kMinCh; iCh <= Param::kMaxCh; iCh++) { // chambers loop
94 padMap = (Float_t)-1; // reset map to -1 (means no digit for this pad)
95 for (size_t iDig = 0; iDig < digs.size(); iDig++) {
96 o2::hmpid::Digit::pad2Absolute(digs[iDig].getPadID(), &module, &padChX, &padChY);
97 if (module == iCh) {
98 padMap(padChX, padChY) = iDig; // fill the map for the given chamber, (padx,pady) cell takes digit index
99 }
100 } // digits loop for current chamber
101
102 for (size_t iDig = 0; iDig < digs.size(); iDig++) { // digits loop for current chamber
103 o2::hmpid::Digit::pad2Absolute(digs[iDig].getPadID(), &module, &padChX, &padChY);
104 if (module != iCh || (pUsedDig = UseDig(padChX, padChY, padMap)) == -1) { // this digit is from other module or already taken in FormClu(), go after next digit
105 continue;
106 }
107 Cluster clu;
108 clu.setCh(iCh);
109 FormClu(clu, pUsedDig, digs, padMap); // form cluster starting from this digit by recursion
110 clu.solve(&clus, pUserCut, isUnfold); // solve this cluster and add all unfolded clusters to provided list
111 } // digits loop for current chamber
112 } // chambers loop
113 return;
114} // Dig2Clu()
115*/
116//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
117void Clusterer::FormClu(Cluster& pClu, int pDig, gsl::span<const o2::hmpid::Digit> digs, TMatrixF& pDigMap)
118{
119 // Forms the initial cluster as a combination of all adjascent digits. Starts from the given digit then calls itself recursevly for all neighbours.
120 // Arguments: pClu - pointer to cluster being formed
121 // Returns: none
122
123 pClu.digAdd(&digs[pDig]); // take this digit in cluster
124 int cnt = 0;
125 int cx[4];
126 int cy[4];
127 int padChX = 0;
128 int padChY = 0;
129 int module = 0;
130 o2::hmpid::Digit::pad2Absolute(digs[pDig].getPadID(), &module, &padChX, &padChY);
131
132 if (padChX > Param::kMinPx) {
133 cx[cnt] = padChX - 1;
134 cy[cnt] = padChY;
135 cnt++;
136 } // left
137 if (padChX < Param::kMaxPcx) {
138 cx[cnt] = padChX + 1;
139 cy[cnt] = padChY;
140 cnt++;
141 } // right
142 if (padChY > Param::kMinPy) {
143 cx[cnt] = padChX;
144 cy[cnt] = padChY - 1;
145 cnt++;
146 } // down
147 if (padChY < Param::kMaxPcy) {
148 cx[cnt] = padChX;
149 cy[cnt] = padChY + 1;
150 cnt++;
151 } // up
152
153 for (int i = 0; i < cnt; i++) { // neighbours loop
154 pDig = UseDig(cx[i], cy[i], pDigMap);
155 if (pDig != -1) {
156 FormClu(pClu, pDig, digs, pDigMap);
157 } // check if this neighbour pad fired and mark it as taken
158 } // neighbours loop
159} // FormClu()
160
161//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
162int Clusterer::UseDig(int padX, int padY, TMatrixF& pPadMap)
163{
164 // Digit map contains a matrix if digit numbers.
165 // Main operation in forming initial cluster is done here. Requested digit pointer is returned and this digit marked as taken.
166 // Arguments: padX,padY - pad number
167 // pDigLst - list of digits for one sector
168 // pDigMap - map of those digits
169 // Returns: index to digit if not yet used or -1 if used
170 int iDig = (int)pPadMap(padX, padY);
171 pPadMap(padX, padY) = -1; // take digit number from the map and reset this map cell to -1
172 return iDig;
173}
174//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
175// bool Clusterer::IsDigSurvive(Int_t *pUserCut, Digit *pDig)const
177{
178 // Check if the current digit survive to a riapllied sigma cut
179 // Arguments: pDig pointer to the current digit
180 // Returns: kTRUE if charge > mean+n*sigma
181 /*int iCh = pDig->Ch();
182 int iDaqSigCut =(int)fDaqSig->At(iCh)->GetUniqueID();
183 if(pUserCut[iCh]<=iDaqSigCut) return kTRUE;
184 TMatrixF *pM = (TMatrixF*)fDaqSig->At(pDig->Ch());
185 float sig = (*pM)(pDig->PadChX(),pDig->PadChY());
186 //if(pDig->Q()>pUserCut[iCh]*sig) return kTRUE; to be improved
187 */
188 if (pDig->getQ() > 4.) {
189 return true;
190 } else {
191 return false;
192 }
193}
194//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
195/*void Clusterer::process(std::vector<o2::hmpid::Digit> const& digits, std::vector<o2::hmpid::Cluster>& clusters, MCLabelContainer const* digitMCTruth)
196{
197 TStopwatch timerProcess;
198 timerProcess.Start();
199
200 // reader.init();
201 // int totNumDigits = 0;
202 //
203 // while (reader.getNextStripData(mStripData)) {
204 // LOG(debug) << "HMPIDClusterer got Strip " << mStripData.stripID << " with Ndigits "
205 // << mStripData.digits.size();
206 // totNumDigits += mStripData.digits.size();
207 //
208 // processStrip(clusters, digitMCTruth);
209 // }
210
211 // LOG(debug) << "We had " << totNumDigits << " digits in this event";
212 timerProcess.Stop();
213 printf("Timing:\n");
214 printf("Clusterer::process: ");
215 timerProcess.Print();
216}*/
int32_t i
Definition of the HMPID cluster finder.
Definition of a container to keep Monte Carlo truth external to simulation objects.
HMPID cluster implementation.
Definition Cluster.h:27
void setCh(int chamber)
Definition Cluster.h:95
void setDigits(std::vector< const o2::hmpid::Digit * > *v=nullptr)
Definition Cluster.h:58
void digAdd(const o2::hmpid::Digit *pDig)
Definition Cluster.cxx:465
int solve(std::vector< o2::hmpid::Cluster > *pCluLst, float *pSigmaCut, bool isUnfold)
Definition Cluster.cxx:257
static void Dig2Clu(gsl::span< const o2::hmpid::Digit > digs, std::vector< o2::hmpid::Cluster > &clus, float *pUserCut, bool isUnfold=kTRUE)
Definition Clusterer.cxx:33
static int UseDig(int padX, int padY, TMatrixF &pDigMap)
static void FormClu(Cluster &pClu, int pDig, gsl::span< const o2::hmpid::Digit > digs, TMatrixF &pDigMap)
bool IsDigSurvive(Digit *pDig) const
HMPID Digit declaration.
Definition Digit.h:36
uint16_t getQ() const
Definition Digit.h:118
static void pad2Absolute(uint32_t pad, int *Module, int *x, int *y)
Definition Digit.cxx:211
GLint GLenum GLint x
Definition glcorearb.h:403
const GLfloat * m
Definition glcorearb.h:4066
GLint y
Definition glcorearb.h:270
Cluster clu
std::vector< Digit > digs