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