CMS 3D CMS Logo

MCElectronAnalyzer.cc
Go to the documentation of this file.
1 #include <iostream>
2 //
6 //
12 //
17 //
19 //
26 //
29 
30 //
31 #include "TFile.h"
32 #include "TH1.h"
33 #include "TH2.h"
34 #include "TTree.h"
35 #include "TVector3.h"
36 #include "TProfile.h"
37 //
38 
39 using namespace std;
40 
42  : fOutputFileName_(pset.getUntrackedParameter<string>("HistOutFile", std::string("TestConversions.root"))),
43  fOutputFile_(nullptr) {}
44 
46 
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 }
66 
67 float MCElectronAnalyzer::etaTransformation(float EtaParticle, float Zvertex) {
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 }
103 
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 }
119 
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 }
182 
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 }
PI
Definition: PayloadInspector.h:20
Handle.h
MessageLogger.h
ESHandle.h
PI
#define PI
Definition: QcdUeDQM.h:37
edm
HLT enums.
Definition: AlignableModifier.h:19
CrossingFrame.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
MCElectronAnalyzer::phiNormalization
float phiNormalization(float &a)
Definition: MCElectronAnalyzer.cc:104
MakerMacros.h
TrackingVertexContainer.h
ElectronMCTruth.h
MixCollection.h
MCElectronAnalyzer::etaTransformation
float etaTransformation(float a, float b)
Definition: MCElectronAnalyzer.cc:67
SimVertex.h
ElectronMCTruthFinder.h
IdealMagneticFieldRecord.h
MCElectronAnalyzer::h_MCEleE_
TH1F * h_MCEleE_
Definition: MCElectronAnalyzer.h:54
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MCElectronAnalyzer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: MCElectronAnalyzer.cc:120
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
ElectronMCTruthFinder::find
std::vector< ElectronMCTruth > find(const std::vector< SimTrack > &simTracks, const std::vector< SimVertex > &simVertices)
Definition: ElectronMCTruthFinder.cc:9
PVValHelper::phi
Definition: PVValidationHelpers.h:68
TWOPI
#define TWOPI
Definition: DQMSourcePi0.cc:36
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
MagneticField.h
MCElectronAnalyzer::beginJob
void beginJob() override
Definition: MCElectronAnalyzer.cc:47
edm::EventSetup
Definition: EventSetup.h:57
MCElectronAnalyzer::nEvt_
int nEvt_
Definition: MCElectronAnalyzer.h:42
MCElectronAnalyzer::theElectronMCTruthFinder_
ElectronMCTruthFinder * theElectronMCTruthFinder_
Definition: MCElectronAnalyzer.h:35
MCElectronAnalyzer::h_BremFrac_
TH1F * h_BremFrac_
Definition: MCElectronAnalyzer.h:57
MCElectronAnalyzer::~MCElectronAnalyzer
~MCElectronAnalyzer() override
Definition: MCElectronAnalyzer.cc:45
MCElectronAnalyzer::h_MCElePhi_
TH1F * h_MCElePhi_
Definition: MCElectronAnalyzer.h:56
MCElectronAnalyzer::endJob
void endJob() override
Definition: MCElectronAnalyzer.cc:183
MCElectronAnalyzer::fOutputFileName_
std::string fOutputFileName_
Definition: MCElectronAnalyzer.h:39
DDAxes::phi
MCElectronAnalyzer::p_BremVsEta_
TProfile * p_BremVsEta_
Definition: MCElectronAnalyzer.h:61
std
Definition: JetResolutionObject.h:76
TrackingParticleFwd.h
MCElectronAnalyzer::p_BremVsR_
TProfile * p_BremVsR_
Definition: MCElectronAnalyzer.h:60
ETA
#define ETA
Definition: GenericBenchmark.cc:28
EventSetup.h
Exception.h
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
MCElectronAnalyzer::MCElectronAnalyzer
MCElectronAnalyzer(const edm::ParameterSet &)
Definition: MCElectronAnalyzer.cc:41
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MCElectronAnalyzer.h
SimTrack.h
HepMCProduct.h
ZEcal
static constexpr float ZEcal
Definition: L1TkEmParticleProducer.cc:40
edm::Event
Definition: Event.h:73
MCElectronAnalyzer::fOutputFile_
TFile * fOutputFile_
Definition: MCElectronAnalyzer.h:40
SimTrackContainer.h
Z_Endcap
static constexpr float Z_Endcap
Definition: ECALPositionCalculator.cc:11
SimVertexContainer.h
R_ECAL
static constexpr float R_ECAL
Definition: ECALPositionCalculator.cc:10
ElectronMCTruthFinder
Definition: ElectronMCTruthFinder.h:13
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MCElectronAnalyzer::h_MCEleEta_
TH1F * h_MCEleEta_
Definition: MCElectronAnalyzer.h:55
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
etaBarrelEndcap
static constexpr float etaBarrelEndcap
Definition: ECALPositionCalculator.cc:12
MCElectronAnalyzer::h_BremEnergy_
TH1F * h_BremEnergy_
Definition: MCElectronAnalyzer.h:58