CMS 3D CMS Logo

EcalRawToRecHitRoI.cc

Go to the documentation of this file.
00001 
00002 //#include <FWCore/Framework/interface/Handle.h>
00003 
00004 #include "EventFilter/EcalRawToDigi/plugins/EcalRawToRecHitRoI.h"
00005 #include "DataFormats/EcalRawData/interface/EcalListOfFEDS.h"
00006 
00007 
00008 // Ecal Mapping 
00009 //#include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
00010 #include <DataFormats/FEDRawData/interface/FEDNumbering.h>
00011 
00012 
00013 // Level 1 Trigger
00014 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"
00015 #include "CondFormats/DataRecord/interface/L1CaloGeometryRecord.h"
00016                                                                                                                         
00017 // EgammaCoreTools
00018 //#include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
00019 #include "RecoEcal/EgammaCoreTools/interface/EcalEtaPhiRegion.h"
00020 
00021 // Muon stuff
00022 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTExtendedCand.h"
00023 #include "DataFormats/L1Trigger/interface/L1MuonParticle.h"
00024 #include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
00025 
00026 // Jets stuff
00027 #include "DataFormats/L1Trigger/interface/L1JetParticle.h"
00028 
00029 //candidate stuff
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::LogError("EcalRawToRecHitRoI")<<"\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(category)<<"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     //throw. this is a typo/omittion in a cfg.
00116   }
00117 
00118  produces<EcalListOfFEDS>();
00119  produces<EcalRecHitRefGetter>();
00120 }
00121 
00122 
00123 
00124 EcalRawToRecHitRoI::~EcalRawToRecHitRoI() {
00125 }
00126 
00127 
00128 void EcalRawToRecHitRoI::beginJob(const edm::EventSetup& c){
00129 }
00130 
00131 void EcalRawToRecHitRoI::endJob(){
00132 }
00133 
00134 #include <sstream>
00135 std::string EcalRawToRecHitRoI::dumpFEDs(const std::vector<int> & FEDs){
00136   std::stringstream ss;
00137   ss<<"unpack FED: ";
00138   for (uint i=0; i < FEDs.size(); i++) {
00139     ss<< FEDs[i] << ((i!= FEDs.size()-1)? ", ":"\n");
00140   }
00141   ss<< "Number of FEDS is " << FEDs.size();
00142   return ss.str();
00143 }
00144 
00145 void EcalRawToRecHitRoI::produce(edm::Event & e, const edm::EventSetup& iSetup){
00146   const std::string category = "EcalRawToRecHit|RoI";
00147   MyWatcher watcher("RoI");
00148   LogDebug(category)<<watcher.lap();
00149 
00150   // retreive cabling
00151   edm::ESHandle<EcalRegionCabling> cabling;
00152   iSetup.get<EcalRegionCablingRecord>().get(cabling);
00153   LogDebug(category)<<"cabling retrieved."
00154                     <<watcher.lap();
00155   TheMapping =cabling->mapping();
00156 
00157   std::pair<int,int> ecalfeds = FEDNumbering::getEcalFEDIds();
00158   int first_fed = ecalfeds.first;
00159   
00160   std::auto_ptr<EcalListOfFEDS> productAddress(new EcalListOfFEDS);
00161   std::vector<int> feds;                // the list of FEDS produced by this module
00162 
00163  if (EGamma_) {   Egamma(e, iSetup, feds); }
00164 
00165  if (Muon_) {   Muon(e, iSetup, feds); }
00166 
00167  if (Jet_) {   Jet(e, iSetup, feds); }
00168 
00169  if (Candidate_) { Cand(e, iSetup, feds); }
00170 
00171  if (All_)  {   for (int i=1; i <= 54; feds.push_back(i++)){} }
00172  
00173  uint nf = feds.size();
00174  for (uint i=0; i <nf; feds[i++]+=first_fed) {}
00175  
00176  LogDebug(category)<< "Will unpack FED\n" <<dumpFEDs(feds)
00177                    <<watcher.lap();
00178  
00179  if (nf<1){edm::LogWarning(category)<<"no ECAL FED to unpack for Run " << e.id().run() << "  Event " << e.id().event() ;}
00180  
00181  productAddress->SetList(feds);
00182  e.put(productAddress);
00183  LogDebug(category)<< "list of fed put in the event."
00184                    <<watcher.lap();
00185  
00186  //now defined the Region of interest to be unpacked. from the feds list
00187 
00188  
00189  //get the lazy gettter
00190  edm::Handle<EcalRecHitLazyGetter> lgetter;
00191  e.getByLabel(sourceTag_, lgetter);
00192  LogDebug(category)<<"lazy getter retrieved from: "<<sourceTag_
00193                    <<watcher.lap();
00194  
00195  //prepare a refgetter
00196  std::auto_ptr<EcalRecHitRefGetter> rgetter(new EcalRecHitRefGetter);
00197  LogDebug(category)<<"ref getter ready to be updated."
00198                                 <<watcher.lap();
00199  
00200  for (uint i=0;i!=nf;i++){
00201    cabling->updateEcalRefGetterWithFedIndex(*rgetter, lgetter, feds[i]);  
00202  }
00203  
00204  //put the refgetter in the event  
00205  LogDebug(category)<<"refGetter to be put in the event."
00206                    << watcher.lap();
00207  e.put(rgetter);
00208  LogDebug(category)<<"refGetter loaded."
00209                                 << watcher.lap();
00210 }
00211  
00212 void EcalRawToRecHitRoI::Cand(edm::Event& e, const edm::EventSetup& es , std::vector<int> & FEDs) {
00213   const std::string category ="EcalRawToRecHit|Cand";
00214   
00215   uint nc=CandSource_.size();
00216   for (uint ic=0;ic!=nc;++ic){
00217     switch (CandSource_[ic].cType){
00218     case CandJobPSet::view :
00219       OneCandCollection< edm::View<reco::Candidate> >(e, es, CandSource_[ic], FEDs);
00220       break;
00221       
00222     case CandJobPSet::candidate :
00223       OneCandCollection<reco::CandidateCollection>(e, es, CandSource_[ic], FEDs);
00224       break;
00225 
00226     case CandJobPSet::chargedcandidate :
00227       OneCandCollection<reco::RecoChargedCandidateCollection>(e, es, CandSource_[ic], FEDs);
00228       break;
00229 
00230     case CandJobPSet::l1muon :
00231       OneCandCollection<L1MuonParticleCollection>(e, es, CandSource_[ic], FEDs);
00232       break;
00233 
00234     case CandJobPSet::l1jet :
00235       OneCandCollection<L1JetParticleCollection>(e, es, CandSource_[ic], FEDs);
00236       break;
00237       
00238     default:
00239       edm::LogError(category)<<"cType not recognised: "<<CandSource_[ic].cType;
00240     }
00241   }
00242 
00243   unique(FEDs);
00244   LogDebug(category)<<"unpack FED\n"<<dumpFEDs(FEDs);
00245 }
00246 
00247 void EcalRawToRecHitRoI::Egamma_OneL1EmCollection(const edm::Handle< l1extra::L1EmParticleCollection > emColl,
00248                                                   const EmJobPSet &ejpset,
00249                                                   const edm::ESHandle<L1CaloGeometry> & l1CaloGeom,
00250                                                   std::vector<int> & FEDs){
00251   const   std::string category = "EcalRawToRecHit|Egamma";
00252   for( l1extra::L1EmParticleCollection::const_iterator emItr = emColl->begin();
00253        emItr != emColl->end() ;++emItr ){
00254     float pt = emItr -> pt();
00255     if (pt < ejpset.Ptmin ) continue;
00256     LogDebug(category)<<" Here is an L1 isoEM candidate of pt " << pt;
00257     // Access the GCT hardware object corresponding to the L1Extra EM object.
00258     int etaIndex = emItr->gctEmCand()->etaIndex() ;
00259     int phiIndex = emItr->gctEmCand()->phiIndex() ;
00260     // Use the L1CaloGeometry to find the eta, phi bin boundaries.
00261     double etaLow  = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
00262     double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
00263     double phiLow  = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
00264     double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
00265     
00266     ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, ejpset.regionEtaMargin, ejpset.regionPhiMargin,FEDs);
00267   }
00268 }
00269 
00270 void EcalRawToRecHitRoI::Egamma(edm::Event& e, const edm::EventSetup& es , std::vector<int> & FEDs) {
00271   const std::string category = "EcalRawToRecHit|Egamma";
00272   
00273   LogDebug(category)<< " enter in EcalRawToRecHitRoI::Egamma";
00274   
00275   // Get the CaloGeometry
00276   edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
00277   es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
00278 
00279   edm::Handle< l1extra::L1EmParticleCollection > emColl;
00280   uint ne=EmSource_.size();
00281   for (uint ie=0;ie!=ne;++ie){
00282     e.getByLabel(EmSource_[ie].Source,emColl);
00283     if (!emColl.isValid()){edm::LogError(category)<<"L1Em Collection: "<<EmSource_[ie].Source<<" is not valid.";continue;}
00284 
00285     Egamma_OneL1EmCollection(emColl,EmSource_[ie],l1CaloGeom,FEDs);
00286   }
00287 
00288   unique(FEDs);
00289   LogDebug(category)<<"end of get list of feds\n"<<dumpFEDs(FEDs);
00290   return;
00291 }
00292 
00293 
00294 void EcalRawToRecHitRoI::Muon(edm::Event& e, const edm::EventSetup& es, std::vector<int>& FEDs) {
00295   const std::string category = "EcalRawToRecHit|Muon";
00296 
00297   LogDebug(category)<< " enter in EcalRawToRecHitRoI::Muon";
00298 
00299   edm::Handle<L1MuonParticleCollection> muColl;
00300   e.getByLabel(MuonSource_.Source, muColl);
00301 
00302   for (L1MuonParticleCollection::const_iterator it=muColl->begin(); it != muColl->end(); it++) {
00303 
00304     const L1MuGMTExtendedCand muonCand = (*it).gmtMuonCand();
00305     double pt    =  (*it).pt();
00306     double eta   =  (*it).eta();
00307     double phi   =  (*it).phi();
00308 
00309     LogDebug(category)<<" here is a L1 muon Seed  with (eta,phi) = " 
00310                       <<eta << " " << phi << " and pt " << pt;
00311     if (pt < MuonSource_.Ptmin) continue;
00312 
00313     ListOfFEDS(eta, eta, phi-MuonSource_.epsilon, phi+MuonSource_.epsilon, MuonSource_.regionEtaMargin, MuonSource_.regionPhiMargin,FEDs);
00314   }
00315   
00316   unique(FEDs);
00317   LogDebug(category)<<"end of get list of feds\n"<<dumpFEDs(FEDs);
00318   
00319   return;
00320 }
00321  
00322 void EcalRawToRecHitRoI::Jet_OneL1JetCollection(const edm::Handle< l1extra::L1JetParticleCollection > jetColl,
00323                                                 const JetJobPSet & jjpset,
00324                                                 std::vector<int> & feds){
00325   const std::string category ="EcalRawToRecHit|Jet";
00326   for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
00327     double pt    =  it -> pt();
00328     double eta   =  it -> eta();
00329     double phi   =  it -> phi();
00330 
00331     LogDebug(category) << " here is a L1 CentralJet Seed  with (eta,phi) = "
00332                        << eta << " " << phi << " and pt " << pt;
00333 
00334     if (pt < jjpset.Ptmin ) continue;
00335 
00336     ListOfFEDS(eta, eta, phi-jjpset.epsilon, phi+jjpset.epsilon, jjpset.regionEtaMargin, jjpset.regionPhiMargin,feds);
00337   }
00338 }
00339 
00340 void EcalRawToRecHitRoI::Jet(edm::Event& e, const edm::EventSetup& es, std::vector<int> & FEDs) {
00341   const std::string category = "EcalRawToRecHit|Jet";
00342 
00343   edm::Handle<L1JetParticleCollection> jetColl;
00344   uint nj=JetSource_.size();
00345   for (uint ij=0;ij!=nj;++ij){
00346     e.getByLabel(JetSource_[ij].Source,jetColl);
00347     if (!jetColl.isValid()){edm::LogError(category)<<"L1Jet collection: "<<JetSource_[ij].Source<<" is not valid.";continue;}
00348 
00349     Jet_OneL1JetCollection(jetColl,JetSource_[ij],FEDs);
00350   }
00351 
00352   unique(FEDs);
00353   LogDebug(category)<<"unpack FED\n"<<dumpFEDs(FEDs);
00354 }
00355 
00356 
00357 
00358 
00359 void EcalRawToRecHitRoI::ListOfFEDS(double etaLow, double etaHigh, double phiLow, 
00360                                         double phiHigh, double etamargin, double phimargin,
00361                                         std::vector<int> & FEDs)
00362 {
00363   const std::string category = "EcalRawToRecHit|ListOfFEDS";
00364   
00365   if (phimargin > Geom::pi()) phimargin =  Geom::pi() ;
00366 
00367   
00368   LogDebug(category)<< " etaLow etaHigh phiLow phiHigh " << etaLow << " "
00369                     <<etaHigh << " " << phiLow << " " << phiHigh;
00370 
00371   
00372   etaLow -= etamargin;
00373   etaHigh += etamargin;
00374   double phiMinus = phiLow - phimargin;
00375   double phiPlus = phiHigh + phimargin;
00376   
00377   bool all = false;
00378   double dd = fabs(phiPlus-phiMinus);
00379   LogDebug(category)<< " dd = " << dd;
00380   if (dd > 2.*Geom::pi() ) all = true;
00381 
00382   while (phiPlus > Geom::pi()) { phiPlus -= 2.*Geom::pi() ; }
00383   while (phiMinus < 0) { phiMinus += 2.*Geom::pi() ; }
00384   if ( phiMinus > Geom::pi()) phiMinus -= 2.*Geom::pi() ;
00385 
00386   double dphi = phiPlus - phiMinus;
00387   if (dphi < 0) dphi += 2.*Geom::pi() ;
00388   LogDebug(category) << "dphi = " << dphi;
00389   if (dphi > Geom::pi()) {
00390     int fed_low1 = TheMapping -> GetFED(etaLow,phiMinus*180./Geom::pi());
00391     int fed_low2 = TheMapping -> GetFED(etaLow,phiPlus*180./Geom::pi());
00392     LogDebug(category) << "fed_low1 fed_low2 " << fed_low1 << " " << fed_low2;
00393     if (fed_low1 == fed_low2) all = true;
00394     int fed_hi1 = TheMapping -> GetFED(etaHigh,phiMinus*180./Geom::pi());
00395     int fed_hi2 = TheMapping -> GetFED(etaHigh,phiPlus*180./Geom::pi());
00396     LogDebug(category) << "fed_hi1 fed_hi2 " << fed_hi1 << " " << fed_hi2;
00397     if (fed_hi1 == fed_hi2) all = true;
00398   }
00399 
00400 
00401   if (all) {
00402     LogDebug(category)<< " unpack everything in phi ! ";
00403     phiMinus = -20 * Geom::pi() / 180.;  // -20 deg
00404     phiPlus = -40 * Geom::pi() / 180.;  // -20 deg
00405   }
00406   
00407   LogDebug(category) << " with margins : " << etaLow << " " << etaHigh << " "
00408                      << phiMinus << " " << phiPlus;
00409 
00410 
00411   const EcalEtaPhiRegion ecalregion(etaLow,etaHigh,phiMinus,phiPlus);
00412 
00413   TheMapping -> GetListofFEDs(ecalregion, FEDs);
00414   LogDebug(category)<<"unpack fed:\n"<<dumpFEDs(FEDs);
00415 
00416 }

Generated on Tue Jun 9 17:34:32 2009 for CMSSW by  doxygen 1.5.4