![]() |
![]() |
00001 #include "EventFilter/RPCRawToDigi/interface/RPCRawDataCounts.h" 00002 #include "EventFilter/RPCRawToDigi/interface/DataRecord.h" 00003 00004 #include <vector> 00005 #include <iostream> 00006 #include <sstream> 00007 00008 using namespace rpcrawtodigi; 00009 using namespace std; 00010 00011 typedef std::map<int,int>::const_iterator IRE; 00012 typedef std::map<int, std::vector<int> >::const_iterator IRT; 00013 00014 void RPCRawDataCounts::addRecordType(int fed, int type, int weight) 00015 { 00016 if (theRecordTypes.find(fed) == theRecordTypes.end()) { 00017 theRecordTypes[fed]=vector<int>( 10,0); 00018 } 00019 vector<int> & v = theRecordTypes[fed]; 00020 v[type] += weight; 00021 } 00022 00023 void RPCRawDataCounts::addReadoutError(int error, int weight) 00024 { 00025 if ( theReadoutErrors.find(error) == theReadoutErrors.end() ) theReadoutErrors[error]=0; 00026 theReadoutErrors[error] += weight; 00027 } 00028 00029 void RPCRawDataCounts::operator+= (const RPCRawDataCounts & o) 00030 { 00031 for (IRE ire=o.theReadoutErrors.begin(); ire != o.theReadoutErrors.end();++ire) 00032 { 00033 addReadoutError(ire->first,ire->second); 00034 } 00035 for (IRT irt= o.theRecordTypes.begin(); irt != o.theRecordTypes.end(); ++irt) { 00036 int fed = irt->first; 00037 const vector<int> & v = irt->second; 00038 for (unsigned int itype=0; itype < v.size(); itype++) 00039 addRecordType(fed, static_cast<int>(itype), v[itype]); 00040 } 00041 } 00042 00043 std::string RPCRawDataCounts::print() const 00044 { 00045 std::ostringstream str; 00046 for (IRT irt=theRecordTypes.begin(); irt != theRecordTypes.end(); ++irt) { 00047 str << "FED: "<<irt->first<<" "; 00048 const vector<int> & v = irt->second; 00049 for (unsigned int itype=0; itype < v.size(); itype++) str <<v[itype]<<", "; 00050 str << endl; 00051 } 00052 for (IRE ire=theReadoutErrors.begin(); ire != theReadoutErrors.end();++ire) { 00053 str <<"ERROR("<<ire->first<<")="<<ire->second<<endl; 00054 } 00055 return str.str(); 00056 } 00057 00058 00059 void RPCRawDataCounts::recordTypeVector(int fedId, std::vector<double>& out) const { 00060 out.clear(); 00061 IRT irt = theRecordTypes.find(fedId); 00062 if (irt != theRecordTypes.end()) { 00063 const vector<int> & v = irt->second; 00064 for (int i=1; i<=9; ++i) { 00065 out.push_back(double(i)); 00066 out.push_back(v[i]); 00067 } 00068 } 00069 } 00070 00071 void RPCRawDataCounts::readoutErrorVector(std::vector<double>& out) const { 00072 out.clear(); 00073 for (int i=1; i<9; ++i) { 00074 IRE ire = theReadoutErrors.find(i); 00075 if(ire != theReadoutErrors.end()) { 00076 out.push_back(ire->first); 00077 out.push_back(ire->second); 00078 } 00079 } 00080 } 00081 00082 00083 TH1F * RPCRawDataCounts::recordTypeHisto(int fedId) const { 00084 std::ostringstream str; 00085 str <<"recordType_"<<fedId; 00086 TH1F * result = new TH1F(str.str().c_str(),str.str().c_str(),9, 0.5,9.5); 00087 result->SetTitleOffset(1.4,"x"); 00088 for (unsigned int i=1; i<=9; ++i) { 00089 DataRecord::recordName code = static_cast<DataRecord::recordName>(i); 00090 result->GetXaxis()->SetBinLabel(i,DataRecord::name(code).c_str()); 00091 } 00092 00093 IRT irt = theRecordTypes.find(fedId); 00094 if (irt != theRecordTypes.end()) { 00095 const vector<int> & v = irt->second; 00096 for (int i=1; i<=9; ++i) result->Fill(float(i),v[i]); 00097 } 00098 return result; 00099 } 00100 00101 TH1F * RPCRawDataCounts::readoutErrorHisto() const { 00102 std::ostringstream str; 00103 str <<"readoutErrors"; 00104 TH1F * result = new TH1F(str.str().c_str(),str.str().c_str(),8, 0.5,8.5); 00105 for (unsigned int i=1; i<=8; ++i) { 00106 RPCRawDataCounts::ReadoutError code = static_cast<RPCRawDataCounts::ReadoutError>(i); 00107 result->GetXaxis()->SetBinLabel(i,readoutErrorName(code).c_str()); 00108 } 00109 for (int i=1; i<9; ++i) { 00110 IRE ire = theReadoutErrors.find(i); 00111 if(ire != theReadoutErrors.end()) result->Fill(ire->first,ire->second); 00112 } 00113 return result; 00114 } 00115 00116 std::string RPCRawDataCounts:: readoutErrorName(const ReadoutError & code) 00117 { 00118 std::string result; 00119 switch (code) { 00120 case (HeaderCheckFail) : { result = "HeaderCheckFail"; break; } 00121 case (InconsitentFedId) : { result = "InconsitentFedId"; break; } 00122 case (TrailerCheckFail) : { result = "TrailerCheckFail"; break; } 00123 case (InconsistentDataSize) : { result = "InconsistentDataSize"; break; } 00124 case (InvalidLB) : { result = "InvalidLB"; break; } 00125 case (EmptyPackedStrips) : { result = "EmptyPackedStrips"; break; } 00126 case (InvalidDetId) : { result = "InvalidDetId"; break; } 00127 case (InvalidStrip) : { result = "InvalidStrip"; break; } 00128 default : { result = "NoProblem"; } 00129 } 00130 return result; 00131 }