CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/CondCore/HcalPlugins/plugins/HcalZSThresholdsPyWrapper.cc

Go to the documentation of this file.
00001 #include "CondFormats/HcalObjects/interface/HcalZSThresholds.h"
00002 #include "CondFormats/HcalObjects/interface/HcalZSThreshold.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 "math.h"
00017 //functions for correct representation of data in summary and plot:
00018 #include "CondCore/HcalPlugins/interface/HcalObjRepresent.h"
00019 using namespace HcalObjRepresent;
00020 
00021 namespace cond {
00022         template<>
00023         class ValueExtractor<HcalZSThresholds>: public  BaseValueExtractor<HcalZSThresholds> {
00024         public:
00025                 typedef HcalZSThresholds Class;
00026                 typedef ExtractWhat<Class> What;
00027                 static What what() { return What();}
00028 
00029                 ValueExtractor(){}
00030 
00031                 ValueExtractor(What const & what)
00032                 {
00033                         // here one can make stuff really complicated...
00034                 }
00035 
00036                 void compute(Class const & it){
00037                 }
00038         private:
00039 
00040         };
00041 
00042         class HcalZSThresholdsDataRepr: public ADataRepr
00043         {
00044         public:
00045                 HcalZSThresholdsDataRepr(unsigned int total, HcalZSThresholds::tAllContWithNames const & allCont)
00046                         :ADataRepr(total), allContainers(allCont){}
00047 
00048 
00049 
00050         protected:
00051                 HcalZSThresholds::tAllContWithNames allContainers;
00052 
00053                 void doFillIn(std::vector<TH2F> &graphData){
00054                         //ITERATORS AND VALUES:
00055                         HcalZSThresholds::tAllContWithNames::const_iterator iter;
00056                         std::vector<HcalZSThreshold>::const_iterator contIter;
00057                         int value = 0;
00058 
00059                         //run trough all pair containers
00060                         for (iter = allContainers.begin(); iter != allContainers.end(); ++iter){
00061                                 //Run trough all values:
00062                                 for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
00063                                         hcal_id = HcalDetId((uint32_t)(*contIter).rawId());
00064 
00065                                         depth = hcal_id.depth();
00066                                         if (depth<1 || depth>4) 
00067                                                 continue;
00068 
00069                                         ieta=hcal_id.ieta();
00070                                         iphi=hcal_id.iphi();
00071 
00072                                         if (hcal_id.subdet() == HcalForward)
00073                                                 ieta>0 ? ++ieta : --ieta;
00074 
00075                                         //GET VALUE:
00076                                         value = (*contIter).getValue();
00077                                         //logstatus = log2(1.*channelBits)+1;
00078 
00079                                         //FILLING GOES HERE:
00080                                         graphData[depth-1].Fill(ieta,iphi, value);      
00081                                 }
00082                         }
00083                 }
00084         };
00085 
00086         template<>
00087         std::string PayLoadInspector<HcalZSThresholds>::summary() const {
00088                 std::stringstream ss;
00089                 unsigned int totalValues = 1;
00090                 // get all containers with names
00091                 HcalZSThresholds::tAllContWithNames allContainers = object().getAllContainers();
00092 
00093                 // initializing iterators
00094                 HcalZSThresholds::tAllContWithNames::const_iterator iter;
00095                 std::vector<HcalZSThreshold>::const_iterator contIter;
00096 
00097                 ss << "Total HCAL containers: " << allContainers.size() << std::endl;
00098 
00099                 typedef std::pair<std::pair< std::vector<float>, std::vector<float> >, int> tPora;
00100 
00101                 std::vector<tPora> vec(allContainers.size());
00102 
00103                 std::vector<tPora>::iterator iMaz = vec.begin();
00104 
00105                 float sum = 0.0, average = 0.0, std_dev = 0.0, sqr_sum = 0.0;
00106                 int size = 0;
00107 
00108                 //Run trough all 8 detector containers:
00109                 for (iter = allContainers.begin(), iMaz = vec.begin(); iter != allContainers.end(); ++iter, ++iMaz){
00110                         ss << "---------------------------------------------" << std::endl;
00111                         ss << "Detector: " << (*iter).first << ";    Total values: "<< (*iter).second.size() << std::endl;
00112                         unsigned int j = 0;
00113                         iMaz->second = (*iter).second.size();
00114                         (iMaz->first).first = std::vector<float>(totalValues, 0.0);
00115                         (iMaz->first).second = std::vector<float>(totalValues, 0.0);
00116                         int capValue = 0;
00117                         //Run trough all values in container
00118                         for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
00119 
00120                                 //Run trough all values (8) in object:
00121                                 for (unsigned int i = 0; i < totalValues; ++i){
00122                                         capValue = (*contIter).getValue();
00123                                         (iMaz->first).first[i] += capValue;
00124                                         (iMaz->first).second[i]+= (capValue * capValue);
00125                                         //ss << "[" << i << "] " << capValue << ", " << (iMaz->first).first[i] << ", " << (iMaz->first).second[i] << "; ";
00126                                 }
00127                                 //ss << std::endl;
00128                                 ++j;
00129                         }
00130 
00131                         size = (*iMaz).second;
00132                         for (unsigned int i = 0; i < totalValues; ++i){
00133                                 sum = ((*iMaz).first).first[i];
00134                                 sqr_sum = ((*iMaz).first).second[i];
00135                                 average = sum/size;
00136                                 //here needs to take absolute value for sqrt:
00137                                 std_dev = sqrt( fabs((sqr_sum / size) - (average * average)) );
00138 
00139                                 ss  << "   ZSThreshold " << " :"<< std::endl;
00140                                 ss      << "          Average: " << average << "; "<< std::endl;
00141                                 ss      << "          Standart deviation: " << std_dev << "; " << std::endl;                                    
00142 
00143                         }       
00144                 }
00145                 //std::cout << ss.str();
00146                         return ss.str();
00147         }
00148 
00149         template<>
00150         std::string PayLoadInspector<HcalZSThresholds>::plot(std::string const & filename,
00151                 std::string const &,
00152                 std::vector<int> const&,
00153                 std::vector<float> const& ) const 
00154         {
00155 
00156                 //how much values are in container
00157                 unsigned int numOfValues = 1;
00158 
00159                 //create object helper for making plots;
00160                 HcalZSThresholdsDataRepr datarepr(numOfValues, object().getAllContainers());
00161 
00162                 datarepr.nr = 0;
00163                 datarepr.id = 0;
00164                 datarepr.rootname.str("_ZSThresholdrootvalue_");
00165                 datarepr.plotname.str("ZSThreshold ");
00166                 datarepr.filename.str("");
00167                 datarepr.filename << filename << "";
00168 
00169                 typedef std::vector<TH2F> graphData;
00170                 std::vector< graphData > graphDataVec(numOfValues);
00171                 std::vector< graphData >::iterator imageIter;
00172 
00173                 /*create images:*/
00174                 for (imageIter = graphDataVec.begin(); imageIter != graphDataVec.end(); ++imageIter){
00175                         //MAIN FUNCTION:
00176                         datarepr.fillOneGain((*imageIter));
00177 
00178                         ++(datarepr.nr);
00179                         ++(datarepr.id);
00180                 }
00181                 return filename;
00182         }
00183 }
00184 PYTHON_WRAPPER(HcalZSThresholds,HcalZSThresholds);