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 beginJob() override;
70  void analyze(const edm::Event&, const edm::EventSetup&) override;
71  void endJob() override;
72 
73  template <class Real>
74  void processTreeData(const edm::Event&, std::ofstream&);
75 
76  template <class Ptr>
77  void checkConfig(const Ptr& ptr, const char* message) {
78  if (ptr.get() == nullptr)
79  throw cms::Exception("FFTJetBadConfig") << message << std::endl;
80  }
81 
82  // ----------member data ---------------------------
83  // The complete clustering tree
85 
88 
90  const double etaMax;
92  const bool insertCompleteEvent;
93  const double completeEventScale;
94 
95  // Distance calculator for the clustering tree
96  std::unique_ptr<fftjet::AbsDistanceCalculator<fftjet::Peak> > distanceCalc;
97 
98  // Scales used
99  std::unique_ptr<std::vector<double> > iniScales;
100 
101  // The sparse clustering tree
103 
104  // Functors which define OpenDX glyph size and color
105  std::unique_ptr<PeakProperty> glyphSize;
106  std::unique_ptr<PeakProperty> glyphColor;
107 
108  // OpenDX formatters
109  std::unique_ptr<DXFormatter> denseFormatter;
110  std::unique_ptr<SparseFormatter> sparseFormatter;
111 
112  unsigned counter;
113 };
114 
115 //
116 // constructors and destructor
117 //
119  : clusteringTree(nullptr),
120  treeLabel(ps.getParameter<edm::InputTag>("treeLabel")),
121  outputPrefix(ps.getParameter<std::string>("outputPrefix")),
122  etaMax(ps.getParameter<double>("etaMax")),
123  storeInSinglePrecision(true),
124  insertCompleteEvent(ps.getParameter<bool>("insertCompleteEvent")),
125  completeEventScale(ps.getParameter<double>("completeEventScale")),
126  counter(0) {
127  if (etaMax < 0.0)
128  throw cms::Exception("FFTJetBadConfig") << "etaMax can not be negative" << std::endl;
129 
130  // Build the set of pattern recognition scales
131  const edm::ParameterSet& InitialScales(ps.getParameter<edm::ParameterSet>("InitialScales"));
133  checkConfig(iniScales, "invalid set of scales");
134  std::sort(iniScales->begin(), iniScales->end(), std::greater<double>());
135 
136  // Distance calculator for the clustering tree
137  const edm::ParameterSet& TreeDistanceCalculator(ps.getParameter<edm::ParameterSet>("TreeDistanceCalculator"));
139  checkConfig(distanceCalc, "invalid tree distance calculator");
140 
141  // Determine representations for the OpenDX glyph size and color
144  checkConfig(glyphSize, "invalid glyph size parameters");
145 
148  checkConfig(glyphColor, "invalid glyph color parameters");
149 
150  // Build the tree formatters
151  denseFormatter = std::make_unique<DXFormatter>(glyphSize.get(), glyphColor.get(), etaMax);
152  sparseFormatter = std::make_unique<SparseFormatter>(glyphSize.get(), glyphColor.get(), etaMax);
153 
154  // Build the clustering tree
156 
157  treeToken = consumes<StoredTree>(treeLabel);
158 }
159 
161 
162 //
163 // member functions
164 //
165 template <class Real>
167  // Get the event number
168  edm::RunNumber_t const runNum = iEvent.id().run();
169  edm::EventNumber_t const evNum = iEvent.id().event();
170 
171  // Get the input
173  iEvent.getByToken(treeToken, input);
174 
175  const double eventScale = insertCompleteEvent ? completeEventScale : 0.0;
176  if (input->isSparse()) {
177  sparsePeakTreeFromStorable(*input, iniScales.get(), eventScale, &sparseTree);
178  sparseFormatter->setTree(sparseTree, runNum, evNum);
179  file << *sparseFormatter << std::endl;
180  } else {
182  denseFormatter->setTree(*clusteringTree, runNum, evNum);
183  file << *denseFormatter << std::endl;
184  }
185 }
186 
187 // ------------ method called to for each event ------------
189  // Create the file name
190  std::ostringstream filename;
191  filename << outputPrefix << '_' << counter++ << ".dx";
192 
193  // Open the file
194  std::ofstream file(filename.str().c_str());
195  if (!file)
196  throw cms::Exception("FFTJetBadConfig") << "Failed to open file \"" << filename.str() << "\"" << std::endl;
197 
199  processTreeData<float>(iEvent, file);
200  else
201  processTreeData<double>(iEvent, file);
202 }
203 
204 // ------------ method called once each job just before starting event loop
206 
207 // ------------ method called once each job just after ending the event loop
209 
210 //define this as a plug-in
DeadROC_duringRun.runNum
runNum
Definition: DeadROC_duringRun.py:21
fftjetcms::fftjet_PeakFunctor_parser
std::unique_ptr< fftjet::Functor1< double, fftjet::Peak > > fftjet_PeakFunctor_parser(const edm::ParameterSet &ps)
Definition: FFTJetParameterParser.cc:473
edm::RunNumber_t
unsigned int RunNumber_t
Definition: RunLumiEventNumber.h:14
counter
Definition: counter.py:1
bk::beginJob
void beginJob()
Definition: Breakpoints.cc:14
electrons_cff.bool
bool
Definition: electrons_cff.py:366
input
static const std::string input
Definition: EdmProvDump.cc:48
fftjetcms
Definition: AbsPileupCalculator.h:15
FFTJetTreeDump::PeakProperty
fftjet::Functor1< double, fftjet::Peak > PeakProperty
Definition: FFTJetTreeDump.cc:66
FFTJetTreeDump::sparseFormatter
std::unique_ptr< SparseFormatter > sparseFormatter
Definition: FFTJetTreeDump.cc:110
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
fftjetcms::fftjet_ScaleSet_parser
std::unique_ptr< std::vector< double > > fftjet_ScaleSet_parser(const edm::ParameterSet &ps)
Definition: FFTJetParameterParser.cc:350
FFTJetTreeDump::endJob
void endJob() override
Definition: FFTJetTreeDump.cc:208
RunLumiEventNumber.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
FFTJetTreeDump::~FFTJetTreeDump
~FFTJetTreeDump() override
Definition: FFTJetTreeDump.cc:160
FFTJetTreeDump::processTreeData
void processTreeData(const edm::Event &, std::ofstream &)
Definition: FFTJetTreeDump.cc:166
fftjetdijetfilter_cfi.completeEventScale
completeEventScale
Definition: fftjetdijetfilter_cfi.py:17
clusteringTreeConverters.h
FFTJetTreeDump::glyphSize
std::unique_ptr< PeakProperty > glyphSize
Definition: FFTJetTreeDump.cc:105
EDAnalyzer.h
fftjetdijetfilter_cfi.insertCompleteEvent
insertCompleteEvent
Definition: fftjetdijetfilter_cfi.py:16
FFTJetTreeDump::DXFormatter
fftjet::OpenDXPeakTree< long, fftjet::AbsClusteringTree > DXFormatter
Definition: FFTJetTreeDump.cc:64
edm::Handle
Definition: AssociativeIterator.h:50
FFTJetTreeDump::insertCompleteEvent
const bool insertCompleteEvent
Definition: FFTJetTreeDump.cc:92
FFTJetTreeDump::SparseFormatter
fftjet::OpenDXPeakTree< long, fftjet::SparseClusteringTree > SparseFormatter
Definition: FFTJetTreeDump.cc:65
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
fftjetcms::densePeakTreeFromStorable
void densePeakTreeFromStorable(const reco::PattRecoTree< Real, reco::PattRecoPeak< Real > > &in, const std::vector< double > *scaleSetIfNotAdaptive, double completeEventScale, fftjet::AbsClusteringTree< fftjet::Peak, long > *out)
Definition: clusteringTreeConverters.h:271
FFTJetTreeDump::outputPrefix
const std::string outputPrefix
Definition: FFTJetTreeDump.cc:89
FFTJetTreeDump::beginJob
void beginJob() override
Definition: FFTJetTreeDump.cc:205
MakerMacros.h
FFTJetTreeDump::treeToken
edm::EDGetTokenT< StoredTree > treeToken
Definition: FFTJetTreeDump.cc:87
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
FFTJetTreeDump::storeInSinglePrecision
const bool storeInSinglePrecision
Definition: FFTJetTreeDump.cc:91
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
FFTJetTreeDump::etaMax
const double etaMax
Definition: FFTJetTreeDump.cc:90
FFTJetTreeDump::SparseTree
fftjet::SparseClusteringTree< fftjet::Peak, long > SparseTree
Definition: FFTJetTreeDump.cc:63
edm::EventNumber_t
unsigned long long EventNumber_t
Definition: RunLumiEventNumber.h:12
fftjetcms::sparsePeakTreeFromStorable
void sparsePeakTreeFromStorable(const reco::PattRecoTree< Real, reco::PattRecoPeak< Real > > &in, const std::vector< double > *scaleSetIfNotAdaptive, double completeEventScale, fftjet::SparseClusteringTree< fftjet::Peak, long > *out)
Definition: clusteringTreeConverters.h:133
fftjettreedump_cfi.GlyphColor
GlyphColor
Definition: fftjettreedump_cfi.py:55
FFTJetTreeDump::treeLabel
const edm::InputTag treeLabel
Definition: FFTJetTreeDump.cc:86
geometryDiff.file
file
Definition: geometryDiff.py:13
fftjettreedump_cfi.GlyphSize
GlyphSize
Definition: fftjettreedump_cfi.py:50
funct::true
true
Definition: Factorize.h:173
reco::PattRecoTree
Class for storing FFTJet sparse clustering trees.
Definition: PattRecoTree.h:20
FFTJetTreeDump::checkConfig
void checkConfig(const Ptr &ptr, const char *message)
Definition: FFTJetTreeDump.cc:77
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
iEvent
int iEvent
Definition: GenABIO.cc:224
FFTJetTreeDump::sparseTree
SparseTree sparseTree
Definition: FFTJetTreeDump.cc:102
analyze
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
FFTJetTreeDump::distanceCalc
std::unique_ptr< fftjet::AbsDistanceCalculator< fftjet::Peak > > distanceCalc
Definition: FFTJetTreeDump.cc:96
FFTJetTreeDump::completeEventScale
const double completeEventScale
Definition: FFTJetTreeDump.cc:93
FFTJetTreeDump::FFTJetTreeDump
FFTJetTreeDump()=delete
edm::EventSetup
Definition: EventSetup.h:58
FFTJetTreeDump::glyphColor
std::unique_ptr< PeakProperty > glyphColor
Definition: FFTJetTreeDump.cc:106
fftjetdijetfilter_cfi.InitialScales
InitialScales
Definition: fftjetdijetfilter_cfi.py:22
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
fftjetdijetfilter_cfi.treeLabel
treeLabel
Definition: fftjetdijetfilter_cfi.py:11
FFTJetTreeDump::StoredTree
reco::PattRecoTree< Real, reco::PattRecoPeak< Real > > StoredTree
Definition: FFTJetTreeDump.cc:67
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
FFTJetTreeDump::ClusteringTree
fftjet::ProximityClusteringTree< fftjet::Peak, long > ClusteringTree
Definition: FFTJetTreeDump.cc:62
FFTJetTreeDump::iniScales
std::unique_ptr< std::vector< double > > iniScales
Definition: FFTJetTreeDump.cc:99
fftjetdijetfilter_cfi.TreeDistanceCalculator
TreeDistanceCalculator
Definition: fftjetdijetfilter_cfi.py:25
Exception
Definition: hltDiff.cc:245
FFTJetParameterParser.h
FFTJetTreeDump::clusteringTree
ClusteringTree * clusteringTree
Definition: FFTJetTreeDump.cc:84
fftjettreedump_cfi.outputPrefix
outputPrefix
Definition: fftjettreedump_cfi.py:32
ALCARECOTkAlBeamHalo_cff.etaMax
etaMax
Definition: ALCARECOTkAlBeamHalo_cff.py:33
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
FFTJetTreeDump::denseFormatter
std::unique_ptr< DXFormatter > denseFormatter
Definition: FFTJetTreeDump.cc:109
FFTJetTreeDump::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: FFTJetTreeDump.cc:188
cms::Exception
Definition: Exception.h:70
ParameterSet.h
FFTJetTreeDump::counter
unsigned counter
Definition: FFTJetTreeDump.cc:112
edm::Event
Definition: Event.h:73
fftjetcms::fftjet_DistanceCalculator_parser
std::unique_ptr< fftjet::AbsDistanceCalculator< fftjet::Peak > > fftjet_DistanceCalculator_parser(const edm::ParameterSet &ps)
Definition: FFTJetParameterParser.cc:404
edm::InputTag
Definition: InputTag.h:15
FFTJetTreeDump
Definition: FFTJetTreeDump.cc:52