CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CalibratedPatElectronProducer.cc
Go to the documentation of this file.
1 // This file is imported from:
2 //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/Mangano/WWAnalysis/AnalysisStep/plugins/CalibratedPatElectronProducer.cc?revision=1.2&view=markup
3 
4 
5 // -*- C++ -*-
6 //
7 // Package: EgammaElectronProducers
8 // Class: CalibratedPatElectronProducer
9 //
18 //#if CMSSW_VERSION>500
19 
21 
29 
37 
39 
40 #include <iostream>
41 
43 {
44  produces<pat::ElectronCollection>();
45 
46  inputPatElectronsToken = consumes<edm::View<reco::Candidate> >(cfg.getParameter<edm::InputTag>("inputPatElectronsTag"));
47  dataset = cfg.getParameter<std::string>("inputDataset");
48  isMC = cfg.getParameter<bool>("isMC");
49  updateEnergyError = cfg.getParameter<bool>("updateEnergyError");
50  lumiRatio = cfg.getParameter<double>("lumiRatio");
51  correctionsType = cfg.getParameter<int>("correctionsType");
52  applyLinearityCorrection = cfg.getParameter<bool>("applyLinearityCorrection");
53  combinationType = cfg.getParameter<int>("combinationType");
54  verbose = cfg.getParameter<bool>("verbose");
55  synchronization = cfg.getParameter<bool>("synchronization");
56  combinationRegressionInputPath = cfg.getParameter<std::string>("combinationRegressionInputPath");
57  scaleCorrectionsInputPath = cfg.getParameter<std::string>("scaleCorrectionsInputPath");
58  linCorrectionsInputPath = cfg.getParameter<std::string>("linearityCorrectionsInputPath");
59 
60  //basic checks
61  if ( isMC && ( dataset != "Summer11" && dataset != "Fall11"
62  && dataset != "Summer12" && dataset != "Summer12_DR53X_HCP2012"
63  && dataset != "Summer12_LegacyPaper" ) )
64  {
65  throw cms::Exception("CalibratedPATElectronProducer|ConfigError") << "Unknown MC dataset";
66  }
67  if ( !isMC && ( dataset != "Prompt" && dataset != "ReReco"
68  && dataset != "Jan16ReReco" && dataset != "ICHEP2012"
69  && dataset != "Moriond2013" && dataset != "22Jan2013ReReco" ) )
70  {
71  throw cms::Exception("CalibratedPATElectronProducer|ConfigError") << "Unknown Data dataset";
72  }
73 
74  // Linearity correction only applied on combined momentum obtain with regression combination
75  if(combinationType!=3 && applyLinearityCorrection)
76  {
77  std::cout << "[CalibratedElectronProducer] "
78  << "Warning: you chose combinationType!=3 and applyLinearityCorrection=True. Linearity corrections are only applied on top of combination 3." << std::endl;
79  }
80 
81 
82  std::cout << "[CalibratedPATElectronProducer] Correcting scale for dataset " << dataset << std::endl;
83 
84  //initializations
85  std::string pathToDataCorr;
86  switch ( correctionsType )
87  {
88  case 0:
89  break;
90  case 1:
91  if ( verbose )
92  {
93  std::cout << "You choose regression 1 scale corrections" << std::endl;
94  }
95  break;
96  case 2:
97  if ( verbose )
98  {
99  std::cout << "You choose regression 2 scale corrections." << std::endl;
100  }
101  break;
102  case 3:
103  throw cms::Exception("CalibratedPATElectronProducer|ConfigError")
104  << "You choose standard non-regression ecal energy scale corrections. They are not implemented yet.";
105  break;
106  default:
107  throw cms::Exception("CalibratedPATElectronProducer|ConfigError")
108  << "Unknown correctionsType !!!";
109  }
110 
112  (
113  edm::FileInPath(scaleCorrectionsInputPath.c_str()).fullPath().c_str(),
114  edm::FileInPath(linCorrectionsInputPath.c_str()).fullPath().c_str(),
115  dataset,
118  lumiRatio,
119  isMC,
121  verbose,
123  );
124 
125  if ( verbose )
126  {
127  std::cout << "[CalibratedPATElectronProducer] "
128  << "ElectronEnergyCalibrator object is created " << std::endl;
129  }
130 
133  (
134  edm::FileInPath(combinationRegressionInputPath.c_str()).fullPath().c_str(),
135  "CombinationWeight"
136  );
137 
139 
140  if ( verbose )
141  {
142  std::cout << "[CalibratedPATElectronProducer] "
143  << "Combination tools are created and initialized " << std::endl;
144  }
145 }
146 
147 
148 
150 {}
151 
153 {
154 
156  event.getByToken(inputPatElectronsToken,oldElectrons) ;
157  std::auto_ptr<pat::ElectronCollection> electrons( new pat::ElectronCollection ) ;
158  pat::ElectronCollection::const_iterator electron ;
159  pat::ElectronCollection::iterator ele ;
160  // first clone the initial collection
161  for
162  (
163  edm::View<reco::Candidate>::const_iterator ele=oldElectrons->begin();
164  ele!=oldElectrons->end();
165  ++ele
166  )
167  {
168  const pat::ElectronRef elecsRef = edm::RefToBase<reco::Candidate>(oldElectrons,ele-oldElectrons->begin()).castTo<pat::ElectronRef>();
169  pat::Electron clone = *edm::RefToBase<reco::Candidate>(oldElectrons,ele-oldElectrons->begin()).castTo<pat::ElectronRef>();
170  electrons->push_back(clone);
171  }
172 
173  if (correctionsType != 0 )
174  {
175  for
176  (
177  ele = electrons->begin();
178  ele != electrons->end() ;
179  ++ele
180  )
181  {
182  int elClass = -1;
183  int run = event.run();
184 
185  float r9 = ele->r9();
186  double correctedEcalEnergy = ele->correctedEcalEnergy();
187  double correctedEcalEnergyError = ele->correctedEcalEnergyError();
188  double trackMomentum = ele->trackMomentumAtVtx().R();
189  double trackMomentumError = ele->trackMomentumError();
190  double combinedMomentum = ele->p();
191  double combinedMomentumError = 0;
192  if ( ele->candidateP4Kind() != reco::GsfElectron::P4_UNKNOWN )
193  {
194  combinedMomentumError = ele->p4Error(ele->candidateP4Kind());
195  }
196  // FIXME : p4Error not filled for pure tracker electrons
197  // Recompute it using the parametrization implemented in
198  // RecoEgamma/EgammaElectronAlgos/src/ElectronEnergyCorrector.cc::simpleParameterizationUncertainty()
199  if( !ele->ecalDrivenSeed() )
200  {
201  double error = 999. ;
202  double momentum = (combinedMomentum<15. ? 15. : combinedMomentum);
203  if ( ele->isEB() )
204  {
205  float parEB[3] = { 5.24e-02, 2.01e-01, 1.00e-02} ;
206  error = momentum * sqrt( pow(parEB[0]/sqrt(momentum),2) + pow(parEB[1]/momentum,2) + pow(parEB[2],2) );
207  }
208  else if ( ele->isEE() )
209  {
210  float parEE[3] = { 1.46e-01, 9.21e-01, 1.94e-03} ;
211  error = momentum * sqrt( pow(parEE[0]/sqrt(momentum),2) + pow(parEE[1]/momentum,2) + pow(parEE[2],2) );
212  }
213  combinedMomentumError = error;
214  }
215 
216  if (ele->classification() == reco::GsfElectron::GOLDEN) {elClass = 0;}
217  if (ele->classification() == reco::GsfElectron::BIGBREM) {elClass = 1;}
218  if (ele->classification() == reco::GsfElectron::BADTRACK) {elClass = 2;}
219  if (ele->classification() == reco::GsfElectron::SHOWERING) {elClass = 3;}
220  if (ele->classification() == reco::GsfElectron::GAP) {elClass = 4;}
221 
222  SimpleElectron mySimpleElectron
223  (
224  run,
225  elClass,
226  r9,
227  correctedEcalEnergy,
228  correctedEcalEnergyError,
229  trackMomentum,
230  trackMomentumError,
231  ele->ecalRegressionEnergy(),
232  ele->ecalRegressionError(),
233  combinedMomentum,
234  combinedMomentumError,
235  ele->superCluster()->eta(),
236  ele->isEB(),
237  isMC,
238  ele->ecalDriven(),
239  ele->trackerDrivenSeed()
240  );
241 
242  // energy calibration for ecalDriven electrons
243  if ( ele->core()->ecalDrivenSeed() || correctionsType==2 || combinationType==3 )
244  {
245  theEnCorrector->calibrate(mySimpleElectron, event.streamID());
246 
247  // E-p combination
248 
249  switch ( combinationType )
250  {
251  case 0:
252  if ( verbose )
253  {
254  std::cout << "[CalibratedPATElectronProducer] "
255  << "You choose not to combine." << std::endl;
256  }
257  break;
258  case 1:
259  if ( verbose )
260  {
261  std::cout << "[CalibratedPATElectronProducer] "
262  << "You choose corrected regression energy for standard combination" << std::endl;
263  }
265  myCombinator->combine(mySimpleElectron);
266  break;
267  case 2:
268  if ( verbose )
269  {
270  std::cout << "[CalibratedPATElectronProducer] "
271  << "You choose uncorrected regression energy for standard combination" << std::endl;
272  }
274  myCombinator->combine(mySimpleElectron);
275  break;
276  case 3:
277  if ( verbose )
278  {
279  std::cout << "[CalibratedPATElectronProducer] "
280  << "You choose regression combination." << std::endl;
281  }
282  myEpCombinationTool->combine(mySimpleElectron);
283  theEnCorrector->correctLinearity(mySimpleElectron);
284  break;
285  default:
286  throw cms::Exception("CalibratedPATElectronProducer|ConfigError")
287  << "Unknown combination Type !!!" ;
288  }
289 
290  math::XYZTLorentzVector oldMomentum = ele->p4() ;
291  math::XYZTLorentzVector newMomentum_ ;
292  newMomentum_ = math::XYZTLorentzVector
293  ( oldMomentum.x()*mySimpleElectron.getCombinedMomentum()/oldMomentum.t(),
294  oldMomentum.y()*mySimpleElectron.getCombinedMomentum()/oldMomentum.t(),
295  oldMomentum.z()*mySimpleElectron.getCombinedMomentum()/oldMomentum.t(),
296  mySimpleElectron.getCombinedMomentum() ) ;
297 
298  ele->correctMomentum
299  (
300  newMomentum_,
301  mySimpleElectron.getTrackerMomentumError(),
302  mySimpleElectron.getCombinedMomentumError()
303  );
304 
305  if ( verbose )
306  {
307  std::cout << "[CalibratedPATElectronProducer] Combined momentum after saving "
308  << ele->p4().t() << std::endl;
309  }
310  }// end of if (ele.core()->ecalDrivenSeed())
311  }// end of loop on electrons
312  } else
313  {
314  if ( verbose )
315  {
316  std::cout << "[CalibratedPATElectronProducer] "
317  << "You choose not to correct. Uncorrected Regression Energy is taken." << std::endl;
318  }
319  }
320  // Save the electrons
321  event.put(electrons) ;
322 }
323 
edm::EDGetTokenT< edm::View< reco::Candidate > > inputPatElectronsToken
T getParameter(std::string const &) const
tuple cfg
Definition: looper.py:293
virtual void produce(edm::Event &, const edm::EventSetup &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool init(const GBRForest *forest)
void combine(SimpleElectron &mySimpleElectron) const
void calibrate(SimpleElectron &electron, edm::StreamID const &)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
CalibratedPatElectronProducer(const edm::ParameterSet &)
std::vector< Electron > ElectronCollection
Definition: Electron.h:37
T sqrt(T t)
Definition: SSEVec.h:18
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
void correctLinearity(SimpleElectron &electron)
void setCombinationMode(int mode)
Analysis-level electron class.
Definition: Electron.h:52
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
StreamID streamID() const
Definition: Event.h:80
void combine(SimpleElectron &electron)
const_iterator begin() const
first daughter const_iterator
Definition: Candidate.h:144
ElectronEnergyCalibrator * theEnCorrector
tuple cout
Definition: gather_cfg.py:145
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40