00001 #include "CondFormats/EcalObjects/interface/EcalTPGLinearizationConst.h"
00002 #include "CondTools/Ecal/interface/EcalTPGLinearizationConstXMLTranslator.h"
00003 #include "CondTools/Ecal/interface/EcalCondHeader.h"
00004 #include "TH2F.h"
00005 #include "TCanvas.h"
00006 #include "TLine.h"
00007 #include "TStyle.h"
00008 #include "TPave.h"
00009 #include "TPaveStats.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
00019 #include "CondCore/EcalPlugins/plugins/EcalPyWrapperFunctions.h"
00020
00021 namespace cond {
00022
00023 template<>
00024 class ValueExtractor<EcalTPGLinearizationConst>: public BaseValueExtractor<EcalTPGLinearizationConst> {
00025 public:
00026
00027 typedef EcalTPGLinearizationConst Class;
00028 typedef ExtractWhat<Class> What;
00029 static What what() { return What();}
00030
00031 ValueExtractor(){}
00032 ValueExtractor(What const & what)
00033 {
00034
00035 }
00036 void compute(Class const & it){
00037 }
00038 private:
00039
00040 };
00041
00042 template<>
00043 std::string PayLoadInspector<EcalTPGLinearizationConst>::dump() const {
00044
00045 std::stringstream ss;
00046 EcalCondHeader header;
00047 ss << EcalTPGLinearizationConstXMLTranslator::dumpXML(header,object());
00048 return ss.str();
00049
00050 }
00051
00052 class EcalTPGLinearizationConstHelper: public EcalPyWrapperHelper<EcalTPGLinearizationConstant>{
00053 public:
00054
00055 EcalTPGLinearizationConstHelper():EcalPyWrapperHelper<EcalObject>(6){}
00056 protected:
00057
00058
00059 typedef EcalTPGLinearizationConstant EcalObject;
00060
00061 type_vValues getValues( const std::vector<EcalObject> & vItems)
00062 {
00063
00064 type_vValues vValues(total_values);
00065
00066 vValues[0].second = .0;
00067 vValues[1].second = .0;
00068 vValues[2].second = .0;
00069 vValues[3].second = .0;
00070 vValues[4].second = .0;
00071 vValues[5].second = .0;
00072
00073
00074
00075 vValues[0].first = "mult_x12";
00076 vValues[1].first = "mult_x6";
00077 vValues[2].first = "mult_x1";
00078 vValues[3].first = "shift_x12";
00079 vValues[4].first = "shift_x6";
00080 vValues[5].first = "shift_x1";
00081
00082
00083
00084
00085 for(std::vector<EcalObject>::const_iterator iItems = vItems.begin(); iItems != vItems.end(); ++iItems){
00086
00087 vValues[0].second += iItems->mult_x12;
00088 vValues[1].second += iItems->mult_x6;
00089 vValues[2].second += iItems->mult_x1;
00090 vValues[3].second += iItems->shift_x12;
00091 vValues[4].second += iItems->shift_x6;
00092 vValues[5].second += iItems->shift_x1;
00093
00094 }
00095 return vValues;
00096 }
00097 };
00098
00099 template<>
00100 std::string PayLoadInspector<EcalTPGLinearizationConst>::summary() const {
00101 std::stringstream ss;
00102 EcalTPGLinearizationConstHelper helper;
00103 ss << helper.printBarrelsEndcaps(object().barrelItems(), object().endcapItems());
00104 return ss.str();
00105 }
00106
00107
00108 template<>
00109 std::string PayLoadInspector<EcalTPGLinearizationConst>::plot(std::string const & filename,
00110 std::string const &,
00111 std::vector<int> const&,
00112 std::vector<float> const& ) const {
00113 gStyle->SetPalette(1);
00114
00115 const float IMG_SIZE = 1.5;
00116 TCanvas canvas("CC map","CC map",800 * IMG_SIZE,1200 * IMG_SIZE);
00117
00118 float xmi[3] = {0.0 , 0.22, 0.78};
00119 float xma[3] = {0.22, 0.78, 1.00};
00120 TPad*** pad = new TPad**[6];
00121 for (int gId = 0; gId < 6; gId++) {
00122 pad[gId] = new TPad*[3];
00123 for (int obj = 0; obj < 3; obj++) {
00124 float yma = 1.- (0.17 * gId);
00125 float ymi = yma - 0.15;
00126 pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId),Form("p_%i_%i", obj, gId),
00127 xmi[obj], ymi, xma[obj], yma);
00128 pad[gId][obj]->Draw();
00129 }
00130 }
00131
00132 const int kGains = 3;
00133 const int gainValues[3] = {12, 6, 1};
00134 const int kSides = 2;
00135 const int kBarlRings = EBDetId::MAX_IETA;
00136 const int kBarlWedges = EBDetId::MAX_IPHI;
00137 const int kEndcWedgesX = EEDetId::IX_MAX;
00138 const int kEndcWedgesY = EEDetId::IY_MAX;
00139
00140 TH2F** barrel_m = new TH2F*[3];
00141 TH2F** endc_p_m = new TH2F*[3];
00142 TH2F** endc_m_m = new TH2F*[3];
00143 TH2F** barrel_r = new TH2F*[3];
00144 TH2F** endc_p_r = new TH2F*[3];
00145 TH2F** endc_m_r = new TH2F*[3];
00146 for (int gainId = 0; gainId < kGains; gainId++) {
00147 barrel_m[gainId] = new TH2F(Form("mult_x12 EBm%i",gainId),Form("mult_x%i EB",gainValues[gainId]),360,0,360, 170, -85,85);
00148 endc_p_m[gainId] = new TH2F(Form("mult_x12 EE+m%i",gainId),Form("mult_x%i EE+",gainValues[gainId]),100,1,101,100,1,101);
00149 endc_m_m[gainId] = new TH2F(Form("mult_x12 EE-m%i",gainId),Form("mult_x%i EE-",gainValues[gainId]),100,1,101,100,1,101);
00150 barrel_r[gainId] = new TH2F(Form("shift_x12 EBr%i",gainId),Form("shift_x%i EB",gainValues[gainId]),360,0,360, 170, -85,85);
00151 endc_p_r[gainId] = new TH2F(Form("shift_x12 EE+r%i",gainId),Form("shift_x%i EE+",gainValues[gainId]),100,1,101,100,1,101);
00152 endc_m_r[gainId] = new TH2F(Form("shift_x12 EE-r%i",gainId),Form("shift_x%i EE-",gainValues[gainId]),100,1,101,100,1,101);
00153 }
00154
00155 for (int sign=0; sign < kSides; sign++) {
00156 int thesign = sign==1 ? 1:-1;
00157
00158 for (int ieta=0; ieta<kBarlRings; ieta++) {
00159 for (int iphi=0; iphi<kBarlWedges; iphi++) {
00160 EBDetId id((ieta+1)*thesign, iphi+1);
00161 float y = -1 - ieta;
00162 if(sign == 1) y = ieta;
00163 barrel_m[0]->Fill(iphi, y, object()[id.rawId()].mult_x12);
00164 barrel_r[0]->Fill(iphi, y, object()[id.rawId()].shift_x12);
00165 barrel_m[1]->Fill(iphi, y, object()[id.rawId()].mult_x6);
00166 barrel_r[1]->Fill(iphi, y, object()[id.rawId()].shift_x6);
00167 barrel_m[2]->Fill(iphi, y, object()[id.rawId()].mult_x1);
00168 barrel_r[2]->Fill(iphi, y, object()[id.rawId()].shift_x1);
00169 }
00170 }
00171
00172 for (int ix=0; ix<kEndcWedgesX; ix++) {
00173 for (int iy=0; iy<kEndcWedgesY; iy++) {
00174 if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
00175 EEDetId id(ix+1,iy+1,thesign);
00176 if (thesign==1) {
00177 endc_p_m[0]->Fill(ix+1,iy+1,object()[id.rawId()].mult_x12);
00178 endc_p_r[0]->Fill(ix+1,iy+1,object()[id.rawId()].shift_x12);
00179 endc_p_m[1]->Fill(ix+1,iy+1,object()[id.rawId()].mult_x6);
00180 endc_p_r[1]->Fill(ix+1,iy+1,object()[id.rawId()].shift_x6);
00181 endc_p_m[2]->Fill(ix+1,iy+1,object()[id.rawId()].mult_x1);
00182 endc_p_r[2]->Fill(ix+1,iy+1,object()[id.rawId()].shift_x1);
00183 }
00184 else{
00185 endc_m_m[0]->Fill(ix+1,iy+1,object()[id.rawId()].mult_x12);
00186 endc_m_r[0]->Fill(ix+1,iy+1,object()[id.rawId()].shift_x12);
00187 endc_m_m[1]->Fill(ix+1,iy+1,object()[id.rawId()].mult_x6);
00188 endc_m_r[1]->Fill(ix+1,iy+1,object()[id.rawId()].shift_x6);
00189 endc_m_m[2]->Fill(ix+1,iy+1,object()[id.rawId()].mult_x1);
00190 endc_m_r[2]->Fill(ix+1,iy+1,object()[id.rawId()].shift_x1);
00191 }
00192 }
00193 }
00194 }
00195
00196
00197
00198
00199
00200
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 < 3; gId++) {
00228 pad[gId][0]->cd();
00229 endc_m_m[gId]->SetStats(0);
00230
00231
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 pad[gId + 3][0]->cd();
00242 endc_m_r[gId]->SetStats(0);
00243
00244
00245 endc_m_r[gId]->Draw("colz");
00246 for ( int i=0; i<201; i=i+1) {
00247 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
00248 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00249 l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
00250 ixSectorsEE[i+1], iySectorsEE[i+1]);
00251 }
00252 }
00253
00254 pad[gId][1]->cd();
00255 barrel_m[gId]->SetStats(0);
00256
00257
00258 barrel_m[gId]->Draw("colz");
00259 for(int i = 0; i <17; i++) {
00260 Double_t x = 20.+ (i *20);
00261 l = new TLine(x,-85.,x,86.);
00262 l->Draw();
00263 }
00264 l = new TLine(0.,0.,360.,0.);
00265 l->Draw();
00266 pad[gId + 3][1]->cd();
00267 barrel_r[gId]->SetStats(0);
00268
00269
00270 barrel_r[gId]->Draw("colz");
00271 for(int i = 0; i <17; i++) {
00272 Double_t x = 20.+ (i *20);
00273 l = new TLine(x,-85.,x,86.);
00274 l->Draw();
00275 }
00276 l = new TLine(0.,0.,360.,0.);
00277 l->Draw();
00278
00279 pad[gId][2]->cd();
00280 endc_p_m[gId]->SetStats(0);
00281
00282
00283 endc_p_m[gId]->Draw("colz");
00284 for ( int i=0; i<201; i=i+1) {
00285 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
00286 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00287 l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
00288 ixSectorsEE[i+1], iySectorsEE[i+1]);
00289 }
00290 }
00291 pad[gId + 3][2]->cd();
00292 endc_p_r[gId]->SetStats(0);
00293
00294
00295 endc_p_r[gId]->Draw("colz");
00296 for ( int i=0; i<201; i=i+1) {
00297 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
00298 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00299 l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
00300 ixSectorsEE[i+1], iySectorsEE[i+1]);
00301 }
00302 }
00303 }
00304
00305 canvas.SaveAs(filename.c_str());
00306 return filename;
00307 }
00308
00309 }
00310
00311 PYTHON_WRAPPER(EcalTPGLinearizationConst,EcalTPGLinearizationConst);