CMS 3D CMS Logo

MCPhotonAnalyzer.cc
Go to the documentation of this file.
1 #include <iostream>
2 //
5 //
10 //
16 //
21 //
23 //
30 //
33 
34 //
35 #include "TFile.h"
36 #include "TH1.h"
37 #include "TH2.h"
38 #include "TTree.h"
39 #include "TVector3.h"
40 #include "TProfile.h"
41 //
42 
43 
44 
45 using namespace std;
46 
47 
49 
50 
51 
53 
54 
55  delete thePhotonMCTruthFinder_;
56 
57 }
58 
59 
61 {
62 
63 
64  nEvt_=0;
65 
66  thePhotonMCTruthFinder_ = new PhotonMCTruthFinder();
67 
69 
70 
72  h_MCPhoE_ = fs->make<TH1F>("MCPhoE","MC photon energy",100,0.,100.);
73  h_MCPhoPhi_ = fs->make<TH1F>("MCPhoPhi","MC photon phi",40,-3.14, 3.14);
74  h_MCPhoEta_ = fs->make<TH1F>("MCPhoEta","MC photon eta",25,0., 2.5);
75  h_MCPhoEta1_ = fs->make<TH1F>("MCPhoEta1","MC photon eta",40,-3., 3.);
76  h_MCPhoEta2_ = fs->make<TH1F>("MCPhoEta2","MC photon eta",40,-3., 3.);
77  h_MCPhoEta3_ = fs->make<TH1F>("MCPhoEta3","MC photon eta",40,-3., 3.);
78  h_MCPhoEta4_ = fs->make<TH1F>("MCPhoEta4","MC photon eta",40,-3., 3.);
80  h_MCConvPhoE_ = fs->make<TH1F>("MCConvPhoE","MC converted photon energy",100,0.,100.);
81  h_MCConvPhoPhi_ = fs->make<TH1F>("MCConvPhoPhi","MC converted photon phi",40,-3.14, 3.14);
82  h_MCConvPhoEta_ = fs->make<TH1F>("MCConvPhoEta","MC converted photon eta",25,0., 2.5);
83  h_MCConvPhoR_ = fs->make<TH1F>("MCConvPhoR","MC converted photon R",120,0.,120.);
84 
85  h_MCConvPhoREta1_ = fs->make<TH1F>("MCConvPhoREta1","MC converted photon R",120,0.,120.);
86  h_MCConvPhoREta2_ = fs->make<TH1F>("MCConvPhoREta2","MC converted photon R",120,0.,120.);
87  h_MCConvPhoREta3_ = fs->make<TH1F>("MCConvPhoREta3","MC converted photon R",120,0.,120.);
88  h_MCConvPhoREta4_ = fs->make<TH1F>("MCConvPhoREta4","MC converted photon R",120,0.,120.);
89 
90  h_convFracEta1_ = fs->make<TH1F>("convFracEta1","Integrated(R) fraction of conversion |eta|=0.2",120,0.,120.);
91  h_convFracEta2_ = fs->make<TH1F>("convFracEta2","Integrated(R) fraction of conversion |eta|=0.9",120,0.,120.);
92  h_convFracEta3_ = fs->make<TH1F>("convFracEta3","Integrated(R) fraction of conversion |eta|=1.5",120,0.,120.);
93  h_convFracEta4_ = fs->make<TH1F>("convFracEta4","Integrated(R) fraction of conversion |eta|=2.0",120,0.,120.);
95  h_MCConvPhoTwoTracksE_ = fs->make<TH1F>("MCConvPhoTwoTracksE","MC converted photon with 2 tracks energy",100,0.,100.);
96  h_MCConvPhoTwoTracksPhi_ = fs->make<TH1F>("MCConvPhoTwoTracksPhi","MC converted photon 2 tracks phi",40,-3.14, 3.14);
97  h_MCConvPhoTwoTracksEta_ = fs->make<TH1F>("MCConvPhoTwoTracksEta","MC converted photon 2 tracks eta",40,-3., 3.);
98  h_MCConvPhoTwoTracksR_ = fs->make<TH1F>("MCConvPhoTwoTracksR","MC converted photon 2 tracks eta",48,0.,120.);
99  // conversions with one track
100  h_MCConvPhoOneTrackE_ = fs->make<TH1F>("MCConvPhoOneTrackE","MC converted photon with 1 track energy",100,0.,100.);
101  h_MCConvPhoOneTrackPhi_ = fs->make<TH1F>("MCConvPhoOneTrackPhi","MC converted photon 1 track phi",40,-3.14, 3.14);
102  h_MCConvPhoOneTrackEta_ = fs->make<TH1F>("MCConvPhoOneTrackEta","MC converted photon 1 track eta",40,-3., 3.);
103  h_MCConvPhoOneTrackR_ = fs->make<TH1F>("MCConvPhoOneTrackR","MC converted photon 1 track eta",48,0.,120.);
104 
106  h_MCEleE_ = fs->make<TH1F>("MCEleE","MC ele energy",100,0.,200.);
107  h_MCElePhi_ = fs->make<TH1F>("MCElePhi","MC ele phi",40,-3.14, 3.14);
108  h_MCEleEta_ = fs->make<TH1F>("MCEleEta","MC ele eta",40,-3., 3.);
109  h_BremFrac_ = fs->make<TH1F>("bremFrac","brem frac ", 100, 0., 1.);
110  h_BremEnergy_ = fs->make<TH1F>("BremE","Brem energy",100,0.,200.);
111  h_EleEvsPhoE_ = fs->make<TH2F>("eleEvsPhoE","eleEvsPhoE",100,0.,200.,100,0.,200.);
112  h_bremEvsEleE_ = fs->make<TH2F>("bremEvsEleE","bremEvsEleE",100,0.,200.,100,0.,200.);
113 
114  p_BremVsR_ = fs->make<TProfile>("BremVsR", " Mean Brem Energy vs R ", 48, 0., 120.);
115  p_BremVsEta_ = fs->make<TProfile>("BremVsEta", " Mean Brem Energy vs Eta ", 50, -2.5, 2.5);
116 
117  p_BremVsConvR_ = fs->make<TProfile>("BremVsConvR", " Mean Brem Fraction vs conversion R ", 48, 0., 120.);
118  p_BremVsConvEta_ = fs->make<TProfile>("BremVsConvEta", " Mean Brem Fraction vs converion Eta ", 50, -2.5, 2.5);
119 
120  h_bremFracVsConvR_ = fs->make<TH2F>("bremFracVsConvR","brem Fraction vs conversion R",60,0.,120.,100,0.,1.);
121 
122  return ;
123 }
124 
125 
126 float MCPhotonAnalyzer::etaTransformation( float EtaParticle , float Zvertex) {
127 
128 //---Definitions
129  const float PI = 3.1415927;
130 // const float TWOPI = 2.0*PI;
131 
132 //---Definitions for ECAL
133  const float R_ECAL = 136.5;
134  const float Z_Endcap = 328.0;
135  const float etaBarrelEndcap = 1.479;
136 
137 //---ETA correction
138 
139  float Theta = 0.0 ;
140  float ZEcal = R_ECAL*sinh(EtaParticle)+Zvertex;
141 
142  if(ZEcal != 0.0) Theta = atan(R_ECAL/ZEcal);
143  if(Theta<0.0) Theta = Theta+PI ;
144  float ETA = - log(tan(0.5*Theta));
145 
146  if( fabs(ETA) > etaBarrelEndcap )
147  {
148  float Zend = Z_Endcap ;
149  if(EtaParticle<0.0 ) Zend = -Zend ;
150  float Zlen = Zend - Zvertex ;
151  float RR = Zlen/sinh(EtaParticle);
152  Theta = atan(RR/Zend);
153  if(Theta<0.0) Theta = Theta+PI ;
154  ETA = - log(tan(0.5*Theta));
155  }
156 //---Return the result
157  return ETA;
158 //---end
159 }
160 
162 {
163 //---Definitions
164  const float PI = 3.1415927;
165  const float TWOPI = 2.0*PI;
166 
167 
168  if(phi > PI) {phi = phi - TWOPI;}
169  if(phi < -PI) {phi = phi + TWOPI;}
170 
171  // cout << " Float_t PHInormalization out " << PHI << endl;
172  return phi;
173 
174 }
175 
176 
177 
178 
179 
181 {
182 
183 
184  using namespace edm;
185  //UNUSED const float etaPhiDistance=0.01;
186  // Fiducial region
187  //UNUSED const float TRK_BARL =0.9;
188  //UNUSED const float BARL = 1.4442; // DAQ TDR p.290
189  //UNUSED const float END_LO = 1.566;
190  //UNUSED const float END_HI = 2.5;
191  // Electron mass
192  //UNUSED const Float_t mElec= 0.000511;
193 
194 
195  nEvt_++;
196  LogInfo("mcEleAnalyzer") << "MCPhotonAnalyzer Analyzing event number: " << e.id() << " Global Counter " << nEvt_ <<"\n";
197  // LogDebug("MCPhotonAnalyzer") << "MCPhotonAnalyzer Analyzing event number: " << e.id() << " Global Counter " << nEvt_ <<"\n";
198  std::cout << "MCPhotonAnalyzer Analyzing event number: " << e.id() << " Global Counter " << nEvt_ <<"\n";
199 
200 
201 
203  std::cout << " MCPhotonAnalyzer Looking for MC truth " << "\n";
204 
205  //get simtrack info
206  std::vector<SimTrack> theSimTracks;
207  std::vector<SimVertex> theSimVertices;
208 
211  e.getByLabel("g4SimHits",SimTk);
212  e.getByLabel("g4SimHits",SimVtx);
213 
214  theSimTracks.insert(theSimTracks.end(),SimTk->begin(),SimTk->end());
215  theSimVertices.insert(theSimVertices.end(),SimVtx->begin(),SimVtx->end());
216  std::cout << " MCPhotonAnalyzer This Event has " << theSimTracks.size() << " sim tracks " << std::endl;
217  std::cout << " MCPhotonAnalyzer This Event has " << theSimVertices.size() << " sim vertices " << std::endl;
218  if ( theSimTracks.empty() ) std::cout << " Event number " << e.id() << " has NO sim tracks " << std::endl;
219 
220 
221  std::vector<PhotonMCTruth> mcPhotons=thePhotonMCTruthFinder_->find (theSimTracks, theSimVertices);
222  std::cout << " MCPhotonAnalyzer mcPhotons size " << mcPhotons.size() << std::endl;
223 
224 
225 
226  for ( std::vector<PhotonMCTruth>::const_iterator iPho=mcPhotons.begin(); iPho !=mcPhotons.end(); ++iPho ){
227 
228  if ( (*iPho).fourMomentum().e() < 35 ) continue;
229 
230  h_MCPhoE_->Fill ( (*iPho).fourMomentum().e() );
231  // float correta = etaTransformation( (*iPho).fourMomentum().pseudoRapidity(), (*iPho).primaryVertex().z() );
232  float Theta= (*iPho).fourMomentum().theta();
233  float correta = - log(tan(0.5*Theta));
234  correta = etaTransformation( correta, (*iPho).primaryVertex().z() );
235  //h_MCPhoEta_->Fill ( (*iPho).fourMomentum().pseudoRapidity() );
236  h_MCPhoEta_->Fill ( fabs(correta)-0.001 );
237  h_MCPhoPhi_->Fill ( (*iPho).fourMomentum().phi() );
238 
239  /*
240  if ( fabs((*iPho).fourMomentum().pseudoRapidity() ) <= 0.25 && fabs((*iPho).fourMomentum().pseudoRapidity() ) >=0.15 )
241  h_MCPhoEta1_->Fill ( (*iPho).fourMomentum().pseudoRapidity() );
242  if ( fabs((*iPho).fourMomentum().pseudoRapidity() ) <= 0.95 && fabs((*iPho).fourMomentum().pseudoRapidity() ) >=0.85 )
243  h_MCPhoEta2_->Fill ( (*iPho).fourMomentum().pseudoRapidity() );
244  if ( fabs((*iPho).fourMomentum().pseudoRapidity() ) <= 1.65 && fabs((*iPho).fourMomentum().pseudoRapidity() ) >=1.55 )
245  h_MCPhoEta3_->Fill ( (*iPho).fourMomentum().pseudoRapidity() );
246  if ( fabs((*iPho).fourMomentum().pseudoRapidity() ) <= 2.05 && fabs((*iPho).fourMomentum().pseudoRapidity() ) >=1.95 )
247  h_MCPhoEta4_->Fill ( (*iPho).fourMomentum().pseudoRapidity() );
248  */
249 
250 
251  if ( fabs(correta ) <= 0.3 && fabs(correta ) >0.2 )
252  h_MCPhoEta1_->Fill ( correta );
253  if ( fabs(correta ) <= 1.00 && fabs( correta ) >0.9 )
254  h_MCPhoEta2_->Fill ( correta );
255  if ( fabs( correta ) <= 1.6 && fabs(correta ) >1.5 )
256  h_MCPhoEta3_->Fill ( correta );
257  if ( fabs(correta ) <= 2. && fabs(correta ) >1.9 )
258  h_MCPhoEta4_->Fill ( correta );
259 
260 
261 
262  // if ( (*iPho).isAConversion() && (*iPho).vertex().perp()< 10 ) {
263  if ( (*iPho).isAConversion() ) {
264 
265 
266 
267  h_MCConvPhoE_->Fill ( (*iPho).fourMomentum().e() );
268  // h_MCConvPhoEta_->Fill ( (*iPho).fourMomentum().pseudoRapidity() );
269 
270  h_MCConvPhoEta_->Fill ( fabs(correta)-0.001 );
271  h_MCConvPhoPhi_->Fill ( (*iPho).fourMomentum().phi() );
272  h_MCConvPhoR_->Fill ( (*iPho).vertex().perp() );
273 
274  /*
275  if ( fabs((*iPho).fourMomentum().pseudoRapidity() ) <= 0.25 && fabs((*iPho).fourMomentum().pseudoRapidity() ) >=0.15 )
276  h_MCConvPhoREta1_->Fill ( (*iPho).vertex().perp() );
277  if ( fabs((*iPho).fourMomentum().pseudoRapidity() ) <= 0.95 && fabs((*iPho).fourMomentum().pseudoRapidity() ) >=0.85 )
278  h_MCConvPhoREta2_->Fill ( (*iPho).vertex().perp() );
279  if ( fabs((*iPho).fourMomentum().pseudoRapidity() ) <= 1.65 && fabs((*iPho).fourMomentum().pseudoRapidity() ) >=1.55 )
280  h_MCConvPhoREta3_->Fill ( (*iPho).vertex().perp() );
281  if ( fabs((*iPho).fourMomentum().pseudoRapidity() ) <= 2.05 && fabs((*iPho).fourMomentum().pseudoRapidity() ) >=1.95 )
282  h_MCConvPhoREta4_->Fill ( (*iPho).vertex().perp() );
283  */
284 
285 
286  if ( fabs(correta ) <= 0.3 && fabs(correta ) >0.2 )
287  h_MCConvPhoREta1_->Fill ( (*iPho).vertex().perp() );
288  if ( fabs(correta ) <= 1. && fabs( correta ) >0.9 )
289  h_MCConvPhoREta2_->Fill ( (*iPho).vertex().perp() );
290  if ( fabs( correta ) <= 1.6 && fabs(correta ) >1.5 )
291  h_MCConvPhoREta3_->Fill ( (*iPho).vertex().perp() );
292  if ( fabs(correta ) <= 2 && fabs(correta ) >1.9 )
293  h_MCConvPhoREta4_->Fill ( (*iPho).vertex().perp() );
294 
295 
296 
297 
298 
299  } // end conversions
300 
301 
302 
303 
304 
305  }
306 
307 
308 
309 
310 }
311 
312 
313 
314 
316 {
317 
318 
319  Double_t s1=0;
320  Double_t s2=0;
321  Double_t s3=0;
322  Double_t s4=0;
323  int e1=0;
324  int e2=0;
325  int e3=0;
326  int e4=0;
327 
328  Double_t nTotEta1 = h_MCPhoEta1_->GetEntries();
329  Double_t nTotEta2 = h_MCPhoEta2_->GetEntries();
330  Double_t nTotEta3 = h_MCPhoEta3_->GetEntries();
331  Double_t nTotEta4 = h_MCPhoEta4_->GetEntries();
332 
333  for ( int i=1; i<=120; ++i) {
334  e1 = (int)h_MCConvPhoREta1_->GetBinContent(i);
335  e2 = (int)h_MCConvPhoREta2_->GetBinContent(i);
336  e3 = (int)h_MCConvPhoREta3_->GetBinContent(i);
337  e4 = (int)h_MCConvPhoREta4_->GetBinContent(i);
338  s1+=e1;
339  s2+=e2;
340  s3+=e3;
341  s4+=e4;
342  h_convFracEta1_->SetBinContent(i,s1*100/nTotEta1);
343  h_convFracEta2_->SetBinContent(i,s2*100/nTotEta2);
344  h_convFracEta3_->SetBinContent(i,s3*100/nTotEta3);
345  h_convFracEta4_->SetBinContent(i,s4*100/nTotEta4);
346 
347 
348 
349 
350 
351 }
352 
353 
354 
355  edm::LogInfo("MCPhotonAnalyzer") << "Analyzed " << nEvt_ << "\n";
356  std::cout << "MCPhotonAnalyzer::endJob Analyzed " << nEvt_ << " events " << "\n";
357 
358  return ;
359 }
360 
float etaTransformation(float a, float b)
~MCPhotonAnalyzer() override
void endJob() override
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
return((rh^lh)&mask)
#define ETA
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
static float etaBarrelEndcap
#define TWOPI
Definition: DQMSourcePi0.cc:37
MCPhotonAnalyzer(const edm::ParameterSet &)
#define PI
Definition: QcdUeDQM.h:36
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
void beginJob() override
void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
static float Z_Endcap
float phiNormalization(float &a)
static float R_ECAL