CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
MCElectronAnalyzer Class Reference

#include <MCElectronAnalyzer.h>

Inheritance diagram for MCElectronAnalyzer:
edm::one::EDAnalyzer<> edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginJob () override
 
void endJob () override
 
 MCElectronAnalyzer (const edm::ParameterSet &)
 
 ~MCElectronAnalyzer () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer<>
 EDAnalyzer ()=default
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

float etaTransformation (float a, float b)
 
float phiNormalization (float &a)
 

Private Attributes

TFile * fOutputFile_
 
std::string fOutputFileName_
 
TH1F * h_BremEnergy_
 
TH1F * h_BremFrac_
 
TH1F * h_MCEleE_
 
TH1F * h_MCEleEta_
 
TH1F * h_MCElePhi_
 
std::string HepMCLabel
 
double mcEta_
 
double mcPhi_
 global variable for the MC photon More...
 
int nEvt_
 
int nMatched_
 
TProfile * p_BremVsEta_
 
TProfile * p_BremVsR_
 
std::string SimHitLabel
 
std::string SimTkLabel
 
std::string SimVtxLabel
 
ElectronMCTruthFindertheElectronMCTruthFinder_
 
const TrackerGeometrytrackerGeom
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
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

Definition at line 20 of file MCElectronAnalyzer.h.

Constructor & Destructor Documentation

MCElectronAnalyzer::MCElectronAnalyzer ( const edm::ParameterSet pset)
explicit

Definition at line 41 of file MCElectronAnalyzer.cc.

42  : fOutputFileName_(pset.getUntrackedParameter<string>("HistOutFile", std::string("TestConversions.root"))),
43  fOutputFile_(nullptr) {}
T getUntrackedParameter(std::string const &, T const &) const
std::string fOutputFileName_
MCElectronAnalyzer::~MCElectronAnalyzer ( )
override

Definition at line 45 of file MCElectronAnalyzer.cc.

References theElectronMCTruthFinder_.

45 { delete theElectronMCTruthFinder_; }
ElectronMCTruthFinder * theElectronMCTruthFinder_

Member Function Documentation

void MCElectronAnalyzer::analyze ( const edm::Event e,
const edm::EventSetup  
)
override

Definition at line 120 of file MCElectronAnalyzer.cc.

References gather_cfg::cout, ElectronMCTruthFinder::find(), edm::Event::getByLabel(), h_BremEnergy_, h_BremFrac_, h_MCEleE_, h_MCEleEta_, h_MCElePhi_, edm::EventBase::id(), nEvt_, p_BremVsEta_, p_BremVsR_, and theElectronMCTruthFinder_.

120  {
121  using namespace edm;
122  //const float etaPhiDistance=0.01;
123  // Fiducial region
124  //const float TRK_BARL =0.9;
125  //const float BARL = 1.4442; // DAQ TDR p.290
126  //const float END_LO = 1.566;
127  //const float END_HI = 2.5;
128  // Electron mass
129  //const Float_t mElec= 0.000511;
130 
131  nEvt_++;
132  LogInfo("MCElectronAnalyzer") << "MCElectronAnalyzer Analyzing event number: " << e.id() << " Global Counter "
133  << nEvt_ << "\n";
134  // LogDebug("MCElectronAnalyzer") << "MCElectronAnalyzer Analyzing event number: " << e.id() << " Global Counter " << nEvt_ <<"\n";
135  std::cout << "MCElectronAnalyzer Analyzing event number: " << e.id() << " Global Counter " << nEvt_ << "\n";
136 
138  std::cout << " MCElectronAnalyzer Looking for MC truth "
139  << "\n";
140 
141  //get simtrack info
142  std::vector<SimTrack> theSimTracks;
143  std::vector<SimVertex> theSimVertices;
144 
147  e.getByLabel("g4SimHits", SimTk);
148  e.getByLabel("g4SimHits", SimVtx);
149 
150  theSimTracks.insert(theSimTracks.end(), SimTk->begin(), SimTk->end());
151  theSimVertices.insert(theSimVertices.end(), SimVtx->begin(), SimVtx->end());
152  std::cout << " MCElectronAnalyzer This Event has " << theSimTracks.size() << " sim tracks " << std::endl;
153  std::cout << " MCElectronAnalyzer This Event has " << theSimVertices.size() << " sim vertices " << std::endl;
154  if (theSimTracks.empty())
155  std::cout << " Event number " << e.id() << " has NO sim tracks " << std::endl;
156 
157  std::vector<ElectronMCTruth> MCElectronctrons = theElectronMCTruthFinder_->find(theSimTracks, theSimVertices);
158  std::cout << " MCElectronAnalyzer MCElectronctrons size " << MCElectronctrons.size() << std::endl;
159 
160  for (std::vector<ElectronMCTruth>::const_iterator iEl = MCElectronctrons.begin(); iEl != MCElectronctrons.end();
161  ++iEl) {
162  h_MCEleE_->Fill((*iEl).fourMomentum().e());
163  h_MCEleEta_->Fill((*iEl).fourMomentum().pseudoRapidity());
164  h_MCElePhi_->Fill((*iEl).fourMomentum().phi());
165 
166  float totBrem = 0;
167  unsigned int iBrem;
168  for (iBrem = 0; iBrem < (*iEl).bremVertices().size(); ++iBrem) {
169  float rBrem = (*iEl).bremVertices()[iBrem].perp();
170  float etaBrem = (*iEl).bremVertices()[iBrem].eta();
171  if (rBrem < 120) {
172  totBrem += (*iEl).bremMomentum()[iBrem].e();
173  p_BremVsR_->Fill(rBrem, (*iEl).bremMomentum()[iBrem].e());
174  p_BremVsEta_->Fill(etaBrem, (*iEl).bremMomentum()[iBrem].e());
175  }
176  }
177 
178  h_BremFrac_->Fill(totBrem / (*iEl).fourMomentum().e());
179  h_BremEnergy_->Fill(totBrem);
180  }
181 }
ElectronMCTruthFinder * theElectronMCTruthFinder_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:488
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
std::vector< ElectronMCTruth > find(const std::vector< SimTrack > &simTracks, const std::vector< SimVertex > &simVertices)
void MCElectronAnalyzer::beginJob ( void  )
overridevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 47 of file MCElectronAnalyzer.cc.

