CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQMServices/Examples/src/DQMSourceExample.cc

Go to the documentation of this file.
00001 /*
00002  * \file DQMSourceExample.cc
00003  * \author C.Leonidopoulos
00004  * Last Update:
00005  * $Date: 2009/12/14 22:22:23 $
00006  * $Revision: 1.26 $
00007  * $Author: wmtan $
00008  *
00009  * Description: Simple example showing how to create a DQM source creating and filling
00010  * monitoring elements
00011 */
00012 
00013 #include "DQMServices/Examples/interface/DQMSourceExample.h"
00014 #include "FWCore/ServiceRegistry/interface/Service.h"
00015 
00016 #include "TRandom.h"
00017 #include <math.h>
00018 
00019 using namespace std;
00020 using namespace edm;
00021 
00022 //==================================================================//
00023 //================= Constructor and Destructor =====================//
00024 //==================================================================//
00025 DQMSourceExample::DQMSourceExample( const edm::ParameterSet& ps ){
00026   parameters_ = ps;
00027   initialize();
00028 }
00029 
00030 DQMSourceExample::~DQMSourceExample(){
00031 }
00032 
00033 //==================================================================//
00034 //======================= Initialise ===============================//
00035 //==================================================================//
00036 void DQMSourceExample::initialize() {
00037 
00039   counterEvt_ = 0; counterLS_  = 0;
00040 
00042   dbe_ = Service<DQMStore>().operator->();
00043 
00045   monitorName_ = parameters_.getUntrackedParameter<string>("monitorName","YourSubsystemName");
00046   cout << "DQMSourceExample: Monitor name = " << monitorName_ << endl;
00047   if (monitorName_ != "" ) monitorName_ = monitorName_+"/" ;
00048   
00050   prescaleLS_  = parameters_.getUntrackedParameter<int>("prescaleLS",  -1);
00051   cout << "DQMSourceExample: DQM lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< endl;
00052   prescaleEvt_ = parameters_.getUntrackedParameter<int>("prescaleEvt", -1);
00053   cout << "DQMSourceExample: DQM event prescale = " << prescaleEvt_ << " events(s)"<< endl;
00054 
00055 // read in files (use DQMStore.collateHistograms = True for summing
00056 //  dbe_->load("ref.root");
00057 //  dbe_->load("ref.root");
00058 }
00059 
00060 //==================================================================//
00061 //========================= beginJob ===============================//
00062 //==================================================================//
00063 void DQMSourceExample::beginJob() {
00065   dbe_ = Service<DQMStore>().operator->();
00066 
00068   dbe_->setCurrentFolder(monitorName_+"DQMsource/Summary");
00069   summ = dbe_->book1D("summary", "Run Summary", 100, 0, 100); 
00070 
00071   //-------------------------------------
00072   // testing of Quality Tests 
00073   //-------------------------------------
00074 
00076    dbe_->setCurrentFolder(monitorName_+"DQMsource/QTests");
00077 
00079    NBINS = 40 ; XMIN  =  0.; XMAX  = 40.;
00080 
00084   xTrue     = dbe_->book1D("XTrue",       "X Range QTest",                  NBINS, XMIN, XMAX);
00085   xFalse    = dbe_->book1D("XFalse",      "X Range QTest",                  NBINS, XMIN, XMAX);
00086   yTrue     = dbe_->book1D("YTrue",       "Y Range QTest",                  NBINS, XMIN, XMAX);
00087   yFalse    = dbe_->book1D("YFalse",      "Y Range QTest",                  NBINS, XMIN, XMAX);
00088   wExpTrue  = dbe_->book2D("WExpTrue",    "Contents Within Expected QTest", NBINS, XMIN, XMAX, NBINS, XMIN, XMAX);
00089   wExpFalse = dbe_->book2D("WExpFalse",   "Contents Within Expected QTest", NBINS, XMIN, XMAX, NBINS, XMIN, XMAX);
00090   meanTrue  = dbe_->book1D("MeanTrue",    "Mean Within Expected QTest",     NBINS, XMIN, XMAX);
00091   meanFalse = dbe_->book1D("MeanFalse",   "Mean Within Expected QTest",     NBINS, XMIN, XMAX);
00092   deadTrue  = dbe_->book1D("DeadTrue",    "Dead Channel QTest",             NBINS, XMIN, XMAX);
00093   deadFalse = dbe_->book1D("DeadFalse",   "Dead Channel QTest",             NBINS, XMIN, XMAX);
00094   noisyTrue  = dbe_->book1D("NoisyTrue",  "Noisy Channel QTest",            NBINS, XMIN, XMAX);
00095   noisyFalse = dbe_->book1D("NoisyFalse", "Noisy Channel QTest",            NBINS, XMIN, XMAX);
00096 
00097 
00098   //-------------------------------------
00099   // book several ME more  
00100   //-------------------------------------
00101 
00103   dbe_->setCurrentFolder(monitorName_+"DQMsource/C1");
00104   const int NBINS2 = 10;
00105  
00106   i1        = dbe_->bookInt("int1");
00107   f1        = dbe_->bookFloat("float1");
00108   s1        = dbe_->bookString("s1", "My string");
00109   h1        = dbe_->book1D("h1f", "Example TH1F 1D histogram.", NBINS2, XMIN, XMAX);
00110   h2        = dbe_->book1S("h1s", "Example TH1S histogram.", NBINS, XMIN, XMAX);
00111 //  h3        = dbe_->book1DD("h1d", "Example TH1D histogram.", NBINS, XMIN, XMAX);
00112 //  h4        = dbe_->book2DD("h2d", "Example TH2D histogram.", NBINS, XMIN, XMAX,NBINS, XMIN, XMAX);
00113   p1        = dbe_->bookProfile(  "prof1", "My profile 1D", NBINS,XMIN,XMAX,NBINS,XMIN,XMAX,"");
00114   p2        = dbe_->bookProfile2D("prof2", "My profile 2D", NBINS,XMIN,XMAX,NBINS,XMIN,XMAX,NBINS,XMIN,XMAX,"");
00115   h1hist    = dbe_->book1D("history 1D","Example 1 1D history plot", 30, 0.,30.);
00116  
00117   // set labels for h1
00118   char temp[1024];
00119   for(int i = 1; i <= NBINS2; ++i) {
00120     sprintf(temp, " bin no. %d", i);
00121     h1->setBinLabel(i, temp);
00122   }
00123 
00124   // assign tag to MEs h1
00125   const unsigned int detector_id = 17;
00126   dbe_->tag(h1, detector_id);
00127 
00128   // tag full directory
00129   dbe_->tagContents(monitorName_+"DQMsource/C1", detector_id);
00130 
00131   /*
00132   // contents of h5 & h6 will be reset at end of monitoring cycle
00133   h5->setResetMe(true);
00134   h6->setResetMe(true);
00135   dbe_->showDirStructure();
00136   std::vector<std::string> tags;
00137   dbe_->getAllTags(tags);
00138   for (size_t i = 0, e = tags.size(); i < e; ++i)
00139     std::cout << "TAGS [" << i << "] = " << tags[i] << std::endl;
00140   */
00141 
00142     dbe_->showDirStructure ();
00143 }
00144 
00145 //==================================================================//
00146 //========================= beginRun ===============================//
00147 //==================================================================//
00148 void DQMSourceExample::beginRun(const edm::Run& r, const EventSetup& context) {
00149 }
00150 
00151 
00152 //==================================================================//
00153 //==================== beginLuminosityBlock ========================//
00154 //==================================================================//
00155 void DQMSourceExample::beginLuminosityBlock(const LuminosityBlock& lumiSeg,
00156                                             const EventSetup& context) {
00157 }
00158 
00159 
00160 //==================================================================//
00161 //==================== analyse (takes each event) ==================//
00162 //==================================================================//
00163 void DQMSourceExample::analyze(const Event& iEvent, const EventSetup& iSetup) {
00164   counterEvt_++;
00165   if (prescaleEvt_<1)  return;
00166   if (prescaleEvt_ > 0 && counterEvt_%prescaleEvt_!=0)  return;
00167   //  cout << " processing conterEvt_: " << counterEvt_ <<endl;
00168 
00169   // fill integer and float
00170 // number exceeding 32 bits
00171   i1->Fill(400000000000000LL); // FIXME use double
00172   f1->Fill(-3.14);
00173  
00174   //----------------------------------------
00175   // Filling the histograms with random data
00176   //----------------------------------------
00177 
00178   srand( 0 );
00179   // fill summ histo
00180   if(counterEvt_%1000 == 0) {
00181     cout << " # of events = " << counterEvt_ << endl;
00182     summ->Fill(counterEvt_/1000., counterEvt_);
00183   }
00184   // fill summ histo
00185   if(counterEvt_%100 == 0) {
00186     h1hist->ShiftFillLast(gRandom->Gaus(12,1.),1.,5);
00187   }
00188 
00189   float z  = gRandom->Uniform(XMAX);
00190   xTrue->Fill(  z, 1./log(z+1.) );
00191   xFalse->Fill( z+(XMAX/2.),  z );
00192   yTrue->Fill(  z, 1./log(z+1.) );
00193   yFalse->Fill( z, z );
00194   meanTrue->Fill(  gRandom->Gaus(10,  2), 1.);
00195   meanFalse->Fill( gRandom->Gaus(12,  3), 1.);
00196   wExpTrue->Fill(  gRandom->Gaus(12,  1), gRandom->Gaus(12, 1), 1.);
00197   wExpFalse->Fill( gRandom->Gaus(20,  2), gRandom->Gaus(20, 2), 1.);
00198   deadTrue->Fill(  gRandom->Gaus(20, 10), 2.);
00199   deadFalse->Fill( gRandom->Gaus(20,  4), 1.);
00200   h2->Fill(  gRandom->Gaus(20,  4), 1.);
00201 //  h3->Fill(  XMIN, 0xffff00000000LL);
00202 //  h4->Fill(  XMIN, XMIN, 0xffff00000000LL); 
00203   
00204   //h1hist->Print();
00205   //h1hist->Print();
00206 
00207   for ( int i = 0; i != 10; ++i ) {
00208     float w = gRandom->Uniform(XMAX);
00209     noisyTrue->Fill(  w, 1.);
00210     noisyFalse->Fill( z, 1.);
00211     float x = gRandom->Gaus(12, 1);
00212     float y = gRandom->Gaus(20, 2);
00213     p1->Fill(x, y);
00214     p2->Fill(x, y, (x+y)/2.);
00215     h1->Fill(y, 1.);
00216   }
00217 
00218   // usleep(100);
00219 
00220 }
00221 
00222 //==================================================================//
00223 //========================= endLuminosityBlock =====================//
00224 //==================================================================//
00225 void DQMSourceExample::endLuminosityBlock(const LuminosityBlock& lumiSeg,
00226                                           const EventSetup& context) {
00227 
00228 }
00229 
00230 //==================================================================//
00231 //============================= endRun =============================//
00232 //==================================================================//
00233 void DQMSourceExample::endRun(const Run& r, const EventSetup& context) {
00234 
00235 }
00236 
00237 //==================================================================//
00238 //============================= endJob =============================//
00239 //==================================================================//
00240 void DQMSourceExample::endJob() {
00241    std::cout << "DQMSourceExample::endJob()" << std::endl;
00242 }