CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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(0),m_pacTrigger(0)
27 {
28  produces<std::vector<L1MuRegionalCand> >("RPCb");
29  produces<std::vector<L1MuRegionalCand> >("RPCf");
30 
31  produces<std::vector<RPCDigiL1Link> >("RPCb");
32  produces<std::vector<RPCDigiL1Link> >("RPCf");
33 
34  m_firstRun = true;
35  m_cacheID = 0;
36 
37 
38  m_triggerDebug = iConfig.getUntrackedParameter<int>("RPCTriggerDebug",0);
39 
40  // 0 - no debug
41  // 1 - dump to xml
42  if ( m_triggerDebug != 1){
43  m_triggerDebug = 0;
44  }
45 
46 
47  m_label = iConfig.getParameter<std::string>("label");
48 }
49 
50 
51 
52 
54  if (m_pacTrigger != 0) delete m_pacTrigger;
55  if (m_trigConfig != 0) delete m_trigConfig;
56 }
57 
58 
59 
60 void
62 {
63 
64  if ( m_triggerDebug == 1) MuonsGrabber::Instance().startNewEvent(iEvent.id().event(), iEvent.bunchCrossing());
65 
66  if (m_firstRun){
67 
68  m_cacheID = iSetup.get<L1RPCConfigRcd>().cacheIdentifier();
69  m_firstRun = false;
71  iSetup.get<L1RPCConfigRcd>().get(conf);
72  const L1RPCConfig *rpcconf = conf.product();
73 
74 
75  m_pacManager.init(rpcconf);
80 
81 
82  }
83 
84  if (m_cacheID != iSetup.get<L1RPCConfigRcd>().cacheIdentifier()) {
85 
86  //std::cout << " New pats: " << iSetup.get<L1RPCConfigRcd>().cacheIdentifier() << std::endl ;
87  m_cacheID = iSetup.get<L1RPCConfigRcd>().cacheIdentifier();
88 
90  iSetup.get<L1RPCConfigRcd>().get(conf);
91  const L1RPCConfig *rpcconf = conf.product();
92 
93  m_pacManager.init(rpcconf);
94  delete m_trigConfig;
97 
98  delete m_pacTrigger;
100 
102 
103 
104  }
105 
106 
107 
109 // iEvent.getByType(rpcDigis);
110  //iEvent.getByLabel("muonRPCDigis",rpcDigis);
111  iEvent.getByLabel(m_label, rpcDigis);
112 
113  std::auto_ptr<std::vector<L1MuRegionalCand> > candBarell(new std::vector<L1MuRegionalCand>);
114  std::auto_ptr<std::vector<L1MuRegionalCand> > candForward(new std::vector<L1MuRegionalCand>);
115  if (!rpcDigis.isValid())
116  {
117  LogDebug("RPCTrigger")
118  << "\nWarning: RPCDigiCollection with input tag " << m_label
119  << "\nrequested in configuration, but not found in the event. Emulator will produce empty collection \n ";
120 
121  iEvent.put(candBarell, "RPCb");
122  iEvent.put(candForward, "RPCf");
123 
124  return;
125  }
126 
127 
128  if (rpcDigis->begin() == rpcDigis->end() )
129  {
130  LogDebug("RPCTrigger")
131  << "\nWarning: RPCDigiCollection with input tag " << m_label
132  << "\n seems to be empty for this event. Emulator will run on empty collection ";
133 
134  }
135 
136 
137 
138  std::auto_ptr<std::vector<RPCDigiL1Link> > brlLinks(new std::vector<RPCDigiL1Link>);
139  std::auto_ptr<std::vector<RPCDigiL1Link> > fwdLinks(new std::vector<RPCDigiL1Link>);
140 
141  for (int iBx = -1; iBx < 2; ++ iBx) {
142 
143  L1RpcLogConesVec ActiveCones;
144 
146  iSetup.get<L1RPCConeBuilderRcd>().get(coneBuilder);
147 
148  edm::ESHandle<L1RPCConeDefinition> l1RPCConeDefinition;
149  iSetup.get<L1RPCConeDefinitionRcd>().get(l1RPCConeDefinition);
150 
152  iSetup.get<L1RPCHwConfigRcd>().get(hwConfig);
153 
155  iSetup.get<L1RPCBxOrConfigRcd>().get(bxOrConfig);
156 
157 
158 
159  ActiveCones = m_theLinksystemFromES.getConesFromES(rpcDigis, coneBuilder, l1RPCConeDefinition, bxOrConfig, hwConfig, iBx);
160 
162  iSetup.get<L1RPCHsbConfigRcd>().get(hsbConfig);
163 
164  L1RpcTBMuonsVec2 finalMuons = m_pacTrigger->runEvent(ActiveCones, hsbConfig);
165 
166  //int maxFiredPlanes = 0;
167 
168  /*
169  for (unsigned int i=0;i<ActiveCones.size();i++){
170  int fpCnt = ActiveCones[i].getFiredPlanesCnt();
171  if (fpCnt > maxFiredPlanes)
172  maxFiredPlanes = fpCnt;
173  }
174 
175  // Fill out the products
176  // finalMuons[0]=barell, finalMuons[1]=endcap
177  LogDebug("RPCTrigger") << "---Filling candindates in new event--- "
178  << maxFiredPlanes << std::endl;
179 <<<<<<< RPCTrigger.cc
180  */
181 
182 // std::vector<L1MuRegionalCand> RPCb = giveFinallCandindates(finalMuons[0],1, iBx);
183 // std::vector<L1MuRegionalCand> RPCf = giveFinallCandindates(finalMuons[1],3, iBx);
184  std::vector<RPCDigiL1Link> dlBrl;
185  std::vector<RPCDigiL1Link> dlFwd;
186  std::vector<L1MuRegionalCand> RPCb = giveFinallCandindates(finalMuons[0],1, iBx, rpcDigis, dlBrl);
187  std::vector<L1MuRegionalCand> RPCf = giveFinallCandindates(finalMuons[1],3, iBx, rpcDigis, dlFwd);
188 
189 
190  brlLinks->insert(brlLinks->end(), dlBrl.begin(), dlBrl.end() );
191  fwdLinks->insert(fwdLinks->end(), dlFwd.begin(), dlFwd.end() );
192 
193  candBarell->insert(candBarell->end(), RPCb.begin(), RPCb.end());
194  candForward->insert(candForward->end(), RPCf.begin(), RPCf.end());
195 
197  }
198 
199  iEvent.put(fwdLinks, "RPCf");
200  iEvent.put(brlLinks, "RPCb");
201  iEvent.put(candBarell, "RPCb");
202  iEvent.put(candForward, "RPCf");
203 
204 }
206 
213 std::vector<L1MuRegionalCand> RPCTrigger::giveFinallCandindates(L1RpcTBMuonsVec finalMuons, int type, int bx,
215  edm::Handle<RPCDigiCollection> rpcDigis, std::vector<RPCDigiL1Link> & retRPCDigiLink)
216 {
217 
218  std::vector<L1MuRegionalCand> RPCCand;
219 
220  for(unsigned int iMu = 0; iMu < finalMuons.size(); iMu++)
221  {
222 
223  if (finalMuons[iMu].getPtCode()==0){
224  continue;
225  }
226 
227  RPCDigiL1Link newDigiLink;
228 
229  //std::cout << "######################################## " << std::endl;
230  //std::cout << finalMuons[iMu].getPhiAddr() << " " << finalMuons[iMu].getEtaAddr() << std::endl;
231  RPCMuon::TDigiLinkVec digiIVec = finalMuons[iMu].getDigiIdxVec();
232  // Here the iteration has to be the same as in
233  short int digiIndex = 0;
235  for (detUnitIt=rpcDigis->begin();
236  detUnitIt!=rpcDigis->end();
237  ++detUnitIt)
238  {
239 
240  const RPCDetId& id = (*detUnitIt).first;
241  uint32_t rawId = id.rawId();
242  const RPCDigiCollection::Range& range = (*detUnitIt).second;
243 
244 
245  for (RPCDigiCollection::const_iterator digiIt = range.first;
246  digiIt!=range.second;
247  ++digiIt)
248  {
249  ++digiIndex;
250 
251  RPCMuon::TDigiLinkVec::iterator it = digiIVec.begin();
252  for(;it!=digiIVec.end();++it) {
253  if (digiIndex==it->m_digiIdx) {
254  newDigiLink.setLink(it->m_layer+1, rawId, digiIt->strip(), digiIt->bx() );
255  //std::cout << type << " " << iMu << " layer: " << it->m_layer << " index " << it->m_digiIdx << std::endl;
256  //std::cout << " " << id << " " << " |bx " << digiIt->bx() << " strip " << digiIt->strip() << std::endl;
257  }
258  }
259  }
260  }
261  retRPCDigiLink.push_back(newDigiLink);
262 
263 
264  L1MuRegionalCand l1Cand;
265 
266  l1Cand.setBx(bx);
267 
268 
269  l1Cand.setQualityPacked(finalMuons[iMu].getQuality());
270  l1Cand.setPtPacked(finalMuons[iMu].getPtCode());
271 
272  l1Cand.setType(type);
273 
274  int charge=finalMuons[iMu].getSign();
275 
276  if (charge == 0) // negative
277  l1Cand.setChargePacked(1);
278  else
279  l1Cand.setChargePacked(0);
280 
281  //RPCConst::l1RpcConeCrdnts cone = finalMuons[iMu].getConeCrdnts();
282 
283  /*
284  int pac = cone.m_LogSector*12+cone.m_LogSegment;
285  const float pi = 3.14159265;
286  const float offset = 5*(2*pi/360); // redefinition! Defined also in RPCRingFromRolls::phiMapCompare
287  float phi = 2*pi*pac/144-offset;
288  if (phi<0)
289  phi+=2*pi;
290 
291  l1Cand.setPhiValue(phi);
292  */
293 
294  //Note: pac numbering begins at 5 deg and goes from 1 to 144.
295  // we want phi values from 0 to 2.5 deg to be phiPacked=0
296  // max phiPacked value is 143 (see CMS IN 2004-022)
297  //int phiPacked = (finalMuons[iMu].getPhiAddr()+2)%144;
298  int phiPacked = finalMuons[iMu].getPhiAddr();
299  l1Cand.setPhiPacked(phiPacked);
300 /*
301  float eta = RPCConst::etaFromTowerNum(cone.m_Tower);
302  l1Cand.setEtaValue(eta);
303 */
304  //Note: etaAddr is packed in special way: see CMS IN 2004-022
305  signed short etaAddr = finalMuons[iMu].getEtaAddr(); //
306 // signed short etaAddr = finalMuons[iMu].getEtaAddr()-16; // -16..16
307 // bool etaNegative = false;
308 // if (etaAddr < 0){
309 // etaNegative = true;
310 // etaAddr = ~(-etaAddr)+1; // convert to negative :)
311 // }
312 
313 // etaAddr &= 63; // 6 bits only
314 
315  l1Cand.setEtaPacked(etaAddr);
316  l1Cand.setChargeValid(true);
317 
318  /*
319  std::cout<< std::endl << "RBMuon::" << finalMuons[iMu].getEtaAddr() << " "
320  << finalMuons[iMu].getPhiAddr() << std::endl ;
321  std::cout<< "cand " << l1Cand.eta_packed() << " "
322  << l1Cand.phi_packed() << std::endl ;
323  */
324 
325  RPCCand.push_back(l1Cand);
326 
327  LogDebug("RPCTrigger") << "Found muonf of pt "
328  << finalMuons[iMu].getPtCode()
329  << " bx " << l1Cand.bx()
330  << " L1Charge " << l1Cand.charge_packed()
331  << " ql " << l1Cand.quality()
332  << " fp " << finalMuons[iMu].getFiredPlanes()
333  << " b/f " << l1Cand.type_idx()
334  << " phi " << l1Cand.phi_packed()
335  << " eta " << l1Cand.eta_packed()
336  //<< " eta l1 " << l1Cand.etaValue() // will drop out soon
337  << " killed " << finalMuons[iMu].wasKilled();
338 
339 
340  }
341 
342  return RPCCand;
343 }
344 
#define LogDebug(id)
RPCBasicTrigConfig * m_trigConfig
Definition: RPCTrigger.h:63
type
Definition: HCALResponse.h:22
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
unsigned long long cacheIdentifier() const
T getUntrackedParameter(std::string const &, T const &) const
bool m_firstRun
Definition: RPCTrigger.h:67
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)
int bunchCrossing() const
Definition: EventBase.h:62
virtual void produce(edm::Event &, const edm::EventSetup &)
Definition: RPCTrigger.cc:61
std::string m_label
Definition: RPCTrigger.h:74
double charge(const std::vector< uint8_t > &Ampls)
std::vector< L1MuRegionalCand > giveFinallCandindates(L1RpcTBMuonsVec finalMuons, int type, int bx, edm::Handle< RPCDigiCollection > rpcDigis, std::vector< RPCDigiL1Link > &retRPCDigiLink)
Returns vector of L1MuRegionalCand (input of L1GMT)
Definition: RPCTrigger.cc:214
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
static MuonsGrabber & Instance()
Definition: MuonsGrabber.cc:59
void setRPCBasicTrigConfig(RPCBasicTrigConfig *c)
Definition: MuonsGrabber.h:61
void setBx(int bx)
Set Bunch Crossing.
int iEvent
Definition: GenABIO.cc:243
std::vector< RPCTBMuon > L1RpcTBMuonsVec
Definition: RPCTBMuon.h:206
void startNewEvent(int event, int bx)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
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:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
tuple conf
Definition: dbtoconf.py:185
RPCConeBuilderFromES m_theLinksystemFromES
Definition: RPCTrigger.h:59
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.
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
std::vector< DigiType >::const_iterator const_iterator
unsigned int quality() const
return quality
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:59
void setDebugLevel(int debgLevel)
int bx() const
return bunch crossing identifier
edm::EventID id() const
Definition: EventBase.h:56
void setQualityPacked(unsigned qual)
Set Quality: 0..7.
void setEtaPacked(unsigned eta)
Set Eta: 6-bit code.
int m_triggerDebug
Definition: RPCTrigger.h:68
std::pair< const_iterator, const_iterator > Range
void setChargeValid(bool valid)
Set Charge Valid.
RPCPacTrigger * m_pacTrigger
Definition: RPCTrigger.h:65
L1RpcTBMuonsVec2 runEvent(const L1RpcLogConesVec &logConesVec, edm::ESHandle< L1RPCHsbConfig > hsbConf)
void writeDataForRelativeBX(int bx)
unsigned type_idx() const
return type: 0 DT, 1 bRPC, 2 CSC, 3 fRPC
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:69