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
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 (const std::string &iProcessName, std::vector< const char * > &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
 
- 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 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 = 0;
198  if ( ele->candidateP4Kind() != GsfElectron::P4_UNKNOWN )
199  {
200  combinedMomentumError = ele->p4Error(ele->candidateP4Kind());
201  }
202  // FIXME : p4Error not filled for pure tracker electrons
203  // Recompute it using the parametrization implemented in
204  // RecoEgamma/EgammaElectronAlgos/src/ElectronEnergyCorrector.cc::simpleParameterizationUncertainty()
205  if( !ele->ecalDrivenSeed() )
206  {
207  double error = 999. ;
208  double momentum = (combinedMomentum<15. ? 15. : combinedMomentum);
209  if ( ele->isEB() )
210  {
211  float parEB[3] = { 5.24e-02, 2.01e-01, 1.00e-02} ;
212  error = momentum * sqrt( pow(parEB[0]/sqrt(momentum),2) + pow(parEB[1]/momentum,2) + pow(parEB[2],2) );
213  }
214  else if ( ele->isEE() )
215  {
216  float parEE[3] = { 1.46e-01, 9.21e-01, 1.94e-03} ;
217  error = momentum * sqrt( pow(parEE[0]/sqrt(momentum),2) + pow(parEE[1]/momentum,2) + pow(parEE[2],2) );
218  }
219  combinedMomentumError = error;
220  }
221 
222  if (ele->classification() == reco::GsfElectron::GOLDEN) {elClass = 0;}
223  if (ele->classification() == reco::GsfElectron::BIGBREM) {elClass = 1;}
224  if (ele->classification() == reco::GsfElectron::BADTRACK) {elClass = 2;}
225  if (ele->classification() == reco::GsfElectron::SHOWERING) {elClass = 3;}
226  if (ele->classification() == reco::GsfElectron::GAP) {elClass = 4;}
227 
228  SimpleElectron mySimpleElectron
229  (
230  run,
231  elClass,
232  r9,
233  correctedEcalEnergy,
234  correctedEcalEnergyError,
235  trackMomentum,
236  trackMomentumError,
237  ele->ecalRegressionEnergy(),
238  ele->ecalRegressionError(),
239  combinedMomentum,
240  combinedMomentumError,
241  ele->superCluster()->eta(),
242  ele->isEB(),
243  isMC,
244  ele->ecalDriven(),
245  ele->trackerDrivenSeed()
246  );
247 
248  // energy calibration for ecalDriven electrons
249  if ( ele->core()->ecalDrivenSeed() || correctionsType==2 || combinationType==3 )
250  {
251  theEnCorrector->calibrate(mySimpleElectron, event.streamID());
252 
253  // E-p combination
254 
255  switch ( combinationType )
256  {
257  case 0:
258  if ( verbose )
259  {
260  std::cout << "[CalibratedPATElectronProducer] "
261  << "You choose not to combine." << std::endl;
262  }
263  break;
264  case 1:
265  if ( verbose )
266  {
267  std::cout << "[CalibratedPATElectronProducer] "
268  << "You choose corrected regression energy for standard combination" << std::endl;
269  }
271  myCombinator->combine(mySimpleElectron);
272  break;
273  case 2:
274  if ( verbose )
275  {
276  std::cout << "[CalibratedPATElectronProducer] "
277  << "You choose uncorrected regression energy for standard combination" << std::endl;
278  }
280  myCombinator->combine(mySimpleElectron);
281  break;
282  case 3:
283  if ( verbose )
284  {
285  std::cout << "[CalibratedPATElectronProducer] "
286  << "You choose regression combination." << std::endl;
287  }
288  myEpCombinationTool->combine(mySimpleElectron);
289  theEnCorrector->correctLinearity(mySimpleElectron);
290  break;
291  default:
292  throw cms::Exception("CalibratedPATElectronProducer|ConfigError")
293  << "Unknown combination Type !!!" ;
294  }
295 
296  math::XYZTLorentzVector oldMomentum = ele->p4() ;
297  math::XYZTLorentzVector newMomentum_ ;
298  newMomentum_ = math::XYZTLorentzVector
299  ( oldMomentum.x()*mySimpleElectron.getCombinedMomentum()/oldMomentum.t(),
300  oldMomentum.y()*mySimpleElectron.getCombinedMomentum()/oldMomentum.t(),
301  oldMomentum.z()*mySimpleElectron.getCombinedMomentum()/oldMomentum.t(),
302  mySimpleElectron.getCombinedMomentum() ) ;
303 
304  ele->correctMomentum
305  (
306  newMomentum_,
307  mySimpleElectron.getTrackerMomentumError(),
308  mySimpleElectron.getCombinedMomentumError()
309  );
310 
311  if ( verbose )
312  {
313  std::cout << "[CalibratedPATElectronProducer] Combined momentum after saving "
314  << ele->p4().t() << std::endl;
315  }
316  }// end of if (ele.core()->ecalDrivenSeed())
317  }// end of loop on electrons
318  } else
319  {
320  if ( verbose )
321  {
322  std::cout << "[CalibratedPATElectronProducer] "
323  << "You choose not to correct. Uncorrected Regression Energy is taken." << std::endl;
324  }
325  }
326  // Save the electrons
327  event.put(electrons) ;
328 }
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
StreamID streamID() const
Definition: Event.h:72
void combine(SimpleElectron &electron)
const_iterator begin() const
first daughter const_iterator
Definition: Candidate.h:144
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