CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1EmulBias.h
Go to the documentation of this file.
1 #ifndef L1_EMUL_BIAS_H
2 #define L1_EMUL_BIAS_H
3 
4 /*\class L1EmulBias
5  *\description produces modified emulator data to mimmic hw problems
6  *\usage l1 monitoring software validation
7  *\author Nuno Leonardo (CERN)
8  *\date 07.07
9  */
10 
11 // system includes
12 #include <memory>
13 #include <string>
14 #include <iostream>
15 #include <fstream>
16 #include <iomanip>
17 #include <vector>
18 #include <algorithm>
19 
20 // common includes
28 
29 // l1 dataformats, d|e record includes
31 
32 // random generation
34 #include "CLHEP/Random/RandFlat.h"
35 #include "CLHEP/Random/RandGaussQ.h"
36 
37 
38 class L1EmulBias : public edm::EDProducer {
39 
40  public:
41  explicit L1EmulBias(const edm::ParameterSet&);
42  ~L1EmulBias();
43 
44  protected:
45  virtual void beginJob(void) {};
46  //virtual void beginRun(edm::Run&, const edm::EventSetup&);
47  virtual void produce(edm::Event&, const edm::EventSetup&);
48  virtual void endJob(void) {};
49 
50  public:
51  template <class T>
52  void ModifyCollection ( std::auto_ptr<T>& data, const edm::Handle<T> emul);
53 
54  private:
55  int verbose_;
56  int verbose() {return verbose_;}
60  CLHEP::RandFlat *rndFlat_;
61  CLHEP::RandGaussQ *rndGaus_;
62 
63 };
64 
65 /* Notes:
66  .by default data is make identical to emul
67  .biasing is to be implemented via specialization
68  .bias may be defined for each data type, eg data word bit-shifting
69  .keep template function specialization in header file
70 */
71 
72 template <class T>
73 void L1EmulBias::ModifyCollection(std::auto_ptr<T>& data, const edm::Handle<T> emul) {
74  data = (std::auto_ptr<T>)(const_cast<T*>(emul.product()));
75 }
76 
77 template <> inline void
78 L1EmulBias::ModifyCollection(std::auto_ptr<EcalTrigPrimDigiCollection>& data,
81  for(col_cit it = emul->begin(); it!=emul->end(); it++) {
83  int iphi = it->id().iphi();
84  bool reset = (iphi>18 && iphi<39);//remove few supermodules
85  for(int s=0; s<5; s++) {
86  uint16_t sample = it->sample(s).raw();
87  if(sample==0) continue;
88  uint16_t tmp = reset?0:sample;
89  if(reset)
90  tmp = sample>>1;
91  col.setSampleValue(s,tmp);
92  if(verbose() && sample!=0)
93  std::cout << "[emulbias] etp " << *it << "\t sample: " << s << " "
94  << std::hex << sample << " -> " << col.sample(s).raw()
95  << std::dec << std::endl;
96  }
97  data->push_back(col);
98  }
99 }
100 
101 template <> inline void
102 L1EmulBias::ModifyCollection(std::auto_ptr<HcalTrigPrimDigiCollection>& data,
105  for(col_cit it = emul->begin(); it!=emul->end(); it++) {
107  int iphi = it->id().iphi();
108  bool reset = (iphi>18 && iphi<27);//remove few supermodules
109  for(int s=0; s<5; s++) {
110  uint16_t sample = it->sample(s).raw();
111  if(sample==0) continue;
112  uint16_t tmp = reset?0:sample;
113  if(reset)
114  tmp = sample>>1;
115  col.setSample(s,tmp);
116  }
117  data->push_back(col);
118  }
119 }
120 
121 template <> inline void
122 L1EmulBias::ModifyCollection(std::auto_ptr<L1CaloEmCollection>& data,
123  const edm::Handle<L1CaloEmCollection> emul) {
124  typedef L1CaloEmCollection::const_iterator col_cit;
125  for(col_cit it = emul->begin(); it!=emul->end(); it++) {
126  unsigned crate = it->rctCrate();
127  unsigned raw = it->raw();
128  bool iso = it->isolated();
129  unsigned rdata = raw;
130  if(crate<4*rndFlat_->fire())
131  rdata = raw>>1;
132  L1CaloEmCand cand(rdata,crate,iso,it->index(),it->bx(),false);
133  data->push_back(cand);
134  }
135  //L1CaloEmCand(uint16_t data, unsigned crate, bool iso);
136  //L1CaloEmCand(uint16_t data, unsigned crate, bool iso, uint16_t index, int16_t bx, bool dummy);
137 }
138 
139 
140 template <> inline void
141 L1EmulBias::ModifyCollection(std::auto_ptr<L1CaloRegionCollection>& data,
143  typedef L1CaloRegionCollection::const_iterator col_cit;
144  for(col_cit it = emul->begin(); it!=emul->end(); it++) {
145  unsigned crate = it->rctCrate();
146  unsigned raw = it->et();
147  uint16_t rdata = raw;
148  if(crate<4*rndFlat_->fire())
149  rdata = raw>>1;
150  L1CaloRegion cand(rdata,it->gctEta(),it->gctPhi(),it->bx());
151  data->push_back(cand);
152  }
153  //L1CaloRegion(uint16_t data, unsigned ieta, unsigned iphi, int16_t bx);
154  //Note: raw data accessor missing in dataformats!
155 }
156 
157 template <> inline void
158 L1EmulBias::ModifyCollection(std::auto_ptr<L1GctEmCandCollection>& data,
160  typedef L1GctEmCandCollection::const_iterator col_cit;
161  for(col_cit it = emul->begin(); it!=emul->end(); it++) {
162  unsigned raw = it->raw();
163  uint16_t rdata = raw;
164  if(it->phiIndex()<4*rndFlat_->fire()) //0-17
165  rdata = raw>>1;
166  L1GctEmCand cand(rdata,it->isolated());
167  data->push_back(cand);
168  }
169  //etaIndex(), etaSign() : -6 to -0, +0 to +6
170  //L1GctEmCand(uint16_t data, bool iso);
171 }
172 
173 template <> inline void
174 L1EmulBias::ModifyCollection(std::auto_ptr<L1GctJetCandCollection>& data,
176  typedef L1GctJetCandCollection::const_iterator col_cit;
177  for(col_cit it = emul->begin(); it!=emul->end(); it++) {
178  unsigned raw = it->raw();
179  uint16_t rdata = raw;
180  if(it->phiIndex()<4*rndFlat_->fire()) //0-17
181  rdata = raw>>1;
182  L1GctJetCand cand(rdata,it->isTau(),it->isForward());
183  data->push_back(cand);
184  }
185  //L1GctJetCand(uint16_t data, bool isTau, bool isFor);
186 }
187 
188 template <> inline void
189 L1EmulBias::ModifyCollection ( std::auto_ptr<L1MuRegionalCandCollection>& data,
191  typedef L1MuRegionalCandCollection::const_iterator col_cit;
192  for(col_cit it = emul->begin(); it!=emul->end(); it++) {
193  L1MuRegionalCand cand(*it);
194  //unsigned raw = it->getDataWord();
195  unsigned phi = it->phi_packed();
196  if(phi>90 && phi<110)
197  cand.setPtPacked( (it->pt_packed())>>1 );
198  //raw = (raw>>2);
199  //L1MuRegionalCand cand(raw);
200  //cand.setType(it->type_idx());
201  data->push_back(cand);
202  }
203  /* few alternatives...
204  unsigned pt= it->pt_packed(); //0..31
205  unsigned int qua = it->quality(); //0..7
206  if(qua<4){cand.setPtPacked((pt>>2)&0x1f);cand.setQualityPacked((qua<<1)&0x07);}
207  double rnd = rndGaus_->fire();
208  if(rnd>0.7) {
209  raw_=(raw>>1);
210  cand.setDataWord(raw_);
211  } else if (rnd>0.3) {
212  pt_ *= (int)(1+0.3*rndFlat_->fire());
213  cand.setPtPacked(pt_);
214  } else
215  cand.reset();
216  unsigned raw = it->getDataWord();
217  if(2.5<fabs(it->phiValue())<3.0)
218  rdata = raw>>1;
219  L1MuRegionalCand cand(rdata,it->bx());
220  */
221  //L1MuRegionalCand(unsigned dataword = 0, int bx = 0);
222  //L1MuRegionalCand(unsigned type_idx, unsigned phi, unsigned eta, unsigned pt, unsigned charge, unsigned ch_valid, unsigned finehalo, unsigned quality, int bx);
223 }
224 
225 template <> inline void
226 L1EmulBias::ModifyCollection(std::auto_ptr<L1MuDTTrackContainer>& data,
228  typedef std::vector<L1MuDTTrackCand> TrackContainer;
229  typedef TrackContainer::const_iterator col_cit;
230  TrackContainer const* tracks_in = emul->getContainer();
231  TrackContainer tracks;
232  for(col_cit it = tracks_in->begin(); it!=tracks_in->end(); it++) {
233  L1MuDTTrackCand cand(*it);
234  cand.setType(it->type_idx());
235  unsigned pt = it->pt_packed(); //0..31
236  unsigned qua = it->quality(); //0..7
237  if(qua<4) {
238  cand.setPtPacked((pt>>2)&0x1f);
239  cand.setQualityPacked((qua<<1)&0x07);
240  }
241  tracks.push_back(cand);
242  }
243  data->setContainer(tracks);
244  /* few alternatives...
245  unsigned phip = it->phi_packed();
246  unsigned raw = it->getDataWord();
247  uint16_t rdata = raw;
248  if(2.5<fabs(it->phiValue())<3.0)
249  rdata = raw>>1;
250  L1MuRegionalCand cand(rdata,it->bx());
251  double rnd = rndFlat_->fire();
252  */
253 }
254 
255 template <> inline void
256 L1EmulBias::ModifyCollection(std::auto_ptr<L1MuDTChambPhContainer>& data,
258  typedef std::vector<L1MuDTChambPhDigi> Phi_Container;
259  typedef Phi_Container::const_iterator col_it;
260  Phi_Container const* tracks_in = emul->getContainer();
261  Phi_Container tracks(tracks_in->size());
262  int uqua;
263  for(col_it it=tracks_in->begin(); it!=tracks_in->end(); it++) {
264  uqua = it->code(); // (int)(10*rndFlat_->fire());
265  uqua = (uqua<2?uqua+1:uqua);
267  cand(it->bxNum(),it->whNum(),it->scNum(),it->stNum(),
268  it->phi(),it->phiB(),uqua,it->Ts2Tag(),it->BxCnt() );
269  tracks.push_back(cand);
270  }
271  data->setContainer(tracks);
272 }
273 
274 template <> inline void
275 L1EmulBias::ModifyCollection(std::auto_ptr<L1MuDTChambThContainer>& data,
277  typedef std::vector<L1MuDTChambThDigi> Thi_Container;
278  typedef Thi_Container::const_iterator col_cit;
279  Thi_Container const* tracks_in = emul->getContainer();
280  Thi_Container tracks(tracks_in->size());
281  int uos[7],uqa[7];
282  for(col_cit it=tracks_in->begin(); it!=tracks_in->end(); it++) {
283  for(int j=0; j<7; j++) {
284  uos[j]=(it->position(j)?0:1);
285  uqa[j]=(it->quality (j)?0:1);
286  }
287  int stnum = it->stNum();
288  stnum = (stnum>2?stnum-1:stnum);
290  cand(it->bxNum(),it->whNum(),it->scNum(),stnum,uos,uqa);
291  tracks.push_back(cand);
292  }
293  data->setContainer(tracks);
294 }
295 
296 template <> inline void
297 L1EmulBias::ModifyCollection(std::auto_ptr<LTCDigiCollection>& data,
298  const edm::Handle<LTCDigiCollection> emul) {
299  typedef std::vector<LTCDigi>::const_iterator col_cit;
300  for(col_cit it=emul->begin(); it!=emul->end(); it++) {
301  data->push_back(*it);
302  //note: raw data accessor missing in dataformats!
303  //data->push_back(LTCDigi(it->data()>>1));
304  }
305 }
306 
307 template <> inline void
308 L1EmulBias::ModifyCollection(std::auto_ptr<L1MuGMTCandCollection>& data,
310  //typedef std::vector<L1MuGMTCand> L1MuGMTCandCollection;
311  typedef std::vector<L1MuGMTCand>::const_iterator col_cit;
312  for(col_cit it=emul->begin(); it!=emul->end(); it++) {
313  float phiv = it->phiValue();
314  unsigned dword = it->getDataWord();
315  if(phiv>2. && phiv<4.)
316  dword = dword>>2;
317  L1MuGMTCand cand(dword,it->bx());
318  data->push_back(cand);
319  //cand.setPtPacked(cand.ptIndex()>>1);
320  //data->push_back(L1MuGMTCand((it->getDataWord()>>1),it->bx()));
321  }
322 }
323 
324 template <> inline void
325 L1EmulBias::ModifyCollection(std::auto_ptr<L1MuGMTReadoutCollection>& data,
327  typedef std::vector<L1MuGMTReadoutRecord>::const_iterator col_cit;
328  std::vector<L1MuGMTReadoutRecord> col = emul->getRecords();
329  for(col_cit it = col.begin(); it!=col.end(); it++) {
330  L1MuGMTReadoutRecord rec(it->getBxInEvent());
331  rec.setBxNr (it->getBxNr ());
332  rec.setEvNr (it->getEvNr ());
333  rec.setBCERR(it->getBCERR());
334 
335  std::auto_ptr<L1MuRegionalCandCollection> new_dttf(new L1MuRegionalCandCollection);
336  std::auto_ptr<L1MuRegionalCandCollection> new_rpcb(new L1MuRegionalCandCollection);
337  std::auto_ptr<L1MuRegionalCandCollection> new_csc (new L1MuRegionalCandCollection);
338  std::auto_ptr<L1MuRegionalCandCollection> new_rpcf(new L1MuRegionalCandCollection);
339 
340  L1MuRegionalCandCollection old_dttf = it->getDTBXCands();
341  L1MuRegionalCandCollection old_rpcb = it->getBrlRPCCands();
342  L1MuRegionalCandCollection old_csc = it->getCSCCands();
343  L1MuRegionalCandCollection old_rpcf = it->getFwdRPCCands();
344 
345  typedef L1MuRegionalCandCollection::const_iterator ait;
346  for(ait it = old_dttf.begin(); it!=old_dttf.end(); it++) {
347  L1MuRegionalCand cand(*it);
348  if(it->quality()<4)
349  cand.setPtPacked((it->pt_packed()>>2)&0x1f);
350  cand.setType(it->type_idx());
351  new_dttf->push_back(cand);
352  }
353  for(ait it = old_rpcb.begin(); it!=old_rpcb.end(); it++) {
354  L1MuRegionalCand cand(*it);
355  if(it->quality()<4)
356  cand.setPtPacked((it->pt_packed()>>2)&0x1f);
357  cand.setType(it->type_idx());
358  new_rpcb->push_back(cand);
359  }
360  for(ait it = old_csc.begin(); it!=old_csc.end(); it++) {
361  L1MuRegionalCand cand(*it);
362  if(it->quality()<4)
363  cand.setPtPacked((it->pt_packed()>>2)&0x1f);
364  cand.setType(it->type_idx());
365  new_csc->push_back(cand);
366  }
367  for(ait it = old_rpcf.begin(); it!=old_rpcf.end(); it++) {
368  L1MuRegionalCand cand(*it);
369  if(it->quality()<4)
370  cand.setPtPacked((it->pt_packed()>>2)&0x1f);
371  cand.setType(it->type_idx());
372  new_rpcf->push_back(cand);
373  }
374 
375  for(unsigned i=0; i<old_dttf.size(); i++)
376  rec.setInputCand(i ,new_dttf->at(i));//dt : 0..3
377  for(unsigned i=0; i<old_rpcb.size(); i++)
378  rec.setInputCand(i+ 4,new_rpcb->at(i));//rpcb: 4..7
379  for(unsigned i=0; i<old_csc .size(); i++)
380  rec.setInputCand(i+ 8,new_csc ->at(i));//csc : 8..11
381  for(unsigned i=0; i<old_rpcf.size(); i++)
382  rec.setInputCand(i+12,new_rpcf->at(i));//rpcf:12..15
383 
384  data->addRecord(rec);
385  }
386  //void addRecord(L1MuGMTReadoutRecord const& rec) {
387 }
388 
389 template <> inline void
390 L1EmulBias::ModifyCollection(std::auto_ptr<CSCCorrelatedLCTDigiCollection>& data,
392  //typedef MuonDigiCollection<CSCDetId,CSCCorrelatedLCTDigi> CSCCorrelatedLCTDigiCollection;
393  typedef CSCCorrelatedLCTDigiCollection::DigiRangeIterator mapIt;//map iterator
394  typedef CSCCorrelatedLCTDigiCollection::const_iterator vecIt;//vec iterator
395  //loop over data (map<idx,vec_digi>)
396  for (mapIt mit = emul->begin(); mit != emul->end(); mit++) {
397  //get detector index
398  CSCDetId did = (*mit).first;
399  //get vec_digi range(pair) corresponding to idx of map
400  //CSCCorrelatedLCTDigiCollection::Range ctpRange = emul->get(did)
401  //loop over digi vector (ie between begin and end pointers in range)
402  //for (vecIt vit = ctpRange.first; vit != ctpRange.second; vit++) {
403  for (vecIt vit = emul->get((*mit).first).first;
404  vit != emul->get((*mit).first).second; vit++) {
406  CSCCorrelatedLCTDigi dg = *vit;
407  //dg.clear;
408  uint16_t tn = dg.getTrknmb();
409  if(tn==2) tn--;
410  dg.setTrknmb(tn);
411  //dg.setTrknmb (dg.getTrknmb ());
412  //dg.setMPCLink (dg.getMPCLink ());
413  //dg.setWireGroup(dg.getWireGroup());
415  data->insertDigi(did,dg);
416  }
417  }
418 }
419 
420 template <> inline void L1EmulBias::ModifyCollection(std::auto_ptr<L1CSCTrackCollection>& data,
422  typedef L1CSCTrackCollection::const_iterator col_cit;
423  //typedef std::vector<L1CSCTrack> L1CSCTrackCollection;
424  //typedef std::pair<csc::L1Track,CSCCorrelatedLCTDigiCollection> L1CSCTrack;
425  //typedef MuonDigiCollection<CSCDetId,CSCCorrelatedLCTDigi> CSCCorrelatedLCTDigiCollection;
426  typedef CSCCorrelatedLCTDigiCollection::DigiRangeIterator mapIt;//map iterator
427  typedef CSCCorrelatedLCTDigiCollection::const_iterator vecIt;//vec iterator
428  CSCCorrelatedLCTDigiCollection_ ctf_trk_data_v, ctf_trk_emul_v; //vector
429  //loop over csc-tracks (ie pairs<l1track,digi_vec>)
430  for(col_cit tcit=emul->begin(); tcit!=emul->end(); tcit++) {
431  csc::L1Track l1trk = tcit->first;
432  if(l1trk.quality()<4)
433  l1trk.setPtPacked((l1trk.pt_packed()>>2)&0x1f);
434  l1trk.setType(l1trk.type_idx());
435  //L1MuRegionalCand reg(tcit->first.getDataWord(), tcit->first.bx());
436  std::auto_ptr<CSCCorrelatedLCTDigiCollection> dgcoll(new CSCCorrelatedLCTDigiCollection);
437  CSCCorrelatedLCTDigiCollection ldc = tcit->second; //muondigicollection=map
438  //get the lct-digi-collection (ie muon-digi-collection)
439  //loop over data (map<idx,vec_digi>)
440  for (mapIt mit = ldc.begin(); mit != ldc.end(); mit++) {
441  //get vec_digi range(pair) corresponding to idx of map
442  //loop over digi vector (ie between begin and end pointers in range)
443  //CSCCorrelatedLCTDigiCollection::Range ctpRange = ctp_lct_data_->get((*mit).first)
444  CSCDetId did = (*mit).first;
445  //for (vecIt vit = ctpRange.first; vit != ctpRange.second; vit++) {
446  for (vecIt vit = ldc.get((*mit).first).first;
447  vit != ldc.get((*mit).first).second; vit++) {
448  CSCCorrelatedLCTDigi dg = *vit;
449  uint16_t tn = dg.getTrknmb();
450  if(tn==2) tn--;
451  dg.setTrknmb(tn);
452  dgcoll->insertDigi(did,dg);
453  }
454  }
455  L1CSCTrack l1csctrk = std::make_pair(l1trk,*dgcoll);
456  data->push_back(l1csctrk);
457  }
458 }
459 
460 #endif
int i
Definition: DBlmapReader.cc:9
void setSample(int i, const HcalTriggerPrimitiveSample &sam)
const int DEnsys
Definition: DEtrait.h:38
bool m_doSys[dedefs::DEnsys]
Definition: L1EmulBias.h:58
std::vector< EcalTriggerPrimitiveDigi >::const_iterator const_iterator
Level-1 Trigger jet candidate.
Definition: L1GctJetCand.h:18
void ModifyCollection(std::auto_ptr< T > &data, const edm::Handle< T > emul)
Definition: L1EmulBias.h:73
Level-1 Region Calorimeter Trigger EM candidate.
Definition: L1CaloEmCand.h:18
CLHEP::RandFlat * rndFlat_
Definition: L1EmulBias.h:60
L1EmulBias(const edm::ParameterSet &)
Definition: L1EmulBias.cc:5
Level-1 Trigger EM candidate at output of GCT.
Definition: L1GctEmCand.h:22
uint16_t raw() const
get the raw word
int verbose()
Definition: L1EmulBias.h:56
CLHEP::RandGaussQ * rndGaus_
Definition: L1EmulBias.h:61
std::vector< TrackWithHistory * > TrackContainer
Definition: TrackContainer.h:8
virtual void produce(edm::Event &, const edm::EventSetup &)
Definition: L1EmulBias.cc:110
int j
Definition: DBlmapReader.cc:9
virtual void endJob(void)
Definition: L1EmulBias.h:48
const EcalTriggerPrimitiveSample & sample(int i) const
void setType(unsigned type)
Set Type: 0 DT, 1 bRPC, 2 CSC, 3 fRPC.
int getTrknmb() const
return track number
edm::InputTag m_DEsource[dedefs::DEnsys][2]
Definition: L1EmulBias.h:57
std::vector< L1MuRegionalCand > L1MuRegionalCandCollection
std::string instName[dedefs::DEnsys][5]
Definition: L1EmulBias.h:59
void setPtPacked(unsigned pt)
Set Pt: 0..31.
std::vector< CSCCorrelatedLCTDigi > CSCCorrelatedLCTDigiCollection_
Definition: DEtrait.h:75
tuple tracks
Definition: testEve_cfg.py:39
int verbose_
Definition: L1EmulBias.h:55
void setSampleValue(int i, uint16_t value)
std::vector< CSCCorrelatedLCTDigi >::const_iterator const_iterator
unsigned int quality() const
return quality
void setBxNr(int bxnr)
set counters
T const * product() const
Definition: Handle.h:81
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
void setQualityPacked(unsigned qual)
Set Quality: 0..7.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
virtual void beginJob(void)
Definition: L1EmulBias.h:45
std::pair< csc::L1Track, CSCCorrelatedLCTDigiCollection > L1CSCTrack
A calorimeter trigger region (sum of 4x4 trigger towers)
Definition: L1CaloRegion.h:22
tuple cout
Definition: gather_cfg.py:121
unsigned pt_packed() const
return pt packed as in hardware
int col
Definition: cuy.py:1008
void setTrknmb(const uint16_t number)
Set track number (1,2) after sorting LCTs.
void reset(double vett[256])
Definition: TPedValues.cc:11
unsigned type_idx() const
return type: 0 DT, 1 bRPC, 2 CSC, 3 fRPC
Definition: DDAxes.h:10