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