CMS 3D CMS Logo

VisEERecHit.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "VisReco/Analyzer/interface/VisEERecHit.h"
00004 #include "VisReco/Analyzer/interface/IguanaService.h"
00005 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00006 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00007 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "FWCore/Framework/interface/EventSetup.h"
00010 #include "FWCore/Framework/interface/ESHandle.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/CaloGeometry/interface/CaloCellGeometry.h"
00016 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00017 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00018 #include "Iguana/Framework/interface/IgCollection.h"
00019 #include "Iguana/Utilities/classlib/utils/DebugAids.h"
00020 #include <classlib/utils/DebugAids.h>
00021 #include <iostream>
00022 #include <sstream>
00023 
00024 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00025 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00026 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00027 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00028 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00029 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00030 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00031 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00032 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00033 
00034 using namespace edm::service;
00035 
00036 VisEERecHit::VisEERecHit (const edm::ParameterSet& iConfig)
00037     : inputTag_ (iConfig.getParameter<edm::InputTag>("visEERecHitTag"))
00038 {}
00039 
00040 void
00041 VisEERecHit::analyze( const edm::Event& event, const edm::EventSetup& eventSetup)
00042 {
00043     edm::Service<IguanaService> config;
00044     if (! config.isAvailable ()) 
00045     {
00046         throw cms::Exception ("Configuration")
00047             << "VisEERecHit requires the IguanaService\n"
00048             "which is not present in the configuration file.\n"
00049             "You must add the service in the configuration file\n"
00050             "or remove the module that requires it";
00051     }
00052     
00053     edm::ESHandle<CaloGeometry> geom;
00054     eventSetup.get<CaloGeometryRecord> ().get (geom);
00055 
00056     edm::Handle<EcalRecHitCollection> collection;
00057     event.getByLabel (inputTag_, collection);
00058 
00059     if (collection.isValid () && geom.isValid ())
00060     {       
00061         IgDataStorage *storage = config->storage ();
00062         IgCollection &recHits = storage->getCollection("EERecHits_V1");
00063         IgProperty E = recHits.addProperty("energy", 0.0);
00064         IgProperty ETA = recHits.addProperty("eta", 0.0);
00065         IgProperty PHI = recHits.addProperty("phi", 0.0);
00066         IgProperty DETID = recHits.addProperty("detid", int (0));                       
00067         IgProperty FRONT_1 = recHits.addProperty("front_1", IgV3d());
00068         IgProperty FRONT_2 = recHits.addProperty("front_2", IgV3d());   
00069         IgProperty FRONT_3 = recHits.addProperty("front_3", IgV3d());   
00070         IgProperty FRONT_4 = recHits.addProperty("front_4", IgV3d());
00071         IgProperty BACK_1  = recHits.addProperty("back_1",  IgV3d());
00072         IgProperty BACK_2  = recHits.addProperty("back_2",  IgV3d());
00073         IgProperty BACK_3  = recHits.addProperty("back_3",  IgV3d());
00074         IgProperty BACK_4  = recHits.addProperty("back_4",  IgV3d());
00075 
00076         for (std::vector<EcalRecHit>::const_iterator it=collection->begin(), itEnd=collection->end(); it!=itEnd; ++it)
00077         {
00078             const CaloCellGeometry *cell = (*geom).getGeometry ((*it).detid ());
00079             const CaloCellGeometry::CornersVec& corners = cell->getCorners ();
00080             const GlobalPoint& pos = cell->getPosition ();
00081             float energy = (*it).energy ();
00082             float eta = pos.eta ();
00083             float phi = pos.phi ();
00084 
00085             IgCollectionItem irechit = recHits.create();
00086             irechit[E] = static_cast<double>(energy);
00087             irechit[ETA] = static_cast<double>(eta);
00088             irechit[PHI] = static_cast<double>(phi);
00089             irechit[DETID] = static_cast<int>((*it).detid ());
00090             irechit[FRONT_1] = IgV3d(static_cast<double>(corners[3].x()/100.0), 
00091                                      static_cast<double>(corners[3].y()/100.0), 
00092                                      static_cast<double>(corners[3].z()/100.0));
00093             irechit[FRONT_2] = IgV3d(static_cast<double>(corners[2].x()/100.0), 
00094                                      static_cast<double>(corners[2].y()/100.0), 
00095                                      static_cast<double>(corners[2].z()/100.0));
00096             irechit[FRONT_3] = IgV3d(static_cast<double>(corners[1].x()/100.0), 
00097                                      static_cast<double>(corners[1].y()/100.0), 
00098                                      static_cast<double>(corners[1].z()/100.0));
00099             irechit[FRONT_4] = IgV3d(static_cast<double>(corners[0].x()/100.0), 
00100                                      static_cast<double>(corners[0].y()/100.0), 
00101                                      static_cast<double>(corners[0].z()/100.0));
00102             
00103             irechit[BACK_1] = IgV3d(static_cast<double>(corners[7].x()/100.0), 
00104                                     static_cast<double>(corners[7].y()/100.0), 
00105                                     static_cast<double>(corners[7].z()/100.0));
00106             irechit[BACK_2] = IgV3d(static_cast<double>(corners[6].x()/100.0), 
00107                                     static_cast<double>(corners[6].y()/100.0), 
00108                                     static_cast<double>(corners[6].z()/100.0));
00109             irechit[BACK_3] = IgV3d(static_cast<double>(corners[5].x()/100.0), 
00110                                     static_cast<double>(corners[5].y()/100.0), 
00111                                     static_cast<double>(corners[5].z()/100.0));
00112             irechit[BACK_4] = IgV3d(static_cast<double>(corners[4].x()/100.0), 
00113                                     static_cast<double>(corners[4].y()/100.0), 
00114                                     static_cast<double>(corners[4].z()/100.0)); 
00115         }
00116     }
00117     
00118     else 
00119     {
00120         // friendlyName:moduleLabel:instanceName:processName
00121         std::string error = "### Error: EERecHits "
00122                             + edm::TypeID (typeid (EcalRecHitCollection)).friendlyClassName () + ":" 
00123                             + inputTag_.label() + ":"
00124                             + inputTag_.instance() + ":" 
00125                             + inputTag_.process() + " are not found.";
00126 
00127         IgDataStorage *storage = config->storage ();
00128         IgCollection &collection = storage->getCollection ("Errors_V1");
00129         IgProperty ERROR_MSG = collection.addProperty ("Error", std::string ());
00130         IgCollectionItem item = collection.create ();
00131         item [ERROR_MSG] = error;
00132     }
00133 }
00134 
00135 DEFINE_FWK_MODULE(VisEERecHit);

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