CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PhotonsWithConversionsAnalyzer.cc
Go to the documentation of this file.
1 #include <iostream>
2 //
5 //
10 //
16 //
23 //
33 //
36 
37 //
38 #include "TFile.h"
39 #include "TH1.h"
40 #include "TH2.h"
41 #include "TTree.h"
42 #include "TVector3.h"
43 #include "TProfile.h"
44 //
45 
46 
47 
48 using namespace std;
49 
50 
52  {
53 
54  photonCollectionProducer_ = pset.getParameter<std::string>("phoProducer");
55  photonCollection_ = pset.getParameter<std::string>("photonCollection");
56  //
57 
58 
59 }
60 
61 
62 
64 
65 
66  delete thePhotonMCTruthFinder_;
67 
68 }
69 
70 
72 {
73 
74 
75  nEvt_=0;
76  nMCPho_=0;
77  nMatched_=0;
78 
79 
80  thePhotonMCTruthFinder_ = new PhotonMCTruthFinder();
81 
82 
83 
85 
86 
88  h_ErecoEMC_ = fs->make<TH1F>("deltaE"," delta(reco-mc) energy",100,0.,2.);
89  h_deltaPhi_ = fs->make<TH1F>("deltaPhi"," delta(reco-mc) phi",100,-0.1, 0.1);
90  h_deltaEta_ = fs->make<TH1F>("deltaEta"," delta(reco-mc) eta",100,-0.05, 0.05);
91 
93  h_MCphoE_ = fs->make<TH1F>("MCphoE","MC photon energy",100,0.,100.);
94  h_MCphoPhi_ = fs->make<TH1F>("MCphoPhi","MC photon phi",40,-3.14, 3.14);
95  h_MCphoEta_ = fs->make<TH1F>("MCphoEta","MC photon eta",40,-3., 3.);
96 
97 
99  h_MCConvE_ = fs->make<TH1F>("MCConvE","MC converted photon energy",100,0.,100.);
100  h_MCConvPt_ = fs->make<TH1F>("MCConvPt","MC converted photon pt",100,0.,100.);
101  h_MCConvEta_ = fs->make<TH1F>("MCConvEta","MC converted photon eta",50, 0., 2.5);
102 
104  h_scE_ = fs->make<TH1F>("scE","SC Energy ",100,0., 200.);
105  h_scEt_ = fs->make<TH1F>("scEt","SC Et ",100,0., 200.);
106  h_scEta_ = fs->make<TH1F>("scEta","SC Eta ",40,-3., 3.);
107  h_scPhi_ = fs->make<TH1F>("scPhi","SC Phi ",40, -3.14, 3.14);
108  //
109  h_phoE_ = fs->make<TH1F>("phoE","Photon Energy ",100,0., 200.);
110  h_phoEta_ = fs->make<TH1F>("phoEta","Photon Eta ",40,-3., 3.);
111  h_phoPhi_ = fs->make<TH1F>("phoPhi","Photon Phi ",40, -3.14, 3.14);
112 
113  // Recontructed tracks from converted photon candidates
114  h2_tk_nHitsVsR_ = fs->make<TH2F>("tknHitsVsR","Tracks Hits vs R ", 12,0.,120.,20,0.5, 20.5);
115  h2_tk_inPtVsR_ = fs->make<TH2F>("tkInPtvsR","Tracks inner Pt vs R ", 12,0.,120.,100,0., 100.);
116 
117 
118  return ;
119 }
120 
121 
122 float PhotonsWithConversionsAnalyzer::etaTransformation( float EtaParticle , float Zvertex) {
123 
124 //---Definitions
125  const float PI = 3.1415927;
126  //UNUSED const float TWOPI = 2.0*PI;
127 
128 //---Definitions for ECAL
129  const float R_ECAL = 136.5;
130  const float Z_Endcap = 328.0;
131  const float etaBarrelEndcap = 1.479;
132 
133 //---ETA correction
134 
135  float Theta = 0.0 ;
136  float ZEcal = R_ECAL*sinh(EtaParticle)+Zvertex;
137 
138  if(ZEcal != 0.0) Theta = atan(R_ECAL/ZEcal);
139  if(Theta<0.0) Theta = Theta+PI ;
140  float ETA = - log(tan(0.5*Theta));
141 
142  if( fabs(ETA) > etaBarrelEndcap )
143  {
144  float Zend = Z_Endcap ;
145  if(EtaParticle<0.0 ) Zend = -Zend ;
146  float Zlen = Zend - Zvertex ;
147  float RR = Zlen/sinh(EtaParticle);
148  Theta = atan(RR/Zend);
149  if(Theta<0.0) Theta = Theta+PI ;
150  ETA = - log(tan(0.5*Theta));
151  }
152 //---Return the result
153  return ETA;
154 //---end
155 }
156 
157 
158 
159 
160 
161 
163 {
164 
165 
166  using namespace edm;
167  const float etaPhiDistance=0.01;
168  // Fiducial region
169  //UNUSED const float TRK_BARL =0.9;
170  //UNUSED const float BARL = 1.4442; // DAQ TDR p.290
171  //UNUSED const float END_LO = 1.566;
172  //UNUSED const float END_HI = 2.5;
173  // Electron mass
174  //UNUSED const Float_t mElec= 0.000511;
175 
176 
177  nEvt_++;
178  LogInfo("ConvertedPhotonAnalyzer") << "ConvertedPhotonAnalyzer Analyzing event number: " << e.id() << " Global Counter " << nEvt_ <<"\n";
179  // LogDebug("ConvertedPhotonAnalyzer") << "ConvertedPhotonAnalyzer Analyzing event number: " << e.id() << " Global Counter " << nEvt_ <<"\n";
180  std::cout << "ConvertedPhotonAnalyzer Analyzing event number: " << e.id() << " Global Counter " << nEvt_ <<"\n";
181 
182 
184  Handle<reco::PhotonCollection> photonHandle;
185  e.getByLabel(photonCollectionProducer_, photonCollection_ , photonHandle);
186  const reco::PhotonCollection photonCollection = *(photonHandle.product());
187  std::cout << "ConvertedPhotonAnalyzer Photons with conversions collection size " << photonCollection.size() << "\n";
188 
189 
191  std::cout << " ConvertedPhotonAnalyzer Looking for MC truth " << "\n";
192 
193  //get simtrack info
194  std::vector<SimTrack> theSimTracks;
195  std::vector<SimVertex> theSimVertices;
196 
199  e.getByLabel("g4SimHits",SimTk);
200  e.getByLabel("g4SimHits",SimVtx);
201 
202  theSimTracks.insert(theSimTracks.end(),SimTk->begin(),SimTk->end());
203  theSimVertices.insert(theSimVertices.end(),SimVtx->begin(),SimVtx->end());
204 
205  std::vector<PhotonMCTruth> mcPhotons=thePhotonMCTruthFinder_->find (theSimTracks, theSimVertices);
206  std::cout << " ConvertedPhotonAnalyzer mcPhotons size " << mcPhotons.size() << std::endl;
207 
208 
209 
210  // Loop over simulated photons
211  //UNUSED int iDet=0;
212  //UNUSED int iRadius=-1;
213  //UNUSED int indPho=0;
214 
215  for ( std::vector<PhotonMCTruth>::const_iterator mcPho=mcPhotons.begin(); mcPho !=mcPhotons.end(); mcPho++) {
216  float mcPhi= (*mcPho).fourMomentum().phi();
217  float mcEta= (*mcPho).fourMomentum().pseudoRapidity();
218  mcEta = etaTransformation(mcEta, (*mcPho).primaryVertex().z() );
219 
220  if ( (*mcPho).fourMomentum().et() < 20 ) continue;
221  // if ( ! ( fabs(mcEta) <= BARL || ( fabs(mcEta) >= END_LO && fabs(mcEta) <=END_HI ) ) ) {
222  // continue;
223  //} // all ecal fiducial region
224 
225 
226 
227  h_MCphoE_->Fill( (*mcPho).fourMomentum().e());
228  h_MCphoEta_->Fill( (*mcPho).fourMomentum().eta());
229  h_MCphoPhi_->Fill( (*mcPho).fourMomentum().phi());
230 
231 
232 
233  // keep only visible conversions
234  if ( (*mcPho).isAConversion() == 0 ) continue;
235 
236 
237  nMCPho_++;
238 
239  h_MCConvEta_ ->Fill ( fabs( (*mcPho).fourMomentum().pseudoRapidity()) - 0.001);
240 
241 
242  bool REJECTED;
243 
244 
246  //std::cout << " ConvertedPhotonAnalyzer Starting loop over photon candidates " << "\n";
247  for( reco::PhotonCollection::const_iterator iPho = photonCollection.begin(); iPho != photonCollection.end(); iPho++) {
248  REJECTED=false;
249 
250  // std::cout << " ConvertedPhotonAnalyzer Reco SC energy " << (*iPho).superCluster()->energy() << "\n";
251 
252  float phiClu=(*iPho).superCluster()->phi();
253  float etaClu=(*iPho).superCluster()->eta();
254  float deltaPhi = phiClu-mcPhi;
255  float deltaEta = etaClu-mcEta;
256 
257 
258  if ( deltaPhi > Geom::pi() ) deltaPhi -= Geom::twoPi();
259  if ( deltaPhi < -Geom::pi() ) deltaPhi += Geom::twoPi();
260  deltaPhi=pow(deltaPhi,2);
261  deltaEta=pow(deltaEta,2);
262  float delta = deltaPhi+deltaEta ;
263  if ( delta >= etaPhiDistance ) REJECTED=true;
264 
265 
266  // if ( ! ( fabs(etaClu) <= BARL || ( fabs(etaClu) >= END_LO && fabs(etaClu) <=END_HI ) ) ) REJECTED=true;
267 
268  if ( REJECTED ) continue;
269  std::cout << " MATCHED " << std::endl;
270  nMatched_++;
271 
272 
273  // std::cout << " ConvertedPhotonAnalyzer Matching candidate " << std::endl;
274 
275  // std::cout << " ConvertedPhotonAnalyzer Photons isAconversion " << (*mcPho).isAConversion() << " mcMatchingPhoton energy " << (*mcPho).fourMomentum().e() << " ConvertedPhotonAnalyzer conversion vertex R " << (*mcPho).vertex().perp() << " Z " << (*mcPho).vertex().z() << std::endl;
276 
277 
278  h_ErecoEMC_->Fill( (*iPho).superCluster()->energy()/(*mcPho).fourMomentum().e());
279  h_deltaPhi_-> Fill ( (*iPho).superCluster()->position().phi()- mcPhi);
280  h_deltaEta_-> Fill ( (*iPho).superCluster()->position().eta()- mcEta);
281 
282  h_scE_->Fill( (*iPho).superCluster()->energy() );
283  h_scEt_->Fill( (*iPho).superCluster()->energy()/cosh( (*iPho).superCluster()->position().eta()) );
284  h_scEta_->Fill( (*iPho).superCluster()->position().eta() );
285  h_scPhi_->Fill( (*iPho).superCluster()->position().phi() );
286 
287 
288  h_phoE_->Fill( (*iPho).energy() );
289  h_phoEta_->Fill( (*iPho).eta() );
290  h_phoPhi_->Fill( (*iPho).phi() );
291 
292  if ( !(*iPho).hasConversionTracks() ) continue;
293  // std::cout << " This photons has " << (*iPho).conversions().size() << " conversions candidates " << std::endl;
294  reco::ConversionRefVector conversions = (*iPho).conversions();
295  //std::vector<reco::ConversionRef> conversions = (*iPho).conversions();
296 
297 
298  for (unsigned int i=0; i<conversions.size(); i++) {
299  //std::cout << " Conversion candidate Energy " << (*iPho).energy() << " number of tracks " << conversions[i]->nTracks() << std::endl;
300  std::vector< edm::RefToBase<reco::Track> > tracks = conversions[i]->tracks();
301 
302  for (unsigned int i=0; i<tracks.size(); i++) {
303 
304  // std::cout << " ConvertedPhotonAnalyzer Reco Track charge " << tracks[i]->charge() << " Num of RecHits " << tracks[i]->recHitsSize() << " inner momentum " << sqrt ( tracks[i]->innerMomentum().Mag2() ) << "\n";
305 
306 
307  h2_tk_nHitsVsR_ -> Fill ( (*mcPho).vertex().perp(), tracks[i]->recHitsSize() );
308  h2_tk_inPtVsR_->Fill ( (*mcPho).vertex().perp(), sqrt( tracks[i]->innerMomentum().Mag2() ) );
309  }
310 
311  }
312 
313 
314  }
315 
316  }
317 
318 
319 }
320 
321 
322 
323 
325 {
326 
327 
328 
329 
330  // fOutputFile_->Write() ;
331  // fOutputFile_->Close() ;
332 
333  edm::LogInfo("ConvertedPhotonAnalyzer") << "Analyzed " << nEvt_ << "\n";
334  // std::cout << "::endJob Analyzed " << nEvt_ << " events " << " with total " << nPho_ << " Photons " << "\n";
335  std::cout << "ConvertedPhotonAnalyzer::endJob Analyzed " << nEvt_ << " events " << "\n";
336 
337  return ;
338 }
339 
340 
341 
dbl * delta
Definition: mlp_gen.cc:36
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
#define PI
virtual void analyze(const edm::Event &, const edm::EventSetup &)
PhotonsWithConversionsAnalyzer(const edm::ParameterSet &)
#define ETA
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
T sqrt(T t)
Definition: SSEVec.h:46
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
tuple tracks
Definition: testEve_cfg.py:39
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
static const float etaBarrelEndcap
static const float Z_Endcap
edm::EventID id() const
Definition: EventBase.h:56
double pi()
Definition: Pi.h:31
double twoPi()
Definition: Pi.h:32
T * make() const
make new ROOT object
static const float R_ECAL
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
tuple cout
Definition: gather_cfg.py:121
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40