1 #ifndef ConfigurableAnalysis_ConfigurableHisto_H 2 #define ConfigurableAnalysis_ConfigurableHisto_H 89 if (conf_.exists(
"yAxis")) {
92 yLabel = yAxis.Label();
94 if (yAxisPSet.
exists(
"var"))
96 yVBin = yAxis.variableSize();
99 if (conf_.exists(
"zAxis")) {
103 bool xVBin = xAxis.variableSize();
108 h_ = dir->
make<TH1F>(name_.c_str(), title.c_str(), xAxis.nBin(), xAxis.xBins());
110 h_ = dir->
make<TH1F>(name_.c_str(), title.c_str(), xAxis.nBin(), xAxis.Min(), xAxis.Max());
111 }
else if (
type() == h2) {
115 h_ = dir->
make<TH2F>(name_.c_str(), title.c_str(), xAxis.nBin(), xAxis.xBins(), yAxis.
nBin(), yAxis.
xBins());
117 h_ = dir->
make<TH2F>(
118 name_.c_str(), title.c_str(), xAxis.nBin(), xAxis.xBins(), yAxis.
nBin(), yAxis.
Min(), yAxis.
Max());
121 h_ = dir->
make<TH2F>(
122 name_.c_str(), title.c_str(), xAxis.nBin(), xAxis.Min(), xAxis.Max(), yAxis.
nBin(), yAxis.
xBins());
124 h_ = dir->
make<TH2F>(name_.c_str(),
133 }
else if (
type() == prof) {
136 if (conf_.exists(
"Option"))
140 h_ = dir->
make<TProfile>(
141 name_.c_str(), title.c_str(), xAxis.nBin(), xAxis.xBins(), yAxis.
Min(), yAxis.
Max(), pFopt.c_str());
143 h_ = dir->
make<TProfile>(name_.c_str(),
153 edm::LogError(
"ConfigurableHisto") <<
"cannot book: " << name_ <<
"\n" << conf_.dump();
158 h_->GetXaxis()->SetTitle(xAxis.Label().c_str());
159 h_->SetYTitle(yLabel.c_str());
161 if (conf_.exists(
"weight")) {
172 if (w_->compute(iEvent))
175 edm::LogInfo(
"ConfigurableHisto") <<
"could not compute the weight for: " << name_ <<
" with config:\n" 176 << conf_.dump() <<
" default to 1.0";
180 TProfile* pcast(
nullptr);
181 TH2* h2cast(
nullptr);
186 if (x_->compute(iEvent))
187 h_->Fill((*x_)(iEvent), weight);
189 edm::LogInfo(
"ConfigurableHisto") <<
"could not fill: " << name_ <<
" with config:\n" << conf_.dump();
193 pcast =
dynamic_cast<TProfile*
>(h_);
196 if (x_->compute(iEvent) && y_->compute(iEvent))
197 pcast->Fill((*x_)(iEvent), (*y_)(iEvent), weight);
199 edm::LogInfo(
"ConfigurableHisto") <<
"could not fill: " << name_ <<
" with config:\n" << conf_.dump();
203 h2cast =
dynamic_cast<TH2*
>(h_);
206 if (x_->compute(iEvent) && y_->compute(iEvent))
207 h2cast->Fill((*x_)(iEvent), (*y_)(iEvent), weight);
209 edm::LogInfo(
"ConfigurableHisto") <<
"could not fill: " << name_ <<
" with config:\n" << conf_.dump();
217 TH1*
h() {
return h_; }
221 type_ = master.
type_;
223 name_ = master.
name_;
224 conf_ = master.
conf_;
248 if (pset.
exists(
"splitters")) {
250 std::vector<std::string> splitters = pset.
getParameter<std::vector<std::string> >(
"splitters");
251 for (
unsigned int s = 0;
s != splitters.size(); ++
s) {
256 <<
"for: " << name_ <<
" the splitting variable: " << splitters[
s] <<
" is not a Splitter";
261 std::vector<ConfigurableHisto*>& insertedHisto = subHistoMap_[
splitter];
263 unsigned int mSlots = splitter->
maxSlots();
264 for (
unsigned int i = 0;
i != mSlots; ++
i) {
269 edm::Entry e(
"string", title +
" for " + label,
true);
270 mPset.
insert(
true,
"title", e);
281 splitter_ =
dynamic_cast<const Splitter*
>(
v);
284 <<
"for: " << name_ <<
" the splitting variable: " << v->
name() <<
" is not a Splitter";
287 unsigned int mSlots = splitter_->maxSlots();
288 for (
unsigned int i = 0;
i != mSlots;
i++) {
292 edm::Entry e(
"string", title +
" for " + label,
true);
293 mPset.
insert(
true,
"title", e);
304 if (!subHistoMap_.empty()) {
305 SubHistoMap::iterator
i = subHistoMap_.begin();
306 SubHistoMap::iterator i_end = subHistoMap_.end();
307 for (; i != i_end; ++
i) {
308 for (
unsigned int h = 0;
h != i->second.size(); ++
h) {
309 i->second[
h]->book(dir);
312 std::string sName = name_ +
"_" + i->first->name();
313 std::string sTitle =
"Stack histogram of " + name_ +
" for splitter " + i->first->name();
314 subHistoStacks_[i->first] = dir->
make<THStack>(sName.c_str(), sTitle.c_str());
317 for (
unsigned int h = 0;
h != subHistos_.size();
h++) {
318 subHistos_[
h]->book(dir);
321 std::string sName = name_ +
"_" + splitter_->name();
322 std::string sTitle =
"Stack histogram of " + name_ +
" for splitter " + splitter_->name();
323 stack_ = dir->
make<THStack>(sName.c_str(), sTitle.c_str());
333 if (!subHistoMap_.empty()) {
334 SubHistoMap::iterator
i = subHistoMap_.begin();
335 SubHistoMap::iterator i_end = subHistoMap_.end();
336 for (; i != i_end; ++
i) {
342 unsigned int slot = (
unsigned int)(*splitter)(
e);
343 if (slot >= i->second.size()) {
345 <<
"slot index: " << slot <<
" is bigger than slots size: " << i->second.size()
346 <<
" from variable value: " << (*splitter)(
e);
350 i->second[slot]->fill(e);
356 if (!splitter_->compute(e)) {
359 unsigned int slot = (
unsigned int)(*splitter_)(
e);
360 if (slot >= subHistos_.size()) {
362 <<
"slot index: " << slot <<
" is bigger than slots size: " << subHistos_.size()
363 <<
" from variable value: " << (*splitter_)(
e);
366 subHistos_[slot]->fill(e);
371 if (!subHistoMap_.empty()) {
373 SubHistoMap::iterator
i = subHistoMap_.begin();
374 SubHistoMap::iterator i_end = subHistoMap_.end();
375 for (; i != i_end; ++
i) {
376 for (
unsigned int h = 0;
h != i->second.size();
h++) {
378 subHistoStacks_[i->first]->Add(i->second[
h]->h(), i->first->label(
h).c_str());
384 for (
unsigned int i = 0;
i != subHistos_.size();
i++) {
385 stack_->Add(subHistos_[
i]->
h(), splitter_->label(
i).c_str());
395 SubHistoMap::const_iterator i_end = master.
subHistoMap_.end();
396 for (; i != i_end; ++
i) {
397 const std::vector<ConfigurableHisto*>& masterHistos = i->second;
398 std::vector<ConfigurableHisto*>& clonedHistos = subHistoMap_[i->first];
399 for (
unsigned int i = 0; i != masterHistos.size(); i++) {
400 clonedHistos.push_back(masterHistos[i]->
clone());
404 for (
unsigned int i = 0;
i != master.
subHistos_.size();
i++) {
405 subHistos_.push_back(master.
subHistos_[
i]->clone());
410 typedef std::map<const Splitter*, std::vector<ConfigurableHisto*> >
SubHistoMap;
T getParameter(std::string const &) const
def splitter(iterator, n)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void book(TFileDirectory *dir) override
std::vector< double > vBins_
const Splitter * splitter_
SplittingConfigurableHisto(const SplittingConfigurableHisto &master)
void fill(const edm::Event &e) override
const std::string & Label()
bool exists(std::string const ¶meterName) const
checks if a parameter exists
virtual ConfigurableHisto * clone() const
void insert(bool ok_to_replace, char const *, Entry const &)
SplittingConfigurableHisto(HType t, std::string name, edm::ParameterSet &pset)
std::vector< ConfigurableHisto * > subHistos_
SubHistoStacks subHistoStacks_
virtual void fill(const edm::Event &iEvent)
ConfigurableHisto(HType t, std::string name, edm::ParameterSet &iConfig)
const CachingVariable * y_
const std::string shortLabel(unsigned int i) const
virtual ~ConfigurableHisto()
virtual unsigned int maxSlots() const
ConfigurableHisto(const ConfigurableHisto &master)
const std::string & label(unsigned int i) const
ConfigurableHisto * clone() const override
T * make(const Args &...args) const
make new ROOT object
const CachingVariable * x_
virtual void book(TFileDirectory *dir)
const CachingVariable * w_
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
bool compute(const edm::Event &iEvent) const
std::map< const Splitter *, THStack * > SubHistoStacks
const CachingVariable * z_
const std::string & name() const
std::map< const Splitter *, std::vector< ConfigurableHisto * > > SubHistoMap
ConfigurableAxis(const edm::ParameterSet &par)