36 int JetIDHelper::sanity_checks_left_ = 100;
65 approximatefHPD_ = -1.0;
66 approximatefRBX_ = -1.0;
68 fEB_ = fEE_ = fHB_ = fHE_ = fHO_ = fLong_ = fShort_ = -1.0;
69 fLS_ = fHFOOT_ = -1.0;
81 )->
setComment(
"If using RecHits to calculate the precise jet ID variables that need them, "
82 "their sources need to be specified");
101 if( E_Had + E_EM > 0 ) restrictedEMF_ = E_EM / ( E_EM + E_Had );
102 if( iDbg > 1 )
cout<<
"jet pT: "<<jet.
pt()<<
", eT: "<<jet.
et()<<
", E: "
103 <<jet.
energy()<<
" rEMF: "<<restrictedEMF_<<endl;
108 vector<subtower> subtowers, Ecal_subtowers, Hcal_subtowers, HO_subtowers;
109 vector<double> HPD_energies, RBX_energies;
111 classifyJetTowers( event, jet,
112 subtowers, Ecal_subtowers, Hcal_subtowers, HO_subtowers,
113 HPD_energies, RBX_energies, iDbg );
116 for (
unsigned int i=0;
i<subtowers.size(); ++
i)
cout<<
" "<<subtowers[
i].E<<
","<<subtowers[
i].Nhit;
118 for (
unsigned int i=0;
i<Ecal_subtowers.size(); ++
i)
cout<<
" "<<Ecal_subtowers[
i].E<<
","<<Ecal_subtowers[
i].Nhit;
120 for (
unsigned int i=0;
i<Hcal_subtowers.size(); ++
i)
cout<<
" "<<Hcal_subtowers[
i].E<<
","<<Hcal_subtowers[
i].Nhit;
122 for (
unsigned int i=0;
i<HO_subtowers.size(); ++
i)
cout<<
" "<<HO_subtowers[
i].E<<
","<<HO_subtowers[
i].Nhit;
124 for (
unsigned int i=0;
i<HPD_energies.size(); ++
i)
cout<<
" "<<HPD_energies[
i];
126 for (
unsigned int i=0;
i<RBX_energies.size(); ++
i)
cout<<
" "<<RBX_energies[
i];
131 hitsInN90_ = hitsInNCarrying( 0.9, subtowers );
132 nHCALTowers_ = Hcal_subtowers.size();
133 vector<subtower>::const_iterator it;
134 it = find_if( Ecal_subtowers.begin(), Ecal_subtowers.end(),
hasNonPositiveE );
135 nECALTowers_ = it - Ecal_subtowers.begin();
139 if( HPD_energies.size() > 0 ) approximatefHPD_ = HPD_energies.at( 0 ) / jet.
energy();
140 if( RBX_energies.size() > 0 ) approximatefRBX_ = RBX_energies.at( 0 ) / jet.
energy();
147 vector<double> energies, subdet_energies, Ecal_energies, Hcal_energies, HO_energies;
148 double LS_bad_energy, HF_OOT_energy;
149 classifyJetComponents( event, jet,
150 energies, subdet_energies, Ecal_energies, Hcal_energies, HO_energies,
151 HPD_energies, RBX_energies, LS_bad_energy, HF_OOT_energy, iDbg );
154 n90Hits_ = nCarrying( 0.9, energies );
158 if( HPD_energies.size() > 0 ) fHPD_ = HPD_energies.at( 0 ) / jet.
energy();
159 if( RBX_energies.size() > 0 ) fRBX_ = RBX_energies.at( 0 ) / jet.
energy();
160 if( subdet_energies.size() > 0 ) fSubDetector1_ = subdet_energies.at( 0 ) / jet.
energy();
161 if( subdet_energies.size() > 1 ) fSubDetector2_ = subdet_energies.at( 1 ) / jet.
energy();
162 if( subdet_energies.size() > 2 ) fSubDetector3_ = subdet_energies.at( 2 ) / jet.
energy();
163 if( subdet_energies.size() > 3 ) fSubDetector4_ = subdet_energies.at( 3 ) / jet.
energy();
164 fLS_ = LS_bad_energy / jet.
energy();
165 fHFOOT_ = HF_OOT_energy / jet.
energy();
167 if( sanity_checks_left_ > 0 ) {
168 --sanity_checks_left_;
169 double EH_sum = accumulate( Ecal_energies.begin(), Ecal_energies.end(), 0. );
170 EH_sum = accumulate( Hcal_energies.begin(), Hcal_energies.end(), EH_sum );
171 double EHO_sum = accumulate( HO_energies.begin(), HO_energies.end(), EH_sum );
174 <<
") does not match the total energy in the recHits ("<<EHO_sum
175 <<
", or without HO: "<<EH_sum<<
") . Are these the right recHits? "
176 <<
"Were jet energy corrections mistakenly applied before jet ID? A bug?";
177 if( iDbg > 1 )
cout<<
"Sanity check - E: "<<jet.
energy()<<
" =? EH_sum: "<<EH_sum<<
" / EHO_sum: "<<EHO_sum<<endl;
182 cout<<
"DBG - fHPD: "<<fHPD_<<
", fRBX: "<<fRBX_<<
", nh90: "<<n90Hits_<<
", fLS: "<<fLS_<<
", fHFOOT: "<<fHFOOT_<<endl;
183 cout<<
" -~fHPD: "<<approximatefHPD_<<
", ~fRBX: "<<approximatefRBX_
184 <<
", hits in n90: "<<hitsInN90_<<endl;
185 cout<<
" - nHCALTowers: "<<nHCALTowers_<<
", nECALTowers: "<<nECALTowers_
186 <<
"; subdet fractions: "<<fSubDetector1_<<
", "<<fSubDetector2_<<
", "<<fSubDetector3_<<
", "<<fSubDetector4_<<endl;
195 for(
unsigned int i = 0;
i < descending_energies.size(); ++
i ) totalE += descending_energies[
i ];
198 unsigned int NC = descending_energies.size();
201 for(
unsigned int i = descending_energies.size();
i > 0; --
i ) {
202 runningE += descending_energies[
i-1 ];
203 if (runningE < ( 1-fraction ) * totalE) NC =
i-1;
212 for(
unsigned int i = 0;
i < descending_towers.size(); ++
i ) totalE += descending_towers[
i ].E;
218 for(
unsigned int i = descending_towers.size();
i > 0; --
i ) {
219 runningE += descending_towers[
i-1 ].E;
220 if (runningE >= ( 1-fraction ) * totalE) NH += descending_towers[
i-1 ].Nhit;
226 vector< double > &energies,
227 vector< double > &subdet_energies,
228 vector< double > &Ecal_energies,
229 vector< double > &Hcal_energies,
230 vector< double > &HO_energies,
231 vector< double > &HPD_energies,
232 vector< double > &RBX_energies,
233 double& LS_bad_energy,
double& HF_OOT_energy,
const int iDbg )
235 energies.clear(); subdet_energies.clear(); Ecal_energies.clear(); Hcal_energies.clear(); HO_energies.clear();
236 HPD_energies.clear(); RBX_energies.clear();
237 LS_bad_energy = HF_OOT_energy = 0.;
239 std::map< int, double > HPD_energy_map, RBX_energy_map;
240 vector< double > EB_energies, EE_energies, HB_energies, HE_energies, short_energies, long_energies;
247 event.getByLabel( hbheRecHitsColl_, HBHERecHits );
248 event.getByLabel( hoRecHitsColl_, HORecHits );
249 event.getByLabel( hfRecHitsColl_, HFRecHits );
250 event.getByLabel( ebRecHitsColl_, EBRecHits );
251 event.getByLabel( eeRecHitsColl_, EERecHits );
252 if( iDbg > 2 )
cout<<
"# of rechits found - HBHE: "<<HBHERecHits->size()
253 <<
", HO: "<<HORecHits->size()<<
", HF: "<<HFRecHits->size()
254 <<
", EB: "<<EBRecHits->size()<<
", EE: "<<EERecHits->size()<<endl;
257 int nTowers = towers.size();
258 if( iDbg > 9 )
cout<<
"In classifyJetComponents. # of towers found: "<<nTowers<<endl;
260 for(
int iTower = 0; iTower <nTowers ; iTower++ ) {
264 int nCells = tower->constituentsSize();
265 if( iDbg )
cout<<
"tower #"<<iTower<<
" has "<<nCells<<
" cells. "
266 <<
"It's at iEta: "<<tower->ieta()<<
", iPhi: "<<tower->iphi()<<endl;
268 const vector< DetId >& cellIDs = tower->constituents();
270 for(
int iCell = 0; iCell < nCells; ++iCell ) {
278 if (theRecHit == HORecHits->end()) {
279 edm::LogWarning(
"UnexpectedEventContents")<<
"Can't find the HO recHit with ID: "<<HcalID;
282 hitE = theRecHit->energy();
283 HO_energies.push_back( hitE );
288 if( theRecHit == HFRecHits->end() ) {
289 edm::LogWarning(
"UnexpectedEventContents")<<
"Can't find the HF recHit with ID: "<<HcalID;
292 hitE = theRecHit->energy();
294 <<
"hit #"<<iCell<<
" is HF , E: "<<hitE<<
" iEta: "<<theRecHit->id().ieta()
295 <<
", depth: "<<theRecHit->id().depth()<<
", iPhi: "
296 <<theRecHit->id().iphi();
298 if( HcalID.
depth() == 1 )
299 long_energies.push_back( hitE );
301 short_energies.push_back( hitE );
303 uint32_t
flags = theRecHit->flags();
310 if( iDbg>4 && flags )
cout<<
"flags: "<<flags
311 <<
" -> LS_bad_energy: "<<LS_bad_energy<<
", HF_OOT_energy: "<<HF_OOT_energy<<endl;
316 if( theRecHit == HBHERecHits->end() ) {
317 edm::LogWarning(
"UnexpectedEventContents")<<
"Can't find the HBHE recHit with ID: "<<HcalID;
320 hitE = theRecHit->energy();
321 int iEta = theRecHit->id().
ieta();
322 int depth = theRecHit->id().depth();
323 Region region = HBHE_region( iEta, depth );
324 int hitIPhi = theRecHit->id().iphi();
325 if( iDbg>3 )
cout<<
"hit #"<<iCell<<
" is HBHE, E: "<<hitE<<
" iEta: "<<iEta
326 <<
", depth: "<<depth<<
", iPhi: "<<theRecHit->id().iphi()
328 int absIEta = TMath::Abs( theRecHit->id().ieta() );
329 if( depth == 3 && (absIEta == 28 || absIEta == 29) ) {
332 int iHPD = 100 * region;
333 int iRBX = 100 * region + ((hitIPhi + 1) % 72) / 4;
336 if( (0x1 & hitIPhi) == 0 ) {
337 edm::LogError(
"CodeAssumptionsViolated")<<
"Bug?! Jet ID code assumes no even iPhi recHits at HE edges";
340 bool oddnessIEta = HBHE_oddness( iEta, depth );
341 bool upperIPhi = (( hitIPhi%4 ) == 1 || ( hitIPhi%4 ) == 2);
345 if( upperIPhi != oddnessIEta ) ++hitIPhi;
351 HPD_energy_map[ iHPD ] += hitE;
352 RBX_energy_map[ iRBX ] += hitE;
353 if( iDbg > 5 )
cout<<
" --> H["<<iHPD<<
"]="<<HPD_energy_map[iHPD]
354 <<
", R["<<iRBX<<
"]="<<RBX_energy_map[iRBX];
355 if( iDbg > 1 )
cout<<endl;
357 if( region == HBneg || region == HBpos )
358 HB_energies.push_back( hitE );
360 HE_energies.push_back( hitE );
363 if( hitE == 0 )
edm::LogWarning(
"UnexpectedEventContents")<<
"HCal hitE==0? (or unknown subdetector?)";
369 int EcalNum = cellIDs[iCell].subdetId();
372 EBDetId EcalID = cellIDs[iCell];
374 if( theRecHit == EBRecHits->end() ) {
edm::LogWarning(
"UnexpectedEventContents")
375 <<
"Can't find the EB recHit with ID: "<<EcalID;
continue;}
376 hitE = theRecHit->energy();
377 EB_energies.push_back( hitE );
378 }
else if( EcalNum == 2 ){
379 EEDetId EcalID = cellIDs[iCell];
381 if( theRecHit == EERecHits->end() ) {
edm::LogWarning(
"UnexpectedEventContents")
382 <<
"Can't find the EE recHit with ID: "<<EcalID;
continue;}
383 hitE = theRecHit->energy();
384 EE_energies.push_back( hitE );
386 if( hitE == 0 )
edm::LogWarning(
"UnexpectedEventContents")<<
"ECal hitE==0? (or unknown subdetector?)";
387 if( iDbg > 6 )
cout<<
"EcalNum: "<<EcalNum<<
" hitE: "<<hitE<<endl;
401 Hcal_energies.insert( Hcal_energies.end(), HB_energies.begin(), HB_energies.end() );
402 Hcal_energies.insert( Hcal_energies.end(), HE_energies.begin(), HE_energies.end() );
403 Hcal_energies.insert( Hcal_energies.end(), short_energies.begin(), short_energies.end() );
404 Hcal_energies.insert( Hcal_energies.end(), long_energies.begin(), long_energies.end() );
405 Ecal_energies.insert( Ecal_energies.end(), EB_energies.begin(), EB_energies.end() );
406 Ecal_energies.insert( Ecal_energies.end(), EE_energies.begin(), EE_energies.end() );
409 std::sort( Hcal_energies.begin(), Hcal_energies.end(), greater<double>() );
410 std::sort( Ecal_energies.begin(), Ecal_energies.end(), greater<double>() );
414 std::inserter (HPD_energies, HPD_energies.end()),
select2nd );
416 std::sort( HPD_energies.begin(), HPD_energies.end(), greater<double>() );
418 std::inserter (RBX_energies, RBX_energies.end()),
select2nd );
420 std::sort( RBX_energies.begin(), RBX_energies.end(), greater<double>() );
422 energies.insert( energies.end(), Hcal_energies.begin(), Hcal_energies.end() );
423 energies.insert( energies.end(), Ecal_energies.begin(), Ecal_energies.end() );
424 energies.insert( energies.end(), HO_energies.begin(), HO_energies.end() );
425 std::sort( energies.begin(), energies.end(), greater<double>() );
428 fEB_ = std::accumulate( EB_energies.begin(), EB_energies.end(), 0. );
429 fEE_ = std::accumulate( EE_energies.begin(), EE_energies.end(), 0. );
430 fHB_ = std::accumulate( HB_energies.begin(), HB_energies.end(), 0. );
431 fHE_ = std::accumulate( HE_energies.begin(), HE_energies.end(), 0. );
432 fHO_ = std::accumulate( HO_energies.begin(), HO_energies.end(), 0. );
433 fShort_ = std::accumulate( short_energies.begin(), short_energies.end(), 0. );
434 fLong_ = std::accumulate( long_energies.begin(), long_energies.end(), 0. );
435 subdet_energies.push_back( fEB_ );
436 subdet_energies.push_back( fEE_ );
437 subdet_energies.push_back( fHB_ );
438 subdet_energies.push_back( fHE_ );
439 subdet_energies.push_back( fHO_ );
440 subdet_energies.push_back( fShort_ );
441 subdet_energies.push_back( fLong_ );
442 std::sort( subdet_energies.begin(), subdet_energies.end(), greater<double>() );
452 if( fEB_ > 0 || fEE_ > 0 || fHB_ > 0 || fHE_ > 0 || fHO_ > 0 || fShort_ > 0 || fLong_ > 0 )
453 edm::LogError(
"UnexpectedEventContents")<<
"Jet ID Helper found energy in subdetectors and jet E <= 0";
458 vector< subtower > &subtowers,
459 vector< subtower > &Ecal_subtowers,
460 vector< subtower > &Hcal_subtowers,
461 vector< subtower > &HO_subtowers,
462 vector< double > &HPD_energies,
463 vector< double > &RBX_energies,
466 subtowers.clear(); Ecal_subtowers.clear(); Hcal_subtowers.clear(); HO_subtowers.clear();
467 HPD_energies.clear(); RBX_energies.clear();
469 std::map< int, double > HPD_energy_map, RBX_energy_map;
472 int nTowers = towers.size();
473 if( iDbg > 9 )
cout<<
"classifyJetTowers started. # of towers found: "<<nTowers<<endl;
475 for(
int iTower = 0; iTower <nTowers ; iTower++ ) {
479 int nEM = 0, nHad = 0, nHO = 0;
480 const vector< DetId >& cellIDs = tower->constituents();
481 int nCells = cellIDs.size();
482 if( iDbg )
cout<<
"tower #"<<iTower<<
" has "<<nCells<<
" cells. "
483 <<
"It's at iEta: "<<tower->ieta()<<
", iPhi: "<<tower->iphi()<<endl;
485 for(
int iCell = 0; iCell < nCells; ++iCell ) {
500 double E_em = tower->emEnergy();
501 if( E_em != 0 ) Ecal_subtowers.push_back(
subtower( E_em, nEM ) );
503 double E_HO = tower->outerEnergy();
504 if( E_HO != 0 ) HO_subtowers.push_back(
subtower( E_HO, nHO ) );
506 double E_had = tower->hadEnergy();
508 Hcal_subtowers.push_back(
subtower( E_had, nHad ) );
511 int iEta = tower->ieta();
512 Region reg = region( iEta );
513 int iPhi = tower->iphi();
514 if( iDbg>3 )
cout<<
"tower has E_had: "<<E_had<<
" iEta: "<<iEta
515 <<
", iPhi: "<<iPhi<<
" -> "<<reg;
517 if( reg == HEneg || reg == HBneg || reg == HBpos || reg == HEpos ) {
518 int oddnessIEta = HBHE_oddness( iEta );
519 if( oddnessIEta < 0 )
break;
521 int iHPD = 100 * reg;
522 int iRBX = 100 * reg + ((iPhi + 1) % 72) / 4;
524 if(( reg == HEneg || reg == HEpos ) &&
std::abs( iEta ) >= 21 ) {
525 if( (0x1 & iPhi) == 0 ) {
527 "Bug?! Jet ID code assumes no even iPhi recHits at HE edges";
530 bool boolOddnessIEta = oddnessIEta;
531 bool upperIPhi = (( iPhi%4 ) == 1 || ( iPhi%4 ) == 2);
535 if( upperIPhi != boolOddnessIEta ) ++iPhi;
541 HPD_energy_map[ iHPD ] += E_had;
542 RBX_energy_map[ iRBX ] += E_had;
543 if( iDbg > 5 )
cout<<
" --> H["<<iHPD<<
"]="<<HPD_energy_map[iHPD]
544 <<
", R["<<iRBX<<
"]="<<RBX_energy_map[iRBX];
555 std::inserter (HPD_energies, HPD_energies.end()),
select2nd );
557 std::sort( HPD_energies.begin(), HPD_energies.end(), greater<double>() );
559 std::inserter (RBX_energies, RBX_energies.end()),
select2nd );
561 std::sort( RBX_energies.begin(), RBX_energies.end(), greater<double>() );
563 subtowers.insert( subtowers.end(), Hcal_subtowers.begin(), Hcal_subtowers.end() );
564 subtowers.insert( subtowers.end(), Ecal_subtowers.begin(), Ecal_subtowers.end() );
565 subtowers.insert( subtowers.end(), HO_subtowers.begin(), HO_subtowers.end() );
574 int ae = TMath::Abs( iEta );
575 if( ae == 29 && depth == 1 ) ae += 1;
582 if( iEta <= -17 || ( depth == 3 && iEta == -16 ) )
return HEneg;
583 if( iEta >= 17 || ( depth == 3 && iEta == 16 ) )
return HEpos;
584 if( iEta < 0 )
return HBneg;
590 int ae = TMath::Abs( iEta );
591 if( ae == 29 )
return -1;
597 if( iEta == 16 || iEta == -16 )
return unknown_region;
598 if( iEta == 29 || iEta == -29 )
return unknown_region;
599 if( iEta <= -30 )
return HFneg;
600 if( iEta >= 30 )
return HFpos;
601 if( iEta <= -17 )
return HEneg;
602 if( iEta >= 17 )
return HEpos;
603 if( iEta < 0 )
return HBneg;
float hadEnergyInHE() const
float emEnergyInEE() const
virtual double energy() const GCC11_FINAL
energy
T getParameter(std::string const &) const
void setComment(std::string const &value)
virtual double et() const GCC11_FINAL
transverse energy
bool subtower_has_greater_E(reco::helper::JetIDHelper::subtower i, reco::helper::JetIDHelper::subtower j)
Jets made from CaloTowers.
HcalSubdetector subdet() const
get the subdetector
std::vector< T >::const_iterator const_iterator
float emEnergyInHF() const
std::vector< Variable::Flags > flags
virtual std::vector< CaloTowerPtr > getCaloConstituents() const
get all constituents
bool hasNonPositiveE(reco::helper::JetIDHelper::subtower x)
float hadEnergyInHO() const
int depth() const
get the tower depth
unsigned int hitsInNCarrying(double fraction, std::vector< subtower > descending_towers)
float emEnergyInEB() const
int ieta() const
get the cell ieta
static double select2nd(std::map< int, double >::value_type const &pair)
void fillDescription(edm::ParameterSetDescription &iDesc)
void classifyJetTowers(const edm::Event &event, const reco::CaloJet &jet, std::vector< subtower > &subtowers, std::vector< subtower > &Ecal_subtowers, std::vector< subtower > &Hcal_subtowers, std::vector< subtower > &HO_subtowers, std::vector< double > &HPD_energies, std::vector< double > &RBX_energies, const int iDbg=0)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
Container::value_type value_type
Region HBHE_region(int iEta, int depth)
unsigned int nCarrying(double fraction, std::vector< double > descending_energies)
ParameterDescriptionNode * ifValue(ParameterDescription< T > const &switchParameter, std::auto_ptr< ParameterDescriptionCases< T > > cases)
int HBHE_oddness(int iEta, int depth)
void classifyJetComponents(const edm::Event &event, const reco::CaloJet &jet, std::vector< double > &energies, std::vector< double > &subdet_energies, std::vector< double > &Ecal_energies, std::vector< double > &Hcal_energies, std::vector< double > &HO_energies, std::vector< double > &HPD_energies, std::vector< double > &RBX_energies, double &LS_bad_energy, double &HF_OOT_energy, const int iDbg=0)
float hadEnergyInHB() const
float hadEnergyInHF() const
virtual float pt() const GCC11_FINAL
transverse momentum
void calculate(const edm::Event &event, const reco::CaloJet &jet, const int iDbg=0)