CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ElectronRegressionEnergyProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
6 
13 
16 
26 
27 //
28 // class declaration
29 //
30 
31 using namespace std;
32 using namespace reco;
33 using namespace edm;
34 
36 public:
39 private:
40  virtual bool filter(edm::Event&, const edm::EventSetup&);
41 
42  // ----------member data ---------------------------
45 
46  std::string regressionInputFile_;
48 
49  std::string nameEnergyReg_;
50  std::string nameEnergyErrorReg_;
51 
53 
56 
59 
61 
62 };
63 
64 
66  printDebug_ = iConfig.getUntrackedParameter<bool>("printDebug", false);
67  electronTag_ = iConfig.getParameter<edm::InputTag>("electronTag");
68 
69  regressionInputFile_ = iConfig.getParameter<std::string>("regressionInputFile");
70  energyRegressionType_ = iConfig.getParameter<uint32_t>("energyRegressionType");
71 
72  nameEnergyReg_ = iConfig.getParameter<std::string>("nameEnergyReg");
73  nameEnergyErrorReg_ = iConfig.getParameter<std::string>("nameEnergyErrorReg");
74 
75  recHitCollectionEB_ = iConfig.getParameter<edm::InputTag>("recHitCollectionEB");
76  recHitCollectionEE_ = iConfig.getParameter<edm::InputTag>("recHitCollectionEE");
77 
78  produces<edm::ValueMap<double> >(nameEnergyReg_);
79  produces<edm::ValueMap<double> >(nameEnergyErrorReg_);
80 
81  regressionEvaluator = new ElectronEnergyRegressionEvaluate();
82 
83  //set regression type
85  if (energyRegressionType_ == 1) type = ElectronEnergyRegressionEvaluate::kNoTrkVar;
86  else if (energyRegressionType_ == 2) type = ElectronEnergyRegressionEvaluate::kWithSubCluVar;
87  else if (energyRegressionType_ == 3) type = ElectronEnergyRegressionEvaluate::kWithTrkVarV1;
88  else if (energyRegressionType_ == 4) type = ElectronEnergyRegressionEvaluate::kWithTrkVarV2;
89 
90  //load weights and initialize
91  regressionEvaluator->initialize(regressionInputFile_.c_str(),type);
92 
93  geomInitialized_ = false;
94 
95 }
96 
97 
99 {
100  delete regressionEvaluator;
101 }
102 
103 // ------------ method called on each new Event ------------
105 
106  assert(regressionEvaluator->isInitialized());
107 
108  if (!geomInitialized_) {
109  edm::ESHandle<CaloTopology> theCaloTopology;
110  iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
111  ecalTopology_ = & (*theCaloTopology);
112 
113  edm::ESHandle<CaloGeometry> theCaloGeometry;
114  iSetup.get<CaloGeometryRecord>().get(theCaloGeometry);
115  caloGeometry_ = & (*theCaloGeometry);
116  geomInitialized_ = true;
117  }
118 
119  std::auto_ptr<edm::ValueMap<double> > regrEnergyMap(new edm::ValueMap<double>() );
120  edm::ValueMap<double>::Filler energyFiller(*regrEnergyMap);
121 
122  std::auto_ptr<edm::ValueMap<double> > regrEnergyErrorMap(new edm::ValueMap<double>() );
123  edm::ValueMap<double>::Filler energyErrorFiller(*regrEnergyErrorMap);
124 
126  iEvent.getByLabel(electronTag_,egCollection);
127  const reco::GsfElectronCollection egCandidates = (*egCollection.product());
128 
129  std::vector<double> energyValues;
130  std::vector<double> energyErrorValues;
131  energyValues.reserve(egCollection->size());
132  energyErrorValues.reserve(egCollection->size());
133  //
134  //**************************************************************************
135  // Rechits
136  //**************************************************************************
139  iEvent.getByLabel( recHitCollectionEB_, pEBRecHits );
140  iEvent.getByLabel( recHitCollectionEE_, pEERecHits );
141 
142  //**************************************************************************
143  //Get Number of Vertices
144  //**************************************************************************
145  Handle<reco::VertexCollection> hVertexProduct;
146  iEvent.getByLabel(edm::InputTag("offlinePrimaryVertices"),hVertexProduct);
147  const reco::VertexCollection inVertices = *(hVertexProduct.product());
148 
149  // loop through all vertices
150  Int_t nvertices = 0;
151  for (reco::VertexCollection::const_iterator inV = inVertices.begin();
152  inV != inVertices.end(); ++inV) {
153 
154  // pass these vertex cuts
155  if (inV->ndof() >= 4
156  && inV->position().Rho() <= 2.0
157  && fabs(inV->z()) <= 24.0
158  ) {
159  nvertices++;
160  }
161  }
162 
163  //**************************************************************************
164  //Get Rho
165  //**************************************************************************
166  double rho = 0;
167  Handle<double> hRhoKt6PFJets;
168  iEvent.getByLabel(edm::InputTag("kt6PFJets","rho"), hRhoKt6PFJets);
169  rho = (*hRhoKt6PFJets);
170 
171 
172  for ( reco::GsfElectronCollection::const_iterator egIter = egCandidates.begin();
173  egIter != egCandidates.end(); ++egIter) {
174 
175  const EcalRecHitCollection * recHits=0;
176  if(egIter->isEB())
177  recHits = pEBRecHits.product();
178  else
179  recHits = pEERecHits.product();
180 
181  SuperClusterHelper mySCHelper(&(*egIter),recHits,ecalTopology_,caloGeometry_);
182 
183  double energy=regressionEvaluator->calculateRegressionEnergy(&(*egIter),
184  mySCHelper,
185  rho,nvertices,
186  printDebug_);
187 
188  double error=regressionEvaluator->calculateRegressionEnergyUncertainty(&(*egIter),
189  mySCHelper,
190  rho,nvertices,
191  printDebug_);
192 
193  energyValues.push_back(energy);
194  energyErrorValues.push_back(error);
195 
196  }
197 
198  energyFiller.insert( egCollection, energyValues.begin(), energyValues.end() );
199  energyFiller.fill();
200 
201  energyErrorFiller.insert( egCollection, energyErrorValues.begin(), energyErrorValues.end() );
202  energyErrorFiller.fill();
203 
204  iEvent.put(regrEnergyMap,nameEnergyReg_);
205  iEvent.put(regrEnergyErrorMap,nameEnergyErrorReg_);
206 
207  return true;
208 
209 }
210 
211 
212 //define this as a plug-in
214 
215 
216 
type
Definition: HCALResponse.h:22
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
ElectronEnergyRegressionEvaluate * regressionEvaluator
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual bool filter(edm::Event &, const edm::EventSetup &)
Definition: DDAxes.h:10
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
int iEvent
Definition: GenABIO.cc:243
ElectronRegressionEnergyProducer(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: Handle.h:74