CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
21 // system include files
22 #include <memory>
23 
24 // user include files
27 
31 
33 
34 #include <vector>
35 #include "TH1F.h"
36 #include "TH2F.h"
37 #include "TProfile.h"
38 
40 
43 
48 
50 
51 //
52 // class decleration
53 //
54 
55 template <class T>
57  public:
58  explicit BigEventsDebugger(const edm::ParameterSet&);
60 
61 
62  private:
63  virtual void beginJob(const edm::EventSetup&) ;
64  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
65  virtual void endJob() override ;
66 
67  // ----------member data ---------------------------
68 
72  bool m_folded;
76 
77  std::vector<std::string> m_labels;
78  std::vector<TH1F*> m_hist;
79  std::vector<TProfile*> m_hprof;
80  std::vector<TH2F*> m_hist2d;
81 
82 };
83 
84 //
85 // constants, enums and typedefs
86 //
87 
88 //
89 // static data member definitions
90 //
91 
92 //
93 // constructors and destructor
94 //
95 template <class T>
97  m_digiprofiler(iConfig),
98  m_collectionToken(consumes<T>(iConfig.getParameter<edm::InputTag>("collection"))),
99  m_singleevents(iConfig.getParameter<bool>("singleEvents")),
100  m_folded(iConfig.getUntrackedParameter<bool>("foldedStrips",false)),
101  m_want1dHisto(iConfig.getUntrackedParameter<bool>("want1dHisto",true)),
102  m_wantProfile(iConfig.getUntrackedParameter<bool>("wantProfile",true)),
103  m_want2dHisto(iConfig.getUntrackedParameter<bool>("want2dHisto",false))
104 
105 {
106  //now do what ever initialization is needed
107 
108  std::vector<edm::ParameterSet> selconfigs = iConfig.getParameter<std::vector<edm::ParameterSet> >("selections");
109 
110  for(std::vector<edm::ParameterSet>::const_iterator selconfig=selconfigs.begin();selconfig!=selconfigs.end();++selconfig) {
111  m_labels.push_back(selconfig->getParameter<std::string>("label"));
112  }
113 
114 
116 
117  if(!m_singleevents) {
118  char dirname[500];
119  sprintf(dirname,"Summary");
120  TFileDirectory subd = tfserv->mkdir(dirname);
121 
122  //book histos
123 
124  unsigned int nbins =768;
125  if(m_folded) nbins=256;
126 
127  for(std::vector<std::string>::const_iterator label=m_labels.begin(); label!=m_labels.end(); ++label) {
128  if(m_want1dHisto) {
129  std::string hname = *label + "hist";
130  std::string htitle = *label + " occupancy";
131  m_hist.push_back(subd.make<TH1F>(hname.c_str(),htitle.c_str(),nbins,-0.5,nbins-0.5));
132  }
133  if(m_wantProfile) {
134  std::string hname = *label + "prof";
135  std::string htitle = *label + " charge profile";
136  m_hprof.push_back(subd.make<TProfile>(hname.c_str(),htitle.c_str(),nbins,-0.5,nbins-0.5));
137  }
138  if(m_want2dHisto) {
139  std::string hname = *label + "hist2d";
140  std::string htitle = *label + " charge distribution";
141  m_hist2d.push_back(subd.make<TH2F>(hname.c_str(),htitle.c_str(),nbins,-0.5,nbins-0.5,257,-0.5,256.5));
142  }
143  }
144  }
145 }
146 
147 template <class T>
149 {
150 
151 
152  // do anything here that needs to be done at desctruction time
153  // (e.g. close files, deallocate resources etc.)
154 
155 }
156 
157 
158 //
159 // member functions
160 //
161 
162 // ------------ method called to for each event ------------
163 template <class T>
164 void
166 {
167  using namespace edm;
168 
170 
171  // create a folder for each event
172 
173  if(m_singleevents) {
174 
175  m_hist.clear(); m_hprof.clear(); m_hist2d.clear();
176 
177  char dirname[500];
178  sprintf(dirname,"event_%u_%u",iEvent.run(),iEvent.id().event());
179  TFileDirectory subd = tfserv->mkdir(dirname);
180 
181  //book histos
182 
183  unsigned int nbins =768;
184  if(m_folded) nbins=256;
185 
186  for(std::vector<std::string>::const_iterator label=m_labels.begin(); label!=m_labels.end(); ++label) {
187  if(m_want1dHisto) {
188  std::string hname = *label + "hist";
189  std::string htitle = *label + " occupancy";
190  m_hist.push_back(subd.make<TH1F>(hname.c_str(),htitle.c_str(),nbins,-0.5,nbins-0.5));
191  }
192  if(m_wantProfile) {
193  std::string hname = *label + "prof";
194  std::string htitle = *label + " charge profile";
195  m_hprof.push_back(subd.make<TProfile>(hname.c_str(),htitle.c_str(),nbins,-0.5,nbins-0.5));
196  }
197  if(m_want2dHisto) {
198  std::string hname = *label + "hist2d";
199  std::string htitle = *label + " charge distribution";
200  m_hist2d.push_back(subd.make<TH2F>(hname.c_str(),htitle.c_str(),nbins,-0.5,nbins-0.5,257,-0.5,256.5));
201  }
202  }
203 
204  }
205 
206  //analyze event
207 
208  Handle<T> digis;
209  iEvent.getByToken(m_collectionToken,digis);
210  m_digiprofiler.fill(digis,m_hist,m_hprof,m_hist2d);
211 
212 }
213 
214 
215 // ------------ method called once each job just before starting event loop ------------
216 template <class T>
217 void
219 {
220 }
221 
222 // ------------ method called once each job just after ending the event loop ------------
223 template <class T>
224 void
226 }
227 
230 
231 //define this as a plug-in
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
virtual void beginJob()
Definition: EDAnalyzer.h:67
std::vector< TH1F * > m_hist
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< TH2F * > m_hist2d
BigEventsDebugger< edm::DetSetVector< SiStripDigi > > DigiBigEventsDebugger
int iEvent
Definition: GenABIO.cc:230
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
DigiCollectionProfiler< T > m_digiprofiler
std::vector< TProfile * > m_hprof
RunNumber_t run() const
Definition: Event.h:88
T * make(const Args &...args) const
make new ROOT object
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
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
edm::EventID id() const
Definition: EventBase.h:56
std::vector< std::string > m_labels
volatile std::atomic< bool > shutdown_flag false
long double T
BigEventsDebugger< edmNew::DetSetVector< SiStripCluster > > ClusterBigEventsDebugger
virtual void endJob() override