CMS 3D CMS Logo

VisSiPixelRecHit.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "VisReco/Analyzer/interface/VisSiPixelRecHit.h"
00004 #include "VisReco/Analyzer/interface/IguanaService.h"
00005 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00006 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
00007 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 #include "FWCore/Framework/interface/EventSetup.h"
00011 #include "FWCore/Framework/interface/MakerMacros.h"
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 #include "FWCore/ServiceRegistry/interface/Service.h"
00014 #include "FWCore/Utilities/interface/Exception.h"
00015 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00016 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00017 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00018 #include "Iguana/Framework/interface/IgCollection.h"
00019 
00020 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00021 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00022 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00023 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00024 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00025 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00026 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00027 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00028 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00029 
00030 using namespace edm::service;
00031 
00032 VisSiPixelRecHit::VisSiPixelRecHit (const edm::ParameterSet& iConfig)
00033     : inputTag_ (iConfig.getParameter<edm::InputTag>("visSiPixelRecHitTag"))
00034 {}
00035 
00036 void 
00037 VisSiPixelRecHit::analyze (const edm::Event& event, const edm::EventSetup& eventSetup)
00038 {
00039     edm::Service<IguanaService> config;
00040     if (! config.isAvailable ()) 
00041     {
00042         throw cms::Exception ("Configuration")
00043             << "VisSiPixelRecHit requires the IguanaService\n"
00044             "which is not present in the configuration file.\n"
00045             "You must add the service in the configuration file\n"
00046             "or remove the module that requires it";
00047     }
00048     
00049     edm::Handle<SiPixelRecHitCollection> collection;
00050     event.getByLabel (inputTag_, collection);
00051 
00052     edm::ESHandle<TrackerGeometry> geom;
00053     eventSetup.get<TrackerDigiGeometryRecord> ().get (geom);
00054 
00055     if (collection.isValid () && geom.isValid ())
00056     {       
00057         IgDataStorage *storage = config->storage ();
00058         IgCollection &rechits = storage->getCollection ("SiPixelRecHits_V1");
00059         IgProperty DET_ID   = rechits.addProperty ("detid", int (0)); 
00060         IgProperty POS      = rechits.addProperty ("pos", IgV3d());
00061 
00062 #ifdef CMSSW_2_2_X
00063 
00064         SiPixelRecHitCollection::id_iterator detUnitIt;
00065         for (detUnitIt = collection->id_begin(); detUnitIt != collection->id_end(); ++detUnitIt)
00066         {
00067             SiPixelRecHitCollection::range range = collection->get((*detUnitIt));
00068             for (SiPixelRecHitCollection::const_iterator ipixel = range.first; ipixel != range.second; ++ipixel)
00069             {
00070                 DetId detectorId = (*ipixel).geographicalId ();
00071                 unsigned int id = detectorId.rawId ();
00072                 
00073                 DetId detid (id);
00074 
00075                 if((*ipixel).hasPositionAndError ())
00076                 {                   
00077                     LocalPoint position = (*ipixel).localPosition ();
00078  
00079                     GlobalPoint pos = geom->idToDet (detid)->surface ().toGlobal (position);
00080  
00081                     IgCollectionItem item = rechits.create ();
00082                     item[DET_ID] = static_cast<int> (id);
00083                     item[POS] = IgV3d(static_cast<double>(pos.x()/100.0), static_cast<double>(pos.y()/100.0), static_cast<double>(pos.z()/100.0));
00084                 }               
00085             }
00086         }
00087         
00088 #else
00089         for (SiPixelRecHitCollection::DataContainer::const_iterator ipixel = collection->data ().begin (), ipixelEnd = collection->data ().end ();
00090              ipixel != ipixelEnd; ++ipixel)
00091         {
00092             DetId detectorId = (*ipixel).geographicalId ();
00093             unsigned int id = detectorId.rawId ();
00094                 
00095             DetId detid (id);
00096  
00097             if((*ipixel).hasPositionAndError ())
00098             {               
00099                 LocalPoint position = (*ipixel).localPosition ();
00100  
00101                 GlobalPoint pos = geom->idToDet (detid)->surface ().toGlobal (position);
00102  
00103                 IgCollectionItem item = rechits.create ();
00104                 item[DET_ID] = static_cast<int> (id);
00105                 item[POS] = IgV3d(static_cast<double>(pos.x()/100.0), static_cast<double>(pos.y()/100.0), static_cast<double>(pos.z()/100.0));
00106             }           
00107         }
00108 #endif
00109 
00110     }
00111     else 
00112     {
00113         // friendlyName:moduleLabel:instanceName:processName
00114         std::string error = "### Error: SiPixel RecHits "
00115                             + edm::TypeID (typeid (SiPixelRecHitCollection)).friendlyClassName () + ":" 
00116                             + inputTag_.label() + ":"
00117                             + inputTag_.instance() + ":" 
00118                             + inputTag_.process() + " are not found.";
00119 
00120         IgDataStorage *storage = config->storage ();
00121         IgCollection &collection = storage->getCollection ("Errors_V1");
00122         IgProperty ERROR_MSG = collection.addProperty ("Error", std::string ());
00123         IgCollectionItem item = collection.create ();
00124         item [ERROR_MSG] = error;
00125     }
00126 }
00127 
00128 DEFINE_FWK_MODULE(VisSiPixelRecHit);

Generated on Tue Jun 9 17:50:09 2009 for CMSSW by  doxygen 1.5.4