CMS 3D CMS Logo

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