CMS 3D CMS Logo

CorrectedECALPFClusterProducer.cc
Go to the documentation of this file.
1 #ifndef __CorrectedECALPFClusterProducer__
2 #define __CorrectedECALPFClusterProducer__
3 
4 // user include files
7 
13 
16 
20 
21 namespace {
23  bool sortByKey(const EEPSPair& a, const EEPSPair& b) {
24  return a.first < b.first;
25  }
26 
27  // why, why -1 and not <double>::max() ????
28  double testPreshowerDistance(reco::PFCluster const & eeclus,
29  reco::PFCluster const & psclus) {
30  auto const & pspos = psclus.positionREP();
31  auto const & eepos = eeclus.positionREP();
32  // lazy continue based on geometry
33  if( eeclus.z()*psclus.z() < 0 ) return -1.0;
34  auto deta= std::abs(eepos.eta() - pspos.eta());
35  if( deta > 0.3 ) return -1.0;
36  auto dphi= std::abs(deltaPhi(eepos.phi(), pspos.phi()));
37  if( dphi > 0.6 ) return -1.0;
38  return LinkByRecHit::testECALAndPSByRecHit(eeclus,psclus,false);
39  }
40 }
41 
43 public:
45  _minimumPSEnergy(conf.getParameter<double>("minimumPSEnergy")) {
46  const edm::InputTag& inputECAL =
47  conf.getParameter<edm::InputTag>("inputECAL");
48  _inputECAL = consumes<reco::PFClusterCollection>( inputECAL );
49 
50  const edm::InputTag& inputPS =
51  conf.getParameter<edm::InputTag>("inputPS");
52  _inputPS = consumes<reco::PFClusterCollection>( inputPS );
53 
54  const edm::ParameterSet& corConf = conf.getParameterSet("energyCorrector");
55  _corrector.reset(new PFClusterEMEnergyCorrector(corConf,consumesCollector()));
56 
57  produces<reco::PFCluster::EEtoPSAssociation>();
58  produces<reco::PFClusterCollection>();
59  }
60 
61  void produce(edm::Event& e, const edm::EventSetup& es) override;
62  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
63 
64 private:
65  const double _minimumPSEnergy;
66  std::unique_ptr<PFClusterEMEnergyCorrector> _corrector;
69 };
70 
72 
75  auto clusters_out = std::make_unique<reco::PFClusterCollection>();
76  auto association_out = std::make_unique<reco::PFCluster::EEtoPSAssociation>();
77 
79  e.getByToken(_inputECAL,handleECAL);
81  e.getByToken(_inputPS,handlePS);
82 
83  auto const & ecals = *handleECAL;
84  auto const & pss = *handlePS;
85 
86  clusters_out->reserve(ecals.size());
87  association_out->reserve(ecals.size());
88  clusters_out->insert(clusters_out->end(),
89  ecals.begin(),ecals.end());
90  //build the EE->PS association
91  for( unsigned i = 0; i < pss.size(); ++i ) {
92  switch( pss[i].layer() ) { // just in case this isn't the ES...
93  case PFLayer::PS1:
94  case PFLayer::PS2:
95  break;
96  default:
97  continue;
98  }
99  if( pss[i].energy() < _minimumPSEnergy ) continue;
100  int eematch = -1;
101  auto min_dist = std::numeric_limits<double>::max();
102  for( size_t ic = 0; ic < ecals.size(); ++ic ) {
103  if( ecals[ic].layer() != PFLayer::ECAL_ENDCAP ) continue;
104  auto dist = testPreshowerDistance(ecals[ic],pss[i]);
105  if (dist == -1.0) dist=std::numeric_limits<double>::max();
106  if( dist < min_dist ) {
107  eematch = ic;
108  min_dist = dist;
109  }
110  } // loop on EE clusters
111  if( eematch>=0 ) {
112  edm::Ptr<reco::PFCluster> psclus(handlePS,i);
113  association_out->push_back(std::make_pair(eematch,psclus));
114  }
115  }
116  std::sort(association_out->begin(),association_out->end(),sortByKey);
117 
118  _corrector->correctEnergies(e,es,*association_out,*clusters_out);
119 
120  association_out->shrink_to_fit();
121 
122  e.put(std::move(association_out));
123  e.put(std::move(clusters_out));
124 }
125 
128  desc.add<double>("minimumPSEnergy",0.0);
129  desc.add<edm::InputTag>("inputPS",edm::InputTag("particleFlowClusterPS"));
130  {
132  psd0.add<bool>("applyCrackCorrections",false);
133  psd0.add<bool>("applyMVACorrections",false);
134  psd0.add<bool>("srfAwareCorrection",false);
135  psd0.add<bool>("setEnergyUncertainty",false);
136  psd0.add<bool>("autoDetectBunchSpacing",true);
137  psd0.add<int>("bunchSpacing",25);
138  psd0.add<double>("maxPtForMVAEvaluation",-99.);
139  psd0.add<std::string>("algoName","PFClusterEMEnergyCorrector");
140  psd0.add<edm::InputTag>("recHitsEBLabel",edm::InputTag("ecalRecHit","EcalRecHitsEB"));
141  psd0.add<edm::InputTag>("recHitsEELabel",edm::InputTag("ecalRecHit","EcalRecHitsEE"));
142  psd0.add<edm::InputTag>("verticesLabel",edm::InputTag("offlinePrimaryVertices"));
143  psd0.add<edm::InputTag>("ebSrFlagLabel",edm::InputTag("ecalDigis"));
144  psd0.add<edm::InputTag>("eeSrFlagLabel",edm::InputTag("ecalDigis"));
145  desc.add<edm::ParameterSetDescription>("energyCorrector",psd0);
146  }
147  desc.add<edm::InputTag>("inputECAL",edm::InputTag("particleFlowClusterECALUncorrected"));
148  descriptions.add("particleFlowClusterECAL",desc);
149 }
150 
151 #endif
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
edm::EDGetTokenT< reco::PFClusterCollection > _inputPS
std::pair< ALIstring, ALIstring > pss
Definition: Fit.h:27
CorrectedECALPFClusterProducer(const edm::ParameterSet &conf)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:47
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
static double testECALAndPSByRecHit(const reco::PFCluster &clusterECAL, const reco::PFCluster &clusterPS, bool debug=false)
double z() const
z coordinate of cluster centroid
Definition: CaloCluster.h:165
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const REPPoint & positionREP() const
cluster position: rho, eta, phi
Definition: PFCluster.h:97
void produce(edm::Event &e, const edm::EventSetup &es) override
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::EDGetTokenT< reco::PFClusterCollection > _inputECAL
std::unique_ptr< PFClusterEMEnergyCorrector > _corrector
ParameterSet const & getParameterSet(std::string const &) const
reco::PFCluster::EEtoPSAssociation::value_type EEPSPair
bool sortByKey(const EEPSPair &a, const EEPSPair &b)
double b
Definition: hdecay.h:120
void add(std::string const &label, ParameterSetDescription const &psetDescription)
double a
Definition: hdecay.h:121
def move(src, dest)
Definition: eostools.py:511