ATLAS Offline Software
CscAverage.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // a class to fit CSC strips in a plane into clusters //
7 // //
8 // BNL March 26 2003 --- Ketevi A. Assamagan //
10 
11 #include "CscAverage.h"
12 
13 #include <algorithm>
14 #include <cassert>
15 #include <cmath>
16 #include <map>
17 #include <vector>
18 
20  m_msgSvc = nullptr;
21  ISvcLocator* svcLocator = Gaudi::svcLocator();
22  StatusCode sc = svcLocator->service("MessageSvc", m_msgSvc);
23  if (sc.isFailure()) std::cout << "CscAverage::Fail to locate Message Service" << std::endl;
24 }
25 
26 void CscAverage::cscaverage(const double* qstr, int& NStrip, double& thr, double& da, int& ncl, double* sig, double* zpos, double& noise) {
27  MsgStream mLog(m_msgSvc, "CscAverage");
28 
30 
31  bool cluster_found = false;
32  std::map<unsigned int, std::vector<int> > clusters;
33  unsigned int NClusters = 1;
34 
35  int L = NStrip;
36 
41  for (int is = 0; is < L; ++is) {
42  if (qstr[is] > thr) {
43  cluster_found = true;
44  clusters[NClusters].push_back(is);
45  } else if (cluster_found) {
46  cluster_found = false;
47  ++NClusters;
48  }
49  }
50 
51  ncl = (int)clusters.size();
52 
53  // Loop on clusters and calculate their position
54  for (std::map<unsigned int, std::vector<int> >::const_iterator ic = clusters.begin(); ic != clusters.end(); ++ic) {
56  double sum = 0.;
57  double tcharge = 0.;
58  double tcharge2 = 0.;
59  int count = 0;
60  int maxStrip = -1;
61  double maxCharge = 0;
62  double maxPos = -1000.0;
63  double avg = maxPos;
64 
66  for (std::vector<int>::const_iterator d = (*ic).second.begin(); d != (*ic).second.end(); ++d) {
67  if (qstr[*d] > maxCharge) {
68  maxStrip = *d;
69  maxCharge = qstr[*d];
70  }
71  }
72 
74  for (int i = maxStrip - 1; i <= maxStrip + 1; ++i) {
75  if (i >= 0 && i < L) {
76  double w = qstr[i];
77  sum += da * (i + 0.5 - L / 2) * w;
78  tcharge += w;
79  count++;
80  tcharge2 += count * count;
81  }
82  }
83  if (tcharge > 0) avg = sum / tcharge;
84 
87  if (maxStrip >= 0) maxPos = da * (maxStrip + 0.5 - L / 2);
88 
91  // MS 07-02-2013: remove this section to fix compiler warning:
92  // warning: variable 'ratio' set but not used [-Wunused-but-set-variable]
93  /*****************************************
94  double ratio = avg;
95  if ( (maxStrip-1)>=0 && (maxStrip+1) < L) {
96  double a = qstr[maxStrip-1];
97  double b = qstr[maxStrip];
98  double c = qstr[maxStrip+1];
99  double r = (c-a)/(a+b+c); // raw value
100  if (fabs(r)<0.4)
101  ratio = maxPos + da*( 1.29209*r -7.84829*std::pow(r, 5) +25.6318*std::pow(r, 7) );
102  else
103  ratio = maxPos + da *( 1.27790*r -20.9485*std::pow(r, 7) );
104  }
105  *************************************/
106 
109  *(zpos + (*ic).first - 1) = avg;
110  if (count > 1 && tcharge > 0)
111  *(sig + (*ic).first - 1) = noise * (da / (tcharge)) * sqrt(2.0 * tcharge2); // page 204 of Muon TDR!
112  else
113  *(sig + (*ic).first - 1) = da / sqrt(12.0);
114  if (L < 92) *(sig + (*ic).first - 1) = da / sqrt(12.0);
115  }
116 }
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
hist_file_dump.d
d
Definition: hist_file_dump.py:137
CscAverage::CscAverage
CscAverage()
Definition: CscAverage.cxx:19
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Recovery.avg
def avg(a, b)
Definition: Recovery.py:79
python.BuildSignatureFlags.sig
sig
Definition: BuildSignatureFlags.py:215
grepfile.ic
int ic
Definition: grepfile.py:33
CscAverage::m_msgSvc
IMessageSvc * m_msgSvc
Definition: CscAverage.h:31
dumpNswErrorDb.maxStrip
tuple maxStrip
Definition: dumpNswErrorDb.py:27
CscAverage.h
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
WriteCellNoiseToCool.noise
noise
Definition: WriteCellNoiseToCool.py:380
CscAverage::cscaverage
void cscaverage(const double *qstr, int &NStrip, double &thr, double &da, int &ncl, double *sig, double *zpos, double &noise)
Definition: CscAverage.cxx:26