CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/CondCore/EcalPlugins/plugins/EcalLaserAPDPNRatiosPyWrapper.cc

Go to the documentation of this file.
00001 
00002 #include "CondFormats/EcalObjects/interface/EcalLaserAPDPNRatios.h"
00003 
00004 #include "CondTools/Ecal/interface/EcalLaserAPDPNRatiosXMLTranslator.h"
00005 #include "CondTools/Ecal/interface/EcalCondHeader.h"
00006 #include "TH2F.h"
00007 #include "TCanvas.h"
00008 #include "TLine.h"
00009 #include "TStyle.h"
00010 #include "TPave.h"
00011 #include "TPaveStats.h"
00012 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00013 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00014 
00015 #include "CondCore/Utilities/interface/PayLoadInspector.h"
00016 #include "CondCore/Utilities/interface/InspectorPythonWrapper.h"
00017 
00018 
00019 #include <time.h>
00020 #include <string>
00021 #include <fstream>
00022 
00023 #include "CondCore/EcalPlugins/plugins/EcalPyWrapperFunctions.h"
00024 
00025 
00026 
00027 namespace cond {
00028 
00029   template<>
00030   class ValueExtractor<EcalLaserAPDPNRatios>: public  BaseValueExtractor<EcalLaserAPDPNRatios> {
00031   public:
00032 
00033     typedef EcalLaserAPDPNRatios Class;
00034     typedef ExtractWhat<Class> What;
00035     static What what() { return What();}
00036 
00037     ValueExtractor(){}
00038     ValueExtractor(What const & what)
00039     {
00040       // here one can make stuff really complicated...
00041     }
00042     void compute(Class const & it){
00043     }
00044   private:
00045   
00046   };
00047 
00048 
00049   template<>
00050   std::string
00051   PayLoadInspector<EcalLaserAPDPNRatios>::dump() const {
00052 
00053     std::stringstream ss;
00054     EcalCondHeader header;
00055     ss<<EcalLaserAPDPNRatiosXMLTranslator::dumpXML(header,object());
00056     return ss.str();   
00057  
00058   }
00059   
00060 
00061 
00062   class EcalLaserAPDPNRatiosHelper: public EcalPyWrapperHelper<EcalLaserAPDPNRatios::EcalLaserAPDPNpair>{
00063         public:
00064                 EcalLaserAPDPNRatiosHelper():EcalPyWrapperHelper<EcalObject>(3){}
00065         protected:
00066     typedef EcalLaserAPDPNRatios::EcalLaserAPDPNpair EcalObject;
00067     type_vValues getValues( const std::vector<EcalLaserAPDPNRatios::EcalLaserAPDPNpair> & vItems)
00068                 {
00069                         //unsigned int totalValues = 6; 
00070                         type_vValues vValues(total_values);
00071 
00072                         vValues[0].first = "p1";
00073                         vValues[1].first = "p2";
00074                         vValues[2].first = "p3";
00075                         
00076                         vValues[0].second = .0;
00077                         vValues[1].second = .0;
00078                         vValues[2].second = .0;
00079 
00080                         
00081                         //get info:
00082                         for(std::vector<EcalLaserAPDPNRatios::EcalLaserAPDPNpair>::const_iterator iItems = vItems.begin(); iItems != vItems.end(); ++iItems){
00083                                 vValues[0].second += iItems->p1;
00084                                 vValues[1].second += iItems->p2;
00085                                 vValues[2].second += iItems->p3;
00086 
00087                         }
00088                         return vValues;
00089                 }
00090         };
00091 
00092 
00093 
00094 
00095 
00096   template<>
00097   std::string PayLoadInspector<EcalLaserAPDPNRatios>::summary() const {
00098     std::stringstream ss;
00099 
00100 
00101                 EcalLaserAPDPNRatiosHelper helper;
00102                 ss << helper.printBarrelsEndcaps(object().getLaserMap().barrelItems(), object().getLaserMap().endcapItems());
00103                 ss<< std::endl;
00104 
00105 
00106                 const EcalLaserAPDPNRatios::EcalLaserTimeStampMap& laserTimeMap = 
00107                   object().getTimeMap();
00108 
00109 
00110                 for (int i=0; i<92; i++) {
00111                   EcalLaserAPDPNRatios::EcalLaserTimeStamp timestamp = laserTimeMap[i];
00112 
00113                   
00114                   unsigned int x1= ((timestamp.t1).value() >> 32) ;
00115                   std::time_t tt1 = x1;
00116 
00117 
00118                   ss<<"T1["<<i<<"]=" << timestamp.t1.value()<<" "<< x1<< std::ctime(&tt1) ;
00119 
00120                   unsigned int x2= (timestamp.t2).value() >> 32;
00121                   std::time_t tt2 = x2;
00122 
00123                   ss<<"  T2["<<i<<"]=" << timestamp.t2.value()<< " "<<x2<<std::ctime(&tt2) ;
00124 
00125                   unsigned int x3= (timestamp.t3).value() >> 32 ;
00126                   std::time_t tt3 = x3;
00127 
00128                   ss  <<"  T3["<<i<<"]="  << timestamp.t3.value()<<" "<< x3<< std::ctime(&tt3) << std::endl;
00129 
00130                 }
00131 
00132                 return ss.str();
00133     return ss.str();
00134   }
00135   
00136 
00137 
00138         template<>
00139         std::string PayLoadInspector<EcalLaserAPDPNRatios>::plot(std::string const & filename,
00140                 std::string const &, 
00141                 std::vector<int> const&, 
00142                 std::vector<float> const& ) const {
00143                         gStyle->SetPalette(1);
00144                         //    TCanvas canvas("CC map","CC map",840,600);
00145                         TCanvas canvas("CC map","CC map",800,1200);
00146 
00147                         float xmi[3] = {0.0 , 0.22, 0.78};
00148                         float xma[3] = {0.22, 0.78, 1.00};
00149                         TPad*** pad = new TPad**[3];
00150                         for (int gId = 0; gId < 3; gId++) {
00151                                 pad[gId] = new TPad*[3];
00152                                 for (int obj = 0; obj < 3; obj++) {
00153                                         float yma = 1.- (0.32 * gId);
00154                                         float ymi = yma - 0.30;
00155                                         pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId),Form("p_%i_%i", obj, gId),
00156                                                 xmi[obj], ymi, xma[obj], yma);
00157                                         pad[gId][obj]->Draw();
00158                                 }
00159                         }
00160 
00161                         const int kGains       = 3;
00162                         const int gainValues[3] = {1, 2, 3};
00163                         const int kSides       = 2;
00164                         const int kBarlRings   = EBDetId::MAX_IETA;
00165                         const int kBarlWedges  = EBDetId::MAX_IPHI;
00166                         const int kEndcWedgesX = EEDetId::IX_MAX;
00167                         const int kEndcWedgesY = EEDetId::IY_MAX;
00168 
00169                         TH2F** barrel = new TH2F*[3];
00170                         TH2F** endc_p = new TH2F*[3];
00171                         TH2F** endc_m = new TH2F*[3];
00172 
00173                         for (int gainId = 0; gainId < kGains; gainId++) {
00174                           barrel[gainId] = new TH2F(Form("EBp%i", gainValues[gainId]),Form("EBp%i", gainValues[gainId]),360,0,360, 170, -85,85);
00175                           endc_p[gainId] = new TH2F(Form("EE+p%i",gainValues[gainId]),Form("EE+p%i",gainValues[gainId]),100,1,101,100,1,101);
00176                           endc_m[gainId] = new TH2F(Form("EE-p%i",gainValues[gainId]),Form("EE-p%i",gainValues[gainId]),100,1,101,100,1,101);
00177                                 
00178                         }
00179 
00180                         for (int sign=0; sign < kSides; sign++) {
00181                                 int thesign = sign==1 ? 1:-1;
00182 
00183                                 for (int ieta=0; ieta<kBarlRings; ieta++) {
00184                                         for (int iphi=0; iphi<kBarlWedges; iphi++) {
00185                                                 EBDetId id((ieta+1)*thesign, iphi+1);
00186                                                 float y = -1 - ieta;
00187                                                 if(sign == 1) y = ieta;
00188                                                 barrel[0]->Fill(iphi, y, object().getLaserMap()[id.rawId()].p1);
00189                                                 barrel[1]->Fill(iphi, y, object().getLaserMap()[id.rawId()].p2);
00190                                                 barrel[2]->Fill(iphi, y, object().getLaserMap()[id.rawId()].p3);
00191 
00192                                         }  // iphi
00193                                 }   // ieta
00194 
00195                                 for (int ix=0; ix<kEndcWedgesX; ix++) {
00196                                         for (int iy=0; iy<kEndcWedgesY; iy++) {
00197                                                 if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
00198                                                 EEDetId id(ix+1,iy+1,thesign);
00199                                                 if (thesign==1) {
00200                                                         endc_p[0]->Fill(ix+1,iy+1,object().getLaserMap()[id.rawId()].p1);
00201                                                         endc_p[1]->Fill(ix+1,iy+1,object().getLaserMap()[id.rawId()].p2);
00202                                                         endc_p[2]->Fill(ix+1,iy+1,object().getLaserMap()[id.rawId()].p3);
00203 
00204                                                 }
00205                                                 else{ 
00206                                                         endc_m[0]->Fill(ix+1,iy+1,object().getLaserMap()[id.rawId()].p1);
00207                                                         endc_m[1]->Fill(ix+1,iy+1,object().getLaserMap()[id.rawId()].p2);
00208                                                         endc_m[2]->Fill(ix+1,iy+1,object().getLaserMap()[id.rawId()].p3);
00209                                                 
00210                                                 }
00211                                         }  // iy
00212                                 }   // ix
00213                         }    // side
00214 
00215                         //canvas.cd(1);
00216 
00217                         TLine* l = new TLine(0., 0., 0., 0.);
00218                         l->SetLineWidth(1);
00219                         int ixSectorsEE[202] = {
00220                                 62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 
00221                                 41, 41, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 46, 46, 56, 56, 58, 58, 59, 59, 
00222                                 60, 60, 61, 61, 62, 62,  0,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 
00223                                 81, 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14,  9,
00224                                 9,  6,  6,  4,  4,  1,  1,  4,  4,  6,  6,  9,  9, 14, 14, 16, 16, 21, 21, 26, 
00225                                 26, 36, 36, 41, 41, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 93, 93, 96, 
00226                                 96, 98, 98,101,101,  0, 62, 66, 66, 71, 71, 81, 81, 91, 91, 93,  0, 62, 66, 66, 
00227                                 91, 91, 98,  0, 58, 61, 61, 66, 66, 71, 71, 76, 76, 81, 81,  0, 51, 51,  0, 44, 
00228                                 41, 41, 36, 36, 31, 31, 26, 26, 21, 21,  0, 40, 36, 36, 11, 11,  4,  0, 40, 36, 
00229                                 36, 31, 31, 21, 21, 11, 11,  9,  0, 46, 46, 41, 41, 36, 36,  0, 56, 56, 61, 61, 66, 66};
00230 
00231                                 int iySectorsEE[202] = {
00232                                         51, 56, 56, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 61, 61, 60, 60, 59, 59, 58, 
00233                                         58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 41, 41, 40, 40, 41, 41, 42, 42, 43, 
00234                                         43, 44, 44, 46, 46, 51,  0, 51, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 
00235                                         93, 93, 96, 96, 98, 98,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 81, 
00236                                         76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14,  9,  9, 
00237                                         6,  6,  4,  4,  1,  1,  4,  4,  6,  6,  9,  9, 14, 14, 16, 16, 21, 21, 26, 26, 
00238                                         36, 36, 41, 41, 51,  0, 46, 46, 41, 41, 36, 36, 31, 31, 26, 26,  0, 51, 51, 56, 
00239                                         56, 61, 61,  0, 61, 61, 66, 66, 71, 71, 76, 76, 86, 86, 88,  0, 62,101,  0, 61, 
00240                                         61, 66, 66, 71, 71, 76, 76, 86, 86, 88,  0, 51, 51, 56, 56, 61, 61,  0, 46, 46, 
00241                                         41, 41, 36, 36, 31, 31, 26, 26,  0, 40, 31, 31, 16, 16,  6,  0, 40, 31, 31, 16, 16,  6};
00242 
00243                                         for (int gId = 0; gId < 3; gId++) {
00244                                                 pad[gId][0]->cd();
00245                                                 endc_m[gId]->SetStats(0);
00246                                                 
00247                                                 endc_m[gId]->GetZaxis()->SetRangeUser(0.9,1.1);
00248                                                 endc_m[gId]->Draw("colz");
00249                                                 for ( int i=0; i<201; i=i+1) {
00250                                                         if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) && 
00251                                                                 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00252                                                                         l->DrawLine(ixSectorsEE[i], iySectorsEE[i], 
00253                                                                                 ixSectorsEE[i+1], iySectorsEE[i+1]);
00254                                                                         l->SetLineWidth(0.2);
00255                                                         }
00256                                                 }
00257                                                 pad[gId][1]->cd();
00258                                                 barrel[gId]->SetStats(0);
00259                                                 barrel[gId]->GetZaxis()->SetRangeUser(0.9,1.1); 
00260                                                 
00261                                                 barrel[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 
00270                                                 //canvas.cd(3);
00271                                                 pad[gId][2]->cd();
00272                                                 endc_p[gId]->SetStats(0);
00273                                                 endc_p[gId]->GetZaxis()->SetRangeUser(0.9,1.1); 
00274                                                 
00275                                                 endc_p[gId]->Draw("colz");
00276                                                 for ( int i=0; i<201; i=i+1) {
00277                                                         if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) && 
00278                                                                 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00279                                                                         l->DrawLine(ixSectorsEE[i], iySectorsEE[i], 
00280                                                                                 ixSectorsEE[i+1], iySectorsEE[i+1]);
00281                                                         }
00282                                                 }
00283                                         }
00284 
00285                                         canvas.SaveAs(filename.c_str());
00286                                         return filename;
00287         }  // plot
00288 
00289 
00290 
00291 
00292 
00293 
00294 }
00295 
00296 PYTHON_WRAPPER(EcalLaserAPDPNRatios,EcalLaserAPDPNRatios);