00001 #include "CondFormats/EcalObjects/interface/EcalTPGCrystalStatus.h"
00002 #include "CondTools/Ecal/interface/EcalTPGCrystalStatusXMLTranslator.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 #include "CondCore/EcalPlugins/plugins/EcalPyWrapperFunctions.h"
00029
00030 namespace cond {
00031
00032 namespace ecalcond {
00033
00034 typedef EcalTPGCrystalStatus::Items Items;
00035 typedef EcalTPGCrystalStatus::value_type value_type;
00036
00037 enum How { singleChannel, bySuperModule, all};
00038
00039 int bad(Items const & cont) {
00040 return std::count_if(cont.begin(),cont.end(),
00041 boost::bind(std::greater<int>(),
00042 boost::bind(&value_type::getStatusCode,_1),0)
00043 );
00044 }
00045
00046 void extractBarrel(EcalTPGCrystalStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
00047 result.resize(1);
00048 result[0] = bad(cont.barrelItems());
00049 }
00050
00051 void extractEndcap(EcalTPGCrystalStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
00052 result.resize(1);
00053 result[0] = bad(cont.endcapItems());
00054 }
00055 void extractAll(EcalTPGCrystalStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
00056 result.resize(1);
00057 result[0] = bad(cont.barrelItems())+bad(cont.endcapItems());
00058 }
00059
00060 void extractSuperModules(EcalTPGCrystalStatus const & cont, std::vector<int> const & which, std::vector<float> & result) {
00061
00062 }
00063
00064 void extractSingleChannel(EcalTPGCrystalStatus const & cont, std::vector<int> const & which, std::vector<float> & result) {
00065 result.reserve(which.size());
00066 for (unsigned int i=0; i<which.size();i++) {
00067 result.push_back(cont[which[i]].getStatusCode());
00068 }
00069 }
00070
00071 typedef boost::function<void(EcalTPGCrystalStatus const & cont, std::vector<int> const & which, std::vector<float> & result)> CondExtractor;
00072 }
00073
00074 template<>
00075 struct ExtractWhat<EcalTPGCrystalStatus> {
00076
00077 ecalcond::How m_how;
00078 std::vector<int> m_which;
00079
00080 ecalcond::How const & how() const { return m_how;}
00081 std::vector<int> const & which() const { return m_which;}
00082
00083 void set_how(ecalcond::How i) {m_how=i;}
00084 void set_which(std::vector<int> & i) { m_which.swap(i);}
00085 };
00086
00087
00088 template<>
00089 class ValueExtractor<EcalTPGCrystalStatus>: public BaseValueExtractor<EcalTPGCrystalStatus> {
00090 public:
00091
00092 static ecalcond::CondExtractor & extractor(ecalcond::How how) {
00093 static ecalcond::CondExtractor fun[3] = {
00094 ecalcond::CondExtractor(ecalcond::extractSingleChannel),
00095 ecalcond::CondExtractor(ecalcond::extractSuperModules),
00096 ecalcond::CondExtractor(ecalcond::extractAll)
00097 };
00098 return fun[how];
00099 }
00100
00101 typedef EcalTPGCrystalStatus Class;
00102 typedef ExtractWhat<Class> What;
00103 static What what() { return What();}
00104
00105 ValueExtractor(){}
00106 ValueExtractor(What const & what)
00107 : m_what(what)
00108 {
00109
00110 }
00111
00112 void compute(Class const & it){
00113 std::vector<float> res;
00114 extractor(m_what.how())(it,m_what.which(),res);
00115 swap(res);
00116 }
00117
00118 private:
00119 What m_what;
00120 };
00121
00122
00123 template<>
00124 std::string PayLoadInspector<EcalTPGCrystalStatus>::dump() const {
00125 std::stringstream ss;
00126 EcalCondHeader h;
00127 ss << EcalTPGCrystalStatusXMLTranslator::dumpXML(h,object());
00128 return ss.str();
00129 }
00130
00131 class EcalTPGCrystalStatusHelper: public EcalPyWrapperHelper<EcalTPGCrystalStatusCode>{
00132 public:
00133
00134 EcalTPGCrystalStatusHelper():EcalPyWrapperHelper<EcalObject>(1, STATUS, "-Errors total: "){}
00135 protected:
00136
00137
00138 typedef EcalTPGCrystalStatusCode EcalObject;
00139
00140 type_vValues getValues( const std::vector<EcalObject> & vItems)
00141 {
00142
00143
00144
00145 type_vValues vValues(total_values);
00146
00147
00148 vValues[0].first = "[0]StatusCode";
00149
00150
00151 vValues[0].second = .0;
00152
00153
00154 unsigned int shift = 0, mask = 1;
00155 unsigned int statusCode;
00156 for(std::vector<EcalObject>::const_iterator iItems = vItems.begin(); iItems != vItems.end(); ++iItems){
00157
00158 statusCode = iItems->getStatusCode();
00159 for (shift = 0; shift < total_values; ++shift){
00160 mask = 1 << (shift);
00161
00162 if (statusCode & mask){
00163 vValues[shift].second += 1;
00164 }
00165 }
00166 }
00167 return vValues;
00168 }
00169 };
00170
00171 template<>
00172 std::string PayLoadInspector<EcalTPGCrystalStatus>::summary() const {
00173 std::stringstream ss;
00174
00175
00176 const int kSides = 2;
00177 const int kBarlRings = EBDetId::MAX_IETA;
00178 const int kBarlWedges = EBDetId::MAX_IPHI;
00179 const int kEndcWedgesX = EEDetId::IX_MAX;
00180 const int kEndcWedgesY = EEDetId::IY_MAX;
00181
00182 int EB[2] = {0, 0}, EE[2] = {0, 0};
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 if(object()[id.rawId()].getStatusCode() > 0) EB[sign]++;
00190 }
00191 }
00192
00193 for (int ix=0; ix<kEndcWedgesX; ix++) {
00194 for (int iy=0; iy<kEndcWedgesY; iy++) {
00195 if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
00196 EEDetId id(ix+1,iy+1,thesign);
00197 if(object()[id.rawId()].getStatusCode() > 0) EE[sign]++;
00198 }
00199 }
00200 }
00201 ss << " number of masked Crystals EB- " << EB[0] << " EB+ " << EB[1]
00202 << " EE- " << EE[0] << " EE+ " << EE[1] << std::endl;
00203 return ss.str();
00204 }
00205
00206 template<>
00207 std::string PayLoadInspector<EcalTPGCrystalStatus>::plot(std::string const & filename,
00208 std::string const &,
00209 std::vector<int> const&,
00210 std::vector<float> const& ) const {
00211 gStyle->SetPalette(1);
00212 const int TOTAL_PADS = 3;
00213
00214
00215 Double_t w = 600;
00216 Double_t h = 600;
00217 TCanvas canvas("c", "c", w, h);
00218 canvas.SetWindowSize(w + (w - canvas.GetWw()), h + (h - canvas.GetWh()));
00219
00220
00221
00222 float xmi[3] = {0.0, 0.0, 0.5};
00223 float xma[3] = {1.0, 0.5, 1.0};
00224 float ymi[3] = {0.5, 0.0, 0.0};
00225 float yma[3] = {1.0, 0.5, 0.5};
00226
00227
00228 TPad** pad = new TPad*[TOTAL_PADS];
00229 for (int obj = 0; obj < TOTAL_PADS; obj++) {
00230 pad[obj] = new TPad(Form("p_%i", obj),Form("p_%i", obj),
00231 xmi[obj], ymi[obj], xma[obj], yma[obj]);
00232 pad[obj]->Draw();
00233 }
00234
00235 const int kSides = 2;
00236 const int kBarlRings = EBDetId::MAX_IETA;
00237 const int kBarlWedges = EBDetId::MAX_IPHI;
00238 const int kEndcWedgesX = EEDetId::IX_MAX;
00239 const int kEndcWedgesY = EEDetId::IY_MAX;
00240
00241 TH2F* barrel = new TH2F("EB","EB TPG Crystal Status", 360,0,360, 170, -85,85);
00242 TH2F* endc_m = new TH2F("EEm","EE- TPG Crystal Status",100,1,101,100,1,101);
00243 TH2F* endc_p = new TH2F("EEp","EE+ TPG Crystal Status",100,1,101,100,1,101);
00244
00245 for (int sign=0; sign < kSides; sign++) {
00246 int thesign = sign==1 ? 1:-1;
00247
00248 for (int ieta=0; ieta<kBarlRings; ieta++) {
00249 for (int iphi=0; iphi<kBarlWedges; iphi++) {
00250 EBDetId id((ieta+1)*thesign, iphi+1);
00251 float y = -1 - ieta;
00252 if(sign == 1) y = ieta;
00253 barrel->Fill(iphi, y, object()[id.rawId()].getStatusCode());
00254 }
00255 }
00256
00257 for (int ix=0; ix<kEndcWedgesX; ix++) {
00258 for (int iy=0; iy<kEndcWedgesY; iy++) {
00259 if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
00260 EEDetId id(ix+1,iy+1,thesign);
00261 if (thesign==1) {
00262 endc_p->Fill(ix+1,iy+1,object()[id.rawId()].getStatusCode());
00263 }
00264 else{
00265 endc_m->Fill(ix+1,iy+1,object()[id.rawId()].getStatusCode());
00266 }
00267 }
00268 }
00269 }
00270
00271 TLine* l = new TLine(0., 0., 0., 0.);
00272 l->SetLineWidth(1);
00273 int ixSectorsEE[202] = {
00274 62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42,
00275 41, 41, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 46, 46, 56, 56, 58, 58, 59, 59,
00276 60, 60, 61, 61, 62, 62, 0,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81,
00277 81, 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9,
00278 9, 6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26,
00279 26, 36, 36, 41, 41, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 93, 93, 96,
00280 96, 98, 98,101,101, 0, 62, 66, 66, 71, 71, 81, 81, 91, 91, 93, 0, 62, 66, 66,
00281 91, 91, 98, 0, 58, 61, 61, 66, 66, 71, 71, 76, 76, 81, 81, 0, 51, 51, 0, 44,
00282 41, 41, 36, 36, 31, 31, 26, 26, 21, 21, 0, 40, 36, 36, 11, 11, 4, 0, 40, 36,
00283 36, 31, 31, 21, 21, 11, 11, 9, 0, 46, 46, 41, 41, 36, 36, 0, 56, 56, 61, 61, 66, 66};
00284
00285 int iySectorsEE[202] = {
00286 51, 56, 56, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 61, 61, 60, 60, 59, 59, 58,
00287 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 41, 41, 40, 40, 41, 41, 42, 42, 43,
00288 43, 44, 44, 46, 46, 51, 0, 51, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88,
00289 93, 93, 96, 96, 98, 98,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 81,
00290 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9, 9,
00291 6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26, 26,
00292 36, 36, 41, 41, 51, 0, 46, 46, 41, 41, 36, 36, 31, 31, 26, 26, 0, 51, 51, 56,
00293 56, 61, 61, 0, 61, 61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 62,101, 0, 61,
00294 61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 51, 51, 56, 56, 61, 61, 0, 46, 46,
00295 41, 41, 36, 36, 31, 31, 26, 26, 0, 40, 31, 31, 16, 16, 6, 0, 40, 31, 31, 16, 16, 6};
00296
00297 pad[0]->cd();
00298 barrel->SetStats(0);
00299 barrel->Draw("colz");
00300 for(int i = 0; i <17; i++) {
00301 Double_t x = 20.+ (i *20);
00302 l = new TLine(x,-85.,x,86.);
00303 l->Draw();
00304 }
00305 l = new TLine(0.,0.,360.,0.);
00306 l->Draw();
00307
00308 pad[1]->cd();
00309 endc_m->SetStats(0);
00310 endc_m->Draw("col");
00311 for ( int i=0; i<201; i=i+1) {
00312 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
00313 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00314 l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
00315 ixSectorsEE[i+1], iySectorsEE[i+1]);
00316 l->SetLineWidth(0.2);
00317 }
00318 }
00319
00320 pad[2]->cd();
00321 endc_p->SetStats(0);
00322 endc_p->Draw("col");
00323 for ( int i=0; i<201; i=i+1) {
00324 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
00325 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00326 l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
00327 ixSectorsEE[i+1], iySectorsEE[i+1]);
00328 }
00329 }
00330
00331 canvas.SaveAs(filename.c_str());
00332 return filename;
00333 }
00334 }
00335
00336 PYTHON_WRAPPER(EcalTPGCrystalStatus,EcalTPGCrystalStatus);