00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <DQM/RPCMonitorClient/interface/RPCMultiplicityTest.h>
00011
00012
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014
00015
00016 #include "DQMServices/Core/interface/DQMStore.h"
00017
00018
00019 #include <DataFormats/MuonDetId/interface/RPCDetId.h>
00020 #include "DataFormats/RPCDigi/interface/RPCDigi.h"
00021 #include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
00022
00023
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
00044
00045 referenceOldChannels = parameters.getUntrackedParameter<bool> ("getReferenceFile_MultiplicityInRange",false);
00046 }
00047
00048
00049 RPCMultiplicityTest ::~RPCMultiplicityTest (){
00050
00051 delete dbe_;
00052 }
00053
00054
00055 void RPCMultiplicityTest ::beginJob(DQMStore * dbe){
00056
00057 edm::LogVerbatim ("deadChannel") << "[RPCMultiplicityTest ]: Begin job";
00058
00059
00060 dbe_=dbe;
00061
00062 }
00063
00064
00065
00066 void RPCMultiplicityTest ::beginRun(const Run& r, const EventSetup& c){
00067
00068
00069 time_t t = time(0);
00070 strftime( dateTime, sizeof(dateTime), "Digi_%Y_%m_%d_%H_%M_%S.txt", localtime(&t));
00071
00072
00073 myfile.open(dateTime, ios::app);
00074 myfile<<"RUN LUMIBLOCK CHAMBER #MEANDIGI TAG RefRUN\n";
00075
00076
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
00089 run = lumiSeg.run();
00090 lumiBlock=lumiSeg.luminosityBlock();
00091 }
00092
00093
00094
00095 void RPCMultiplicityTest ::analyze(const edm::Event& iEvent, const edm::EventSetup& c){
00096
00097
00098
00100 edm::Handle<RPCDigiCollection> rpcdigis;
00101 iEvent.getByType(rpcdigis);
00102
00103
00104
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 }
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
00124 nLumiSegs = lumiSeg.id().luminosityBlock();
00125
00126
00127
00128
00129
00130
00131
00132 string TestName = "MultiplicityInRange";
00133 int deadchannel;
00134 string line,referenceRun,referenceLumiBlock,referenceRoll,referenceStrip, referenceTag, lastreferenceRun,nameRoll;
00135
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
00143
00144
00145
00146
00147 RPCGeomServ RPCname((*hOccIt).first);
00148 nameRoll = RPCname.name();
00149
00150
00151 if(myfile.is_open())
00152 {
00153
00154
00155
00156 if(referenceOldChannels && referenceFile_.is_open()){
00157 int i=1;
00158 bool flag= false;
00159
00160 referenceFile_.clear();
00161 referenceFile_.seekg(0);
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
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 }
00193 }
00194
00195
00196
00197
00198 void RPCMultiplicityTest ::endRun(const Run& r, const EventSetup& c){
00199
00200 myfile.close();
00201 }
00202
00203
00204 void RPCMultiplicityTest ::endJob(){
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 }
00218
00219
00220
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