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 
39 
41 
42 #include <iostream>
43 
44 using namespace edm ;
45 using namespace std ;
46 using namespace reco ;
47 using namespace pat ;
48 
50 // : PatElectronBaseProducer(cfg)
51 {
52  produces<ElectronCollection>();
53 
54  inputPatElectrons = cfg.getParameter<edm::InputTag>("inputPatElectronsTag");
55  dataset = cfg.getParameter<std::string>("inputDataset");
56  isMC = cfg.getParameter<bool>("isMC");
57  updateEnergyError = cfg.getParameter<bool>("updateEnergyError");
58  lumiRatio = cfg.getParameter<double>("lumiRatio");
59  correctionsType = cfg.getParameter<int>("correctionsType");
60  applyLinearityCorrection = cfg.getParameter<bool>("applyLinearityCorrection");
61  combinationType = cfg.getParameter<int>("combinationType");
62  verbose = cfg.getParameter<bool>("verbose");
63  synchronization = cfg.getParameter<bool>("synchronization");
64  combinationRegressionInputPath = cfg.getParameter<std::string>("combinationRegressionInputPath");
65  scaleCorrectionsInputPath = cfg.getParameter<std::string>("scaleCorrectionsInputPath");
66  linCorrectionsInputPath = cfg.getParameter<std::string>("linearityCorrectionsInputPath");
67 
68  //basic checks
69  if ( isMC && ( dataset != "Summer11" && dataset != "Fall11"
70  && dataset != "Summer12" && dataset != "Summer12_DR53X_HCP2012"
71  && dataset != "Summer12_LegacyPaper" ) )
72  {
73  throw cms::Exception("CalibratedPATElectronProducer|ConfigError") << "Unknown MC dataset";
74  }
75  if ( !isMC && ( dataset != "Prompt" && dataset != "ReReco"
76  && dataset != "Jan16ReReco" && dataset != "ICHEP2012"
77  && dataset != "Moriond2013" && dataset != "22Jan2013ReReco" ) )
78  {
79  throw cms::Exception("CalibratedPATElectronProducer|ConfigError") << "Unknown Data dataset";
80  }
81 
82  // Linearity correction only applied on combined momentum obtain with regression combination
83  if(combinationType!=3 && applyLinearityCorrection)
84  {
85  std::cout << "[CalibratedElectronProducer] "
86  << "Warning: you chose combinationType!=3 and applyLinearityCorrection=True. Linearity corrections are only applied on top of combination 3." << std::endl;
87  }
88 
89 
90  std::cout << "[CalibratedPATElectronProducer] Correcting scale for dataset " << dataset << std::endl;
91 
92  //initializations
93  std::string pathToDataCorr;
94  switch ( correctionsType )
95  {
96  case 0:
97  break;
98  case 1:
99  if ( verbose )
100  {
101  std::cout << "You choose regression 1 scale corrections" << std::endl;
102  }
103  break;
104  case 2:
105  if ( verbose )
106  {
107  std::cout << "You choose regression 2 scale corrections." << std::endl;
108  }
109  break;
110  case 3:
111  throw cms::Exception("CalibratedPATElectronProducer|ConfigError")
112  << "You choose standard non-regression ecal energy scale corrections. They are not implemented yet.";
113  break;
114  default:
115  throw cms::Exception("CalibratedPATElectronProducer|ConfigError")
116  << "Unknown correctionsType !!!";
117  }
118 
119  theEnCorrector = new ElectronEnergyCalibrator
120  (
121  edm::FileInPath(scaleCorrectionsInputPath.c_str()).fullPath().c_str(),
122  edm::FileInPath(linCorrectionsInputPath.c_str()).fullPath().c_str(),
123  dataset,
124  correctionsType,
125  applyLinearityCorrection,
126  lumiRatio,
127  isMC,
128  updateEnergyError,
129  verbose,
130  synchronization
131  );
132 
133  if ( verbose )
134  {
135  std::cout << "[CalibratedPATElectronProducer] "
136  << "ElectronEnergyCalibrator object is created " << std::endl;
137  }
138 
139  myEpCombinationTool = new EpCombinationTool();
140  myEpCombinationTool->init
141  (
142  edm::FileInPath(combinationRegressionInputPath.c_str()).fullPath().c_str(),
143  "CombinationWeight"
144  );
145 
146  myCombinator = new ElectronEPcombinator();
147 
148  if ( verbose )
149  {
150  std::cout << "[CalibratedPATElectronProducer] "
151  << "Combination tools are created and initialized " << std::endl;
152  }
153 }
154 
155 
156 
158 {}
159 
161 {
162 
164  event.getByLabel(inputPatElectrons,oldElectrons) ;
165  std::auto_ptr<ElectronCollection> electrons( new ElectronCollection ) ;
166  ElectronCollection::const_iterator electron ;
167  ElectronCollection::iterator ele ;
168  // first clone the initial collection
169  for
170  (
171  edm::View<reco::Candidate>::const_iterator ele=oldElectrons->begin();
172  ele!=oldElectrons->end();
173  ++ele
174  )
175  {
176  const pat::ElectronRef elecsRef = edm::RefToBase<reco::Candidate>(oldElectrons,ele-oldElectrons->begin()).castTo<pat::ElectronRef>();
177  pat::Electron clone = *edm::RefToBase<reco::Candidate>(oldElectrons,ele-oldElectrons->begin()).castTo<pat::ElectronRef>();
178  electrons->push_back(clone);
179  }
180 
181  if (correctionsType != 0 )
182  {
183  for
184  (
185  ele = electrons->begin();
186  ele != electrons->end() ;
187  ++ele
188  )
189  {
190  int elClass = -1;
191  int run = event.run();
192 
193  float r9 = ele->r9();
194  double correctedEcalEnergy = ele->correctedEcalEnergy();
195  double correctedEcalEnergyError = ele->correctedEcalEnergyError();
196  double trackMomentum = ele->trackMomentumAtVtx().R();
197  double trackMomentumError = ele->trackMomentumError();
198  double combinedMomentum = ele->p();
199  double combinedMomentumError = ele->p4Error(ele->candidateP4Kind());
200  // FIXME : p4Error not filled for pure tracker electrons
201  // Recompute it using the parametrization implemented in
202  // RecoEgamma/EgammaElectronAlgos/src/ElectronEnergyCorrector.cc::simpleParameterizationUncertainty()
203  if( !ele->ecalDrivenSeed() )
204  {
205  double error = 999. ;
206  double momentum = (combinedMomentum<15. ? 15. : combinedMomentum);
207  if ( ele->isEB() )
208  {
209  float parEB[3] = { 5.24e-02, 2.01e-01, 1.00e-02} ;
210  error = momentum * sqrt( pow(parEB[0]/sqrt(momentum),2) + pow(parEB[1]/momentum,2) + pow(parEB[2],2) );
211  }
212  else if ( ele->isEE() )
213  {
214  float parEE[3] = { 1.46e-01, 9.21e-01, 1.94e-03} ;
215  error = momentum * sqrt( pow(parEE[0]/sqrt(momentum),2) + pow(parEE[1]/momentum,2) + pow(parEE[2],2) );
216  }
217  combinedMomentumError = error;
218  }
219 
220  if (ele->classification() == reco::GsfElectron::GOLDEN) {elClass = 0;}
221  if (ele->classification() == reco::GsfElectron::BIGBREM) {elClass = 1;}
222  if (ele->classification() == reco::GsfElectron::BADTRACK) {elClass = 2;}
223  if (ele->classification() == reco::GsfElectron::SHOWERING) {elClass = 3;}
224  if (ele->classification() == reco::GsfElectron::GAP) {elClass = 4;}
225 
226  SimpleElectron mySimpleElectron
227  (
228  run,
229  elClass,
230  r9,
231  correctedEcalEnergy,
232  correctedEcalEnergyError,
233  trackMomentum,
234  trackMomentumError,
235  ele->ecalRegressionEnergy(),
236  ele->ecalRegressionError(),
237  combinedMomentum,
238  combinedMomentumError,
239  ele->superCluster()->eta(),
240  ele->isEB(),
241  isMC,
242  ele->ecalDriven(),
243  ele->trackerDrivenSeed()
244  );
245 
246  // energy calibration for ecalDriven electrons
247  if ( ele->core()->ecalDrivenSeed() || correctionsType==2 || combinationType==3 )
248  {
249  theEnCorrector->calibrate(mySimpleElectron);
250 
251  // E-p combination
252 
253  switch ( combinationType )
254  {
255  case 0:
256  if ( verbose )
257  {
258  std::cout << "[CalibratedPATElectronProducer] "
259  << "You choose not to combine." << std::endl;
260  }
261  break;
262  case 1:
263  if ( verbose )
264  {
265  std::cout << "[CalibratedPATElectronProducer] "
266  << "You choose corrected regression energy for standard combination" << std::endl;
267  }
268  myCombinator->setCombinationMode(1);
269  myCombinator->combine(mySimpleElectron);
270  break;
271  case 2:
272  if ( verbose )
273  {
274  std::cout << "[CalibratedPATElectronProducer] "
275  << "You choose uncorrected regression energy for standard combination" << std::endl;
276  }
277  myCombinator->setCombinationMode(2);
278  myCombinator->combine(mySimpleElectron);
279  break;
280  case 3:
281  if ( verbose )
282  {
283  std::cout << "[CalibratedPATElectronProducer] "
284  << "You choose regression combination." << std::endl;
285  }
286  myEpCombinationTool->combine(mySimpleElectron);
287  theEnCorrector->correctLinearity(mySimpleElectron);
288  break;
289  default:
290  throw cms::Exception("CalibratedPATElectronProducer|ConfigError")
291  << "Unknown combination Type !!!" ;
292  }
293 
294  math::XYZTLorentzVector oldMomentum = ele->p4() ;
295  math::XYZTLorentzVector newMomentum_ ;
296  newMomentum_ = math::XYZTLorentzVector
297  ( oldMomentum.x()*mySimpleElectron.getCombinedMomentum()/oldMomentum.t(),
298  oldMomentum.y()*mySimpleElectron.getCombinedMomentum()/oldMomentum.t(),
299  oldMomentum.z()*mySimpleElectron.getCombinedMomentum()/oldMomentum.t(),
300  mySimpleElectron.getCombinedMomentum() ) ;
301 
302  ele->correctMomentum
303  (
304  newMomentum_,
305  mySimpleElectron.getTrackerMomentumError(),
306  mySimpleElectron.getCombinedMomentumError()
307  );
308 
309  if ( verbose )
310  {
311  std::cout << "[CalibratedPATElectronProducer] Combined momentum after saving "
312  << ele->p4().t() << std::endl;
313  }
314  }// end of if (ele.core()->ecalDrivenSeed())
315  }// end of loop on electrons
316  } else
317  {
318  if ( verbose )
319  {
320  std::cout << "[CalibratedPATElectronProducer] "
321  << "You choose not to correct. Uncorrected Regression Energy is taken." << std::endl;
322  }
323  }
324  // Save the electrons
325  event.put(electrons) ;
326 }
327 
T getParameter(std::string const &) const
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
virtual void produce(edm::Event &, const edm::EventSetup &)
DEFINE_FWK_MODULE(HiMixingModule)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
CalibratedPatElectronProducer(const edm::ParameterSet &)
T sqrt(T t)
Definition: SSEVec.h:46
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
std::vector< Electron > ElectronCollection
collectin of Electron objects
Definition: ElectronFwd.h:9
tuple dataset
Definition: dataset.py:393
Analysis-level electron class.
Definition: Electron.h:52
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
virtual const_iterator begin() const =0
first daughter const_iterator
tuple cout
Definition: gather_cfg.py:121
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40