00001 #ifndef L1_DUMMY_PRODUCER_H
00002 #define L1_DUMMY_PRODUCER_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <memory>
00013 #include <string>
00014 #include <iostream>
00015 #include <fstream>
00016 #include <iomanip>
00017 #include <vector>
00018 #include <algorithm>
00019 #include "TMath.h"
00020 #include <bitset>
00021
00022
00023 #include "FWCore/ServiceRegistry/interface/Service.h"
00024 #include "FWCore/Framework/interface/Frameworkfwd.h"
00025 #include "FWCore/Framework/interface/EDProducer.h"
00026 #include "FWCore/Framework/interface/Event.h"
00027 #include "FWCore/Framework/interface/MakerMacros.h"
00028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00029 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00030
00031
00032 #include "L1Trigger/HardwareValidation/interface/DEtrait.h"
00033
00034
00035 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00036 #include "CLHEP/Random/RandFlat.h"
00037 #include "CLHEP/Random/RandGaussQ.h"
00038
00039
00040 class L1DummyProducer : public edm::EDProducer {
00041
00042 public:
00043
00044 explicit L1DummyProducer(const edm::ParameterSet&);
00045 ~L1DummyProducer();
00046
00047 private:
00048
00049 virtual void beginJob(void) {};
00050
00051 virtual void produce(edm::Event&, const edm::EventSetup&);
00052 virtual void endJob() {};
00053
00054 public:
00055
00056 template <class T>
00057 void SimpleDigi(std::auto_ptr<T>& data, int type=0);
00058
00059 private:
00060
00061 int verbose_;
00062 int verbose() {return verbose_;}
00063 int nevt_;
00064
00065 bool m_doSys[dedefs::DEnsys];
00066 std::string instName[dedefs::DEnsys][5];
00067
00068 CLHEP::RandFlat *rndFlat_;
00069 CLHEP::RandGaussQ *rndGaus_;
00070 double EBase_;
00071 double ESigm_;
00072
00073 };
00074
00075
00076 template <class T> void
00077 L1DummyProducer::SimpleDigi(std::auto_ptr<T>& data, int type) {
00078
00079 }
00080
00081 template <> inline void
00082 L1DummyProducer::SimpleDigi(std::auto_ptr<EcalTrigPrimDigiCollection>& data,
00083 int type) {
00084 if(verbose())
00085 std::cout << "L1DummyProducer::SimpleDigi<EcalTrigPrimDigiCollection>....\n" << std::flush;
00086 int side = (rndFlat_->fire()>0.5)?-1:1;
00087 int ieta = (int) (1 + 17*rndFlat_->fire());
00088 int iphi = (int) (1 + 72*rndFlat_->fire());
00089 const EcalTrigTowerDetId e_id( side , EcalBarrel, ieta, iphi, 0);
00090 EcalTriggerPrimitiveDigi e_digi(e_id);
00091 int energy = (int) (EBase_ + ESigm_*rndGaus_->fire());
00092 bool fg = (rndFlat_->fire()>0.5);
00093 int ttf = (int)(8*rndFlat_->fire());
00094 EcalTriggerPrimitiveSample e_sample(energy, fg, ttf);
00095 e_digi.setSize(1);
00096 e_digi.setSample(0,e_sample);
00097 data->push_back(e_digi);
00098
00099
00100 if(verbose())
00101 std::cout << "L1DummyProducer::SimpleDigi<EcalTrigPrimDigiCollection> end.\n" << std::flush;
00102 }
00103
00104 template <> inline void
00105 L1DummyProducer::SimpleDigi(std::auto_ptr<HcalTrigPrimDigiCollection>& data,
00106 int type) {
00107 if(verbose())
00108 std::cout << "L1DummyProducer::SimpleDigi<HcalTrigPrimDigiCollection>....\n" << std::flush;
00109 int side = (rndFlat_->fire()>0.5)?-1:1;
00110 int ieta = (int) (1 + 17*rndFlat_->fire());
00111 int iphi = (int) (1 + 72*rndFlat_->fire());
00112 const HcalTrigTowerDetId h_id(side*ieta, iphi);
00113 HcalTriggerPrimitiveDigi h_digi(h_id);
00114 int energy = (int) (EBase_ + ESigm_*rndGaus_->fire());
00115 HcalTriggerPrimitiveSample h_sample(energy, 0, 0, 0);
00116 h_digi.setSize(1);
00117 h_digi.setSample(0,h_sample);
00118 data->push_back(h_digi);
00119
00120
00121 if(verbose())
00122 std::cout << "L1DummyProducer::SimpleDigi<HcalTrigPrimDigiCollection> end.\n" << std::flush;
00123 }
00124
00125 template <> inline void
00126 L1DummyProducer::SimpleDigi(std::auto_ptr<L1CaloEmCollection>& data,
00127 int type) {
00128 if(verbose())
00129 std::cout << "L1DummyProducer::SimpleDigi<L1CaloEmCollection>....\n" << std::flush;
00130 int energy= (int) (EBase_ + ESigm_*rndGaus_->fire());
00131 unsigned rank = energy & 0x3f;
00132 unsigned region= (rndFlat_->fire()>0.5?0:1);
00133 unsigned card = (unsigned)(7*rndFlat_->fire());
00134 unsigned crate = (unsigned)(18*rndFlat_->fire());
00135 bool iso = (rndFlat_->fire()>0.4);
00136 uint16_t index = (unsigned)(4*rndFlat_->fire());
00137 int16_t bx = nevt_;
00138 L1CaloEmCand cand(rank, region, card, crate, iso, index, bx);
00139 data->push_back(cand);
00140
00141 if(verbose())
00142 std::cout << "L1DummyProducer::SimpleDigi<L1CaloEmCollection> end.\n" << std::flush;
00143 }
00144
00145 template <> inline void
00146 L1DummyProducer::SimpleDigi(std::auto_ptr<L1CaloRegionCollection>& data,
00147 int type) {
00148 if(verbose())
00149 std::cout << "L1DummyProducer::SimpleDigi<L1CaloRegionCollection>....\n" << std::flush;
00150 int energy= (int) (EBase_ + ESigm_*rndGaus_->fire());
00151 unsigned et = energy & 0x3ff;
00152 bool overFlow = 0;
00153 bool tauVeto = 0;
00154 bool mip = 0;
00155 bool quiet = 0;
00156 unsigned crate= (unsigned)(18*rndFlat_->fire());
00157 unsigned card = (unsigned)(7*rndFlat_->fire());
00158 unsigned rgn = crate%2;
00159 L1CaloRegion cand( et, overFlow, tauVeto, mip, quiet, crate, card, rgn );
00160 data->push_back(cand);
00161
00162 if(verbose())
00163 std::cout << "L1DummyProducer::SimpleDigi<L1CaloRegionCollection> end.\n" << std::flush;
00164 }
00165
00166 template <> inline void
00167 L1DummyProducer::SimpleDigi(std::auto_ptr<L1GctEmCandCollection>& data,
00168 int type) {
00169 if(verbose())
00170 std::cout << "L1DummyProducer::SimpleDigi<L1GctEmCandCollection>....\n" << std::flush;
00171 bool iso;
00172 switch(type) {
00173 case 0:
00174 iso = true;
00175 break;
00176 case 1:
00177 iso = false;
00178 break;
00179 default:
00180 throw cms::Exception("L1DummyProducerInvalidType")
00181 << "L1DummyProducer::SimpleDigi production of L1GctEmCandCollection "
00182 << " invalid type: " << type << std::endl;
00183 }
00184 int energy= (int) (EBase_ + ESigm_*rndGaus_->fire());
00185 unsigned rank = energy & 0x3f;
00186 unsigned phi = (unsigned)(18*rndFlat_->fire());
00187 unsigned eta = (unsigned)( 7*rndFlat_->fire());
00188 if(rndFlat_->fire()>0.5)
00189 eta = (eta&0x7) + (0x1<<3);
00190 L1GctEmCand cand(rank, phi, eta, iso);
00191 data->push_back(cand);
00192
00193
00194 if(verbose())
00195 std::cout << "L1DummyProducer::SimpleDigi<L1GctEmCandCollection> end.\n" << std::flush;
00196 }
00197
00198 template <> inline void
00199 L1DummyProducer::SimpleDigi(std::auto_ptr<L1GctJetCandCollection>& data,
00200 int type) {
00201 if(verbose())
00202 std::cout << "L1DummyProducer::SimpleDigi<L1GctJetCandCollection>....\n" << std::flush;
00203 bool isFor, isTau;
00204 switch(type) {
00205 case 0:
00206 isFor = false;
00207 isTau = false;
00208 break;
00209 case 1:
00210 isFor = true;
00211 isTau = false;
00212 break;
00213 case 2:
00214 isFor = false;
00215 isTau = true;
00216 break;
00217 default:
00218 throw cms::Exception("L1DummyProducerInvalidType")
00219 << "L1DummyProducer::SimpleDigi production of L1GctJetCandCollection "
00220 << " invalid type: " << type << std::endl;
00221 }
00222
00223 int energy= (int) (EBase_ + ESigm_*rndGaus_->fire());
00224 unsigned rank = energy & 0x3f;
00225 unsigned phi = (unsigned)(18*rndFlat_->fire());
00226 unsigned eta = (unsigned)( 7*rndFlat_->fire());
00227 if(rndFlat_->fire()>0.5)
00228 eta = (eta&0x7) + (0x1<<3);
00229 L1GctJetCand cand(rank, phi, eta, isTau, isFor);
00230 data->push_back(cand);
00231
00232 if(verbose())
00233 std::cout << "L1DummyProducer::SimpleDigi<L1GctJetCandCollection> end.\n" << std::flush;
00234 }
00235
00236 template <> inline void
00237 L1DummyProducer::SimpleDigi ( std::auto_ptr<L1MuRegionalCandCollection>& data,
00238 int type) {
00239 if(verbose())
00240 std::cout << "L1DummyProducer::SimpleDigi<L1MuRegionalCandCollection>....\n" << std::flush;
00241
00242 assert(type>=0 && type<4);
00243 unsigned type_idx=type;
00244 int bx = 0;
00245 unsigned phi, eta, pt, charge, ch_valid, finehalo, quality;
00246 float phiv(0.), etav(0.), ptv(0.);
00247 for(int i=0; i<4; i++) {
00248 phi = (int)(144*rndFlat_->fire());
00249 eta = (int)( 63*rndFlat_->fire());
00250 phiv = phi*2*TMath::Pi()/144.;
00251 etav = 2.5*(-1+2*eta/63.);
00252 pt = ((int)(32*rndFlat_->fire())) & 0x1f;
00253 ptv = 100*(pt/31.);
00254 charge = (rndFlat_->fire()>0.5?0:1);;
00255 ch_valid=0;
00256 finehalo=0;
00257 quality = (int)(8*rndFlat_->fire());
00258 L1MuRegionalCand cand(type_idx, phi, eta, pt, charge,
00259 ch_valid, finehalo, quality, bx);
00260 cand.setPhiValue(phiv);
00261 cand.setEtaValue(etav);
00262 cand.setPtValue (ptv);
00263 data->push_back(cand);
00264 }
00265
00266
00267 if(verbose())
00268 std::cout << "L1DummyProducer::SimpleDigi<L1MuRegionalCandCollection> end.\n" << std::flush;
00269 }
00270
00271 template <> inline void
00272 L1DummyProducer::SimpleDigi(std::auto_ptr<L1MuDTTrackContainer> & data,
00273 int type) {
00274 assert(type==0);
00275 int type_idx = type;
00276 if(verbose())
00277 std::cout << "L1DummyProducer::SimpleDigi<L1MuDTTrackContainer>....\n" << std::flush;
00278 std::auto_ptr<L1MuRegionalCandCollection> tracks(new L1MuRegionalCandCollection());
00279 SimpleDigi(tracks, type_idx);
00280 typedef std::vector<L1MuDTTrackCand> L1MuDTTrackCandCollection;
00281 std::auto_ptr<L1MuDTTrackCandCollection> tracksd (new L1MuDTTrackCandCollection());
00282 for(L1MuRegionalCandCollection::const_iterator it=tracks->begin(); it!=tracks->end(); it++) {
00283 L1MuDTTrackCand * cnd = new L1MuDTTrackCand();
00284 cnd->setDataWord(it->getDataWord());
00285 cnd->setBx(it->bx());
00286 tracksd->push_back(L1MuDTTrackCand());
00287 tracksd->push_back(*cnd);
00288 }
00289 data->setContainer(*tracksd);
00290 if(verbose())
00291 std::cout << "L1DummyProducer::SimpleDigi<L1MuDTTrackContainer> end.\n" << std::flush;
00292
00293
00294
00295 }
00296
00297 template <> inline void
00298 L1DummyProducer::SimpleDigi(std::auto_ptr<L1MuDTChambPhContainer>& data,
00299 int type) {
00300 if(verbose())
00301 std::cout << "L1DummyProducer::SimpleDigi<L1MuDTChambPhContainer>....\n" << std::flush;
00302 typedef std::vector<L1MuDTChambPhDigi> Phi_Container;
00303 int ntrk = 4;
00304 Phi_Container tracks(ntrk);
00305 int ubx, uwh, usc, ust,uphr, uphb, uqua, utag, ucnt;
00306 for (int i=0; i<ntrk; i++) {
00307 ubx = 0;
00308 uwh = 0;
00309 usc = 0;
00310 ust = 0;
00311 uphr = 0;
00312 uphb = 0;
00313 uqua = 0;
00314 utag = 0;
00315 ucnt = 0;
00316 uwh = (int)(-2+5*rndFlat_->fire());
00317 usc = (int)( 12*rndFlat_->fire());
00318 ust = (int)(1.+4*rndFlat_->fire());
00319 uqua= (int)( 8*rndFlat_->fire());
00320 L1MuDTChambPhDigi cand(ubx, uwh, usc, ust, uphr, uphb, uqua, utag, ucnt);
00321 tracks.push_back(cand);
00322 }
00323 data->setContainer(tracks);
00324
00325
00326 if(verbose())
00327 std::cout << "L1DummyProducer::SimpleDigi<L1MuDTChambPhContainer> end.\n" << std::flush;
00328 }
00329
00330 template <> inline void
00331 L1DummyProducer::SimpleDigi(std::auto_ptr<L1MuDTChambThContainer>& data,
00332 int type) {
00333 if(verbose())
00334 std::cout << "L1DummyProducer::SimpleDigi<L1MuDTChambThContainer>....\n" << std::flush;
00335 typedef std::vector<L1MuDTChambThDigi> The_Container;
00336 int ntrk = 4;
00337 The_Container tracks(ntrk);
00338 int ubx, uwh, usc, ust, uos[7], uqa[7];
00339 for (int i=0; i<ntrk; i++) {
00340 ubx = 0;
00341 uwh = (int)(-2+5*rndFlat_->fire());
00342 usc = (int)( 12*rndFlat_->fire());
00343 ust = (int)(1.+4*rndFlat_->fire());
00344 for(int j=0; j<7; j++) {
00345 uos[j]=(rndFlat_->fire()>0.5?0:1);
00346 uqa[j]=(rndFlat_->fire()>0.5?0:1);
00347 }
00348 L1MuDTChambThDigi cand(ubx, uwh, usc, ust, uos, uqa);
00349 tracks.push_back(cand);
00350 }
00351 data->setContainer(tracks);
00352
00353
00354
00355 if(verbose())
00356 std::cout << "L1DummyProducer::SimpleDigi<L1MuDTChambThContainer> end.\n" << std::flush;
00357 }
00358
00359 template <> inline void
00360 L1DummyProducer::SimpleDigi(std::auto_ptr<L1MuGMTCandCollection>& data,
00361 int type) {
00362 if(verbose())
00363 std::cout << "L1DummyProducer::SimpleDigi<L1MuGMTCandCollection>....\n" << std::flush;
00364
00365 L1MuGMTCand cand(0,nevt_);
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375 double eng = EBase_+ESigm_*rndGaus_->fire();
00376 double phi = 2*TMath::Pi()*rndFlat_->fire();
00377 double eta = 2.5*(-1+2*rndFlat_->fire());
00378 cand.setPtValue (eng);
00379 cand.setPhiValue(phi);
00380 cand.setEtaValue(eta);
00381 unsigned engp = (unsigned)(EBase_ + ESigm_*rndGaus_->fire());
00382 unsigned phip = (unsigned)(255*rndFlat_->fire());
00383 unsigned etap = (unsigned)( 63*rndFlat_->fire());
00384 cand.setPtPacked (engp&0x1f);
00385 cand.setPhiPacked(phip&0x7f);
00386 cand.setEtaPacked(etap&0x3f);
00387 double r = rndFlat_->fire();
00388 cand.setIsolation(r>0.2);
00389 cand.setMIP(r>0.7);
00390 cand.setChargePacked(r>0.5?0:1);
00391 cand.setBx(0);
00392 data->push_back(cand);
00393 if(verbose())
00394 std::cout << "L1DummyProducer::SimpleDigi<L1MuGMTCandCollection> end.\n" << std::flush;
00395
00396 }
00397
00398 template <> inline void
00399 L1DummyProducer::SimpleDigi(std::auto_ptr<L1MuGMTReadoutCollection>& data,
00400 int type) {
00401 if(verbose())
00402 std::cout << "L1DummyProducer::SimpleDigi<L1MuGMTReadoutCollection>....\n" << std::flush;
00403 L1MuGMTReadoutRecord rec(0);
00404 int bxn = nevt_;
00405 rec.setBxNr(bxn);
00406 rec.setEvNr(bxn);
00407 rec.setBxInEvent(0);
00408 std::auto_ptr<L1MuRegionalCandCollection> trks_dttf(new L1MuRegionalCandCollection);
00409 std::auto_ptr<L1MuRegionalCandCollection> trks_rpcb(new L1MuRegionalCandCollection);
00410 std::auto_ptr<L1MuRegionalCandCollection> trks_csc (new L1MuRegionalCandCollection);
00411 std::auto_ptr<L1MuRegionalCandCollection> trks_rpcf(new L1MuRegionalCandCollection);
00412 SimpleDigi(trks_dttf,0);
00413 SimpleDigi(trks_rpcb,1);
00414 SimpleDigi(trks_csc ,2);
00415 SimpleDigi(trks_rpcf,3);
00416 for(int i=0; i<4; i++) {
00417 rec.setInputCand(i ,trks_dttf->at(i));
00418 rec.setInputCand(i+ 4,trks_rpcb->at(i));
00419 rec.setInputCand(i+ 8,trks_csc ->at(i));
00420 rec.setInputCand(i+12,trks_rpcf->at(i));
00421 }
00422 for(int nr=0; nr<4; nr++) {
00423 int eng = (int)(EBase_ + ESigm_*rndGaus_->fire());
00424 rec.setGMTBrlCand(nr, eng&0x11, eng&0x11);
00425 rec.setGMTFwdCand(nr, eng&0x11, eng&0x11);
00426 rec.setGMTCand (nr, eng&0x11);
00427 int eta = (int)(14*rndFlat_->fire());
00428 int phi = (int)(18*rndFlat_->fire());
00429 rec.setMIPbit (eta, phi);
00430 rec.setQuietbit(eta, phi);
00431 }
00432 data->addRecord(rec);
00434
00435
00436
00437
00438
00439
00440
00441
00442 if(verbose())
00443 std::cout << "L1DummyProducer::SimpleDigi<L1MuGMTReadoutCollection> end.\n" << std::flush;
00444 }
00445
00446 template <> inline void
00447 L1DummyProducer::SimpleDigi(std::auto_ptr<LTCDigiCollection> & data,
00448 int type) {
00449 if(verbose())
00450 std::cout << "L1DummyProducer::SimpleDigi<LTCDigiCollection>....\n" << std::flush;
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477 if(verbose())
00478 std::cout << "L1DummyProducer::SimpleDigi<LTCDigiCollection> end.\n" << std::flush;
00479 }
00480
00481 template <> inline void L1DummyProducer::SimpleDigi(std::auto_ptr<CSCCorrelatedLCTDigiCollection>& data,
00482 int type) {
00483 if(verbose())
00484 std::cout << "L1DummyProducer::SimpleDigi<CSCCorrelatedLCTDigiCollection>....\n" << std::flush;
00485
00486
00487 CSCCorrelatedLCTDigi dg = CSCCorrelatedLCTDigi();
00488
00489 dg.clear();
00490
00491 enum eMinNum{ MIN_ENDCAP=1, MIN_STATION=1, MIN_RING=1, MIN_CHAMBER= 1, MIN_LAYER=1 };
00492 enum eMaxNum{ MAX_ENDCAP=2, MAX_STATION=4, MAX_RING=4, MAX_CHAMBER=36, MAX_LAYER=6 };
00493 float rnd = rndFlat_->fire();
00494 int ec = (int)( MIN_ENDCAP + (MAX_ENDCAP -MIN_ENDCAP )*rnd +1);
00495 int st = (int)( MIN_STATION + (MAX_STATION-MIN_STATION)*rnd +1);
00496 int rg = (int)( MIN_RING + (MAX_RING -MIN_RING )*rnd +1);
00497 int ch = (int)( MIN_CHAMBER + (MAX_CHAMBER-MIN_CHAMBER)*rnd +1);
00498 int lr = (int)( MIN_LAYER + (MAX_LAYER -MIN_LAYER )*rnd +1);
00499 CSCDetId did = CSCDetId(ec,st,rg,ch,lr);
00500
00501
00502 data->insertDigi(did,dg);
00503 if(verbose())
00504 std::cout << "L1DummyProducer::SimpleDigi<CSCCorrelatedLCTDigiCollection> end.\n" << std::flush;
00505 }
00506
00507 template <> inline void L1DummyProducer::SimpleDigi(std::auto_ptr<L1CSCTrackCollection>& data,
00508 int type) {
00509 if(verbose())
00510 std::cout << "L1DummyProducer::SimpleDigi<L1CSCTrackCollection>...\n" << std::flush;
00511 std::auto_ptr<CSCCorrelatedLCTDigiCollection> dgcoll(new CSCCorrelatedLCTDigiCollection);
00512 SimpleDigi(dgcoll,0);
00513 csc::L1Track l1trk = csc::L1Track();
00514 std::auto_ptr<L1MuRegionalCandCollection> regcoll(new L1MuRegionalCandCollection);
00515 SimpleDigi(regcoll,2);
00516 L1MuRegionalCand regcand = *(regcoll->begin());
00517 l1trk.setDataWord(regcand.getDataWord());
00518 l1trk.setBx(regcand.bx());
00519 l1trk.setPhiValue(regcand.phiValue());
00520 l1trk.setEtaValue(regcand.etaValue());
00521 l1trk.setPtValue (regcand.ptValue());
00522 L1CSCTrack l1csctrk = std::make_pair(l1trk,*dgcoll);
00523 data->push_back(l1csctrk);
00524
00525
00526
00527
00528 if(verbose())
00529 std::cout << "L1DummyProducer::SimpleDigi<L1CSCTrackCollection> end.\n" << std::flush;
00530 }
00531
00532 #endif