CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/DQM/RPCMonitorClient/src/RPCBxTest.cc

Go to the documentation of this file.
00001 #include <DQM/RPCMonitorClient/interface/RPCBxTest.h>
00002 #include "DQM/RPCMonitorDigi/interface/utils.h"
00003 
00004 // Framework
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 
00007 // //Geometry
00008 #include "Geometry/RPCGeometry/interface/RPCGeomServ.h"
00009 # include "TH1F.h"
00010 
00011 
00012 
00013 RPCBxTest::RPCBxTest(const edm::ParameterSet& ps ){
00014   edm::LogVerbatim ("rpcbxtest") << "[RPCBxTest]: Constructor";
00015   
00016   prescaleFactor_ =  ps.getUntrackedParameter<int>("DiagnosticPrescale", 1);
00017   
00018   //Nome della dir per gli istogrammi nuovi . Cominciare sempre con RPC/RecHits/
00019   globalFolder_ = ps.getUntrackedParameter<std::string>("RPCGlobalFolder", "RPC/RecHits/SummaryHistograms/");
00020   
00021   entriesCut_ = ps.getUntrackedParameter<int>("EntriesCut");
00022   rmsCut_ = ps.getUntrackedParameter<double>("RMSCut");
00023   distanceMean_ = ps.getUntrackedParameter<double>("DistanceFromZeroBx");
00024 
00025   numberOfDisks_ = ps.getUntrackedParameter<int>("NumberOfEndcapDisks", 3);
00026   numberOfRings_ = ps.getUntrackedParameter<int>("NumberOfEndcapRings", 2);
00027 }
00028 
00029 RPCBxTest::~RPCBxTest(){ dbe_=0;}
00030 
00031 void RPCBxTest::beginJob(DQMStore *  dbe){
00032   edm::LogVerbatim ("rpcbxtest") << "[RPCBxTest]: Begin job ";
00033   dbe_ = dbe;
00034 }
00035 
00036 //Qui puoi definitre gli istogrammi nuovi che vuoi riempire
00037 void RPCBxTest::beginRun(const edm::Run& r, const edm::EventSetup& c, std::vector<MonitorElement *> meVector, std::vector<RPCDetId> detIdVector){
00038   edm::LogVerbatim ("rpcbxtest") << "[RPCBxTest]: Begin run";
00039   
00040   MonitorElement* me;
00041   dbe_->setCurrentFolder(globalFolder_);
00042 
00043   std::stringstream histoName;
00044 
00045   histoName.str("");
00046   histoName<<"BX_Mean_Distribution_Barrel";  
00047   BXMeanBarrel = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 11, -5.5, 5.5);
00048   BXMeanBarrel->setAxisTitle("Bx",1);
00049 
00050   histoName.str("");
00051   histoName<<"BX_Mean_Distribution_EndcapP";  
00052   BXMeanEndcapP = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 11, -5.5, 5.5);
00053 
00054   histoName.str("");
00055   histoName<<"BX_Mean_Distribution_EndcapN";  
00056   BXMeanEndcapN = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 11, -5.5, 5.5);
00057 
00058 
00059   histoName.str("");
00060   histoName<<"BX_Entries_Distribution_Barrel";  
00061   BXEntriesBarrel = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 1000, -0.5, 999.5);
00062 
00063   histoName.str("");
00064   histoName<<"BX_Entries_Distribution_EndcapP";  
00065   BXEntriesEndcapP = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(),1000, -0.5, 999.5); 
00066 
00067   histoName.str("");
00068   histoName<<"BX_Entries_Distribution_EndcapN";  
00069   BXEntriesEndcapN = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 1000, -0.5, 999.5);
00070 
00071 
00072   histoName.str("");
00073   histoName<<"BX_RMS_Distribution_Barrel"; 
00074   BXRmsBarrel = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 21, -0.1, 4.1);
00075 
00076   histoName.str("");
00077   histoName<<"BX_RMS_Distribution_EndcapP"; 
00078   BXRmsEndcapP = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 21, -0.1, 4.1);
00079 
00080   histoName.str("");
00081   histoName<<"BX_RMS_Distribution_EndcapN"; 
00082   BXRmsEndcapN = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 21, -0.1, 4.1);
00083 
00084   rpcdqm::utils rpcUtils;
00085 
00086   int limit = numberOfDisks_;
00087   if(numberOfDisks_ < 2) limit = 2;
00088   
00089   for (int w = -1 * limit; w<=limit;w++ ){//loop on wheels and disks
00090     if (w>-3 && w<3){//wheels
00091       histoName.str("");
00092       histoName<<"BX_Mean_Distribution_Wheel"<<w;     
00093       me = 0;
00094       me = dbe_->get(globalFolder_ + histoName.str()) ;
00095       if ( 0!=me ) {
00096         dbe_->removeElement(me->getName());
00097       }
00098       BXMeanWheel[w+2] = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 10, -0.5, 9.5);
00099   
00100       histoName.str("");
00101       histoName<<"BX_RMS_Distribution_Wheel"<<w;     
00102       me = 0;
00103       me = dbe_->get(globalFolder_ + histoName.str()) ;
00104       if ( 0!=me){
00105         dbe_->removeElement(me->getName());
00106       }
00107       BXRmsWheel[w+2] = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 50, -0.5, 4.5);
00108     }//end loop on wheels
00109 
00110     if (w == 0 || w< (-1 * numberOfDisks_) || w > numberOfDisks_)continue;
00111     //Endcap
00112     int offset = numberOfDisks_;
00113     if (w>0) offset --; //used to skip case equale to zero
00114       
00115     histoName.str("");
00116     histoName<<"BX_Mean_Distribution_Disk"<<w;     
00117     me = 0;
00118     me = dbe_->get(globalFolder_ + histoName.str()) ;
00119     if ( 0!=me){
00120       dbe_->removeElement(me->getName());
00121     }
00122     BXMeanDisk[w+offset] = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(),10, -0.5, 9.5);
00123     
00124    
00125     histoName.str("");
00126     histoName<<"BX_RMS_Distribution_Disk"<<w;    
00127     me = 0;
00128     me = dbe_->get(globalFolder_ + histoName.str()) ;
00129     if ( 0!=me){
00130       dbe_->removeElement(me->getName());
00131     }
00132     BXRmsDisk[w+offset] = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 50, -0.5, 4.5);
00133  }
00134 
00135 
00136   //Qui prende gli isto del BX per roll definiti nel client
00137   //crea due vettore ordinati myBXMe_(istogrammi) e myDetIds_(rpcDetId)
00138  //Get  ME for each roll
00139  for (unsigned int i = 0 ; i<meVector.size(); i++){
00140 
00141    bool flag= false;
00142    
00143    DQMNet::TagList tagList;
00144    tagList = meVector[i]->getTags();
00145    DQMNet::TagList::iterator tagItr = tagList.begin();
00146 
00147    while (tagItr != tagList.end() && !flag ) {
00148      if((*tagItr) ==  rpcdqm::OCCUPANCY)
00149        flag= true;
00150      tagItr++;
00151    }
00152    
00153    if(flag){
00154      myBXMe_.push_back(meVector[i]);
00155      myDetIds_.push_back(detIdVector[i]);
00156    }
00157  }
00158 
00159 }
00160 
00161 void RPCBxTest::beginLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& context){
00162 } 
00163 
00164 void RPCBxTest::analyze(const edm::Event& iEvent, const edm::EventSetup& c) {}
00165 
00166 void RPCBxTest::endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& iSetup) { }
00167 
00168 void  RPCBxTest::endJob(void) {
00169   edm::LogVerbatim ("rpcbxtest") << "[RPCBxTest]: end job ";
00170 
00171 }
00172 
00173 
00174 //ME = monitor Element
00175 
00176 
00177 //Link a public getters
00178 // http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/DQMServices/Core/interface/MonitorElement.h?revision=1.39&view=markup
00179 
00180 //Link per ROOT
00181 //http://root.cern.ch/root/html522/TH1.html
00182 
00183 //Loop sul vettore degli istogrammi (myBXMe_) e prendi le info
00184 void  RPCBxTest::endRun(const edm::Run& r, const edm::EventSetup& c) {
00185 
00186   MonitorElement * myMe;
00187   RPCDetId detId;
00188   TH1F * myTH1F;
00189 
00190   MonitorElement * ENTRIES =NULL; 
00191   MonitorElement * MEAN =NULL;  
00192   MonitorElement * MEANRing =NULL;  
00193   MonitorElement * RMS =NULL; 
00194   MonitorElement * RMSRing =NULL;  
00195 
00196   for (unsigned int  i = 0 ; i<myBXMe_.size();i++){
00197 
00198     myMe = myBXMe_[i];
00199     detId = myDetIds_[i];
00200 
00201     //Prendi TH1F corrispondente al Monitor Element
00202     myTH1F = myMe->getTH1F();
00203    //  //Spegni Overflow
00204 //     myTH1F->StatOverflows(false); // per accendere overflow mettere true
00205 //     //Ricalcola la media e l'RMS  //commentare le 3 righe seguenti. Ricorda di ricompilare
00206 //     myTH1F->GetXaxis()->SetRangeUser(-9.5,9.5);
00207 //     Double_t stat[4];
00208 //     myTH1F->GetStats(stat);
00209 
00210 
00211     float mean = myTH1F->GetMean();
00212     float rms = myTH1F->GetRMS();
00213     float entries = myTH1F->GetEntries();
00214 
00215     //Get Occupancy ME for roll
00216     RPCGeomServ RPCname(detId);
00217     //  if(rms==0) cout<<RPCname.name()<<endl;
00218 
00219     if(detId.region()== 0){
00220       ENTRIES =  BXEntriesBarrel;
00221       MEAN = BXMeanBarrel; //nome istogramma definito in beginRun
00222       MEANRing = BXMeanWheel[detId.ring()+2];
00223       RMS = BXRmsBarrel;
00224       RMSRing = BXRmsWheel[detId.ring()+2];
00225     }else if(detId.region()==1){
00226       ENTRIES =  BXEntriesEndcapP;
00227       MEAN = BXMeanEndcapP;
00228       MEANRing = BXMeanDisk[detId.station()+2];
00229       RMS = BXRmsEndcapP;
00230       RMSRing = BXRmsDisk[detId.station()+2];
00231     }else if(detId.region()==-1){
00232       ENTRIES =  BXEntriesEndcapN;
00233       MEAN = BXMeanEndcapN;
00234       MEANRing = BXMeanDisk[3-detId.station()];
00235       RMS = BXRmsEndcapN;
00236       RMSRing = BXRmsDisk[3-detId.station()];
00237     }
00238 
00239     ENTRIES->Fill(entries);
00240 
00241     if(entries  >= entriesCut_){
00242       RMSRing->Fill(rms);
00243       RMS->Fill(rms);
00244       
00245       if(rms <= rmsCut_){
00246 
00247         //if(mean> distanceMean_ || mean<-distanceMean_ )  cout<<RPCname.name()<<endl;
00248 
00249         MEAN->Fill(mean);
00250         MEANRing->Fill(mean);
00251       }
00252     }
00253     
00254   }
00255 }