00001 #include "VisReco/Analyzer/interface/VisPFCluster.h"
00002 #include "VisReco/Analyzer/interface/IguanaService.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/EventSetup.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 #include "FWCore/Framework/interface/MakerMacros.h"
00007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00008 #include "FWCore/ServiceRegistry/interface/Service.h"
00009 #include "FWCore/Utilities/interface/Exception.h"
00010 #include "DataFormats/ParticleFlowReco/interface/PFCluster.h"
00011 #include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h"
00012 #include "DataFormats/ParticleFlowReco/interface/PFLayer.h"
00013 #include "DataFormats/ParticleFlowReco/interface/PFRecHitFraction.h"
00014 #include "DataFormats/ParticleFlowReco/interface/PFRecHit.h"
00015 #include "DataFormats/ParticleFlowReco/interface/PFRecHitFwd.h"
00016 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00017 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00018 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00019 #include "Iguana/Framework/interface/IgCollection.h"
00020 #include <iostream>
00021 #include <sstream>
00022
00023 using namespace edm::service;
00024
00025 VisPFCluster::VisPFCluster(const edm::ParameterSet& iConfig)
00026 : inputTag_ (iConfig.getParameter<edm::InputTag>("visPFClusterTag"))
00027
00028
00029
00030
00031
00032 {}
00033
00034 void
00035 VisPFCluster::analyze(const edm::Event& event, const edm::EventSetup& eventSetup)
00036 {
00037 edm::Service<IguanaService> config;
00038
00039 if ( ! config.isAvailable() )
00040 {
00041 throw cms::Exception("Configuration")
00042 << "VisPFCluster requires the IguanaService\n"
00043 "which is not present in the configuration file.\n"
00044 "You must add the service in the configuration file\n"
00045 "or remove the module that requires it";
00046 }
00047
00048 edm::Handle<reco::PFClusterCollection> collection;
00049 event.getByLabel (inputTag_, collection);
00050
00051 edm::ESHandle<CaloGeometry> caloGeometry;
00052 eventSetup.get<CaloGeometryRecord>().get(caloGeometry);
00053
00054 if ( collection.isValid() && caloGeometry.isValid() )
00055 {
00056 IgDataStorage *storage = config->storage();
00057
00058 IgCollection& pfclusters = storage->getCollection("PFClusters_V1");
00059
00060 IgProperty ID = pfclusters.addProperty("id", 0);
00061 IgProperty NAME = pfclusters.addProperty("name", std::string());
00062
00063 IgCollection& rechits = storage->getCollection("PFRecHitFractions_V1");
00064
00065 IgProperty E = rechits.addProperty("energy", 0.0);
00066 IgProperty FRAC = rechits.addProperty("fraction", 0.0);
00067 IgProperty LAYER = rechits.addProperty("layer", std::string());
00068
00069
00070 IgCollection& corners = storage->getCollection("Corners_V1");
00071
00072 IgProperty F1 = corners.addProperty("front1", IgV3d());
00073 IgProperty F2 = corners.addProperty("front2", IgV3d());
00074 IgProperty F3 = corners.addProperty("front3", IgV3d());
00075 IgProperty F4 = corners.addProperty("front4", IgV3d());
00076
00077 IgProperty B1 = corners.addProperty("back1", IgV3d());
00078 IgProperty B2 = corners.addProperty("back2", IgV3d());
00079 IgProperty B3 = corners.addProperty("back3", IgV3d());
00080 IgProperty B4 = corners.addProperty("back4", IgV3d());
00081
00082 IgAssociationSet& clusterRecHits = storage->getAssociationSet("PFClusterPFRecHitFractions_V1");
00083 IgAssociationSet& recHitCorners = storage->getAssociationSet("PFRecHitFractionCorners_V1");
00084
00085 unsigned int i = 0;
00086
00087
00088
00089 for ( std::vector<reco::PFCluster>::const_iterator cluster = collection->begin(), clusterEnd = collection->end();
00090 cluster != clusterEnd; ++cluster, ++i )
00091 {
00092
00093
00094 IgCollectionItem cl = pfclusters.create();
00095 cl[ID] = i;
00096 cl["name"] = std::string("PFCluster");
00097
00098 std::vector<reco::PFRecHitFraction>::const_iterator iR;
00099
00100
00101
00102 for ( iR = (*cluster).recHitFractions().begin();
00103 iR != (*cluster).recHitFractions().end(); ++iR )
00104 {
00105
00106 IgCollectionItem rh = rechits.create();
00107
00108 double energy = (*iR).recHitRef()->energy();
00109
00110 rh["energy"] = energy;
00111 rh["fraction"] = (*iR).fraction();
00112
00113 if ( (*cluster).layer() == PFLayer::ECAL_BARREL )
00114 rh[LAYER] = std::string("EB");
00115
00116 else if ( (*cluster).layer() == PFLayer::ECAL_ENDCAP )
00117 rh[LAYER] = std::string("EE");
00118
00119 else
00120 rh[LAYER] = std::string("UNDEFINED");
00121
00122 clusterRecHits.associate(cl,rh);
00123
00124
00125
00126
00127 double f1x, f1y, f1z;
00128 double f2x, f2y, f2z;
00129 double f3x, f3y, f3z;
00130 double f4x, f4y, f4z;
00131
00132 double b1x, b1y, b1z;
00133 double b2x, b2y, b2z;
00134 double b3x, b3y, b3z;
00135 double b4x, b4y, b4z;
00136
00137 const CaloCellGeometry::CornersVec& cornerPoints
00138 = (*caloGeometry).getGeometry((*iR).recHitRef()->detId())->getCorners();
00139
00140 assert(cornerPoints.size() == 8);
00141
00142 IgCollectionItem cr = corners.create();
00143
00144 f1x = cornerPoints[3].x()/100.0;
00145 f1y = cornerPoints[3].y()/100.0;
00146 f1z = cornerPoints[3].z()/100.0;
00147
00148 cr[F1] = IgV3d(f1x, f1y, f1z);
00149
00150 f2x = cornerPoints[2].x()/100.0;
00151 f2y = cornerPoints[2].y()/100.0;
00152 f2z = cornerPoints[2].z()/100.0;
00153
00154 cr[F2] = IgV3d(f2x, f2y, f2z);
00155
00156 f3x = cornerPoints[1].x()/100.0;
00157 f3y = cornerPoints[1].y()/100.0;
00158 f3z = cornerPoints[1].z()/100.0;
00159
00160 cr[F3] = IgV3d(f3x, f3y, f3z);
00161
00162 f4x = cornerPoints[0].x()/100.0;
00163 f4y = cornerPoints[0].y()/100.0;
00164 f4z = cornerPoints[0].z()/100.0;
00165
00166 cr[F4] = IgV3d(f4x, f4y, f4z);
00167
00168 b1x = cornerPoints[7].x()/100.0;
00169 b1y = cornerPoints[7].y()/100.0;
00170 b1z = cornerPoints[7].z()/100.0;
00171
00172 cr["back1"] = IgV3d(b1x, b1y, b1z);
00173
00174 b2x = cornerPoints[6].x()/100.0;
00175 b2y = cornerPoints[6].y()/100.0;
00176 b2z = cornerPoints[6].z()/100.0;
00177
00178 cr["back2"] = IgV3d(b2x, b2y, b2z);
00179
00180 b3x = cornerPoints[5].x()/100.0;
00181 b3y = cornerPoints[5].y()/100.0;
00182 b3z = cornerPoints[5].z()/100.0;
00183
00184 cr["back3"] = IgV3d(b3x, b3y, b3z);
00185
00186 b4x = cornerPoints[4].x()/100.0;
00187 b4y = cornerPoints[4].y()/100.0;
00188 b4z = cornerPoints[4].z()/100.0;
00189
00190 cr["back4"] = IgV3d(b4x, b4y, b4z);
00191
00192 recHitCorners.associate(rh, cr);
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 }
00207
00208
00209
00210 }
00211 }
00212 else
00213 {
00214
00215
00216
00217 std::string error = "### Error: PFClusters "
00218 + edm::TypeID (typeid (reco::PFClusterCollection)).friendlyClassName () + ":"
00219 + inputTag_.label() + ":"
00220 + inputTag_.instance() + ":"
00221 + inputTag_.process() + " are not found.";
00222
00223 IgDataStorage *storage = config->storage ();
00224 IgCollection &collection = storage->getCollection ("Errors_V1");
00225 IgProperty errorMsg = collection.addProperty ("Error", std::string ());
00226 IgCollectionItem item = collection.create ();
00227 item ["Error"] = error;
00228 }
00229 }
00230
00231 DEFINE_FWK_MODULE(VisPFCluster);