ATLAS Offline Software
MM_StripResponse.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 MM_StripResponse::MM_StripResponse(std::vector<std::unique_ptr<MM_IonizationCluster>>& IonizationClusters, float timeResolution,
8  float stripPitch, int stripID, int minstripID, int maxstripID) :
9  m_timeResolution(timeResolution), m_stripPitch(stripPitch), m_stripID(stripID), m_minstripID(minstripID), m_maxstripID(maxstripID) {
10  for (auto& IonizationCluster : IonizationClusters)
11  for (auto& Electron : IonizationCluster->getElectrons()) m_Electrons.push_back(std::move(Electron));
12 }
13 
14 int MM_StripResponse::getNElectrons() const { return m_Electrons.size(); }
15 
17  float qtot = 0;
18  for (const std::unique_ptr<MM_Electron>& electron : m_Electrons) { qtot += electron->getCharge(); }
19  return qtot;
20 }
21 
22 std::vector<std::unique_ptr<MM_Electron>>& MM_StripResponse::getElectrons() { return m_Electrons; }
23 
25  std::sort(
26  m_Electrons.begin(), m_Electrons.end(),
27  [](const std::unique_ptr<MM_Electron>& a, const std::unique_ptr<MM_Electron>& b) -> bool { return a->getTime() < b->getTime(); });
28 }
29 
30 void MM_StripResponse::calculateTimeSeries(float /*thetaD*/, int /*gasgap*/) {
31  for (auto& Electron : m_Electrons) {
32  int timeBin = (int)(Electron->getTime() / m_timeResolution);
33  // m_stripID defines the initial strip where the muon entered the gas gap
34 
35  int stripVal = 0;
36  if (std::abs(Electron->getX()) > m_stripPitch / 2) {
37  if (Electron->getX() > 0.0)
38  stripVal = m_stripID + int((Electron->getX() - m_stripPitch / 2) / m_stripPitch) + 1;
39  else
40  stripVal = m_stripID + int((Electron->getX() + m_stripPitch / 2) / m_stripPitch) - 1;
41  } else
42  stripVal = m_stripID;
43 
44  // Only add the strips that are either read out, or can cross talk to the read out strips
45  if (stripVal < m_minstripID - 2 || stripVal > m_maxstripID + 1) stripVal = -1;
46  if (stripVal > 0) m_stripCharges[timeBin][stripVal] += Electron->getCharge();
47  }
48 }
49 
50 void MM_StripResponse::simulateCrossTalk(float crossTalk1, float crossTalk2) {
51  // if no cross talk is simulate just skip everything and keep m_stripCharges as it was
52  if (crossTalk1 > 0.) {
53  // Unfortunately get stuck in the loop if you edit the map in the loop
54  // So make a copy!
55 
56  std::map<int, std::map<int, float>> stripChargesCopy1;
57  stripChargesCopy1.insert(m_stripCharges.begin(), m_stripCharges.end());
58 
59  // clear strip charge map since charge on the main strip needs to be scaled
60  m_stripCharges.clear();
61 
62  for (auto& stripTimeSeries : stripChargesCopy1) {
63  int timeBin = stripTimeSeries.first;
64  for (auto& stripCharge : stripTimeSeries.second) {
65  int stripVal = stripCharge.first;
66  float stripChargeVal = stripCharge.second;
67 
68  if (stripChargeVal == 0.) continue;
69 
70  // scale factcor for the charge on the main strip to account for the cross talk charge
71  float chargeScaleFactor = 1.0 / (1. + ((stripVal - 1 > 0) + (stripVal + 1 < m_maxstripID)) * crossTalk1 +
72  ((stripVal - 2 > 0) + (stripVal + 2 < m_maxstripID)) * crossTalk2);
73  stripChargeVal *= chargeScaleFactor;
74 
75  m_stripCharges[timeBin][stripVal] += stripChargeVal;
76 
77  // Allow crosstalk between strips that exist.
78  // Will check for read out strips in calculateSummaries function
79  if (stripVal - 1 > 0) m_stripCharges[timeBin][stripVal - 1] += stripChargeVal * crossTalk1;
80  if (stripVal + 1 < m_maxstripID) m_stripCharges[timeBin][stripVal + 1] += stripChargeVal * crossTalk1;
81 
82  if (crossTalk2 > 0.) {
83  if (stripVal - 2 > 0) m_stripCharges[timeBin][stripVal - 2] += stripChargeVal * crossTalk2;
84  if (stripVal + 2 < m_maxstripID) m_stripCharges[timeBin][stripVal + 2] += stripChargeVal * crossTalk2;
85  }
86  }
87  }
88  }
89 }
90 
91 void MM_StripResponse::calculateSummaries(float chargeThreshold) {
92  std::map<int, std::map<int, float>> stripChargesCopy2;
93  stripChargesCopy2.insert(m_stripCharges.begin(), m_stripCharges.end());
94  for (auto& stripTimeSeries : stripChargesCopy2) {
95  int timeBin = stripTimeSeries.first;
96  for (auto& stripCharge : stripTimeSeries.second) {
97  int stripVal = stripCharge.first;
98  // remove dead (missing) strips
99  // First active strip starts at m_minstripID
100  // Last active strip numbrer is maxStripID-1
101  if (stripVal < m_minstripID || stripVal > m_maxstripID - 1) continue;
102  // remove PCB gap strips
103  if (stripVal == 1024 || stripVal == 1025 || stripVal == 2048 || stripVal == 2049 || stripVal == 3072 || stripVal == 3073 ||
104  stripVal == 4096 || stripVal == 4097)
105  continue;
106  float stripChargeVal = stripCharge.second;
107  if (stripChargeVal < chargeThreshold) continue;
108 
109  bool found = false;
110  for (size_t ii = 0; ii < m_v_strip.size(); ii++) {
111  if (m_v_strip.at(ii) == stripVal) {
112  m_v_stripTimeThreshold.at(ii).push_back(timeBin * m_timeResolution);
113  m_v_stripTotalCharge.at(ii).push_back(stripChargeVal);
114  found = true;
115  break;
116  }
117  }
118  if (!found) { // // strip not in vector, add new entry
119  m_v_strip.push_back(stripVal);
120  std::vector<float> qTemp;
121  qTemp.push_back(stripChargeVal);
122  m_v_stripTotalCharge.push_back(qTemp);
123  std::vector<float> tTemp;
124  tTemp.push_back(timeBin * m_timeResolution);
125  m_v_stripTimeThreshold.push_back(tTemp);
126  }
127  }
128  }
129 }
130 
131 // accessors
132 const std::map<int, int>& MM_StripResponse::getTimeThreshold() const { return m_stripTimeThreshold; }
133 const std::map<int, float>& MM_StripResponse::getTotalCharge() const { return m_stripTotalCharge; }
134 const std::map<int, float>& MM_StripResponse::getMaxCharge() const { return m_stripMaxCharge; }
135 const std::map<int, int>& MM_StripResponse::getTimeMaxCharge() const { return m_stripTimeMaxCharge; }
136 const std::vector<int>& MM_StripResponse::getStripVec() const { return m_v_strip; }
137 const std::vector<std::vector<float>>& MM_StripResponse::getTimeThresholdVec() const { return m_v_stripTimeThreshold; }
138 const std::vector<std::vector<float>>& MM_StripResponse::getTotalChargeVec() const { return m_v_stripTotalCharge; }
139 const std::vector<float>& MM_StripResponse::getMaxChargeVec() const { return m_v_stripMaxCharge; }
140 const std::vector<float>& MM_StripResponse::getTimeMaxChargeVec() const { return m_v_stripTimeMaxCharge; }
MM_StripResponse::m_v_stripTimeMaxCharge
std::vector< float > m_v_stripTimeMaxCharge
Definition: MM_StripResponse.h:68
MM_StripResponse::getTimeThresholdVec
const std::vector< std::vector< float > > & getTimeThresholdVec() const
Definition: MM_StripResponse.cxx:137
MM_StripResponse::m_timeResolution
float m_timeResolution
Definition: MM_StripResponse.h:46
MM_StripResponse::m_stripPitch
float m_stripPitch
Definition: MM_StripResponse.h:47
MM_StripResponse::getTimeThreshold
const std::map< int, int > & getTimeThreshold() const
Definition: MM_StripResponse.cxx:132
MM_StripResponse::m_stripMaxCharge
std::map< int, float > m_stripMaxCharge
Definition: MM_StripResponse.h:60
MM_StripResponse::getMaxChargeVec
const std::vector< float > & getMaxChargeVec() const
Definition: MM_StripResponse.cxx:139
MM_StripResponse::calculateSummaries
void calculateSummaries(float chargeThreshold)
Definition: MM_StripResponse.cxx:91
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
MM_StripResponse::calculateTimeSeries
void calculateTimeSeries(float thetaD, int gasgap)
Definition: MM_StripResponse.cxx:30
MM_StripResponse::getTotalCharge
const std::map< int, float > & getTotalCharge() const
Definition: MM_StripResponse.cxx:133
MM_StripResponse::m_v_stripTotalCharge
std::vector< std::vector< float > > m_v_stripTotalCharge
Definition: MM_StripResponse.h:66
MM_StripResponse::getTotalChargeVec
const std::vector< std::vector< float > > & getTotalChargeVec() const
Definition: MM_StripResponse.cxx:138
MM_StripResponse::m_v_stripTimeThreshold
std::vector< std::vector< float > > m_v_stripTimeThreshold
Definition: MM_StripResponse.h:65
MM_StripResponse::getStripVec
const std::vector< int > & getStripVec() const
Definition: MM_StripResponse.cxx:136
MM_StripResponse::MM_StripResponse
MM_StripResponse()=default
MM_StripResponse::totalCharge
float totalCharge() const
Definition: MM_StripResponse.cxx:16
MM_StripResponse::m_stripID
int m_stripID
Definition: MM_StripResponse.h:48
MM_StripResponse::m_stripTotalCharge
std::map< int, float > m_stripTotalCharge
Definition: MM_StripResponse.h:59
MM_StripResponse::timeOrderElectrons
void timeOrderElectrons()
Definition: MM_StripResponse.cxx:24
MM_StripResponse::getMaxCharge
const std::map< int, float > & getMaxCharge() const
Definition: MM_StripResponse.cxx:134
MM_StripResponse::simulateCrossTalk
void simulateCrossTalk(float crossTalk1, float crossTalk2)
Definition: MM_StripResponse.cxx:50
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
MM_StripResponse::getElectrons
std::vector< std::unique_ptr< MM_Electron > > & getElectrons()
Definition: MM_StripResponse.cxx:22
MM_StripResponse::m_stripTimeThreshold
std::map< int, int > m_stripTimeThreshold
Definition: MM_StripResponse.h:58
MM_StripResponse::getTimeMaxCharge
const std::map< int, int > & getTimeMaxCharge() const
Definition: MM_StripResponse.cxx:135
a
TList * a
Definition: liststreamerinfos.cxx:10
MM_StripResponse::m_Electrons
std::vector< std::unique_ptr< MM_Electron > > m_Electrons
Definition: MM_StripResponse.h:52
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
MM_StripResponse.h
MM_StripResponse::getTimeMaxChargeVec
const std::vector< float > & getTimeMaxChargeVec() const
Definition: MM_StripResponse.cxx:140
Electron
Class describing an electron.
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
MM_StripResponse::m_maxstripID
int m_maxstripID
Definition: MM_StripResponse.h:50
MM_StripResponse::getNElectrons
int getNElectrons() const
Definition: MM_StripResponse.cxx:14
MM_StripResponse::m_stripTimeMaxCharge
std::map< int, int > m_stripTimeMaxCharge
Definition: MM_StripResponse.h:61
MM_StripResponse::m_stripCharges
std::map< int, std::map< int, float > > m_stripCharges
Definition: MM_StripResponse.h:55
MM_StripResponse::m_v_stripMaxCharge
std::vector< float > m_v_stripMaxCharge
Definition: MM_StripResponse.h:67
MM_StripResponse::m_v_strip
std::vector< int > m_v_strip
Definition: MM_StripResponse.h:64