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