CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/QCDAnalysis/ChargedHadronSpectra/src/PlotRecHits.cc

Go to the documentation of this file.
00001 #include "QCDAnalysis/ChargedHadronSpectra/interface/PlotRecHits.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/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00008 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00009 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00010 
00011 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
00012 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2DCollection.h"
00013 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2DCollection.h"
00014 
00015 #include <vector>
00016 
00017 using namespace std;
00018 
00019 /*****************************************************************************/
00020 PlotRecHits::PlotRecHits
00021   (const edm::EventSetup& es, ofstream& file_) : file(file_)
00022 {
00023   // Get tracker geometry
00024   edm::ESHandle<TrackerGeometry> trackerHandle;
00025   es.get<TrackerDigiGeometryRecord>().get(trackerHandle);
00026   theTracker = trackerHandle.product();
00027 }
00028 
00029 /*****************************************************************************/
00030 PlotRecHits::~PlotRecHits()
00031 {
00032 }
00033 
00034 /*****************************************************************************/
00035 void PlotRecHits::printPixelRecHit(const SiPixelRecHit * recHit)
00036 {
00037   DetId id = recHit->geographicalId();
00038 
00039   // DetUnit
00040   double x = theTracker->idToDet(id)->surface().bounds().width() /2;
00041   double y = theTracker->idToDet(id)->surface().bounds().length()/2;
00042   double z = 0.;
00043 
00044   GlobalPoint p00 =  theTracker->idToDet(id)->toGlobal(LocalPoint(-x,-y,z));
00045   GlobalPoint p01 =  theTracker->idToDet(id)->toGlobal(LocalPoint(-x, y,z));
00046   GlobalPoint p10 =  theTracker->idToDet(id)->toGlobal(LocalPoint( x,-y,z));
00047   GlobalPoint p11 =  theTracker->idToDet(id)->toGlobal(LocalPoint( x, y,z));
00048 
00049   file << ", If[sd, {RGBColor[0.4,0.4,0.4], "
00050              <<"Line[{{"<<p00.x()<<","<<p00.y()<<",("<<p00.z()<<"-zs)*mz}, "
00051                    <<"{"<<p01.x()<<","<<p01.y()<<",("<<p01.z()<<"-zs)*mz}, "
00052                    <<"{"<<p11.x()<<","<<p11.y()<<",("<<p11.z()<<"-zs)*mz}, "
00053                    <<"{"<<p10.x()<<","<<p10.y()<<",("<<p10.z()<<"-zs)*mz}, "
00054                    <<"{"<<p00.x()<<","<<p00.y()<<",("<<p00.z()<<"-zs)*mz}}]}]"
00055        << std::endl;
00056   
00057   // RecHit
00058   LocalPoint lpos; GlobalPoint p;
00059   
00060   lpos = LocalPoint(recHit->localPosition().x(),
00061                     recHit->localPosition().y(),
00062                     recHit->localPosition().z());
00063 
00064   p = theTracker->idToDet(id)->toGlobal(lpos);
00065   file << ", Point[{"<<p.x()<<","<<p.y()<<",("<<p.z()<<"-zs)*mz}]" << std::endl;
00066 
00067   // Cluster details
00068   SiPixelRecHit::ClusterRef const& cluster = recHit->cluster();
00069   std::vector<SiPixelCluster::Pixel> pixels = cluster->pixels();
00070 
00071   file << ", Text[StyleForm[\"r\", FontFamily->\"Helvetica\", URL -> \"RecHit |";
00072   for(std::vector<SiPixelCluster::Pixel>::const_iterator
00073     pixel = pixels.begin(); pixel!= pixels.end(); pixel++)
00074   {
00075     file << " [" << int(pixel->x)
00076          << " " << int(pixel->y)
00077          << " " << int(pixel->adc/135) << "]";
00078   }
00079   file << "\"]";
00080 
00081   file << ", {"<< p.x()<<","<<p.y()<<",("<<p.z()<<"-zs)*mz}"
00082        << ", {-1,1}]" << std::endl;
00083 }
00084 
00085 /*****************************************************************************/
00086 void PlotRecHits::printStripRecHit(const SiStripRecHit2D * recHit)
00087 {
00088   DetId id = recHit->geographicalId();
00089 
00090   // DetUnit
00091   double x = theTracker->idToDet(id)->surface().bounds().width() /2;
00092   double y = theTracker->idToDet(id)->surface().bounds().length()/2;
00093   double z = 0.;
00094 
00095   GlobalPoint p00 =  theTracker->idToDet(id)->toGlobal(LocalPoint(-x,-y,z));
00096   GlobalPoint p01 =  theTracker->idToDet(id)->toGlobal(LocalPoint(-x, y,z));
00097   GlobalPoint p10 =  theTracker->idToDet(id)->toGlobal(LocalPoint( x,-y,z));
00098   GlobalPoint p11 =  theTracker->idToDet(id)->toGlobal(LocalPoint( x, y,z));
00099 
00100   file << ", If[sd, {RGBColor[0.6,0.6,0.6], "
00101              <<"Line[{{"<<p00.x()<<","<<p00.y()<<",("<<p00.z()<<"-zs)*mz}, "
00102                    <<"{"<<p01.x()<<","<<p01.y()<<",("<<p01.z()<<"-zs)*mz}, "
00103                    <<"{"<<p11.x()<<","<<p11.y()<<",("<<p11.z()<<"-zs)*mz}, "
00104                    <<"{"<<p10.x()<<","<<p10.y()<<",("<<p10.z()<<"-zs)*mz}, "
00105                    <<"{"<<p00.x()<<","<<p00.y()<<",("<<p00.z()<<"-zs)*mz}}]}]"
00106        << std::endl;
00107 
00108   // RecHit
00109   LocalPoint lpos; GlobalPoint p;
00110 
00111   lpos = LocalPoint(recHit->localPosition().x(),
00112                  y, recHit->localPosition().z());
00113   p = theTracker->idToDet(id)->toGlobal(lpos);
00114   file << ", Line[{{"<<p.x()<<","<<p.y()<<",("<<p.z()<<"-zs)*mz}, {";
00115 
00116   lpos = LocalPoint(recHit->localPosition().x(),
00117                 -y, recHit->localPosition().z());
00118   p = theTracker->idToDet(id)->toGlobal(lpos);
00119   file << ""<<p.x()<<","<<p.y()<<",("<<p.z()<<"-zs)*mz}}]" << std::endl;
00120 }
00121 
00122 /*****************************************************************************/
00123 void PlotRecHits::printPixelRecHits(const edm::Event& ev)
00124 {
00125   // Get pixel hit collections
00126 /*
00127   std::vector<edm::Handle<SiPixelRecHitCollection> > pixelColls;
00128   ev.getManyByType(pixelColls);
00129 
00130   for(std::vector<edm::Handle<SiPixelRecHitCollection> >::const_iterator
00131       pixelColl = pixelColls.begin();
00132       pixelColl!= pixelColls.end(); pixelColl++)
00133   {
00134     const SiPixelRecHitCollection* thePixelHits = (*pixelColl).product();
00135 
00136     for(SiPixelRecHitCollection::DataContainer::const_iterator
00137             recHit = thePixelHits->data().begin();
00138             recHit!= thePixelHits->data().end(); recHit++)
00139     {
00140       if(recHit->isValid())
00141         printPixelRecHit(&(*recHit));
00142     }
00143   }
00144 */
00145 
00146   edm::Handle<SiPixelRecHitCollection> pixelColl;
00147   ev.getByLabel("siPixelRecHits", pixelColl);
00148   const SiPixelRecHitCollection* thePixelHits = pixelColl.product();
00149 
00150   for(SiPixelRecHitCollection::DataContainer::const_iterator
00151           recHit = thePixelHits->data().begin();
00152           recHit!= thePixelHits->data().end(); recHit++)
00153   {
00154     if(recHit->isValid())
00155       printPixelRecHit(&(*recHit));
00156   }
00157 
00158 }
00159 
00160 /*****************************************************************************/
00161 void PlotRecHits::printStripRecHits(const edm::Event& ev)
00162 {
00163   {
00164   // Get strip hit collections
00165   std::vector<edm::Handle<SiStripRecHit2DCollection> > stripColls;
00166   ev.getManyByType(stripColls);
00167   
00168   for(std::vector<edm::Handle<SiStripRecHit2DCollection> >::const_iterator
00169       stripColl = stripColls.begin();
00170       stripColl!= stripColls.end(); stripColl++)
00171   {
00172     const SiStripRecHit2DCollection* theStripHits = (*stripColl).product();
00173     
00174     for(SiStripRecHit2DCollection::DataContainer::const_iterator
00175             recHit = theStripHits->data().begin();
00176             recHit!= theStripHits->data().end(); recHit++)
00177     {
00178       if(recHit->isValid())
00179         printStripRecHit(&(*recHit));
00180     }
00181   } 
00182   }
00183 
00184   // Get matched strip hit collections
00185   {
00186   std::vector<edm::Handle<SiStripMatchedRecHit2DCollection> > stripColls;
00187   ev.getManyByType(stripColls);
00188 
00189   for(std::vector<edm::Handle<SiStripMatchedRecHit2DCollection> >::const_iterator
00190       stripColl = stripColls.begin();
00191       stripColl!= stripColls.end(); stripColl++)
00192   {
00193     const SiStripMatchedRecHit2DCollection* theStripHits = (*stripColl).product();
00194 
00195     for(SiStripMatchedRecHit2DCollection::DataContainer::const_iterator
00196             recHit = theStripHits->data().begin();
00197             recHit!= theStripHits->data().end(); recHit++)
00198       {
00199         if(recHit->monoHit()->isValid())
00200           printStripRecHit((recHit->monoHit()));
00201         if(recHit->stereoHit()->isValid())
00202           printStripRecHit((recHit->stereoHit()));
00203 
00204         DetId id = recHit->geographicalId();
00205         LocalPoint lpos = recHit->localPosition();
00206         GlobalPoint p = theTracker->idToDet(id)->toGlobal(lpos);
00207 
00208         file << ", Point[{"<< p.x()<<","<<p.y()<<",("<<p.z()<<"-zs)*mz}]" << std::endl;
00209       }
00210     }
00211   }
00212 }
00213 
00214 /*****************************************************************************/
00215 void PlotRecHits::printRecHits(const edm::Event& ev)
00216 {
00217   file << "AbsolutePointSize[5]";
00218   file << ", If[pr, {RGBColor[0.4,0.4,1.0]";
00219   printPixelRecHits(ev);
00220   file << "}]";
00221 
00222   file << ", If[sr, {RGBColor[0.6,0.6,1.0]";
00223   printStripRecHits(ev);
00224   file << "}]";
00225 }
00226