@@ -31,6 +31,45 @@ Clusterizer::Clusterizer(bool applyCorrectionZ, bool applyCorrectionE)
3131 mDigitIndices .resize (geo.getNrows (), std::vector<int >(geo.getNcols (), -1 ));
3232 mApplyCorrectionZ = applyCorrectionZ;
3333 mApplyCorrectionE = applyCorrectionE;
34+
35+ mCrystalEnergyCorrectionPars .reserve (6 );
36+ mCrystalEnergyCorrectionPars [0 ] = 0.00444 ;
37+ mCrystalEnergyCorrectionPars [1 ] = -1.322 ;
38+ mCrystalEnergyCorrectionPars [2 ] = 1.021 ;
39+ mCrystalEnergyCorrectionPars [3 ] = 0.0018 ;
40+ mCrystalEnergyCorrectionPars [4 ] = 0 .;
41+ mCrystalEnergyCorrectionPars [5 ] = 0 .;
42+
43+ mSamplingEnergyCorrectionPars .reserve (6 );
44+ mSamplingEnergyCorrectionPars [0 ] = 0.0033 ;
45+ mSamplingEnergyCorrectionPars [1 ] = -2.09 ;
46+ mSamplingEnergyCorrectionPars [2 ] = 1.007 ;
47+ mSamplingEnergyCorrectionPars [3 ] = 0.0667 ;
48+ mSamplingEnergyCorrectionPars [4 ] = -0.108 ;
49+ mSamplingEnergyCorrectionPars [5 ] = 0.0566 ;
50+
51+ mCrystalZCorrectionPars .reserve (9 );
52+ mCrystalZCorrectionPars [0 ] = -0.005187 ;
53+ mCrystalZCorrectionPars [1 ] = 0.7301 ;
54+ mCrystalZCorrectionPars [2 ] = -0.7382 ;
55+ mCrystalZCorrectionPars [3 ] = 0 .;
56+ mCrystalZCorrectionPars [4 ] = 0 .;
57+ mCrystalZCorrectionPars [5 ] = 0 .;
58+ mCrystalZCorrectionPars [6 ] = 0 .;
59+ mCrystalZCorrectionPars [7 ] = 0 .;
60+ mCrystalZCorrectionPars [8 ] = 0 .;
61+
62+ mSamplingZCorrectionPars .reserve (9 );
63+ mSamplingZCorrectionPars [0 ] = -2.137 ;
64+ mSamplingZCorrectionPars [1 ] = 6.400 ;
65+ mSamplingZCorrectionPars [2 ] = -3.342 ;
66+ mSamplingZCorrectionPars [3 ] = -0.1364 ;
67+ mSamplingZCorrectionPars [4 ] = 0.4019 ;
68+ mSamplingZCorrectionPars [5 ] = -0.1969 ;
69+ mSamplingZCorrectionPars [6 ] = 0.008223 ;
70+ mSamplingZCorrectionPars [7 ] = -0.02425 ;
71+ mSamplingZCorrectionPars [8 ] = 0.01190 ;
72+
3473 fCrystalShowerShape = new TF1 (" fCrystal" , " x<[1] ? [0]*exp([3]*x+[4]*x*x+[5]*x*x*x) : (x<[2] ? [0]*[6]*exp([7]*x+[8]*x*x) : [0]*[9]*exp([10]*x+[11]*x*x))" , 0 , 15 );
3574 double pc[12 ];
3675 pc[0 ] = 1 . / 13.15 ;
@@ -94,22 +133,24 @@ void Clusterizer::findClusters(const gsl::span<const Digit>& digits, std::vector
94133void Clusterizer::addDigitToCluster (Cluster& cluster, int row, int col, const gsl::span<const Digit>& digits)
95134{
96135 auto & geo = Geometry::instance ();
97- if (row < 0 || row >= geo.getNrows () || col < 0 || col >= geo.getNcols ())
136+ if (row < 0 || row >= geo.getNrows () || col < 0 || col >= geo.getNcols ()) {
98137 return ;
138+ }
99139 int digitIndex = mDigitIndices [row][col];
100140 LOGP (debug, " checking row={} and col={} digitIndex={}" , row, col, digitIndex);
101- if (digitIndex < 0 )
141+ if (digitIndex < 0 ) {
102142 return ;
103-
143+ }
104144 const Digit& digit = digits[digitIndex];
105145 if (cluster.getMultiplicity () > 0 ) {
106146 // check if new digit is in the same chamber and sector
107147 const Digit& digit2 = digits[cluster.getDigitIndex (0 )];
108148 auto [sector1, ch1] = geo.getSectorChamber (digit.getTower ());
109149 auto [sector2, ch2] = geo.getSectorChamber (digit2.getTower ());
110150 LOGP (debug, " checking if sector and chamber are the same: ({},{}) ({},{})" , sector1, ch1, sector2, ch2);
111- if (sector1 != sector2 || ch1 != ch2)
151+ if (sector1 != sector2 || ch1 != ch2) {
112152 return ;
153+ }
113154 }
114155
115156 mDigitIndices [row][col] = -1 ;
@@ -140,11 +181,13 @@ void Clusterizer::makeClusters(const gsl::span<const Digit>& digits, std::vector
140181 auto [row, col] = geo.globalRowColFromIndex (digit.getTower ());
141182 bool isCrystal = geo.isCrystal (digit.getTower ());
142183 if (isCrystal) {
143- if (digit.getEnergy () < mCrystalDigitThreshold )
184+ if (digit.getEnergy () < mCrystalDigitThreshold ) {
144185 continue ;
186+ }
145187 } else {
146- if (digit.getEnergy () < mSamplingDigitThreshold )
188+ if (digit.getEnergy () < mSamplingDigitThreshold ) {
147189 continue ;
190+ }
148191 }
149192 mDigitIndices [row][col] = i;
150193 }
@@ -153,10 +196,12 @@ void Clusterizer::makeClusters(const gsl::span<const Digit>& digits, std::vector
153196 for (int i = 0 ; i < nDigits; i++) {
154197 const Digit& digitSeed = digits[i];
155198 auto [row, col] = geo.globalRowColFromIndex (digitSeed.getTower ());
156- if (mDigitIndices [row][col] < 0 )
199+ if (mDigitIndices [row][col] < 0 ) {
157200 continue ; // digit was already added in one of the clusters
158- if (digitSeed.getEnergy () < mClusteringThreshold )
201+ }
202+ if (digitSeed.getEnergy () < mClusteringThreshold ) {
159203 continue ;
204+ }
160205 LOGP (debug, " starting new cluster at row={} and col={}" , row, col);
161206 auto & cluster = clusters.emplace_back ();
162207 addDigitToCluster (cluster, row, col, digits);
@@ -343,8 +388,9 @@ void Clusterizer::evalClusters(std::vector<Cluster>& clusters)
343388 double xi, yi, zi;
344389 geo.detIdToGlobalPosition (towerId, xi, yi, zi);
345390 double r = std::sqrt ((x - xi) * (x - xi) + (y - yi) * (y - yi) + (z - zi) * (z - zi));
346- if (r > 2.2 )
391+ if (r > 2.2 ) {
347392 continue ;
393+ }
348394 double frac = fCrystalShowerShape ->Eval (r);
349395 double rms = fCrystalRMS ->Eval (r);
350396 chi2 += std::pow ((energy / ee - frac) / rms, 2 .);
@@ -354,38 +400,30 @@ void Clusterizer::evalClusters(std::vector<Cluster>& clusters)
354400
355401 // correct cluster energy and z position
356402 float eta = std::abs (cluster.getEta ());
357- float eCor = 1 ;
358- float zCor = 0 ;
359403 bool isCrystal = geo.isCrystal (cluster.getDigitTowerId (0 ));
360- if (isCrystal) {
361- eCor = 0.00444 * std::pow (ee, -1.322 ) + (1.021 + 0.0018 * eta);
362- if (mApplyCorrectionE )
363- ee *= eCor;
364- if (mApplyCorrectionZ )
365- zCor = (-0.00518682 + 0.730052 * eta - 0.73817 * eta * eta);
366- } else {
367- eCor = 0.0033 * std::pow (ee, -2.09 ) + (1.007 + 0.0667 * eta - 0.108 * eta * eta + 0.0566 * eta * eta * eta);
368- if (mApplyCorrectionE )
369- ee *= eCor;
370- if (mApplyCorrectionZ )
371- zCor = (-2.13679 + 6.40009 * eta - 3.34233 * eta * eta) + (-0.136425 + 0.401887 * eta - 0.196851 * eta * eta) * ee + (0.00822276 - 0.0242512 * eta + 0.0118986 * eta * eta) * ee * ee;
404+ if (mApplyCorrectionE ) {
405+ std::vector<double >& pe = isCrystal ? mCrystalEnergyCorrectionPars : mSamplingEnergyCorrectionPars ;
406+ ee *= pe[0 ] * std::pow (ee, pe[1 ]) + pe[2 ] + pe[3 ] * eta + pe[4 ] * eta * eta + pe[5 ] * eta * eta * eta;
407+ cluster.setE (ee);
408+ }
409+ if (mApplyCorrectionZ ) {
410+ std::vector<double >& pz = isCrystal ? mCrystalZCorrectionPars : mSamplingZCorrectionPars ;
411+ float zCor = (pz[0 ] + pz[1 ] * eta + pz[2 ] * eta * eta) + (pz[3 ] + pz[4 ] * eta + pz[5 ] * eta * eta) * ee + (pz[6 ] + pz[7 ] * eta + pz[8 ] * eta * eta) * ee * ee;
412+ cluster.setZ (z > 0 ? z - zCor : z + zCor);
372413 }
373-
374- cluster.setE (ee);
375- cluster.setZ (cluster.getZ () - zCor);
376414
377415 // check if cluster is at the edge of detector module
378416 bool isEdge = 0 ;
379417 for (size_t i = 0 ; i < cluster.getMultiplicity (); i++) {
380418 int towerId = cluster.getDigitTowerId (i);
381- if (! geo.isAtTheEdge (towerId))
382- continue ;
383- isEdge = 1 ;
384- break ;
419+ if (geo.isAtTheEdge (towerId)) {
420+ isEdge = 1 ;
421+ break ;
422+ }
385423 }
386424 cluster.setEdgeFlag (isEdge);
387425
388- LOGF (debug, " Cluster coordinates: (%6.2f,%6.2f,%6.2f), eCor=%6.2f zCor=%6.2f " , cluster.getX (), cluster.getY (), cluster.getZ (), eCor, zCor );
426+ LOGF (debug, " Cluster coordinates: (%6.2f,%6.2f,%6.2f)" , cluster.getX (), cluster.getY (), cluster.getZ ());
389427 }
390428}
391429
@@ -403,8 +441,9 @@ int Clusterizer::getNumberOfLocalMax(Cluster& clu, int* maxAt, float* maxAtEnerg
403441 for (int i = 0 ; i < n; i++) {
404442 isLocalMax[i] = false ;
405443 float en1 = clu.getDigitEnergy (i);
406- if (en1 > mClusteringThreshold )
444+ if (en1 > mClusteringThreshold ) {
407445 isLocalMax[i] = true ;
446+ }
408447 }
409448
410449 for (int i = 0 ; i < n; i++) {
0 commit comments