CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CondCore/HcalPlugins/plugins/HcalGainsPyWrapper.cc

Go to the documentation of this file.
00001 #include "CondFormats/HcalObjects/interface/HcalGains.h"
00002 
00003 #include "CondCore/Utilities/interface/PayLoadInspector.h"
00004 #include "CondCore/Utilities/interface/InspectorPythonWrapper.h"
00005 
00006 #include <string>
00007 #include <fstream>
00008 #include <sstream>
00009 
00010 #include "TH1F.h"
00011 #include "TH2F.h"
00012 #include "DataFormats/DetId/interface/DetId.h"
00013 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00014 
00015 #include "TROOT.h"
00016 #include "TCanvas.h"
00017 #include "TStyle.h"
00018 #include "TColor.h"
00019 #include "TLine.h"
00020 
00021 #include "math.h"
00022 //functions for correct representation of data in summary and plot:
00023 #include "CondCore/HcalPlugins/interface/HcalObjRepresent.h"
00024 using namespace HcalObjRepresent;
00025 
00026 namespace cond {
00027 
00028         template<>
00029         class ValueExtractor<HcalGains>: public  BaseValueExtractor<HcalGains> {
00030         public:
00031                 typedef HcalGains Class;
00032                 typedef ExtractWhat<Class> What;
00033                 static What what() { return What();}
00034 
00035                 ValueExtractor(){}
00036 
00037                 ValueExtractor(What const & what)
00038                 {
00039                         // here one can make stuff really complicated...
00040                 }
00041 
00042                 void compute(Class const & it){
00043                 }
00044         private:
00045 
00046         };
00047 
00048 
00049         template<>
00050         std::string PayLoadInspector<HcalGains>::summary() const {
00051                 std::stringstream ss;
00052 
00053                 // get all containers with names
00054                 HcalGains::tAllContWithNames allContainers = object().getAllContainers();
00055 
00056                 // initializing iterators
00057                 HcalGains::tAllContWithNames::const_iterator iter;
00058                 std::vector<HcalGain>::const_iterator contIter;
00059 
00060                 ss << "Total HCAL containers: " << allContainers.size() << std::endl;
00061 
00062                 int capIdSize = 4;
00063                 float capValue = 0.0;
00064                 typedef std::pair<std::pair< std::vector<float>, std::vector<float> >, int> tPora;
00065 
00066                 std::vector<tPora> vec(allContainers.size());
00067 
00068                 std::vector<tPora>::iterator iMaz = vec.begin();
00069 
00070                 float sum = 0.0, average = 0.0, std_dev = 0.0, sqr_sum = 0.0;
00071                 int size = 0;
00072 
00073                 //Run trough all 8 detector containers:
00074                 for (iter = allContainers.begin(), iMaz = vec.begin(); iter != allContainers.end(); ++iter, ++iMaz){
00075                         ss << "---------------------------------------------" << std::endl;
00076                         ss << "Detector: " << (*iter).first << ";    Total values: "<< (*iter).second.size() << std::endl;
00077                         unsigned int j = 0;
00078                         //ss << sizes.size() <<index;
00079                         //vec.push_back(std::pair<std::vector<float>(4, 0.0), 0>);
00080                         iMaz->second = (*iter).second.size();
00081                         (iMaz->first).first = std::vector<float>(4, 0.0);
00082                         (iMaz->first).second = std::vector<float>(4, 0.0);
00083 
00084                         //Run trough all values in container
00085                         for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
00086 
00087                                 //Run trough all values (4) in object:
00088                                 for (int i = 0; i < capIdSize; ++i){
00089                                         capValue = (*contIter).getValue(i);
00090                                         (iMaz->first).first[i] += capValue;
00091                                         (iMaz->first).second[i]+= (capValue * capValue);
00092                                         //ss << "[" << i << "] " << capValue << ", " << (iMaz->first).first[i] << ", " << (iMaz->first).second[i] << "; ";
00093                                 }
00094                                 //ss << std::endl;
00095                                 ++j;
00096                         }
00097 
00098                         size = (*iMaz).second;
00099                         //ss << k++ << ": size =  "<< size << "; ";
00100                         for (int i = 0; i < capIdSize; ++i){
00101                                 sum = ((*iMaz).first).first[i];
00102                                 sqr_sum = ((*iMaz).first).second[i];
00103                                 average = sum/size;
00104                                 std_dev = sqrt( (sqr_sum/size) - (average * average) );
00105                                 ss  << "    Gain " << i << " :"<< std::endl;
00106                                 ss      << "          Average: " << average << "; "<< std::endl;
00107                                 ss      << "          Standart deviation: " << std_dev << "; " << std::endl;
00108                         }       
00109                 }
00110                 return ss.str();
00111         }
00112 
00113         void draw(std::vector<TH2F> &graphData, std::string filename) {
00114                 //Drawing...
00115                 // use David's palette
00116                 gStyle->SetPalette(1);
00117                 const Int_t NCont = 999;
00118                 gStyle->SetNumberContours(NCont);
00119                 TCanvas canvas("CC map","CC map",840,369*4);
00120 
00121                 TPad pad1("pad1","pad1", 0.0, 0.75, 1.0, 1.0);
00122                 pad1.Draw();
00123                 TPad pad2("pad2","pad2", 0.0, 0.5, 1.0, 0.75);
00124                 pad2.Draw();
00125                 TPad pad3("pad3","pad3", 0.0, 0.25, 1.0, 0.5);
00126                 pad3.Draw();
00127                 TPad pad4("pad4","pad4", 0.0, 0.0, 1.0, 0.25);
00128                 pad4.Draw();
00129 
00130 
00131                 pad1.cd();
00132                 graphData[0].SetStats(0);
00133                 graphData[0].Draw("colz");
00134 
00135                 pad2.cd();
00136                 graphData[1].SetStats(0);
00137                 graphData[1].Draw("colz");
00138 
00139                 pad3.cd();
00140                 graphData[2].SetStats(0);
00141                 graphData[2].Draw("colz");
00142 
00143                 pad4.cd();
00144                 graphData[3].SetStats(0);
00145                 graphData[3].Draw("colz");
00146 
00147                 canvas.SaveAs(filename.c_str());
00148         }
00149 
00150         template<>
00151         std::string PayLoadInspector<HcalGains>::plot(std::string const & filename,
00152                 std::string const &,
00153                 std::vector<int> const&,
00154                 std::vector<float> const& ) const 
00155         {
00156                  //void set(since, till, filename); {
00157                 unsigned int numOfValues = 4;
00158                 std::string plotname = "_Gain_";
00159                 //filename = filename + "_Gain";
00160 
00161 
00162                 typedef std::vector<TH2F> graphData;
00163                 std::vector< graphData > graphDataVec(numOfValues);
00164                 std::vector< graphData >::iterator bigIter;
00165 
00166                 std::stringstream ss, plotname_i;
00167                 HcalGains::tAllContWithNames allContainers = object().getAllContainers();
00168 
00169                 int i = 0;
00170                 for (bigIter = graphDataVec.begin(); bigIter != graphDataVec.end(); ++bigIter){
00171                         plotname_i << plotname << i ;
00172                         ss << filename << "_Gain_"<<i<<".png";
00173                         fillOneGain((*bigIter), allContainers, plotname_i.str(), i);
00174                         FillUnphysicalHEHFBins(*bigIter);
00175                         draw((*bigIter), ss.str());
00176                         ++i;
00177                         ss.str("");
00178                         plotname_i.str("");
00179                 }
00180                 return filename;
00181         }
00182 }
00183 PYTHON_WRAPPER(HcalGains,HcalGains);