Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:56

0001 //*****************************************************************************
0002 // File:      EgammaTowerIsolation.cc
0003 // ----------------------------------------------------------------------------
0004 // OrigAuth:  Matthias Mozer
0005 // Institute: IIHE-VUB
0006 //=============================================================================
0007 //*****************************************************************************
0008 
0009 //CMSSW includes
0010 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaTowerIsolation.h"
0011 #include <cassert>
0012 #include <memory>
0013 
0014 #ifdef ETISTATDEBUG
0015 // #include<iostream>
0016 namespace etiStat {
0017   Count::~Count() {
0018     //    std::cout << "\nEgammaTowerIsolationNew " << create << "/" << comp << "/" << float(span)/float(comp)
0019     //        << std::endl<< std::endl;
0020   }
0021 
0022   Count Count::count;
0023 }  // namespace etiStat
0024 #endif
0025 
0026 namespace {
0027   struct TLS {
0028     std::unique_ptr<EgammaTowerIsolationNew<1>> newAlgo = nullptr;
0029     ;
0030     const CaloTowerCollection* oldTowers = nullptr;
0031     ;
0032     uint32_t id15 = 0;
0033   };
0034   thread_local TLS tls;
0035 }  // namespace
0036 
0037 EgammaTowerIsolation::EgammaTowerIsolation(
0038     float extRadiusI, float intRadiusI, float etLow, signed int depth, const CaloTowerCollection* towers)
0039     : depth_(depth), extRadius(extRadiusI), intRadius(intRadiusI) {
0040   assert(0 == etLow);
0041 
0042   // extremely poor in quality  (test of performance)
0043   if (tls.newAlgo.get() == nullptr || towers != tls.oldTowers || towers->size() != tls.newAlgo->nt ||
0044       (towers->size() > 15 && (*towers)[15].id() != tls.id15)) {
0045     tls.newAlgo = std::make_unique<EgammaTowerIsolationNew<1>>(&extRadius, &intRadius, *towers);
0046     tls.oldTowers = towers;
0047     tls.id15 = towers->size() > 15 ? (*towers)[15].id() : 0;
0048   }
0049 }
0050 
0051 double EgammaTowerIsolation::getSum(bool et,
0052                                     reco::SuperCluster const& sc,
0053                                     const std::vector<CaloTowerDetId>* detIdToExclude) const {
0054   if (nullptr != detIdToExclude)
0055     assert(0 == intRadius);
0056 
0057   // hack
0058   tls.newAlgo->setRadius(&extRadius, &intRadius);
0059 
0060   EgammaTowerIsolationNew<1>::Sum sum;
0061   if (detIdToExclude == nullptr) {
0062     tls.newAlgo->compute(
0063         et, sum, sc, static_cast<CaloTowerDetId const*>(nullptr), static_cast<CaloTowerDetId const*>(nullptr));
0064   } else {
0065     tls.newAlgo->compute(et, sum, sc, detIdToExclude->cbegin(), detIdToExclude->cend());
0066   }
0067 
0068   switch (depth_) {
0069     case AllDepths:
0070       return detIdToExclude == nullptr ? sum.he[0] : sum.heBC[0];
0071     case Depth1:
0072       return detIdToExclude == nullptr ? sum.he[0] - sum.h2[0] : sum.heBC[0] - sum.h2BC[0];
0073     case Depth2:
0074       return detIdToExclude == nullptr ? sum.h2[0] : sum.h2BC[0];
0075     default:
0076       return 0;
0077   }
0078   return 0;
0079 }