CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/CondCore/EcalPlugins/plugins/EcalTPGLinearizationConstPyWrapper.cc

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