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() override;
56 
57 private:
58  // Useful local typedefs
59  typedef fftjet::ProximityClusteringTree<fftjet::Peak, long> ClusteringTree;
60  typedef fftjet::SparseClusteringTree<fftjet::Peak, long> SparseTree;
61  typedef fftjet::OpenDXPeakTree<long, fftjet::AbsClusteringTree> DXFormatter;
62  typedef fftjet::OpenDXPeakTree<long, fftjet::SparseClusteringTree> SparseFormatter;
63  typedef fftjet::Functor1<double, fftjet::Peak> PeakProperty;
65 
66  FFTJetTreeDump() = delete;
67  FFTJetTreeDump(const FFTJetTreeDump&) = delete;
68  FFTJetTreeDump& operator=(const FFTJetTreeDump&) = delete;
69 
70  void beginJob() override;
71  void analyze(const edm::Event&, const edm::EventSetup&) override;
72  void endJob() override;
73 
74  template <class Real>
75  void processTreeData(const edm::Event&, std::ofstream&);
76 
77  template <class Ptr>
78  void checkConfig(const Ptr& ptr, const char* message) {
79  if (ptr.get() == nullptr)
80  throw cms::Exception("FFTJetBadConfig") << message << std::endl;
81  }
82 
83  // ----------member data ---------------------------
84  // The complete clustering tree
86 
89 
91  const double etaMax;
93  const bool insertCompleteEvent;
94  const double completeEventScale;
95 
96  // Distance calculator for the clustering tree
97  std::unique_ptr<fftjet::AbsDistanceCalculator<fftjet::Peak> > distanceCalc;
98 
99  // Scales used
100  std::unique_ptr<std::vector<double> > iniScales;
101 
102  // The sparse clustering tree
104 
105  // Functors which define OpenDX glyph size and color
106  std::unique_ptr<PeakProperty> glyphSize;
107  std::unique_ptr<PeakProperty> glyphColor;
108 
109  // OpenDX formatters
110  std::unique_ptr<DXFormatter> denseFormatter;
111  std::unique_ptr<SparseFormatter> sparseFormatter;
112 
113  unsigned counter;
114 };
115 
116 //
117 // constructors and destructor
118 //
120  : clusteringTree(nullptr),
121  treeLabel(ps.getParameter<edm::InputTag>("treeLabel")),
122  outputPrefix(ps.getParameter<std::string>("outputPrefix")),
123  etaMax(ps.getParameter<double>("etaMax")),
124  storeInSinglePrecision(true),
125  insertCompleteEvent(ps.getParameter<bool>("insertCompleteEvent")),
126  completeEventScale(ps.getParameter<double>("completeEventScale")),
127  counter(0) {
128  if (etaMax < 0.0)
129  throw cms::Exception("FFTJetBadConfig") << "etaMax can not be negative" << std::endl;
130 
131  // Build the set of pattern recognition scales
132  const edm::ParameterSet& InitialScales(ps.getParameter<edm::ParameterSet>("InitialScales"));
134  checkConfig(iniScales, "invalid set of scales");
135  std::sort(iniScales->begin(), iniScales->end(), std::greater<double>());
136 
137  // Distance calculator for the clustering tree
138  const edm::ParameterSet& TreeDistanceCalculator(ps.getParameter<edm::ParameterSet>("TreeDistanceCalculator"));
140  checkConfig(distanceCalc, "invalid tree distance calculator");
141 
142  // Determine representations for the OpenDX glyph size and color
145  checkConfig(glyphSize, "invalid glyph size parameters");
146 
149  checkConfig(glyphColor, "invalid glyph color parameters");
150 
151  // Build the tree formatters
152  denseFormatter = std::make_unique<DXFormatter>(glyphSize.get(), glyphColor.get(), etaMax);
153  sparseFormatter = std::make_unique<SparseFormatter>(glyphSize.get(), glyphColor.get(), etaMax);
154 
155  // Build the clustering tree
157 
158  treeToken = consumes<StoredTree>(treeLabel);
159 }
160 
162 
163 //
164 // member functions
165 //
166 template <class Real>
168  // Get the event number
169  edm::RunNumber_t const runNum = iEvent.id().run();
170  edm::EventNumber_t const evNum = iEvent.id().event();
171 
172  // Get the input
174  iEvent.getByToken(treeToken, input);
175 
176  const double eventScale = insertCompleteEvent ? completeEventScale : 0.0;
177  if (input->isSparse()) {
178  sparsePeakTreeFromStorable(*input, iniScales.get(), eventScale, &sparseTree);
179  sparseFormatter->setTree(sparseTree, runNum, evNum);
180  file << *sparseFormatter << std::endl;
181  } else {
183  denseFormatter->setTree(*clusteringTree, runNum, evNum);
184  file << *denseFormatter << std::endl;
185  }
186 }
187 
188 // ------------ method called to for each event ------------
190  // Create the file name
191  std::ostringstream filename;
192  filename << outputPrefix << '_' << counter++ << ".dx";
193 
194  // Open the file
195  std::ofstream file(filename.str().c_str());
196  if (!file)
197  throw cms::Exception("FFTJetBadConfig") << "Failed to open file \"" << filename.str() << "\"" << std::endl;
198 
200  processTreeData<float>(iEvent, file);
201  else
202  processTreeData<double>(iEvent, file);
203 }
204 
205 // ------------ method called once each job just before starting event loop
207 
208 // ------------ method called once each job just after ending the event loop
210 
211 //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:63
FFTJetTreeDump::sparseFormatter
std::unique_ptr< SparseFormatter > sparseFormatter
Definition: FFTJetTreeDump.cc:111
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:209
RunLumiEventNumber.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
FFTJetTreeDump::~FFTJetTreeDump
~FFTJetTreeDump() override
Definition: FFTJetTreeDump.cc:161
FFTJetTreeDump::processTreeData
void processTreeData(const edm::Event &, std::ofstream &)
Definition: FFTJetTreeDump.cc:167
fftjetdijetfilter_cfi.completeEventScale
completeEventScale
Definition: fftjetdijetfilter_cfi.py:17
clusteringTreeConverters.h
FFTJetTreeDump::glyphSize
std::unique_ptr< PeakProperty > glyphSize
Definition: FFTJetTreeDump.cc:106
EDAnalyzer.h
fftjetdijetfilter_cfi.insertCompleteEvent
insertCompleteEvent
Definition: fftjetdijetfilter_cfi.py:16
FFTJetTreeDump::DXFormatter
fftjet::OpenDXPeakTree< long, fftjet::AbsClusteringTree > DXFormatter
Definition: FFTJetTreeDump.cc:61
edm::Handle
Definition: AssociativeIterator.h:50
FFTJetTreeDump::insertCompleteEvent
const bool insertCompleteEvent
Definition: FFTJetTreeDump.cc:93
FFTJetTreeDump::SparseFormatter
fftjet::OpenDXPeakTree< long, fftjet::SparseClusteringTree > SparseFormatter
Definition: FFTJetTreeDump.cc:62
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:90
FFTJetTreeDump::beginJob
void beginJob() override
Definition: FFTJetTreeDump.cc:206
MakerMacros.h
FFTJetTreeDump::treeToken
edm::EDGetTokenT< StoredTree > treeToken
Definition: FFTJetTreeDump.cc:88
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
FFTJetTreeDump::storeInSinglePrecision
const bool storeInSinglePrecision
Definition: FFTJetTreeDump.cc:92
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
FFTJetTreeDump::etaMax
const double etaMax
Definition: FFTJetTreeDump.cc:91
FFTJetTreeDump::SparseTree
fftjet::SparseClusteringTree< fftjet::Peak, long > SparseTree
Definition: FFTJetTreeDump.cc:60
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:87
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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:78
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
iEvent
int iEvent
Definition: GenABIO.cc:224
FFTJetTreeDump::sparseTree
SparseTree sparseTree
Definition: FFTJetTreeDump.cc:103
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:97
FFTJetTreeDump::completeEventScale
const double completeEventScale
Definition: FFTJetTreeDump.cc:94
FFTJetTreeDump::FFTJetTreeDump
FFTJetTreeDump()=delete
edm::EventSetup
Definition: EventSetup.h:58
FFTJetTreeDump::glyphColor
std::unique_ptr< PeakProperty > glyphColor
Definition: FFTJetTreeDump.cc:107
fftjetdijetfilter_cfi.InitialScales
InitialScales
Definition: fftjetdijetfilter_cfi.py:22
fftjetdijetfilter_cfi.treeLabel
treeLabel
Definition: fftjetdijetfilter_cfi.py:11
FFTJetTreeDump::StoredTree
reco::PattRecoTree< Real, reco::PattRecoPeak< Real > > StoredTree
Definition: FFTJetTreeDump.cc:64
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
FFTJetTreeDump::ClusteringTree
fftjet::ProximityClusteringTree< fftjet::Peak, long > ClusteringTree
Definition: FFTJetTreeDump.cc:59
FFTJetTreeDump::iniScales
std::unique_ptr< std::vector< double > > iniScales
Definition: FFTJetTreeDump.cc:100
fftjetdijetfilter_cfi.TreeDistanceCalculator
TreeDistanceCalculator
Definition: fftjetdijetfilter_cfi.py:25
Exception
Definition: hltDiff.cc:245
FFTJetParameterParser.h
FFTJetTreeDump::clusteringTree
ClusteringTree * clusteringTree
Definition: FFTJetTreeDump.cc:85
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:110
FFTJetTreeDump::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: FFTJetTreeDump.cc:189
cms::Exception
Definition: Exception.h:70
ParameterSet.h
FFTJetTreeDump::counter
unsigned counter
Definition: FFTJetTreeDump.cc:113
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