CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/QCDAnalysis/ChargedHadronSpectra/src/PlotEcalRecHits.cc

Go to the documentation of this file.
00001 #include "QCDAnalysis/ChargedHadronSpectra/interface/PlotEcalRecHits.h"
00002 
00003 #include "FWCore/Framework/interface/EventSetup.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 
00007 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00008 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00009 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00010 
00011 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00012 
00013 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00014 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00015 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00016 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00017 #include "DataFormats/EcalDetId/interface/ESDetId.h"
00018 
00019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00020 
00021 #include <vector>
00022 
00023 using namespace std;
00024 
00025 /*****************************************************************************/
00026 PlotEcalRecHits::PlotEcalRecHits
00027   (const edm::EventSetup& es, ofstream& file_) : file(file_)
00028 {
00029   // Get calorimetry
00030   edm::ESHandle<CaloGeometry> calo;
00031   es.get<CaloGeometryRecord>().get(calo);
00032   theCaloGeometry = (const CaloGeometry*)calo.product();
00033 }
00034 
00035 /*****************************************************************************/
00036 PlotEcalRecHits::~PlotEcalRecHits()
00037 {
00038 }
00039 
00040 /*****************************************************************************/
00041 void PlotEcalRecHits::printEcalRecHit
00042   (const CaloCellGeometry* cell, float energy)
00043 { 
00044   float x = energy;
00045   if(x > 1) x = 1.;
00046   float red   = fabs(2*x-0.5);
00047   float green = sin(180*x);
00048   float blue  = cos( 90*x);
00049   
00050   file << ", PointSize[" << energy*0.01 << "]";
00051   file << ", RGBColor[" << red << "," << green << "," << blue << "]";
00052   file << ", Point[{" << cell->getPosition().x() << ","
00053                       << cell->getPosition().y() << ",("
00054                       << cell->getPosition().z() << "-zs)*mz}]" << std::endl;
00055 
00056   const CaloCellGeometry::CornersVec & p(cell->getCorners()) ;
00057 
00058   file << ", If[sd, {RGBColor[0.5,0.5,0.5]";
00059 
00060   file << ", Line[{";
00061   file << "{" << p[0].x() << "," <<p[0].y() << ",(" << p[0].z() << "-zs)*mz}, ";
00062   file << "{" << p[1].x() << "," <<p[1].y() << ",(" << p[1].z() << "-zs)*mz}, ";
00063   file << "{" << p[2].x() << "," <<p[2].y() << ",(" << p[2].z() << "-zs)*mz}, ";
00064   file << "{" << p[3].x() << "," <<p[3].y() << ",(" << p[3].z() << "-zs)*mz}, ";
00065   file << "{" << p[0].x() << "," <<p[0].y() << ",(" << p[0].z() << "-zs)*mz}";
00066   file << "}]" << std::endl;
00067 
00068   file << ", Line[{";
00069   file << "{" << p[4].x() << "," <<p[4].y() << ",(" << p[4].z() << "-zs)*mz}, ";
00070   file << "{" << p[5].x() << "," <<p[5].y() << ",(" << p[5].z() << "-zs)*mz}, ";
00071   file << "{" << p[6].x() << "," <<p[6].y() << ",(" << p[6].z() << "-zs)*mz}, ";
00072   file << "{" << p[7].x() << "," <<p[7].y() << ",(" << p[7].z() << "-zs)*mz}, ";
00073   file << "{" << p[4].x() << "," <<p[4].y() << ",(" << p[4].z() << "-zs)*mz}";
00074   file << "}]" << std::endl;
00075   
00076   file << ", Line[{";
00077   file << "{" << p[0].x() << "," <<p[0].y() << ",(" << p[0].z() << "-zs)*mz}, ";
00078   file << "{" << p[4].x() << "," <<p[4].y() << ",(" << p[4].z() << "-zs)*mz}";
00079   file << "}]" << std::endl;
00080   
00081   file << ", Line[{";
00082   file << "{" << p[1].x() << "," <<p[1].y() << ",(" << p[1].z() << "-zs)*mz}, ";
00083   file << "{" << p[5].x() << "," <<p[5].y() << ",(" << p[5].z() << "-zs)*mz}";
00084   file << "}]" << std::endl;
00085   
00086   file << ", Line[{";
00087   file << "{" << p[2].x() << "," <<p[2].y() << ",(" << p[2].z() << "-zs)*mz}, ";
00088   file << "{" << p[6].x() << "," <<p[6].y() << ",(" << p[6].z() << "-zs)*mz}";
00089   file << "}]" << std::endl;
00090   
00091   file << ", Line[{";
00092   file << "{" << p[3].x() << "," <<p[3].y() << ",(" << p[3].z() << "-zs)*mz}, ";
00093   file << "{" << p[7].x() << "," <<p[7].y() << ",(" << p[7].z() << "-zs)*mz}";
00094   file << "}]" << std::endl;
00095 
00096   file << "}]" << std::endl;
00097 }
00098 
00099 /*****************************************************************************/
00100 void PlotEcalRecHits::printEcalRecHits(const edm::Event& ev)
00101 {
00102 //  const float minEnergy = 0.060;
00103 
00104   edm::Handle<EBRecHitCollection>              recHitsBarrel;
00105   ev.getByLabel("ecalRecHit", "EcalRecHitsEB", recHitsBarrel);
00106   edm::Handle<EERecHitCollection>              recHitsEndcap;
00107   ev.getByLabel("ecalRecHit", "EcalRecHitsEE", recHitsEndcap);
00108 /*
00109   edm::Handle<ESRecHitCollection>              recHitsPreshower;
00110   ev.getByLabel("ecalPreshowerRecHit", "EcalRecHitsES", recHitsPreshower);
00111 */
00112 
00113   LogTrace("MinBiasTracking")
00114        << " [EventPlotter] ecal barrel/endcap :"
00115        << " " << recHitsBarrel->size()
00116        << "/" << recHitsEndcap->size();
00117 //       << "/" << recHitsPreshower->size() << std::endl;
00118 
00119   const CaloSubdetectorGeometry * geom;
00120 
00121   file << ", If[er, {RGBColor[0.0,0.0,0.0]";
00122 
00123   // Barrel
00124   geom = theCaloGeometry->getSubdetectorGeometry(DetId::Ecal,EcalBarrel);
00125   for(EBRecHitCollection::const_iterator recHit = recHitsBarrel->begin();
00126                                          recHit!= recHitsBarrel->end();
00127                                          recHit++)
00128   {
00129     EBDetId detId(recHit->id());
00130     const CaloCellGeometry* cell = geom->getGeometry(detId);
00131     if(cell != 0)
00132       printEcalRecHit(cell, recHit->energy());
00133   }
00134 
00135   // Endcap
00136   geom = theCaloGeometry->getSubdetectorGeometry(DetId::Ecal,EcalEndcap);
00137   for(EERecHitCollection::const_iterator recHit = recHitsEndcap->begin();
00138                                          recHit!= recHitsEndcap->end();
00139                                          recHit++)
00140   {
00141     EEDetId detId(recHit->id());
00142     const CaloCellGeometry* cell = geom->getGeometry(detId);
00143     if(cell != 0)
00144       printEcalRecHit(cell, recHit->energy());
00145   }
00146 
00147   // Preshower
00148 /*
00149   geom = theCaloGeometry->getSubdetectorGeometry(DetId::Ecal,EcalPreshower);
00150   for(ESRecHitCollection::const_iterator recHit = recHitsPreshower->begin();
00151                                          recHit!= recHitsPreshower->end();
00152                                          recHit++)
00153   {
00154     ESDetId detId(recHit->id()); 
00155     const CaloCellGeometry* cell = geom->getGeometry(detId);
00156     printEcalRecHit(cell, recHit->energy() * 1e+3);
00157   }
00158 */
00159   file << "}]";
00160 }
00161