CMS 3D CMS Logo

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