References fOutputFile_, fOutputFileName_, h_BremEnergy_, h_BremFrac_, h_MCEleE_, h_MCEleEta_, h_MCElePhi_, nEvt_, p_BremVsEta_, p_BremVsR_, and theElectronMCTruthFinder_.

47  {
48  nEvt_ = 0;
49 
51 
52  fOutputFile_ = new TFile(fOutputFileName_.c_str(), "RECREATE");
53 
55  h_MCEleE_ = new TH1F("MCEleE", "MC ele energy", 100, 0., 200.);
56  h_MCElePhi_ = new TH1F("MCElePhi", "MC ele phi", 40, -3.14, 3.14);
57  h_MCEleEta_ = new TH1F("MCEleEta", "MC ele eta", 40, -3., 3.);
58  h_BremFrac_ = new TH1F("bremFrac", "brem frac ", 100, 0., 1.);
59  h_BremEnergy_ = new TH1F("BremE", "Brem energy", 100, 0., 200.);
60 
61  p_BremVsR_ = new TProfile("BremVsR", " Mean Brem energy vs R ", 48, 0., 120.);
62  p_BremVsEta_ = new TProfile("BremVsEta", " Mean Brem energy vs Eta ", 50, -2.5, 2.5);
63 
64  return;
65 }
ElectronMCTruthFinder * theElectronMCTruthFinder_
std::string fOutputFileName_
void MCElectronAnalyzer::endJob ( void  )
overridevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 183 of file MCElectronAnalyzer.cc.

References gather_cfg::cout, fOutputFile_, and nEvt_.

183  {
184  fOutputFile_->Write();
185  fOutputFile_->Close();
186 
187  edm::LogInfo("MCElectronAnalyzer") << "Analyzed " << nEvt_ << "\n";
188  std::cout << "MCElectronAnalyzer::endJob Analyzed " << nEvt_ << " events "
189  << "\n";
190 
191  return;
192 }
float MCElectronAnalyzer::etaTransformation ( float  a,
float  b 
)
private

Definition at line 67 of file MCElectronAnalyzer.cc.

References funct::abs(), ETA, etaBarrelEndcap, dqm-mbProfile::log, PI, R_ECAL, funct::tan(), and Z_Endcap.

