00001
00002 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
00003 #include "CondTools/Ecal/interface/EcalChannelStatusXMLTranslator.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 <fstream>
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 namespace cond {
00027
00028
00029 namespace ecalcond {
00030
00031 typedef EcalChannelStatus Container;
00032 typedef Container::Items Items;
00033 typedef Container::value_type value_type;
00034
00035 enum How { singleChannel, bySuperModule, barrel, endcap, 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
00045 void extractBarrel(Container const & cont, std::vector<int> const &, std::vector<float> & result) {
00046 result.resize(1);
00047 result[0] = bad(cont.barrelItems());
00048 }
00049 void extractEndcap(Container const & cont, std::vector<int> const &, std::vector<float> & result) {
00050 result.resize(1);
00051 result[0] = bad(cont.endcapItems());
00052 }
00053 void extractAll(Container 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(Container const & cont, std::vector<int> const & which, std::vector<float> & result) {
00059
00060 }
00061
00062 void extractSingleChannel(Container 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(Container const & cont, std::vector<int> const & which, std::vector<float> & result)> CondExtractor;
00070
00071 }
00072
00073 template<>
00074 struct ExtractWhat<ecalcond::Container> {
00075
00076 ecalcond::How m_how;
00077 std::vector<int> m_which;
00078
00079 ecalcond::How const & how() const { return m_how;}
00080 std::vector<int> const & which() const { return m_which;}
00081
00082 void set_how(ecalcond::How i) {m_how=i;}
00083 void set_which(std::vector<int> & i) { m_which.swap(i);}
00084 };
00085
00086
00087
00088
00089 template<>
00090 class ValueExtractor<ecalcond::Container>: public BaseValueExtractor<ecalcond::Container> {
00091 public:
00092
00093 static ecalcond::CondExtractor & extractor(ecalcond::How how) {
00094 static ecalcond::CondExtractor fun[5] = {
00095 ecalcond::CondExtractor(ecalcond::extractSingleChannel),
00096 ecalcond::CondExtractor(ecalcond::extractSuperModules),
00097 ecalcond::CondExtractor(ecalcond::extractBarrel),
00098 ecalcond::CondExtractor(ecalcond::extractEndcap),
00099 ecalcond::CondExtractor(ecalcond::extractAll)
00100 };
00101 return fun[how];
00102 }
00103
00104
00105 typedef ecalcond::Container Class;
00106 typedef ExtractWhat<Class> What;
00107 static What what() { return What();}
00108
00109 ValueExtractor(){}
00110 ValueExtractor(What const & what)
00111 : m_what(what)
00112 {
00113
00114
00115 }
00116
00117 void compute(Class const & it){
00118 std::vector<float> res;
00119 extractor(m_what.how())(it,m_what.which(),res);
00120 swap(res);
00121 }
00122
00123 private:
00124 What m_what;
00125
00126 };
00127
00128
00129 template<>
00130 std::string
00131 PayLoadInspector<EcalChannelStatus>::dump() const {
00132 std::stringstream ss;
00133 EcalCondHeader h;
00134 ss << EcalChannelStatusXMLTranslator::dumpXML(h,object());
00135 return ss.str();
00136
00137 }
00138
00139 template<>
00140 std::string PayLoadInspector<EcalChannelStatus>::summary() const {
00141 std::stringstream ss;
00142 ss << ecalcond::bad(object().barrelItems()) << ", " << ecalcond::bad(object().endcapItems());
00143 return ss.str();
00144 }
00145
00146
00147 template<>
00148 std::string PayLoadInspector<EcalChannelStatus>::plot(std::string const & filename,
00149 std::string const &,
00150 std::vector<int> const&,
00151 std::vector<float> const& ) const {
00152
00153 gStyle->SetPalette(1);
00154
00155 const Int_t NRGBs = 5;
00156 const Int_t NCont = 255;
00157
00158 Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
00159 Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
00160 Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
00161 Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
00162 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
00163 gStyle->SetNumberContours(NCont);
00164
00165 TCanvas canvas("CC map","CC map",800,800);
00166 TPad* padb = new TPad("padb","padb", 0., 0.55, 1., 1.);
00167 padb->Draw();
00168 TPad* padem = new TPad("padem","padem", 0., 0., 0.45, 0.45);
00169 padem->Draw();
00170 TPad* padep = new TPad("padep","padep", 0.55, 0., 1., 0.45);
00171 padep->Draw();
00172
00173 const int kSides = 2;
00174 const int kBarlRings = EBDetId::MAX_IETA;
00175 const int kBarlWedges = EBDetId::MAX_IPHI;
00176 const int kEndcWedgesX = EEDetId::IX_MAX;
00177 const int kEndcWedgesY = EEDetId::IY_MAX;
00178
00179 TH2F* barrel = new TH2F("EB","EB Channel Status",360,0,360, 171, -85,86);
00180 TH2F* endc_p = new TH2F("EE+","EE+ Channel Status",100,1,101,100,1,101);
00181 TH2F* endc_m = new TH2F("EE-","EE- Channel Status",100,1,101,100,1,101);
00182
00183 for (int sign=0; sign < kSides; sign++) {
00184 int thesign = sign==1 ? 1:-1;
00185
00186 for (int ieta=0; ieta<kBarlRings; ieta++) {
00187 for (int iphi=0; iphi<kBarlWedges; iphi++) {
00188 EBDetId id((ieta+1)*thesign, iphi+1);
00189 barrel->Fill(iphi, ieta*thesign + thesign, object()[id.rawId()].getStatusCode());
00190
00191
00192 }
00193 }
00194
00195 for (int ix=0; ix<kEndcWedgesX; ix++) {
00196 for (int iy=0; iy<kEndcWedgesY; iy++) {
00197 if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
00198 EEDetId id(ix+1,iy+1,thesign);
00199 if (thesign==1) {
00200 endc_p->Fill(ix+1,iy+1,object()[id.rawId()].getStatusCode());
00201 }
00202 else{
00203 endc_m->Fill(ix+1,iy+1,object()[id.rawId()].getStatusCode());
00204 }
00205 }
00206 }
00207 }
00208
00209 TLine* l = new TLine(0., 0., 0., 0.);
00210 l->SetLineWidth(1);
00211 padb->cd();
00212 barrel->SetStats(0);
00213 barrel->SetMaximum(14);
00214 barrel->SetMinimum(0);
00215 barrel->Draw("colz");
00216 for(int i = 0; i <17; i++) {
00217 Double_t x = 20.+ (i *20);
00218 l = new TLine(x,-85.,x,86.);
00219 l->Draw();
00220 }
00221 l = new TLine(0.,0.,360.,0.);
00222 l->Draw();
00223 int ixSectorsEE[202] = {
00224 62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42,
00225 41, 41, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 46, 46, 56, 56, 58, 58, 59, 59,
00226 60, 60, 61, 61, 62, 62, 0,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81,
00227 81, 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9,
00228 9, 6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26,
00229 26, 36, 36, 41, 41, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 93, 93, 96,
00230 96, 98, 98,101,101, 0, 62, 66, 66, 71, 71, 81, 81, 91, 91, 93, 0, 62, 66, 66,
00231 91, 91, 98, 0, 58, 61, 61, 66, 66, 71, 71, 76, 76, 81, 81, 0, 51, 51, 0, 44,
00232 41, 41, 36, 36, 31, 31, 26, 26, 21, 21, 0, 40, 36, 36, 11, 11, 4, 0, 40, 36,
00233 36, 31, 31, 21, 21, 11, 11, 9, 0, 46, 46, 41, 41, 36, 36, 0, 56, 56, 61, 61, 66, 66};
00234
00235 int iySectorsEE[202] = {
00236 51, 56, 56, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 61, 61, 60, 60, 59, 59, 58,
00237 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 41, 41, 40, 40, 41, 41, 42, 42, 43,
00238 43, 44, 44, 46, 46, 51, 0, 51, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88,
00239 93, 93, 96, 96, 98, 98,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 81,
00240 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9, 9,
00241 6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26, 26,
00242 36, 36, 41, 41, 51, 0, 46, 46, 41, 41, 36, 36, 31, 31, 26, 26, 0, 51, 51, 56,
00243 56, 61, 61, 0, 61, 61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 62,101, 0, 61,
00244 61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 51, 51, 56, 56, 61, 61, 0, 46, 46,
00245 41, 41, 36, 36, 31, 31, 26, 26, 0, 40, 31, 31, 16, 16, 6, 0, 40, 31, 31, 16, 16, 6};
00246
00247 padem->cd();
00248 endc_m->SetStats(0);
00249 endc_m->SetMaximum(14);
00250 endc_m->SetMinimum(0);
00251 endc_m->Draw("colz");
00252 for ( int i=0; i<201; i=i+1) {
00253 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
00254 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00255 l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
00256 ixSectorsEE[i+1], iySectorsEE[i+1]);
00257 }
00258 }
00259 padep->cd();
00260 endc_p->SetStats(0);
00261 endc_p->SetMaximum(14);
00262 endc_p->SetMinimum(0);
00263 endc_p->Draw("colz");
00264 for ( int i=0; i<201; i=i+1) {
00265 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
00266 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00267 l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
00268 ixSectorsEE[i+1], iySectorsEE[i+1]);
00269 }
00270 }
00271
00272 canvas.SaveAs(filename.c_str());
00273 return filename;
00274 }
00275
00276
00277 }
00278
00279 namespace condPython {
00280 template<>
00281 void defineWhat<cond::ecalcond::Container>() {
00282 using namespace boost::python;
00283 enum_<cond::ecalcond::How>("How")
00284 .value("singleChannel",cond::ecalcond::singleChannel)
00285 .value("bySuperModule",cond::ecalcond::bySuperModule)
00286 .value("barrel",cond::ecalcond::barrel)
00287 .value("endcap",cond::ecalcond::endcap)
00288 .value("all",cond::ecalcond::all)
00289 ;
00290
00291 typedef cond::ExtractWhat<cond::ecalcond::Container> What;
00292 class_<What>("What",init<>())
00293 .def("set_how",&What::set_how)
00294 .def("set_which",&What::set_which)
00295 .def("how",&What::how, return_value_policy<copy_const_reference>())
00296 .def("which",&What::which, return_value_policy<copy_const_reference>())
00297 ;
00298 }
00299 }
00300
00301 PYTHON_WRAPPER(EcalChannelStatus,EcalChannelStatus);