CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/CondCore/EcalPlugins/plugins/EcalTPGPedestalsPyWrapper.cc

Go to the documentation of this file.
00001 #include "CondFormats/EcalObjects/interface/EcalTPGPedestals.h"
00002 //#include "CondTools/Ecal/interface/EcalTPGPedestalsXMLTranslator.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<EcalTPGPedestals>: public  BaseValueExtractor<EcalTPGPedestals> {
00025   public:
00026 
00027     typedef EcalTPGPedestals Class;
00028     typedef ExtractWhat<Class> What;
00029     static What what() { return What();}
00030 
00031     ValueExtractor(){}
00032     ValueExtractor(What const & what)
00033     {
00034       // here one can make stuff really complicated...
00035     }
00036     void compute(Class const & it){
00037     }
00038   private:
00039   
00040   };
00041  
00042         class EcalTPGPedestalsHelper: public EcalPyWrapperHelper<EcalTPGPedestal>{
00043         public:
00044                 EcalTPGPedestalsHelper():EcalPyWrapperHelper<EcalObject>(3){}
00045         protected:
00046 
00047                 //change me
00048                 typedef EcalTPGPedestal EcalObject;
00049 
00050                 type_vValues getValues( const std::vector<EcalObject> & vItems)
00051                 {
00052                         type_vValues vValues(total_values);
00053 
00054                         //change us
00055                         vValues[0].first = "mean_x12";
00056                         vValues[1].first = "mean_x6";
00057                         vValues[2].first = "mean_x1";   
00058 
00059                         vValues[0].second = .0;
00060                         vValues[1].second = .0;
00061                         vValues[2].second = .0;
00062                         
00063                         //get info:
00064                         for(std::vector<EcalObject>::const_iterator iItems = vItems.begin(); iItems != vItems.end(); ++iItems){
00065                                 //change us
00066                                 vValues[0].second += iItems->mean_x12;
00067                                 vValues[1].second += iItems->mean_x6;
00068                                 vValues[2].second += iItems->mean_x1;
00069                         }
00070                         return vValues;
00071                 }
00072         };
00073 
00074   template<>
00075   std::string PayLoadInspector<EcalTPGPedestals>::summary() const {
00076         std::stringstream ss;
00077         EcalTPGPedestalsHelper helper;
00078         ss << helper.printBarrelsEndcaps(object().barrelItems(), object().endcapItems());
00079         return ss.str();
00080   }
00081 
00082         template<>
00083         std::string PayLoadInspector<EcalTPGPedestals>::plot(std::string const & filename,
00084                 std::string const &, 
00085                 std::vector<int> const&, 
00086                 std::vector<float> const& ) const {
00087                         gStyle->SetPalette(1);
00088                         const int TOTAL_IMAGES = 3;
00089                         const int TOTAL_PADS = 3;
00090 
00091                         //    TCanvas canvas("CC map","CC map",840,600);
00092                         const float IMG_SIZE = 1.3;
00093                         TCanvas canvas("CC map","CC map",800*IMG_SIZE + 100, 200 * TOTAL_IMAGES*IMG_SIZE);//800, 1200
00094 
00095                         float xmi[3] = {0.0 , 0.22, 0.78};
00096                         float xma[3] = {0.22, 0.78, 1.00};
00097 
00098 
00099                         TPad*** pad = new TPad**[TOTAL_IMAGES];
00100                         for (int gId = 0; gId < TOTAL_IMAGES; gId++) {
00101                                 pad[gId] = new TPad*[TOTAL_PADS];
00102                                 for (int obj = 0; obj < TOTAL_PADS; obj++) {
00103                                         float yma = 1. - (0.33 * gId);  //1.- (0.17 * gId);
00104                                         float ymi = yma - 0.33; //yma - 0.15;
00105                                         pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId),Form("p_%i_%i", obj, gId),
00106                                                 xmi[obj], ymi, xma[obj], yma);
00107                                         pad[gId][obj]->Draw();
00108                                 }
00109                         }
00110 
00111                         const int kGains       = 3;
00112                         const int gainValues[3] = {12, 6, 1};
00113                         const int kSides       = 2;
00114                         const int kBarlRings   = EBDetId::MAX_IETA;
00115                         const int kBarlWedges  = EBDetId::MAX_IPHI;
00116                         const int kEndcWedgesX = EEDetId::IX_MAX;
00117                         const int kEndcWedgesY = EEDetId::IY_MAX;
00118 
00119                         TH2F** barrel_m = new TH2F*[3];
00120                         TH2F** endc_p_m = new TH2F*[3];
00121                         TH2F** endc_m_m = new TH2F*[3];
00122                         //TH2F** barrel_r = new TH2F*[3];
00123                         //TH2F** endc_p_r = new TH2F*[3];
00124                         //TH2F** endc_m_r = new TH2F*[3];
00125                         std::string variableName = "mean_x";
00126                         for (int gainId = 0; gainId < kGains; gainId++) {
00127                                 barrel_m[gainId] = new TH2F(Form((variableName + "EBm%i").c_str(),gainId),Form((variableName + "%i EB").c_str(),gainValues[gainId]),360,0,360, 170, -85,85);
00128                                 endc_p_m[gainId] = new TH2F(Form((variableName + "EE+m%i").c_str(),gainId),Form((variableName + "%i EE+").c_str(),gainValues[gainId]),100,1,101,100,1,101);
00129                                 endc_m_m[gainId] = new TH2F(Form((variableName + "EE-m%i").c_str(),gainId),Form((variableName + "%i EE-").c_str(),gainValues[gainId]),100,1,101,100,1,101);
00130                                 //barrel_r[gainId] = new TH2F(Form("EBr%i",gainId),Form("rms %i EB",gainValues[gainId]),360,0,360, 170, -85,85);
00131                                 //endc_p_r[gainId] = new TH2F(Form("EE+r%i",gainId),Form("rms %i EE+",gainValues[gainId]),100,1,101,100,1,101);
00132                                 //endc_m_r[gainId] = new TH2F(Form("EE-r%i",gainId),Form("rms %i EE-",gainValues[gainId]),100,1,101,100,1,101);
00133                         }
00134 
00135                         for (int sign=0; sign < kSides; sign++) {
00136                                 int thesign = sign==1 ? 1:-1;
00137 
00138                                 for (int ieta=0; ieta<kBarlRings; ieta++) {
00139                                         for (int iphi=0; iphi<kBarlWedges; iphi++) {
00140                                                 EBDetId id((ieta+1)*thesign, iphi+1);
00141                                                 float y = -1 - ieta;
00142                                                 if(sign == 1) y = ieta;
00143                                                 barrel_m[0]->Fill(iphi, y, object()[id.rawId()].mean_x12);
00144                                                 barrel_m[1]->Fill(iphi, y, object()[id.rawId()].mean_x6);
00145                                                 barrel_m[2]->Fill(iphi, y, object()[id.rawId()].mean_x1);
00146                                                 //barrel_r[0]->Fill(iphi, y, object()[id.rawId()].rms_x12);
00147                                                 //barrel_m[1]->Fill(iphi, y, object()[id.rawId()].mean_x6);
00148                                                 //barrel_r[1]->Fill(iphi, y, object()[id.rawId()].rms_x6);
00149                                                 //barrel_m[2]->Fill(iphi, y, object()[id.rawId()].mean_x1);
00150                                                 //barrel_r[2]->Fill(iphi, y, object()[id.rawId()].rms_x1);
00151                                         }   // iphi
00152                                 }       // ieta
00153 
00154                                 for (int ix=0; ix<kEndcWedgesX; ix++) {
00155                                         for (int iy=0; iy<kEndcWedgesY; iy++) {
00156                                                 if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
00157                                                 EEDetId id(ix+1,iy+1,thesign);
00158                                                 if (thesign==1) {
00159                                                         endc_p_m[0]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x12);
00160                                                         endc_p_m[1]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x6);
00161                                                         endc_p_m[2]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x1);
00162                                                         //endc_p_r[0]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x12);
00163                                                         //endc_p_m[1]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x6);
00164                                                         //endc_p_r[1]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x6);
00165                                                         //endc_p_m[2]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x1);
00166                                                         //endc_p_r[2]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x1);
00167                                                 }
00168                                                 else{ 
00169                                                         endc_m_m[0]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x12);
00170                                                         endc_m_m[1]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x6);
00171                                                         endc_m_m[2]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x1);
00172                                                         //endc_m_r[0]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x12);
00173                                                         //endc_m_m[1]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x6);
00174                                                         //endc_m_r[1]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x6);
00175                                                         //endc_m_m[2]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x1);
00176                                                         //endc_m_r[2]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x1);
00177                                                 }
00178                                         }  // iy
00179                                 }   // ix
00180                         }    // side
00181 
00182                         //canvas.cd(1);
00183                         //float bmin[3] ={0.7, 0.5, 0.4};
00184                         //float bmax[3] ={1.7, 1.0, 0.8};
00185                         //float emin[3] ={1.5, 0.8, 0.4};
00186                         //float emax[3] ={2.5, 1.5, 0.8};
00187                         TLine* l = new TLine(0., 0., 0., 0.);
00188                         l->SetLineWidth(1);
00189                         int ixSectorsEE[202] = {
00190                                 62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 
00191                                 41, 41, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 46, 46, 56, 56, 58, 58, 59, 59, 
00192                                 60, 60, 61, 61, 62, 62,  0,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 
00193                                 81, 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14,  9,
00194                                 9,  6,  6,  4,  4,  1,  1,  4,  4,  6,  6,  9,  9, 14, 14, 16, 16, 21, 21, 26, 
00195                                 26, 36, 36, 41, 41, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 93, 93, 96, 
00196                                 96, 98, 98,101,101,  0, 62, 66, 66, 71, 71, 81, 81, 91, 91, 93,  0, 62, 66, 66, 
00197                                 91, 91, 98,  0, 58, 61, 61, 66, 66, 71, 71, 76, 76, 81, 81,  0, 51, 51,  0, 44, 
00198                                 41, 41, 36, 36, 31, 31, 26, 26, 21, 21,  0, 40, 36, 36, 11, 11,  4,  0, 40, 36, 
00199                                 36, 31, 31, 21, 21, 11, 11,  9,  0, 46, 46, 41, 41, 36, 36,  0, 56, 56, 61, 61, 66, 66};
00200 
00201                                 int iySectorsEE[202] = {
00202                                         51, 56, 56, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 61, 61, 60, 60, 59, 59, 58, 
00203                                         58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 41, 41, 40, 40, 41, 41, 42, 42, 43, 
00204                                         43, 44, 44, 46, 46, 51,  0, 51, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 
00205                                         93, 93, 96, 96, 98, 98,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 81, 
00206                                         76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14,  9,  9, 
00207                                         6,  6,  4,  4,  1,  1,  4,  4,  6,  6,  9,  9, 14, 14, 16, 16, 21, 21, 26, 26, 
00208                                         36, 36, 41, 41, 51,  0, 46, 46, 41, 41, 36, 36, 31, 31, 26, 26,  0, 51, 51, 56, 
00209                                         56, 61, 61,  0, 61, 61, 66, 66, 71, 71, 76, 76, 86, 86, 88,  0, 62,101,  0, 61, 
00210                                         61, 66, 66, 71, 71, 76, 76, 86, 86, 88,  0, 51, 51, 56, 56, 61, 61,  0, 46, 46, 
00211                                         41, 41, 36, 36, 31, 31, 26, 26,  0, 40, 31, 31, 16, 16,  6,  0, 40, 31, 31, 16, 16,  6};
00212 
00213                                         for (int gId = 0; gId < TOTAL_IMAGES; gId++) {//was 3
00214                                                 pad[gId][0]->cd();
00215                                                 endc_m_m[gId]->SetStats(0);
00216                                                 //endc_m_m[gId]->SetMaximum(225);
00217                                                 //endc_m_m[gId]->SetMinimum(175);
00218                                                 endc_m_m[gId]->Draw("colz");
00219                                                 for ( int i=0; i<201; i=i+1) {
00220                                                         if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) && 
00221                                                                 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00222                                                                         l->DrawLine(ixSectorsEE[i], iySectorsEE[i], 
00223                                                                                 ixSectorsEE[i+1], iySectorsEE[i+1]);
00224                                                                         l->SetLineWidth(0.2);
00225                                                         }
00226                                                 }
00227 
00228                                                 //pad[gId + 3][0]->cd();
00229                                                 //endc_m_r[gId]->SetStats(0);
00230                                                 //endc_m_r[gId]->SetMaximum(emax[gId]);
00231                                                 //endc_m_r[gId]->SetMinimum(emin[gId]);
00232                                                 //endc_m_r[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                                                 //      }
00239                                                 //}
00240 
00241                                                 //canvas.cd(2);
00242                                                 pad[gId][1]->cd();
00243                                                 barrel_m[gId]->SetStats(0);
00244                                                 //barrel_m[gId]->SetMaximum(225);
00245                                                 //barrel_m[gId]->SetMinimum(175);
00246                                                 barrel_m[gId]->Draw("colz");
00247                                                 for(int i = 0; i <17; i++) {
00248                                                         Double_t x = 20.+ (i *20);
00249                                                         l = new TLine(x,-85.,x,86.);
00250                                                         l->Draw();
00251                                                 }
00252                                                 l = new TLine(0.,0.,360.,0.);
00253                                                 l->Draw();
00254 
00255                                                 //pad[gId + 3][1]->cd();
00256                                                 //barrel_r[gId]->SetStats(0);
00257                                                 //barrel_r[gId]->SetMaximum(bmax[gId]);
00258                                                 //barrel_r[gId]->SetMinimum(bmin[gId]);
00259                                                 //barrel_r[gId]->Draw("colz");
00260                                                 //for(int i = 0; i <17; i++) {
00261                                                 //      Double_t x = 20.+ (i *20);
00262                                                 //      l = new TLine(x,-85.,x,86.);
00263                                                 //      l->Draw();
00264                                                 //}
00265                                                 //l = new TLine(0.,0.,360.,0.);
00266                                                 //l->Draw();
00267 
00268                                                 //canvas.cd(3);
00269                                                 pad[gId][2]->cd();
00270                                                 endc_p_m[gId]->SetStats(0);
00271                                                 //endc_p_m[gId]->SetMaximum(225);
00272                                                 //endc_p_m[gId]->SetMinimum(175);
00273                                                 endc_p_m[gId]->Draw("colz");
00274                                                 for ( int i=0; i<201; i=i+1) {
00275                                                         if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) && 
00276                                                                 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00277                                                                         l->DrawLine(ixSectorsEE[i], iySectorsEE[i], 
00278                                                                                 ixSectorsEE[i+1], iySectorsEE[i+1]);
00279                                                         }
00280                                                 }
00281 
00282                                         //      pad[gId + 3][2]->cd();
00283                                         //      endc_p_r[gId]->SetStats(0);
00284                                         //      endc_p_r[gId]->SetMaximum(emax[gId]);
00285                                         //      endc_p_r[gId]->SetMinimum(emin[gId]);
00286                                         //      endc_p_r[gId]->Draw("colz");
00287                                         //      for ( int i=0; i<201; i=i+1) {
00288                                         //              if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) && 
00289                                         //                      (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00290                                         //                              l->DrawLine(ixSectorsEE[i], iySectorsEE[i], 
00291                                         //                                      ixSectorsEE[i+1], iySectorsEE[i+1]);
00292                                         //              }
00293                                         //      }
00294                                         }
00295 
00296                                         canvas.SaveAs(filename.c_str());
00297                                         return filename;
00298         }  // plot
00299 
00300 }
00301 
00302 PYTHON_WRAPPER(EcalTPGPedestals,EcalTPGPedestals);