ATLAS Offline Software
PadTriggerLookupTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "GaudiKernel/ITHistSvc.h"
8 #include "GaudiKernel/IIncidentSvc.h"
18 
19 #include <boost/geometry.hpp>
20 #include <boost/geometry/geometries/point_xy.hpp>
21 #include <boost/geometry/geometries/polygon.hpp>
22 #include <algorithm>
23 #include <fstream>
24 #include <numeric>
25 
26 namespace NSWL1 {
27 //------------------------------------------------------------------------------
28 PadTriggerLookupTool::PadTriggerLookupTool(const std::string& type, const std::string& name, const IInterface* parent) :
30  m_etaBandsLargeSector(BandsInEtaLargeSector),
31  m_etaBandsSmallSector(BandsInEtaSmallSector),
32  m_detManager(nullptr) {
33  declareInterface<NSWL1::IPadTriggerLookupTool>(this);
34 }
35 
37  ATH_MSG_DEBUG( "initializing " << name() );
38  ATH_MSG_DEBUG( name() << " configuration:");
40  ATH_CHECK(loadCoincidenceTable("TriggerPatterns.dat") );
42  ATH_MSG_DEBUG(" Will dump 3D pad geometry / sector");
43  std::ofstream padGeoFile("NSWSectorPadsGeoDump.dat");//use local variables in order not to contaminate members
44  //grab full sector pads
45  std::vector<std::shared_ptr<PadOfflineData>> smallSectorPads=fetchSmallSectorPads();
46  std::vector<std::shared_ptr<PadOfflineData>> largeSectorPads=fetchLargeSectorPads();
47  ATH_CHECK(printGeometry(largeSectorPads,padGeoFile) );
48  ATH_CHECK(printGeometry(smallSectorPads,padGeoFile) );
49  padGeoFile.close();
50 
51  }
52  ATH_CHECK(m_idHelperSvc.retrieve());
53  return StatusCode::SUCCESS;
54 }
55 //------------------------------------------------------------------------------
56 
57 void PadTriggerLookupTool::handle(const Incident& inc) {
58 
59  if( inc.type()==IncidentType::BeginEvent ) {
60  return;
61  }
62 
63 
64  return;
65 }
66 //given a set of Pads / event this will distinguish the activated sides + sectors then looks up all possible triggers from the LUT
67 StatusCode PadTriggerLookupTool::lookup_pad_triggers(const std::vector<std::shared_ptr<PadData>>& pads,
68  std::vector<std::unique_ptr<PadTrigger>> &triggers)
69 {
70  std::set<int> activeSides;
71  std::set<int> activeSectors;
72  //use sector numbers {1,2,3,.....16}
73  std::for_each(pads.begin(),pads.end(),[&](const std::shared_ptr<PadData>& p){
74  activeSides.insert(p->sideId() );
75  activeSectors.insert(p->triggerSectorNumber());
76  }
77  );
78 
79  //use only active sectors selected by the pads / event
80  for(const int side : activeSides){//0:C 1:A
81  for(const int sector : activeSectors){//{1...16} odd:L even:S
83  }
84  }
85  //now you have gathered all the triggers from all sides/sectors..
86  //fill some geometric info for strip selection. the info is sent to the strip
87  //(currently using band eta-design from Y.R)
88  //However it must be removed from the code once xml file is fixed for bands-strips
89 
90  return StatusCode::SUCCESS;
91 }
92 
93 
94 StatusCode PadTriggerLookupTool::loadCoincidenceTable(const std::string& padCoincidenceFileName){
95 
96  std::string file = PathResolver::find_file (padCoincidenceFileName, "DATAPATH");
97  ATH_MSG_DEBUG("Loading coincidence table from "<<file);
98  std::ifstream infile(file.c_str());
99  if(!infile){
100  ATH_MSG_FATAL("Can't open file " << file);
101  return StatusCode::FAILURE;
102  }
103  std::string line;
104  while( getline( infile, line ) ){
105 
106  std::stringstream iss( line );
107  int number;
108  std::vector<int> fullPattern;
109  while ( iss >> number ){
110  fullPattern.push_back( number );
111  }
112  //strip pads and band-phiId parts off
113  //The first 8 elements are coincidence patterns the remaining two and band and phi ids
114  std::vector<int> padsOnlyPattern(fullPattern.begin(), fullPattern.begin() + 8);
115  std::vector<int> bandAndPhiId(fullPattern.begin()+8, fullPattern.begin() + 10);
116  int bandId=bandAndPhiId.at(0);
117  int phiId=bandAndPhiId.at(1);
118  m_pats[padsOnlyPattern]=std::pair<int,int>(bandId,phiId);
119  }
120 
122  ATH_MSG_DEBUG(" Load "<<m_pats.size()<<" coincidence patterns...");
123  return StatusCode::SUCCESS;
124 }
125 
126 StatusCode PadTriggerLookupTool::expandCoincidenceTable(){//There we append 3o4s to the lookup table itself...
127 
128  std::unordered_map<std::vector<int>,std::pair<int,int> ,hashPattern> derivedCoincidencePatterns;
129 
130  std::vector<int> innerIndices(4);
131  std::vector<int> outerIndices(4);
132  std::vector<int> allIndices(8);
133  std::iota(innerIndices.begin(), innerIndices.begin() + 4, 0);
134  std::iota(outerIndices.begin(), outerIndices.begin() + 4, 4);
135  std::iota(allIndices.begin(),allIndices.begin()+8,0);
136 
137  for(const auto& kv : m_pats){
138  int bandid=kv.second.first;
139  int phiid=kv.second.second;
140  for(int in : innerIndices ){
141  std::vector<int> pattern=kv.first;//copy
142  if(pattern.at(in)==nullPadNumber || pattern.at(in+4)==nullPadNumber){
143  continue;
144  }
145  pattern.at(in)=nullPadNumber;
146  for(int out :outerIndices){
147  int thispattern=pattern.at(out);
149  derivedCoincidencePatterns[pattern]=std::pair<int,int>(bandid,phiid);
150  pattern.at(out)=thispattern;//revert the change for the next one
151  }
152  }
153 
154  for(int i : allIndices){
155  std::vector<int> pattern=kv.first;//copy
156  pattern.at(i)=nullPadNumber;
157  derivedCoincidencePatterns[pattern]=std::pair<int,int>(bandid,phiid);
158  }
159  }
160 
161  m_pats.insert(derivedCoincidencePatterns.begin(),derivedCoincidencePatterns.end());
162  ATH_MSG_DEBUG(" Picked up "<<m_pats.size()<<" pad coincidences");
163  return StatusCode::SUCCESS;
164 }
165 
166 
167 
168 /*
169 selectWedgePatterns :
170 
171 Given a set of pads / event
172 This will filter the given pads w.r.t to side/sector/multiplet/layers
173 then will return all possible pad combinations (taking the logic into account..)
174 later on these combinations are to be lookedup from the table / execute
175 //for 4-layers hit patterns, use a weak logic to tolerate noisy pads(only 1 layer tolerance)
176 
177 ====it may return empty vector ====
178 */
179 
180 
181 
182 std::vector<std::vector<std::shared_ptr<PadData> >> PadTriggerLookupTool::selectWedgePatterns(const std::vector<std::shared_ptr<PadData>> &pads,int side, int sector,int wedge) const {
183 
184  //first filter w.r.t inner/outer
185  std::vector<std::shared_ptr<PadData> > padsInThisWedge;
186  //Within logic we have sectors numbered as {1,2,3....16} : A/C
187  auto wedgeSelector=[=](const std::shared_ptr<PadData>& pad)->bool{
188  return pad->sideId() == side &&
189  pad->triggerSectorNumber() == sector &&
190  pad->multipletId() == wedge;
191  };
192  //filter pads within this sector / wedge
193  std::copy_if(pads.begin(),pads.end(),std::back_inserter(padsInThisWedge),[=]( const std::shared_ptr<PadData>& pad){ return wedgeSelector(pad);} );
194  //too many pad hits might cause a performance issue . 100 pads ~ 100/4 ~ 25 pad hits per layer !!!!
195  if(padsInThisWedge.size()>100){
196  ATH_MSG_WARNING("Too many pad hits: ("<<padsInThisWedge.size()<<")pad hits on side= "<<side<<" sector="<<sector<<" wedge="<<wedge);
197  }
198  //classify pads now layerwise
199  std::vector<std::shared_ptr<PadData> > padsOnLayer1;
200  std::vector<std::shared_ptr<PadData> > padsOnLayer2;
201  std::vector<std::shared_ptr<PadData> > padsOnLayer3;
202  std::vector<std::shared_ptr<PadData> > padsOnLayer4;
203  std::copy_if(padsInThisWedge.begin(),padsInThisWedge.end(),std::back_inserter(padsOnLayer1),[](const std::shared_ptr<PadData>& pad){ return pad->gasGapId()==1;} );
204  std::copy_if(padsInThisWedge.begin(),padsInThisWedge.end(),std::back_inserter(padsOnLayer2),[](const std::shared_ptr<PadData>& pad){ return pad->gasGapId()==2;} );
205  std::copy_if(padsInThisWedge.begin(),padsInThisWedge.end(),std::back_inserter(padsOnLayer3),[](const std::shared_ptr<PadData>& pad){ return pad->gasGapId()==3;} );
206  std::copy_if(padsInThisWedge.begin(),padsInThisWedge.end(),std::back_inserter(padsOnLayer4),[](const std::shared_ptr<PadData>& pad){ return pad->gasGapId()==4;} );
207 
208  //build all possible combinations with pad/layer
209  std::vector<std::vector<std::shared_ptr<PadData> >> padCombinationsInWedge;
210  //if we have more than 1 layer missing reject / returns an empty list
211  std::vector< size_t> nHitsLayerWise={ padsOnLayer1.size(),padsOnLayer2.size(),padsOnLayer3.size(),padsOnLayer4.size() };
212  if( std::count(nHitsLayerWise.begin(),nHitsLayerWise.end(),0)>1){
213  ATH_MSG_WARNING("Not enough layer hits to build a pattern at side="<<side<<" sector="<<sector);
214  return padCombinationsInWedge;//returns empty
215  }
216  //assigns a vector of {nullPad} (size 1) on a layer if it has no hits
217  auto addEmptyLayerIfAny=[]( std::vector<std::shared_ptr<PadData> >& layerPads)->void{
218  if(layerPads.empty()){
219  std::vector<std::shared_ptr<PadData>> emptyLayer;
220  std::shared_ptr<PadData> nullPad=std::make_shared<PadOfflineData>(Identifier(0), 0, 0, nullptr);//do not change the null pointer !
221  emptyLayer.push_back(nullPad);
222  layerPads=emptyLayer;
223  }
224  };
225 
226  addEmptyLayerIfAny(padsOnLayer1);
227  addEmptyLayerIfAny(padsOnLayer2);
228  addEmptyLayerIfAny(padsOnLayer3);
229  addEmptyLayerIfAny(padsOnLayer4);
230  //The neighborhood, in ieta and iphi, can be spanned by 1 at max in both directions (logic)
231  //Obviously , do not apply logic or any other kind of check if one layer is missing
232 
233  auto padBinaryLogic=[](const std::shared_ptr<PadData>& padNext,const std::shared_ptr<PadData>& padPrev)->bool{//compares two pads on consecutive layers
234  if(padNext->padNumber()==nullPadNumber || padPrev->padNumber() == nullPadNumber) return true;
235  else{
236  return std::abs(padNext->padNumber()-padPrev->padNumber() )==1 ||
237  std::abs(padNext->padNumber() -padPrev->padNumber() )==18 ||
238  std::abs(padNext->padNumber() -padPrev->padNumber() )==19 ||
239  std::abs(padNext->padNumber() -padPrev->padNumber() )==17 ||
240  (padNext->padNumber() -padPrev->padNumber() ==0);
241  }
242  };
243 
244  //given a set of pads check if all is within the same module...
245  auto allInSameModule=[](const std::vector<std::shared_ptr<PadData>>& pads)->bool{
246  if(pads.size()!=4) return false;//no need to check again here but extra protection doesnt hurt
247  int moduleIdFirst;
248  int ctr=0;
249  for(const std::shared_ptr<PadData>& pad : pads){
250  if(pad->padNumber()==nullPadNumber) continue;//ignore missing layer
251  if(ctr==0){
252  moduleIdFirst=pad->moduleId();
253  ctr++;
254  continue;
255  }
256  if(pad->moduleId()!=moduleIdFirst) return false;
257 
258  }
259  return true;
260  };
261  //Given a set of pads/module/wedge check if the given pad configuration satisfies the logic
262  //for 4 layer hit patterns use the 2-bits weak logic.
263  //if you want to scan all the legit triggers use full logic (with 3 bits for 4 layer hits!)
264  auto padTowerLogic=[&padBinaryLogic,&allInSameModule](const std::vector<std::shared_ptr<PadData>>& pads)->bool{
265  std::bitset<3> layerbits;//holds 0-->1 1-->2 2-->3 logic / transitions across consecutive layers
266  //==== check all pads have same module ids =====
267  if(not allInSameModule(pads)) return false;
268  for(unsigned i=0;i<4;i++){
269  if( padBinaryLogic(pads.at(i),pads.at(i+1)) ) layerbits.set(i); //sets bits 0 ,1 and 2 (layer transitions 0->1 1->2 2->3 )
270  if(i==2) break;
271  }
272  // for 3o4s the logic bits must be 1,1,1
273  //for 4o4s the bits must have at least two bits set (1 layer fault tolerance, to acount for noise as discussed with Y.R, E.K and Riccardo to mimic the hardware)
274  bool is4o4= true ? std::count_if(pads.begin(),pads.end(),[](const std::shared_ptr<PadData>& p){ return p->padNumber()==nullPadNumber;})==0 : false;
275  if(is4o4){
276  return layerbits.count()>=2;
277  }
278  else{//3o4
279  return layerbits.count()==3;
280  }
281  };
282  //as we are using pads/sector but not pads/module this will boost performance by eliminating meaningless pad combinations across different modules
283  auto sameModule=[](const std::shared_ptr<PadData>& padNext,const std::shared_ptr<PadData>& padPrev )->bool{
284  if(padNext->padNumber()==nullPadNumber || padPrev->padNumber() == nullPadNumber) return true;
285  else return (padNext->padNumber()/1000 == padPrev->padNumber()/1000);
286  /*
287  No need to check sector/side matching as the whole thing runs on per unique sector
288  */
289  };
290 
291  //We can remove the entire "allInSameModule" check as we do module checks with sameModule in nested loops (Gal spotted this)
292  for(const std::shared_ptr<PadData>& pad1 : padsOnLayer1 ){
293  for(const std::shared_ptr<PadData>& pad2 : padsOnLayer2 ){
294  if( !sameModule(pad2,pad1) ) continue;
295  for(const std::shared_ptr<PadData>& pad3 : padsOnLayer3 ){
296  if( !sameModule(pad3,pad2) ) continue;
297  for(const std::shared_ptr<PadData>& pad4 : padsOnLayer4 ){
298  if( !sameModule(pad4,pad3) ) continue;
299  std::vector<std::shared_ptr<PadData>> patt={pad1,pad2,pad3,pad4};
300  if(! padTowerLogic(patt) ) continue;
301  padCombinationsInWedge.emplace_back(std::vector<std::shared_ptr<PadData> >({pad1,pad2,pad3,pad4}) );
302  }
303  }
304  }
305  }
306  return padCombinationsInWedge;
307  }
308 
309  StatusCode PadTriggerLookupTool::LookupSectorTriggers(const std::vector<std::shared_ptr<PadData>>& pads,int side, int sector, std::vector<std::unique_ptr<PadTrigger>> &triggers){
310  const int STGCINNER=1;
311  const int STGCOUTER=2;
312  auto inOutModuleMatch=[](const std::vector<std::shared_ptr<PadData>>& inM,const std::vector<std::shared_ptr<PadData>>& outM)->bool{
313  for(const auto& in : inM){
314  for(const auto& out : outM){
315  if(in->padNumber()!=nullPadNumber && out->padNumber()!=nullPadNumber ){
316  //if youre not sure what these numbers are here and all around see PadOfflineData::padNumber()
317  return out->padNumber()/1000-in->padNumber()/1000 <=1;
318  }
319  }
320  }
321  return false;
322  };
323 
324  std::vector<std::pair<int,int> > uniqueBandPhiIds;//just to keep track of the unique triggers found within this lookup call
325  std::vector<std::vector<std::shared_ptr<PadData>> > innerPatterns=selectWedgePatterns(pads, side, sector,STGCINNER);
326  std::vector<std::vector<std::shared_ptr<PadData>> > outerPatterns=selectWedgePatterns(pads, side, sector,STGCOUTER);
327  if(innerPatterns.empty()){
328  ATH_MSG_WARNING(" No hit patterns found / inner wedge");
329  return StatusCode::SUCCESS;
330  }
331  if(outerPatterns.empty()){
332  ATH_MSG_WARNING(" No hit patterns found / outer wedge");
333  return StatusCode::SUCCESS;
334  }
335 
336  for(const std::vector<std::shared_ptr<PadData>>& inner: innerPatterns){
337  for(const std::vector<std::shared_ptr<PadData>>& outer: outerPatterns){
338  //concatenate the two if modules match then Lookup
339  if(! inOutModuleMatch(inner,outer)) continue;
340  std::vector<std::shared_ptr<PadData>> combinedInOut;
341  combinedInOut.insert(combinedInOut.end(),inner.begin(),inner.end());
342  combinedInOut.insert(combinedInOut.end(),outer.begin(),outer.end());
343  //convert set of pads into numbers as in the LUT
344  std::vector<int> pads2Numbers;
345  std::transform(combinedInOut.begin(),combinedInOut.end(),std::back_inserter(pads2Numbers),[](const std::shared_ptr<PadData>& p){ return p->padNumber();});
346  std::pair<int,int> lookupValue=Lookup(pads2Numbers);
347  if(lookupValue.first<0) continue;//{ //no trigger is found yet
348  //append pads to triggers + fill in unique triggers
349  //if band and phi id found is already in the list of sector triggers do not add it to the list
350  //uniqueness defined by sideId /sectorId /bandId /phiId (!!!not only band and phiIds !!!)
351  auto trgpos=std::find_if(triggers.begin(),triggers.end(),
352  [&lookupValue,&side,&sector](const std::unique_ptr<PadTrigger>&tr){
353  return tr->bandId() == lookupValue.second &&
354  tr->phiId() == lookupValue.first &&
355  tr->triggerSectorNumber() == sector &&
356  tr->sideId() == side;
357  });
358  if( trgpos != triggers.end() ) continue;//trigger already exists int the list ... skip
359  uniqueBandPhiIds.push_back(lookupValue);
360  //otherwise instantiate a trigger and append to the list
361  auto trigger=std::make_unique<PadTrigger>();//TODO : PadTrigger needs to be rewriten as a proper class.using a C struct is too messy
362  std::copy(combinedInOut.begin(),combinedInOut.begin()+4,std::back_inserter(trigger->m_padsInner));
363  std::copy(combinedInOut.begin()+4,combinedInOut.end(),std::back_inserter(trigger->m_padsOuter));
364  std::copy(combinedInOut.begin(),combinedInOut.end(),std::back_inserter(trigger->m_pads));
365  trigger->m_bandid=lookupValue.second;
366  trigger->m_phi_id=lookupValue.first;
367  int triggerSectorType=trigger->firstPad()->sectorType();//S:0/1:L
368  switch(triggerSectorType){
369  case(0)://S
370  //Y.R says band ids should start from 2, so to convert it to a C index subtract 2 from bandId
371  //See the header file sTGCTriggerBandsInEta (strip channels<--> bands must be implmeneted in the XML and this eta mased matching must be abandoned. The existing XML values are wrong)
372  trigger->m_etamin=m_etaBandsSmallSector.at(trigger->bandId()-1);
373  trigger->m_etamax=m_etaBandsSmallSector.at(trigger->bandId()-2);
374  break;
375  case(1)://L
376  // The same subtraction likewise for L as well
377  trigger->m_etamin=m_etaBandsLargeSector.at(trigger->bandId()-1);
378  trigger->m_etamax=m_etaBandsLargeSector.at(trigger->bandId()-2);
379  break;
380 
381  default:
382  ATH_MSG_FATAL("Unable to determine trigger sector type");
383  break;
384  }
385  triggers.push_back(std::move(trigger));
386  }
387  }
388 
389  ATH_MSG_DEBUG("Found "<<uniqueBandPhiIds.size()<<" unique triggers from LUT");
390  //Upto this point no geometry is used ... i.e no pad corners , no tower roi , no overlap area etc ....
391  //In principle band id should be suficient to select strips . But we dont have the band configuration in the XML yet ...
392  //so we have to stick to the eta-based strip selection for now ....
393 
394  return StatusCode::SUCCESS;
395 
396  }
397  //grabs a whole sector pads with Identifiers and 3D geometry information available
398  /* The method is necessary to create pad coincidence LUT by using the methods within this class
399  also useful to dump the full geometetry for geometry validation& side studies(see 'printGeometry' meth. and corresponding flag in the JO)
400  */
401  std::vector<std::shared_ptr<PadOfflineData>> PadTriggerLookupTool::fetchSectorPads(bool isSmall, int SIDE,int SECTOR) {
402 
403  std::vector<std::shared_ptr<PadOfflineData>> sectorPads;
404  std::vector<Identifier> padIds;
405 
406  for(const Identifier& modId : m_idHelperSvc->stgcIdHelper().idVector() ){
407  int ModuleSide=1?m_idHelperSvc->stgcIdHelper().stationEta(modId)>0 :0;
408  int ModuleSect=m_idHelperSvc->stgcIdHelper().stationPhi(modId);
409  bool SectType=m_idHelperSvc->stgcIdHelper().isSmall(modId);
410  if(ModuleSide!=SIDE || ModuleSect !=SECTOR || SectType!=isSmall) continue;//grab only sector modules selected by the method args
411  std::vector<Identifier> all_channels;
412  m_idHelperSvc->stgcIdHelper().idChannels(modId,all_channels);
413 
414  std::vector<Identifier> pad_channels;
415  const sTgcIdHelper* idHelper = &m_idHelperSvc->stgcIdHelper();
416  std::copy_if(all_channels.begin(),all_channels.end(),std::back_inserter(pad_channels),
417  [idHelper](const Identifier& id){
418  int chanType=idHelper->channelType(id);
419  return chanType==0;
420  }
421  );
422  padIds.insert(padIds.end(),pad_channels.begin(),pad_channels.end());
423 
424  }
425 
426  for(Identifier id : padIds){
427  int multilayer=m_idHelperSvc->stgcIdHelper().multilayer(id);
428  int gasgap=m_idHelperSvc->stgcIdHelper().gasGap(id);
429 
430  int channeltype=m_idHelperSvc->stgcIdHelper().channelType(id);
432  const MuonGM::MuonPadDesign* mpd=rdoEl->getPadDesign(id);
433  int padEtaMinFromDesign=mpd->padEtaMin;
434  int padEtaMaxFromDesign=mpd->padEtaMax;
435  int nPadCols=mpd->nPadColumns;
436 
437  int thisEta=m_idHelperSvc->stgcIdHelper().padEta(id);
438  int thisPhi=m_idHelperSvc->stgcIdHelper().padPhi(id);
439 
440  int nPadRowsFromDesign=padEtaMaxFromDesign-padEtaMinFromDesign;
441  if( thisEta>nPadRowsFromDesign || thisPhi > nPadCols ) continue;
442 
443  Identifier pid=m_idHelperSvc->stgcIdHelper().padID(id, multilayer, gasgap, channeltype, thisEta, thisPhi);
444  auto pad=std::make_shared<PadOfflineData>(pid, 0, 0, m_detManager);
445  pad->fillGeometricInformation();
446  sectorPads.push_back(pad);
447  }
448  return sectorPads;
449  }
450  //check the header, default sector is 1 default side is 1
451 
452 
453  //just as some wrapping for other sectors
454  std::vector<std::shared_ptr<PadOfflineData>> PadTriggerLookupTool::fetchSmallSectorPads(int side,int sector){
455  return fetchSectorPads(true,side,sector);
456  }
457  std::vector<std::shared_ptr<PadOfflineData>> PadTriggerLookupTool::fetchLargeSectorPads(int side,int sector){
458  return fetchSectorPads(false,side,sector);
459  }
460 
461 StatusCode PadTriggerLookupTool::printGeometry( const std::vector<std::shared_ptr<PadOfflineData> >& pads, std::ofstream& ofile) const {
462  const static std::vector<int> vertexordering={0,1,3,2};
463  if(! ofile.is_open()){
464  ATH_MSG_FATAL("File is not open!");
465  }
466  auto dumpPadGeometry=[&ofile](const std::shared_ptr<PadOfflineData>& p)->void{
467  Vertices padVertices;
468  for(int i=0;i<4;i++){//four corners
469  int index=vertexordering.at(i);
470  float x=p->m_cornerXyz[index][0];
471  float y=p->m_cornerXyz[index][1];
472  Vertex vtx(x,y);
473  padVertices.push_back(std::move(vtx));
474  }
475  std::string secType= p->sectorType()==1 ? "LARGE": "SMALL";
476  float layerZ=p->m_cornerXyz[0][2];
477  Polygon padPolygon=buildPolygon(padVertices);
478  std::stringstream ss;
479  ss<<secType<<" multilayer="<<p->multipletId()<<" module="<<p->moduleId()<<" layer="<<p->gasGapId()<<" layerZ="<<layerZ<<" iEta="<<p->padEtaId()<<" iPhi="<<p->padPhiId()<<" <--> "<<boost::geometry::wkt(padPolygon)<<std::endl;
480  ofile<<ss.rdbuf();
481  };
482  std::for_each(pads.begin(),pads.end(),dumpPadGeometry);
483  return StatusCode::SUCCESS;
484 }
485 
486 //Given a pattern check if it is in the LUT if yes get bandId and PhiId
487  std::pair<int,int> PadTriggerLookupTool::Lookup( std::vector<int> patt){
488  auto pos=m_pats.find(patt);//should be consant in time
489  if( pos != m_pats.end() ){//if something is found from this pattern then return it
490  return pos->second;
491  }
492 
493  //if nothing is found yet, check if the pattern is 4o4+4o4 or 3o4+3o4 + ... etc
494  //if 3o4+3o4 return (-1,-1) i.e nothing to lookup up furthermore
495  //else if 4o4+4o4 or 4o4+3o4 or vice versa continue lookup by removing layers from 4o4s ...
496  int nullCountInner=std::count(patt.begin(),patt.begin()+4,nullPadNumber);
497  int nullCountOuter=std::count(patt.begin()+4,patt.end(),nullPadNumber);
498  if(nullCountInner+nullCountOuter==2) return std::pair<int,int>(-1,-1);
499  if( nullCountInner ==0 ){//outer is then 3o4, dont touch outer, remove layers from inner + lookup
500  for(int i :{0,1,2,3}){
501  int valueOnLayer=patt.at(i);
502  patt.at(i)=nullPadNumber;//removes layer
503  auto pos=m_pats.find(patt);
504  if( pos!=m_pats.end() ) return pos->second;
505  patt.at(i)=valueOnLayer;//add the layer back
506  }
507  }
508  if( nullCountOuter ==0 ){// inner is then 3o4 dont touch inner, remove layers from outer+lookup
509  for(int i :{4,5,6,7}){
510  int valueOnLayer=patt.at(i);
511  patt.at(i)=nullPadNumber;//removes layer
512  auto pos=m_pats.find(patt);
513  if( pos!=m_pats.end() ) return pos->second;
514  patt.at(i)=valueOnLayer;//add the layer back
515  }
516  }
517  return std::pair<int,int>(-1,-1);
518  }
519 
520 } // NSWL1
NSWL1::PadTriggerLookupTool::m_dumpSectorGeometry
Gaudi::Property< bool > m_dumpSectorGeometry
Definition: PadTriggerLookupTool.h:52
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
mergePhysValFiles.pattern
pattern
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:26
MuonGM::MuonPadDesign
Parameters defining the design of the readout sTGC pads.
Definition: MuonPadDesign.h:40
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
checkFileSG.line
line
Definition: checkFileSG.py:75
NSWL1::PadTriggerLookupTool::selectWedgePatterns
std::vector< std::vector< std::shared_ptr< PadData > > > selectWedgePatterns(const std::vector< std::shared_ptr< PadData >> &pads, int side, int sector, int multiplet) const
Definition: PadTriggerLookupTool.cxx:182
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
tdr_compat_enum.h
run.infile
string infile
Definition: run.py:13
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
NSWL1::PadTriggerLookupTool::m_etaBandsSmallSector
const std::vector< float > m_etaBandsSmallSector
Definition: PadTriggerLookupTool.h:59
sTgcReadoutElement.h
index
Definition: index.py:1
PadData.h
NSWL1::Vertex
boost::geometry::model::d2::point_xy< double > Vertex
Definition: GeoUtils.h:17
NSWL1::BandsInEtaLargeSector
const std::vector< float > BandsInEtaLargeSector
Definition: sTGCTriggerBandsInEta.h:16
NSWL1::BandsInEtaSmallSector
const std::vector< float > BandsInEtaSmallSector
Definition: sTGCTriggerBandsInEta.h:111
validation.ofile
ofile
Definition: validation.py:96
NSWL1::Polygon
boost::geometry::model::polygon< Vertex > Polygon
Definition: GeoUtils.h:18
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
makeHists.thisPhi
thisPhi
Definition: makeHists.py:127
NSWL1::PadTriggerLookupTool::expandCoincidenceTable
StatusCode expandCoincidenceTable()
Definition: PadTriggerLookupTool.cxx:126
NSWL1::PadTriggerLookupTool::m_detManager
const MuonGM::MuonDetectorManager * m_detManager
Definition: PadTriggerLookupTool.h:63
python.TrigTLAMonitorAlgorithm.triggers
triggers
Definition: TrigTLAMonitorAlgorithm.py:196
x
#define x
NSWL1::PadTriggerLookupTool::fetchSectorPads
std::vector< std::shared_ptr< PadOfflineData > > fetchSectorPads(bool isSmall, int side=1, int sector=1)
Definition: PadTriggerLookupTool.cxx:401
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
NSWL1::PadTriggerLookupTool::handle
virtual void handle(const Incident &inc) override
Definition: PadTriggerLookupTool.cxx:57
TRT::Hit::side
@ side
Definition: HitInfo.h:83
sTGCDetectorDescription.h
NSWL1::hashPattern
Definition: PadTriggerLookupTool.h:29
lumiFormat.i
int i
Definition: lumiFormat.py:92
NSWL1::PadTriggerLookupTool::printGeometry
StatusCode printGeometry(const std::vector< std::shared_ptr< PadOfflineData >> &, std::ofstream &) const
Definition: PadTriggerLookupTool.cxx:461
MuonGM::MuonPadDesign::padEtaMax
int padEtaMax
Definition: MuonPadDesign.h:47
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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
MuonGM::sTgcReadoutElement
An sTgcReadoutElement corresponds to a single STGC module; therefore typicaly a barrel muon station c...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/sTgcReadoutElement.h:28
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
sTGCTriggerBandsInEta.h
ParticleGun_EoverP_Config.pid
pid
Definition: ParticleGun_EoverP_Config.py:62
file
TFile * file
Definition: tile_monitor.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
AnalysisUtils::copy_if
Out copy_if(In first, const In &last, Out res, const Pred &p)
Definition: IFilterUtils.h:30
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
NSWL1::PadTriggerLookupTool::loadCoincidenceTable
StatusCode loadCoincidenceTable(const std::string &)
load the 4o4 coincidence table
Definition: PadTriggerLookupTool.cxx:94
sTGCDetectorHelper.h
find_tgc_unfilled_channelids.all_channels
all_channels
Definition: find_tgc_unfilled_channelids.py:18
NSWL1::nullPadNumber
const int nullPadNumber
Definition: tdr_compat_enum.h:21
NSWL1::PadTriggerLookupTool::m_pats
std::unordered_map< std::vector< int >, std::pair< int, int >,hashPattern > m_pats
Definition: PadTriggerLookupTool.h:70
PathResolver.h
python.selection.number
number
Definition: selection.py:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
PadOfflineData.h
sTgcIdHelper
Definition: sTgcIdHelper.h:55
MuonGM::MuonPadDesign::nPadColumns
int nPadColumns
Definition: MuonPadDesign.h:69
PadTriggerLookupTool.h
NSWL1::PadTriggerLookupTool::Lookup
std::pair< int, int > Lookup(std::vector< int >)
Definition: PadTriggerLookupTool.cxx:487
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
NSWL1::PadTriggerLookupTool::m_etaBandsLargeSector
const std::vector< float > m_etaBandsLargeSector
Definition: PadTriggerLookupTool.h:58
NSWL1::PadTriggerLookupTool::PadTriggerLookupTool
PadTriggerLookupTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: PadTriggerLookupTool.cxx:28
DeMoScan.index
string index
Definition: DeMoScan.py:362
y
#define y
NSWL1::PadTriggerLookupTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: PadTriggerLookupTool.h:51
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
NSWL1::PadTriggerLookupTool::initialize
virtual StatusCode initialize() override
Definition: PadTriggerLookupTool.cxx:36
calibdata.copy
bool copy
Definition: calibdata.py:27
MuonGM::sTgcReadoutElement::getPadDesign
const MuonPadDesign * getPadDesign(const Identifier &id) const
returns the MuonChannelDesign class for the given identifier
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/sTgcReadoutElement.h:287
SIDE
SIDE
Definition: CellClusterLinkTool.h:52
PadTrigger.h
MuonGM::MuonDetectorManager::getsTgcReadoutElement
const sTgcReadoutElement * getsTgcReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:259
NSWL1::PadTriggerLookupTool::fetchSmallSectorPads
std::vector< std::shared_ptr< PadOfflineData > > fetchSmallSectorPads(int side=1, int sector=1)
Definition: PadTriggerLookupTool.cxx:454
AthAlgTool
Definition: AthAlgTool.h:26
NSWL1::PadTriggerLookupTool::fetchLargeSectorPads
std::vector< std::shared_ptr< PadOfflineData > > fetchLargeSectorPads(int side=1, int sector=1)
Definition: PadTriggerLookupTool.cxx:457
dqt_zlumi_alleff_HIST.ctr
ctr
Definition: dqt_zlumi_alleff_HIST.py:193
NSWL1::PadTriggerLookupTool::lookup_pad_triggers
virtual StatusCode lookup_pad_triggers(const std::vector< std::shared_ptr< PadData >> &pads, std::vector< std::unique_ptr< PadTrigger >> &triggers) override
Definition: PadTriggerLookupTool.cxx:67
NSWL1
A trigger trigger candidate for a stgc sector.
Definition: NSWL1Simulation.cxx:9
NSWL1::Vertices
std::vector< Vertex > Vertices
Definition: GeoUtils.h:19
MuonGM::MuonPadDesign::padEtaMin
int padEtaMin
Definition: MuonPadDesign.h:46
NSWL1::buildPolygon
Polygon buildPolygon(const Vertices &pts)
Definition: GeoUtils.cxx:44
PhysDESDM_Quirks.trigger
trigger
Definition: PhysDESDM_Quirks.py:27
NSWL1::PadTriggerLookupTool::LookupSectorTriggers
StatusCode LookupSectorTriggers(const std::vector< std::shared_ptr< PadData >> &pads, int side, int sector, std::vector< std::unique_ptr< PadTrigger >> &triggers)
Definition: PadTriggerLookupTool.cxx:309