CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CorrectedECALPFClusterProducer.cc
Go to the documentation of this file.
1 #ifndef __CorrectedECALPFClusterProducer__
2 #define __CorrectedECALPFClusterProducer__
3 
4 // user include files
7 
13 
16 
19 #include "TVector2.h"
20 
21 namespace {
23  bool sortByKey(const EEPSPair& a, const EEPSPair& b) {
24  return a.first < b.first;
25  }
26  double testPreshowerDistance(const edm::Ptr<reco::PFCluster>& eeclus,
27  const edm::Ptr<reco::PFCluster>& psclus) {
28  if( psclus.isNull() ) return -1.0;
29  /*
30  // commented out since PFCluster::layer() uses a lot of CPU
31  // and since
32  if( PFLayer::ECAL_ENDCAP != eeclus->layer() ) return -1.0;
33  if( PFLayer::PS1 != psclus->layer() &&
34  PFLayer::PS2 != psclus->layer() ) {
35  throw cms::Exception("testPreshowerDistance")
36  << "The second argument passed to this function was "
37  << "not a preshower cluster!" << std::endl;
38  }
39  */
40  const reco::PFCluster::REPPoint& pspos = psclus->positionREP();
41  const reco::PFCluster::REPPoint& eepos = eeclus->positionREP();
42  // lazy continue based on geometry
43  if( eeclus->z()*psclus->z() < 0 ) return -1.0;
44  const double dphi= std::abs(TVector2::Phi_mpi_pi(eepos.phi() -
45  pspos.phi()));
46  if( dphi > 0.6 ) return -1.0;
47  const double deta= std::abs(eepos.eta() - pspos.eta());
48  if( deta > 0.3 ) return -1.0;
49  return LinkByRecHit::testECALAndPSByRecHit(*eeclus,*psclus,false);
50  }
51 }
52 
54 public:
56  _minimumPSEnergy(conf.getParameter<double>("minimumPSEnergy")) {
57  const edm::InputTag& inputECAL =
58  conf.getParameter<edm::InputTag>("inputECAL");
59  _inputECAL = consumes<reco::PFClusterCollection>( inputECAL );
60 
61  const edm::InputTag& inputPS =
62  conf.getParameter<edm::InputTag>("inputPS");
63  _inputPS = consumes<reco::PFClusterCollection>( inputPS );
64 
65  const edm::ParameterSet corConf = conf.getParameterSet("energyCorrector");
67 
68  produces<reco::PFCluster::EEtoPSAssociation>();
69  produces<reco::PFClusterCollection>();
70  }
71 
72  virtual void produce(edm::Event& e, const edm::EventSetup& es);
73  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
74 
75 private:
76  const double _minimumPSEnergy;
77  std::unique_ptr<PFClusterEMEnergyCorrector> _corrector;
80 };
81 
83 
86  std::auto_ptr<reco::PFClusterCollection> clusters_out;
87  clusters_out.reset(new reco::PFClusterCollection);
88  std::auto_ptr<reco::PFCluster::EEtoPSAssociation> association_out;
89  association_out.reset(new reco::PFCluster::EEtoPSAssociation);
90 
92  e.getByToken(_inputECAL,handleECAL);
94  e.getByToken(_inputPS,handlePS);
95 
96  clusters_out->reserve(handleECAL->size());
97  association_out->reserve(handleECAL->size());
98  clusters_out->insert(clusters_out->end(),
99  handleECAL->begin(),handleECAL->end());
100  //build the EE->PS association
101  double dist = -1.0, min_dist = -1.0;
102  for( unsigned i = 0; i < handlePS->size(); ++i ) {
103  switch( handlePS->at(i).layer() ) { // just in case this isn't the ES...
104  case PFLayer::PS1:
105  case PFLayer::PS2:
106  break;
107  default:
108  continue;
109  }
110  edm::Ptr<reco::PFCluster> psclus(handlePS,i);
111  if( psclus->energy() < _minimumPSEnergy ) continue;
112  edm::Ptr<reco::PFCluster> eematch,eeclus;
113  dist = min_dist = -1.0; // reset
114  for( size_t ic = 0; ic < handleECAL->size(); ++ic ) {
115  if( handleECAL->at(ic).layer() != PFLayer::ECAL_ENDCAP ) continue;
116  eeclus = edm::Ptr<reco::PFCluster>(handleECAL,ic);
117  dist = testPreshowerDistance(eeclus,psclus);
118  if( dist == -1.0 || (min_dist != -1.0 && dist > min_dist) ) continue;
119  if( dist < min_dist || min_dist == -1.0 ) {
120  eematch = eeclus;
121  min_dist = dist;
122  }
123  } // loop on EE clusters
124  if( eematch.isNonnull() ) {
125  association_out->push_back(std::make_pair(eematch.key(),psclus));
126  }
127  }
128  std::sort(association_out->begin(),association_out->end(),sortByKey);
129 
130  _corrector->correctEnergies(e,es,*association_out,*clusters_out);
131 
132  association_out->shrink_to_fit();
133 
134  e.put(association_out);
135  e.put(clusters_out);
136 }
137 
140  desc.add<double>("minimumPSEnergy",0.0);
141  desc.add<edm::InputTag>("inputPS",edm::InputTag("particleFlowClusterPS"));
142  {
144  psd0.add<bool>("applyCrackCorrections",false);
145  psd0.add<bool>("applyMVACorrections",false);
146  psd0.add<double>("maxPtForMVAEvaluation",-99.);
147  psd0.add<std::string>("algoName","PFClusterEMEnergyCorrector");
148  psd0.add<edm::InputTag>("recHitsEBLabel",edm::InputTag("ecalRecHit","EcalRecHitsEB"));
149  psd0.add<edm::InputTag>("recHitsEELabel",edm::InputTag("ecalRecHit","EcalRecHitsEE"));
150  psd0.add<edm::InputTag>("verticesLabel",edm::InputTag("offlinePrimaryVertices"));
151  psd0.add<bool>("autoDetectBunchSpacing",true);
152  psd0.add<int>("bunchSpacing",25);
153  desc.add<edm::ParameterSetDescription>("energyCorrector",psd0);
154  }
155  desc.add<edm::InputTag>("inputECAL",edm::InputTag("particleFlowClusterECALUncorrected"));
156  descriptions.add("particleFlowClusterECAL",desc);
157 }
158 
159 #endif
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
edm::EDGetTokenT< reco::PFClusterCollection > _inputPS
CorrectedECALPFClusterProducer(const edm::ParameterSet &conf)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
key_type key() const
Definition: Ptr.h:186
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
static double testECALAndPSByRecHit(const reco::PFCluster &clusterECAL, const reco::PFCluster &clusterPS, bool debug=false)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double Phi_mpi_pi(double x)
Definition: JetUtil.h:24
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::vector< std::pair< CaloClusterPtr::key_type, edm::Ptr< PFCluster > > > EEtoPSAssociation
Definition: PFCluster.h:50
bool isNull() const
Checks for null.
Definition: Ptr.h:165
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Container::value_type value_type
edm::EDGetTokenT< reco::PFClusterCollection > _inputECAL
tuple conf
Definition: dbtoconf.py:185
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:169
virtual void produce(edm::Event &e, const edm::EventSetup &es)
std::unique_ptr< PFClusterEMEnergyCorrector > _corrector
ParameterSet const & getParameterSet(std::string const &) const
double b
Definition: hdecay.h:120
void add(std::string const &label, ParameterSetDescription const &psetDescription)
double a
Definition: hdecay.h:121
ROOT::Math::PositionVector3D< ROOT::Math::CylindricalEta3D< double > > REPPoint
Definition: PFCluster.h:54
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
Definition: PFClusterFwd.h:9