ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonValidation
MuonPRDTest
src
NswOccupancyAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3
*/
4
#include "
NswOccupancyAlg.h
"
5
#include <
StoreGate/ReadHandle.h
>
6
7
#include <TH1I.h>
8
#include <TH2I.h>
9
#include <set>
10
11
NswOccupancyAlg::NswOccupancyAlg
(
const
std::string& name, ISvcLocator* pSvcLocator):
12
AthHistogramAlgorithm
(name, pSvcLocator){}
13
14
StatusCode
NswOccupancyAlg::initialize
() {
15
ATH_CHECK
(
m_idHelperSvc
.retrieve());
16
ATH_CHECK
(
m_patternCollKey
.initialize());
17
std::stringstream selection_title{};
18
selection_title<<
"Bin size "
<<
m_binWidth
.value()<<
";"
;
19
selection_title<<
"Hit occupancy;"
;
20
m_singleBinOccupancy
=
new
TH1I(
"SingleBinOccupancy"
, selection_title.str().c_str(), 50, 0, 50);
21
m_pairBinOccupancy
=
new
TH1I(
"PairBinOccupancy"
, selection_title.str().c_str(), 50, 0, 50);
22
selection_title<<
"; Pair occupancy"
;
23
m_pairVsSingleOccupancy
=
new
TH2I(
"PairVsSingleOccupancy"
,selection_title.str().c_str(), 50,0,50,50,0,50);
24
std::stringstream folderName{};
25
folderName<<
"/"
<<
m_fileStream
.value()<<
"/OccupancyBinWidth"
<<
m_binWidth
.value()<<
"/"
;
26
ATH_MSG_INFO
(
"Write out histograms in "
<<folderName.str());
27
ATH_CHECK
(
histSvc
()->regHist(folderName.str() +
m_singleBinOccupancy
->GetName(),
m_singleBinOccupancy
));
28
ATH_CHECK
(
histSvc
()->regHist(folderName.str() +
m_pairBinOccupancy
->GetName(),
m_pairBinOccupancy
));
29
ATH_CHECK
(
histSvc
()->regHist(folderName.str() +
m_pairVsSingleOccupancy
->GetName(),
m_pairVsSingleOccupancy
));
30
31
return
StatusCode::SUCCESS;
32
}
33
StatusCode
NswOccupancyAlg::execute
(
const
EventContext& ctx) {
34
SG::ReadHandle<MuonPatternCombinationCollection>
pattCol{
m_patternCollKey
, ctx};
35
if
(!pattCol.
isValid
()){
36
ATH_MSG_FATAL
(
"Failed to retrieve the pattern collection "
<<
m_patternCollKey
.fullKey());
37
return
StatusCode::FAILURE;
38
}
39
40
for
(
const
Muon::MuonPatternCombination
* patComb : *pattCol ) {
42
std::map<unsigned int, Layer> sectorsHits{};
43
for
(
const
Muon::MuonPatternChamberIntersect
& it :patComb->chamberData()) {
44
if
(it.prepRawDataVec().empty())
continue
;
45
const
Identifier
id
= it.prepRawDataVec().front()->identify();
46
if
(!
m_idHelperSvc
->isMM(
id
) && !
m_idHelperSvc
->issTgc(
id
))
continue
;
47
Layer
& hitIds = sectorsHits[
m_idHelperSvc
->sector(
id
)];
48
hitIds.reserve(it.prepRawDataVec().size() + hitIds.size());
49
50
for
(
const
Trk::PrepRawData
* prd : it.prepRawDataVec()) {
51
if
(prd->type(
Trk::PrepRawDataType::MMPrepData
)) hitIds.push_back(prd->identify());
52
}
53
}
54
for
(
auto
& [sector, hitIds] : sectorsHits ) {
55
LayerVec
sortedHits =
sortByLayer
(hitIds);
56
for
(
Layer
& lay : sortedHits) {
57
fillHistograms
(lay);
58
}
59
}
60
}
61
62
return
StatusCode::SUCCESS;
63
}
64
std::vector<std::vector<Identifier>>
NswOccupancyAlg::sortByLayer
(
Layer
& micromegaHits)
const
{
65
LayerVec
layerVec;
66
std::stable_sort
(micromegaHits.begin(), micromegaHits.end(),[
this
](
const
Identifier
&
a
,
const
Identifier
& b){
67
return m_idHelperSvc->gasGapId(a) < m_idHelperSvc->gasGapId(b);
68
});
69
std::set<Identifier> unique_set{};
70
for
(
const
Identifier
&
id
: micromegaHits) {
71
if
(!unique_set.insert(
id
).second)
continue
;
72
if
(layerVec.empty() ||
m_idHelperSvc
->gasGapId(
id
) !=
m_idHelperSvc
->gasGapId(layerVec.back().back()) ){
73
layerVec.emplace_back();
74
layerVec.back().reserve(micromegaHits.size());
75
}
76
layerVec.back().push_back(
id
);
77
}
78
for
(
Layer
& lay : layerVec) {
79
std::sort
(lay.begin(),lay.end(),[
this
] (
const
Identifier
&
a
,
const
Identifier
& b){
80
return m_idHelperSvc->mmIdHelper().channel(a) < m_idHelperSvc->mmIdHelper().channel(b);
81
});
82
}
83
return
layerVec;
84
}
85
void
NswOccupancyAlg::fillHistograms
(
const
Layer
& clustInLay) {
86
if
(clustInLay.size() < 2)
return
;
87
std::vector<unsigned int>
histogram
{};
88
const
unsigned
int
firstCh =
m_idHelperSvc
->mmIdHelper().channel(clustInLay[0]);
89
const
unsigned
int
lastCh =
m_idHelperSvc
->mmIdHelper().channel(clustInLay[clustInLay.size() -1]);
91
const
unsigned
int
deltaCh = lastCh - firstCh;
92
const
unsigned
int
nBins = deltaCh /
m_binWidth
+ (deltaCh %
m_binWidth
> 0);
93
if
(!nBins)
return
;
94
histogram
.resize(nBins);
95
for
(
const
Identifier
&
id
: clustInLay) {
96
const
int
bin_num = (
m_idHelperSvc
->mmIdHelper().channel(
id
) - firstCh) %nBins;
97
++(
histogram
[bin_num]);
98
}
99
for
(
unsigned
int
occup :
histogram
){
100
if
(occup)
m_singleBinOccupancy
->Fill(occup);
101
}
102
for
(
unsigned
int
i = 0 ; i <
histogram
.size() -1 ; ++i){
103
unsigned
int
pair
=
histogram
[i]+
histogram
[i+1];
104
if
(!
pair
)
continue
;
105
m_pairBinOccupancy
->Fill(
pair
);
106
107
if
(
histogram
[i])
m_pairVsSingleOccupancy
->Fill(
histogram
[i],
pair
);
108
if
(
histogram
[i+1])
m_pairVsSingleOccupancy
->Fill(
histogram
[i+1],
pair
);
109
110
}
111
112
}
113
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition
AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
a
static Double_t a
Definition
LArPhysWaveHECTool.cxx:38
NswOccupancyAlg.h
ReadHandle.h
Handle class for reading from StoreGate.
histogram
std::string histogram
Definition
chains.cxx:52
AthHistogramAlgorithm::histSvc
const ServiceHandle< ITHistSvc > & histSvc() const
The standard THistSvc (for writing histograms and TTrees and more to a root file) Returns (kind of) a...
Definition
AthHistogramAlgorithm.h:113
AthHistogramAlgorithm::AthHistogramAlgorithm
AthHistogramAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Definition
AthHistogramAlgorithm.cxx:31
Muon::MuonPatternChamberIntersect
This class holds information needed for the Moore and MoMu pattern recognition for a muon chamber.
Definition
MuonPatternChamberIntersect.h:38
Muon::MuonPatternCombination
The MuonPatternCombination class provides the means to store the output of the initial global pattern...
Definition
MuonPatternCombination.h:29
NswOccupancyAlg::m_pairVsSingleOccupancy
TH1 * m_pairVsSingleOccupancy
Definition
NswOccupancyAlg.h:45
NswOccupancyAlg::LayerVec
std::vector< Layer > LayerVec
Definition
NswOccupancyAlg.h:26
NswOccupancyAlg::fillHistograms
void fillHistograms(const Layer &layers)
Definition
NswOccupancyAlg.cxx:85
NswOccupancyAlg::initialize
StatusCode initialize() override
Definition
NswOccupancyAlg.cxx:14
NswOccupancyAlg::m_fileStream
Gaudi::Property< std::string > m_fileStream
Definition
NswOccupancyAlg.h:40
NswOccupancyAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition
NswOccupancyAlg.h:22
NswOccupancyAlg::Layer
std::vector< Identifier > Layer
Definition
NswOccupancyAlg.h:25
NswOccupancyAlg::m_binWidth
Gaudi::Property< unsigned int > m_binWidth
Definition
NswOccupancyAlg.h:41
NswOccupancyAlg::sortByLayer
LayerVec sortByLayer(std::vector< Identifier > µmegaHits) const
Definition
NswOccupancyAlg.cxx:64
NswOccupancyAlg::m_singleBinOccupancy
TH1 * m_singleBinOccupancy
Definition
NswOccupancyAlg.h:43
NswOccupancyAlg::NswOccupancyAlg
NswOccupancyAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
NswOccupancyAlg.cxx:11
NswOccupancyAlg::execute
StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
NswOccupancyAlg.cxx:33
NswOccupancyAlg::m_patternCollKey
SG::ReadHandleKey< MuonPatternCombinationCollection > m_patternCollKey
Definition
NswOccupancyAlg.h:33
NswOccupancyAlg::m_pairBinOccupancy
TH1 * m_pairBinOccupancy
Definition
NswOccupancyAlg.h:44
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Trk::PrepRawData
Definition
PrepRawData.h:62
pair
STL class.
Identifier
Definition
IdentifierFieldParser.cxx:14
Trk::PrepRawDataType::MMPrepData
@ MMPrepData
Definition
PrepRawData.h:49
std::sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition
DVL_algorithms.h:554
std::stable_sort
void stable_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > end)
Specialization of stable_sort for DataVector/List.
Definition
DVL_algorithms.h:644
Generated on
for ATLAS Offline Software by
1.17.0