Go to the documentation of this file.00001 #include "CondFormats/HcalObjects/interface/HcalGainWidths.h"
00002 #include "CondFormats/HcalObjects/interface/HcalGainWidth.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
00024 #include "CondCore/HcalPlugins/interface/HcalObjRepresent.h"
00025 using namespace HcalObjRepresent;
00026
00027 namespace cond {
00028 template<>
00029 class ValueExtractor<HcalGainWidths>: public BaseValueExtractor<HcalGainWidths> {
00030 public:
00031 typedef HcalGainWidths Class;
00032 typedef ExtractWhat<Class> What;
00033 static What what() { return What();}
00034
00035 ValueExtractor(){}
00036
00037 ValueExtractor(What const & what)
00038 {
00039
00040 }
00041
00042 void compute(Class const & it){
00043 }
00044 private:
00045
00046 };
00047
00048 class HcalGainWidthsDataRepr: public ADataRepr
00049 {
00050 public:
00051 HcalGainWidthsDataRepr(unsigned int total, HcalGainWidths::tAllContWithNames const & allCont)
00052 :ADataRepr(total), allContainers(allCont){}
00053
00054
00055
00056 protected:
00057 HcalGainWidths::tAllContWithNames allContainers;
00058
00059 void doFillIn(std::vector<TH2F> &graphData){
00060
00061 HcalGainWidths::tAllContWithNames::const_iterator iter;
00062 std::vector<HcalGainWidth>::const_iterator contIter;
00063 float value = 0.0;
00064
00065
00066 for (iter = allContainers.begin(); iter != allContainers.end(); ++iter){
00067
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
00082 value = (*contIter).getValue(id);
00083
00084
00085
00086 graphData[depth-1].Fill(ieta,iphi, value);
00087 }
00088 }
00089 }
00090 };
00091
00092 template<>
00093 std::string PayLoadInspector<HcalGainWidths>::summary() const {
00094 std::stringstream ss;
00095 unsigned int totalValues = 4;
00096
00097 HcalGainWidths::tAllContWithNames allContainers = object().getAllContainers();
00098
00099
00100 HcalGainWidths::tAllContWithNames::const_iterator iter;
00101 std::vector<HcalGainWidth>::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
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
00124 for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
00125
00126
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
00132 }
00133
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
00143 std_dev = sqrt( fabs((sqr_sum / size) - (average * average)) );
00144
00145 ss << " GainWidth " << i << " :"<< std::endl;
00146 ss << " Average: " << average << "; "<< std::endl;
00147 ss << " Standart deviation: " << std_dev << "; " << std::endl;
00148 }
00149 }
00150
00151 return ss.str();
00152 }
00153
00154 template<>
00155 std::string PayLoadInspector<HcalGainWidths>::plot(std::string const & filename,
00156 std::string const &,
00157 std::vector<int> const&,
00158 std::vector<float> const& ) const
00159 {
00160
00161
00162 unsigned int numOfValues = 4;
00163
00164
00165 HcalGainWidthsDataRepr datarepr(numOfValues, object().getAllContainers());
00166
00167 datarepr.nr = 0;
00168 datarepr.id = 0;
00169 datarepr.rootname.str("_GainWidthrootvalue_");
00170 datarepr.plotname.str("GainWidthValue ");
00171 datarepr.filename.str("");
00172 datarepr.filename << filename << "_GainWidth_";
00173
00174 typedef std::vector<TH2F> graphData;
00175 std::vector< graphData > graphDataVec(numOfValues);
00176 std::vector< graphData >::iterator imageIter;
00177
00178
00179 for (imageIter = graphDataVec.begin(); imageIter != graphDataVec.end(); ++imageIter){
00180
00181
00182 datarepr.fillOneGain((*imageIter));
00183
00184 ++(datarepr.nr);
00185 ++(datarepr.id);
00186 }
00187 return filename;
00188 }
00189 }
00190 PYTHON_WRAPPER(HcalGainWidths,HcalGainWidths);