00001 #include "CondFormats/EcalObjects/interface/EcalTPGTowerStatus.h" 00002 //#include "CondTools/Ecal/interface/EcalTPGFineGrainEBMapXMLTranslator.h" 00003 #include "CondTools/Ecal/interface/EcalCondHeader.h" 00004 #include "TROOT.h" 00005 #include "TH2F.h" 00006 #include "TCanvas.h" 00007 #include "TStyle.h" 00008 #include "TColor.h" 00009 #include "TLine.h" 00010 #include "DataFormats/EcalDetId/interface/EBDetId.h" 00011 #include "DataFormats/EcalDetId/interface/EEDetId.h" 00012 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h" 00013 00014 #include "CondCore/Utilities/interface/PayLoadInspector.h" 00015 #include "CondCore/Utilities/interface/InspectorPythonWrapper.h" 00016 00017 #include <string> 00018 #include <sstream> 00019 #include <algorithm> 00020 #include <numeric> 00021 #include <iterator> 00022 #include <boost/ref.hpp> 00023 #include <boost/bind.hpp> 00024 #include <boost/function.hpp> 00025 #include <boost/iterator/transform_iterator.hpp> 00026 00027 #include <fstream> 00028 00029 namespace cond { 00030 template<> 00031 std::string PayLoadInspector<EcalTPGTowerStatus>::summary() const { 00032 std::stringstream ss; 00033 int ieta = 0; 00034 int iphi = 0; 00035 00036 const EcalTPGTowerStatusMap & badTTMap = object().getMap(); 00037 EcalTPGTowerStatusMapIterator it; 00038 00039 ss <<"Barrel and endcap masked Trigger Towers"<<std::endl; 00040 //ss <<"RawId " << " iphi " << " ieta " << std::endl; 00041 //ss <<""<< std::endl; 00042 00043 //for (it=badTTMap.begin();it!=badTTMap.end();++it) { 00044 00045 // // Print in the text file only the masked barrel and endcap TTs 00046 // if ((*it).second != 0){ 00047 // EcalTrigTowerDetId ttId((*it).first); 00048 // ieta = ttId.ieta(); 00049 // iphi = ttId.iphi(); 00050 // ss <<""<< std::dec<<(*it).first << " " << iphi << " " << ieta << std::endl; 00051 // } 00052 //} 00053 const std::map<uint32_t, uint16_t> intsMap = object().getMap(); 00054 std::map<uint32_t, uint16_t>::const_iterator intsIter; 00055 std::vector<EcalTrigTowerDetId> towerVec; 00056 std::vector<EcalTrigTowerDetId>::const_iterator towIter; 00057 //map keys are rawIds, get EcalTrigTowerDetIds from them: 00058 ss << "intsMap size: " << intsMap.size() << std::endl; 00059 for(intsIter = intsMap.begin(); intsIter != intsMap.end(); ++intsIter){ 00060 ss << "Key: " << intsIter->first << "->Value: " << intsIter->second; 00061 towerVec.push_back(EcalTrigTowerDetId(intsIter->first)); 00062 towIter = towerVec.end() - 1; 00063 ss 00064 //<< " ieta: " << towIter->ieta() 00065 //<< " iphi: " << towIter->iphi() 00066 << " subdet: " << towIter->subDet() 00067 //<< " zside: " << towIter->zside() 00068 << " ietaAbs: " << towIter->ietaAbs() 00069 //<< " iquadratant: " << towIter->iquadrant() 00070 << " hashedIndex: " << towIter->hashedIndex() 00071 //<< " denseIndex: " << towIter->denseIndex() 00072 //<< " iDCC: " << towIter->iDCC() 00073 //<< " iTT: " << towIter->iTT() 00074 << " Stream: " << *towIter 00075 << std::endl; 00076 } 00077 return ss.str(); 00078 } 00079 00080 template<> 00081 std::string PayLoadInspector<EcalTPGTowerStatus>::plot(std::string const & filename, 00082 std::string const &, 00083 std::vector<int> const&, 00084 std::vector<float> const& ) const { 00085 gStyle->SetPalette(1); 00086 const int TOTAL_IMAGES = 1; 00087 const int TOTAL_PADS = 3; 00088 00089 const float IMG_SIZE = 1.5; 00090 TCanvas canvas("CC map","CC map",800*IMG_SIZE, 200 * TOTAL_IMAGES*IMG_SIZE);//800, 1200 00091 00092 float xmi[3] = {0.0 , 0.22, 0.78}; 00093 float xma[3] = {0.22, 0.78, 1.00}; 00094 00095 00096 TPad*** pad = new TPad**[TOTAL_IMAGES]; 00097 for (int gId = 0; gId < TOTAL_IMAGES; gId++) { 00098 pad[gId] = new TPad*[TOTAL_PADS]; 00099 for (int obj = 0; obj < TOTAL_PADS; obj++) { 00100 float yma = 1. - 0;//1.- (0.17 * gId); 00101 float ymi = yma - 1;//0.15; 00102 pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId),Form("p_%i_%i", obj, gId), 00103 xmi[obj], ymi, xma[obj], yma); 00104 pad[gId][obj]->Draw(); 00105 } 00106 } 00108 const std::map<uint32_t, uint16_t> intsMap = object().getMap(); 00109 std::map<uint32_t, uint16_t>::const_iterator intsIter; 00110 std::vector<EcalTrigTowerDetId> towerVec; 00111 std::vector<EcalTrigTowerDetId>::const_iterator towIter; 00112 std::stringstream ss; 00113 //map keys are rawIds, get EcalTrigTowerDetIds from them: 00114 std::cout << "intsMap size: " << intsMap.size() << std::endl; 00115 for(intsIter = intsMap.begin(); intsIter != intsMap.end(); ++intsIter){ 00116 std::cout << "Key: " << intsIter->first << "->Value: " << intsIter->second; 00117 towerVec.push_back(EcalTrigTowerDetId(intsIter->first)); 00118 towIter = towerVec.end() - 1; 00119 std::cout 00120 //<< " ieta: " << towIter->ieta() 00121 //<< " iphi: " << towIter->iphi() 00122 << " subdet: " << towIter->subDet() 00123 //<< " zside: " << towIter->zside() 00124 << " ietaAbs: " << towIter->ietaAbs() 00125 //<< " iquadratant: " << towIter->iquadrant() 00126 << " hashedIndex: " << towIter->hashedIndex() 00127 //<< " denseIndex: " << towIter->denseIndex() 00128 //<< " iDCC: " << towIter->iDCC() 00129 //<< " iTT: " << towIter->iTT() 00130 << " Stream: " << *towIter 00131 << std::endl; 00132 } 00133 00134 //<BUSINESS LOGIC> 00135 //If in tower exists crystal with status == 1, plot all values in this tower as 1; 00136 //Run trough towers values 00137 //</BUSINESS LOGIC> 00138 00139 //for (towIter = towerVec.begin(); towIter != towerVec.end(); ++towIter){ 00140 // std::cout 00141 // << " ieta: " << towIter->ieta() 00142 // << " iphi: " << towIter->iphi() 00143 // << " subdet: " << towIter->subDet() 00144 // << " zside: " << towIter->zside() 00145 // << " ietaAbs: " << towIter->ietaAbs() 00146 // << " iquadratant: " << towIter->iquadrant() 00147 // << " hashedIndex: " << towIter->hashedIndex() 00148 // << " denseIndex: " << towIter->denseIndex() 00149 // //<< " iDCC: " << towIter->iDCC() 00150 // //<< " iTT: " << towIter->iTT() 00151 // << " Stream: " << *towIter 00152 // << std::endl; 00153 //} 00155 /* 00156 const int kGains = 3; 00157 const int gainValues[3] = {12, 6, 1}; 00158 const int kSides = 2; 00159 const int kBarlRings = EBDetId::MAX_IETA; 00160 const int kBarlWedges = EBDetId::MAX_IPHI; 00161 const int kEndcWedgesX = EEDetId::IX_MAX; 00162 const int kEndcWedgesY = EEDetId::IY_MAX; 00163 00164 TH2F** barrel_m = new TH2F*[3]; 00165 TH2F** endc_p_m = new TH2F*[3]; 00166 TH2F** endc_m_m = new TH2F*[3]; 00167 std::string variableName = "TPGTowerStatus"; 00168 for (int gainId = 0; gainId < kGains; gainId++) { 00169 barrel_m[gainId] = new TH2F(Form((variableName + " EBm%i").c_str(),gainId), Form((variableName + " EB").c_str(),gainValues[gainId]),360,0,360, 170, -85,85); 00170 endc_p_m[gainId] = new TH2F(Form((variableName + " EE+m%i").c_str(),gainId), Form((variableName + " EE+").c_str(),gainValues[gainId]),100,1,101,100,1,101); 00171 endc_m_m[gainId] = new TH2F(Form((variableName + " EE-m%i").c_str(),gainId), Form((variableName + " EE-").c_str(),gainValues[gainId]),100,1,101,100,1,101); 00172 } 00173 00174 for (int sign=0; sign < kSides; sign++) { 00175 int thesign = sign==1 ? 1:-1; 00176 00177 for (int ieta=0; ieta<kBarlRings; ieta++) { 00178 for (int iphi=0; iphi<kBarlWedges; iphi++) { 00179 EBDetId id((ieta+1)*thesign, iphi+1); 00180 float y = -1 - ieta; 00181 if(sign == 1) y = ieta; 00182 barrel_m[0]->Fill(iphi, y, object()[id.rawId()].getStatusCode()); 00183 } // iphi 00184 } // ieta 00185 00186 for (int ix=0; ix<kEndcWedgesX; ix++) { 00187 for (int iy=0; iy<kEndcWedgesY; iy++) { 00188 if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue; 00189 EEDetId id(ix+1,iy+1,thesign); 00190 if (thesign==1) { 00191 endc_p_m[0]->Fill(ix+1,iy+1,object()[id.rawId()].getStatusCode()); 00192 } 00193 else{ 00194 endc_m_m[0]->Fill(ix+1,iy+1,object()[id.rawId()].getStatusCode()); 00195 } 00196 } // iy 00197 } // ix 00198 } // side 00199 00200 //canvas.cd(1); 00201 TLine* l = new TLine(0., 0., 0., 0.); 00202 l->SetLineWidth(1); 00203 int ixSectorsEE[202] = { 00204 62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 00205 41, 41, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 46, 46, 56, 56, 58, 58, 59, 59, 00206 60, 60, 61, 61, 62, 62, 0,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 00207 81, 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9, 00208 9, 6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26, 00209 26, 36, 36, 41, 41, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 93, 93, 96, 00210 96, 98, 98,101,101, 0, 62, 66, 66, 71, 71, 81, 81, 91, 91, 93, 0, 62, 66, 66, 00211 91, 91, 98, 0, 58, 61, 61, 66, 66, 71, 71, 76, 76, 81, 81, 0, 51, 51, 0, 44, 00212 41, 41, 36, 36, 31, 31, 26, 26, 21, 21, 0, 40, 36, 36, 11, 11, 4, 0, 40, 36, 00213 36, 31, 31, 21, 21, 11, 11, 9, 0, 46, 46, 41, 41, 36, 36, 0, 56, 56, 61, 61, 66, 66}; 00214 00215 int iySectorsEE[202] = { 00216 51, 56, 56, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 61, 61, 60, 60, 59, 59, 58, 00217 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 41, 41, 40, 40, 41, 41, 42, 42, 43, 00218 43, 44, 44, 46, 46, 51, 0, 51, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 00219 93, 93, 96, 96, 98, 98,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 81, 00220 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9, 9, 00221 6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26, 26, 00222 36, 36, 41, 41, 51, 0, 46, 46, 41, 41, 36, 36, 31, 31, 26, 26, 0, 51, 51, 56, 00223 56, 61, 61, 0, 61, 61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 62,101, 0, 61, 00224 61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 51, 51, 56, 56, 61, 61, 0, 46, 46, 00225 41, 41, 36, 36, 31, 31, 26, 26, 0, 40, 31, 31, 16, 16, 6, 0, 40, 31, 31, 16, 16, 6}; 00226 00227 for (int gId = 0; gId < TOTAL_IMAGES; gId++) {//was 3 00228 pad[gId][0]->cd(); 00229 endc_m_m[gId]->SetStats(0); 00230 //endc_m_m[gId]->SetMaximum(225); 00231 //endc_m_m[gId]->SetMinimum(175); 00232 endc_m_m[gId]->Draw("colz"); 00233 for ( int i=0; i<201; i=i+1) { 00234 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) && 00235 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) { 00236 l->DrawLine(ixSectorsEE[i], iySectorsEE[i], 00237 ixSectorsEE[i+1], iySectorsEE[i+1]); 00238 l->SetLineWidth(0.2); 00239 } 00240 } 00241 00242 //canvas.cd(2); 00243 pad[gId][1]->cd(); 00244 barrel_m[gId]->SetStats(0); 00245 //barrel_m[gId]->SetMaximum(225); 00246 //barrel_m[gId]->SetMinimum(175); 00247 barrel_m[gId]->Draw("colz"); 00248 for(int i = 0; i <17; i++) { 00249 Double_t x = 20.+ (i *20); 00250 l = new TLine(x,-85.,x,86.); 00251 l->Draw(); 00252 } 00253 l = new TLine(0.,0.,360.,0.); 00254 l->Draw(); 00255 00256 //canvas.cd(3); 00257 pad[gId][2]->cd(); 00258 endc_p_m[gId]->SetStats(0); 00259 //endc_p_m[gId]->SetMaximum(225); 00260 //endc_p_m[gId]->SetMinimum(175); 00261 endc_p_m[gId]->Draw("colz"); 00262 for ( int i=0; i<201; i=i+1) { 00263 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) && 00264 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) { 00265 l->DrawLine(ixSectorsEE[i], iySectorsEE[i], 00266 ixSectorsEE[i+1], iySectorsEE[i+1]); 00267 } 00268 } 00269 } 00270 */ 00271 00272 canvas.SaveAs(filename.c_str()); 00273 return filename; 00274 } // plot 00275 } 00276 PYTHON_WRAPPER(EcalTPGTowerStatus,EcalTPGTowerStatus);