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