CMS 3D CMS Logo

FFTJetTreeDump.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FFTJetTreeDump
4 // Class: FFTJetTreeDump
5 //
13 //
14 // Original Author: Igor Volobouev
15 // Created: Sun Jun 20 14:32:36 CDT 2010
16 //
17 //
18 
19 #include <iostream>
20 #include <memory>
21 
22 #include <fstream>
23 #include <functional>
24 #include <sstream>
25 
26 // FFTJet headers
27 #include "fftjet/ProximityClusteringTree.hh"
28 #include "fftjet/OpenDXPeakTree.hh"
29 
30 // user include files
33 
36 
38 
39 // parameter parser header
41 
42 // functions which manipulate storable trees
44 
46 
47 using namespace fftjetcms;
48 
49 //
50 // class declaration
51 //
53 public:
54  explicit FFTJetTreeDump(const edm::ParameterSet&);
55  FFTJetTreeDump() = delete;
56  FFTJetTreeDump(const FFTJetTreeDump&) = delete;
57  FFTJetTreeDump& operator=(const FFTJetTreeDump&) = delete;
58  ~FFTJetTreeDump() override;
59 
60 private:
61  // Useful local typedefs
62  typedef fftjet::ProximityClusteringTree<fftjet::Peak, long> ClusteringTree;
63  typedef fftjet::SparseClusteringTree<fftjet::Peak, long> SparseTree;
64  typedef fftjet::OpenDXPeakTree<long, fftjet::AbsClusteringTree> DXFormatter;
65  typedef fftjet::OpenDXPeakTree<long, fftjet::SparseClusteringTree> SparseFormatter;
66  typedef fftjet::Functor1<double, fftjet::Peak> PeakProperty;
68 
69  void analyze(const edm::Event&, const edm::EventSetup&) override;
70 
71  void processTreeData(const edm::Event&, std::ofstream&);
72 
73  template <class Ptr>
74  void checkConfig(const Ptr& ptr, const char* message) {
75  if (ptr.get() == nullptr)
76  throw cms::Exception("FFTJetBadConfig") << message << std::endl;
77  }
78 
79  // ----------member data ---------------------------
80  // The complete clustering tree
82 
85 
87  const double etaMax;
88  const bool insertCompleteEvent;
89  const double completeEventScale;
90 
91  // Distance calculator for the clustering tree
92  std::unique_ptr<fftjet::AbsDistanceCalculator<fftjet::Peak> > distanceCalc;
93 
94  // Scales used
95  std::unique_ptr<std::vector<double> > iniScales;
96 
97  // The sparse clustering tree
99 
100  // Functors which define OpenDX glyph size and color
101  std::unique_ptr<PeakProperty> glyphSize;
102  std::unique_ptr<PeakProperty> glyphColor;
103 
104  // OpenDX formatters
105  std::unique_ptr<DXFormatter> denseFormatter;
106  std::unique_ptr<SparseFormatter> sparseFormatter;
107 
108  unsigned counter;
109 };
110 
111 //
112 // constructors and destructor
113 //
115  : clusteringTree(nullptr),
116  treeLabel(ps.getParameter<edm::InputTag>("treeLabel")),
117  outputPrefix(ps.getParameter<std::string>("outputPrefix")),
118  etaMax(ps.getParameter<double>("etaMax")),
119  insertCompleteEvent(ps.getParameter<bool>("insertCompleteEvent")),
120  completeEventScale(ps.getParameter<double>("completeEventScale")),
121  counter(0) {
122  if (etaMax < 0.0)
123  throw cms::Exception("FFTJetBadConfig") << "etaMax can not be negative" << std::endl;
124 
125  // Build the set of pattern recognition scales
126  const edm::ParameterSet& InitialScales(ps.getParameter<edm::ParameterSet>("InitialScales"));
128  checkConfig(iniScales, "invalid set of scales");
129  std::sort(iniScales->begin(), iniScales->end(), std::greater<double>());
130 
131  // Distance calculator for the clustering tree
132  const edm::ParameterSet& TreeDistanceCalculator(ps.getParameter<edm::ParameterSet>("TreeDistanceCalculator"));
134  checkConfig(distanceCalc, "invalid tree distance calculator");
135 
136  // Determine representations for the OpenDX glyph size and color
139  checkConfig(glyphSize, "invalid glyph size parameters");
140 
143  checkConfig(glyphColor, "invalid glyph color parameters");
144 
145  // Build the tree formatters
146  denseFormatter = std::make_unique<DXFormatter>(glyphSize.get(), glyphColor.get(), etaMax);
147  sparseFormatter = std::make_unique<SparseFormatter>(glyphSize.get(), glyphColor.get(), etaMax);
148 
149  // Build the clustering tree
151 
152  treeToken = consumes<StoredTree>(treeLabel);
153 }
154 
156 
157 //
158 // member functions
159 //
161  // Get the event number
162  edm::RunNumber_t const runNum = iEvent.id().run();
163  edm::EventNumber_t const evNum = iEvent.id().event();
164 
165  // Get the input
167  iEvent.getByToken(treeToken, input);
168 
169  const double eventScale = insertCompleteEvent ? completeEventScale : 0.0;
170  if (input->isSparse()) {
171  sparsePeakTreeFromStorable(*input, iniScales.get(), eventScale, &sparseTree);
172  sparseFormatter->setTree(sparseTree, runNum, evNum);
173  file << *sparseFormatter << std::endl;
174  } else {
176  denseFormatter->setTree(*clusteringTree, runNum, evNum);
177  file << *denseFormatter << std::endl;
178  }
179 }
180 
181 // ------------ method called to for each event ------------
183  // Create the file name
184  std::ostringstream filename;
185  filename << outputPrefix << '_' << counter++ << ".dx";
186 
187  // Open the file
188  std::ofstream file(filename.str().c_str());
189  if (!file)
190  throw cms::Exception("FFTJetBadConfig") << "Failed to open file \"" << filename.str() << "\"" << std::endl;
191 
193 }
194 
195 //define this as a plug-in
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
Class for storing FFTJet sparse clustering trees.
Definition: PattRecoTree.h:20
fftjet::OpenDXPeakTree< long, fftjet::SparseClusteringTree > SparseFormatter
const edm::InputTag treeLabel
SparseTree sparseTree
std::unique_ptr< fftjet::Functor1< double, fftjet::Peak > > fftjet_PeakFunctor_parser(const edm::ParameterSet &ps)
fftjet::Functor1< double, fftjet::Peak > PeakProperty
unsigned long long EventNumber_t
void checkConfig(const Ptr &ptr, const char *message)
const double etaMax
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
reco::PattRecoTree< float, reco::PattRecoPeak< float > > StoredTree
edm::EDGetTokenT< StoredTree > treeToken
static std::string const input
Definition: EdmProvDump.cc:50
void processTreeData(const edm::Event &, std::ofstream &)
fftjet::OpenDXPeakTree< long, fftjet::AbsClusteringTree > DXFormatter
int iEvent
Definition: GenABIO.cc:224
ClusteringTree * clusteringTree
~FFTJetTreeDump() override
fftjet::ProximityClusteringTree< fftjet::Peak, long > ClusteringTree
std::unique_ptr< fftjet::AbsDistanceCalculator< fftjet::Peak > > distanceCalc
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
fftjet::SparseClusteringTree< fftjet::Peak, long > SparseTree
const std::string outputPrefix
std::unique_ptr< DXFormatter > denseFormatter
std::unique_ptr< fftjet::AbsDistanceCalculator< fftjet::Peak > > fftjet_DistanceCalculator_parser(const edm::ParameterSet &ps)
std::unique_ptr< PeakProperty > glyphSize
void sparsePeakTreeFromStorable(const reco::PattRecoTree< Real, reco::PattRecoPeak< Real > > &in, const std::vector< double > *scaleSetIfNotAdaptive, double completeEventScale, fftjet::SparseClusteringTree< fftjet::Peak, long > *out)
void densePeakTreeFromStorable(const reco::PattRecoTree< Real, reco::PattRecoPeak< Real > > &in, const std::vector< double > *scaleSetIfNotAdaptive, double completeEventScale, fftjet::AbsClusteringTree< fftjet::Peak, long > *out)
std::unique_ptr< SparseFormatter > sparseFormatter
const double completeEventScale
HLT enums.
const bool insertCompleteEvent
FFTJetTreeDump()=delete
unsigned int RunNumber_t
std::unique_ptr< std::vector< double > > iniScales
void analyze(const edm::Event &, const edm::EventSetup &) override
std::unique_ptr< std::vector< double > > fftjet_ScaleSet_parser(const edm::ParameterSet &ps)
std::unique_ptr< PeakProperty > glyphColor