CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
40 
41 using namespace std;
42 
43 
45  : fOutputFileName_( pset.getUntrackedParameter<string>("HistOutFile",std::string("TestConversions.root")) ),
46  fOutputFile_(0)
47 {
48 
49 
50 }
51 
52 
53 
55 
56 
58 
59 }
60 
61 
63 {
64 
65 
66  nEvt_=0;
67 
69 
70 
71  fOutputFile_ = new TFile( fOutputFileName_.c_str(), "RECREATE" ) ;
72 
74  h_MCEleE_ = new TH1F("MCEleE","MC ele energy",100,0.,200.);
75  h_MCElePhi_ = new TH1F("MCElePhi","MC ele phi",40,-3.14, 3.14);
76  h_MCEleEta_ = new TH1F("MCEleEta","MC ele eta",40,-3., 3.);
77  h_BremFrac_ = new TH1F("bremFrac","brem frac ", 100, 0., 1.);
78  h_BremEnergy_ = new TH1F("BremE","Brem energy",100,0.,200.);
79 
80  p_BremVsR_ = new TProfile("BremVsR", " Mean Brem energy vs R ", 48, 0., 120.);
81  p_BremVsEta_ = new TProfile("BremVsEta", " Mean Brem energy vs Eta ", 50, -2.5, 2.5);
82 
83 
84 
85 
86  return ;
87 }
88 
89 
90 float MCElectronAnalyzer::etaTransformation( float EtaParticle , float Zvertex) {
91 
92 //---Definitions
93  const float PI = 3.1415927;
94  //const float TWOPI = 2.0*PI;
95 
96 //---Definitions for ECAL
97  const float R_ECAL = 136.5;
98  const float Z_Endcap = 328.0;
99  const float etaBarrelEndcap = 1.479;
100 
101 //---ETA correction
102 
103  float Theta = 0.0 ;
104  float ZEcal = R_ECAL*sinh(EtaParticle)+Zvertex;
105 
106  if(ZEcal != 0.0) Theta = atan(R_ECAL/ZEcal);
107  if(Theta<0.0) Theta = Theta+PI ;
108  float ETA = - log(tan(0.5*Theta));
109 
110  if( std::abs(ETA) > etaBarrelEndcap )
111  {
112  float Zend = Z_Endcap ;
113  if(EtaParticle<0.0 ) Zend = -Zend ;
114  float Zlen = Zend - Zvertex ;
115  float RR = Zlen/sinh(EtaParticle);
116  Theta = atan(RR/Zend);
117  if(Theta<0.0) Theta = Theta+PI ;
118  ETA = - log(tan(0.5*Theta));
119  }
120 //---Return the result
121  return ETA;
122 //---end
123 }
124 
126 {
127 //---Definitions
128  const float PI = 3.1415927;
129  const float TWOPI = 2.0*PI;
130 
131 
132  if(phi > PI) {phi = phi - TWOPI;}
133  if(phi < -PI) {phi = phi + TWOPI;}
134 
135  // cout << " Float_t PHInormalization out " << PHI << endl;
136  return phi;
137 
138 }
139 
140 
141 
142 
143 
145 {
146 
147 
148  using namespace edm;
149  //const float etaPhiDistance=0.01;
150  // Fiducial region
151  //const float TRK_BARL =0.9;
152  //const float BARL = 1.4442; // DAQ TDR p.290
153  //const float END_LO = 1.566;
154  //const float END_HI = 2.5;
155  // Electron mass
156  //const Float_t mElec= 0.000511;
157 
158 
159  nEvt_++;
160  LogInfo("MCElectronAnalyzer") << "MCElectronAnalyzer Analyzing event number: " << e.id() << " Global Counter " << nEvt_ <<"\n";
161  // LogDebug("MCElectronAnalyzer") << "MCElectronAnalyzer Analyzing event number: " << e.id() << " Global Counter " << nEvt_ <<"\n";
162  std::cout << "MCElectronAnalyzer Analyzing event number: " << e.id() << " Global Counter " << nEvt_ <<"\n";
163 
165  std::cout << " MCElectronAnalyzer Looking for MC truth " << "\n";
166 
167  //get simtrack info
168  std::vector<SimTrack> theSimTracks;
169  std::vector<SimVertex> theSimVertices;
170 
173  e.getByLabel("g4SimHits",SimTk);
174  e.getByLabel("g4SimHits",SimVtx);
175 
176  theSimTracks.insert(theSimTracks.end(),SimTk->begin(),SimTk->end());
177  theSimVertices.insert(theSimVertices.end(),SimVtx->begin(),SimVtx->end());
178  std::cout << " MCElectronAnalyzer This Event has " << theSimTracks.size() << " sim tracks " << std::endl;
179  std::cout << " MCElectronAnalyzer This Event has " << theSimVertices.size() << " sim vertices " << std::endl;
180  if ( ! theSimTracks.size() ) std::cout << " Event number " << e.id() << " has NO sim tracks " << std::endl;
181 
182 
183  std::vector<ElectronMCTruth> MCElectronctrons=theElectronMCTruthFinder_->find (theSimTracks, theSimVertices);
184  std::cout << " MCElectronAnalyzer MCElectronctrons size " << MCElectronctrons.size() << std::endl;
185 
186  for ( std::vector<ElectronMCTruth>::const_iterator iEl=MCElectronctrons.begin(); iEl !=MCElectronctrons.end(); ++iEl ){
187 
188  h_MCEleE_->Fill ( (*iEl).fourMomentum().e() );
189  h_MCEleEta_->Fill ( (*iEl).fourMomentum().pseudoRapidity() );
190  h_MCElePhi_->Fill ( (*iEl).fourMomentum().phi() );
191 
192  float totBrem=0 ;
193  unsigned int iBrem ;
194  for ( iBrem=0; iBrem < (*iEl).bremVertices().size(); ++iBrem ) {
195  float rBrem= (*iEl).bremVertices()[iBrem].perp();
196  float etaBrem= (*iEl).bremVertices()[iBrem].eta();
197  if ( rBrem < 120 ) {
198  totBrem += (*iEl).bremMomentum()[iBrem].e();
199  p_BremVsR_ ->Fill ( rBrem, (*iEl).bremMomentum()[iBrem].e() );
200  p_BremVsEta_ ->Fill ( etaBrem, (*iEl).bremMomentum()[iBrem].e() );
201 
202  }
203  }
204 
205 
206  h_BremFrac_->Fill( totBrem/(*iEl).fourMomentum().e() );
207  h_BremEnergy_->Fill ( totBrem );
208 
209 
210 
211 
212  }
213 
214 
215 
216 
217 }
218 
219 
220 
221 
223 {
224 
225 
226 
227 
228  fOutputFile_->Write() ;
229  fOutputFile_->Close() ;
230 
231  edm::LogInfo("MCElectronAnalyzer") << "Analyzed " << nEvt_ << "\n";
232  std::cout << "MCElectronAnalyzer::endJob Analyzed " << nEvt_ << " events " << "\n";
233 
234  return ;
235 }
236 
#define PI
MCElectronAnalyzer(const edm::ParameterSet &)
ElectronMCTruthFinder * theElectronMCTruthFinder_
return((rh^lh)&mask)
#define ETA
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define TWOPI
EgammaCoreTools.
Definition: DQMSourcePi0.cc:40
float phiNormalization(float &a)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:420
virtual void analyze(const edm::Event &, const edm::EventSetup &)
float etaTransformation(float a, float b)
static const float etaBarrelEndcap
Geom::Phi< T > phi() const
static const float Z_Endcap
edm::EventID id() const
Definition: EventBase.h:60
std::vector< ElectronMCTruth > find(const std::vector< SimTrack > &simTracks, const std::vector< SimVertex > &simVertices)
static const float R_ECAL
virtual void beginJob()
tuple cout
Definition: gather_cfg.py:121
std::string fOutputFileName_
tuple log
Definition: cmsBatch.py:341