CMS 3D CMS Logo

SimpleConvertedPhotonAnalyzer.cc
Go to the documentation of this file.
1 #include <iostream>
2 //
7 //
13 //
20 //
27 //#include "DataFormats/EgammaReco/interface/SuperCluster.h"
29 //
32 
33 //
34 #include "TFile.h"
35 #include "TH1.h"
36 #include "TH2.h"
37 #include "TTree.h"
38 #include "TVector3.h"
39 #include "TProfile.h"
40 //
41 
42 using namespace std;
43 
45  : fOutputFileName_(pset.getUntrackedParameter<string>("HistOutFile", std::string("TestConversions.root"))),
46  fOutputFile_(nullptr) {
47  convertedPhotonCollectionProducer_ = pset.getParameter<std::string>("phoProducer");
48  convertedPhotonCollection_ = pset.getParameter<std::string>("convertedPhotonCollection");
49  //
50 }
51 
53 
55  nEvt_ = 0;
56  nMCPho_ = 0;
57  nMatched_ = 0;
58 
60 
61  fOutputFile_ = new TFile(fOutputFileName_.c_str(), "RECREATE");
62 
64  h_ErecoEMC_ = new TH1F("deltaE", " delta(reco-mc) energy", 100, 0., 2.);
65  h_deltaPhi_ = new TH1F("deltaPhi", " delta(reco-mc) phi", 100, -0.1, 0.1);
66  h_deltaEta_ = new TH1F("deltaEta", " delta(reco-mc) eta", 100, -0.05, 0.05);
67 
69  h_MCphoE_ = new TH1F("MCphoE", "MC photon energy", 100, 0., 100.);
70  h_MCphoPhi_ = new TH1F("MCphoPhi", "MC photon phi", 40, -3.14, 3.14);
71  h_MCphoEta_ = new TH1F("MCphoEta", "MC photon eta", 40, -3., 3.);
72 
74  h_MCConvE_ = new TH1F("MCConvE", "MC converted photon energy", 100, 0., 100.);
75  h_MCConvPt_ = new TH1F("MCConvPt", "MC converted photon pt", 100, 0., 100.);
76  h_MCConvEta_ = new TH1F("MCConvEta", "MC converted photon eta", 50, 0., 2.5);
77 
79  h_scE_ = new TH1F("scE", "Uncorrected converted photons : SC Energy ", 100, 0., 200.);
80  h_scEta_ = new TH1F("scEta", "Uncorrected converted photons: SC Eta ", 40, -3., 3.);
81  h_scPhi_ = new TH1F("scPhi", "Uncorrected converted photons: SC Phi ", 40, -3.14, 3.14);
82  //
83  h_phoE_ = new TH1F("phoE", "Uncorrected converted photons : Energy ", 100, 0., 200.);
84  h_phoEta_ = new TH1F("phoEta", "Uncorrected converted photons: Eta ", 40, -3., 3.);
85  h_phoPhi_ = new TH1F("phoPhi", "Uncorrected converted photons: Phi ", 40, -3.14, 3.14);
86 
87  // Recontructed tracks from converted photon candidates
88  h2_tk_nHitsVsR_ = new TH2F("tknHitsVsR", "Tracks Hits vs R ", 12, 0., 120., 20, 0.5, 20.5);
89  h2_tk_inPtVsR_ = new TH2F("tkInPtvsR", "Tracks inner Pt vs R ", 12, 0., 120., 100, 0., 100.);
90 
91  return;
92 }
93 
94 float SimpleConvertedPhotonAnalyzer::etaTransformation(float EtaParticle, float Zvertex) {
95  //---Definitions
96  const float PI = 3.1415927;
97  //UNUSED const float TWOPI = 2.0*PI;
98 
99  //---Definitions for ECAL
100  const float R_ECAL = 136.5;
101  const float Z_Endcap = 328.0;
102  const float etaBarrelEndcap = 1.479;
103 
104  //---ETA correction
105 
106  float Theta = 0.0;
107  float ZEcal = R_ECAL * sinh(EtaParticle) + Zvertex;
108 
109  if (ZEcal != 0.0)
110  Theta = atan(R_ECAL / ZEcal);
111  if (Theta < 0.0)
112  Theta = Theta + PI;
113  float ETA = -log(tan(0.5 * Theta));
114 
115  if (fabs(ETA) > etaBarrelEndcap) {
116  float Zend = Z_Endcap;
117  if (EtaParticle < 0.0)
118  Zend = -Zend;
119  float Zlen = Zend - Zvertex;
120  float RR = Zlen / sinh(EtaParticle);
121  Theta = atan(RR / Zend);
122  if (Theta < 0.0)
123  Theta = Theta + PI;
124  ETA = -log(tan(0.5 * Theta));
125  }
126  //---Return the result
127  return ETA;
128  //---end
129 }
130 
132  using namespace edm;
133  const float etaPhiDistance = 0.01;
134  // Fiducial region
135  //UNUSED const float TRK_BARL =0.9;
136  const float BARL = 1.4442; // DAQ TDR p.290
137  const float END_LO = 1.566;
138  const float END_HI = 2.5;
139  // Electron mass
140  //UNUSED const Float_t mElec= 0.000511;
141 
142  nEvt_++;
143  LogInfo("ConvertedPhotonAnalyzer") << "ConvertedPhotonAnalyzer Analyzing event number: " << e.id()
144  << " Global Counter " << nEvt_ << "\n";
145  // LogDebug("ConvertedPhotonAnalyzer") << "ConvertedPhotonAnalyzer Analyzing event number: " << e.id() << " Global Counter " << nEvt_ <<"\n";
146  std::cout << "ConvertedPhotonAnalyzer Analyzing event number: " << e.id() << " Global Counter " << nEvt_ << "\n";
147 
149  Handle<reco::ConversionCollection> convertedPhotonHandle;
150  e.getByLabel(convertedPhotonCollectionProducer_, convertedPhotonCollection_, convertedPhotonHandle);
151  const reco::ConversionCollection phoCollection = *(convertedPhotonHandle.product());
152  std::cout << "ConvertedPhotonAnalyzer Converted photon collection size " << phoCollection.size() << "\n";
153 
155  std::cout << " ConvertedPhotonAnalyzer Looking for MC truth "
156  << "\n";
157 
158  //get simtrack info
159  std::vector<SimTrack> theSimTracks;
160  std::vector<SimVertex> theSimVertices;
161 
164  e.getByLabel("g4SimHits", SimTk);
165  e.getByLabel("g4SimHits", SimVtx);
166 
167  theSimTracks.insert(theSimTracks.end(), SimTk->begin(), SimTk->end());
168  theSimVertices.insert(theSimVertices.end(), SimVtx->begin(), SimVtx->end());
169 
170  std::vector<PhotonMCTruth> mcPhotons = thePhotonMCTruthFinder_->find(theSimTracks, theSimVertices);
171  std::cout << " ConvertedPhotonAnalyzer mcPhotons size " << mcPhotons.size() << std::endl;
172 
173  // Loop over simulated photons
174  //UNUSED int iDet=0;
175  //UNUSED int iRadius=-1;
176  //UNUSED int indPho=0;
177 
178  for (std::vector<PhotonMCTruth>::const_iterator mcPho = mcPhotons.begin(); mcPho != mcPhotons.end(); mcPho++) {
179  float mcPhi = (*mcPho).fourMomentum().phi();
180  float mcEta = (*mcPho).fourMomentum().pseudoRapidity();
181  mcEta = etaTransformation(mcEta, (*mcPho).primaryVertex().z());
182 
183  if (!(fabs(mcEta) <= BARL || (fabs(mcEta) >= END_LO && fabs(mcEta) <= END_HI))) {
184  continue;
185  } // all ecal fiducial region
186 
187  std::cout << " ConvertedPhotonAnalyzer MC Photons before matching " << std::endl;
188  std::cout << " ConvertedPhotonAnalyzer Photons isAconversion " << (*mcPho).isAConversion()
189  << " mcMatchingPhoton energy " << (*mcPho).fourMomentum().e() << " conversion vertex R "
190  << (*mcPho).vertex().perp() << " Z " << (*mcPho).vertex().z() << " x " << (*mcPho).vertex().x() << " y "
191  << (*mcPho).vertex().y() << " z " << (*mcPho).vertex().z() << std::endl;
192  std::cout << " ConvertedPhotonAnalyzer mcEta " << mcEta << " mcPhi " << mcPhi << std::endl;
193 
194  h_MCphoE_->Fill((*mcPho).fourMomentum().e());
195  h_MCphoEta_->Fill((*mcPho).fourMomentum().eta());
196  h_MCphoPhi_->Fill((*mcPho).fourMomentum().phi());
197 
198  // keep only visible conversions
199  if ((*mcPho).isAConversion() == 0)
200  continue;
201 
202  nMCPho_++;
203 
204  h_MCConvEta_->Fill(fabs((*mcPho).fourMomentum().pseudoRapidity()) - 0.001);
205 
206  bool REJECTED;
207 
209  std::cout << " ConvertedPhotonAnalyzer Starting loop over photon candidates "
210  << "\n";
211  for (reco::ConversionCollection::const_iterator iPho = phoCollection.begin(); iPho != phoCollection.end(); iPho++) {
212  REJECTED = false;
213 
214  std::cout << " ConvertedPhotonAnalyzer Reco SC energy " << (*iPho).caloCluster()[0]->energy() << "\n";
215 
216  float phiClu = (*iPho).caloCluster()[0]->phi();
217  float etaClu = (*iPho).caloCluster()[0]->eta();
218  float deltaPhi = phiClu - mcPhi;
219  float deltaEta = etaClu - mcEta;
220 
221  if (deltaPhi > Geom::pi())
222  deltaPhi -= Geom::twoPi();
223  if (deltaPhi < -Geom::pi())
224  deltaPhi += Geom::twoPi();
225  deltaPhi = std::pow(deltaPhi, 2);
226  deltaEta = std::pow(deltaEta, 2);
227  float delta = deltaPhi + deltaEta;
228  if (delta >= etaPhiDistance)
229  REJECTED = true;
230 
231  // if ( ! ( fabs(etaClu) <= BARL || ( fabs(etaClu) >= END_LO && fabs(etaClu) <=END_HI ) ) ) REJECTED=true;
232 
233  if (REJECTED)
234  continue;
235  std::cout << " MATCHED " << std::endl;
236  nMatched_++;
237 
238  std::cout << " ConvertedPhotonAnalyzer Matching candidate " << std::endl;
239 
240  std::cout << " ConvertedPhotonAnalyzer Photons isAconversion " << (*mcPho).isAConversion()
241  << " mcMatchingPhoton energy " << (*mcPho).fourMomentum().e()
242  << " ConvertedPhotonAnalyzer conversion vertex R " << (*mcPho).vertex().perp() << " Z "
243  << (*mcPho).vertex().z() << std::endl;
244 
245  h_ErecoEMC_->Fill((*iPho).caloCluster()[0]->energy() / (*mcPho).fourMomentum().e());
246  h_deltaPhi_->Fill((*iPho).caloCluster()[0]->position().phi() - mcPhi);
247  h_deltaEta_->Fill((*iPho).caloCluster()[0]->position().eta() - mcEta);
248 
249  h_scE_->Fill((*iPho).caloCluster()[0]->energy());
250  h_scEta_->Fill((*iPho).caloCluster()[0]->position().eta());
251  h_scPhi_->Fill((*iPho).caloCluster()[0]->position().phi());
252 
253  for (unsigned int i = 0; i < (*iPho).tracks().size(); i++) {
254  std::cout << " ConvertedPhotonAnalyzer Reco Track charge " << (*iPho).tracks()[i]->charge()
255  << " Num of RecHits " << (*iPho).tracks()[i]->recHitsSize() << " inner momentum "
256  << sqrt((*iPho).tracks()[i]->innerMomentum().Mag2()) << "\n";
257 
258  h2_tk_nHitsVsR_->Fill((*mcPho).vertex().perp(), (*iPho).tracks()[i]->recHitsSize());
259  h2_tk_inPtVsR_->Fill((*mcPho).vertex().perp(), sqrt((*iPho).tracks()[i]->innerMomentum().Mag2()));
260  }
261 
262  }
263 
264  }
265 }
266 
268  fOutputFile_->Write();
269  fOutputFile_->Close();
270 
271  edm::LogInfo("ConvertedPhotonAnalyzer") << "Analyzed " << nEvt_ << "\n";
272  // std::cout << "::endJob Analyzed " << nEvt_ << " events " << " with total " << nPho_ << " Photons " << "\n";
273  std::cout << "ConvertedPhotonAnalyzer::endJob Analyzed " << nEvt_ << " events "
274  << "\n";
275 
276  return;
277 }
SimpleConvertedPhotonAnalyzer::h_MCConvEta_
TH1F * h_MCConvEta_
Definition: SimpleConvertedPhotonAnalyzer.h:63
PI
Definition: PayloadInspector.h:19
TrackExtra.h
Handle.h
mps_fire.i
i
Definition: mps_fire.py:355
SimpleConvertedPhotonAnalyzer::SimpleConvertedPhotonAnalyzer
SimpleConvertedPhotonAnalyzer(const edm::ParameterSet &)
Definition: SimpleConvertedPhotonAnalyzer.cc:44
MessageLogger.h
SimpleConvertedPhotonAnalyzer::h_phoE_
TH1F * h_phoE_
Definition: SimpleConvertedPhotonAnalyzer.h:70
edm::Handle::product
T const * product() const
Definition: Handle.h:70
ESHandle.h
PI
#define PI
Definition: QcdUeDQM.h:37
edm
HLT enums.
Definition: AlignableModifier.h:19
SimpleConvertedPhotonAnalyzer.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::LogInfo
Definition: MessageLogger.h:254
SimpleConvertedPhotonAnalyzer::h_MCphoE_
TH1F * h_MCphoE_
Definition: SimpleConvertedPhotonAnalyzer.h:56
PhotonMCTruthFinder::find
std::vector< PhotonMCTruth > find(const std::vector< SimTrack > &simTracks, const std::vector< SimVertex > &simVertices)
Definition: PhotonMCTruthFinder.cc:17
SimpleConvertedPhotonAnalyzer::nEvt_
int nEvt_
Definition: SimpleConvertedPhotonAnalyzer.h:39
ConversionFwd.h
edm::Handle< reco::ConversionCollection >
SimpleConvertedPhotonAnalyzer::h_MCConvPt_
TH1F * h_MCConvPt_
Definition: SimpleConvertedPhotonAnalyzer.h:62
reco::ConversionCollection
std::vector< Conversion > ConversionCollection
collectin of Conversion objects
Definition: ConversionFwd.h:9
MakerMacros.h
Track.h
TrackFwd.h
spr::deltaEta
static const double deltaEta
Definition: CaloConstants.h:8
ElectronMCTruth.h
SimpleConvertedPhotonAnalyzer::h_deltaPhi_
TH1F * h_deltaPhi_
Definition: SimpleConvertedPhotonAnalyzer.h:52
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
SimpleConvertedPhotonAnalyzer::endJob
void endJob() override
Definition: SimpleConvertedPhotonAnalyzer.cc:267
PhotonMCTruth.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
SimVertex.h
IdealMagneticFieldRecord.h
SimpleConvertedPhotonAnalyzer::h_phoPhi_
TH1F * h_phoPhi_
Definition: SimpleConvertedPhotonAnalyzer.h:72
Geom::pi
constexpr double pi()
Definition: Pi.h:31
Geom::twoPi
constexpr double twoPi()
Definition: Pi.h:32
PhotonMCTruthFinder
Definition: PhotonMCTruthFinder.h:20
SimpleConvertedPhotonAnalyzer::h_scE_
TH1F * h_scE_
Definition: SimpleConvertedPhotonAnalyzer.h:66
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PhotonMCTruthFinder.h
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
SimpleConvertedPhotonAnalyzer::fOutputFile_
TFile * fOutputFile_
Definition: SimpleConvertedPhotonAnalyzer.h:37
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
SimpleConvertedPhotonAnalyzer::convertedPhotonCollectionProducer_
std::string convertedPhotonCollectionProducer_
Definition: SimpleConvertedPhotonAnalyzer.h:48
SimpleConvertedPhotonAnalyzer::thePhotonMCTruthFinder_
PhotonMCTruthFinder * thePhotonMCTruthFinder_
Definition: SimpleConvertedPhotonAnalyzer.h:34
SimpleConvertedPhotonAnalyzer::h_deltaEta_
TH1F * h_deltaEta_
Definition: SimpleConvertedPhotonAnalyzer.h:53
SimpleConvertedPhotonAnalyzer::nMatched_
int nMatched_
Definition: SimpleConvertedPhotonAnalyzer.h:41
MagneticField.h
edm::EventSetup
Definition: EventSetup.h:57
SimpleConvertedPhotonAnalyzer::h_scEta_
TH1F * h_scEta_
Definition: SimpleConvertedPhotonAnalyzer.h:67
SimpleConvertedPhotonAnalyzer::h_MCphoPhi_
TH1F * h_MCphoPhi_
Definition: SimpleConvertedPhotonAnalyzer.h:57
SimpleConvertedPhotonAnalyzer::h2_tk_nHitsVsR_
TH2F * h2_tk_nHitsVsR_
Definition: SimpleConvertedPhotonAnalyzer.h:75
SimpleConvertedPhotonAnalyzer::~SimpleConvertedPhotonAnalyzer
~SimpleConvertedPhotonAnalyzer() override
Definition: SimpleConvertedPhotonAnalyzer.cc:52
std
Definition: JetResolutionObject.h:76
SimpleConvertedPhotonAnalyzer::h_phoEta_
TH1F * h_phoEta_
Definition: SimpleConvertedPhotonAnalyzer.h:71
SimpleConvertedPhotonAnalyzer::h_scPhi_
TH1F * h_scPhi_
Definition: SimpleConvertedPhotonAnalyzer.h:68
SimpleConvertedPhotonAnalyzer::nMCPho_
int nMCPho_
Definition: SimpleConvertedPhotonAnalyzer.h:40
SimpleConvertedPhotonAnalyzer::convertedPhotonCollection_
std::string convertedPhotonCollection_
Definition: SimpleConvertedPhotonAnalyzer.h:49
ETA
#define ETA
Definition: GenericBenchmark.cc:28
SimpleConvertedPhotonAnalyzer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: SimpleConvertedPhotonAnalyzer.cc:131
SimpleConvertedPhotonAnalyzer::h_MCphoEta_
TH1F * h_MCphoEta_
Definition: SimpleConvertedPhotonAnalyzer.h:58
EventSetup.h
Exception.h
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
SimpleConvertedPhotonAnalyzer::etaTransformation
float etaTransformation(float a, float b)
Definition: SimpleConvertedPhotonAnalyzer.cc:94
SimTrack.h
SimpleConvertedPhotonAnalyzer::h_MCConvE_
TH1F * h_MCConvE_
Definition: SimpleConvertedPhotonAnalyzer.h:61
HepMCProduct.h
ZEcal
static constexpr float ZEcal
Definition: L1TkEmParticleProducer.cc:40
edm::Event
Definition: Event.h:73
SimpleConvertedPhotonAnalyzer::fOutputFileName_
std::string fOutputFileName_
Definition: SimpleConvertedPhotonAnalyzer.h:36
SimTrackContainer.h
SimpleConvertedPhotonAnalyzer::h2_tk_inPtVsR_
TH2F * h2_tk_inPtVsR_
Definition: SimpleConvertedPhotonAnalyzer.h:77
SimpleConvertedPhotonAnalyzer::beginJob
void beginJob() override
Definition: SimpleConvertedPhotonAnalyzer.cc:54
Z_Endcap
static constexpr float Z_Endcap
Definition: ECALPositionCalculator.cc:11
SimVertexContainer.h
R_ECAL
static constexpr float R_ECAL
Definition: ECALPositionCalculator.cc:10
SimpleConvertedPhotonAnalyzer::h_ErecoEMC_
TH1F * h_ErecoEMC_
Definition: SimpleConvertedPhotonAnalyzer.h:51
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
CaloCluster.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
etaBarrelEndcap
static constexpr float etaBarrelEndcap
Definition: ECALPositionCalculator.cc:12
Conversion.h