CMS 3D CMS Logo

VisHORecHit.cc

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

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