CMS 3D CMS Logo

RPCMultiplicityTest.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2008/04/25 16:45:54 $
00005  *  $Revision: 1.1 $
00006  *  \author Anna Cimmino
00007  */
00008 
00009 
00010 #include <DQM/RPCMonitorClient/interface/RPCMultiplicityTest.h>
00011 
00012 // Framework
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 
00015 //DQM Services
00016 #include "DQMServices/Core/interface/DQMStore.h"
00017 
00018 //DataFormats
00019 #include <DataFormats/MuonDetId/interface/RPCDetId.h>
00020 #include "DataFormats/RPCDigi/interface/RPCDigi.h"
00021 #include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
00022 
00023 // Geometry
00024 #include "Geometry/RPCGeometry/interface/RPCGeomServ.h"
00025 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00026 
00027 #include <iostream>
00028 #include <stdio.h>
00029 #include <string>
00030 #include <sstream>
00031 #include <math.h>
00032 #include <fstream>
00033 #include <time.h>
00034 
00035 using namespace edm;
00036 using namespace std;
00037 
00038 RPCMultiplicityTest ::RPCMultiplicityTest (const ParameterSet& ps ){
00039  
00040   edm::LogVerbatim ("deadChannel") << "[RPCMultiplicityTest ]: Constructor";
00041 
00042   parameters = ps;
00043   //  getQualityTestsFromFile = parameters.getUntrackedParameter<bool> ("getQualityTestsFromFile",false);
00044   // prescaleFactor = parameters.getUntrackedParameter<int>("diagnosticPrescale", 1);
00045   referenceOldChannels = parameters.getUntrackedParameter<bool> ("getReferenceFile_MultiplicityInRange",false);
00046 }
00047 
00048 
00049 RPCMultiplicityTest ::~RPCMultiplicityTest (){
00050 
00051   delete dbe_;
00052 }
00053 
00054 //called only once
00055 void RPCMultiplicityTest ::beginJob(DQMStore * dbe){
00056 
00057    edm::LogVerbatim ("deadChannel") << "[RPCMultiplicityTest ]: Begin job";
00058   
00059  // get hold of back-end interface
00060  dbe_=dbe;
00061 
00062 }
00063 
00064 
00065   //Begin Run
00066 void RPCMultiplicityTest ::beginRun(const Run& r, const EventSetup& c){
00067   
00068 //get local date and time
00069  time_t t = time(0);
00070  strftime( dateTime, sizeof(dateTime), "Digi_%Y_%m_%d_%H_%M_%S.txt", localtime(&t));
00071  
00072  //open txt output file
00073  myfile.open(dateTime, ios::app);
00074  myfile<<"RUN LUMIBLOCK CHAMBER #MEANDIGI TAG RefRUN\n";
00075  
00076  //get reference file
00077  if (referenceOldChannels)
00078    referenceFile_.open(parameters.getUntrackedParameter<string> ("referenceFileName_MultiplicityInRange","reference.txt").c_str()); 
00079 
00080 }
00081   
00082 
00083 
00084 void RPCMultiplicityTest ::beginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00085 
00086   edm::LogVerbatim ("numberofdigis") <<"[RPCMultiplicityTest ]: Begin of LS transition";
00087 
00088   // Get the run number & luminosity block
00089   run = lumiSeg.run();
00090   lumiBlock=lumiSeg.luminosityBlock();
00091 }
00092 
00093 
00094 //called at each event
00095 void RPCMultiplicityTest ::analyze(const edm::Event& iEvent, const edm::EventSetup& c){
00096   // nevents++;
00097   // edm::LogVerbatim ("numberofdigis") << "[RPCMultiplicityTest ]: "<<nevents<<" events";
00098 
00100   edm::Handle<RPCDigiCollection> rpcdigis;
00101   iEvent.getByType(rpcdigis);
00102 
00103   //get new Histos
00104   //loop on digi collection 
00105   for( RPCDigiCollection::DigiRangeIterator collectionItr=rpcdigis->begin(); 
00106        collectionItr!=rpcdigis->end(); ++collectionItr){
00107     RPCDetId detId=(*collectionItr ).first; 
00108     std::map<RPCDetId ,MonitorElement*>::iterator meItr = meCollection.find(detId);
00109     if (meItr == meCollection.end() || (meCollection.size()==0)) {
00110       
00111       meCollection[detId] = getMEs(detId);
00112     }
00113   }// end loop on digi collection
00114 }      
00115 
00116 
00117 
00118 void RPCMultiplicityTest ::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00119  
00120   
00121   edm::LogVerbatim ("numberofdigis") <<"[RPCMultiplicityTest ]: End of LS transition, performing the DQM client operation";
00122   
00123   // counts number of lumiSegs 
00124   nLumiSegs = lumiSeg.id().luminosityBlock();
00125  
00126  /* 
00127   //check some statements and prescale Factor
00128   if( !getQualityTestsFromFile ||  nLumiSegs%prescaleFactor != 0 ) return;
00129    */
00130 
00131   // Quality test - the test was already performed and attached to the ME. Here we only retreive the results
00132   string TestName = "MultiplicityInRange";
00133   int deadchannel;
00134   string line,referenceRun,referenceLumiBlock,referenceRoll,referenceStrip, referenceTag, lastreferenceRun,nameRoll;
00135   //Loop over Histos
00136   for(std::map<RPCDetId, MonitorElement*>::const_iterator hOccIt = meCollection.begin();
00137       hOccIt != meCollection.end();
00138       hOccIt++) {
00139     if((*hOccIt).second->getEntries() > (prescaleFactor-1 )){
00140       const QReport * theOccupancyQReport = (*hOccIt).second->getQReport(TestName );
00141       if(theOccupancyQReport) {
00142         //      vector<dqm::me_util::Channel> badChannels = theOccupancyQReport->getBadChannels();
00143         //loop on bad channels
00144         //      for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); 
00145         //   channel != badChannels.end(); channel++) {
00146           //get roll name
00147           RPCGeomServ RPCname((*hOccIt).first);
00148           nameRoll = RPCname.name();
00149           
00150           //edm::LogError ("numberofdigis") << "Chamber : "<<nameRoll<<" Bad occupancy channel: "<<(*channel).getBin()<<" Contents : "<<(*channel).getContents();
00151           if(myfile.is_open())
00152             {
00153 
00154               //  deadchannel = (* channel).getBin();
00155 
00156               if(referenceOldChannels && referenceFile_.is_open()){
00157                 int i=1; // line zero has titles -> start from line 1
00158                 bool flag= false;
00159                 //read reference file and find already known dead channels  
00160                 referenceFile_.clear();// clear all status flags
00161                 referenceFile_.seekg(0);//start reading file from the begining
00162                 while (!referenceFile_.eof()&& !flag  )
00163                   {
00164                     referenceFile_>>referenceRun;
00165                     referenceFile_>>referenceLumiBlock;
00166                     referenceFile_>>referenceRoll;
00167                     referenceFile_>>referenceTag;
00168                     referenceFile_>>lastreferenceRun;
00169                     int p= atoi(referenceStrip.c_str());
00170                     if (referenceRoll == nameRoll)flag = true;
00171                     i++;
00172                   }
00173                 if (flag){
00174                   myfile<<run<<" "<<lumiBlock<<" "<<nameRoll<<" "<<(*hOccIt).second->getMean()<<" OLD-Reference Run:" + referenceRun +"\n";
00175                 }
00176                 else{ 
00177                   myfile<<run<<" "<<lumiBlock<<" "<<nameRoll<<" "<<(*hOccIt).second->getMean()<<" NEW-Reference Run:" + referenceRun +"\n";
00178                 }
00179               }else {
00180 
00181                 myfile<<run<<" "<<lumiBlock<<" "<<nameRoll<<" "<<(*hOccIt).second->getMean()<<" No Info\n";
00182               }
00183               
00184             }
00185           //    }//end loop on bad channels
00186         edm::LogWarning("numberofdigis")<< "-------- Chamber : "<< nameRoll<<"  "<<theOccupancyQReport->getMessage()<<" ------- "<<theOccupancyQReport->getStatus(); 
00187       }
00188       else 
00189         edm::LogVerbatim ("numberofdigis") << "[RPCMultiplicityTest ]: QReport for QTest "<<TestName <<" is empty";
00190       
00191     }
00192   }//end loop over Histos
00193 }
00194 
00195 
00196 
00197 //End Run
00198 void RPCMultiplicityTest ::endRun(const Run& r, const EventSetup& c){
00199   
00200  myfile.close();
00201 }
00202 
00203 
00204 void RPCMultiplicityTest ::endJob(){
00205   
00206   /*  edm::LogVerbatim ("numberofdigis") << "[RPCMultiplicityTest ]: endjob called!";
00207   if ( parameters.getUntrackedParameter<bool>("writeHisto", true) ) {
00208     stringstream runNumber; runNumber << run;
00209     string rootFile = "RPCMultiplicityTest _" + runNumber.str() + ".root";
00210     dbe_->save(parameters.getUntrackedParameter<string>("outputFile", rootFile));
00211     }*/
00212 
00213   //close txt file
00214   //  myfile.close();
00215 
00216   // dbe_->rmdir("RPC/Tests/RPCDeadChannel");  
00217 }
00218 
00219 
00220 // find ME name using RPC geometry
00221 MonitorElement* RPCMultiplicityTest::getMEs(RPCDetId & detId) {
00222   
00223   MonitorElement* me;
00224   
00225   std::string regionName;
00226   std::string ringType;
00227   if(detId.region() ==  0) {
00228     regionName="Barrel";
00229     ringType="Wheel";
00230   }else{
00231     ringType="Disk";
00232     if(detId.region() == -1) regionName="Encap-";
00233     if(detId.region() ==  1) regionName="Encap+";
00234   }
00235   
00236      
00237   RPCGeomServ RPCname(detId);
00238   char meId [328];
00239    
00241    sprintf(meId,"RPC/RecHits/%s/%s_%d/station_%d/sector_%d/NumberOfDigi_%s",regionName.c_str(),ringType.c_str(),
00242           detId.ring(),detId.station(),detId.sector(),RPCname.name().c_str());
00243 
00244      me = dbe_->get(meId);
00245    return me;
00246  }
00247 

Generated on Tue Jun 9 17:33:17 2009 for CMSSW by  doxygen 1.5.4