00001
00002
00003 #include "VisReco/Analyzer/interface/VisCSCSegment.h"
00004 #include "VisReco/Analyzer/interface/IguanaService.h"
00005 #include "DataFormats/CSCRecHit/interface/CSCSegment.h"
00006 #include "DataFormats/CSCRecHit/interface/CSCSegmentCollection.h"
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/Framework/interface/ESHandle.h"
00009 #include "FWCore/Framework/interface/EventSetup.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/CSCGeometry/interface/CSCGeometry.h"
00015 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00016 #include "Iguana/Framework/interface/IgCollection.h"
00017 #include <iostream>
00018 #include <sstream>
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 using namespace edm::service;
00031
00032 VisCSCSegment::VisCSCSegment (const edm::ParameterSet& iConfig)
00033 : inputTag_ (iConfig.getParameter<edm::InputTag>("visCSCSegmentTag"))
00034 {}
00035
00036 void
00037 VisCSCSegment::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 << "VisCSCSegment 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<CSCSegmentCollection> collection;
00050 event.getByLabel (inputTag_, collection);
00051
00052 edm::ESHandle<CSCGeometry> geom;
00053 eventSetup.get<MuonGeometryRecord> ().get (geom);
00054
00055 if (collection.isValid () && geom.isValid ())
00056 {
00057 IgDataStorage *storage = config->storage ();
00058 IgCollection &segments = storage->getCollection ("CSCSegments_V1");
00059 IgProperty DET_ID = segments.addProperty ("detid", int (0));
00060 IgProperty POS_1 = segments.addProperty ("pos_1", IgV3d());
00061 IgProperty POS_2 = segments.addProperty ("pos_2", IgV3d());
00062
00063 CSCSegmentCollection::const_iterator it = collection->begin ();
00064 CSCSegmentCollection::const_iterator end = collection->end ();
00065 for (; it != end; ++it)
00066 {
00067 IgCollectionItem isegment = segments.create ();
00068 isegment[DET_ID] = static_cast<int> ((*it).geographicalId ().rawId ());
00069
00070
00071 LocalPoint pos = (*it).localPosition();
00072 LocalVector dir = (*it).localDirection();
00073
00074 const GeomDet *det = geom->idToDet((*it).cscDetId());
00075
00076
00077 float halfThickness = det->surface ().bounds ().thickness () / 2.;
00078
00079 float z1 = halfThickness;
00080 float x1 = pos.x() + dir.x()*z1/dir.z();
00081 float y1 = pos.y() + dir.y()*z1/dir.z();
00082 GlobalPoint g1 = det->surface().toGlobal( LocalPoint(x1,y1,z1) );
00083
00084 float z2 = -halfThickness;
00085 float x2 = pos.x() + dir.x()*z2/dir.z();
00086 float y2 = pos.y() + dir.y()*z2/dir.z();
00087 GlobalPoint g2 = det->surface().toGlobal( LocalPoint(x2,y2,z2) );
00088
00089 float x = g1.x () / 100.0;
00090 float y = g1.y () / 100.0;
00091 float z = g1.z () / 100.0;
00092 isegment[POS_1] = IgV3d(static_cast<double>(x), static_cast<double>(y), static_cast<double>(z));
00093
00094 x = g2.x () / 100.0;
00095 y = g2.y () / 100.0;
00096 z = g2.z () / 100.0;
00097 isegment[POS_2] = IgV3d(static_cast<double>(x), static_cast<double>(y), static_cast<double>(z));
00098 }
00099 }
00100 else
00101 {
00102
00103 std::string error = "### Error: CSC Segments "
00104 + edm::TypeID (typeid (CSCSegmentCollection)).friendlyClassName () + ":"
00105 + inputTag_.label() + ":"
00106 + inputTag_.instance() + ":"
00107 + inputTag_.process() + " are not found.";
00108
00109 IgDataStorage *storage = config->storage ();
00110 IgCollection &collection = storage->getCollection ("Errors_V1");
00111 IgProperty ERROR_MSG = collection.addProperty ("Error", std::string ());
00112 IgCollectionItem item = collection.create ();
00113 item [ERROR_MSG] = error;
00114 }
00115 }
00116
00117 DEFINE_FWK_MODULE(VisCSCSegment);