00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019 #include "Validation/EcalClusters/interface/EnergyScaleAnalyzer.h"
00020 #include "RecoEcal/EgammaClusterProducers/interface/PreshowerAnalyzer.h"
00021 #include "RecoEcal/EgammaClusterProducers/interface/PreshowerClusterProducer.h"
00022
00023
00024 #include "FWCore/Framework/interface/Frameworkfwd.h"
00025 #include "FWCore/Framework/interface/EDAnalyzer.h"
00026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00027 #include "FWCore/Utilities/interface/Exception.h"
00028 #include "DataFormats/Common/interface/Handle.h"
00029 #include "FWCore/Framework/interface/Event.h"
00030 #include "FWCore/Framework/interface/MakerMacros.h"
00031 #include "FWCore/Framework/interface/EventSetup.h"
00032 #include "FWCore/Framework/interface/ESHandle.h"
00033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00034
00035
00036 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00037 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00038 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00039 #include "Geometry/CaloTopology/interface/EcalBarrelHardcodedTopology.h"
00040 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00041 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00042
00043 #include "TFile.h"
00044
00045 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00046 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00047 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00048 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00049 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00050 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
00051 #include "DataFormats/EgammaReco/interface/PreshowerCluster.h"
00052 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00053
00054 #include "DataFormats/EgammaReco/interface/BasicClusterShapeAssociation.h"
00055 #include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
00056 #include "DataFormats/Math/interface/LorentzVector.h"
00057
00059 #include "RecoEcal/EgammaClusterProducers/interface/HybridClusterProducer.h"
00060 #include "RecoEcal/EgammaCoreTools/interface/ClusterShapeAlgo.h"
00061 #include "DataFormats/EgammaReco/interface/ClusterShape.h"
00062 #include "DataFormats/EgammaReco/interface/ClusterShapeFwd.h"
00063 #include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
00064 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00065
00066 #include <iostream>
00067 #include <fstream>
00068 #include <iomanip>
00069 #include <ios>
00070 #include <map>
00071 #include "TString.h"
00072 #include "Validation/EcalClusters/interface/AnglesUtil.h"
00073
00074
00075 EnergyScaleAnalyzer::EnergyScaleAnalyzer( const edm::ParameterSet& ps )
00076
00077 {
00078
00079 hepMCLabel_ = ps.getParameter<std::string>("hepMCLabel");
00080
00081 outputFile_ = ps.getParameter<std::string>("outputFile");
00082 rootFile_ = TFile::Open(outputFile_.c_str(),"RECREATE");
00083
00084 evtN = 0;
00085 }
00086
00087
00088
00089 EnergyScaleAnalyzer::~EnergyScaleAnalyzer()
00090
00091 {
00092 delete rootFile_;
00093 }
00094
00095
00096 void
00097 EnergyScaleAnalyzer::beginJob() {
00098
00099
00100 mytree_ = new TTree("energyScale","");
00101 TString treeVariables = "mc_npar/I:parID:mc_sep/F:mc_e:mc_et:mc_phi:mc_eta:mc_theta:";
00102 treeVariables += "em_dR/F:";
00103 treeVariables += "em_isInCrack/I:em_scType:em_e/F:em_et:em_phi:em_eta:em_theta:em_nCell/I:em_nBC:";
00104 treeVariables += "em_pet/F:em_pe:em_peta:em_ptheta:" ;
00105
00106 treeVariables += "emCorr_e/F:emCorr_et:emCorr_eta:emCorr_phi:emCorr_theta:";
00107 treeVariables += "emCorr_pet/F:emCorr_peta:emCorr_ptheta:" ;
00108
00109 treeVariables += "em_pw/F:em_ew:em_br" ;
00110
00111 mytree_->Branch("energyScale",&(tree_.mc_npar),treeVariables);
00112
00113 }
00114
00115
00116 void
00117 EnergyScaleAnalyzer::analyze( const edm::Event& evt, const edm::EventSetup& es ) {
00118 using namespace edm;
00119 using namespace std;
00120
00121
00122
00123
00124
00125
00126 Handle<HepMCProduct> hepMC;
00127 evt.getByLabel( hepMCLabel_, hepMC ) ;
00128
00129 const HepMC::GenEvent* genEvent = hepMC->GetEvent();
00130 if ( !(hepMC.isValid())) {
00131 LogInfo("EnergyScaleAnalyzer") << "Could not get MC Product!";
00132 return;
00133 }
00134
00135
00136
00137 std::vector< Handle< HepMCProduct > > evtHandles ;
00138 evt.getManyByType( evtHandles ) ;
00139
00140 for ( unsigned int i=0; i<evtHandles.size(); ++i) {
00141 if ( evtHandles[i].isValid() ) {
00142 const HepMC::GenEvent* evt = evtHandles[i]->GetEvent() ;
00143
00144
00145
00146 HepMC::GenEvent::vertex_const_iterator vtx = evt->vertices_begin() ;
00147 if ( evtHandles[i].provenance()->moduleLabel() == hepMCLabel_ ) {
00148
00149 xVtx_ = 0.1*(*vtx)->position().x();
00150 yVtx_ = 0.1*(*vtx)->position().y();
00151 zVtx_ = 0.1*(*vtx)->position().z();
00152 }
00153 }
00154 }
00155
00156
00157
00158 Handle<reco::SuperClusterCollection> hybridSuperClusters;
00159 try {
00160 evt.getByLabel("hybridSuperClusters","",hybridSuperClusters);
00161 }catch (cms::Exception& ex) {
00162 edm::LogError("EnergyScaleAnalyzer") << "Can't get collection with producer hybridSuperClusters.";
00163 }
00164
00165 Handle<reco::SuperClusterCollection> dynamicHybridSuperClusters;
00166 try {
00167 evt.getByLabel("dynamicHybridSuperClusters","",dynamicHybridSuperClusters);
00168 }catch (cms::Exception& ex) {
00169 edm::LogError("EnergyScaleAnalyzer") << "Can't get collection with producer dynamicHybridSuperClusters.";
00170 }
00171
00172 Handle<reco::SuperClusterCollection> fixedMatrixSuperClustersWithPS;
00173 try {
00174 evt.getByLabel("fixedMatrixSuperClustersWithPreshower","",fixedMatrixSuperClustersWithPS);
00175 }catch (cms::Exception& ex) {
00176 edm::LogError("EnergyScaleAnalyzer") << "Can't get collection with producer fixedMatrixSuperClustersWithPreshower.";
00177 }
00178
00179
00180 Handle<reco::SuperClusterCollection> correctedHybridSC;
00181 try {
00182 evt.getByLabel("correctedHybridSuperClusters","",correctedHybridSC);
00183 }catch (cms::Exception& ex) {
00184 edm::LogError("EnergyScaleAnalyzer") << "Can't get collection with producer correctedHybridSuperClusters.";
00185 }
00186
00187 Handle<reco::SuperClusterCollection> correctedDynamicHybridSC;
00188 try{
00189 evt.getByLabel("correctedDynamicHybridSuperClusters","",correctedDynamicHybridSC);
00190 }catch (cms::Exception& ex) {
00191 edm::LogError("EnergyScaleAnalyzer") << "Can't get collection with producer correctedDynamicHybridSuperClusters.";
00192 }
00193
00194 Handle<reco::SuperClusterCollection> correctedFixedMatrixSCWithPS;
00195 try {
00196 evt.getByLabel("correctedFixedMatrixSuperClustersWithPreshower","",correctedFixedMatrixSCWithPS);
00197 }catch (cms::Exception& ex ) {
00198 edm::LogError("EnergyScaleAnalyzer") << "Can't get collection with producer correctedFixedMatrixSuperClustersWithPreshower.";
00199 }
00200
00201 const reco::SuperClusterCollection* dSC = dynamicHybridSuperClusters.product();
00202 const reco::SuperClusterCollection* hSC = hybridSuperClusters.product();
00203 const reco::SuperClusterCollection* fmSC = fixedMatrixSuperClustersWithPS.product();
00204 const reco::SuperClusterCollection* chSC = correctedHybridSC.product();
00205 const reco::SuperClusterCollection* cdSC = correctedDynamicHybridSC.product();
00206 const reco::SuperClusterCollection* cfmSC = correctedFixedMatrixSCWithPS.product();
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 HepMC::GenEvent::particle_const_iterator p = genEvent->particles_begin();
00245
00246
00247 float min_eT = 5;
00248 float max_eta = 2.5;
00249
00250 std::vector<HepMC::GenParticle* > mcParticles;
00251
00252 for ( HepMC::GenEvent::particle_const_iterator p = genEvent->particles_begin();
00253 p != genEvent->particles_end();
00254 ++p ) {
00255
00256
00257
00258 if ( (*p)->pdg_id() != 22 && abs((*p)->pdg_id()) != 11 ) continue;
00259
00260
00261 bool satisfySelectionCriteria =
00262 (*p)->momentum().perp() > min_eT &&
00263 fabs((*p)->momentum().eta()) < max_eta;
00264
00265 if ( ! satisfySelectionCriteria ) continue;
00266
00267
00268 mcParticles.push_back(*p);
00269 }
00270
00271
00272 if ( mcParticles.size() == 2 ) {
00273 HepMC::GenParticle* mc1 = mcParticles[0];
00274 HepMC::GenParticle* mc2 = mcParticles[1];
00275 tree_.mc_sep = kinem::delta_R(mc1->momentum().eta(), mc1->momentum().phi(),
00276 mc2->momentum().eta(), mc2->momentum().phi());
00277 } else
00278 tree_.mc_sep = -100;
00279
00280
00281
00282
00283 for(std::vector<HepMC::GenParticle* >::const_iterator p = mcParticles.begin();
00284 p != mcParticles.end(); ++p) {
00285 HepMC::GenParticle* mc = *p;
00286
00287
00288 tree_.mc_npar = mcParticles.size();
00289 tree_.parID = mc->pdg_id();
00290 tree_.mc_e = mc->momentum().e();
00291 tree_.mc_et = mc->momentum().e()*sin(mc->momentum().theta());
00292 tree_.mc_phi = mc->momentum().phi();
00293 tree_.mc_eta = mc->momentum().eta();
00294 tree_.mc_theta = mc->momentum().theta();
00295
00296
00297
00298
00299
00300
00301
00302
00303 fillTree( hSC, chSC, mc, tree_, xVtx_, yVtx_, zVtx_, 1);
00304
00305
00306 fillTree( dSC, cdSC, mc, tree_, xVtx_, yVtx_, zVtx_, 2);
00307
00308
00309 fillTree( fmSC, cfmSC, mc, tree_, xVtx_, yVtx_, zVtx_, 3);
00310
00311
00312
00313 }
00314 }
00315
00316
00317 void EnergyScaleAnalyzer::fillTree ( const reco::SuperClusterCollection* scColl, const reco::SuperClusterCollection* corrSCColl,
00318 HepMC::GenParticle* mc, tree_structure_& tree_, float xV, float yV, float zV, int scType) {
00319
00320
00321 reco::SuperClusterCollection::const_iterator em = scColl->end();
00322 float energyMax = -100.0;
00323 for(reco::SuperClusterCollection::const_iterator aClus = scColl->begin();
00324 aClus != scColl->end(); ++aClus) {
00325
00326 float dR = kinem::delta_R(mc ->momentum().eta(), mc ->momentum().phi(),
00327 aClus->position().eta(), aClus->position().phi());
00328 if (dR < 0.4) {
00329 float energy = aClus->energy();
00330 if ( energy < energyMax ) continue;
00331 energyMax = energy;
00332 em = aClus;
00333 }
00334 }
00335
00336 if (em == scColl->end() ) {
00337
00338
00339 return;
00340 }
00341
00342
00343 tree_.em_scType = scType;
00344
00345 tree_.em_isInCrack = 0;
00346 double emAbsEta = fabs(em->position().eta());
00347
00348 if ( emAbsEta < 0.018 ||
00349 (emAbsEta > 0.423 && emAbsEta < 0.461) ||
00350 (emAbsEta > 0.770 && emAbsEta < 0.806) ||
00351 (emAbsEta > 1.127 && emAbsEta < 1.163) ||
00352 (emAbsEta > 1.460 && emAbsEta < 1.558) )
00353 tree_.em_isInCrack = 1;
00354
00355 tree_.em_dR = kinem::delta_R(mc->momentum().eta(), mc->momentum().phi(),
00356 em->position().eta(), em->position().phi());
00357 tree_.em_e = em->energy();
00358 tree_.em_et = em->energy() * sin(em->position().theta());
00359 tree_.em_phi = em->position().phi();
00360 tree_.em_eta = em->position().eta();
00361 tree_.em_theta = em->position().theta();
00362 tree_.em_nCell = em->size();
00363 tree_.em_nBC = em->clustersSize();
00364
00365
00366
00367 xClust_zero_ = em->position().x();
00368 yClust_zero_ = em->position().y();
00369 zClust_zero_ = em->position().z();
00370
00371 xClust_vtx_ = xClust_zero_ - xV;
00372 yClust_vtx_ = yClust_zero_ - yV;
00373 zClust_vtx_ = zClust_zero_ - zV;
00374
00375 energyMax_ = em->energy();
00376 thetaMax_ = em->position().theta();
00377 etaMax_ = em->position().eta();
00378 phiMax_ = em->position().phi();
00379 eTMax_ = energyMax_ * sin(thetaMax_);
00380 if ( phiMax_ < 0) phiMax_ += 2*3.14159;
00381
00382 rClust_vtx_ = sqrt (xClust_vtx_*xClust_vtx_ + yClust_vtx_*yClust_vtx_ + zClust_vtx_*zClust_vtx_);
00383 thetaMaxVtx_ = acos(zClust_vtx_/rClust_vtx_);
00384 etaMaxVtx_ = - log(tan(thetaMaxVtx_/2));
00385 eTMaxVtx_ = energyMax_ * sin(thetaMaxVtx_);
00386 phiMaxVtx_ = atan2(yClust_vtx_,xClust_vtx_);
00387 if ( phiMaxVtx_ < 0) phiMaxVtx_ += 2*3.14159;
00388
00389
00390 tree_.em_pet = eTMaxVtx_;
00391 tree_.em_pe = tree_.em_pet/sin(thetaMaxVtx_);
00392 tree_.em_peta = etaMaxVtx_;
00393 tree_.em_ptheta = thetaMaxVtx_;
00394
00395
00396
00397 em = corrSCColl->end();
00398 energyMax = -100.0;
00399 for(reco::SuperClusterCollection::const_iterator aClus = corrSCColl->begin();
00400 aClus != corrSCColl->end(); ++aClus) {
00401
00402 float dR = kinem::delta_R(mc ->momentum().eta(), mc ->momentum().phi(),
00403 aClus->position().eta(), aClus->position().phi());
00404 if (dR < 0.4) {
00405 float energy = aClus->energy();
00406 if ( energy < energyMax ) continue;
00407 energyMax = energy;
00408 em = aClus;
00409 }
00410 }
00411
00412 if (em == corrSCColl->end() ) {
00413
00414
00415 return;
00416 }
00417
00418
00420 tree_.emCorr_e = em->energy();
00421 tree_.emCorr_et = em->energy() * sin(em->position().theta());
00422 tree_.emCorr_phi = em->position().phi();
00423 tree_.emCorr_eta = em->position().eta();
00424 tree_.emCorr_theta = em->position().theta();
00425
00426
00427
00428
00429 tree_.emCorr_peta = tree_.em_peta;
00430 tree_.emCorr_ptheta = tree_.em_ptheta;
00431 tree_.emCorr_pet = tree_.emCorr_e/cosh(tree_.emCorr_peta);
00432
00433 tree_.em_pw = em->phiWidth();
00434 tree_.em_ew = em->etaWidth();
00435 tree_.em_br = tree_.em_pw/tree_.em_ew;
00436
00437 mytree_->Fill();
00438
00439 }
00440
00441
00442 void
00443 EnergyScaleAnalyzer::endJob() {
00444
00445
00446 rootFile_->Write();
00447 }
00448
00449 DEFINE_FWK_MODULE(EnergyScaleAnalyzer);