ATLAS Offline Software
Loading...
Searching...
No Matches
MuonIdCutTool.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
10
11//Tool to impliment a set of cuts on an Identifier, and then determine if a given ID is in that set
12
13MuonIdCutTool::MuonIdCutTool(const std::string& t,const std::string& n,const IInterface* p) :
14 AthAlgTool(t,n,p) {
15 declareInterface<IMuonIdCutTool>(this);
16
17 declareProperty("CutStationRegion",m_cutStationRegion = false ); //0 inner, 1 extra(BEE), 2 middle, 3 outer
18 declareProperty("CutStationName",m_cutStationName = true ); //integer which maps to BIL etc.
19 declareProperty("CutSubstation",m_cutSubstation = false ); //do you want to cut on gas-gap or multilayer
20 declareProperty("CutEta",m_cutEta = false );
21 declareProperty("CutPhi",m_cutPhi = false );
22 declareProperty("CutEE",m_cutEE = false ); //cut all EES, leave some EEL
23
24
25 declareProperty("CutMdtRegionList",m_mdtRegionList );
26 declareProperty("CutCscRegionList",m_cscRegionList );
27 declareProperty("CutRpcRegionList",m_rpcRegionList );
28 declareProperty("CutTgcRegionList",m_tgcRegionList );
29 declareProperty("CutMdtStationNameList",m_mdtStationNameList );//cut these station names
30 declareProperty("CutCscStationNameList",m_cscStationNameList );
31 declareProperty("CutRpcStationNameList",m_rpcStationNameList );
32 declareProperty("CutTgcStationNameList",m_tgcStationNameList );
33 declareProperty("CutMdtMultilayerList",m_mdtMultilayerList );//entries in these lists are matched
34 declareProperty("CutRpcDoubletRList",m_rpcDoubletRList );//to entries in the stationName list.
35 declareProperty("CutRpcGasGapList",m_rpcGasGapList );//the size of each list should be the same
36 declareProperty("CutTgcGasGapList",m_tgcGasGapList );
37 declareProperty("EELList",m_EELList ); //eta/sector to keep for EEL
38
39
40 //note that the following properties are the eta/phi sectors too keep
41 declareProperty("MdtBarrelEtaList",m_mdtBarEtaList );// -8 to 8, 0 would refer to eta = 0
42 declareProperty("MdtEndcapEtaList",m_mdtEndEtaList );// -6 to 6, abs value increases with |R|
43 declareProperty("MdtSectorList",m_mdtSectorList );// 1 to 8 for the whole detector, 1 points in +x
44
45 declareProperty("RpcEtaList",m_rpcEtaList );// -8 to 8, 0 would refer to eta = 0
46 declareProperty("RpcSectorList",m_rpcSectorList );// 1 to 8 for the whole detector, 1 points in +x
47
48 declareProperty("CscEtaList",m_cscEtaList );// 1 is the only value
49 declareProperty("CscSectorList",m_cscSectorList );// 1 to 8 for the whole detector, 1 points in +x
50
51 //tgcs go by a different eta/phi numbering scheme and so must be cut separately
52 declareProperty("TgcEtaList",m_tgcEtaList );// -5 to 5, [roughly] matches the endcap mdt naming scheme
53 declareProperty("TgcEndcapPhiList",m_tgcEndPhiList );// 1 to 48 endcap
54 declareProperty("TgcForwardPhiList",m_tgcForPhiList );// 1 to 24 forward
55
56
57 //The cuts are independent, but if you have both cutEta = true and cutPhi = true make
58 //sure to set either both eta and phi or neither lists for a given technology, otherwise, the program will
59 //cut the whole technology
60
61}
62
64 ATH_CHECK( m_idToFixedIdTool.retrieve() );
65 ATH_CHECK( m_idHelperSvc.retrieve() );
66
68 ATH_MSG_WARNING( "MuonIdCutTool invoked with no cuts performed" );
69 }
70
71 //interpret EEL cuts
72 int max = m_EELList.size();
73
74 for(int i=0;i<max;i++){
75 std::string_view cut = m_EELList[i];
76 ATH_MSG_DEBUG( "EEL String: " << cut );
77 size_t length = cut.size();
78 size_t loc = cut.find('/');
79 if (loc!=std::string::npos){
80 std::string_view etaString = cut.substr(0,loc);
81 std::string_view sectorString = cut.substr(loc+1,length-loc-1);
82 int eta = CxxUtils::atoi(etaString);
83 int sector = CxxUtils::atoi(sectorString);
84
85 ATH_MSG_DEBUG( "EEL eta/phi string: "<< etaString << " " << sectorString );
86 ATH_MSG_DEBUG( "EEL eta/phi int: "<< eta << " " << sector );
87
88
89 if(std::abs(eta) > 0 && std::abs(eta) < 3 && sector > 0 && sector < 17){
90 m_EELeta.push_back(eta);
91 m_EELsector.push_back(sector);
92
93 } else {
94 ATH_MSG_WARNING( "Improper EEL Cut Selected, this cut is skipped" );
95 }
96
97 } else {
98 ATH_MSG_WARNING( "Improperly formated EEL Cut Selected, this cut is skipped" );
99 }
100 }
101
102 for(unsigned int i=0; i < m_EELeta.size();i++){
103 ATH_MSG_DEBUG( "Eta: " << m_EELeta[i] << " Sector: " << m_EELsector[i] );
104 }
105
106 return StatusCode::SUCCESS;
107}
108
109bool MuonIdCutTool::isCut(Identifier ID) const { //false indicates all cuts are passed
110
111 //some checks to see if the tool is configured in a state that makes sense
113 ATH_MSG_WARNING( "MuonIdCutTool invoked with both Region Cuts and Station name cuts.Are you sure this is what you want?");
114 }
115
116 if (m_cutSubstation){
117 if ((m_mdtMultilayerList.size() != m_mdtStationNameList.size()) || (m_tgcGasGapList.size() != m_tgcStationNameList.size()) ){
118 ATH_MSG_WARNING( "Station and Substation cuts lists should match in length, no cut perfomed" );
119 return false;
120 }
121 else if ((m_rpcDoubletRList.size() != m_rpcStationNameList.size()) || ((m_rpcGasGapList.size() != m_rpcStationNameList.size()) && !m_rpcGasGapList.empty() )){
122 ATH_MSG_WARNING( "Station and Substation cuts lists should match in length, no cut perfomed" );
123 return false;
124 }
125 }
126
127 std::vector<int> cutList; //this will chose the correct cut list (StationName or Station Region)
128
129 unsigned int staName = m_idHelperSvc->stationName(ID);
130 unsigned int staPhi = m_idHelperSvc->stationPhi(ID);
131
132 int sector = FindSector(staName,staPhi);
133
134 //Routine for cutting all EES and some EEL chambers
135 if(m_cutEE && staName == 15) return true;
136 if(m_cutEE && staName == 14){
137 int listSize = m_EELeta.size();
138 for (int i=0;i<listSize;i++){
139 if(m_EELeta[i]==(m_idHelperSvc->stationEta(ID)) && m_EELsector[i]==sector) break;
140 if(i==(listSize-1)) return true; //if fails last entry, cut = true
141 }
142 }
143
144 //Routine for cutting on Station Region
145
146 if (m_cutStationRegion){
147 if (m_idHelperSvc->isMdt(ID)){
148 cutList = m_mdtRegionList;
149 }
150 else if (m_idHelperSvc->isCsc(ID)){
151 cutList = m_cscRegionList;
152 }
153 else if (m_idHelperSvc->isRpc(ID)){
154 cutList = m_rpcRegionList;
155 }
156 else if (m_idHelperSvc->isTgc(ID)){
157 cutList = m_tgcRegionList;
158 }
159 else{
160 ATH_MSG_ERROR( "Failure to determine technology type of ID#, returning false" );
161 return false;
162 }
163
164 int listSize = cutList.size();
165 for (int i=0; i<listSize;i++){
166 ATH_MSG_DEBUG( "Region " << m_idHelperSvc->stationRegion(ID)
167 << " compared with " << cutList[i] );
168 if( cutList[i] == m_idHelperSvc->stationRegion(ID)){
169 ATH_MSG_DEBUG( "Return True" );
170 return true;
171 }
172 }
173 ATH_MSG_DEBUG( "Passes Region Cut" );
174 }
175
176
177 //Routine for cutting on Station Name and optional sub-region cuts
178
179
180 if (m_cutStationName){
181 if (m_idHelperSvc->isMdt(ID)){
182 cutList = m_mdtStationNameList;
183 }
184 else if (m_idHelperSvc->isCsc(ID)){
185 cutList = m_cscStationNameList;
186 }
187 else if (m_idHelperSvc->isRpc(ID)){
188 cutList = m_rpcStationNameList;
189 }
190 else if (m_idHelperSvc->isTgc(ID)){
191 cutList = m_tgcStationNameList;
192 }
193 else{
194 ATH_MSG_ERROR( "Failure to determine technology type of ID#, returning false" );
195 return false;
196 }
197
198 int listSize = cutList.size();
199 for (int i=0; i<listSize;i++){
200 ATH_MSG_DEBUG( "Station Name " << m_idHelperSvc->stationName(ID) << " compared with "
201 <<cutList[i] );
202 if( cutList[i] == m_idHelperSvc->stationName(ID)){
203 if (!m_cutSubstation){
204 return true;
205 }
206
207 else { //proceed with more specific cuts
208
209 if (m_idHelperSvc->isMdt(ID)){
210 ATH_MSG_DEBUG( "MDT multilayer " <<m_idHelperSvc->mdtIdHelper().multilayer(ID)
211 << " compared with " << m_mdtMultilayerList[i] );
212 if(m_mdtMultilayerList[i] == m_idHelperSvc->mdtIdHelper().multilayer(ID))
213 return true;
214 }
215
216
217 else if (m_idHelperSvc->isRpc(ID)){
218 ATH_MSG_DEBUG( "RPC doublet R " <<m_idHelperSvc->rpcIdHelper().doubletR(ID)
219 << " compared with " << m_rpcDoubletRList[i] );
220 if( m_rpcDoubletRList[i] == m_idHelperSvc->rpcIdHelper().doubletR(ID) ){
221 if (m_rpcGasGapList.empty()){
222 return true;
223 }
224 else {
225 ATH_MSG_DEBUG( "RPC gasgap " <<m_idHelperSvc->rpcIdHelper().gasGap(ID)
226 << " compared with " << m_rpcGasGapList[i] );
227 if (m_rpcGasGapList[i] == m_idHelperSvc->rpcIdHelper().gasGap(ID))
228 return true;
229 }
230
231 }
232 }
233
234
235 else if (m_idHelperSvc->isTgc(ID)){
236 ATH_MSG_DEBUG( "TGC gasgap " <<m_idHelperSvc->tgcIdHelper().gasGap(ID)
237 << " compared with " << m_tgcGasGapList[i] );
238 if (m_tgcGasGapList[i] == m_idHelperSvc->tgcIdHelper().gasGap(ID))
239 return true;
240 }
241
242
243 } //end sub-region cuts
244 } //end if statement checking station name
245 } //end station name loop
246 } //end if m_cutStationName
247
248
249 //Routine for cutting on eta and phi
250 //this routine should always be last because its the only one that
251 //ever returns false
252
253 if (m_cutEta || m_cutPhi){
254
255 std::vector<int> genEtaList; //general eta list (can be tgc list)
256 std::vector<int> genPhiList; //general phi list (can be tgc list)
257 int etaListSize;
258 int phiListSize;
259 int phi; //this variable is the phi index for tgcs, the sector for everyone else
260 unsigned int staName = m_idHelperSvc->stationName(ID);
261 unsigned int staPhi = m_idHelperSvc->stationPhi(ID);
262 int sector = FindSector(staName,staPhi);
263 phi = sector;
264
265 ATH_MSG_DEBUG( "Phi Station is " << staPhi
266 << " and Station name is " << staName );
267
268 ATH_MSG_DEBUG( "Phi Sector is " << sector );
269
270 //Is it tgc?
271 if (m_idHelperSvc->isTgc(ID)){
272 //If no cuts specified, don't cut anything
273 if (m_tgcEtaList.empty() && m_tgcEndPhiList.empty() && m_tgcForPhiList.empty())
274 return false;
275 genEtaList = m_tgcEtaList;
276 phi = m_idHelperSvc->stationPhi(ID);
277 //Is it forward?
278 if (staName == 41 || staName == 43 || staName == 45 || staName == 47)
279 genPhiList = m_tgcForPhiList;
280 else
281 genPhiList = m_tgcEndPhiList;
282 }
283
284
285 //mdt?
286 else if(m_idHelperSvc->isMdt(ID)){
287 //If no cuts specified, don't cut anything
288 if (m_mdtSectorList.empty() && m_mdtEndEtaList.empty() && m_mdtBarEtaList.empty())
289 return false;
290 genPhiList = m_mdtSectorList;
291 if (m_idHelperSvc->isEndcap(ID)) {
292 genEtaList = m_mdtEndEtaList;
293 } else {
294 genEtaList = m_mdtBarEtaList;
295 }
296 }
297
298 //rpc?
299 else if(m_idHelperSvc->isRpc(ID)){
300 //If no cuts specified, don't cut anything
301 if (m_rpcSectorList.empty() && m_rpcEtaList.empty())
302 return false;
303 genPhiList = m_rpcSectorList;
304 genEtaList = m_rpcEtaList;
305 }
306
307 //csc?
308 else if(m_idHelperSvc->isCsc(ID)){
309 //If no cuts specified, don't cut anything
310 if (m_cscSectorList.empty() && m_cscEtaList.empty())
311 return false;
312 genPhiList = m_cscSectorList;
313 genEtaList = m_cscEtaList;
314 }
315
316 etaListSize = genEtaList.size();
317 phiListSize = genPhiList.size();
318
319 bool etapass = true;
320 bool phipass = true;
321
322 if(m_cutEta){
323 etapass = false;
324 for (int i=0; i<etaListSize;i++){
325 ATH_MSG_DEBUG( "Eta Station " << m_idHelperSvc->stationEta(ID)
326 << " compared with list to keep " << genEtaList[i] );
327 if( genEtaList[i] == m_idHelperSvc->stationEta(ID))
328 etapass = true;
329 }
330 }
331
332 if(m_cutPhi){
333 phipass = false;
334
335 for (int i=0; i<phiListSize;i++){
336 ATH_MSG_DEBUG( "Phi Station " << phi
337 << " compared with list to keep " << genPhiList[i] );
338 if( genPhiList[i] == phi)
339 phipass = true;
340 }
341 }
342
343 if (!etapass || !phipass) //if eta or phi fail it is cut
344 return true;
345
346 }
347
348
349
350
351 return false; //keep the event if none of the cuts removed the event
352}
353
354
355//overloaded function to take in MuonFixedId
356
358// std::cout << "testing if IdCuts called" << std::endl;
359Identifier ID = m_idToFixedIdTool->fixedIdToId(mfid);
360bool iscut = MuonIdCutTool::isCut(ID);
361return iscut;
362}
363
364//function to find phi sector (1-16) from phi station (1-8)
365int MuonIdCutTool::FindSector(unsigned int staName, unsigned int staPhi) {
366
367 int sector=-1;
368
369 //This strange looking array specifies whether the station is large or small
370 //999 specifies a number not used, or a tgc
371 //station name maps to BIL,EOS,etc
372 int isStationNameLarge[53] = {1,0,1,0,1,0,0,1,0,0,0,0,999,1,1,0,999,1,0,999,1,0,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,0,0,1,1};
373
374 if (staName < 53){
375 sector = staPhi*2 - isStationNameLarge[staName];
376 }
377
378 return sector;
379
380}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
std::vector< Identifier > ID
double length(const pvec &v)
#define max(a, b)
Definition cfImp.cxx:41
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Implements fixed identifiers not dependent upon Athena Identifier for internal use in the calibration...
Definition MuonFixedId.h:50
std::vector< int > m_mdtMultilayerList
std::vector< int > m_tgcRegionList
std::vector< int > m_tgcStationNameList
std::vector< int > m_rpcDoubletRList
StatusCode initialize()
initialize method, method taken from bass-class AlgTool
std::vector< int > m_cscStationNameList
std::vector< int > m_tgcEndPhiList
std::vector< int > m_mdtEndEtaList
std::vector< int > m_rpcRegionList
std::vector< int > m_mdtStationNameList
std::vector< std::string > m_EELList
std::vector< int > m_rpcGasGapList
std::vector< int > m_EELsector
bool m_cutStationRegion
virtual bool isCut(Identifier ID) const
std::vector< int > m_tgcForPhiList
std::vector< int > m_cscEtaList
std::vector< int > m_mdtBarEtaList
std::vector< int > m_mdtSectorList
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
std::vector< int > m_tgcEtaList
ToolHandle< MuonCalib::IIdToFixedIdTool > m_idToFixedIdTool
std::vector< int > m_EELeta
std::vector< int > m_cscSectorList
static int FindSector(unsigned int staName, unsigned int staPhi)
MuonIdCutTool(const std::string &, const std::string &, const IInterface *)
default AlgTool constructor
std::vector< int > m_rpcSectorList
std::vector< int > m_rpcEtaList
std::vector< int > m_mdtRegionList
std::vector< int > m_tgcGasGapList
std::vector< int > m_rpcStationNameList
std::vector< int > m_cscRegionList
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...