25 using namespace l1extra;
37 if (EGamma_ && Muon_) {
39 " Wrong configuration : EGamma and Muon should not be true at the same time." ;
79 consumesMany<EcalListOfFEDS>();
80 produces<EcalListOfFEDS>(OutputLabel_);
90 desc.
add<
bool>(
"debug",
false);
92 desc.
add<
bool>(
"EGamma",
false);
93 desc.
add<
bool>(
"Muon",
false);
94 desc.
add<
bool>(
"Jets",
false);
97 desc.
add<
bool>(
"EM_doIsolated",
true);
98 desc.
add<
bool>(
"EM_doNonIsolated",
true);
99 desc.
add<
double>(
"EM_regionEtaMargin",0.25);
100 desc.
add<
double>(
"EM_regionPhiMargin",0.40);
101 desc.
add<
double>(
"Ptmin_iso",0.);
102 desc.
add<
double>(
"Ptmin_noniso",0.);
103 desc.
add<
double>(
"MU_regionEtaMargin",1.0);
104 desc.
add<
double>(
"MU_regionPhiMargin",1.0);
105 desc.
add<
double>(
"Ptmin_muon",0.);
107 desc.
add<
double>(
"JETS_regionEtaMargin",1.0);
108 desc.
add<
double>(
"JETS_regionPhiMargin",1.0);
109 desc.
add<
double>(
"Ptmin_jets",0.);
113 desc.
add<
bool>(
"JETS_doCentral",
true);
114 desc.
add<
bool>(
"JETS_doForward",
true);
115 desc.
add<
bool>(
"JETS_doTau",
true);
117 descriptions.
add((
"hltEcalListOfFEDSProducer"), desc);
132 *TheMapping = *TheMapping_;
136 auto productAddress = std::make_unique<EcalListOfFEDS>();
138 std::vector<int>
feds;
143 std::vector< edm::Handle<EcalListOfFEDS> > FEDs_Done;
144 std::vector<int> Done;
146 unsigned int nDone = FEDs_Done.size();
147 if (debug_)
std::cout <<
" ECAL unpacking module has already run " << nDone <<
" times. " << std::endl;
148 for (
unsigned int id=0;
id < nDone;
id++) {
150 if( Pi0ListToIgnore_.label() == FEDs_Done[id].provenance()->moduleLabel() ){
continue;}
151 std::vector<int>
done = FEDs_Done[id]-> GetList();
152 for (
int jd=0; jd < (int)done.size(); jd++) {
156 if (debug_)
std::cout <<
" For this event, " << Done.size() <<
" ECAL FEDs have already been unpacked." << std::endl;
161 Egamma(e, iSetup, Done, feds);
166 Muon(e, iSetup, Done, feds);
171 Jets(e, iSetup, Done, feds);
174 if ( !EGamma_ && !Muon_ && ! Jets_) {
175 for (
int i=1;
i <= 54;
i++) {
176 if (
std::find(Done.begin(), Done.end(),
i) == Done.end())
181 int nf = (int)feds.size();
182 for (
int i=0;
i <nf;
i++) {
184 if (debug_)
std::cout <<
"Will unpack FED " << feds[
i] << std::endl;
187 if (debug_ && nf < 1 )
188 std::cout <<
" Warning : no ECAL FED to unpack for Run " << e.
id().
run() <<
" Event " << e.
id().
event() << std::endl;
190 productAddress.get() -> SetList(feds);
198 if (debug_)
std::cout << std::endl << std::endl <<
" enter in EcalListOfFEDSProducer::Egamma" << std::endl;
207 if (EMdoNonIsolated_)
208 e.
getByToken(EMl1TagNonIsolated_, emNonIsolColl);
216 for( l1extra::L1EmParticleCollection::const_iterator emItr = emIsolColl->begin();
217 emItr != emIsolColl->end() ;++emItr ){
219 float pt = emItr ->
pt();
220 if (pt < Ptmin_iso_ )
continue;
221 if (debug_)
std::cout <<
" Here is an L1 isoEM candidate of pt " << pt << std::endl;
223 int etaIndex = emItr->gctEmCand()->etaIndex() ;
224 int phiIndex = emItr->gctEmCand()->phiIndex() ;
226 double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
227 double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
228 double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
229 double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
231 std::vector<int>
feds = ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, EMregionEtaMargin_, EMregionPhiMargin_);
232 for (
int i=0;
i < (int)feds.size();
i++) {
233 if (
std::find(FEDs.begin(), FEDs.end(), feds[
i]) == FEDs.end() &&
234 std::find(done.begin(), done.end(), feds[
i]) == done.end() ) FEDs.push_back(feds[
i]);
239 if (EMdoNonIsolated_) {
241 for( l1extra::L1EmParticleCollection::const_iterator emItr = emNonIsolColl->begin();
242 emItr != emNonIsolColl->end() ;++emItr ){
244 float pt = emItr ->
pt();
245 if (debug_)
std::cout <<
" Here is an L1 nonisoEM candidate of pt " << pt << std::endl;
246 if (pt < Ptmin_noniso_ )
continue;
248 int etaIndex = emItr->gctEmCand()->etaIndex() ;
249 int phiIndex = emItr->gctEmCand()->phiIndex() ;
252 double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
253 double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
254 double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
255 double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
257 std::vector<int>
feds = ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, EMregionEtaMargin_, EMregionPhiMargin_);
258 for (
int i=0;
i < (int)feds.size();
i++) {
259 if (
std::find(FEDs.begin(), FEDs.end(), feds[
i]) == FEDs.end() &&
260 std::find(done.begin(), done.end(), feds[
i]) == done.end() ) FEDs.push_back(feds[
i]);
271 for (
int i=0;
i < (int)FEDs.size();
i++) {
272 std::cout <<
"Egamma: unpack FED " << FEDs[
i] << std::endl;
274 std::cout <<
"Number of FEDS is " << FEDs.size() << std::endl;
285 if (debug_)
std::cout << std::endl << std::endl <<
" enter in EcalListOfFEDSProducer::Muon" << std::endl;
292 for (L1MuonParticleCollection::const_iterator it=muColl->begin(); it != muColl->end(); it++) {
294 double pt = (*it).pt();
295 double eta = (*it).eta();
296 double phi = (*it).phi();
298 if (debug_)
std::cout <<
" here is a L1 muon Seed with (eta,phi) = " <<
299 eta <<
" " << phi <<
" and pt " << pt << std::endl;
300 if (pt < Ptmin_muon_ )
continue;
302 std::vector<int>
feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, MUregionEtaMargin_, MUregionPhiMargin_);
304 for (
int i=0;
i < (int)feds.size();
i++) {
305 if (
std::find(FEDs.begin(), FEDs.end(), feds[
i]) == FEDs.end() &&
306 std::find(done.begin(), done.end(), feds[
i]) == done.end() ) FEDs.push_back(feds[
i]);
312 for (
int i=0;
i < (int)FEDs.size();
i++) {
313 std::cout <<
"Muons: unpack FED " << FEDs[
i] << std::endl;
315 std::cout <<
"Number of FEDS is " << FEDs.size() << std::endl;
326 if (debug_)
std::cout << std::endl << std::endl <<
" enter in EcalListOfFEDSProducer::Jets" << std::endl;
329 if (JETSdoCentral_) {
333 for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
335 double pt = it ->
pt();
337 double phi = it -> phi();
339 if (debug_)
std::cout <<
" here is a L1 CentralJet Seed with (eta,phi) = " <<
340 eta <<
" " << phi <<
" and pt " << pt << std::endl;
342 if (pt < Ptmin_jets_ )
continue;
344 std::vector<int>
feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
346 for (
int i=0;
i < (int)feds.size();
i++) {
347 if (
std::find(FEDs.begin(), FEDs.end(), feds[
i]) == FEDs.end() &&
348 std::find(done.begin(), done.end(), feds[
i]) == done.end() ) FEDs.push_back(feds[
i]);
353 if (JETSdoForward_) {
357 for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
359 double pt = it ->
pt();
361 double phi = it -> phi();
363 if (debug_)
std::cout <<
" here is a L1 ForwardJet Seed with (eta,phi) = " <<
364 eta <<
" " << phi <<
" and pt " << pt << std::endl;
365 if (pt < Ptmin_jets_ )
continue;
367 std::vector<int>
feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
369 for (
int i=0;
i < (int)feds.size();
i++) {
370 if (
std::find(FEDs.begin(), FEDs.end(), feds[
i]) == FEDs.end() &&
371 std::find(done.begin(), done.end(), feds[
i]) == done.end() ) FEDs.push_back(feds[
i]);
380 for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
382 double pt = it ->
pt();
384 double phi = it -> phi();
386 if (debug_)
std::cout <<
" here is a L1 TauJet Seed with (eta,phi) = " <<
387 eta <<
" " << phi <<
" and pt " << pt << std::endl;
388 if (pt < Ptmin_jets_ )
continue;
390 std::vector<int>
feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
392 for (
int i=0;
i < (int)feds.size();
i++) {
393 if (
std::find(FEDs.begin(), FEDs.end(), feds[
i]) == FEDs.end() &&
394 std::find(done.begin(), done.end(), feds[
i]) == done.end() ) FEDs.push_back(feds[
i]);
403 for (
int i=0;
i < (int)FEDs.size();
i++) {
404 std::cout <<
"Jets: unpack FED " << FEDs[
i] << std::endl;
406 std::cout <<
"Number of FEDS is " << FEDs.size() << std::endl;
413 double phiHigh,
double etamargin,
double phimargin) {
415 std::vector<int>
FEDs;
420 if (debug_)
std::cout <<
" etaLow etaHigh phiLow phiHigh " << etaLow <<
" " <<
421 etaHigh <<
" " << phiLow <<
" " << phiHigh << std::endl;
424 etaHigh += etamargin;
425 double phiMinus = phiLow - phimargin;
426 double phiPlus = phiHigh + phimargin;
429 double dd = fabs(phiPlus-phiMinus);
430 if (debug_)
std::cout <<
" dd = " << dd << std::endl;
431 if (dd > 2.*
Geom::pi() ) all =
true;
434 while (phiMinus < 0) { phiMinus += 2.*
Geom::pi() ; }
437 double dphi = phiPlus - phiMinus;
438 if (dphi < 0) dphi += 2.*
Geom::pi() ;
439 if (debug_)
std::cout <<
"dphi = " << dphi << std::endl;
441 int fed_low1 = TheMapping -> GetFED(etaLow,phiMinus*180./
Geom::pi());
442 int fed_low2 = TheMapping -> GetFED(etaLow,phiPlus*180./
Geom::pi());
443 if (debug_)
std::cout <<
"fed_low1 fed_low2 " << fed_low1 <<
" " << fed_low2 << std::endl;
444 if (fed_low1 == fed_low2) all =
true;
445 int fed_hi1 = TheMapping -> GetFED(etaHigh,phiMinus*180./
Geom::pi());
446 int fed_hi2 = TheMapping -> GetFED(etaHigh,phiPlus*180./
Geom::pi());
447 if (debug_)
std::cout <<
"fed_hi1 fed_hi2 " << fed_hi1 <<
" " << fed_hi2 << std::endl;
448 if (fed_hi1 == fed_hi2) all =
true;
453 if (debug_)
std::cout <<
" unpack everything in phi ! " << std::endl;
458 if (debug_)
std::cout <<
" with margins : " << etaLow <<
" " << etaHigh <<
" " <<
459 phiMinus <<
" " << phiPlus << std::endl;
464 FEDs = TheMapping -> GetListofFEDs(ecalregion);
void getManyByType(std::vector< Handle< PROD > > &results) const
T getParameter(std::string const &) const
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
void Muon(edm::Event &e, const edm::EventSetup &es, std::vector< int > &done, std::vector< int > &FEDs)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void endJob(void) override
void Egamma(edm::Event &e, const edm::EventSetup &es, std::vector< int > &done, std::vector< int > &FEDs)
void beginJob(void) override
void produce(edm::Event &e, const edm::EventSetup &c) override
virtual ~EcalListOfFEDSProducer()
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void Jets(edm::Event &e, const edm::EventSetup &es, std::vector< int > &done, std::vector< int > &FEDs)
EcalListOfFEDSProducer(const edm::ParameterSet &pset)
T const * product() const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< int > ListOfFEDS(double etaLow, double etaHigh, double phiLow, double phiHigh, double etamargin, double phimargin)
Geom::Phi< T > phi() const