CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DQMSourceExample.cc
Go to the documentation of this file.
1 /*
2  * \file DQMSourceExample.cc
3  * \author C.Leonidopoulos
4  * Last Update:
5  * $Date: 2009/12/14 22:22:23 $
6  * $Revision: 1.26 $
7  * $Author: wmtan $
8  *
9  * Description: Simple example showing how to create a DQM source creating and filling
10  * monitoring elements
11 */
12 
15 
16 #include "TRandom.h"
17 #include <math.h>
18 
19 using namespace std;
20 using namespace edm;
21 
22 //==================================================================//
23 //================= Constructor and Destructor =====================//
24 //==================================================================//
26  parameters_ = ps;
27  initialize();
28 }
29 
31 }
32 
33 //==================================================================//
34 //======================= Initialise ===============================//
35 //==================================================================//
37 
39  counterEvt_ = 0; counterLS_ = 0;
40 
43 
45  monitorName_ = parameters_.getUntrackedParameter<string>("monitorName","YourSubsystemName");
46  cout << "DQMSourceExample: Monitor name = " << monitorName_ << endl;
47  if (monitorName_ != "" ) monitorName_ = monitorName_+"/" ;
48 
50  prescaleLS_ = parameters_.getUntrackedParameter<int>("prescaleLS", -1);
51  cout << "DQMSourceExample: DQM lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< endl;
52  prescaleEvt_ = parameters_.getUntrackedParameter<int>("prescaleEvt", -1);
53  cout << "DQMSourceExample: DQM event prescale = " << prescaleEvt_ << " events(s)"<< endl;
54 
55 // read in files (use DQMStore.collateHistograms = True for summing
56 // dbe_->load("ref.root");
57 // dbe_->load("ref.root");
58 }
59 
60 //==================================================================//
61 //========================= beginJob ===============================//
62 //==================================================================//
66 
68  dbe_->setCurrentFolder(monitorName_+"DQMsource/Summary");
69  summ = dbe_->book1D("summary", "Run Summary", 100, 0, 100);
70 
71  //-------------------------------------
72  // testing of Quality Tests
73  //-------------------------------------
74 
76  dbe_->setCurrentFolder(monitorName_+"DQMsource/QTests");
77 
79  NBINS = 40 ; XMIN = 0.; XMAX = 40.;
80 
84  xTrue = dbe_->book1D("XTrue", "X Range QTest", NBINS, XMIN, XMAX);
85  xFalse = dbe_->book1D("XFalse", "X Range QTest", NBINS, XMIN, XMAX);
86  yTrue = dbe_->book1D("YTrue", "Y Range QTest", NBINS, XMIN, XMAX);
87  yFalse = dbe_->book1D("YFalse", "Y Range QTest", NBINS, XMIN, XMAX);
88  wExpTrue = dbe_->book2D("WExpTrue", "Contents Within Expected QTest", NBINS, XMIN, XMAX, NBINS, XMIN, XMAX);
89  wExpFalse = dbe_->book2D("WExpFalse", "Contents Within Expected QTest", NBINS, XMIN, XMAX, NBINS, XMIN, XMAX);
90  meanTrue = dbe_->book1D("MeanTrue", "Mean Within Expected QTest", NBINS, XMIN, XMAX);
91  meanFalse = dbe_->book1D("MeanFalse", "Mean Within Expected QTest", NBINS, XMIN, XMAX);
92  deadTrue = dbe_->book1D("DeadTrue", "Dead Channel QTest", NBINS, XMIN, XMAX);
93  deadFalse = dbe_->book1D("DeadFalse", "Dead Channel QTest", NBINS, XMIN, XMAX);
94  noisyTrue = dbe_->book1D("NoisyTrue", "Noisy Channel QTest", NBINS, XMIN, XMAX);
95  noisyFalse = dbe_->book1D("NoisyFalse", "Noisy Channel QTest", NBINS, XMIN, XMAX);
96 
97 
98  //-------------------------------------
99  // book several ME more
100  //-------------------------------------
101 
103  dbe_->setCurrentFolder(monitorName_+"DQMsource/C1");
104  const int NBINS2 = 10;
105 
106  i1 = dbe_->bookInt("int1");
107  f1 = dbe_->bookFloat("float1");
108  s1 = dbe_->bookString("s1", "My string");
109  h1 = dbe_->book1D("h1f", "Example TH1F 1D histogram.", NBINS2, XMIN, XMAX);
110  h2 = dbe_->book1S("h1s", "Example TH1S histogram.", NBINS, XMIN, XMAX);
111 // h3 = dbe_->book1DD("h1d", "Example TH1D histogram.", NBINS, XMIN, XMAX);
112 // h4 = dbe_->book2DD("h2d", "Example TH2D histogram.", NBINS, XMIN, XMAX,NBINS, XMIN, XMAX);
113  p1 = dbe_->bookProfile( "prof1", "My profile 1D", NBINS,XMIN,XMAX,NBINS,XMIN,XMAX,"");
114  p2 = dbe_->bookProfile2D("prof2", "My profile 2D", NBINS,XMIN,XMAX,NBINS,XMIN,XMAX,NBINS,XMIN,XMAX,"");
115  h1hist = dbe_->book1D("history 1D","Example 1 1D history plot", 30, 0.,30.);
116 
117  // set labels for h1
118  char temp[1024];
119  for(int i = 1; i <= NBINS2; ++i) {
120  sprintf(temp, " bin no. %d", i);
121  h1->setBinLabel(i, temp);
122  }
123 
124  // assign tag to MEs h1
125  const unsigned int detector_id = 17;
126  dbe_->tag(h1, detector_id);
127 
128  // tag full directory
129  dbe_->tagContents(monitorName_+"DQMsource/C1", detector_id);
130 
131  /*
132  // contents of h5 & h6 will be reset at end of monitoring cycle
133  h5->setResetMe(true);
134  h6->setResetMe(true);
135  dbe_->showDirStructure();
136  std::vector<std::string> tags;
137  dbe_->getAllTags(tags);
138  for (size_t i = 0, e = tags.size(); i < e; ++i)
139  std::cout << "TAGS [" << i << "] = " << tags[i] << std::endl;
140  */
141 
143 }
144 
145 //==================================================================//
146 //========================= beginRun ===============================//
147 //==================================================================//
148 void DQMSourceExample::beginRun(const edm::Run& r, const EventSetup& context) {
149 }
150 
151 
152 //==================================================================//
153 //==================== beginLuminosityBlock ========================//
154 //==================================================================//
156  const EventSetup& context) {
157 }
158 
159 
160 //==================================================================//
161 //==================== analyse (takes each event) ==================//
162 //==================================================================//
163 void DQMSourceExample::analyze(const Event& iEvent, const EventSetup& iSetup) {
164  counterEvt_++;
165  if (prescaleEvt_<1) return;
166  if (prescaleEvt_ > 0 && counterEvt_%prescaleEvt_!=0) return;
167  // cout << " processing conterEvt_: " << counterEvt_ <<endl;
168 
169  // fill integer and float
170 // number exceeding 32 bits
171  i1->Fill(400000000000000LL); // FIXME use double
172  f1->Fill(-3.14);
173 
174  //----------------------------------------
175  // Filling the histograms with random data
176  //----------------------------------------
177 
178  srand( 0 );
179  // fill summ histo
180  if(counterEvt_%1000 == 0) {
181  cout << " # of events = " << counterEvt_ << endl;
182  summ->Fill(counterEvt_/1000., counterEvt_);
183  }
184  // fill summ histo
185  if(counterEvt_%100 == 0) {
186  h1hist->ShiftFillLast(gRandom->Gaus(12,1.),1.,5);
187  }
188 
189  float z = gRandom->Uniform(XMAX);
190  xTrue->Fill( z, 1./log(z+1.) );
191  xFalse->Fill( z+(XMAX/2.), z );
192  yTrue->Fill( z, 1./log(z+1.) );
193  yFalse->Fill( z, z );
194  meanTrue->Fill( gRandom->Gaus(10, 2), 1.);
195  meanFalse->Fill( gRandom->Gaus(12, 3), 1.);
196  wExpTrue->Fill( gRandom->Gaus(12, 1), gRandom->Gaus(12, 1), 1.);
197  wExpFalse->Fill( gRandom->Gaus(20, 2), gRandom->Gaus(20, 2), 1.);
198  deadTrue->Fill( gRandom->Gaus(20, 10), 2.);
199  deadFalse->Fill( gRandom->Gaus(20, 4), 1.);
200  h2->Fill( gRandom->Gaus(20, 4), 1.);
201 // h3->Fill( XMIN, 0xffff00000000LL);
202 // h4->Fill( XMIN, XMIN, 0xffff00000000LL);
203 
204  //h1hist->Print();
205  //h1hist->Print();
206 
207  for ( int i = 0; i != 10; ++i ) {
208  float w = gRandom->Uniform(XMAX);
209  noisyTrue->Fill( w, 1.);
210  noisyFalse->Fill( z, 1.);
211  float x = gRandom->Gaus(12, 1);
212  float y = gRandom->Gaus(20, 2);
213  p1->Fill(x, y);
214  p2->Fill(x, y, (x+y)/2.);
215  h1->Fill(y, 1.);
216  }
217 
218  // usleep(100);
219 
220 }
221 
222 //==================================================================//
223 //========================= endLuminosityBlock =====================//
224 //==================================================================//
226  const EventSetup& context) {
227 
228 }
229 
230 //==================================================================//
231 //============================= endRun =============================//
232 //==================================================================//
233 void DQMSourceExample::endRun(const Run& r, const EventSetup& context) {
234 
235 }
236 
237 //==================================================================//
238 //============================= endJob =============================//
239 //==================================================================//
241  std::cout << "DQMSourceExample::endJob()" << std::endl;
242 }
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
int i
Definition: DBlmapReader.cc:9
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
DQMSourceExample(const edm::ParameterSet &)
double double double z
MonitorElement * bookFloat(const char *name)
Book float.
Definition: DQMStore.cc:654
void tag(MonitorElement *me, unsigned int myTag)
Definition: DQMStore.cc:1354
int iEvent
Definition: GenABIO.cc:243
MonitorElement * bookString(const char *name, const char *value)
Book string.
Definition: DQMStore.cc:683
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
void analyze(const edm::Event &e, const edm::EventSetup &c)
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
Definition: DQMStore.cc:1031
double p2[4]
Definition: TauolaWrapper.h:90
DQMStore * dbe_
double p1[4]
Definition: TauolaWrapper.h:89
void tagContents(const std::string &path, unsigned int myTag)
tag all children of folder (does NOT include subfolders)
Definition: DQMStore.cc:1385
tuple cout
Definition: gather_cfg.py:121
void endRun(const edm::Run &r, const edm::EventSetup &c)
void showDirStructure(void) const
Definition: DQMStore.cc:2761
Definition: DDAxes.h:10
MonitorElement * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:624
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:845
MonitorElement * book1S(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1S histogram.
Definition: DQMStore.cc:733
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
const int NBINS
Definition: Run.h:33
T w() const
void beginRun(const edm::Run &r, const edm::EventSetup &c)
MonitorElement * bookProfile2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ, const char *option="s")
Definition: DQMStore.cc:1175