CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalRawToRecHitRoI.cc
Go to the documentation of this file.
1 
2 //#include <FWCore/Framework/interface/Handle.h>
3 
7 
8 // Ecal Mapping
9 //#include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
11 
12 
13 // Level 1 Trigger
16 
17 // EgammaCoreTools
18 //#include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
20 
21 // Muon stuff
25 
26 // Jets stuff
28 
29 //candidate stuff
32 
35 //#include "EventFilter/EcalRawToDigi/interface/MyWatcher.h"
37 
38 
39 using namespace l1extra;
40 
42  epsilon = cfg.getParameter<double>("epsilon");
43  bePrecise = cfg.getParameter<bool>("bePrecise");
44  if (bePrecise){ propagatorNameToBePrecise = cfg.getParameter<std::string>("propagatorNameToBePrecise");}
46  std::string type = cfg.getParameter<std::string>("cType");
47  if (type == "view"){cType=view;}
48  else if (type == "candidate"){cType=candidate;}
49  else if (type == "chargedcandidate"){cType=chargedcandidate;}
50  else if (type == "l1muon"){cType=l1muon;}
51  else if (type == "l1jet"){cType=l1jet;}
52  else {
53  edm::LogWarning("IncorrectConfiguration")<<"\n\n could not interpret the cType: "<<type
54  <<"\n using edm::View< reco::Candidate > by default. expect your trigger path to be slow !\n\n";
55  cType=view;}
56 }
57 
58 
61  const std::string category = "EcalRawToRecHit|RoI";
62 
63  sourceTag_=pset.getParameter<edm::InputTag>("sourceTag");
64 
65  std::string type = pset.getParameter<std::string>("type");
66 
67  if (type.find("candidate")!=std::string::npos){
68  LogDebug(category)<<"configured for candidate-versatile input.";
69  Candidate_ = true;
70  std::vector<edm::ParameterSet> emPSet = pset.getParameter<std::vector<edm::ParameterSet> >("CandJobPSet");
71  for (std::vector<edm::ParameterSet>::iterator iepset = emPSet.begin(); iepset!=emPSet.end();++iepset){
72  CandSource_.push_back(CandJobPSet(*iepset));
73  LogDebug(category)<<iepset->dump();
74  }
75  }
76 
77  if (type.find("muon")!=std::string::npos){
78  LogDebug(category)<<"configured for L1MuonParticleCollection input.";
79  Muon_ = true;
80  edm::ParameterSet ps = pset.getParameter<edm::ParameterSet>("MuJobPSet");
81  MuonSource_ = MuJobPSet(ps);
82  LogDebug(category)<<ps.dump();
83  }
84 
85  if (type.find("egamma")!=std::string::npos){
86  LogDebug(category)<<"configured for L1EMParticleCollection input.";
87  EGamma_ = true;
88  std::vector<edm::ParameterSet> emPSet = pset.getParameter<std::vector<edm::ParameterSet> >("EmJobPSet");
89  for (std::vector<edm::ParameterSet>::iterator iepset = emPSet.begin(); iepset!=emPSet.end();++iepset){
90  EmSource_.push_back(EmJobPSet(*iepset));
91  LogDebug(category)<<iepset->dump();
92  }
93  }
94 
95  if (type.find("jet")!=std::string::npos){
96  LogDebug(category)<<"configured for L1JetParticleCollection input.";
97  Jet_ =true;
98  std::vector<edm::ParameterSet> jetPSet = pset.getParameter<std::vector<edm::ParameterSet> >("JetJobPSet");
99  for (std::vector<edm::ParameterSet>::iterator ijpset = jetPSet.begin(); ijpset!=jetPSet.end();++ijpset){
100  JetSource_.push_back(JetJobPSet(*ijpset));
101  LogDebug(category)<<ijpset->dump();
102  }
103  }
104 
105  if (type.find("all")!=std::string::npos){
106  LogDebug(category)<<"configured for ALL feds unpacking";
107  All_ = true;
108  }
109 
110  if (!All_ && !Muon_ && !EGamma_ && !Jet_ && !Candidate_){
111  edm::LogError("IncorrectConfiguration")<<"I have no specified type of work."
112  <<"\nI will produce empty list of FEDs."
113  <<"\nI will produce an empty EcalRecHitRefGetter."
114  <<"\n I am sure you don't want that.";
115  //throw. this is a typo/omittion in a cfg.
116  }
117 
118  produces<EcalListOfFEDS>();
119  produces<EcalRecHitRefGetter>();
120 
121  if (pset.exists("doES"))
122  do_es_ = pset.getParameter<bool>("doES");
123  else
124  do_es_ = false;
125 
126  if (do_es_) {
127  LogDebug(category)<<"will also make the list of FEDs for the ES.";
128  sourceTag_es_=pset.getParameter<edm::InputTag>("sourceTag_es");
129  esinstance_=pset.getUntrackedParameter<std::string>("esInstance","es");
130  if (esinstance_=="")
131  edm::LogError("IncorrectConfiguration")<<" instance name for ES region and FED list cannot be empty. expect a fwk failure.";
132  produces<ESListOfFEDS>(esinstance_);
133  produces<EcalRecHitRefGetter>(esinstance_);
134  }
135 }
136 
137 
138 
140 }
141 
142 
143 
144 #include <sstream>
146  std::stringstream ss;
147  ss<<"unpack FED: ";
148  for (unsigned int i=0; i < FEDs.size(); i++) {
149  ss<< FEDs[i] << ((i!= FEDs.size()-1)? ", ":"\n");
150  }
151  ss<< "Number of FEDS is " << FEDs.size();
152  return ss.str();
153 }
154 
156  const std::string category = "EcalRawToRecHit|RoI";
157 // MyWatcher watcher("RoI");
158 // LogDebug(category)<<watcher.lap();
159 //std::cout<<watcher.lap() << std::endl;
160  // retreive cabling
162  iSetup.get<EcalRegionCablingRecord>().get(cabling);
163  LogDebug(category)<<"cabling retrieved.";
164 // <<watcher.lap();
165  TheMapping =cabling->mapping();
166  TheESMapping =cabling->es_mapping();
167 
168  std::auto_ptr<EcalListOfFEDS> productAddress(new EcalListOfFEDS);
169  std::vector<int> feds; // the list of FEDS produced by this module
170 
171  if (EGamma_) { Egamma(e, iSetup, feds); }
172 
173  if (Muon_) { Muon(e, iSetup, feds); }
174 
175  if (Jet_) { Jet(e, iSetup, feds); }
176 
177  if (Candidate_) { Cand(e, iSetup, feds); }
178 
179  if (All_) { for (int i=1; i <= 54; feds.push_back(i++)){} }
180 
181  unsigned int nf = feds.size();
182  for (unsigned int i=0; i <nf; feds[i++]+=FEDNumbering::MINECALFEDID) {}
183 
184  LogDebug(category)<< "Will unpack Ecal FED\n" <<dumpFEDs(feds) ;
185 // <<watcher.lap();
186 
187  // if (nf<1){edm::LogWarning(category)<<"no ECAL FED to unpack for Run " << e.id().run() << " Event " << e.id().event() ;}
188 
189  productAddress->SetList(feds);
190  e.put(productAddress);
191  LogDebug(category)<< "list of ECAL fed put in the event." ;
192 // <<watcher.lap();
193 
194 
195  //now defined the Region of interest to be unpacked. from the feds list
196 
197 
198  //get the lazy gettters
200  e.getByLabel(sourceTag_, lgetter);
201  if (lgetter.failedToGet())
202  {
203  edm::LogError("IncorrectConfiguration")<<" could not retrieve the lazy getter from: "<<sourceTag_;
204  return;
205  }
206 
207  LogDebug(category)<<"Ecal lazy getter retrieved from: "<<sourceTag_ ;
208 // <<watcher.lap();
209 
210 
211  //prepare a refgetter
212  std::auto_ptr<EcalRecHitRefGetter> rgetter(new EcalRecHitRefGetter);
213  LogDebug(category)<<"ECal ref getter ready to be updated." ;
214 // <<watcher.lap();
215 
216  for (unsigned int i=0;i!=nf;i++){
217  cabling->updateEcalRefGetterWithFedIndex(*rgetter, lgetter, feds[i]);
218  //cabling->updateEcalRefGetterWithElementIndex(*rgetter, lgetter, cabling->elementIndex(feds[i]));
219  }
220 
221  //put the refgetters in the event
222  LogDebug(category)<<"Ecal refGetter to be put in the event." ;
223 // << watcher.lap();
224  e.put(rgetter);
225  LogDebug(category)<<"Ecal refGetter loaded." ;
226 // << watcher.lap();
227 
228  //further process the ES if required
229  if (do_es_){
230  LogDebug(category)<< "Will make the ES list of FEDs at the same time." ;
231 // <<watcher.lap();
232  std::auto_ptr<ESListOfFEDS> productAddressES(new ESListOfFEDS);
233  std::vector<int> es_feds = TheESMapping->GetListofFEDs(feds);
234 
235  LogDebug(category)<< "Will unpack ES FED\n" <<dumpFEDs(es_feds) ;
236 // <<watcher.lap();
237 
238 
239  productAddressES->SetList(es_feds);
240  e.put(productAddressES,esinstance_);
241 
242 
243  LogDebug(category)<< "list of ES fed put in the event." ;
244 // <<watcher.lap();
245 
247  e.getByLabel(sourceTag_es_, lgetter_es);
248  if (lgetter_es.failedToGet())
249  {
250  edm::LogError("IncorrectConfiguration")<<" could not retrieve the lazy getter from: "<<sourceTag_es_;
251  return;
252  }
253 
254  LogDebug(category)<<"ES lazy getter retrieved from: "<<sourceTag_es_ ;
255 // <<watcher.lap();
256 
257  std::auto_ptr<EcalRecHitRefGetter> rgetter_es(new EcalRecHitRefGetter);
258  LogDebug(category)<<"ES ref getter ready to be updated." ;
259 // <<watcher.lap();
260 
261  unsigned int nf_es=es_feds.size();
262  for (unsigned int i=0;i!=nf_es;i++){
263  cabling->updateEcalRefGetterWithElementIndex(*rgetter_es, lgetter_es, cabling->esElementIndex(es_feds[i]));
264  }
265 
266  LogDebug(category)<<"ES refGetter to be put in the event." ;
267 // << watcher.lap();
268  e.put(rgetter_es,esinstance_);
269  LogDebug(category)<<"ES refGetter loaded." ;
270 // << watcher.lap();
271  }
272 
273 }
274 
275 void EcalRawToRecHitRoI::Cand(edm::Event& e, const edm::EventSetup& es , std::vector<int> & FEDs) {
276  const std::string category ="EcalRawToRecHit|Cand";
277 
278  unsigned int nc=CandSource_.size();
279  for (unsigned int ic=0;ic!=nc;++ic){
280  switch (CandSource_[ic].cType){
281  case CandJobPSet::view :
282  OneCandCollection< edm::View<reco::Candidate> >(e, es, CandSource_[ic], FEDs);
283  break;
284 
286  OneCandCollection<reco::CandidateCollection>(e, es, CandSource_[ic], FEDs);
287  break;
288 
290  OneCandCollection<reco::RecoChargedCandidateCollection>(e, es, CandSource_[ic], FEDs);
291  break;
292 
293  case CandJobPSet::l1muon :
294  OneCandCollection<L1MuonParticleCollection>(e, es, CandSource_[ic], FEDs);
295  break;
296 
297  case CandJobPSet::l1jet :
298  OneCandCollection<L1JetParticleCollection>(e, es, CandSource_[ic], FEDs);
299  break;
300 
301  default:
302  edm::LogError("IncorrectRecHit")<<"cType not recognised: "<<CandSource_[ic].cType;
303  }
304  }
305 
306  unique(FEDs);
307  LogDebug(category)<<"unpack FED\n"<<dumpFEDs(FEDs);
308 }
309 
311  const EmJobPSet &ejpset,
312  const edm::ESHandle<L1CaloGeometry> & l1CaloGeom,
313  std::vector<int> & FEDs){
314  const std::string category = "EcalRawToRecHit|Egamma";
315  for( l1extra::L1EmParticleCollection::const_iterator emItr = emColl->begin();
316  emItr != emColl->end() ;++emItr ){
317  float pt = emItr -> pt();
318  if (pt < ejpset.Ptmin ) continue;
319  LogDebug(category)<<" Here is an L1 isoEM candidate of pt " << pt;
320  // Access the GCT hardware object corresponding to the L1Extra EM object.
321  int etaIndex = emItr->gctEmCand()->etaIndex() ;
322  int phiIndex = emItr->gctEmCand()->phiIndex() ;
323  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
324  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
325  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
326  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
327  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
328 
329  ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, ejpset.regionEtaMargin, ejpset.regionPhiMargin,FEDs);
330  }
331 }
332 
333 void EcalRawToRecHitRoI::Egamma(edm::Event& e, const edm::EventSetup& es , std::vector<int> & FEDs) {
334  const std::string category = "EcalRawToRecHit|Egamma";
335 
336  LogDebug(category)<< " enter in EcalRawToRecHitRoI::Egamma";
337 
338  // Get the CaloGeometry
339  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
340  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
341 
343  unsigned int ne=EmSource_.size();
344  for (unsigned int ie=0;ie!=ne;++ie){
345  e.getByLabel(EmSource_[ie].Source,emColl);
346  if (!emColl.isValid()){edm::LogError("IncorrectConfiguration")<<"L1Em Collection: "<<EmSource_[ie].Source<<" is not valid.";continue;}
347 
348  Egamma_OneL1EmCollection(emColl,EmSource_[ie],l1CaloGeom,FEDs);
349  }
350 
351  unique(FEDs);
352  LogDebug(category)<<"end of get list of feds\n"<<dumpFEDs(FEDs);
353  return;
354 }
355 
356 
357 void EcalRawToRecHitRoI::Muon(edm::Event& e, const edm::EventSetup& es, std::vector<int>& FEDs) {
358  const std::string category = "EcalRawToRecHit|Muon";
359 
360  LogDebug(category)<< " enter in EcalRawToRecHitRoI::Muon";
361 
363  e.getByLabel(MuonSource_.Source, muColl);
364  if (muColl.failedToGet())
365  {
366  edm::LogError("IncorrectConfiguration")<<" could not retrieve the l1 muon collection from: "<<MuonSource_.Source;
367  return;
368  }
369 
370  for (L1MuonParticleCollection::const_iterator it=muColl->begin(); it != muColl->end(); it++) {
371 
372  const L1MuGMTExtendedCand muonCand = (*it).gmtMuonCand();
373  double pt = (*it).pt();
374  double eta = (*it).eta();
375  double phi = (*it).phi();
376 
377  LogDebug(category)<<" here is a L1 muon Seed with (eta,phi) = "
378  <<eta << " " << phi << " and pt " << pt;
379  if (pt < MuonSource_.Ptmin) continue;
380 
382  }
383 
384  unique(FEDs);
385  LogDebug(category)<<"end of get list of feds\n"<<dumpFEDs(FEDs);
386 
387  return;
388 }
389 
391  const JetJobPSet & jjpset,
392  std::vector<int> & feds){
393  const std::string category ="EcalRawToRecHit|Jet";
394  for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
395  double pt = it -> pt();
396  double eta = it -> eta();
397  double phi = it -> phi();
398 
399  LogDebug(category) << " here is a L1 CentralJet Seed with (eta,phi) = "
400  << eta << " " << phi << " and pt " << pt;
401 
402  if (pt < jjpset.Ptmin ) continue;
403 
404  ListOfFEDS(eta, eta, phi-jjpset.epsilon, phi+jjpset.epsilon, jjpset.regionEtaMargin, jjpset.regionPhiMargin,feds);
405  }
406 }
407 
408 void EcalRawToRecHitRoI::Jet(edm::Event& e, const edm::EventSetup& es, std::vector<int> & FEDs) {
409  const std::string category = "EcalRawToRecHit|Jet";
410 
412  unsigned int nj=JetSource_.size();
413  for (unsigned int ij=0;ij!=nj;++ij){
414  e.getByLabel(JetSource_[ij].Source,jetColl);
415  if (!jetColl.isValid()) {
416  edm::LogError("IncorrectConfiguration") << "L1Jet collection: " << JetSource_[ij].Source << " is not valid.";
417  continue;
418  }
419 
420  Jet_OneL1JetCollection(jetColl,JetSource_[ij],FEDs);
421  }
422 
423  unique(FEDs);
424  LogDebug(category)<<"unpack FED\n"<<dumpFEDs(FEDs);
425 }
426 
427 
428 
429 
430 void EcalRawToRecHitRoI::ListOfFEDS(double etaLow, double etaHigh, double phiLow,
431  double phiHigh, double etamargin, double phimargin,
432  std::vector<int> & FEDs)
433 {
434  const std::string category = "EcalRawToRecHit|ListOfFEDS";
435 
436  if (phimargin > Geom::pi()) phimargin = Geom::pi() ;
437 
438 
439  LogDebug(category)<< " etaLow etaHigh phiLow phiHigh " << etaLow << " "
440  <<etaHigh << " " << phiLow << " " << phiHigh;
441 
442 
443  etaLow -= etamargin;
444  etaHigh += etamargin;
445  double phiMinus = phiLow - phimargin;
446  double phiPlus = phiHigh + phimargin;
447 
448  bool all = false;
449  double dd = fabs(phiPlus-phiMinus);
450  LogDebug(category)<< " dd = " << dd;
451  if (dd > 2.*Geom::pi() ) all = true;
452 
453  while (phiPlus > Geom::pi()) { phiPlus -= 2.*Geom::pi() ; }
454  while (phiMinus < 0) { phiMinus += 2.*Geom::pi() ; }
455  if ( phiMinus > Geom::pi()) phiMinus -= 2.*Geom::pi() ;
456 
457  double dphi = phiPlus - phiMinus;
458  if (dphi < 0) dphi += 2.*Geom::pi() ;
459  LogDebug(category) << "dphi = " << dphi;
460  if (dphi > Geom::pi()) {
461  int fed_low1 = TheMapping -> GetFED(etaLow,phiMinus*180./Geom::pi());
462  int fed_low2 = TheMapping -> GetFED(etaLow,phiPlus*180./Geom::pi());
463  LogDebug(category) << "fed_low1 fed_low2 " << fed_low1 << " " << fed_low2;
464  if (fed_low1 == fed_low2) all = true;
465  int fed_hi1 = TheMapping -> GetFED(etaHigh,phiMinus*180./Geom::pi());
466  int fed_hi2 = TheMapping -> GetFED(etaHigh,phiPlus*180./Geom::pi());
467  LogDebug(category) << "fed_hi1 fed_hi2 " << fed_hi1 << " " << fed_hi2;
468  if (fed_hi1 == fed_hi2) all = true;
469  }
470 
471 
472  if (all) {
473  LogDebug(category)<< " unpack everything in phi ! ";
474  phiMinus = -20 * Geom::pi() / 180.; // -20 deg
475  phiPlus = -40 * Geom::pi() / 180.; // -20 deg
476  }
477 
478  LogDebug(category) << " with margins : " << etaLow << " " << etaHigh << " "
479  << phiMinus << " " << phiPlus;
480 
481 
482  const EcalEtaPhiRegion ecalregion(etaLow,etaHigh,phiMinus,phiPlus);
483 
484  TheMapping -> GetListofFEDs(ecalregion, FEDs);
485  LogDebug(category)<<"unpack fed:\n"<<dumpFEDs(FEDs);
486 
487 }
#define LogDebug(id)
bool Candidate_
Candidate-versatile objects part flag.
type
Definition: HCALResponse.h:21
void Cand(edm::Event &e, const edm::EventSetup &es, std::vector< int > &FEDs)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
class to drive the job on L1Jet
std::string dump(unsigned int indent=0) const
void unique(std::vector< int > &FEDs)
remove duplicates
MuJobPSet MuonSource_
what drives the job from ONE L1Muon collection
const ESElectronicsMapper * TheESMapping
class to drive the job on Candidate-inheriting object
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool Muon_
Muon part flag.
std::vector< JetJobPSet > JetSource_
what drive the job on L1Jet collection
std::string dumpFEDs(const std::vector< int > &FEDs)
T eta() const
void Jet(edm::Event &e, const edm::EventSetup &es, std::vector< int > &FEDs)
std::vector< EmJobPSet > EmSource_
what drive the job on L1Em collection
void Muon(edm::Event &e, const edm::EventSetup &es, std::vector< int > &FEDs)
const EcalElectronicsMapping * TheMapping
tools
generic class to drive the job
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
edm::InputTag sourceTag_es_
std::vector< CandJobPSet > CandSource_
what drives the job from candidate
class to drive the job on L1Em
void ListOfFEDS(double etaLow, double etaHigh, double phiLow, double phiHigh, double etamargin, double phimargin, std::vector< int > &FEDs)
actually fill the vector with FED numbers
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
void Egamma_OneL1EmCollection(const edm::Handle< l1extra::L1EmParticleCollection > emColl, const EmJobPSet &ejpset, const edm::ESHandle< L1CaloGeometry > &l1CaloGeom, std::vector< int > &FEDs)
process one collection of L1Em
bool failedToGet() const
Definition: HandleBase.h:80
class to drive the job on L1Muon
edm::InputTag sourceTag_
input tag for the lazy getter
const T & get() const
Definition: EventSetup.h:55
void produce(edm::Event &e, const edm::EventSetup &c)
double pi()
Definition: Pi.h:31
bool All_
if all need to be done
volatile std::atomic< bool > shutdown_flag false
void Egamma(edm::Event &e, const edm::EventSetup &es, std::vector< int > &FEDs)
bool EGamma_
Egamma part flag.
bool Jet_
jet part flag
CandJobPSet(edm::ParameterSet &cfg)
std::vector< int > GetListofFEDs(const std::vector< int > &eeFEDs) const
EcalRawToRecHitRoI(const edm::ParameterSet &pset)
void Jet_OneL1JetCollection(const edm::Handle< l1extra::L1JetParticleCollection > jetColl, const JetJobPSet &jjpset, std::vector< int > &feds)
process on collection of L1Jets
Definition: DDAxes.h:10