CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
CalibratedPatElectronProducer Class Reference

#include <CalibratedPatElectronProducer.h>

Inheritance diagram for CalibratedPatElectronProducer:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

Public Member Functions

 CalibratedPatElectronProducer (const edm::ParameterSet &)
 
virtual void produce (edm::Event &, const edm::EventSetup &)
 
virtual ~CalibratedPatElectronProducer ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 

Private Attributes

bool applyLinearityCorrection
 
std::string combinationRegressionInputPath
 
int combinationType
 
int correctionsType
 
std::string dataset
 
edm::InputTag inputPatElectrons
 
bool isAOD
 
bool isMC
 
std::string linCorrectionsInputPath
 
double lumiRatio
 
ElectronEPcombinatormyCombinator
 
EpCombinationToolmyEpCombinationTool
 
std::string scaleCorrectionsInputPath
 
bool synchronization
 
ElectronEnergyCalibratortheEnCorrector
 
bool updateEnergyError
 
bool verbose
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 

Detailed Description

Description: EDProducer of PatElectron objects

Implementation: <Notes on="" implementation>="">

Definition at line 19 of file CalibratedPatElectronProducer.h.

Constructor & Destructor Documentation

CalibratedPatElectronProducer::CalibratedPatElectronProducer ( const edm::ParameterSet cfg)
explicit

Definition at line 49 of file CalibratedPatElectronProducer.cc.

References gather_cfg::cout, dataset::dataset, edm::hlt::Exception, edm::ParameterSet::getParameter(), and validate_alignment_devdb10_cfg::verbose.

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 
120  (
121  edm::FileInPath(scaleCorrectionsInputPath.c_str()).fullPath().c_str(),
122  edm::FileInPath(linCorrectionsInputPath.c_str()).fullPath().c_str(),
123  dataset,
126  lumiRatio,
127  isMC,
129  verbose,
131  );
132 
133  if ( verbose )
134  {
135  std::cout << "[CalibratedPATElectronProducer] "
136  << "ElectronEnergyCalibrator object is created " << std::endl;
137  }
138 
141  (
142  edm::FileInPath(combinationRegressionInputPath.c_str()).fullPath().c_str(),
143  "CombinationWeight"
144  );
145 
147 
148  if ( verbose )
149  {
150  std::cout << "[CalibratedPATElectronProducer] "
151  << "Combination tools are created and initialized " << std::endl;
152  }
153 }
T getParameter(std::string const &) const
bool init(const std::string &regressionFile, const std::string &bdtName="")
ElectronEnergyCalibrator * theEnCorrector
tuple cout
Definition: gather_cfg.py:121
CalibratedPatElectronProducer::~CalibratedPatElectronProducer ( )
virtual

Definition at line 157 of file CalibratedPatElectronProducer.cc.

158 {}

Member Function Documentation

void CalibratedPatElectronProducer::produce ( edm::Event event,
const edm::EventSetup setup 
)
virtual

Implements edm::EDProducer.

Definition at line 160 of file CalibratedPatElectronProducer.cc.

References reco::GsfElectron::BADTRACK, reco::Candidate::begin(), reco::GsfElectron::BIGBREM, clone(), gather_cfg::cout, metsig::electron, HI_PhotonSkim_cff::electrons, error, edm::hlt::Exception, reco::GsfElectron::GAP, reco::GsfElectron::GOLDEN, funct::pow(), DTTTrigCorrFirst::run, reco::GsfElectron::SHOWERING, mathSSE::sqrt(), and reco::btau::trackMomentum.

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), and HTMLExport.HTMLExportStatic::export().

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  }
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  }
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 }
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
void calibrate(SimpleElectron &electron)
void combine(SimpleElectron &mySimpleElectron)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
T sqrt(T t)
Definition: SSEVec.h:46
std::vector< Electron > ElectronCollection
collectin of Electron objects
Definition: ElectronFwd.h:9
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
virtual const_iterator begin() const =0
first daughter const_iterator
void combine(SimpleElectron &electron)
ElectronEnergyCalibrator * theEnCorrector
tuple cout
Definition: gather_cfg.py:121
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40

Member Data Documentation

bool CalibratedPatElectronProducer::applyLinearityCorrection
private

Definition at line 33 of file CalibratedPatElectronProducer.h.

std::string CalibratedPatElectronProducer::combinationRegressionInputPath
private

Definition at line 38 of file CalibratedPatElectronProducer.h.

int CalibratedPatElectronProducer::combinationType
private

Definition at line 34 of file CalibratedPatElectronProducer.h.

int CalibratedPatElectronProducer::correctionsType
private

Definition at line 32 of file CalibratedPatElectronProducer.h.

std::string CalibratedPatElectronProducer::dataset
private

Definition at line 28 of file CalibratedPatElectronProducer.h.

edm::InputTag CalibratedPatElectronProducer::inputPatElectrons
private

Definition at line 27 of file CalibratedPatElectronProducer.h.

bool CalibratedPatElectronProducer::isAOD
private

Definition at line 29 of file CalibratedPatElectronProducer.h.

bool CalibratedPatElectronProducer::isMC
private

Definition at line 30 of file CalibratedPatElectronProducer.h.

std::string CalibratedPatElectronProducer::linCorrectionsInputPath
private

Definition at line 40 of file CalibratedPatElectronProducer.h.

double CalibratedPatElectronProducer::lumiRatio
private

Definition at line 37 of file CalibratedPatElectronProducer.h.

ElectronEPcombinator* CalibratedPatElectronProducer::myCombinator
private

Definition at line 44 of file CalibratedPatElectronProducer.h.

EpCombinationTool* CalibratedPatElectronProducer::myEpCombinationTool
private

Definition at line 43 of file CalibratedPatElectronProducer.h.

std::string CalibratedPatElectronProducer::scaleCorrectionsInputPath
private

Definition at line 39 of file CalibratedPatElectronProducer.h.

bool CalibratedPatElectronProducer::synchronization
private

Definition at line 36 of file CalibratedPatElectronProducer.h.

ElectronEnergyCalibrator* CalibratedPatElectronProducer::theEnCorrector
private

Definition at line 42 of file CalibratedPatElectronProducer.h.

bool CalibratedPatElectronProducer::updateEnergyError
private

Definition at line 31 of file CalibratedPatElectronProducer.h.

bool CalibratedPatElectronProducer::verbose
private