1 |
// -*- C++ -*-
|
2 |
//
|
3 |
// Package: HistoAnalyzer
|
4 |
// Class: HistoAnalyzer
|
5 |
//
|
6 |
/**\class HistoAnalyzer HistoAnalyzer.cc Prototyping/HistoAnalyzer/src/HistoAnalyzer.cc
|
7 |
|
8 |
Description: <one line class summary>
|
9 |
|
10 |
Implementation:
|
11 |
<Notes on implementation>
|
12 |
*/
|
13 |
//
|
14 |
// Original Author: Benedikt HEGNER
|
15 |
// Created: Mon May 7 15:31:00 CEST 2007
|
16 |
// $Id: ExpressionHisto.h,v 1.1.1.4 2008/02/25 15:54:04 auterman Exp $
|
17 |
//
|
18 |
//
|
19 |
|
20 |
|
21 |
// system include files
|
22 |
#include <memory>
|
23 |
|
24 |
// user include files
|
25 |
#include "FWCore/Framework/interface/Event.h"
|
26 |
#include "FWCore/Framework/interface/MakerMacros.h"
|
27 |
|
28 |
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
29 |
|
30 |
// code specific includes
|
31 |
#include "PhysicsTools/Parser/interface/MethodMap.h"
|
32 |
#include "Reflex/Type.h"
|
33 |
|
34 |
#include "FWCore/ServiceRegistry/interface/Service.h"
|
35 |
#include "PhysicsTools/UtilAlgos/interface/TFileService.h"
|
36 |
#include "PhysicsTools/Parser/interface/MethodMap.h"
|
37 |
#include "PhysicsTools/Parser/interface/cutParser.h"
|
38 |
#include "PhysicsTools/Parser/interface/ExpressionVar.h"
|
39 |
|
40 |
//#include "Object.h"
|
41 |
#include "TFile.h"
|
42 |
#include "TH1F.h"
|
43 |
#include "TH1.h"
|
44 |
#include <string>
|
45 |
#include <sstream>
|
46 |
#include <ostream>
|
47 |
#include <fstream>
|
48 |
#include <iostream>
|
49 |
#include <iomanip>
|
50 |
#include <ios>
|
51 |
|
52 |
|
53 |
//
|
54 |
// class decleration
|
55 |
//
|
56 |
template<typename T>
|
57 |
class ExpressionHisto {
|
58 |
|
59 |
private:
|
60 |
int nbins;
|
61 |
double min, max;
|
62 |
std::string name, plotquantity;
|
63 |
TH1F * hist;
|
64 |
ROOT::Reflex::Type & type;
|
65 |
reco::parser::ExpressionVar * expr;
|
66 |
|
67 |
public:
|
68 |
ExpressionHisto(const edm::ParameterSet& iConfig);
|
69 |
~ExpressionHisto();
|
70 |
|
71 |
void initialize(edm::Service<TFileService>& fs);
|
72 |
void fill( T element);
|
73 |
};
|
74 |
|
75 |
template<typename T>
|
76 |
ExpressionHisto<T>::ExpressionHisto(const edm::ParameterSet& iConfig)
|
77 |
{
|
78 |
min = iConfig.template getUntrackedParameter<double>("min");
|
79 |
max = iConfig.template getUntrackedParameter<double>("max");
|
80 |
nbins = iConfig.template getUntrackedParameter<int>("nbins");
|
81 |
name = iConfig.template getUntrackedParameter<std::string>("name");
|
82 |
plotquantity = iConfig.template getUntrackedParameter<std::string>("plotquantity");
|
83 |
reco::MethodMap methods_ = reco::MethodMap::methods<T>();
|
84 |
reco::MethodMap::const_iterator m = methods_.find(plotquantity);
|
85 |
type = methods_.type();
|
86 |
if (m==methods_.end())
|
87 |
throw cms::Exception("BadConfig") << "ExpressionHisto: Cannot find expression ("
|
88 |
<< plotquantity << ", " << name << ").";
|
89 |
expr = new reco::parser::ExpressionVar( m->second );
|
90 |
}
|
91 |
|
92 |
template<typename T>
|
93 |
ExpressionHisto<T>::~ExpressionHisto()
|
94 |
{
|
95 |
delete expr;
|
96 |
}
|
97 |
|
98 |
|
99 |
template<typename T>
|
100 |
void ExpressionHisto<T>::initialize(edm::Service<TFileService>& fs)
|
101 |
{
|
102 |
hist = fs->template make<TH1F>(name.c_str(),plotquantity.c_str(),nbins,min,max);
|
103 |
}
|
104 |
|
105 |
template<typename T>
|
106 |
void ExpressionHisto<T>::fill(T element)
|
107 |
{
|
108 |
hist->Fill(expr->value(ROOT::Reflex::Object(type, &element)));
|
109 |
}
|
110 |
|
111 |
|