ATLAS Offline Software
Loading...
Searching...
No Matches
MdtVsTgcRawData_TGCEffCheck.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
6// Package : MdtVsTgcRawDataValAlg
7// Author: M.King(Kobe)
8// Feb. 2011
9//
10// DESCRIPTION:
11// Subject: TGC Efficiency -->TGC Efficiency plots including EIFI by comparing with MDT Segments
13
15
20//use new MDT segment container
23
24#include <TH2.h>
25#include <TList.h>
26#include <inttypes.h>
27
28#include <sstream>
29#include <algorithm>
30#include <fstream>
31
32// Function to generate TGC efficiency histograms
33// Selects valid segments and attempts to match them into a track, then looks for TGC hits in the various layers
34//New to calculate the efficiency
35void
37 const Muon::TgcPrepDataContainer *tgc_prepcontainer){
38 ATH_MSG_DEBUG("inside tgcEIFIeffcalc" );
40 // Declare vector arrays to hold segment pointers
41
42 // Holds Segments sorted into MDT Stations on each side
43 std::vector<const Muon::MuonSegment*> sortedSegments[2][4]; //[AC][MDTStation]
44
45 // Holds Segments which have been disqualified, any segments in this array are ignored when looping through sortedSegments
46 std::vector<const Muon::MuonSegment*> DQdisqualifiedSegments[2][4]; //[AC][MDTStation] // Segments which have been disqualified by DQ
47 std::vector<const Muon::MuonSegment*> MATCHdisqualifiedSegments[2][4];//[AC][MDTStation] // Segments which have been disqualified by DQ or already been included in a track
48
49 // Holds Segments which have been matched into a track
50 std::vector<SegmTrack> matchedSegments[2]; //[AC]
51
52
54 // Sort and filter Segments
55
56 // Sort Segments from segmcollection into correct bin in sortedSegments array
57 SortMDTSegments(newmdtsegment, sortedSegments);
58 // Disqualify Segments with bad DQ
59 DQCheckMDTSegments(sortedSegments, DQdisqualifiedSegments);
60 for(int i=0;i<2;i++){
61 for(int jMDT=0;jMDT<4;jMDT++){
62 MATCHdisqualifiedSegments[i][jMDT] = DQdisqualifiedSegments[i][jMDT];
63 }
64 }
65
66
68 // Segment Track Method
69 // Match up Segments into tracks
70 MatchMDTSegments(sortedSegments, MATCHdisqualifiedSegments, matchedSegments);
71 // Use tracks to look for TGC hits
72 CheckTGConTrack(matchedSegments, tgc_prepcontainer);
73
74
76 // Midstation-only Method
77
78 // Use segments to check Midstation again
79 MidstationOnlyCheck(sortedSegments, DQdisqualifiedSegments, tgc_prepcontainer);
80
81 return;
82}// End of function
83
84// Prepare array of TGC Readout Elements
85void
87 int TGCStationNames[8]={41, 42, 43, 44, 45, 46, 47, 48};
88
89 // Make array of TGC Readout Element pointers
90 for(int stationNameIndex=0; stationNameIndex<8; stationNameIndex++){// Station Name
91 int stationName = TGCStationNames[stationNameIndex];
92 for(int stationEta=-8; stationEta<=8; stationEta++){// Station Eta
93 int tgcAC(stationEta<0);
94 int absStationEta = std::abs(stationEta);
95 for(int stationPhi=0; stationPhi<=48; stationPhi++){// Station Phi
96 // Exclude non-existent "zero" sectors included in the array for ease of use
97 if(stationEta==0){
98 m_TREarray[stationNameIndex][0][absStationEta][stationPhi]=nullptr;
99 m_TREarray[stationNameIndex][1][absStationEta][stationPhi]=nullptr;
100 continue;
101 }
102 m_TREarray[stationNameIndex][tgcAC][absStationEta][stationPhi]=nullptr;
103 if(stationPhi==0)continue;
104
105 // Exclude sectors known not to exist
106 if(stationNameIndex==6){ // Inner Forward
107 if(std::abs(stationEta)>1)continue;
108 if(stationPhi>24)continue;
109 }
110 else if(stationNameIndex==7){ // Inner Endcap
111 if(std::abs(stationEta)>1)continue;
112 if(stationPhi>21)continue;
113 }
114 else if((stationNameIndex==0)|| // Midstation Forward
115 (stationNameIndex==2)||
116 (stationNameIndex==4)){
117 if(std::abs(stationEta)>1)continue;
118 if(stationPhi>24)continue;
119 }
120 else{ // Midstation Endcap
121 if(std::abs(stationEta)>5)continue;
122 if((stationNameIndex==1)&&
123 (std::abs(stationEta)>4))continue;
124 }
125
126 // Get identifier of TRE at this set of indexes
127 bool isValid{false};
128 Identifier tgc_testId = m_idHelperSvc->tgcIdHelper().elementID(stationName, stationEta, stationPhi, isValid);
129 if(!isValid){continue;}
130
131 // Get TRE and put into to array
132 m_TREarray[stationNameIndex][tgcAC][absStationEta][stationPhi] = MuonDetMgrDS->getTgcReadoutElement(tgc_testId);
133 if(m_TREarray[stationNameIndex][tgcAC][absStationEta][stationPhi]==nullptr){
134 ATH_MSG_WARNING( "prepareTREarray: TgcReadoutElement==0 passed checks" );
135 continue;
136 }
137 }// Station Phi
138 }// Station Eta
139 }// Station Name
140 return;
141}// End of function
142
143// Finalize histograms which need post processing
144void
146 int beff, bdenom, berror;
147 float feff, fdenom;
148 for(int i=0;i<2;i++){// AC
149 // Station Coordinate Efficiency Histograms
150 for(int k=0;k<2;k++){// WireStrip
151 // Loop Numerator and Denominator, total up histograms
152 for(int e=1;e<3;e++){
153 TList histlist;
154 histlist.Add(m_eff_stationmapbase[i][k][e]);
155 histlist.Add(m_eff_stationmapmid[i][k][e]);
156 m_eff_stationmap[i][k][e]->Merge(&histlist);
157 }
158
159 const int nhtypes = 3;
160 // Make array of pointers to different efficiency histogram types
161 TH2 *histarray[nhtypes][4] = {{ m_eff_stationmapbase[i][k][0], m_eff_stationmapbase[i][k][1], m_eff_stationmapbase[i][k][2], m_eff_stationmapbase[i][k][3]},
162 { m_eff_stationmapmid[i][k][0], m_eff_stationmapmid[i][k][1], m_eff_stationmapmid[i][k][2], m_eff_stationmapmid[i][k][3]},
163 { m_eff_stationmap[i][k][0], m_eff_stationmap[i][k][1], m_eff_stationmap[i][k][2], m_eff_stationmap[i][k][3]}};
164 for(int h=0;h<nhtypes;h++){
165 // Calculate Efficiency
166 histarray[h][0]->Divide(histarray[h][1], histarray[h][2]);
167
168 // Calculate Error
169 int nX=histarray[h][3]->GetNbinsX();
170 int nY=histarray[h][3]->GetNbinsY();
171 for(int x=1;x<=nX;x++){
172 for(int y=1;y<=nY;y++){
173 beff =histarray[h][0]->GetBin(x,y);
174 bdenom=histarray[h][2]->GetBin(x,y);
175 berror=histarray[h][3]->GetBin(x,y);
176
177 feff =histarray[h][0]->GetBinContent(beff);
178 fdenom=histarray[h][2]->GetBinContent(bdenom);
179
180 float result = 0;
181 if(fdenom>0){
182 result=sqrt(feff*(1-feff)/fdenom);
183 }
184 histarray[h][3]->SetBinContent(berror,result);
185 }// nY Bins
186 }// nX Bins
187 }
188 }// WireStrip
189 }// AC
190
191 return;
192}// End of function
193
194// Get TGC layer number from stationName and gasgap values
195int
197 if(g<1){
198 ATH_MSG_WARNING( "TGCgetlayer passed invalid gasgap g=" << g );
199 return -1;
200 }
201 int l = g-1;
202 if(stationName==41||stationName==42){
203 if(g>3){
204 ATH_MSG_WARNING( "TGCgetlayer passed invalid gasgap and stationName combination n=" << stationName << " g=" << g );
205 return -1;
206 }
207 }else if(stationName==43||stationName==44){
208 if(g>2){
209 ATH_MSG_WARNING( "TGCgetlayer passed invalid gasgap and stationName combination n=" << stationName << " g=" << g );
210 return -1;
211 }
212 l+=3;
213 }else if(stationName==45||stationName==46){
214 if(g>2){
215 ATH_MSG_WARNING( "TGCgetlayer passed invalid gasgap and stationName combination n=" << stationName << " g=" << g );
216 return -1;
217 }
218 l+=5;
219 }else if(stationName==47||stationName==48){
220 if(g>2){
221 ATH_MSG_WARNING( "TGCgetlayer passed invalid gasgap and stationName combination n=" << stationName << " g=" << g );
222 return -1;
223 }
224 l+=7;
225 }else{
226 ATH_MSG_WARNING( "TGCgetlayer passed invalid stationName n=" << stationName );
227 return -1;
228 }
229 return l;
230}// End of function
231
232// Get stationIndex from layer number
233int
235 if(l==0||l==1||l==2)return 0;
236 else if(l==3||l==4)return 1;
237 else if(l==5||l==6)return 2;
238 else if(l==7||l==8)return 3;
239 else{
240 ATH_MSG_WARNING( "TGClayer2Station passed invalid layer number:" << l );
241 return -1;
242 }
243}// End of function
244// Get stationIndex from stationName
245int
247 if(stationName==41||stationName==42)return 0;
248 else if(stationName==43||stationName==44)return 1;
249 else if(stationName==45||stationName==46)return 2;
250 else if(stationName==47||stationName==48)return 3;
251 else{
252 ATH_MSG_WARNING( "TGCstationname2stationindex passed invalid stationName n=" << stationName );
253 return -1;
254 }
255}// End of function
256
257// Get Eta or Phi index for the StationMap histograms from TRE variables
258int
259MdtVsTgcRawDataValAlg::getStationMapIndex(int x, int l, int stationFE, int stationEta, int stationPhi){
260 // Display error messages if invalid TRE variables are passed in
261 if((stationFE!=0)&&(stationFE!=1)) ATH_MSG_WARNING( "getStationMapIndex passed invalid stationFE=" << stationFE );
262 if((l<0)||(l>8)) ATH_MSG_WARNING( "getStationMapIndex passed invalid layer index l=" << l );
263 if(stationEta<1) ATH_MSG_WARNING( "getStationMapIndex passed invalid stationEta=" << stationEta );
264 if(stationPhi<1) ATH_MSG_WARNING( "getStationMapIndex passed invalid stationPhi=" << stationPhi );
265 int index=0;
266 switch(x){
267 case 1:// Getting Eta Index //use old eta bin
268 if(l==0||l==1||l==2){// T1
269 if(stationEta>4) ATH_MSG_WARNING( "getStationMapIndex(" << x << ") passed invalid l=" << l << " stationEta=" << stationEta );
270 if(stationFE==0)index=32+l;
271 else{
272 index=4-stationEta;
273 index=index*7+l;
274 }
275 }
276 else if(l==3||l==4){// T2
277 if(stationEta>5) ATH_MSG_WARNING( "getStationMapIndex(" << x << ") passed invalid l=" << l << " stationEta=" << stationEta );
278 if(stationFE==0)index=32+l;
279 else {
280 index=5-stationEta;
281 index=index*7+l;
282 if(stationEta==1)index=25+l;
283 }
284 }
285 else if(l==5||l==6){// T3
286 if(stationEta>5) ATH_MSG_WARNING( "getStationMapIndex(" << x << ") passed invalid l=" << l << " stationEta=" << stationEta );
287 if(stationFE==0)index=32+l;
288 else{
289 index=5-stationEta;
290 index=index*7+l;
291 if(stationEta==1)index=25+l;
292 }
293 }
294 else if(l==7||l==8){// T4
295 if(stationEta>1) ATH_MSG_WARNING( "getStationMapIndex(" << x << ") passed invalid l=" << l << " stationEta=" << stationEta );
296 if(stationFE==0){
297 if(l==7){index=41;}
298 else if(l==8){index=42;}
299 }else{
300 if(l==7){index=39;}
301 else if(l==8){index=40;}
302 }
303 }
304 break;
305 case 2:// Getting Phi Index
306 if(stationFE==0){// Forward
307 if((l==7)||(l==8)){// FI
308 if(stationPhi>24) ATH_MSG_WARNING( "getStationMapIndex(" << x << ") passed invalid l=" << l << " FE=" << stationFE << " stationPhi=" << stationPhi );
309 index=(stationPhi-1)*2;
310 }
311 else{// Forward Midstation
312 if(stationPhi>24) ATH_MSG_WARNING( "getStationMapIndex(" << x << ") passed invalid l=" << l << " FE=" << stationFE << " stationPhi=" << stationPhi );
313 index=(stationPhi-1)*2;
314 }
315 }
316 else{// Endcap
317 if((l==7)||(l==8)){// EI
318 if(stationPhi>21) ATH_MSG_WARNING( "getStationMapIndex(" << x << ") passed invalid l=" << l << " FE=" << stationFE << " stationPhi=" << stationPhi );
319 index=(stationPhi-1);
320 if(index>7)index++;
321 if(index>15)index++;
322 if(index>19)index++;
323 index*=2;
324 }
325 else{// Endcap Midstation
326 if(stationPhi>48) ATH_MSG_WARNING( "getStationMapIndex(" << x << ") passed invalid l=" << l << " FE=" << stationFE << " stationPhi=" << stationPhi );
327 index=stationPhi-1;
328 }
329 }
330 // Adjust to set A01phi0(stationPhi=47 for Midstation)at 0
331 index+=2;
332 if(index>47)index-=48;
333 break;
334 default:
335 ATH_MSG_WARNING( "getStationMapIndex(" << x << ") is invalid" );
336 break;
337 }
338 return index;
339}// End of function
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
#define y
#define x
Header file for AthHistogramAlgorithm.
int TGCgetlayer(int stationName, int g)
void prepareTREarray(const MuonGM::MuonDetectorManager *MuonDetMgrDS)
void SortMDTSegments(const xAOD::MuonSegmentContainer *m_newsegment, std::vector< const Muon::MuonSegment * >(&sortedSegments)[2][4])
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
void MatchMDTSegments(std::vector< const Muon::MuonSegment * >(&sortedSegments)[2][4], std::vector< const Muon::MuonSegment * >(&disqualifiedSegments)[2][4], std::vector< SegmTrack >(&matchedSegments)[2])
void tgceffcalc(const xAOD::MuonSegmentContainer *m_newsegment, const Muon::TgcPrepDataContainer *tgc_prepcontainer)
void CheckTGConTrack(std::vector< SegmTrack >(&matchedSegments)[2], const Muon::TgcPrepDataContainer *tgc_prepcontainer)
void MidstationOnlyCheck(std::vector< const Muon::MuonSegment * >(&sortedSegments)[2][4], std::vector< const Muon::MuonSegment * >(&disqualifiedSegments)[2][4], const Muon::TgcPrepDataContainer *tgc_prepcontainer)
void DQCheckMDTSegments(std::vector< const Muon::MuonSegment * >(&sortedSegments)[2][4], std::vector< const Muon::MuonSegment * >(&disqualifiedSegments)[2][4])
int getStationMapIndex(int x, int l, int stationFE, int stationEta, int stationPhi)
const MuonGM::TgcReadoutElement * m_TREarray[8][2][9][49]
int TGCstationname2stationindex(int stationName)
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
const TgcReadoutElement * getTgcReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
MuonPrepDataContainerT< TgcPrepData > TgcPrepDataContainer
Definition index.py:1
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".