CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/DTMonitorModule/src/DTTimeEvolutionHisto.cc

Go to the documentation of this file.
00001 
00002 /*
00003  *  See header file for a description of this class.
00004  *
00005  *  $Date: 2010/01/24 14:35:23 $
00006  *  $Revision: 1.5 $
00007  *  \author G. Cerminara - INFN Torino
00008  */
00009 
00010 #include "DQM/DTMonitorModule/interface/DTTimeEvolutionHisto.h"
00011 
00012 #include "DQMServices/Core/interface/DQMStore.h"
00013 #include "DQMServices/Core/interface/MonitorElement.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 
00016 using namespace std;
00017 using namespace edm;
00018 
00019 
00020 DTTimeEvolutionHisto::DTTimeEvolutionHisto(DQMStore *dbe, const string& name,
00021                                            const string& title,
00022                                            int nbins,
00023                                            int lsPrescale,
00024                                            bool sliding,
00025                                            int mode) : valueLastTimeSlot(0),
00026                                                        nEventsInLastTimeSlot(0),
00027                                                        theFirstLS(1),
00028                                                        theLSPrescale(lsPrescale),
00029                                                        doSlide(sliding),
00030                                                        nLSinTimeSlot(0),
00031                                                        firstLSinTimeSlot(0),
00032                                                        theMode(mode) {
00033   
00034   DTTimeEvolutionHisto(dbe, name, title, nbins, theFirstLS, lsPrescale, sliding, mode);
00035   histo = dbe->get(dbe->pwd() + "/" + name);
00036   nBookedBins = histo->getNbinsX();
00037 }
00038 
00039 
00040 // DTTimeEvolutionHisto::DTTimeEvolutionHisto(DQMStore *dbe, const string& name,
00041 //                                         const string& title,
00042 //                                         int nbins,
00043 //                                         int lsPrescale,
00044 //                                         bool sliding,
00045 //                                         int mode) : valueLastTimeSlot(0),
00046 //                                                     nEventsInLastTimeSlot(0),
00047 //                                                     theLSPrescale(lsPrescale),
00048 //                                                     doSlide(sliding),
00049 //                                                     nLSinTimeSlot(0),
00050 //                                                     firstLSinTimeSlot(0),
00051 //                                                     theMode(mode) {
00052 //   // set the number of bins to be booked
00053 //   nBookedBins = nbins;
00054 //   if(sliding) nBookedBins++;
00055 //   if(!sliding && theMode == 0)
00056 //     LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00057 //       << "[DTTimeEvolutionHisto]***Error: wrong configuration" << endl;
00058 
00059 
00060 //   stringstream realTitle; realTitle << title << "/" <<  theLSPrescale << " LS";
00061 
00062 //   // book the ME
00063 //   histo = dbe->book1D(name, realTitle.str(), nBookedBins, 1., nBookedBins+1.);
00064 
00065 //   // set the axis label
00066 //   if(sliding) {
00067 //     histo->setBinLabel(1,"avg. previous",1);
00068 //   } else {
00069 //     // loop over bins and 
00070 //     for(int bin =1; bin != nBookedBins+1; ++bin) {    
00071 //       stringstream label;
00072 //       if(theLSPrescale > 1) {
00073 //      label << "LS " << ((bin-1)*theLSPrescale)+1 << "-" << bin*theLSPrescale;
00074 //       } else {
00075 //      label << "LS " << ((bin-1)*theLSPrescale)+1;
00076 //       }
00077 //       histo->setBinLabel(bin, label.str(),1);
00078 
00079 //     }
00080 
00081 //   }
00082 
00083 // }
00084 
00085 
00086 
00087 
00088 DTTimeEvolutionHisto::DTTimeEvolutionHisto(DQMStore *dbe, const string& name,
00089                                            const string& title,
00090                                            int nbins,
00091                                            int firstLS,
00092                                            int lsPrescale,
00093                                            bool sliding,
00094                                            int mode) : valueLastTimeSlot(0),
00095                                                        nEventsInLastTimeSlot(0),
00096                                                        theFirstLS(firstLS),
00097                                                        theLSPrescale(lsPrescale),
00098                                                        doSlide(sliding),
00099                                                        nLSinTimeSlot(0),
00100                                                        firstLSinTimeSlot(0),
00101                                                        theMode(mode) {
00102   // set the number of bins to be booked
00103   nBookedBins = nbins;
00104   if(sliding) nBookedBins++;
00105   if(!sliding && theMode == 0)
00106     LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00107       << "[DTTimeEvolutionHisto]***Error: wrong configuration" << endl;
00108 
00109 
00110   stringstream realTitle; realTitle << title << "/" <<  theLSPrescale << " LS";
00111 
00112   // book the ME
00113   histo = dbe->book1D(name, realTitle.str(), nBookedBins, (float)theFirstLS, nBookedBins+1.);
00114 
00115   // set the axis label
00116   if(sliding) {
00117     histo->setBinLabel(1,"avg. previous",1);
00118   } else {
00119     // loop over bins and 
00120     for(int bin =1; bin != nBookedBins+1; ++bin) {    
00121       stringstream label;
00122       if(theLSPrescale > 1) {
00123         label << "LS " << ((bin-1)*theLSPrescale)+theFirstLS << "-" << bin*theLSPrescale+theFirstLS;
00124       } else {
00125         label << "LS " << ((bin-1)*theLSPrescale)+theFirstLS;
00126       }
00127       histo->setBinLabel(bin, label.str(),1);
00128 
00129     }
00130 
00131   }
00132 
00133 }
00134 
00135 
00136 
00137 DTTimeEvolutionHisto::DTTimeEvolutionHisto(DQMStore *dbe, const string& name) : valueLastTimeSlot(0),
00138                                                                                 nEventsInLastTimeSlot(0),
00139                                                                                 theFirstLS(1),
00140                                                                                 theLSPrescale(-1),
00141                                                                                 doSlide(false),
00142                                                                                 nLSinTimeSlot(0),
00143                                                                                 firstLSinTimeSlot(0),
00144                                                                                 theMode(0) { // FIXME: set other memebers to sensible values
00145   LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00146     << "[DTTimeEvolutionHisto] Retrieve ME with name: " << name << endl;
00147   histo = dbe->get(name);
00148 }
00149 
00150 
00151 DTTimeEvolutionHisto::~DTTimeEvolutionHisto(){}
00152 
00153 
00154 
00155 void DTTimeEvolutionHisto::setTimeSlotValue(float value, int timeSlot) {
00156   //   LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00157   //   << "[DTTimeEvolutionHisto] ME name: " <<  histo->getName() << endl;
00158   if(!doSlide) {
00159     //     LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00160     //     << "        fill bin: " << timeSlot << " with value: " << value << endl;
00161     histo->Fill(timeSlot,value);
00162   } else {
00163     for(int bin = 1; bin != nBookedBins; ++bin) {
00164       float value = histo->getBinContent(bin);
00165       //       LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00166       //  << "        bin: " << bin << " has value: " << value << endl;
00167       if(bin == 1) { // average of previous time slots (fixme)
00168         histo->setBinContent(bin, (value + histo->getBinContent(bin+1))/2.);
00169       } else if(bin != nBookedBins) {
00170         histo->setBinContent(bin, histo->getBinContent(bin+1));
00171         histo->setBinError(bin, histo->getBinError(bin+1));
00172         histo->setBinLabel(bin, histo->getTH1F()->GetXaxis()->GetBinLabel(bin+1),1);
00173       }
00174     }
00175     histo->setBinContent(nBookedBins, value);
00176   }
00177 }
00178 
00179 
00180 void DTTimeEvolutionHisto::accumulateValueTimeSlot(float value) {
00181   valueLastTimeSlot += value;
00182 }
00183 
00184 
00185 
00186 void DTTimeEvolutionHisto::updateTimeSlot(int ls, int nEventsInLS) {
00187   
00188   if(doSlide) { // sliding bins
00189     // count LS in this time-slot
00190     nLSinTimeSlot++;
00191     nEventsInLastTimeSlot += nEventsInLS;
00192     
00193     if(nLSinTimeSlot == 1) firstLSinTimeSlot = ls;
00194 
00195     if(nLSinTimeSlot%theLSPrescale ==0) { // update the value of the slot and reset the counters
00196       LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00197         << "[DTTimeEvolutionHisto] Update time-slot, # entries: " << valueLastTimeSlot 
00198         << " # events: " << nEventsInLastTimeSlot << endl;
00199       // set the bin content
00200       float value = 0;
00201       if(theMode == 0) {
00202         if(nEventsInLastTimeSlot != 0) value = valueLastTimeSlot/(float)nEventsInLastTimeSlot;
00203       } else if(theMode == 1) {
00204         value = valueLastTimeSlot;
00205       } else if(theMode == 2) {
00206         value = nEventsInLastTimeSlot;
00207       } else if(theMode == 3) {
00208         value = valueLastTimeSlot/theLSPrescale;
00209       }
00210       setTimeSlotValue(value, nBookedBins);
00211       LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00212         << "       updated value: " << histo->getBinContent(nBookedBins) << endl;
00213 
00214       // set the bin label
00215       stringstream binLabel; binLabel << "LS " << firstLSinTimeSlot;
00216       if(nLSinTimeSlot > 1) binLabel << "-" << ls;
00217       histo->setBinLabel(nBookedBins,binLabel.str(),1);
00218 
00219       // reset the counters for the time slot
00220       nLSinTimeSlot = 0; 
00221       nEventsInLastTimeSlot = 0;
00222       valueLastTimeSlot = 0;
00223     }
00224 
00225 
00226   } else {
00227     int binN = (int)ls-(theFirstLS-1)/(int)theLSPrescale;
00228     // set the bin content
00229     float value = 0;
00230     if(theMode == 1) {
00231       value = valueLastTimeSlot;
00232     } else if(theMode == 2) {
00233       value = nEventsInLS;
00234     } else if(theMode == 3) {
00235       value = valueLastTimeSlot/theLSPrescale;
00236     }
00237     LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00238       << "[DTTimeEvolutionHisto] Update time-slot: "<< binN << " with value: " << value << endl;
00239     setTimeSlotValue(value,binN);
00240   }
00241 }
00242 
00243 
00244 
00245 
00246 void DTTimeEvolutionHisto::normalizeTo(const MonitorElement *histForNorm) {
00247   if(histo == 0) {
00248     LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00249       << "[DTTimeEvolutionHisto]***Error: pointer to ME is NULL" << endl;
00250     return;
00251   }
00252   int nBins = histo->getNbinsX();
00253   if(histForNorm->getNbinsX() != nBins) {
00254     LogWarning("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00255       << "[DTTimeEvolutionHisto]***Error: normalizing histos with != # of bins" << endl;
00256     return;
00257   }
00258   for(int bin = 1; bin <= nBins; ++bin) { // loop over bins
00259     if(histForNorm->getBinContent(bin) != 0) {
00260       double normValue = histo->getBinContent(bin)/histForNorm->getBinContent(bin);
00261       LogVerbatim("DTDQM|DTMonitorModule|DTMonitorClient|DTTimeEvolutionHisto")
00262         << "[DTTimeEvolutionHisto] Normalizing bin: " << bin << " to: " <<  histo->getBinContent(bin) << " / " << histForNorm->getBinContent(bin)
00263         << " = " << normValue << endl;
00264       histo->setBinContent(bin, normValue);
00265     } else {
00266       histo->setBinContent(bin, 0);
00267     }
00268   }
00269 }