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
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 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
std::vector< ConsumesInfoconsumesInfo () const
 
 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 (std::string const &iProcessName, std::string const &iModuleLabel, bool iPrint, std::vector< char const * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) 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
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- 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::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 42 of file CalibratedPatElectronProducer.cc.

References applyLinearityCorrection, combinationRegressionInputPath, combinationType, correctionsType, gather_cfg::cout, dataset, Exception, contentValuesFiles::fullPath, edm::ParameterSet::getParameter(), EpCombinationTool::init(), inputPatElectronsToken, isMC, linCorrectionsInputPath, lumiRatio, myCombinator, myEpCombinationTool, scaleCorrectionsInputPath, AlCaHLTBitMon_QueryRunRegistry::string, synchronization, theEnCorrector, updateEnergyError, and verbose.

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
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  (
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  (
135  "CombinationWeight"
136  );
137 
139 
140  if ( verbose )
141  {
142  std::cout << "[CalibratedPATElectronProducer] "
143  << "Combination tools are created and initialized " << std::endl;
144  }
145 }
edm::EDGetTokenT< edm::View< reco::Candidate > > inputPatElectronsToken
T getParameter(std::string const &) const
bool init(const GBRForest *forest)
ElectronEnergyCalibrator * theEnCorrector
tuple cout
Definition: gather_cfg.py:145
CalibratedPatElectronProducer::~CalibratedPatElectronProducer ( )
virtual

Definition at line 149 of file CalibratedPatElectronProducer.cc.

150 {}

Member Function Documentation

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

Implements edm::EDProducer.

Definition at line 152 of file CalibratedPatElectronProducer.cc.

References reco::GsfElectron::BADTRACK, reco::Candidate::begin(), reco::GsfElectron::BIGBREM, ElectronEnergyCalibrator::calibrate(), clone(), combinationType, ElectronEPcombinator::combine(), EpCombinationTool::combine(), correctionsType, ElectronEnergyCalibrator::correctLinearity(), gather_cfg::cout, metsig::electron, HI_PhotonSkim_cff::electrons, relativeConstraints::error, Exception, reco::GsfElectron::GAP, reco::GsfElectron::GOLDEN, inputPatElectronsToken, isMC, myCombinator, myEpCombinationTool, reco::GsfElectron::P4_UNKNOWN, funct::pow(), DTTTrigCorrFirst::run, ElectronEPcombinator::setCombinationMode(), reco::GsfElectron::SHOWERING, mathSSE::sqrt(), edm::Event::streamID(), theEnCorrector, and reco::btau::trackMomentum.

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

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 }
edm::EDGetTokenT< edm::View< reco::Candidate > > inputPatElectronsToken
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
std::vector< Electron > ElectronCollection
Definition: Electron.h:37
T sqrt(T t)
Definition: SSEVec.h:18
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

Member Data Documentation

bool CalibratedPatElectronProducer::applyLinearityCorrection
private

Definition at line 34 of file CalibratedPatElectronProducer.h.

Referenced by CalibratedPatElectronProducer().

std::string CalibratedPatElectronProducer::combinationRegressionInputPath
private

Definition at line 39 of file CalibratedPatElectronProducer.h.

Referenced by CalibratedPatElectronProducer().

int CalibratedPatElectronProducer::combinationType
private

Definition at line 35 of file CalibratedPatElectronProducer.h.

Referenced by CalibratedPatElectronProducer(), and produce().

int CalibratedPatElectronProducer::correctionsType
private

Definition at line 33 of file CalibratedPatElectronProducer.h.

Referenced by CalibratedPatElectronProducer(), and produce().

std::string CalibratedPatElectronProducer::dataset
private
edm::EDGetTokenT<edm::View<reco::Candidate> > CalibratedPatElectronProducer::inputPatElectronsToken
private

Definition at line 28 of file CalibratedPatElectronProducer.h.

Referenced by CalibratedPatElectronProducer(), and produce().

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.

Referenced by CalibratedPatElectronProducer().

double CalibratedPatElectronProducer::lumiRatio
private

Definition at line 38 of file CalibratedPatElectronProducer.h.

Referenced by CalibratedPatElectronProducer().

ElectronEPcombinator* CalibratedPatElectronProducer::myCombinator
private

Definition at line 45 of file CalibratedPatElectronProducer.h.

Referenced by CalibratedPatElectronProducer(), and produce().

EpCombinationTool* CalibratedPatElectronProducer::myEpCombinationTool
private

Definition at line 44 of file CalibratedPatElectronProducer.h.

Referenced by CalibratedPatElectronProducer(), and produce().

std::string CalibratedPatElectronProducer::scaleCorrectionsInputPath
private

Definition at line 40 of file CalibratedPatElectronProducer.h.

Referenced by CalibratedPatElectronProducer().

bool CalibratedPatElectronProducer::synchronization
private

Definition at line 37 of file CalibratedPatElectronProducer.h.

Referenced by CalibratedPatElectronProducer().

ElectronEnergyCalibrator* CalibratedPatElectronProducer::theEnCorrector
private

Definition at line 43 of file CalibratedPatElectronProducer.h.

Referenced by CalibratedPatElectronProducer(), and produce().

bool CalibratedPatElectronProducer::updateEnergyError
private

Definition at line 32 of file CalibratedPatElectronProducer.h.

Referenced by CalibratedPatElectronProducer().

bool CalibratedPatElectronProducer::verbose
private