00001 #include "CondFormats/EcalObjects/interface/EcalGainRatios.h"
00002 #include "CondTools/Ecal/interface/EcalGainRatiosXMLTranslator.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<EcalGainRatios>: public BaseValueExtractor<EcalGainRatios> {
00025 public:
00026
00027 typedef EcalGainRatios 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
00043 template<>
00044 std::string
00045 PayLoadInspector<EcalGainRatios>::dump() const {
00046
00047
00048 std::stringstream ss;
00049 EcalCondHeader header;
00050 ss<<EcalGainRatiosXMLTranslator::dumpXML(header,object());
00051 return ss.str();
00052
00053 }
00054
00055 class EcalGainRatiosHelper: public EcalPyWrapperHelper<EcalMGPAGainRatio>{
00056 public:
00057 EcalGainRatiosHelper():EcalPyWrapperHelper<EcalObject>(2){}
00058 protected:
00059
00060
00061 typedef EcalMGPAGainRatio EcalObject;
00062
00063 type_vValues getValues( const std::vector<EcalObject> & vItems)
00064 {
00065
00066
00067
00068 type_vValues vValues(total_values);
00069
00070
00071 vValues[0].first = "gain12Over6";
00072 vValues[1].first = "gain6Over1";
00073
00074 vValues[0].second = .0;
00075 vValues[1].second = .0;
00076
00077
00078 for(std::vector<EcalObject>::const_iterator iItems = vItems.begin(); iItems != vItems.end(); ++iItems){
00079
00080 vValues[0].second += iItems->gain12Over6();
00081 vValues[1].second += iItems->gain6Over1();
00082 }
00083 return vValues;
00084 }
00085 };
00086
00087 template<>
00088 std::string PayLoadInspector<EcalGainRatios>::summary() const {
00089 std::stringstream ss;
00090 EcalGainRatiosHelper helper;
00091 ss << helper.printBarrelsEndcaps(object().barrelItems(), object().endcapItems());
00092 return ss.str();
00093 }
00094
00095
00096 template<>
00097 std::string PayLoadInspector<EcalGainRatios>::plot(std::string const & filename,
00098 std::string const &,
00099 std::vector<int> const&,
00100 std::vector<float> const& ) const {
00101 gStyle->SetPalette(1);
00102 TCanvas canvas("CC map","CC map",840,600);
00103 float xmi[3] = {0.0 , 0.22, 0.78};
00104 float xma[3] = {0.22, 0.78, 1.00};
00105 TPad*** pad = new TPad**[2];
00106 for (int gId = 0; gId < 2; gId++) {
00107 pad[gId] = new TPad*[3];
00108 for (int obj = 0; obj < 3; obj++) {
00109 float yma = 1.- (0.34 * gId);
00110 float ymi = yma - 0.32;
00111 pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId),Form("p_%i_%i", obj, gId),
00112 xmi[obj], ymi, xma[obj], yma);
00113 pad[gId][obj]->Draw();
00114 }
00115 }
00116 TPad** pad1 = new TPad*[4];
00117 for (int obj = 0; obj < 4; obj++) {
00118 float xmi = 0.26 * obj;
00119 float xma = xmi + 0.22;
00120 pad1[obj] = new TPad(Form("p1_%i", obj),Form("p1_%i", obj),
00121 xmi, 0.0, xma, 0.32);
00122 pad1[obj]->Draw();
00123 }
00124 const int kSides = 2;
00125 const int kBarlRings = EBDetId::MAX_IETA;
00126 const int kBarlWedges = EBDetId::MAX_IPHI;
00127 const int kEndcWedgesX = EEDetId::IX_MAX;
00128 const int kEndcWedgesY = EEDetId::IY_MAX;
00129
00130 TH2F* barrel_12O6 = new TH2F("EB_12O6","EB gain 12/6",360,0,360, 170, -85,85);
00131 TH2F* endc_p_12O6 = new TH2F("EE+_12O6","EE+ gain 12/6",100,1,101,100,1,101);
00132 TH2F* endc_m_12O6 = new TH2F("EE-_12O6","EE- gain 12/6",100,1,101,100,1,101);
00133 TH2F* barrel_6O1 = new TH2F("EB_6O1","EB gain 6/1",360,0,360, 170, -85,85);
00134 TH2F* endc_p_6O1 = new TH2F("EE+_6O1","EE+ gain 6/1",100,1,101,100,1,101);
00135 TH2F* endc_m_6O1 = new TH2F("EE-_6O1","EE- gain 6/1",100,1,101,100,1,101);
00136 TH1F* b_12O6 = new TH1F("b_12O6","EB gain 12/6", 50, 1.8, 2.1);
00137 TH1F* e_12O6 = new TH1F("e_12O6","EE gain 12/6", 50, 1.8, 2.1);
00138 TH1F* b_6O1 = new TH1F("b_6O1","EB gain 6/1", 50, 5.35, 5.85);
00139 TH1F* e_6O1 = new TH1F("e_6O1","EE gain 6/1", 50, 5.35, 5.85);
00140
00141 for (int sign=0; sign < kSides; sign++) {
00142 int thesign = sign==1 ? 1:-1;
00143
00144 for (int ieta=0; ieta<kBarlRings; ieta++) {
00145 for (int iphi=0; iphi<kBarlWedges; iphi++) {
00146 EBDetId id((ieta+1)*thesign, iphi+1);
00147 float y = -1 - ieta;
00148 if(sign == 1) y = ieta;
00149 barrel_12O6->Fill(iphi, y, object()[id.rawId()].gain12Over6());
00150 barrel_6O1->Fill(iphi, y, object()[id.rawId()].gain6Over1());
00151 b_12O6->Fill(object()[id.rawId()].gain12Over6());
00152 b_6O1->Fill(object()[id.rawId()].gain6Over1());
00153 }
00154 }
00155
00156 for (int ix=0; ix<kEndcWedgesX; ix++) {
00157 for (int iy=0; iy<kEndcWedgesY; iy++) {
00158 if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
00159 EEDetId id(ix+1,iy+1,thesign);
00160 if (thesign==1) {
00161 endc_p_12O6->Fill(ix+1,iy+1,object()[id.rawId()].gain12Over6());
00162 endc_p_6O1->Fill(ix+1,iy+1,object()[id.rawId()].gain6Over1());
00163 }
00164 else{
00165 endc_m_12O6->Fill(ix+1,iy+1,object()[id.rawId()].gain12Over6());
00166 endc_m_6O1->Fill(ix+1,iy+1,object()[id.rawId()].gain6Over1());
00167 }
00168 e_12O6->Fill(object()[id.rawId()].gain12Over6());
00169 e_6O1->Fill(object()[id.rawId()].gain6Over1());
00170 }
00171 }
00172 }
00173
00174 TLine* l = new TLine(0., 0., 0., 0.);
00175 l->SetLineWidth(1);
00176 int ixSectorsEE[202] = {
00177 62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42,
00178 41, 41, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 46, 46, 56, 56, 58, 58, 59, 59,
00179 60, 60, 61, 61, 62, 62, 0,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81,
00180 81, 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9,
00181 9, 6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26,
00182 26, 36, 36, 41, 41, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 93, 93, 96,
00183 96, 98, 98,101,101, 0, 62, 66, 66, 71, 71, 81, 81, 91, 91, 93, 0, 62, 66, 66,
00184 91, 91, 98, 0, 58, 61, 61, 66, 66, 71, 71, 76, 76, 81, 81, 0, 51, 51, 0, 44,
00185 41, 41, 36, 36, 31, 31, 26, 26, 21, 21, 0, 40, 36, 36, 11, 11, 4, 0, 40, 36,
00186 36, 31, 31, 21, 21, 11, 11, 9, 0, 46, 46, 41, 41, 36, 36, 0, 56, 56, 61, 61, 66, 66};
00187
00188 int iySectorsEE[202] = {
00189 51, 56, 56, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 61, 61, 60, 60, 59, 59, 58,
00190 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 41, 41, 40, 40, 41, 41, 42, 42, 43,
00191 43, 44, 44, 46, 46, 51, 0, 51, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88,
00192 93, 93, 96, 96, 98, 98,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 81,
00193 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9, 9,
00194 6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26, 26,
00195 36, 36, 41, 41, 51, 0, 46, 46, 41, 41, 36, 36, 31, 31, 26, 26, 0, 51, 51, 56,
00196 56, 61, 61, 0, 61, 61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 62,101, 0, 61,
00197 61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 51, 51, 56, 56, 61, 61, 0, 46, 46,
00198 41, 41, 36, 36, 31, 31, 26, 26, 0, 40, 31, 31, 16, 16, 6, 0, 40, 31, 31, 16, 16, 6};
00199
00200 float min12O6 = 1.9, max12O6 = 2.0, min6O1 = 5.4, max6O1 = 5.8;
00201 pad[0][0]->cd();
00202 endc_m_12O6->SetStats(0);
00203 endc_m_12O6->SetMaximum(max12O6);
00204 endc_m_12O6->SetMinimum(min12O6);
00205 endc_m_12O6->Draw("colz");
00206 for ( int i=0; i<201; i=i+1) {
00207 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
00208 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00209 l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
00210 ixSectorsEE[i+1], iySectorsEE[i+1]);
00211 l->SetLineWidth(0.2);
00212 }
00213 }
00214 pad[0][1]->cd();
00215 barrel_12O6->SetStats(0);
00216 barrel_12O6->SetMaximum(max12O6);
00217 barrel_12O6->SetMinimum(min12O6);
00218 barrel_12O6->Draw("colz");
00219 for(int i = 0; i <17; i++) {
00220 Double_t x = 20.+ (i *20);
00221 l = new TLine(x,-85.,x,86.);
00222 l->Draw();
00223 }
00224 l = new TLine(0.,0.,360.,0.);
00225 l->Draw();
00226 pad[0][2]->cd();
00227 endc_p_12O6->SetStats(0);
00228 endc_p_12O6->SetMaximum(max12O6);
00229 endc_p_12O6->SetMinimum(min12O6);
00230 endc_p_12O6->Draw("colz");
00231 for ( int i=0; i<201; i=i+1) {
00232 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
00233 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00234 l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
00235 ixSectorsEE[i+1], iySectorsEE[i+1]);
00236 l->SetLineWidth(0.2);
00237 }
00238 }
00239 pad[1][0]->cd();
00240 endc_m_6O1->SetStats(0);
00241 endc_m_6O1->SetMaximum(max6O1);
00242 endc_m_6O1->SetMinimum(min6O1);
00243 endc_m_6O1->Draw("colz");
00244 for ( int i=0; i<201; i=i+1) {
00245 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
00246 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00247 l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
00248 ixSectorsEE[i+1], iySectorsEE[i+1]);
00249 l->SetLineWidth(0.2);
00250 }
00251 }
00252 pad[1][1]->cd();
00253 barrel_6O1->SetStats(0);
00254 barrel_6O1->SetMaximum(max6O1);
00255 barrel_6O1->SetMinimum(min6O1);
00256 barrel_6O1->Draw("colz");
00257 for(int i = 0; i <17; i++) {
00258 Double_t x = 20.+ (i *20);
00259 l = new TLine(x,-85.,x,86.);
00260 l->Draw();
00261 }
00262 l = new TLine(0.,0.,360.,0.);
00263 l->Draw();
00264 pad[1][2]->cd();
00265 endc_p_6O1->SetStats(0);
00266 endc_p_6O1->SetMaximum(max6O1);
00267 endc_p_6O1->SetMinimum(min6O1);
00268 endc_p_6O1->Draw("colz");
00269 for ( int i=0; i<201; i=i+1) {
00270 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
00271 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00272 l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
00273 ixSectorsEE[i+1], iySectorsEE[i+1]);
00274 l->SetLineWidth(0.2);
00275 }
00276 }
00277
00278 gStyle->SetOptStat(111110);
00279 pad1[0]->cd();
00280 b_12O6->Draw();
00281 pad1[0]->Update();
00282 TPaveStats *st = (TPaveStats*)b_12O6->FindObject("stats");
00283 st->SetX1NDC(0.6);
00284 st->SetY1NDC(0.75);
00285 pad1[1]->cd();
00286 e_12O6->Draw();
00287 pad1[0]->Update();
00288 st = (TPaveStats*)e_12O6->FindObject("stats");
00289 st->SetX1NDC(0.6);
00290 st->SetY1NDC(0.75);
00291 pad1[2]->cd();
00292 b_6O1->Draw();
00293 pad1[0]->Update();
00294 st = (TPaveStats*)b_6O1->FindObject("stats");
00295 st->SetX1NDC(0.6);
00296 st->SetY1NDC(0.75);
00297 pad1[3]->cd();
00298 e_6O1->Draw();
00299 pad1[0]->Update();
00300 st = (TPaveStats*)e_6O1->FindObject("stats");
00301 st->SetX1NDC(0.6);
00302 st->SetY1NDC(0.75);
00303
00304 canvas.SaveAs(filename.c_str());
00305 return filename;
00306 }
00307
00308
00309 }
00310
00311 PYTHON_WRAPPER(EcalGainRatios,EcalGainRatios);