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