CMS 3D CMS Logo

ElectronRegressionEnergyProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
6 
12 
15 
25 
26 //
27 // class declaration
28 //
29 
31 public:
34 
35 private:
36  bool filter(edm::Event&, const edm::EventSetup&) override;
37 
38  // ----------member data ---------------------------
41 
44 
47 
49 
52 
55 
57 
60 };
61 
63  printDebug_ = iConfig.getUntrackedParameter<bool>("printDebug", false);
64  electronToken_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electronTag"));
65 
66  regressionInputFile_ = iConfig.getParameter<std::string>("regressionInputFile");
67  energyRegressionType_ = iConfig.getParameter<uint32_t>("energyRegressionType");
68 
69  nameEnergyReg_ = iConfig.getParameter<std::string>("nameEnergyReg");
70  nameEnergyErrorReg_ = iConfig.getParameter<std::string>("nameEnergyErrorReg");
71 
72  recHitCollectionEBToken_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitCollectionEB"));
73  recHitCollectionEEToken_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitCollectionEE"));
74 
75  hVertexToken_ = consumes<reco::VertexCollection>(edm::InputTag("offlinePrimaryVertices"));
76  hRhoKt6PFJetsToken_ = consumes<double>(edm::InputTag("kt6PFJets", "rho"));
77 
78  produces<edm::ValueMap<double> >(nameEnergyReg_);
79  produces<edm::ValueMap<double> >(nameEnergyErrorReg_);
80 
82 
83  //set regression type
85  if (energyRegressionType_ == 1)
87  else if (energyRegressionType_ == 2)
89  else if (energyRegressionType_ == 3)
91  else if (energyRegressionType_ == 4)
93 
94  //load weights and initialize
96 
97  geomInitialized_ = false;
98 }
99 
101 
102 // ------------ method called on each new Event ------------
105 
106  if (!geomInitialized_) {
107  edm::ESHandle<CaloTopology> theCaloTopology;
108  iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
109  ecalTopology_ = &(*theCaloTopology);
110 
111  edm::ESHandle<CaloGeometry> theCaloGeometry;
112  iSetup.get<CaloGeometryRecord>().get(theCaloGeometry);
113  caloGeometry_ = &(*theCaloGeometry);
114  geomInitialized_ = true;
115  }
116 
117  std::unique_ptr<edm::ValueMap<double> > regrEnergyMap(new edm::ValueMap<double>());
118  edm::ValueMap<double>::Filler energyFiller(*regrEnergyMap);
119 
120  std::unique_ptr<edm::ValueMap<double> > regrEnergyErrorMap(new edm::ValueMap<double>());
121  edm::ValueMap<double>::Filler energyErrorFiller(*regrEnergyErrorMap);
122 
124  iEvent.getByToken(electronToken_, egCollection);
125  const reco::GsfElectronCollection egCandidates = (*egCollection.product());
126 
127  std::vector<double> energyValues;
128  std::vector<double> energyErrorValues;
129  energyValues.reserve(egCollection->size());
130  energyErrorValues.reserve(egCollection->size());
131  //
132  //**************************************************************************
133  // Rechits
134  //**************************************************************************
137  iEvent.getByToken(recHitCollectionEBToken_, pEBRecHits);
138  iEvent.getByToken(recHitCollectionEEToken_, pEERecHits);
139 
140  //**************************************************************************
141  //Get Number of Vertices
142  //**************************************************************************
144  iEvent.getByToken(hVertexToken_, hVertexProduct);
145  const reco::VertexCollection inVertices = *(hVertexProduct.product());
146 
147  // loop through all vertices
148  Int_t nvertices = 0;
149  for (reco::VertexCollection::const_iterator inV = inVertices.begin(); inV != inVertices.end(); ++inV) {
150  // pass these vertex cuts
151  if (inV->ndof() >= 4 && inV->position().Rho() <= 2.0 && fabs(inV->z()) <= 24.0) {
152  nvertices++;
153  }
154  }
155 
156  //**************************************************************************
157  //Get Rho
158  //**************************************************************************
159  double rho = 0;
160  edm::Handle<double> hRhoKt6PFJets;
161  iEvent.getByToken(hRhoKt6PFJetsToken_, hRhoKt6PFJets);
162  rho = (*hRhoKt6PFJets);
163 
164  for (reco::GsfElectronCollection::const_iterator egIter = egCandidates.begin(); egIter != egCandidates.end();
165  ++egIter) {
166  const EcalRecHitCollection* recHits = nullptr;
167  if (egIter->isEB())
168  recHits = pEBRecHits.product();
169  else
170  recHits = pEERecHits.product();
171 
172  SuperClusterHelper mySCHelper(&(*egIter), recHits, ecalTopology_, caloGeometry_);
173 
174  double energy = regressionEvaluator->calculateRegressionEnergy(&(*egIter), mySCHelper, rho, nvertices, printDebug_);
175 
176  double error =
177  regressionEvaluator->calculateRegressionEnergyUncertainty(&(*egIter), mySCHelper, rho, nvertices, printDebug_);
178 
179  energyValues.push_back(energy);
180  energyErrorValues.push_back(error);
181  }
182 
183  energyFiller.insert(egCollection, energyValues.begin(), energyValues.end());
184  energyFiller.fill();
185 
186  energyErrorFiller.insert(egCollection, energyErrorValues.begin(), energyErrorValues.end());
187  energyErrorFiller.fill();
188 
189  iEvent.put(std::move(regrEnergyMap), nameEnergyReg_);
190  iEvent.put(std::move(regrEnergyErrorMap), nameEnergyErrorReg_);
191 
192  return true;
193 }
194 
195 //define this as a plug-in
ElectronRegressionEnergyProducer::electronToken_
edm::EDGetTokenT< reco::GsfElectronCollection > electronToken_
Definition: ElectronRegressionEnergyProducer.cc:40
ElectronEnergyRegressionEvaluate::isInitialized
bool isInitialized() const
Definition: ElectronEnergyRegressionEvaluate.h:48
Handle.h
edm::helper::Filler::insert
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
ElectronEnergyRegressionEvaluate::calculateRegressionEnergyUncertainty
double calculateRegressionEnergyUncertainty(const reco::GsfElectron *ele, SuperClusterHelper &mySCHelper, double rho, double nvertices, bool printDebug=false)
Definition: ElectronEnergyRegressionEvaluate.cc:305
edm::Handle::product
T const * product() const
Definition: Handle.h:70
ElectronRegressionEnergyProducer::filter
bool filter(edm::Event &, const edm::EventSetup &) override
Definition: ElectronRegressionEnergyProducer.cc:103
ElectronRegressionEnergyProducer::recHitCollectionEEToken_
edm::EDGetTokenT< EcalRecHitCollection > recHitCollectionEEToken_
Definition: ElectronRegressionEnergyProducer.cc:54
EDProducer.h
ESHandle.h
edm::EDGetTokenT< reco::GsfElectronCollection >
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
ElectronEnergyRegressionEvaluate
Definition: ElectronEnergyRegressionEvaluate.h:32
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::helper::Filler::fill
void fill()
Definition: ValueMap.h:65
cms::cuda::assert
assert(be >=bs)
edm::SortedCollection< EcalRecHit >
EDFilter.h
reco::GsfElectronCollection
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
Definition: GsfElectronFwd.h:14
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
CaloTopologyRecord
Definition: CaloTopologyRecord.h:10
ElectronEnergyRegressionEvaluate::kWithTrkVarV1
Definition: ElectronEnergyRegressionEvaluate.h:41
edm::Handle< reco::GsfElectronCollection >
relativeConstraints.error
error
Definition: relativeConstraints.py:53
ElectronRegressionEnergyProducer::nameEnergyReg_
std::string nameEnergyReg_
Definition: ElectronRegressionEnergyProducer.cc:45
CaloTopology
Definition: CaloTopology.h:19
ElectronRegressionEnergyProducer::geomInitialized_
bool geomInitialized_
Definition: ElectronRegressionEnergyProducer.cc:48
ElectronRegressionEnergyProducer::ecalTopology_
const CaloTopology * ecalTopology_
Definition: ElectronRegressionEnergyProducer.cc:50
MakerMacros.h
CaloGeometry
Definition: CaloGeometry.h:21
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ElectronRegressionEnergyProducer::~ElectronRegressionEnergyProducer
~ElectronRegressionEnergyProducer() override
Definition: ElectronRegressionEnergyProducer.cc:100
edm::ESHandle< CaloTopology >
ElectronRegressionEnergyProducer::hRhoKt6PFJetsToken_
edm::EDGetTokenT< double > hRhoKt6PFJetsToken_
Definition: ElectronRegressionEnergyProducer.cc:59
ElectronRegressionEnergyProducer::caloGeometry_
const CaloGeometry * caloGeometry_
Definition: ElectronRegressionEnergyProducer.cc:51
ElectronEnergyRegressionEvaluate::ElectronEnergyRegressionType
ElectronEnergyRegressionType
Definition: ElectronEnergyRegressionEvaluate.h:37
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
ElectronRegressionEnergyProducer::regressionEvaluator
ElectronEnergyRegressionEvaluate * regressionEvaluator
Definition: ElectronRegressionEnergyProducer.cc:56
ElectronEnergyRegressionEvaluate::kNoTrkVar
Definition: ElectronEnergyRegressionEvaluate.h:38
GsfElectron.h
ElectronRegressionEnergyProducer::regressionInputFile_
std::string regressionInputFile_
Definition: ElectronRegressionEnergyProducer.cc:42
CaloGeometryRecord.h
DDAxes::rho
ElectronEnergyRegressionEvaluate.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
FastTrackerRecHitMaskProducer_cfi.recHits
recHits
Definition: FastTrackerRecHitMaskProducer_cfi.py:8
ElectronRegressionEnergyProducer::recHitCollectionEBToken_
edm::EDGetTokenT< EcalRecHitCollection > recHitCollectionEBToken_
Definition: ElectronRegressionEnergyProducer.cc:53
GsfElectronFwd.h
ElectronRegressionEnergyProducer::printDebug_
bool printDebug_
Definition: ElectronRegressionEnergyProducer.cc:39
edm::ParameterSet
Definition: ParameterSet.h:47
ElectronEnergyRegressionEvaluate::kWithSubCluVar
Definition: ElectronEnergyRegressionEvaluate.h:43
Event.h
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
CaloTopologyRecord.h
iEvent
int iEvent
Definition: GenABIO.cc:224
ElectronRegressionEnergyProducer::energyRegressionType_
uint32_t energyRegressionType_
Definition: ElectronRegressionEnergyProducer.cc:43
edm::EDFilter
Definition: EDFilter.h:38
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
ElectronRegressionEnergyProducer::hVertexToken_
edm::EDGetTokenT< reco::VertexCollection > hVertexToken_
Definition: ElectronRegressionEnergyProducer.cc:58
SuperClusterHelper
Definition: SuperClusterHelper.h:12
ElectronEnergyRegressionEvaluate::calculateRegressionEnergy
double calculateRegressionEnergy(const reco::GsfElectron *ele, SuperClusterHelper &mySCHelper, double rho, double nvertices, bool printDebug=false)
Definition: ElectronEnergyRegressionEvaluate.cc:47
VertexFwd.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
edm::ValueMap
Definition: ValueMap.h:107
ElectronRegressionEnergyProducer::nameEnergyErrorReg_
std::string nameEnergyErrorReg_
Definition: ElectronRegressionEnergyProducer.cc:46
ElectronRegressionEnergyProducer::ElectronRegressionEnergyProducer
ElectronRegressionEnergyProducer(const edm::ParameterSet &)
Definition: ElectronRegressionEnergyProducer.cc:62
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Electron.h
ElectronRegressionEnergyProducer
Definition: ElectronRegressionEnergyProducer.cc:30
edm::helper::Filler
Definition: ValueMap.h:22
ParameterSet.h
ElectronEnergyRegressionEvaluate::kWithTrkVarV2
Definition: ElectronEnergyRegressionEvaluate.h:42
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
ElectronEnergyRegressionEvaluate::initialize
void initialize(std::string weightsFile, ElectronEnergyRegressionEvaluate::ElectronEnergyRegressionType type)
Definition: ElectronEnergyRegressionEvaluate.cc:25