00001 #include "CondFormats/EcalObjects/interface/EcalDCSTowerStatus.h"
00002 #include "CondTools/Ecal/interface/EcalDCSTowerStatusXMLTranslator.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
00013 #include "CondCore/Utilities/interface/PayLoadInspector.h"
00014 #include "CondCore/Utilities/interface/InspectorPythonWrapper.h"
00015
00016 #include <string>
00017 #include <sstream>
00018 #include <algorithm>
00019 #include <numeric>
00020 #include <iterator>
00021 #include <boost/ref.hpp>
00022 #include <boost/bind.hpp>
00023 #include <boost/function.hpp>
00024 #include <boost/iterator/transform_iterator.hpp>
00025
00026 #include <fstream>
00027
00028 namespace cond {
00029
00030 namespace ecalcond {
00031
00032 typedef EcalDCSTowerStatus::Items Items;
00033 typedef EcalDCSTowerStatus::value_type value_type;
00034
00035 enum How { singleChannel, bySuperModule, all};
00036
00037 int bad(Items const & cont) {
00038 return std::count_if(cont.begin(),cont.end(),
00039 boost::bind(std::greater<int>(),
00040 boost::bind(&value_type::getStatusCode,_1),0)
00041 );
00042 }
00043
00044 void extractBarrel(EcalDCSTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
00045 result.resize(1);
00046 result[0] = bad(cont.barrelItems());
00047 }
00048
00049 void extractEndcap(EcalDCSTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
00050 result.resize(1);
00051 result[0] = bad(cont.endcapItems());
00052 }
00053 void extractAll(EcalDCSTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
00054 result.resize(1);
00055 result[0] = bad(cont.barrelItems())+bad(cont.endcapItems());
00056 }
00057
00058 void extractSuperModules(EcalDCSTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result) {
00059
00060 }
00061
00062 void extractSingleChannel(EcalDCSTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result) {
00063 result.reserve(which.size());
00064 for (unsigned int i=0; i<which.size();i++) {
00065 result.push_back(cont[which[i]].getStatusCode());
00066 }
00067 }
00068
00069 typedef boost::function<void(EcalDCSTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result)> CondExtractor;
00070 }
00071
00072 template<>
00073 struct ExtractWhat<EcalDCSTowerStatus> {
00074
00075 ecalcond::How m_how;
00076 std::vector<int> m_which;
00077
00078 ecalcond::How const & how() const { return m_how;}
00079 std::vector<int> const & which() const { return m_which;}
00080
00081 void set_how(ecalcond::How i) {m_how=i;}
00082 void set_which(std::vector<int> & i) { m_which.swap(i);}
00083 };
00084
00085
00086 template<>
00087 class ValueExtractor<EcalDCSTowerStatus>: public BaseValueExtractor<EcalDCSTowerStatus> {
00088 public:
00089
00090 static ecalcond::CondExtractor & extractor(ecalcond::How how) {
00091 static ecalcond::CondExtractor fun[3] = {
00092 ecalcond::CondExtractor(ecalcond::extractSingleChannel),
00093 ecalcond::CondExtractor(ecalcond::extractSuperModules),
00094 ecalcond::CondExtractor(ecalcond::extractAll)
00095 };
00096 return fun[how];
00097 }
00098
00099 typedef EcalDCSTowerStatus Class;
00100 typedef ExtractWhat<Class> What;
00101 static What what() { return What();}
00102
00103 ValueExtractor(){}
00104 ValueExtractor(What const & what)
00105 : m_what(what)
00106 {
00107
00108 }
00109
00110 void compute(Class const & it){
00111 std::vector<float> res;
00112 extractor(m_what.how())(it,m_what.which(),res);
00113 swap(res);
00114 }
00115
00116 private:
00117 What m_what;
00118 };
00119
00120
00121 template<>
00122 std::string PayLoadInspector<EcalDCSTowerStatus>::dump() const {
00123 std::stringstream ss;
00124 EcalCondHeader h;
00125 ss << EcalDCSTowerStatusXMLTranslator::dumpXML(h,object());
00126 return ss.str();
00127 }
00128
00129 template<>
00130 std::string PayLoadInspector<EcalDCSTowerStatus>::summary() const {
00131 std::cout << "***************************************"<< std::endl;
00132 std::stringstream ss;
00133 ss << "sizes="
00134 << object().barrelItems().size() <<","
00135 << object().endcapItems().size() <<";";
00136 ss << std::endl;
00137 return ss.str();
00138 }
00139
00140
00141
00142 template<>
00143 std::string PayLoadInspector<EcalDCSTowerStatus>::plot(std::string const & filename,
00144 std::string const &,
00145 std::vector<int> const&,
00146 std::vector<float> const& ) const {
00147
00148
00149
00150
00151
00152 gStyle->SetPalette(1);
00153
00154 const Int_t NRGBs = 5;
00155 const Int_t NCont = 255;
00156
00157 Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
00158 Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
00159 Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
00160 Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
00161 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
00162 gStyle->SetNumberContours(NCont);
00163
00164 TCanvas canvas("CC map","CC map",800,800);
00165 TPad* padb = new TPad("padb","padb", 0., 0.55, 1., 1.);
00166 padb->Draw();
00167 TPad* padem = new TPad("padem","padem", 0., 0., 0.45, 0.45);
00168 padem->Draw();
00169 TPad* padep = new TPad("padep","padep", 0.55, 0., 1., 0.45);
00170 padep->Draw();
00171
00172
00173 TH2F* barrel = new TH2F("EB","EB Tower Status", 72, 0, 72, 34, -17, 17);
00174 TH2F* endc_p = new TH2F("EE+","EE+ Tower Status",22, 0, 22, 22, 0, 22);
00175 TH2F* endc_m = new TH2F("EE-","EE- Tower Status",22, 0, 22, 22, 0, 22);
00176 for(uint cellid = 0;
00177 cellid < EcalTrigTowerDetId::kEBTotalTowers;
00178 ++cellid) {
00179 EcalTrigTowerDetId rawid = EcalTrigTowerDetId::detIdFromDenseIndex(cellid);
00180 if (object().find(rawid) == object().end()) continue;
00181 int ieta = rawid.ieta();
00182 if(ieta > 0) ieta--;
00183 int iphi = rawid.iphi() - 1;
00184 barrel->Fill(iphi, ieta, object()[rawid].getStatusCode());
00185 }
00186 for(uint cellid = 0;
00187 cellid < EcalTrigTowerDetId::kEETotalTowers;
00188 ++cellid) {
00189 if(EcalScDetId::validHashIndex(cellid)) {
00190 EcalScDetId rawid = EcalScDetId::unhashIndex(cellid);
00191 int ix = rawid.ix();
00192 int iy = rawid.iy();
00193 int side = rawid.zside();
00194 if(side == -1)
00195 endc_m->Fill(ix, iy, object()[rawid].getStatusCode());
00196 else
00197 endc_p->Fill(ix, iy, object()[rawid].getStatusCode());
00198 }
00199 }
00200 TLine* l = new TLine(0., 0., 0., 0.);
00201 l->SetLineWidth(1);
00202 padb->cd();
00203 barrel->SetStats(0);
00204 barrel->SetMaximum(14);
00205 barrel->SetMinimum(0);
00206 barrel->Draw("colz");
00207
00208 for(int i = 0; i <17; i++) {
00209 Double_t x = 4.+ (i * 4);
00210 l = new TLine(x, -17., x, 17.);
00211 l->Draw();
00212 }
00213 l = new TLine(0., 0., 72., 0.);
00214 l->Draw();
00215
00216 int ixSectorsEE[136] = {
00217 8,14,14,17,17,18,18,19,19,20,20,21,21,20,20,19,19,18,18,17,
00218 17,14,14, 8, 8, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 4,
00219 4, 5, 5, 8, 8, 8, 9, 9,10,10,12,12,13,13,12,12,10,10, 9, 9,
00220 10,10, 0,11,11, 0,10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 0,12,13,
00221 13,14,14,15,15,16,16,17,17, 0, 9, 8, 8, 3, 3, 1, 0,13,14,14,
00222 19,19,21, 0, 9, 8, 8, 7, 7, 5, 5, 3, 3, 2, 0,13,14,14,15,15,
00223 17,17,19,19,20, 0,14,14,13,13,12,12,0};
00224 int iySectorsEE[136] = {
00225 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 8, 8,14,14,17,17,18,18,19,19,
00226 20,20,21,21,20,20,19,19,18,18,17,17,14,14, 8, 8, 5, 5, 4, 4,
00227 3, 3, 2, 2, 1, 4, 4, 7, 7, 9, 9,10,10,12,12,13,13,12,12,10,
00228 10, 9, 0,13,21, 0,13,13,14,14,15,15,16,16,18,18,19, 0,13,13,
00229 14,14,15,15,16,16,18,18,19, 0,11,11,12,12,13,13, 0,11,11,12,
00230 12,13,13, 0,10,10, 9, 9, 8, 8, 7, 7, 6, 6, 0,10,10, 9, 9, 8,
00231 8, 7, 7, 6, 6, 0, 2, 4, 4, 7, 7, 9, 0} ;
00232 padem->cd();
00233 endc_m->SetStats(0);
00234 endc_m->SetMaximum(14);
00235 endc_m->SetMinimum(0);
00236 endc_m->Draw("colz");
00237 for ( int i = 0; i < 136; i=i+1) {
00238 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
00239 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00240 l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
00241 ixSectorsEE[i+1], iySectorsEE[i+1]);
00242 }
00243 }
00244
00245 padep->cd();
00246 endc_p->SetStats(0);
00247 endc_p->SetMaximum(14);
00248 endc_p->SetMinimum(0);
00249 endc_p->Draw("colz");
00250 for ( int i = 0; i < 136; i=i+1) {
00251 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
00252 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00253 l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
00254 ixSectorsEE[i+1], iySectorsEE[i+1]);
00255 }
00256 }
00257
00258 canvas.SaveAs(filename.c_str());
00259 return filename;
00260 }
00261 }
00262
00263
00264 namespace condPython {
00265 template<>
00266 void defineWhat<EcalDCSTowerStatus>() {
00267 using namespace boost::python;
00268 enum_<cond::ecalcond::How>("How")
00269 .value("singleChannel",cond::ecalcond::singleChannel)
00270 .value("bySuperModule",cond::ecalcond::bySuperModule)
00271 .value("all",cond::ecalcond::all)
00272 ;
00273
00274 typedef cond::ExtractWhat<EcalDCSTowerStatus> What;
00275 class_<What>("What",init<>())
00276 .def("set_how",&What::set_how)
00277 .def("set_which",&What::set_which)
00278 .def("how",&What::how, return_value_policy<copy_const_reference>())
00279 .def("which",&What::which, return_value_policy<copy_const_reference>())
00280 ;
00281 }
00282 }
00283
00284 PYTHON_WRAPPER(EcalDCSTowerStatus,EcalDCSTowerStatus);