Go to the documentation of this file.00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020 #include <iostream>
00021 #include <sstream>
00022 #include <fstream>
00023 #include <functional>
00024
00025
00026 #include "fftjet/ProximityClusteringTree.hh"
00027 #include "fftjet/OpenDXPeakTree.hh"
00028
00029
00030 #include "FWCore/Framework/interface/Frameworkfwd.h"
00031 #include "FWCore/Framework/interface/EDAnalyzer.h"
00032
00033 #include "FWCore/Framework/interface/Event.h"
00034 #include "FWCore/Framework/interface/MakerMacros.h"
00035
00036 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00037
00038
00039 #include "RecoJets/FFTJetProducers/interface/FFTJetParameterParser.h"
00040
00041
00042 #include "RecoJets/FFTJetAlgorithms/interface/clusteringTreeConverters.h"
00043
00044 using namespace fftjetcms;
00045
00046
00047
00048
00049 class FFTJetTreeDump : public edm::EDAnalyzer
00050 {
00051 public:
00052 explicit FFTJetTreeDump(const edm::ParameterSet&);
00053 ~FFTJetTreeDump();
00054
00055 private:
00056
00057 typedef fftjet::ProximityClusteringTree<fftjet::Peak,long> ClusteringTree;
00058 typedef fftjet::SparseClusteringTree<fftjet::Peak,long> SparseTree;
00059 typedef fftjet::OpenDXPeakTree<long,fftjet::AbsClusteringTree> DXFormatter;
00060 typedef fftjet::OpenDXPeakTree<long,fftjet::SparseClusteringTree> SparseFormatter;
00061 typedef fftjet::Functor1<double,fftjet::Peak> PeakProperty;
00062
00063 FFTJetTreeDump();
00064 FFTJetTreeDump(const FFTJetTreeDump&);
00065 FFTJetTreeDump& operator=(const FFTJetTreeDump&);
00066
00067 virtual void beginJob() ;
00068 virtual void analyze(const edm::Event&, const edm::EventSetup&);
00069 virtual void endJob() ;
00070
00071 template<class Real>
00072 void processTreeData(const edm::Event&, std::ofstream&);
00073
00074 template<class Ptr>
00075 void checkConfig(const Ptr& ptr, const char* message)
00076 {
00077 if (ptr.get() == NULL)
00078 throw cms::Exception("FFTJetBadConfig") << message << std::endl;
00079 }
00080
00081
00082
00083 ClusteringTree* clusteringTree;
00084
00085 const edm::InputTag treeLabel;
00086 const std::string outputPrefix;
00087 const double etaMax;
00088 const bool storeInSinglePrecision;
00089 const bool insertCompleteEvent;
00090 const double completeEventScale;
00091
00092
00093 std::auto_ptr<fftjet::AbsDistanceCalculator<fftjet::Peak> > distanceCalc;
00094
00095
00096 std::auto_ptr<std::vector<double> > iniScales;
00097
00098
00099 SparseTree sparseTree;
00100
00101
00102 std::auto_ptr<PeakProperty> glyphSize;
00103 std::auto_ptr<PeakProperty> glyphColor;
00104
00105
00106 std::auto_ptr<DXFormatter> denseFormatter;
00107 std::auto_ptr<SparseFormatter> sparseFormatter;
00108
00109 unsigned counter;
00110 };
00111
00112
00113
00114
00115 FFTJetTreeDump::FFTJetTreeDump(const edm::ParameterSet& ps)
00116 : clusteringTree(0),
00117 treeLabel(ps.getParameter<edm::InputTag>("treeLabel")),
00118 outputPrefix(ps.getParameter<std::string>("outputPrefix")),
00119 etaMax(ps.getParameter<double>("etaMax")),
00120 storeInSinglePrecision(true),
00121 insertCompleteEvent(ps.getParameter<bool>("insertCompleteEvent")),
00122 completeEventScale(ps.getParameter<double>("completeEventScale")),
00123 counter(0)
00124 {
00125 if (etaMax < 0.0)
00126 throw cms::Exception("FFTJetBadConfig")
00127 << "etaMax can not be negative" << std::endl;
00128
00129
00130 const edm::ParameterSet& InitialScales(
00131 ps.getParameter<edm::ParameterSet>("InitialScales"));
00132 iniScales = fftjet_ScaleSet_parser(InitialScales);
00133 checkConfig(iniScales, "invalid set of scales");
00134 std::sort(iniScales->begin(), iniScales->end(), std::greater<double>());
00135
00136
00137 const edm::ParameterSet& TreeDistanceCalculator(
00138 ps.getParameter<edm::ParameterSet>("TreeDistanceCalculator"));
00139 distanceCalc = fftjet_DistanceCalculator_parser(TreeDistanceCalculator);
00140 checkConfig(distanceCalc, "invalid tree distance calculator");
00141
00142
00143 const edm::ParameterSet& GlyphSize(
00144 ps.getParameter<edm::ParameterSet>("GlyphSize"));
00145 glyphSize = fftjet_PeakFunctor_parser(GlyphSize);
00146 checkConfig(glyphSize, "invalid glyph size parameters");
00147
00148 const edm::ParameterSet& GlyphColor(
00149 ps.getParameter<edm::ParameterSet>("GlyphColor"));
00150 glyphColor = fftjet_PeakFunctor_parser(GlyphColor);
00151 checkConfig(glyphColor, "invalid glyph color parameters");
00152
00153
00154 denseFormatter = std::auto_ptr<DXFormatter>(new DXFormatter(
00155 glyphSize.get(), glyphColor.get(), etaMax));
00156 sparseFormatter = std::auto_ptr<SparseFormatter>(new SparseFormatter(
00157 glyphSize.get(), glyphColor.get(), etaMax));
00158
00159
00160 clusteringTree = new ClusteringTree(distanceCalc.get());
00161 }
00162
00163
00164 FFTJetTreeDump::~FFTJetTreeDump()
00165 {
00166 delete clusteringTree;
00167 }
00168
00169
00170
00171
00172
00173 template<class Real>
00174 void FFTJetTreeDump::processTreeData(const edm::Event& iEvent,
00175 std::ofstream& file)
00176 {
00177 typedef reco::PattRecoTree<Real,reco::PattRecoPeak<Real> > StoredTree;
00178
00179
00180 const unsigned long runNum = iEvent.id().run();
00181 const unsigned long evNum = iEvent.id().event();
00182
00183
00184 edm::Handle<StoredTree> input;
00185 iEvent.getByLabel(treeLabel, input);
00186
00187 const double eventScale = insertCompleteEvent ? completeEventScale : 0.0;
00188 if (input->isSparse())
00189 {
00190 sparsePeakTreeFromStorable(*input, iniScales.get(),
00191 eventScale, &sparseTree);
00192 sparseFormatter->setTree(sparseTree, runNum, evNum);
00193 file << *sparseFormatter << std::endl;
00194 }
00195 else
00196 {
00197 densePeakTreeFromStorable(*input, iniScales.get(),
00198 eventScale, clusteringTree);
00199 denseFormatter->setTree(*clusteringTree, runNum, evNum);
00200 file << *denseFormatter << std::endl;
00201 }
00202 }
00203
00204
00205
00206 void FFTJetTreeDump::analyze(const edm::Event& iEvent,
00207 const edm::EventSetup& iSetup)
00208 {
00209
00210 std::ostringstream filename;
00211 filename << outputPrefix << '_' << counter++ << ".dx";
00212
00213
00214 std::ofstream file(filename.str().c_str());
00215 if (!file)
00216 throw cms::Exception("FFTJetBadConfig")
00217 << "Failed to open file \""
00218 << filename.str() << "\"" << std::endl;
00219
00220 if (storeInSinglePrecision)
00221 processTreeData<float>(iEvent, file);
00222 else
00223 processTreeData<double>(iEvent, file);
00224 }
00225
00226
00227
00228 void FFTJetTreeDump::beginJob()
00229 {
00230 }
00231
00232
00233 void FFTJetTreeDump::endJob() {
00234 }
00235
00236
00237 DEFINE_FWK_MODULE(FFTJetTreeDump);