00001
00002
00003 #include "VisReco/Analyzer/interface/VisBasicCluster.h"
00004 #include "VisReco/Analyzer/interface/IguanaService.h"
00005 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00006 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.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 "Iguana/Framework/interface/IgCollection.h"
00015 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00016 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00017 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00018 #include <iostream>
00019 #include <sstream>
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 using namespace edm::service;
00032
00033 VisBasicCluster::VisBasicCluster (const edm::ParameterSet& iConfig)
00034 : inputTag_ (iConfig.getParameter<edm::InputTag>("visBasicClusterTag"))
00035 {}
00036
00037 void
00038 VisBasicCluster::analyze (const edm::Event& event, const edm::EventSetup& eventSetup)
00039 {
00040 edm::Service<IguanaService> config;
00041 if (! config.isAvailable ())
00042 {
00043 throw cms::Exception ("Configuration")
00044 << "VisBasicCluster requires the IguanaService\n"
00045 "which is not present in the configuration file.\n"
00046 "You must add the service in the configuration file\n"
00047 "or remove the module that requires it";
00048 }
00049
00050 edm::Handle<reco::BasicClusterCollection> collection;
00051 event.getByLabel (inputTag_, collection);
00052
00053 edm::ESHandle<CaloGeometry> geom;
00054 eventSetup.get<CaloGeometryRecord> ().get (geom);
00055
00056 if (collection.isValid () && geom.isValid ())
00057 {
00058 IgDataStorage *storage = config->storage ();
00059 IgCollection &icollection = storage->getCollection("BasicClusters_V1");
00060 IgProperty ENERGY = icollection.addProperty("energy", 0.0);
00061 IgProperty POS = icollection.addProperty("pos", IgV3d());
00062 IgProperty ETA = icollection.addProperty("eta", 0.0);
00063 IgProperty PHI = icollection.addProperty("phi", 0.0);
00064 IgProperty ALGO = icollection.addProperty("algo", std::string ());
00065
00066 IgCollection &idetids = storage->getCollection("CaloHits_V1");
00067 IgProperty DETID = idetids.addProperty("detid", int(0));
00068 IgProperty FRACT = idetids.addProperty("fraction", 0.0);
00069 IgProperty FRONT_1 = idetids.addProperty("front_1", IgV3d());
00070 IgProperty FRONT_2 = idetids.addProperty("front_2", IgV3d());
00071 IgProperty FRONT_3 = idetids.addProperty("front_3", IgV3d());
00072 IgProperty FRONT_4 = idetids.addProperty("front_4", IgV3d());
00073 IgProperty BACK_1 = idetids.addProperty("back_1", IgV3d());
00074 IgProperty BACK_2 = idetids.addProperty("back_2", IgV3d());
00075 IgProperty BACK_3 = idetids.addProperty("back_3", IgV3d());
00076 IgProperty BACK_4 = idetids.addProperty("back_4", IgV3d());
00077
00078 IgAssociationSet &basicClustersDetIds = storage->getAssociationSet("BasicClustersCaloHits_V1");
00079
00080 for (reco::BasicClusterCollection::const_iterator it = collection->begin (), end = collection->end (); it != end; ++it)
00081 {
00082 IgCollectionItem icluster = icollection.create();
00083 icluster[ENERGY] = static_cast<double>((*it).energy());
00084 icluster[POS] = IgV3d(static_cast<double>((*it).x()/100.0), static_cast<double>((*it).y()/100.0), static_cast<double>((*it).z()/100.0));
00085 icluster[ETA] = static_cast<double>((*it).eta());
00086 icluster[PHI] = static_cast<double>((*it).phi());
00087 icluster[ALGO] = algoName ((*it).algo());
00088
00089 # ifdef CMSSW_2_2_X
00090
00091 std::vector<DetId> clusterDetIds = (*it).getHitsByDetId ();
00092 for (std::vector<DetId>::const_iterator idIt = clusterDetIds.begin (), idItEnd = clusterDetIds.end (); idIt != idItEnd; ++idIt)
00093 {
00094 IgCollectionItem idetid = idetids.create();
00095 idetid[DETID] = static_cast<int>(*idIt);
00096
00097
00098
00099
00100
00101
00102 idetid[FRACT] = static_cast<double>(0.0);
00103 basicClustersDetIds.associate(icluster,idetid);
00104 }
00105 # else
00106 std::vector<std::pair<DetId, float> > clusterDetIds = (*it).hitsAndFractions ();
00107 for (std::vector<std::pair<DetId, float> >::iterator id = clusterDetIds.begin (), idend = clusterDetIds.end (); id != idend; ++id)
00108 {
00109 IgCollectionItem idetid = idetids.create();
00110 idetid[DETID] = static_cast<int>((*id).first);
00111 idetid[FRACT] = static_cast<double>((*id).second);
00112
00113 const CaloCellGeometry *cell = (*geom).getGeometry ((*id).first);
00114 const CaloCellGeometry::CornersVec& corners = cell->getCorners ();
00115
00116 assert(corners.size() == 8);
00117
00118 idetid[FRONT_1] = IgV3d(static_cast<double>(corners[3].x()/100.0),
00119 static_cast<double>(corners[3].y()/100.0),
00120 static_cast<double>(corners[3].z()/100.0));
00121 idetid[FRONT_2] = IgV3d(static_cast<double>(corners[2].x()/100.0),
00122 static_cast<double>(corners[2].y()/100.0),
00123 static_cast<double>(corners[2].z()/100.0));
00124 idetid[FRONT_3] = IgV3d(static_cast<double>(corners[1].x()/100.0),
00125 static_cast<double>(corners[1].y()/100.0),
00126 static_cast<double>(corners[1].z()/100.0));
00127 idetid[FRONT_4] = IgV3d(static_cast<double>(corners[0].x()/100.0),
00128 static_cast<double>(corners[0].y()/100.0),
00129 static_cast<double>(corners[0].z()/100.0));
00130
00131 idetid[BACK_1] = IgV3d(static_cast<double>(corners[7].x()/100.0),
00132 static_cast<double>(corners[7].y()/100.0),
00133 static_cast<double>(corners[7].z()/100.0));
00134 idetid[BACK_2] = IgV3d(static_cast<double>(corners[6].x()/100.0),
00135 static_cast<double>(corners[6].y()/100.0),
00136 static_cast<double>(corners[6].z()/100.0));
00137 idetid[BACK_3] = IgV3d(static_cast<double>(corners[5].x()/100.0),
00138 static_cast<double>(corners[5].y()/100.0),
00139 static_cast<double>(corners[5].z()/100.0));
00140 idetid[BACK_4] = IgV3d(static_cast<double>(corners[4].x()/100.0),
00141 static_cast<double>(corners[4].y()/100.0),
00142 static_cast<double>(corners[4].z()/100.0));
00143
00144 basicClustersDetIds.associate(icluster,idetid);
00145 }
00146 # endif
00147
00148 }
00149 }
00150 else
00151 {
00152
00153 std::string error = "### Error: BasicClusters "
00154 + edm::TypeID (typeid (reco::BasicClusterCollection)).friendlyClassName () + ":"
00155 + inputTag_.label() + ":"
00156 + inputTag_.instance() + ":"
00157 + inputTag_.process() + " are not found.";
00158
00159 IgDataStorage *storage = config->storage ();
00160 IgCollection &collection = storage->getCollection ("Errors_V1");
00161 IgProperty ERROR_MSG = collection.addProperty ("Error", std::string ());
00162 IgCollectionItem item = collection.create ();
00163 item [ERROR_MSG] = error;
00164 }
00165 }
00166
00167 # ifdef CMSSW_2_2_X
00168
00169 const std::string
00170 VisBasicCluster::algoName (reco::AlgoId key)
00171 {
00172 std::map<reco::AlgoId, std::string> type;
00173
00174 type [reco::island] = "island";
00175 type [reco::hybrid] = "hybrid";
00176 type [reco::fixedMatrix] = "fixedMatrix";
00177 type [reco::dynamicHybrid] = "dynamicHybrid";
00178 type [reco::multi5x5] = "multi5x5";
00179
00180 return type [key];
00181 }
00182
00183 # else
00184
00185 const std::string
00186 VisBasicCluster::algoName (reco::CaloCluster::AlgoId key)
00187 {
00188 std::map<reco::CaloCluster::AlgoId, std::string> type;
00189
00190 type [reco::CaloCluster::island] = "island";
00191 type [reco::CaloCluster::hybrid] = "hybrid";
00192 type [reco::CaloCluster::fixedMatrix] = "fixedMatrix";
00193 type [reco::CaloCluster::dynamicHybrid] = "dynamicHybrid";
00194 type [reco::CaloCluster::multi5x5] = "multi5x5";
00195 type [reco::CaloCluster::particleFlow] = "particleFlow";
00196 type [reco::CaloCluster::undefined] = "undefined";
00197
00198 return type [key];
00199 }
00200
00201 # endif
00202
00203 DEFINE_FWK_MODULE(VisBasicCluster);