CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/CondCore/HcalPlugins/plugins/HcalLutMetadataPyWrapper.cc

Go to the documentation of this file.
00001 #include "CondFormats/HcalObjects/interface/HcalLutMetadata.h"
00002 #include "CondFormats/HcalObjects/interface/HcalLutMetadatum.h"
00003 
00004 #include "CondCore/Utilities/interface/PayLoadInspector.h"
00005 #include "CondCore/Utilities/interface/InspectorPythonWrapper.h"
00006 
00007 #include <string>
00008 #include <fstream>
00009 #include <sstream>
00010 
00011 #include "TH1F.h"
00012 #include "TH2F.h"
00013 #include "DataFormats/DetId/interface/DetId.h"
00014 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00015 
00016 #include "TROOT.h"
00017 #include "TCanvas.h"
00018 #include "TStyle.h"
00019 #include "TColor.h"
00020 #include "TLine.h"
00021 
00022 #include "math.h"
00023 //functions for correct representation of data in summary and plot:
00024 #include "CondCore/HcalPlugins/interface/HcalObjRepresent.h"
00025 using namespace HcalObjRepresent;
00026 
00027 namespace cond {
00028         template<>
00029         class ValueExtractor<HcalLutMetadata>: public  BaseValueExtractor<HcalLutMetadata> {
00030         public:
00031                 typedef HcalLutMetadata 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         class HcalLutMetadataDataRepr: public ADataRepr
00049         {
00050         public:
00051                 HcalLutMetadataDataRepr(unsigned int total, HcalLutMetadata::tAllContWithNames const & allCont)
00052                         :ADataRepr(total), allContainers(allCont){}
00053 
00054 
00055 
00056         protected:
00057                 HcalLutMetadata::tAllContWithNames allContainers;
00058 
00059                 void doFillIn(std::vector<TH2F> &graphData){
00060                         //ITERATORS AND VALUES:
00061                         HcalLutMetadata::tAllContWithNames::const_iterator iter;
00062                         std::vector<HcalLutMetadatum>::const_iterator contIter;
00063                         float value = 0.0;
00064 
00065                         //run trough all pair containers
00066                         for (iter = allContainers.begin(); iter != allContainers.end(); ++iter){
00067                                 //Run trough all values:
00068                                 for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
00069                                         hcal_id = HcalDetId((uint32_t)(*contIter).rawId());
00070 
00071                                         depth = hcal_id.depth();
00072                                         if (depth<1 || depth>4) 
00073                                                 continue;
00074 
00075                                         ieta=hcal_id.ieta();
00076                                         iphi=hcal_id.iphi();
00077 
00078                                         if (hcal_id.subdet() == HcalForward)
00079                                                 ieta>0 ? ++ieta : --ieta;
00080 
00081                                         //GET VALUE:
00082                                         switch(id){
00083         case 0:
00084                 value = (*contIter).getRCalib();
00085                 break;
00086         case 1:
00087                 value = (*contIter).getLutGranularity();
00088                 break;
00089         case 2:
00090                 value = (*contIter).getOutputLutThreshold();
00091                 break;
00092         default:
00093                 throw("Trying to access not existing value!");
00094 
00095                                         }
00096                                         //value = (*contIter).getValue(id);
00097                                         //logstatus = log2(1.*channelBits)+1;
00098 
00099                                         //FILLING GOES HERE:
00100                                         graphData[depth-1].Fill(ieta,iphi, value);      
00101                                 }
00102                         }
00103                 }
00104         };
00105 
00106         template<>
00107         std::string PayLoadInspector<HcalLutMetadata>::summary() const {
00108                 std::stringstream ss;
00109 
00110                 unsigned int totalValues = 3;
00111 
00112                 // get all containers with names
00113                 HcalLutMetadata::tAllContWithNames allContainers = object().getAllContainers();
00114 
00115                 // initializing iterators
00116                 HcalLutMetadata::tAllContWithNames::const_iterator iter;
00117                 std::vector<HcalLutMetadatum>::const_iterator contIter;
00118 
00119                 ss << "Total HCAL containers: " << allContainers.size() << std::endl;
00120 
00121                 typedef std::pair<std::pair< std::vector<float>, std::vector<float> >, int> tPora;
00122 
00123                 std::vector<tPora> vec(allContainers.size());
00124 
00125                 std::vector<tPora>::iterator iMaz = vec.begin();
00126 
00127                 float sum = 0.0, average = 0.0, std_dev = 0.0, sqr_sum = 0.0;
00128                 int size = 0;
00129 
00130                 //Run trough all 8 detector containers:
00131                 for (iter = allContainers.begin(), iMaz = vec.begin(); iter != allContainers.end(); ++iter, ++iMaz){
00132                         ss << "---------------------------------------------" << std::endl;
00133                         ss << "Detector: " << (*iter).first << ";    Total values: "<< (*iter).second.size() << std::endl;
00134                         unsigned int j = 0;
00135                         iMaz->second = (*iter).second.size();
00136                         (iMaz->first).first = std::vector<float>(totalValues, 0.0);
00137                         (iMaz->first).second = std::vector<float>(totalValues, 0.0);
00138                         float capValue = 0.0;
00139                         //Run trough all values in container
00140                         for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
00141 
00142                                 //Run trough all values in object:
00143                                 for (unsigned int i = 0; i < totalValues; ++i){
00144 
00145                                         //GET VALUE:
00146                                         switch(i){
00147                                                 case 0:
00148                                                         capValue = (*contIter).getRCalib();
00149                                                         break;
00150                                                 case 1:
00151                                                         capValue = (*contIter).getLutGranularity();
00152                                                         break;
00153                                                 case 2:
00154                                                         capValue = (*contIter).getOutputLutThreshold();
00155                                                         break;
00156                                                 default:
00157                                                         throw("Trying to access not existing value!");
00158                                         }
00159 
00160                                         //capValue = (*contIter).getValue(i);
00161                                         (iMaz->first).first[i] += capValue;
00162                                         (iMaz->first).second[i]+= (capValue * capValue);
00163                                         //ss << "[" << i << "] " << capValue << ", " << (iMaz->first).first[i] << ", " << (iMaz->first).second[i] << "; ";
00164                                 }
00165                                 //ss << std::endl;
00166                                 ++j;
00167                         }
00168 
00169                         size = (*iMaz).second;
00170                         for (unsigned int i = 0; i < totalValues; ++i){
00171                                 sum = ((*iMaz).first).first[i];
00172                                 sqr_sum = ((*iMaz).first).second[i];
00173                                 average = sum/size;
00174                                 //here needs to take absolute value for sqrt:
00175                                 std_dev = sqrt( fabs((sqr_sum / size) - (average * average)) );
00176 
00177                                 switch(i){
00178                                         case 0:
00179                                                 ss  << "    LutMetadata RecHit calibration:"<< std::endl;
00180                                                 break;
00181                                         case 1:
00182                                                 ss  << "    LutMetadata LUT granularity:"<< std::endl;
00183                                                 break;
00184                                         case 2:
00185                                                 ss  << "    LutMetadata output LUT threshold :"<< std::endl;
00186                                                 break;
00187                                         default:
00188                                                 throw("Trying to access not existing value!");
00189                                 }
00190 
00191                                 ss      << "          Average: " << average << "; "<< std::endl;
00192                                 ss      << "          Standart deviation: " << std_dev << "; " << std::endl;
00193                         }       
00194                 }
00195                 //std::cout << ss.str();
00196                 return ss.str();
00197         }
00198 
00199         template<>
00200         std::string PayLoadInspector<HcalLutMetadata>::plot(std::string const & filename,
00201                 std::string const &,
00202                 std::vector<int> const&,
00203                 std::vector<float> const& ) const 
00204         {
00205 
00206                 //how much values are in container
00207                 unsigned int numOfValues = 3;
00208 
00209                 //create object helper for making plots;
00210                 HcalLutMetadataDataRepr datarepr(numOfValues, object().getAllContainers());
00211 
00212                 datarepr.nr = 0;
00213                 datarepr.id = 0;
00214                 datarepr.rootname.str("_LutMetadatumrootvalue_");
00215                 datarepr.plotname.str("LutMetadatumValue ");
00216                 datarepr.filename.str("");
00217                 datarepr.filename << filename << "_LutMetadatum_";
00218 
00219                 typedef std::vector<TH2F> graphData;
00220                 std::vector< graphData > graphDataVec(numOfValues);
00221                 std::vector< graphData >::iterator imageIter;
00222                 //create images:
00223                 for (imageIter = graphDataVec.begin(); imageIter != graphDataVec.end(); ++imageIter){
00224                         switch(datarepr.id){
00225         case 0:
00226                 datarepr.rootname.str("_RCalibrootvalue_");
00227                 datarepr.plotname.str("RCalib ");
00228                 datarepr.filename.str("");
00229                 datarepr.filename << filename << "_RCalib_";
00230                 break;
00231         case 1:
00232                 datarepr.rootname.str("_LutGranularityrootvalue_");
00233                 datarepr.plotname.str("LutGranularity ");
00234                 datarepr.filename.str("");
00235                 datarepr.filename << filename << "_LutGranularity_";
00236                 break;
00237         case 2:
00238                 datarepr.rootname.str("_OutputLutThresholdrootvalue_");
00239                 datarepr.plotname.str("OutputLutThreshold ");
00240                 datarepr.filename.str("");
00241                 datarepr.filename << filename << "_OutputLutThreshold_";
00242                 break;
00243         default:
00244                 throw("Trying to access not existing value!");
00245                         }
00246                         //MAIN FUNCTION:
00247                         datarepr.fillOneGain((*imageIter));
00248 
00249                         //++(datarepr.nr);
00250                         ++(datarepr.id);
00251                 }
00252                 return filename;
00253         }
00254 }
00255 PYTHON_WRAPPER(HcalLutMetadata,HcalLutMetadata);