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::EDConsumerBase 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 ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Attributes

bool applyLinearityCorrection
 
std::string combinationRegressionInputPath
 
int combinationType
 
int correctionsType
 
std::string dataset
 
edm::EDGetTokenT< edm::View
< reco::Candidate > > 
inputPatElectronsToken
 
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
 
- 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::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Description: EDProducer of PatElectron objects

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

Definition at line 20 of file CalibratedPatElectronProducer.h.

Constructor & Destructor Documentation

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

Definition at line 47 of file CalibratedPatElectronProducer.cc.

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

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
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 
118  (
121  dataset,
124  lumiRatio,
125  isMC,
127  verbose,
129  );
130 
131  if ( verbose )
132  {
133  std::cout << "[CalibratedPATElectronProducer] "
134  << "ElectronEnergyCalibrator object is created " << std::endl;
135  }
136 
139  (
141  "CombinationWeight"
142  );
143 
145 
146  if ( verbose )
147  {
148  std::cout << "[CalibratedPATElectronProducer] "
149  << "Combination tools are created and initialized " << std::endl;
150  }
151 }
edm::EDGetTokenT< edm::View< reco::Candidate > > inputPatElectronsToken
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 155 of file CalibratedPatElectronProducer.cc.

156 {}

Member Function Documentation

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

Implements edm::EDProducer.

Definition at line 158 of file CalibratedPatElectronProducer.cc.

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

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

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  }
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  }
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 }
edm::EDGetTokenT< edm::View< reco::Candidate > > inputPatElectronsToken
void combine(SimpleElectron &mySimpleElectron)
void calibrate(SimpleElectron &electron, edm::StreamID const &)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
T sqrt(T t)
Definition: SSEVec.h:48
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
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
virtual const_iterator begin() const =0
first daughter const_iterator
StreamID streamID() const
Definition: Event.h:72
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 34 of file CalibratedPatElectronProducer.h.

std::string CalibratedPatElectronProducer::combinationRegressionInputPath
private

Definition at line 39 of file CalibratedPatElectronProducer.h.

int CalibratedPatElectronProducer::combinationType
private

Definition at line 35 of file CalibratedPatElectronProducer.h.

int CalibratedPatElectronProducer::correctionsType
private

Definition at line 33 of file CalibratedPatElectronProducer.h.

std::string CalibratedPatElectronProducer::dataset
private

Definition at line 29 of file CalibratedPatElectronProducer.h.

edm::EDGetTokenT<edm::View<reco::Candidate> > CalibratedPatElectronProducer::inputPatElectronsToken
private

Definition at line 28 of file CalibratedPatElectronProducer.h.

bool CalibratedPatElectronProducer::isAOD
private

Definition at line 30 of file CalibratedPatElectronProducer.h.

bool CalibratedPatElectronProducer::isMC
private
std::string CalibratedPatElectronProducer::linCorrectionsInputPath
private

Definition at line 41 of file CalibratedPatElectronProducer.h.

double CalibratedPatElectronProducer::lumiRatio
private

Definition at line 38 of file CalibratedPatElectronProducer.h.

ElectronEPcombinator* CalibratedPatElectronProducer::myCombinator
private

Definition at line 45 of file CalibratedPatElectronProducer.h.

EpCombinationTool* CalibratedPatElectronProducer::myEpCombinationTool
private

Definition at line 44 of file CalibratedPatElectronProducer.h.

std::string CalibratedPatElectronProducer::scaleCorrectionsInputPath
private

Definition at line 40 of file CalibratedPatElectronProducer.h.

bool CalibratedPatElectronProducer::synchronization
private

Definition at line 37 of file CalibratedPatElectronProducer.h.

ElectronEnergyCalibrator* CalibratedPatElectronProducer::theEnCorrector
private

Definition at line 43 of file CalibratedPatElectronProducer.h.

bool CalibratedPatElectronProducer::updateEnergyError
private

Definition at line 32 of file CalibratedPatElectronProducer.h.

bool CalibratedPatElectronProducer::verbose
private