00001
00002
00003 #include <FWCore/Framework/interface/Event.h>
00004 #include <FWCore/Framework/interface/EventSetup.h>
00005 #include <FWCore/Framework/interface/ESHandle.h>
00006
00007 #include "RecoEgamma/EgammaHLTProducers/interface/ESListOfFEDSProducer.h"
00008 #include "DataFormats/EcalRawData/interface/ESListOfFEDS.h"
00009 #include "DataFormats/EcalRawData/interface/EcalListOfFEDS.h"
00010
00011 #include "FWCore/Utilities/interface/Exception.h"
00012
00013
00014 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
00015 #include "Geometry/EcalMapping/interface/ESElectronicsMapper.h"
00016
00017 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
00018 #include <DataFormats/FEDRawData/interface/FEDNumbering.h>
00019
00020
00021
00022 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"
00023 #include "DataFormats/L1Trigger/interface/L1EmParticleFwd.h"
00024 #include "CondFormats/L1TObjects/interface/L1CaloGeometry.h"
00025 #include "CondFormats/DataRecord/interface/L1CaloGeometryRecord.h"
00026
00027
00028 #include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
00029 #include "RecoEcal/EgammaCoreTools/interface/EcalEtaPhiRegion.h"
00030
00031
00032 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTExtendedCand.h"
00033 #include "DataFormats/L1Trigger/interface/L1MuonParticle.h"
00034 #include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
00035
00036
00037 #include "DataFormats/L1Trigger/interface/L1JetParticle.h"
00038 #include "DataFormats/L1Trigger/interface/L1JetParticleFwd.h"
00039 #include <vector>
00040
00041
00042 using namespace l1extra;
00043
00044
00045 ESListOfFEDSProducer::ESListOfFEDSProducer(const edm::ParameterSet& pset) {
00046
00047 debug_ = pset.getUntrackedParameter<bool>("debug");
00048
00049
00050
00051
00052 EGamma_ = pset.getUntrackedParameter<bool>("EGamma",false);
00053 Muon_ = pset.getUntrackedParameter<bool>("Muon",false);
00054 Jets_ = pset.getUntrackedParameter<bool>("Jets",false);
00055
00056 if (EGamma_ && Muon_) {
00057 throw cms::Exception("ESListOfFEDSProducer") <<
00058 " Wrong configuration : EGamma and Muon should not be true at the same time." ;
00059 }
00060
00061
00062 if (EGamma_) {
00063
00064 EMl1TagIsolated_ = pset.getUntrackedParameter<edm::InputTag>("EM_l1TagIsolated");
00065 EMl1TagNonIsolated_ = pset.getUntrackedParameter<edm::InputTag>("EM_l1TagNonIsolated");
00066 EMdoIsolated_ = pset.getUntrackedParameter<bool>("EM_doIsolated",true);
00067 EMdoNonIsolated_ = pset.getUntrackedParameter<bool>("EM_doNonIsolated",true);
00068 EMregionEtaMargin_ = pset.getUntrackedParameter<double>("EM_regionEtaMargin",0.25);
00069 EMregionPhiMargin_ = pset.getUntrackedParameter<double>("EM_regionPhiMargin",0.40);
00070 Ptmin_iso_ = pset.getUntrackedParameter<double>("Ptmin_iso",0.);
00071 Ptmin_noniso_ = pset.getUntrackedParameter<double>("Ptmin_noniso",0.);
00072 }
00073
00074 if (Muon_) {
00075 MUregionEtaMargin_ = pset.getUntrackedParameter<double>("MU_regionEtaMargin",1.0);
00076 MUregionPhiMargin_ = pset.getUntrackedParameter<double>("MU_regionPhiMargin",1.0);
00077 Ptmin_muon_ = pset.getUntrackedParameter<double>("Ptmin_muon",0.);
00078 MuonSource_ = pset.getUntrackedParameter<edm::InputTag>("MuonSource");
00079 }
00080
00081 if (Jets_) {
00082 JETSregionEtaMargin_ = pset.getUntrackedParameter<double>("JETS_regionEtaMargin",1.0);
00083 JETSregionPhiMargin_ = pset.getUntrackedParameter<double>("JETS_regionPhiMargin",1.0);
00084 Ptmin_jets_ = pset.getUntrackedParameter<double>("Ptmin_jets",0.);
00085 CentralSource_ = pset.getUntrackedParameter<edm::InputTag>("CentralSource");
00086 ForwardSource_ = pset.getUntrackedParameter<edm::InputTag>("ForwardSource");
00087 TauSource_ = pset.getUntrackedParameter<edm::InputTag>("TauSource");
00088 JETSdoCentral_ = pset.getUntrackedParameter<bool>("JETS_doCentral",true);
00089 JETSdoForward_ = pset.getUntrackedParameter<bool>("JETS_doForward",true);
00090 JETSdoTau_ = pset.getUntrackedParameter<bool>("JETS_doTau",true);
00091 }
00092
00093
00094 OutputLabel_ = pset.getUntrackedParameter<std::string>("OutputLabel");
00095
00096 TheMapping = new EcalElectronicsMapping();
00097 first_ = true;
00098
00099 TheESMapping = new ESElectronicsMapper(pset);
00100
00101 produces<ESListOfFEDS>(OutputLabel_);
00102
00103
00104
00105 }
00106
00107
00108
00109 ESListOfFEDSProducer::~ESListOfFEDSProducer() {
00110 delete TheMapping;
00111 }
00112
00113
00114 void ESListOfFEDSProducer::beginJob(){
00115 }
00116
00117 void ESListOfFEDSProducer::endJob(){
00118 }
00119
00120 void ESListOfFEDSProducer::produce(edm::Event & e, const edm::EventSetup& iSetup){
00121
00122 if (first_) {
00123 edm::ESHandle< EcalElectronicsMapping > ecalmapping;
00124 iSetup.get< EcalMappingRcd >().get(ecalmapping);
00125 const EcalElectronicsMapping* TheMapping_ = ecalmapping.product();
00126 *TheMapping = *TheMapping_;
00127 first_ = false;
00128
00129 }
00130
00131 std::auto_ptr<ESListOfFEDS> productAddress(new ESListOfFEDS);
00132
00133 std::vector<int> feds;
00134
00135
00137 std::vector<int> Done;
00138 if (EGamma_) {
00139
00140 Egamma(e, iSetup, Done, feds);
00141 }
00142
00143 if (Muon_) {
00145
00146
00147 }
00148
00149 if (Jets_) {
00150
00151
00152 }
00153
00154 if ( !EGamma_ && !Muon_ && ! Jets_) {
00155 for (int i=1; i <= 54; i++) {
00156 if ( std::find(Done.begin(), Done.end(), i) == Done.end())
00157 feds.push_back(i);
00158 }
00159 }
00160
00161
00162 int nf = (int)feds.size();
00163 for (int i=0; i <nf; i++) {
00164 feds[i] += FEDNumbering::MINECALFEDID;
00165 if (debug_) std::cout << "Will unpack FED " << feds[i] << std::endl;
00166 }
00167
00168 if (debug_ && nf < 1 )
00169 std::cout << " Warning : no ECAL FED to unpack for Run " << e.id().run() << " Event " << e.id().event() << std::endl;
00170
00172 std::vector<int> es_feds = TheESMapping->GetListofFEDs(feds);
00173
00174
00175 std::vector< edm::Handle<ESListOfFEDS> > esFEDs_Done;
00176 e.getManyByType(esFEDs_Done);
00177 unsigned int esnDone = esFEDs_Done.size();
00178
00179 if(debug_){
00180 std::cout<<int(es_feds.size())<<" feds requested, and ESunpacking have already been done "<<esnDone<<" times."<<std::endl;
00181 }
00182
00183 for(int i=0; i<int(esFEDs_Done.size());i++){
00184 std::vector<int> done = esFEDs_Done[i]-> GetList();
00185 for(int n=0; n<int(done.size());n++){
00186 for(int j=0; j<int(es_feds.size());j++){
00187 std::vector<int>::iterator it = find(es_feds.begin(),es_feds.end(),done[n]);
00188 if( it != es_feds.end()){
00189 es_feds.erase(it);
00190 j--;
00191 }
00192 }
00193 }
00194 }
00195
00196 if (debug_ ){
00197 std::cout<<"ESListofFEDSProducer: new ES_list will be put into event: total "<<int(es_feds.size())<<std::endl;
00198 for(int j=0; j<int(es_feds.size());j++){
00199 std::cout<<es_feds[j]<<" ";
00200 }
00201 std::cout<<std::endl;
00202 }
00203
00204
00206 productAddress.get() -> SetList(es_feds);
00207 e.put(productAddress,OutputLabel_);
00208
00209 }
00210
00211
00212
00213 void ESListOfFEDSProducer::Egamma(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs ) {
00214
00215
00216
00217 if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Egamma" << std::endl;
00218
00219
00220
00221 edm::Handle< l1extra::L1EmParticleCollection > emIsolColl ;
00222 if(EMdoIsolated_)
00223 e.getByLabel(EMl1TagIsolated_, emIsolColl);
00224
00225 edm::Handle< l1extra::L1EmParticleCollection > emNonIsolColl ;
00226 if (EMdoNonIsolated_)
00227 e.getByLabel(EMl1TagNonIsolated_, emNonIsolColl);
00228
00229
00230 edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
00231 es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
00232
00233 if(EMdoIsolated_) {
00234
00235 for( l1extra::L1EmParticleCollection::const_iterator emItr = emIsolColl->begin();
00236 emItr != emIsolColl->end() ;++emItr ){
00237
00238 float pt = emItr -> pt();
00239 if (pt < Ptmin_iso_ ) continue;
00240 if (debug_) std::cout << " Here is an L1 isoEM candidate of pt " << pt << std::endl;
00241
00242 int etaIndex = emItr->gctEmCand()->etaIndex() ;
00243 int phiIndex = emItr->gctEmCand()->phiIndex() ;
00244
00245 double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
00246 double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
00247 double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
00248 double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
00249
00250 std::vector<int> feds = ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, EMregionEtaMargin_, EMregionPhiMargin_);
00251 for (int i=0; i < (int)feds.size(); i++) {
00252 if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
00253 std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
00254 }
00255
00256 }
00257
00258 }
00259
00260
00261 if (EMdoNonIsolated_) {
00262
00263 for( l1extra::L1EmParticleCollection::const_iterator emItr = emNonIsolColl->begin();
00264 emItr != emNonIsolColl->end() ;++emItr ){
00265
00266 float pt = emItr -> pt();
00267 if (debug_) std::cout << " Here is an L1 nonisoEM candidate of pt " << pt << std::endl;
00268 if (pt < Ptmin_noniso_ ) continue;
00269
00270 int etaIndex = emItr->gctEmCand()->etaIndex() ;
00271 int phiIndex = emItr->gctEmCand()->phiIndex() ;
00272
00273
00274 double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
00275 double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
00276 double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
00277 double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
00278
00279 std::vector<int> feds = ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, EMregionEtaMargin_, EMregionPhiMargin_);
00280 for (int i=0; i < (int)feds.size(); i++) {
00281 if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
00282 std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
00283
00284 }
00285
00286 }
00287 }
00288
00289
00290
00291 if (debug_) {
00292 std::cout << std::endl;
00293 for (int i=0; i < (int)FEDs.size(); i++) {
00294 std::cout << "Egamma: unpack FED " << FEDs[i] << std::endl;
00295 }
00296 std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
00297 }
00298
00299
00300
00301 }
00302
00303
00304
00305 void ESListOfFEDSProducer::Muon(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs) {
00306
00307
00308
00309 if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Muon" << std::endl;
00310
00311 edm::Handle<L1MuonParticleCollection> muColl;
00312 e.getByLabel(MuonSource_, muColl);
00313
00314
00315 double epsilon = 0.01;
00316
00317 for (L1MuonParticleCollection::const_iterator it=muColl->begin(); it != muColl->end(); it++) {
00318
00319 const L1MuGMTExtendedCand muonCand = (*it).gmtMuonCand();
00320 double pt = (*it).pt();
00321 double eta = (*it).eta();
00322 double phi = (*it).phi();
00323
00324 if (debug_) std::cout << " here is a L1 muon Seed with (eta,phi) = " <<
00325 eta << " " << phi << " and pt " << pt << std::endl;
00326 if (pt < Ptmin_muon_ ) continue;
00327
00328 std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, MUregionEtaMargin_, MUregionPhiMargin_);
00329
00330 for (int i=0; i < (int)feds.size(); i++) {
00331 if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
00332 std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
00333 }
00334 }
00335
00336 if (debug_) {
00337 std::cout << std::endl;
00338 for (int i=0; i < (int)FEDs.size(); i++) {
00339 std::cout << "Muons: unpack FED " << FEDs[i] << std::endl;
00340 }
00341 std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
00342 }
00343
00344
00345
00346
00347 }
00348
00349
00350
00351
00352 void ESListOfFEDSProducer::Jets(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs) {
00353
00354
00355
00356 if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Jets" << std::endl;
00357 double epsilon = 0.01;
00358
00359
00360
00361
00362
00363 if (JETSdoCentral_) {
00364
00365 edm::Handle<L1JetParticleCollection> jetColl;
00366 e.getByLabel(CentralSource_,jetColl);
00367
00368 for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
00369
00370 double pt = it -> pt();
00371 double eta = it -> eta();
00372 double phi = it -> phi();
00373
00374 if (debug_) std::cout << " here is a L1 CentralJet Seed with (eta,phi) = " <<
00375 eta << " " << phi << " and pt " << pt << std::endl;
00376
00377
00378
00379
00380
00381
00382
00383
00384 if (pt < Ptmin_jets_ ) continue;
00385
00386 std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
00387
00388 for (int i=0; i < (int)feds.size(); i++) {
00389 if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
00390 std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
00391 }
00392 }
00393 }
00394
00395 if (JETSdoForward_) {
00396
00397 edm::Handle<L1JetParticleCollection> jetColl;
00398 e.getByLabel(ForwardSource_,jetColl);
00399
00400 for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
00401
00402 double pt = it -> pt();
00403 double eta = it -> eta();
00404 double phi = it -> phi();
00405
00406 if (debug_) std::cout << " here is a L1 ForwardJet Seed with (eta,phi) = " <<
00407 eta << " " << phi << " and pt " << pt << std::endl;
00408 if (pt < Ptmin_jets_ ) continue;
00409
00410 std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
00411
00412 for (int i=0; i < (int)feds.size(); i++) {
00413 if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
00414 std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
00415 }
00416 }
00417 }
00418
00419 if (JETSdoTau_) {
00420
00421 edm::Handle<L1JetParticleCollection> jetColl;
00422 e.getByLabel(TauSource_,jetColl);
00423
00424 for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
00425
00426 double pt = it -> pt();
00427 double eta = it -> eta();
00428 double phi = it -> phi();
00429
00430 if (debug_) std::cout << " here is a L1 TauJet Seed with (eta,phi) = " <<
00431 eta << " " << phi << " and pt " << pt << std::endl;
00432 if (pt < Ptmin_jets_ ) continue;
00433
00434 std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
00435
00436 for (int i=0; i < (int)feds.size(); i++) {
00437 if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
00438 std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
00439 }
00440 }
00441 }
00442
00443
00444
00445 if (debug_) {
00446 std::cout << std::endl;
00447 for (int i=0; i < (int)FEDs.size(); i++) {
00448 std::cout << "Jets: unpack FED " << FEDs[i] << std::endl;
00449 }
00450 std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
00451 }
00452
00453
00454
00455
00456 }
00457
00458
00459 std::vector<int> ESListOfFEDSProducer::ListOfFEDS(double etaLow, double etaHigh, double phiLow,
00460 double phiHigh, double etamargin, double phimargin)
00461 {
00462
00463 std::vector<int> FEDs;
00464
00465 if (phimargin > Geom::pi()) phimargin = Geom::pi() ;
00466
00467
00468 if (debug_) std::cout << " etaLow etaHigh phiLow phiHigh " << etaLow << " " <<
00469 etaHigh << " " << phiLow << " " << phiHigh << std::endl;
00470
00471 etaLow -= etamargin;
00472 etaHigh += etamargin;
00473 double phiMinus = phiLow - phimargin;
00474 double phiPlus = phiHigh + phimargin;
00475
00476 bool all = false;
00477 double dd = fabs(phiPlus-phiMinus);
00478 if (debug_) std::cout << " dd = " << dd << std::endl;
00479 if (dd > 2.*Geom::pi() ) all = true;
00480
00481 while (phiPlus > Geom::pi()) { phiPlus -= 2.*Geom::pi() ; }
00482 while (phiMinus < 0) { phiMinus += 2.*Geom::pi() ; }
00483 if ( phiMinus > Geom::pi()) phiMinus -= 2.*Geom::pi() ;
00484
00485 double dphi = phiPlus - phiMinus;
00486 if (dphi < 0) dphi += 2.*Geom::pi() ;
00487 if (debug_) std::cout << "dphi = " << dphi << std::endl;
00488 if (dphi > Geom::pi()) {
00489 int fed_low1 = TheMapping -> GetFED(etaLow,phiMinus*180./Geom::pi());
00490 int fed_low2 = TheMapping -> GetFED(etaLow,phiPlus*180./Geom::pi());
00491 if (debug_) std::cout << "fed_low1 fed_low2 " << fed_low1 << " " << fed_low2 << std::endl;
00492 if (fed_low1 == fed_low2) all = true;
00493 int fed_hi1 = TheMapping -> GetFED(etaHigh,phiMinus*180./Geom::pi());
00494 int fed_hi2 = TheMapping -> GetFED(etaHigh,phiPlus*180./Geom::pi());
00495 if (debug_) std::cout << "fed_hi1 fed_hi2 " << fed_hi1 << " " << fed_hi2 << std::endl;
00496 if (fed_hi1 == fed_hi2) all = true;
00497 }
00498
00499
00500 if (all) {
00501 if (debug_) std::cout << " unpack everything in phi ! " << std::endl;
00502 phiMinus = -20 * Geom::pi() / 180.;
00503 phiPlus = -40 * Geom::pi() / 180.;
00504 }
00505
00506 if (debug_) std::cout << " with margins : " << etaLow << " " << etaHigh << " " <<
00507 phiMinus << " " << phiPlus << std::endl;
00508
00509
00510 const EcalEtaPhiRegion ecalregion(etaLow,etaHigh,phiMinus,phiPlus);
00511
00512 FEDs = TheMapping -> GetListofFEDs(ecalregion);
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523 return FEDs;
00524
00525 }
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550