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 
48 
51 
53 
56 
59 
61 
64 
65 };
66 
67 
69  printDebug_ = iConfig.getUntrackedParameter<bool>("printDebug", false);
70  electronToken_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electronTag"));
71 
72  regressionInputFile_ = iConfig.getParameter<std::string>("regressionInputFile");
73  energyRegressionType_ = iConfig.getParameter<uint32_t>("energyRegressionType");
74 
75  nameEnergyReg_ = iConfig.getParameter<std::string>("nameEnergyReg");
76  nameEnergyErrorReg_ = iConfig.getParameter<std::string>("nameEnergyErrorReg");
77 
78  recHitCollectionEBToken_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitCollectionEB"));
79  recHitCollectionEEToken_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitCollectionEE"));
80 
81  hVertexToken_ = consumes<reco::VertexCollection>(edm::InputTag("offlinePrimaryVertices"));
82  hRhoKt6PFJetsToken_ = consumes<double>(edm::InputTag("kt6PFJets","rho"));
83 
84  produces<edm::ValueMap<double> >(nameEnergyReg_);
85  produces<edm::ValueMap<double> >(nameEnergyErrorReg_);
86 
87  regressionEvaluator = new ElectronEnergyRegressionEvaluate();
88 
89  //set regression type
91  if (energyRegressionType_ == 1) type = ElectronEnergyRegressionEvaluate::kNoTrkVar;
92  else if (energyRegressionType_ == 2) type = ElectronEnergyRegressionEvaluate::kWithSubCluVar;
93  else if (energyRegressionType_ == 3) type = ElectronEnergyRegressionEvaluate::kWithTrkVarV1;
94  else if (energyRegressionType_ == 4) type = ElectronEnergyRegressionEvaluate::kWithTrkVarV2;
95 
96  //load weights and initialize
97  regressionEvaluator->initialize(regressionInputFile_.c_str(),type);
98 
99  geomInitialized_ = false;
100 
101 }
102 
103 
105 {
106  delete regressionEvaluator;
107 }
108 
109 // ------------ method called on each new Event ------------
111 
112  assert(regressionEvaluator->isInitialized());
113 
114  if (!geomInitialized_) {
115  edm::ESHandle<CaloTopology> theCaloTopology;
116  iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
117  ecalTopology_ = & (*theCaloTopology);
118 
119  edm::ESHandle<CaloGeometry> theCaloGeometry;
120  iSetup.get<CaloGeometryRecord>().get(theCaloGeometry);
121  caloGeometry_ = & (*theCaloGeometry);
122  geomInitialized_ = true;
123  }
124 
125  std::auto_ptr<edm::ValueMap<double> > regrEnergyMap(new edm::ValueMap<double>() );
126  edm::ValueMap<double>::Filler energyFiller(*regrEnergyMap);
127 
128  std::auto_ptr<edm::ValueMap<double> > regrEnergyErrorMap(new edm::ValueMap<double>() );
129  edm::ValueMap<double>::Filler energyErrorFiller(*regrEnergyErrorMap);
130 
132  iEvent.getByToken(electronToken_,egCollection);
133  const reco::GsfElectronCollection egCandidates = (*egCollection.product());
134 
135  std::vector<double> energyValues;
136  std::vector<double> energyErrorValues;
137  energyValues.reserve(egCollection->size());
138  energyErrorValues.reserve(egCollection->size());
139  //
140  //**************************************************************************
141  // Rechits
142  //**************************************************************************
145  iEvent.getByToken( recHitCollectionEBToken_, pEBRecHits );
146  iEvent.getByToken( recHitCollectionEEToken_, pEERecHits );
147 
148  //**************************************************************************
149  //Get Number of Vertices
150  //**************************************************************************
151  Handle<reco::VertexCollection> hVertexProduct;
152  iEvent.getByToken(hVertexToken_,hVertexProduct);
153  const reco::VertexCollection inVertices = *(hVertexProduct.product());
154 
155  // loop through all vertices
156  Int_t nvertices = 0;
157  for (reco::VertexCollection::const_iterator inV = inVertices.begin();
158  inV != inVertices.end(); ++inV) {
159 
160  // pass these vertex cuts
161  if (inV->ndof() >= 4
162  && inV->position().Rho() <= 2.0
163  && fabs(inV->z()) <= 24.0
164  ) {
165  nvertices++;
166  }
167  }
168 
169  //**************************************************************************
170  //Get Rho
171  //**************************************************************************
172  double rho = 0;
173  Handle<double> hRhoKt6PFJets;
174  iEvent.getByToken(hRhoKt6PFJetsToken_, hRhoKt6PFJets);
175  rho = (*hRhoKt6PFJets);
176 
177 
178  for ( reco::GsfElectronCollection::const_iterator egIter = egCandidates.begin();
179  egIter != egCandidates.end(); ++egIter) {
180 
181  const EcalRecHitCollection * recHits=0;
182  if(egIter->isEB())
183  recHits = pEBRecHits.product();
184  else
185  recHits = pEERecHits.product();
186 
187  SuperClusterHelper mySCHelper(&(*egIter),recHits,ecalTopology_,caloGeometry_);
188 
189  double energy=regressionEvaluator->calculateRegressionEnergy(&(*egIter),
190  mySCHelper,
191  rho,nvertices,
192  printDebug_);
193 
194  double error=regressionEvaluator->calculateRegressionEnergyUncertainty(&(*egIter),
195  mySCHelper,
196  rho,nvertices,
197  printDebug_);
198 
199  energyValues.push_back(energy);
200  energyErrorValues.push_back(error);
201 
202  }
203 
204  energyFiller.insert( egCollection, energyValues.begin(), energyValues.end() );
205  energyFiller.fill();
206 
207  energyErrorFiller.insert( egCollection, energyErrorValues.begin(), energyErrorValues.end() );
208  energyErrorFiller.fill();
209 
210  iEvent.put(regrEnergyMap,nameEnergyReg_);
211  iEvent.put(regrEnergyErrorMap,nameEnergyErrorReg_);
212 
213  return true;
214 
215 }
216 
217 
218 //define this as a plug-in
220 
221 
222 
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
ElectronEnergyRegressionEvaluate * regressionEvaluator
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#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:52
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::EDGetTokenT< EcalRecHitCollection > recHitCollectionEEToken_
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
int iEvent
Definition: GenABIO.cc:230
ElectronRegressionEnergyProducer(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
edm::EDGetTokenT< reco::VertexCollection > hVertexToken_
edm::EDGetTokenT< EcalRecHitCollection > recHitCollectionEBToken_
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: Handle.h:81
edm::EDGetTokenT< reco::GsfElectronCollection > electronToken_