67  {
68  //---Definitions
69  const float PI = 3.1415927;
70  //const float TWOPI = 2.0*PI;
71 
72  //---Definitions for ECAL
73  const float R_ECAL = 136.5;
74  const float Z_Endcap = 328.0;
75  const float etaBarrelEndcap = 1.479;
76 
77  //---ETA correction
78 
79  float Theta = 0.0;
80  float ZEcal = R_ECAL * sinh(EtaParticle) + Zvertex;
81 
82  if (ZEcal != 0.0)
83  Theta = atan(R_ECAL / ZEcal);
84  if (Theta < 0.0)
85  Theta = Theta + PI;
86  float ETA = -log(tan(0.5 * Theta));
87 
88  if (std::abs(ETA) > etaBarrelEndcap) {
89  float Zend = Z_Endcap;
90  if (EtaParticle < 0.0)
91  Zend = -Zend;
92  float Zlen = Zend - Zvertex;
93  float RR = Zlen / sinh(EtaParticle);
94  Theta = atan(RR / Zend);
95  if (Theta < 0.0)
96  Theta = Theta + PI;
97  ETA = -log(tan(0.5 * Theta));
98  }
99  //---Return the result
100  return ETA;
101  //---end
102 }
#define ETA
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
static float etaBarrelEndcap
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define PI
Definition: QcdUeDQM.h:37
static float Z_Endcap
static float R_ECAL
float MCElectronAnalyzer::phiNormalization ( float &  a)
private

Definition at line 104 of file MCElectronAnalyzer.cc.

References phi, PI, and TWOPI.

104  {
105  //---Definitions
106  const float PI = 3.1415927;
107  const float TWOPI = 2.0 * PI;
108 
109  if (phi > PI) {
110  phi = phi - TWOPI;
111  }
112  if (phi < -PI) {
113  phi = phi + TWOPI;
114  }
115 
116  // cout << " Float_t PHInormalization out " << PHI << endl;
117  return phi;
118 }
#define TWOPI
Definition: DQMSourcePi0.cc:36
#define PI
Definition: QcdUeDQM.h:37

Member Data Documentation

TFile* MCElectronAnalyzer::fOutputFile_
private

Definition at line 40 of file MCElectronAnalyzer.h.

Referenced by beginJob(), and endJob().

std::string MCElectronAnalyzer::fOutputFileName_
private

Definition at line 39 of file MCElectronAnalyzer.h.

Referenced by beginJob().

TH1F* MCElectronAnalyzer::h_BremEnergy_
private

Definition at line 58 of file MCElectronAnalyzer.h.

Referenced by analyze(), and beginJob().

TH1F* MCElectronAnalyzer::h_BremFrac_
private

Definition at line 57 of file MCElectronAnalyzer.h.

Referenced by analyze(), and beginJob().

TH1F* MCElectronAnalyzer::h_MCEleE_
private

Definition at line 54 of file MCElectronAnalyzer.h.

Referenced by analyze(), and beginJob().

TH1F* MCElectronAnalyzer::h_MCEleEta_
private

Definition at line 55 of file MCElectronAnalyzer.h.

Referenced by analyze(), and beginJob().

TH1F* MCElectronAnalyzer::h_MCElePhi_
private

Definition at line 56 of file MCElectronAnalyzer.h.

Referenced by analyze(), and beginJob().

std::string MCElectronAnalyzer::HepMCLabel
private

Definition at line 49 of file MCElectronAnalyzer.h.

double MCElectronAnalyzer::mcEta_
private

Definition at line 47 of file MCElectronAnalyzer.h.

double MCElectronAnalyzer::mcPhi_
private

global variable for the MC photon

Definition at line 46 of file MCElectronAnalyzer.h.

int MCElectronAnalyzer::nEvt_
private

Definition at line 42 of file MCElectronAnalyzer.h.

Referenced by analyze(), beginJob(), and endJob().

int MCElectronAnalyzer::nMatched_
private

Definition at line 43 of file MCElectronAnalyzer.h.

TProfile* MCElectronAnalyzer::p_BremVsEta_
private

Definition at line 61 of file MCElectronAnalyzer.h.

Referenced by analyze(), and beginJob().

TProfile* MCElectronAnalyzer::p_BremVsR_
private

Definition at line 60 of file MCElectronAnalyzer.h.

Referenced by analyze(), and beginJob().

std::string MCElectronAnalyzer::SimHitLabel
private

Definition at line 52 of file MCElectronAnalyzer.h.

std::string MCElectronAnalyzer::SimTkLabel
private

Definition at line 50 of file MCElectronAnalyzer.h.

std::string MCElectronAnalyzer::SimVtxLabel
private

Definition at line 51 of file MCElectronAnalyzer.h.

ElectronMCTruthFinder* MCElectronAnalyzer::theElectronMCTruthFinder_
private

Definition at line 35 of file MCElectronAnalyzer.h.

Referenced by analyze(), beginJob(), and ~MCElectronAnalyzer().

const TrackerGeometry* MCElectronAnalyzer::trackerGeom
private

Definition at line 37 of file MCElectronAnalyzer.h.