CMS 3D CMS Logo

BigEventsDebugger.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: BigEventsDebugger
4 // Class: BigEventsDebugger
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Sun Nov 16 16:04:44 CET 2008
16 // $Id: BigEventsDebugger.cc,v 1.2 2012/12/05 21:51:54 venturia Exp $
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
30 
32 
33 #include <vector>
34 #include "TH1F.h"
35 #include "TH2F.h"
36 #include "TProfile.h"
37 
39 
42 
48 
50 
51 //
52 // class decleration
53 //
54 
55 template <class T>
56 class BigEventsDebugger : public edm::one::EDAnalyzer<edm::one::SharedResources> {
57 public:
58  explicit BigEventsDebugger(const edm::ParameterSet&);
59  ~BigEventsDebugger() override;
60 
61 private:
62  void analyze(const edm::Event&, const edm::EventSetup&) override;
63 
64  // ----------member data ---------------------------
65 
69  bool m_folded;
73 
74  std::vector<std::string> m_labels;
75  std::vector<TH1F*> m_hist;
76  std::vector<TProfile*> m_hprof;
77  std::vector<TH2F*> m_hist2d;
78 };
79 
80 //
81 // constants, enums and typedefs
82 //
83 
84 //
85 // static data member definitions
86 //
87 
88 //
89 // constructors and destructor
90 //
91 template <class T>
93  : m_digiprofiler(iConfig),
94  m_collectionToken(consumes<T>(iConfig.getParameter<edm::InputTag>("collection"))),
95  m_singleevents(iConfig.getParameter<bool>("singleEvents")),
96  m_folded(iConfig.getUntrackedParameter<bool>("foldedStrips", false)),
97  m_want1dHisto(iConfig.getUntrackedParameter<bool>("want1dHisto", true)),
98  m_wantProfile(iConfig.getUntrackedParameter<bool>("wantProfile", true)),
99  m_want2dHisto(iConfig.getUntrackedParameter<bool>("want2dHisto", false))
100 
101 {
102  //now do what ever initialization is needed
103  usesResource(TFileService::kSharedResource);
104 
105  std::vector<edm::ParameterSet> selconfigs = iConfig.getParameter<std::vector<edm::ParameterSet> >("selections");
106 
107  for (std::vector<edm::ParameterSet>::const_iterator selconfig = selconfigs.begin(); selconfig != selconfigs.end();
108  ++selconfig) {
109  m_labels.push_back(selconfig->getParameter<std::string>("label"));
110  }
111 
113 
114  if (!m_singleevents) {
115  char dirname[500];
116  sprintf(dirname, "Summary");
117  TFileDirectory subd = tfserv->mkdir(dirname);
118 
119  //book histos
120 
121  unsigned int nbins = 768;
122  if (m_folded)
123  nbins = 256;
124 
125  for (std::vector<std::string>::const_iterator label = m_labels.begin(); label != m_labels.end(); ++label) {
126  if (m_want1dHisto) {
127  std::string hname = *label + "hist";
128  std::string htitle = *label + " occupancy";
129  m_hist.push_back(subd.make<TH1F>(hname.c_str(), htitle.c_str(), nbins, -0.5, nbins - 0.5));
130  }
131  if (m_wantProfile) {
132  std::string hname = *label + "prof";
133  std::string htitle = *label + " charge profile";
134  m_hprof.push_back(subd.make<TProfile>(hname.c_str(), htitle.c_str(), nbins, -0.5, nbins - 0.5));
135  }
136  if (m_want2dHisto) {
137  std::string hname = *label + "hist2d";
138  std::string htitle = *label + " charge distribution";
139  m_hist2d.push_back(subd.make<TH2F>(hname.c_str(), htitle.c_str(), nbins, -0.5, nbins - 0.5, 257, -0.5, 256.5));
140  }
141  }
142  }
143 }
144 
145 template <class T>
147  // do anything here that needs to be done at desctruction time
148  // (e.g. close files, deallocate resources etc.)
149 }
150 
151 //
152 // member functions
153 //
154 
155 // ------------ method called to for each event ------------
156 template <class T>
158  using namespace edm;
159 
161 
162  // create a folder for each event
163 
164  if (m_singleevents) {
165  m_hist.clear();
166  m_hprof.clear();
167  m_hist2d.clear();
168 
169  char dirname[500];
170  sprintf(dirname, "event_%u_%llu", iEvent.run(), iEvent.id().event());
171  TFileDirectory subd = tfserv->mkdir(dirname);
172 
173  //book histos
174 
175  unsigned int nbins = 768;
176  if (m_folded)
177  nbins = 256;
178 
179  for (std::vector<std::string>::const_iterator label = m_labels.begin(); label != m_labels.end(); ++label) {
180  if (m_want1dHisto) {
181  std::string hname = *label + "hist";
182  std::string htitle = *label + " occupancy";
183  m_hist.push_back(subd.make<TH1F>(hname.c_str(), htitle.c_str(), nbins, -0.5, nbins - 0.5));
184  }
185  if (m_wantProfile) {
186  std::string hname = *label + "prof";
187  std::string htitle = *label + " charge profile";
188  m_hprof.push_back(subd.make<TProfile>(hname.c_str(), htitle.c_str(), nbins, -0.5, nbins - 0.5));
189  }
190  if (m_want2dHisto) {
191  std::string hname = *label + "hist2d";
192  std::string htitle = *label + " charge distribution";
193  m_hist2d.push_back(subd.make<TH2F>(hname.c_str(), htitle.c_str(), nbins, -0.5, nbins - 0.5, 257, -0.5, 256.5));
194  }
195  }
196  }
197 
198  //analyze event
199 
200  Handle<T> digis;
201  iEvent.getByToken(m_collectionToken, digis);
202  m_digiprofiler.fill(digis, m_hist, m_hprof, m_hist2d);
203 }
204 
208 
209 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::vector< TH1F * > m_hist
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< TH2F * > m_hist2d
~BigEventsDebugger() override
BigEventsDebugger< edm::DetSetVector< SiStripDigi > > DigiBigEventsDebugger
T * make(const Args &...args) const
make new ROOT object
char const * label
int iEvent
Definition: GenABIO.cc:224
void analyze(const edm::Event &, const edm::EventSetup &) override
DigiCollectionProfiler< T > m_digiprofiler
std::vector< TProfile * > m_hprof
BigEventsDebugger(const edm::ParameterSet &)
edm::EDGetTokenT< T > m_collectionToken
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
HLT enums.
std::vector< std::string > m_labels
long double T
BigEventsDebugger< edm::DetSetVector< SiStripRawDigi > > RawDigiBigEventsDebugger
BigEventsDebugger< edmNew::DetSetVector< SiStripCluster > > ClusterBigEventsDebugger