00001
00002
00003
00004 #include "EventFilter/EcalRawToDigi/plugins/EcalRawToRecHitRoI.h"
00005 #include "DataFormats/EcalRawData/interface/EcalListOfFEDS.h"
00006 #include "DataFormats/EcalRawData/interface/ESListOfFEDS.h"
00007
00008
00009
00010 #include <DataFormats/FEDRawData/interface/FEDNumbering.h>
00011
00012
00013
00014 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"
00015 #include "CondFormats/DataRecord/interface/L1CaloGeometryRecord.h"
00016
00017
00018
00019 #include "RecoEcal/EgammaCoreTools/interface/EcalEtaPhiRegion.h"
00020
00021
00022 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTExtendedCand.h"
00023 #include "DataFormats/L1Trigger/interface/L1MuonParticle.h"
00024 #include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
00025
00026
00027 #include "DataFormats/L1Trigger/interface/L1JetParticle.h"
00028
00029
00030 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00031 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00032
00033 #include "EventFilter/EcalRawToDigi/interface/EcalRegionCablingRecord.h"
00034 #include "EventFilter/EcalRawToDigi/interface/EcalRegionCabling.h"
00035 #include "EventFilter/EcalRawToDigi/interface/MyWatcher.h"
00036 #include "DataFormats/EcalRecHit/interface/EcalRecHitComparison.h"
00037
00038
00039 using namespace l1extra;
00040
00041 EcalRawToRecHitRoI::CandJobPSet::CandJobPSet(edm::ParameterSet &cfg) : CalUnpackJobPSet(cfg) {
00042 epsilon = cfg.getParameter<double>("epsilon");
00043 bePrecise = cfg.getParameter<bool>("bePrecise");
00044 if (bePrecise){ propagatorNameToBePrecise = cfg.getParameter<std::string>("propagatorNameToBePrecise");}
00045 else propagatorNameToBePrecise="";
00046 std::string type = cfg.getParameter<std::string>("cType");
00047 if (type == "view"){cType=view;}
00048 else if (type == "candidate"){cType=candidate;}
00049 else if (type == "chargedcandidate"){cType=chargedcandidate;}
00050 else if (type == "l1muon"){cType=l1muon;}
00051 else if (type == "l1jet"){cType=l1jet;}
00052 else {
00053 edm::LogWarning("IncorrectConfiguration")<<"\n\n could not interpret the cType: "<<type
00054 <<"\n using edm::View< reco::Candidate > by default. expect your trigger path to be slow !\n\n";
00055 cType=view;}
00056 }
00057
00058
00059 EcalRawToRecHitRoI::EcalRawToRecHitRoI(const edm::ParameterSet& pset) :
00060 EGamma_(false), Muon_(false), Jet_(false), Candidate_(false), All_(false){
00061 const std::string category = "EcalRawToRecHit|RoI";
00062
00063 sourceTag_=pset.getParameter<edm::InputTag>("sourceTag");
00064
00065 std::string type = pset.getParameter<std::string>("type");
00066
00067 if (type.find("candidate")!=std::string::npos){
00068 LogDebug(category)<<"configured for candidate-versatile input.";
00069 Candidate_ = true;
00070 std::vector<edm::ParameterSet> emPSet = pset.getParameter<std::vector<edm::ParameterSet> >("CandJobPSet");
00071 for (std::vector<edm::ParameterSet>::iterator iepset = emPSet.begin(); iepset!=emPSet.end();++iepset){
00072 CandSource_.push_back(CandJobPSet(*iepset));
00073 LogDebug(category)<<iepset->dump();
00074 }
00075 }
00076
00077 if (type.find("muon")!=std::string::npos){
00078 LogDebug(category)<<"configured for L1MuonParticleCollection input.";
00079 Muon_ = true;
00080 edm::ParameterSet ps = pset.getParameter<edm::ParameterSet>("MuJobPSet");
00081 MuonSource_ = MuJobPSet(ps);
00082 LogDebug(category)<<ps.dump();
00083 }
00084
00085 if (type.find("egamma")!=std::string::npos){
00086 LogDebug(category)<<"configured for L1EMParticleCollection input.";
00087 EGamma_ = true;
00088 std::vector<edm::ParameterSet> emPSet = pset.getParameter<std::vector<edm::ParameterSet> >("EmJobPSet");
00089 for (std::vector<edm::ParameterSet>::iterator iepset = emPSet.begin(); iepset!=emPSet.end();++iepset){
00090 EmSource_.push_back(EmJobPSet(*iepset));
00091 LogDebug(category)<<iepset->dump();
00092 }
00093 }
00094
00095 if (type.find("jet")!=std::string::npos){
00096 LogDebug(category)<<"configured for L1JetParticleCollection input.";
00097 Jet_ =true;
00098 std::vector<edm::ParameterSet> jetPSet = pset.getParameter<std::vector<edm::ParameterSet> >("JetJobPSet");
00099 for (std::vector<edm::ParameterSet>::iterator ijpset = jetPSet.begin(); ijpset!=jetPSet.end();++ijpset){
00100 JetSource_.push_back(JetJobPSet(*ijpset));
00101 LogDebug(category)<<ijpset->dump();
00102 }
00103 }
00104
00105 if (type.find("all")!=std::string::npos){
00106 LogDebug(category)<<"configured for ALL feds unpacking";
00107 All_ = true;
00108 }
00109
00110 if (!All_ && !Muon_ && !EGamma_ && !Jet_ && !Candidate_){
00111 edm::LogError("IncorrectConfiguration")<<"I have no specified type of work."
00112 <<"\nI will produce empty list of FEDs."
00113 <<"\nI will produce an empty EcalRecHitRefGetter."
00114 <<"\n I am sure you don't want that.";
00115
00116 }
00117
00118 produces<EcalListOfFEDS>();
00119 produces<EcalRecHitRefGetter>();
00120
00121 if (pset.exists("doES"))
00122 do_es_ = pset.getParameter<bool>("doES");
00123 else
00124 do_es_ = false;
00125
00126 if (do_es_) {
00127 LogDebug(category)<<"will also make the list of FEDs for the ES.";
00128 sourceTag_es_=pset.getParameter<edm::InputTag>("sourceTag_es");
00129 esinstance_=pset.getUntrackedParameter<std::string>("esInstance","es");
00130 if (esinstance_=="")
00131 edm::LogError("IncorrectConfiguration")<<" instance name for ES region and FED list cannot be empty. expect a fwk failure.";
00132 produces<ESListOfFEDS>(esinstance_);
00133 produces<EcalRecHitRefGetter>(esinstance_);
00134 }
00135 }
00136
00137
00138
00139 EcalRawToRecHitRoI::~EcalRawToRecHitRoI() {
00140 }
00141
00142
00143
00144 #include <sstream>
00145 std::string EcalRawToRecHitRoI::dumpFEDs(const std::vector<int> & FEDs){
00146 std::stringstream ss;
00147 ss<<"unpack FED: ";
00148 for (unsigned int i=0; i < FEDs.size(); i++) {
00149 ss<< FEDs[i] << ((i!= FEDs.size()-1)? ", ":"\n");
00150 }
00151 ss<< "Number of FEDS is " << FEDs.size();
00152 return ss.str();
00153 }
00154
00155 void EcalRawToRecHitRoI::produce(edm::Event & e, const edm::EventSetup& iSetup){
00156 const std::string category = "EcalRawToRecHit|RoI";
00157 MyWatcher watcher("RoI");
00158 LogDebug(category)<<watcher.lap();
00159
00160
00161 edm::ESHandle<EcalRegionCabling> cabling;
00162 iSetup.get<EcalRegionCablingRecord>().get(cabling);
00163 LogDebug(category)<<"cabling retrieved."
00164 <<watcher.lap();
00165 TheMapping =cabling->mapping();
00166 TheESMapping =cabling->es_mapping();
00167
00168 std::auto_ptr<EcalListOfFEDS> productAddress(new EcalListOfFEDS);
00169 std::vector<int> feds;
00170
00171 if (EGamma_) { Egamma(e, iSetup, feds); }
00172
00173 if (Muon_) { Muon(e, iSetup, feds); }
00174
00175 if (Jet_) { Jet(e, iSetup, feds); }
00176
00177 if (Candidate_) { Cand(e, iSetup, feds); }
00178
00179 if (All_) { for (int i=1; i <= 54; feds.push_back(i++)){} }
00180
00181 unsigned int nf = feds.size();
00182 for (unsigned int i=0; i <nf; feds[i++]+=FEDNumbering::MINECALFEDID) {}
00183
00184 LogDebug(category)<< "Will unpack Ecal FED\n" <<dumpFEDs(feds)
00185 <<watcher.lap();
00186
00187
00188
00189 productAddress->SetList(feds);
00190 e.put(productAddress);
00191 LogDebug(category)<< "list of ECAL fed put in the event."
00192 <<watcher.lap();
00193
00194
00195
00196
00197
00198
00199 edm::Handle<EcalRecHitLazyGetter> lgetter;
00200 e.getByLabel(sourceTag_, lgetter);
00201 if (lgetter.failedToGet())
00202 {
00203 edm::LogError("IncorrectConfiguration")<<" could not retrieve the lazy getter from: "<<sourceTag_;
00204 return;
00205 }
00206
00207 LogDebug(category)<<"Ecal lazy getter retrieved from: "<<sourceTag_
00208 <<watcher.lap();
00209
00210
00211
00212 std::auto_ptr<EcalRecHitRefGetter> rgetter(new EcalRecHitRefGetter);
00213 LogDebug(category)<<"ECal ref getter ready to be updated."
00214 <<watcher.lap();
00215
00216 for (unsigned int i=0;i!=nf;i++){
00217 cabling->updateEcalRefGetterWithFedIndex(*rgetter, lgetter, feds[i]);
00218
00219 }
00220
00221
00222 LogDebug(category)<<"Ecal refGetter to be put in the event."
00223 << watcher.lap();
00224 e.put(rgetter);
00225 LogDebug(category)<<"Ecal refGetter loaded."
00226 << watcher.lap();
00227
00228
00229 if (do_es_){
00230 LogDebug(category)<< "Will make the ES list of FEDs at the same time."
00231 <<watcher.lap();
00232 std::auto_ptr<ESListOfFEDS> productAddressES(new ESListOfFEDS);
00233 std::vector<int> es_feds = TheESMapping->GetListofFEDs(feds);
00234
00235 LogDebug(category)<< "Will unpack ES FED\n" <<dumpFEDs(es_feds)
00236 <<watcher.lap();
00237
00238
00239 productAddressES->SetList(es_feds);
00240 e.put(productAddressES,esinstance_);
00241
00242
00243 LogDebug(category)<< "list of ES fed put in the event."
00244 <<watcher.lap();
00245
00246 edm::Handle<EcalRecHitLazyGetter> lgetter_es;
00247 e.getByLabel(sourceTag_es_, lgetter_es);
00248 if (lgetter_es.failedToGet())
00249 {
00250 edm::LogError("IncorrectConfiguration")<<" could not retrieve the lazy getter from: "<<sourceTag_es_;
00251 return;
00252 }
00253
00254 LogDebug(category)<<"ES lazy getter retrieved from: "<<sourceTag_es_
00255 <<watcher.lap();
00256
00257 std::auto_ptr<EcalRecHitRefGetter> rgetter_es(new EcalRecHitRefGetter);
00258 LogDebug(category)<<"ES ref getter ready to be updated."
00259 <<watcher.lap();
00260
00261 unsigned int nf_es=es_feds.size();
00262 for (unsigned int i=0;i!=nf_es;i++){
00263 cabling->updateEcalRefGetterWithElementIndex(*rgetter_es, lgetter_es, cabling->esElementIndex(es_feds[i]));
00264 }
00265
00266 LogDebug(category)<<"ES refGetter to be put in the event."
00267 << watcher.lap();
00268 e.put(rgetter_es,esinstance_);
00269 LogDebug(category)<<"ES refGetter loaded."
00270 << watcher.lap();
00271 }
00272
00273 }
00274
00275 void EcalRawToRecHitRoI::Cand(edm::Event& e, const edm::EventSetup& es , std::vector<int> & FEDs) {
00276 const std::string category ="EcalRawToRecHit|Cand";
00277
00278 unsigned int nc=CandSource_.size();
00279 for (unsigned int ic=0;ic!=nc;++ic){
00280 switch (CandSource_[ic].cType){
00281 case CandJobPSet::view :
00282 OneCandCollection< edm::View<reco::Candidate> >(e, es, CandSource_[ic], FEDs);
00283 break;
00284
00285 case CandJobPSet::candidate :
00286 OneCandCollection<reco::CandidateCollection>(e, es, CandSource_[ic], FEDs);
00287 break;
00288
00289 case CandJobPSet::chargedcandidate :
00290 OneCandCollection<reco::RecoChargedCandidateCollection>(e, es, CandSource_[ic], FEDs);
00291 break;
00292
00293 case CandJobPSet::l1muon :
00294 OneCandCollection<L1MuonParticleCollection>(e, es, CandSource_[ic], FEDs);
00295 break;
00296
00297 case CandJobPSet::l1jet :
00298 OneCandCollection<L1JetParticleCollection>(e, es, CandSource_[ic], FEDs);
00299 break;
00300
00301 default:
00302 edm::LogError("IncorrectRecHit")<<"cType not recognised: "<<CandSource_[ic].cType;
00303 }
00304 }
00305
00306 unique(FEDs);
00307 LogDebug(category)<<"unpack FED\n"<<dumpFEDs(FEDs);
00308 }
00309
00310 void EcalRawToRecHitRoI::Egamma_OneL1EmCollection(const edm::Handle< l1extra::L1EmParticleCollection > emColl,
00311 const EmJobPSet &ejpset,
00312 const edm::ESHandle<L1CaloGeometry> & l1CaloGeom,
00313 std::vector<int> & FEDs){
00314 const std::string category = "EcalRawToRecHit|Egamma";
00315 for( l1extra::L1EmParticleCollection::const_iterator emItr = emColl->begin();
00316 emItr != emColl->end() ;++emItr ){
00317 float pt = emItr -> pt();
00318 if (pt < ejpset.Ptmin ) continue;
00319 LogDebug(category)<<" Here is an L1 isoEM candidate of pt " << pt;
00320
00321 int etaIndex = emItr->gctEmCand()->etaIndex() ;
00322 int phiIndex = emItr->gctEmCand()->phiIndex() ;
00323
00324 double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
00325 double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
00326 double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
00327 double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
00328
00329 ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, ejpset.regionEtaMargin, ejpset.regionPhiMargin,FEDs);
00330 }
00331 }
00332
00333 void EcalRawToRecHitRoI::Egamma(edm::Event& e, const edm::EventSetup& es , std::vector<int> & FEDs) {
00334 const std::string category = "EcalRawToRecHit|Egamma";
00335
00336 LogDebug(category)<< " enter in EcalRawToRecHitRoI::Egamma";
00337
00338
00339 edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
00340 es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
00341
00342 edm::Handle< l1extra::L1EmParticleCollection > emColl;
00343 unsigned int ne=EmSource_.size();
00344 for (unsigned int ie=0;ie!=ne;++ie){
00345 e.getByLabel(EmSource_[ie].Source,emColl);
00346 if (!emColl.isValid()){edm::LogError("IncorrectConfiguration")<<"L1Em Collection: "<<EmSource_[ie].Source<<" is not valid.";continue;}
00347
00348 Egamma_OneL1EmCollection(emColl,EmSource_[ie],l1CaloGeom,FEDs);
00349 }
00350
00351 unique(FEDs);
00352 LogDebug(category)<<"end of get list of feds\n"<<dumpFEDs(FEDs);
00353 return;
00354 }
00355
00356
00357 void EcalRawToRecHitRoI::Muon(edm::Event& e, const edm::EventSetup& es, std::vector<int>& FEDs) {
00358 const std::string category = "EcalRawToRecHit|Muon";
00359
00360 LogDebug(category)<< " enter in EcalRawToRecHitRoI::Muon";
00361
00362 edm::Handle<L1MuonParticleCollection> muColl;
00363 e.getByLabel(MuonSource_.Source, muColl);
00364 if (muColl.failedToGet())
00365 {
00366 edm::LogError("IncorrectConfiguration")<<" could not retrieve the l1 muon collection from: "<<MuonSource_.Source;
00367 return;
00368 }
00369
00370 for (L1MuonParticleCollection::const_iterator it=muColl->begin(); it != muColl->end(); it++) {
00371
00372 const L1MuGMTExtendedCand muonCand = (*it).gmtMuonCand();
00373 double pt = (*it).pt();
00374 double eta = (*it).eta();
00375 double phi = (*it).phi();
00376
00377 LogDebug(category)<<" here is a L1 muon Seed with (eta,phi) = "
00378 <<eta << " " << phi << " and pt " << pt;
00379 if (pt < MuonSource_.Ptmin) continue;
00380
00381 ListOfFEDS(eta, eta, phi-MuonSource_.epsilon, phi+MuonSource_.epsilon, MuonSource_.regionEtaMargin, MuonSource_.regionPhiMargin,FEDs);
00382 }
00383
00384 unique(FEDs);
00385 LogDebug(category)<<"end of get list of feds\n"<<dumpFEDs(FEDs);
00386
00387 return;
00388 }
00389
00390 void EcalRawToRecHitRoI::Jet_OneL1JetCollection(const edm::Handle< l1extra::L1JetParticleCollection > jetColl,
00391 const JetJobPSet & jjpset,
00392 std::vector<int> & feds){
00393 const std::string category ="EcalRawToRecHit|Jet";
00394 for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
00395 double pt = it -> pt();
00396 double eta = it -> eta();
00397 double phi = it -> phi();
00398
00399 LogDebug(category) << " here is a L1 CentralJet Seed with (eta,phi) = "
00400 << eta << " " << phi << " and pt " << pt;
00401
00402 if (pt < jjpset.Ptmin ) continue;
00403
00404 ListOfFEDS(eta, eta, phi-jjpset.epsilon, phi+jjpset.epsilon, jjpset.regionEtaMargin, jjpset.regionPhiMargin,feds);
00405 }
00406 }
00407
00408 void EcalRawToRecHitRoI::Jet(edm::Event& e, const edm::EventSetup& es, std::vector<int> & FEDs) {
00409 const std::string category = "EcalRawToRecHit|Jet";
00410
00411 edm::Handle<L1JetParticleCollection> jetColl;
00412 unsigned int nj=JetSource_.size();
00413 for (unsigned int ij=0;ij!=nj;++ij){
00414 e.getByLabel(JetSource_[ij].Source,jetColl);
00415 if (!jetColl.isValid()) {
00416 edm::LogError("IncorrectConfiguration") << "L1Jet collection: " << JetSource_[ij].Source << " is not valid.";
00417 continue;
00418 }
00419
00420 Jet_OneL1JetCollection(jetColl,JetSource_[ij],FEDs);
00421 }
00422
00423 unique(FEDs);
00424 LogDebug(category)<<"unpack FED\n"<<dumpFEDs(FEDs);
00425 }
00426
00427
00428
00429
00430 void EcalRawToRecHitRoI::ListOfFEDS(double etaLow, double etaHigh, double phiLow,
00431 double phiHigh, double etamargin, double phimargin,
00432 std::vector<int> & FEDs)
00433 {
00434 const std::string category = "EcalRawToRecHit|ListOfFEDS";
00435
00436 if (phimargin > Geom::pi()) phimargin = Geom::pi() ;
00437
00438
00439 LogDebug(category)<< " etaLow etaHigh phiLow phiHigh " << etaLow << " "
00440 <<etaHigh << " " << phiLow << " " << phiHigh;
00441
00442
00443 etaLow -= etamargin;
00444 etaHigh += etamargin;
00445 double phiMinus = phiLow - phimargin;
00446 double phiPlus = phiHigh + phimargin;
00447
00448 bool all = false;
00449 double dd = fabs(phiPlus-phiMinus);
00450 LogDebug(category)<< " dd = " << dd;
00451 if (dd > 2.*Geom::pi() ) all = true;
00452
00453 while (phiPlus > Geom::pi()) { phiPlus -= 2.*Geom::pi() ; }
00454 while (phiMinus < 0) { phiMinus += 2.*Geom::pi() ; }
00455 if ( phiMinus > Geom::pi()) phiMinus -= 2.*Geom::pi() ;
00456
00457 double dphi = phiPlus - phiMinus;
00458 if (dphi < 0) dphi += 2.*Geom::pi() ;
00459 LogDebug(category) << "dphi = " << dphi;
00460 if (dphi > Geom::pi()) {
00461 int fed_low1 = TheMapping -> GetFED(etaLow,phiMinus*180./Geom::pi());
00462 int fed_low2 = TheMapping -> GetFED(etaLow,phiPlus*180./Geom::pi());
00463 LogDebug(category) << "fed_low1 fed_low2 " << fed_low1 << " " << fed_low2;
00464 if (fed_low1 == fed_low2) all = true;
00465 int fed_hi1 = TheMapping -> GetFED(etaHigh,phiMinus*180./Geom::pi());
00466 int fed_hi2 = TheMapping -> GetFED(etaHigh,phiPlus*180./Geom::pi());
00467 LogDebug(category) << "fed_hi1 fed_hi2 " << fed_hi1 << " " << fed_hi2;
00468 if (fed_hi1 == fed_hi2) all = true;
00469 }
00470
00471
00472 if (all) {
00473 LogDebug(category)<< " unpack everything in phi ! ";
00474 phiMinus = -20 * Geom::pi() / 180.;
00475 phiPlus = -40 * Geom::pi() / 180.;
00476 }
00477
00478 LogDebug(category) << " with margins : " << etaLow << " " << etaHigh << " "
00479 << phiMinus << " " << phiPlus;
00480
00481
00482 const EcalEtaPhiRegion ecalregion(etaLow,etaHigh,phiMinus,phiPlus);
00483
00484 TheMapping -> GetListofFEDs(ecalregion, FEDs);
00485 LogDebug(category)<<"unpack fed:\n"<<dumpFEDs(FEDs);
00486
00487 }