ATLAS Offline Software
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 
9 #include "CxxUtils/StringUtils.h"
10 
11 //Tool to impliment a set of cuts on an Identifier, and then determine if a given ID is in that set
12 
13 MuonIdCutTool::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 
109 bool 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;
359 Identifier ID = m_idToFixedIdTool->fixedIdToId(mfid);
360 bool iscut = MuonIdCutTool::isCut(ID);
361 return iscut;
362 }
363 
364 //function to find phi sector (1-16) from phi station (1-8)
365 int 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 }
MuonIdCutTool::m_cutSubstation
bool m_cutSubstation
Definition: MuonIdCutTool.h:46
MuonIdCutTool::m_cscRegionList
std::vector< int > m_cscRegionList
Definition: MuonIdCutTool.h:53
MuonIdCutTool::m_mdtBarEtaList
std::vector< int > m_mdtBarEtaList
Definition: MuonIdCutTool.h:67
MuonIdCutTool::m_tgcForPhiList
std::vector< int > m_tgcForPhiList
Definition: MuonIdCutTool.h:77
MuonIdCutTool::m_rpcEtaList
std::vector< int > m_rpcEtaList
Definition: MuonIdCutTool.h:70
MuonIdCutTool::m_rpcStationNameList
std::vector< int > m_rpcStationNameList
Definition: MuonIdCutTool.h:59
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
max
#define max(a, b)
Definition: cfImp.cxx:41
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
ID
std::vector< Identifier > ID
Definition: CalibHitIDCheck.h:24
MuonIdCutTool::m_cutEta
bool m_cutEta
Definition: MuonIdCutTool.h:48
MuonIdCutTool::m_cutEE
bool m_cutEE
Definition: MuonIdCutTool.h:47
MuonIdCutTool::m_rpcDoubletRList
std::vector< int > m_rpcDoubletRList
Definition: MuonIdCutTool.h:63
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
MuonIdCutTool::initialize
StatusCode initialize()
initialize method, method taken from bass-class AlgTool
Definition: MuonIdCutTool.cxx:63
MuonIdCutTool::isCut
virtual bool isCut(Identifier ID) const
Definition: MuonIdCutTool.cxx:109
StringUtils.h
MuonIdCutTool::m_EELsector
std::vector< int > m_EELsector
Definition: MuonIdCutTool.h:88
MuonIdCutTool::m_cscStationNameList
std::vector< int > m_cscStationNameList
Definition: MuonIdCutTool.h:58
IdToFixedIdTool.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
MuonIdCutTool::m_rpcSectorList
std::vector< int > m_rpcSectorList
Definition: MuonIdCutTool.h:71
MuonIdCutTool::m_idToFixedIdTool
ToolHandle< MuonCalib::IIdToFixedIdTool > m_idToFixedIdTool
Definition: MuonIdCutTool.h:83
MuonIdCutTool::m_cutStationName
bool m_cutStationName
Definition: MuonIdCutTool.h:45
MuonIdCutTool::m_tgcRegionList
std::vector< int > m_tgcRegionList
Definition: MuonIdCutTool.h:55
MuonIdCutTool::m_rpcGasGapList
std::vector< int > m_rpcGasGapList
Definition: MuonIdCutTool.h:64
MuonIdCutTool::m_mdtStationNameList
std::vector< int > m_mdtStationNameList
Definition: MuonIdCutTool.h:57
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MuonIdCutTool::FindSector
static int FindSector(unsigned int staName, unsigned int staPhi)
Definition: MuonIdCutTool.cxx:365
lumiFormat.i
int i
Definition: lumiFormat.py:92
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MuonIdCutTool::m_mdtEndEtaList
std::vector< int > m_mdtEndEtaList
Definition: MuonIdCutTool.h:68
BindingsTest.cut
cut
This script demonstrates how to call a C++ class from Python Also how to use PyROOT is shown.
Definition: BindingsTest.py:13
MuonIdCutTool::m_EELList
std::vector< std::string > m_EELList
Definition: MuonIdCutTool.h:51
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MuonIdCutTool::m_tgcStationNameList
std::vector< int > m_tgcStationNameList
Definition: MuonIdCutTool.h:60
MuonIdCutTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonIdCutTool.h:85
MuonIdCutTool::m_mdtSectorList
std::vector< int > m_mdtSectorList
Definition: MuonIdCutTool.h:69
MuonIdCutTool::m_tgcGasGapList
std::vector< int > m_tgcGasGapList
Definition: MuonIdCutTool.h:65
MuonIdCutTool::m_rpcRegionList
std::vector< int > m_rpcRegionList
Definition: MuonIdCutTool.h:54
MuonCalib::MuonFixedId
Definition: MuonFixedId.h:50
MuonIdCutTool::MuonIdCutTool
MuonIdCutTool(const std::string &, const std::string &, const IInterface *)
default AlgTool constructor
Definition: MuonIdCutTool.cxx:13
MuonIdCutTool::m_mdtRegionList
std::vector< int > m_mdtRegionList
Definition: MuonIdCutTool.h:52
MuonIdCutTool::m_cscSectorList
std::vector< int > m_cscSectorList
Definition: MuonIdCutTool.h:73
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
MuonIdCutTool::m_cscEtaList
std::vector< int > m_cscEtaList
Definition: MuonIdCutTool.h:72
MuonIdCutTool::m_tgcEtaList
std::vector< int > m_tgcEtaList
Definition: MuonIdCutTool.h:75
MuonIdCutTool::m_mdtMultilayerList
std::vector< int > m_mdtMultilayerList
Definition: MuonIdCutTool.h:62
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
MuonIdCutTool::m_cutStationRegion
bool m_cutStationRegion
Definition: MuonIdCutTool.h:44
AthAlgTool
Definition: AthAlgTool.h:26
MuonIdCutTool::m_tgcEndPhiList
std::vector< int > m_tgcEndPhiList
Definition: MuonIdCutTool.h:76
length
double length(const pvec &v)
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
MuonFixedId.h
MuonIdCutTool.h
MuonIdCutTool::m_cutPhi
bool m_cutPhi
Definition: MuonIdCutTool.h:49
MuonIdCutTool::m_EELeta
std::vector< int > m_EELeta
Definition: MuonIdCutTool.h:87