1 |
// -*- C++ -*-
|
2 |
//
|
3 |
// Package: HHSimpleAnalyzer
|
4 |
// Class: HHSimpleAnalyzer
|
5 |
//
|
6 |
/**\class HHSimpleAnalyzer HHSimpleAnalyzer.cc HHAnalysis/HHSimpleAnalyzer/src/HHSimpleAnalyzer.cc
|
7 |
|
8 |
Description: <one line class summary>
|
9 |
|
10 |
Implementation:
|
11 |
<Notes on implementation>
|
12 |
*/
|
13 |
//
|
14 |
// Original Author: Christian Autermann
|
15 |
// Created: Wed May 16 14:02:29 CEST 2007
|
16 |
// $Id: HHSimpleAnalyzer.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 |
#include <string>
|
24 |
#include <sstream>
|
25 |
#include <ostream>
|
26 |
#include <fstream>
|
27 |
#include <iostream>
|
28 |
#include <iomanip>
|
29 |
#include <ios>
|
30 |
|
31 |
|
32 |
// user include files
|
33 |
#include "FWCore/Framework/interface/Frameworkfwd.h"
|
34 |
#include "FWCore/Framework/interface/EDAnalyzer.h"
|
35 |
#include "FWCore/Framework/interface/Event.h"
|
36 |
#include "FWCore/Framework/interface/MakerMacros.h"
|
37 |
#include "FWCore/ServiceRegistry/interface/Service.h"
|
38 |
#include "PhysicsTools/UtilAlgos/interface/TFileService.h"
|
39 |
|
40 |
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
41 |
|
42 |
#include "TFile.h"
|
43 |
#include "TH1F.h"
|
44 |
#include "TH1.h"
|
45 |
|
46 |
|
47 |
#include "HHAnalysis/HHSimpleAnalyzer/interface/ExpressionHisto.h"
|
48 |
//
|
49 |
// class decleration
|
50 |
//
|
51 |
|
52 |
template <typename T1, typename T2>
|
53 |
class HHSimpleAnalyzer : public edm::EDAnalyzer {
|
54 |
public:
|
55 |
explicit HHSimpleAnalyzer(const edm::ParameterSet&);
|
56 |
~HHSimpleAnalyzer();
|
57 |
|
58 |
|
59 |
private:
|
60 |
virtual void beginJob(const edm::EventSetup&) ;
|
61 |
virtual void analyze(const edm::Event&, const edm::EventSetup&);
|
62 |
virtual void endJob() ;
|
63 |
|
64 |
// ----------member data ---------------------------
|
65 |
edm::InputTag src1_, src2_;
|
66 |
std::string histo_file_;
|
67 |
std::vector<ExpressionHisto<T2>* > hists;
|
68 |
};
|
69 |
|
70 |
//
|
71 |
// constants, enums and typedefs
|
72 |
//
|
73 |
|
74 |
//
|
75 |
// static data member definitions
|
76 |
//
|
77 |
|
78 |
//
|
79 |
// constructors and destructor
|
80 |
//
|
81 |
template <typename T1, typename T2>
|
82 |
HHSimpleAnalyzer<T1,T2>::HHSimpleAnalyzer(const edm::ParameterSet& iConfig) :
|
83 |
src1_( iConfig.template getParameter<edm::InputTag>( "src1" ) ),
|
84 |
src2_( iConfig.template getParameter<edm::InputTag>( "src2" ) ),
|
85 |
histo_file_( iConfig.template getUntrackedParameter<std::string>( "histo_file" ) )
|
86 |
{
|
87 |
//now do what ever initialization is needed
|
88 |
using edm::ParameterSet;
|
89 |
typedef std::vector<edm::ParameterSet> VPSet;
|
90 |
|
91 |
//VPSet not yet implemented ???
|
92 |
VPSet histograms = iConfig.template getParameter<VPSet>("histograms");
|
93 |
VPSet::const_iterator i = histograms.begin();
|
94 |
VPSet::const_iterator e = histograms.end();
|
95 |
edm::Service<TFileService> fs;
|
96 |
for ( ; i!=e; ++i )
|
97 |
{
|
98 |
ExpressionHisto<T2> hist( *i );
|
99 |
hist.initialize( fs );
|
100 |
hists.push_back( &hist );
|
101 |
}
|
102 |
ofstream hist(histo_file_.c_str(), std::ios::out);
|
103 |
}
|
104 |
|
105 |
|
106 |
template <typename T1, typename T2>
|
107 |
HHSimpleAnalyzer<T1,T2>::~HHSimpleAnalyzer()
|
108 |
{
|
109 |
// do anything here that needs to be done at desctruction time
|
110 |
// (e.g. close files, deallocate resources etc.)
|
111 |
typename std::vector<ExpressionHisto<T2>* >::iterator it = hists.begin();
|
112 |
for (;it!=hists.end(); ++it)
|
113 |
(*it)->~ExpressionHisto();
|
114 |
hists.clear();
|
115 |
}
|
116 |
|
117 |
|
118 |
//
|
119 |
// member functions
|
120 |
//
|
121 |
|
122 |
// ------------ method called to for each event ------------
|
123 |
template <typename T1, typename T2> void
|
124 |
HHSimpleAnalyzer<T1,T2>::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
|
125 |
{
|
126 |
using namespace edm;
|
127 |
using namespace std;
|
128 |
Handle<T1> src1;
|
129 |
//Handle<T2> src2;
|
130 |
iEvent.getByLabel( src1_, src1 );
|
131 |
//iEvent.getByLabel( src2_, src2 );
|
132 |
|
133 |
typename std::vector<ExpressionHisto<T2>* >::iterator it = hists.begin();
|
134 |
for (;it!=hists.end(); ++it)
|
135 |
for( typename T1::const_iterator elem1=src1->begin(); elem1!=src1->end(); ++elem1 )
|
136 |
(*it)->fill( *elem1 );
|
137 |
|
138 |
// ESHandle<SetupData> pSetup;
|
139 |
// iSetup.get<SetupRecord>().get(pSetup);
|
140 |
}
|
141 |
|
142 |
|
143 |
// ------------ method called once each job just before starting event loop ------------
|
144 |
template <typename T1, typename T2> void
|
145 |
HHSimpleAnalyzer<T1,T2>::beginJob(const edm::EventSetup&)
|
146 |
{
|
147 |
|
148 |
}
|
149 |
|
150 |
// ------------ method called once each job just after ending the event loop ------------
|
151 |
template <typename T1, typename T2> void
|
152 |
HHSimpleAnalyzer<T1,T2>::endJob() {
|
153 |
}
|
154 |
|
155 |
/*
|
156 |
|
157 |
void Test(const edm::EventSetup&)
|
158 |
{
|
159 |
edm::Service<TFileService> fs;
|
160 |
TH1F * hist = fs->make<TH1F>("a","b", 10, -2., 2.);
|
161 |
}
|
162 |
|
163 |
#include "MagneticField/Engine/interface/MagneticField.h"
|
164 |
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
|
165 |
#include "FWCore/Framework/interface/EventSetup.h"
|
166 |
#include "FWCore/Framework/interface/ESHandle.h"
|
167 |
#include "DataFormats/Common/interface/Handle.h"
|
168 |
#include "FWCore/ParameterSet/interface/InputTag.h"
|
169 |
class MagneticField;
|
170 |
void Test2(const edm::EventSetup& setup)
|
171 |
{
|
172 |
edm::ESHandle<MagneticField> fieldHandle;
|
173 |
setup.get<IdealMagneticFieldRecord>().get(fieldHandle);
|
174 |
}
|
175 |
*/
|
176 |
|