CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 #include "CondFormats/HcalObjects/interface/HcalPedestals.h"
00002 #include "CondFormats/HcalObjects/interface/HcalPedestal.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<HcalPedestals>: public  BaseValueExtractor<HcalPedestals> {
00030         public:
00031                 typedef HcalPedestals 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 HcalPedestalsDataRepr: public ADataRepr
00049         {
00050         public:
00051                 HcalPedestalsDataRepr(unsigned int total, HcalPedestals::tAllContWithNames const & allCont)
00052                         :ADataRepr(total), allContainers(allCont){}
00053 
00054 
00055 
00056         protected:
00057                 HcalPedestals::tAllContWithNames allContainers;
00058 
00059                 void doFillIn(std::vector<TH2F> &graphData){
00060                         //ITERATORS AND VALUES:
00061                         HcalPedestals::tAllContWithNames::const_iterator iter;
00062                         std::vector<HcalPedestal>::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                                         value = (*contIter).getValue(id);
00083                                         //logstatus = log2(1.*channelBits)+1;
00084 
00085                                         //FILLING GOES HERE:
00086                                         graphData[depth-1].Fill(ieta,iphi, value);      
00087                                 }
00088                         }
00089                 }
00090         };
00091 
00092         template<>
00093         std::string PayLoadInspector<HcalPedestals>::summary() const {
00094                 std::stringstream ss;
00095                 unsigned int totalValues = 8;
00096                 // get all containers with names
00097                 HcalPedestals::tAllContWithNames allContainers = object().getAllContainers();
00098 
00099                 // initializing iterators
00100                 HcalPedestals::tAllContWithNames::const_iterator iter;
00101                 std::vector<HcalPedestal>::const_iterator contIter;
00102 
00103                 ss << "Total HCAL containers: " << allContainers.size() << std::endl;
00104 
00105                 typedef std::pair<std::pair< std::vector<float>, std::vector<float> >, int> tPora;
00106 
00107                 std::vector<tPora> vec(allContainers.size());
00108 
00109                 std::vector<tPora>::iterator iMaz = vec.begin();
00110 
00111                 float sum = 0.0, average = 0.0, std_dev = 0.0, sqr_sum = 0.0;
00112                 int size = 0;
00113 
00114                 //Run trough all 8 detector containers:
00115                 for (iter = allContainers.begin(), iMaz = vec.begin(); iter != allContainers.end(); ++iter, ++iMaz){
00116                         ss << "---------------------------------------------" << std::endl;
00117                         ss << "Detector: " << (*iter).first << ";    Total values: "<< (*iter).second.size() << std::endl;
00118                         unsigned int j = 0;
00119                         iMaz->second = (*iter).second.size();
00120                         (iMaz->first).first = std::vector<float>(totalValues, 0.0);
00121                         (iMaz->first).second = std::vector<float>(totalValues, 0.0);
00122                         float capValue = 0.0;
00123                         //Run trough all values in container
00124                         for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
00125 
00126                                 //Run trough all values (8) in object:
00127                                 for (unsigned int i = 0; i < totalValues; ++i){
00128                                         capValue = (*contIter).getValue(i);
00129                                         (iMaz->first).first[i] += capValue;
00130                                         (iMaz->first).second[i]+= (capValue * capValue);
00131                                         //ss << "[" << i << "] " << capValue << ", " << (iMaz->first).first[i] << ", " << (iMaz->first).second[i] << "; ";
00132                                 }
00133                                 //ss << std::endl;
00134                                 ++j;
00135                         }
00136 
00137                         size = (*iMaz).second;
00138                         for (unsigned int i = 0; i < totalValues; ++i){
00139                                 sum = ((*iMaz).first).first[i];
00140                                 sqr_sum = ((*iMaz).first).second[i];
00141                                 average = sum/size;
00142                                 std_dev = sqrt( (sqr_sum/size) - (average * average) );
00143                                 if (i >= 4){
00144                                 ss  << "    PedestalWidth " << (i - 4) << " :"<< std::endl;
00145                                 ss      << "          Average: " << average << "; "<< std::endl;
00146                                 ss      << "          Standart deviation: " << std_dev << "; " << std::endl;                                    
00147                                 }
00148                                 else {
00149                                 ss  << "    Pedestal " << i << " :"<< std::endl;
00150                                 ss      << "          Average: " << average << "; "<< std::endl;
00151                                 ss      << "          Standart deviation: " << std_dev << "; " << std::endl;
00152                                 }
00153                         }       
00154                 }
00155                 //std::cout << ss.str();
00156                         return ss.str();
00157         }
00158 
00159         template<>
00160         std::string PayLoadInspector<HcalPedestals>::plot(std::string const & filename,
00161                 std::string const &,
00162                 std::vector<int> const&,
00163                 std::vector<float> const& ) const 
00164         {
00165 
00166                 //how much values are in container
00167                 unsigned int numOfValues = 8;
00168 
00169                 //create object helper for making plots;
00170                 HcalPedestalsDataRepr datarepr(numOfValues, object().getAllContainers());
00171 
00172                 datarepr.nr = 0;
00173                 datarepr.id = 0;
00174                 datarepr.rootname.str("_Pedestalrootvalue_");
00175                 datarepr.plotname.str("PedestalValue ");
00176                 datarepr.filename.str("");
00177                 datarepr.filename << filename << "_Pedestal_";
00178 
00179                 typedef std::vector<TH2F> graphData;
00180                 std::vector< graphData > graphDataVec(numOfValues);
00181                 std::vector< graphData >::iterator imageIter;
00182 
00183                 //create images:
00184                 for (imageIter = graphDataVec.begin(); imageIter != graphDataVec.end(); ++imageIter){
00185                         if (datarepr.nr == 4){
00186                                 datarepr.nr = 0;
00187                                 datarepr.rootname.str("_PedestalWidthrootname_");
00188                                 datarepr.plotname.str("PedestalWidth ");
00189                                 datarepr.filename.str("");
00190                                 datarepr.filename << filename << "_PedestalWidth_";                                     
00191                         }
00192                         //MAIN FUNCTION:
00193                         datarepr.fillOneGain((*imageIter));
00194 
00195                         ++(datarepr.nr);
00196                         ++(datarepr.id);
00197                 }
00198                 return filename;
00199         }
00200 }
00201 PYTHON_WRAPPER(HcalPedestals,HcalPedestals);