CMS 3D CMS Logo

RPCTrigger.cc
Go to the documentation of this file.
2 
3 // Configuration via eventsetup:
6 
9 
12 
15 
16 
17 
18 //#define ML_DEBUG
19 
20 
21 
23 
24 
26  m_trigConfig(),m_pacTrigger(),
27  // 0 - no debug
28  // 1 - dump to xml
29  m_triggerDebug{iConfig.getUntrackedParameter<int>("RPCTriggerDebug",0) == 1? 1 : 0},
30  m_cacheID{0},
31  m_label{iConfig.getParameter<std::string>("label")},
32  m_rpcDigiToken{consumes<RPCDigiCollection>(m_label)},
33 
34  m_brlCandPutToken{produces<std::vector<L1MuRegionalCand> >("RPCb")},
35  m_fwdCandPutToken{produces<std::vector<L1MuRegionalCand> >("RPCf")},
36 
37  m_brlLinksPutToken{produces<std::vector<RPCDigiL1Link> >("RPCb")},
38  m_fwdLinksPutToken{produces<std::vector<RPCDigiL1Link> >("RPCf")}
39 {
40  //MuonsGrabber is a singleton
41  usesResource("MuonsGrabber");
42 }
43 
44 void
46 {
47 
48  //static int ev=1;
49  //std::cout << "----------------------------------- " << ev++ << std::endl;
50  if ( m_triggerDebug == 1) MuonsGrabber::Instance().startNewEvent(iEvent.id().event(), iEvent.bunchCrossing());
51 
52  if (m_cacheID != iSetup.get<L1RPCConfigRcd>().cacheIdentifier()) {
53 
54  //std::cout << " New pats: " << iSetup.get<L1RPCConfigRcd>().cacheIdentifier() << std::endl ;
55  m_cacheID = iSetup.get<L1RPCConfigRcd>().cacheIdentifier();
56 
58  iSetup.get<L1RPCConfigRcd>().get(conf);
59  const L1RPCConfig *rpcconf = conf.product();
60 
61  m_pacManager.init(rpcconf);
62  m_trigConfig = std::make_unique<RPCBasicTrigConfig>(&m_pacManager);
63  m_trigConfig->setDebugLevel(m_triggerDebug);
64 
65  m_pacTrigger = std::make_unique<RPCPacTrigger>(m_trigConfig.get());
66 
68  }
69 
70 
72  iEvent.getByToken(m_rpcDigiToken, rpcDigis);
73 
74  std::vector<L1MuRegionalCand> candBarell;
75  std::vector<L1MuRegionalCand> candForward;
76  if (!rpcDigis.isValid())
77  {
78  LogDebug("RPCTrigger")
79  << "\nWarning: RPCDigiCollection with input tag " << m_label
80  << "\nrequested in configuration, but not found in the event. Emulator will produce empty collection \n ";
81 
82  iEvent.emplace(m_brlCandPutToken, std::move(candBarell) );
83  iEvent.emplace(m_fwdCandPutToken, std::move(candForward) );
84 
85  return;
86  }
87 
88 
89  if (rpcDigis->begin() == rpcDigis->end() )
90  {
91  LogDebug("RPCTrigger")
92  << "\nWarning: RPCDigiCollection with input tag " << m_label
93  << "\n seems to be empty for this event. Emulator will run on empty collection ";
94 
95  }
96 
97 
98 
99  std::vector<RPCDigiL1Link> brlLinks;
100  std::vector<RPCDigiL1Link> fwdLinks;
101 
103  iSetup.get<L1RPCConeBuilderRcd>().get(coneBuilder);
104 
105  edm::ESHandle<L1RPCConeDefinition> l1RPCConeDefinition;
106  iSetup.get<L1RPCConeDefinitionRcd>().get(l1RPCConeDefinition);
107 
109  iSetup.get<L1RPCHwConfigRcd>().get(hwConfig);
110 
112  iSetup.get<L1RPCBxOrConfigRcd>().get(bxOrConfig);
113 
115  iSetup.get<L1RPCHsbConfigRcd>().get(hsbConfig);
116 
117 
118  for (int iBx = -1; iBx < 2; ++ iBx) {
119 
120  L1RpcLogConesVec ActiveCones = m_theLinksystemFromES.getConesFromES(rpcDigis, coneBuilder, l1RPCConeDefinition, bxOrConfig, hwConfig, iBx);
121 
122  L1RpcTBMuonsVec2 finalMuons = m_pacTrigger->runEvent(ActiveCones, hsbConfig);
123 
124  //int maxFiredPlanes = 0;
125 
126  /*
127  for (unsigned int i=0;i<ActiveCones.size();i++){
128  int fpCnt = ActiveCones[i].getFiredPlanesCnt();
129  if (fpCnt > maxFiredPlanes)
130  maxFiredPlanes = fpCnt;
131  }
132 
133  // Fill out the products
134  // finalMuons[0]=barell, finalMuons[1]=endcap
135  LogDebug("RPCTrigger") << "---Filling candindates in new event--- "
136  << maxFiredPlanes << std::endl;
137 <<<<<<< RPCTrigger.cc
138  */
139 
140 // std::vector<L1MuRegionalCand> RPCb = giveFinallCandindates(finalMuons[0],1, iBx);
141 // std::vector<L1MuRegionalCand> RPCf = giveFinallCandindates(finalMuons[1],3, iBx);
142  std::vector<RPCDigiL1Link> dlBrl;
143  std::vector<RPCDigiL1Link> dlFwd;
144  std::vector<L1MuRegionalCand> RPCb = giveFinallCandindates(finalMuons[0],1, iBx, rpcDigis, dlBrl);
145  std::vector<L1MuRegionalCand> RPCf = giveFinallCandindates(finalMuons[1],3, iBx, rpcDigis, dlFwd);
146 
147 
148  brlLinks.insert(brlLinks.end(), dlBrl.begin(), dlBrl.end() );
149  fwdLinks.insert(fwdLinks.end(), dlFwd.begin(), dlFwd.end() );
150 
151  candBarell.insert(candBarell.end(), RPCb.begin(), RPCb.end());
152  candForward.insert(candForward.end(), RPCf.begin(), RPCf.end());
153 
155  }
156 
157  iEvent.emplace(m_fwdLinksPutToken, std::move(fwdLinks));
158  iEvent.emplace(m_brlLinksPutToken, std::move(brlLinks));
159  iEvent.emplace(m_brlCandPutToken, std::move(candBarell));
160  iEvent.emplace(m_fwdCandPutToken, std::move(candForward));
161 
162 }
164 
171 std::vector<L1MuRegionalCand> RPCTrigger::giveFinallCandindates(const L1RpcTBMuonsVec& finalMuons, int type, int bx,
173  edm::Handle<RPCDigiCollection> rpcDigis, std::vector<RPCDigiL1Link> & retRPCDigiLink)
174 {
175 
176  std::vector<L1MuRegionalCand> RPCCand;
177 
178  for(unsigned int iMu = 0; iMu < finalMuons.size(); iMu++)
179  {
180 
181  if (finalMuons[iMu].getPtCode()==0){
182  continue;
183  }
184 
185  RPCDigiL1Link newDigiLink;
186 
187  //std::cout << "######################################## " << std::endl;
188  //std::cout << finalMuons[iMu].getPhiAddr() << " " << finalMuons[iMu].getEtaAddr() << std::endl;
189  RPCMuon::TDigiLinkVec digiIVec = finalMuons[iMu].getDigiIdxVec();
190  // Here the iteration has to be the same as in
191  short int digiIndex = 0;
193  for (detUnitIt=rpcDigis->begin();
194  detUnitIt!=rpcDigis->end();
195  ++detUnitIt)
196  {
197 
198  const RPCDetId& id = (*detUnitIt).first;
199  uint32_t rawId = id.rawId();
200  const RPCDigiCollection::Range& range = (*detUnitIt).second;
201 
202 
203  for (RPCDigiCollection::const_iterator digiIt = range.first;
204  digiIt!=range.second;
205  ++digiIt)
206  {
207  ++digiIndex;
208 
209  RPCMuon::TDigiLinkVec::iterator it = digiIVec.begin();
210  for(;it!=digiIVec.end();++it) {
211  if (digiIndex==it->m_digiIdx) {
212  newDigiLink.setLink(it->m_layer+1, rawId, digiIt->strip(), digiIt->bx() );
213  //std::cout << type << " " << iMu << " layer: " << it->m_layer << " index " << it->m_digiIdx << std::endl;
214  //std::cout << " " << id << " " << " |bx " << digiIt->bx() << " strip " << digiIt->strip() << std::endl;
215  }
216  }
217  }
218  }
219  retRPCDigiLink.push_back(newDigiLink);
220 
221 
222  L1MuRegionalCand l1Cand;
223 
224  l1Cand.setBx(bx);
225 
226 
227  l1Cand.setQualityPacked(finalMuons[iMu].getQuality());
228  l1Cand.setPtPacked(finalMuons[iMu].getPtCode());
229 
230  l1Cand.setType(type);
231 
232  int charge=finalMuons[iMu].getSign();
233 
234  if (charge == 0) // negative
235  l1Cand.setChargePacked(1);
236  else
237  l1Cand.setChargePacked(0);
238 
239  //RPCConst::l1RpcConeCrdnts cone = finalMuons[iMu].getConeCrdnts();
240 
241  /*
242  int pac = cone.m_LogSector*12+cone.m_LogSegment;
243  const float pi = 3.14159265;
244  const float offset = 5*(2*pi/360); // redefinition! Defined also in RPCRingFromRolls::phiMapCompare
245  float phi = 2*pi*pac/144-offset;
246  if (phi<0)
247  phi+=2*pi;
248 
249  l1Cand.setPhiValue(phi);
250  */
251 
252  //Note: pac numbering begins at 5 deg and goes from 1 to 144.
253  // we want phi values from 0 to 2.5 deg to be phiPacked=0
254  // max phiPacked value is 143 (see CMS IN 2004-022)
255  //int phiPacked = (finalMuons[iMu].getPhiAddr()+2)%144;
256  int phiPacked = finalMuons[iMu].getPhiAddr();
257  l1Cand.setPhiPacked(phiPacked);
258 /*
259  float eta = RPCConst::etaFromTowerNum(cone.m_Tower);
260  l1Cand.setEtaValue(eta);
261 */
262  //Note: etaAddr is packed in special way: see CMS IN 2004-022
263  signed short etaAddr = finalMuons[iMu].getEtaAddr(); //
264 // signed short etaAddr = finalMuons[iMu].getEtaAddr()-16; // -16..16
265 // bool etaNegative = false;
266 // if (etaAddr < 0){
267 // etaNegative = true;
268 // etaAddr = ~(-etaAddr)+1; // convert to negative :)
269 // }
270 
271 // etaAddr &= 63; // 6 bits only
272 
273  l1Cand.setEtaPacked(etaAddr);
274  l1Cand.setChargeValid(true);
275 
276  /*
277  std::cout<< std::endl << "RBMuon::" << finalMuons[iMu].getEtaAddr() << " "
278  << finalMuons[iMu].getPhiAddr() << std::endl ;
279  std::cout<< "cand " << l1Cand.eta_packed() << " "
280  << l1Cand.phi_packed() << std::endl ;
281  */
282 
283  RPCCand.push_back(l1Cand);
284 
285  LogDebug("RPCTrigger") << "Found muonf of pt "
286  << finalMuons[iMu].getPtCode()
287  << " bx " << l1Cand.bx()
288  << " L1Charge " << l1Cand.charge_packed()
289  << " ql " << l1Cand.quality()
290  << " fp " << finalMuons[iMu].getFiredPlanes()
291  << " b/f " << l1Cand.type_idx()
292  << " phi " << l1Cand.phi_packed()
293  << " eta " << l1Cand.eta_packed()
294  //<< " eta l1 " << l1Cand.etaValue() // will drop out soon
295  << " killed " << finalMuons[iMu].wasKilled();
296 
297 
298  }
299 
300  return RPCCand;
301 }
302 
#define LogDebug(id)
type
Definition: HCALResponse.h:21
EventNumber_t event() const
Definition: EventID.h:41
unsigned long long cacheIdentifier() const
T getUntrackedParameter(std::string const &, T const &) const
const edm::EDPutTokenT< std::vector< L1MuRegionalCand > > m_fwdCandPutToken
Definition: RPCTrigger.h:77
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::unique_ptr< RPCBasicTrigConfig > m_trigConfig
Definition: RPCTrigger.h:63
const edm::EDPutTokenT< std::vector< RPCDigiL1Link > > m_brlLinksPutToken
Definition: RPCTrigger.h:79
unsigned charge_packed() const
return charge packed as in hardware (0=pos, 1=neg)
L1RpcLogConesVec getConesFromES(edm::Handle< RPCDigiCollection > rpcDigis, edm::ESHandle< L1RPCConeBuilder > coneBuilder, edm::ESHandle< L1RPCConeDefinition > coneDef, edm::ESHandle< L1RPCBxOrConfig > bxOrDef, edm::ESHandle< L1RPCHwConfig > hwConfig, int bx)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
int bunchCrossing() const
Definition: EventBase.h:64
void produce(edm::Event &, const edm::EventSetup &) override
Definition: RPCTrigger.cc:45
std::vector< L1MuRegionalCand > giveFinallCandindates(const L1RpcTBMuonsVec &finalMuons, int type, int bx, edm::Handle< RPCDigiCollection > rpcDigis, std::vector< RPCDigiL1Link > &retRPCDigiLink)
Returns vector of L1MuRegionalCand (input of L1GMT)
Definition: RPCTrigger.cc:172
const std::string m_label
Definition: RPCTrigger.h:73
static MuonsGrabber & Instance()
Definition: MuonsGrabber.cc:58
void setRPCBasicTrigConfig(RPCBasicTrigConfig *c)
Definition: MuonsGrabber.h:61
void setBx(int bx)
Set Bunch Crossing.
int iEvent
Definition: GenABIO.cc:224
std::vector< RPCTBMuon > L1RpcTBMuonsVec
Definition: RPCTBMuon.h:206
void startNewEvent(int event, int bx)
const int m_triggerDebug
Definition: RPCTrigger.h:67
RPCPacManager< RPCPacData > m_pacManager
Definition: RPCTrigger.h:61
std::vector< L1RpcTBMuonsVec > L1RpcTBMuonsVec2
Definition: RPCTBMuon.h:207
unsigned eta_packed() const
return eta packed as in hardware
void setType(unsigned type)
Set Type: 0 DT, 1 bRPC, 2 CSC, 3 fRPC.
bool isValid() const
Definition: HandleBase.h:74
RPCConeBuilderFromES m_theLinksystemFromES
Definition: RPCTrigger.h:59
const edm::EDPutTokenT< std::vector< RPCDigiL1Link > > m_fwdLinksPutToken
Definition: RPCTrigger.h:80
void setChargePacked(unsigned ch)
Set Charge (0=pos, 1=neg)
std::vector< TDigiLink > TDigiLinkVec
Definition: RPCMuon.h:77
void setPtPacked(unsigned pt)
Set Pt: 0..31.
OrphanHandle< PROD > emplace(EDPutTokenT< PROD > token, Args &&...args)
puts a new product
Definition: Event.h:413
std::vector< RPCDigi >::const_iterator const_iterator
unsigned int quality() const
return quality
const edm::EDPutTokenT< std::vector< L1MuRegionalCand > > m_brlCandPutToken
Definition: RPCTrigger.h:76
RPCTrigger(const edm::ParameterSet &)
Definition: RPCTrigger.cc:25
void setPhiPacked(unsigned phi)
Set Phi: 0..143.
void init(std::string patFilesDirectory, L1RpcPACsCntEnum _PACsCnt)
Definition: RPCPacManager.h:60
int bx() const
return bunch crossing identifier
edm::EventID id() const
Definition: EventBase.h:59
void setQualityPacked(unsigned qual)
Set Quality: 0..7.
void setEtaPacked(unsigned eta)
Set Eta: 6-bit code.
T get() const
Definition: EventSetup.h:71
std::unique_ptr< RPCPacTrigger > m_pacTrigger
Definition: RPCTrigger.h:65
std::pair< const_iterator, const_iterator > Range
void setChargeValid(bool valid)
Set Charge Valid.
const edm::EDGetTokenT< RPCDigiCollection > m_rpcDigiToken
Definition: RPCTrigger.h:74
T const * product() const
Definition: ESHandle.h:86
void writeDataForRelativeBX(int bx)
unsigned type_idx() const
return type: 0 DT, 1 bRPC, 2 CSC, 3 fRPC
def move(src, dest)
Definition: eostools.py:511
std::vector< RPCLogCone > L1RpcLogConesVec
Definition: RPCLogCone.h:126
unsigned phi_packed() const
return phi packed as in hardware
unsigned long long m_cacheID
Definition: RPCTrigger.h:68