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