CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CondCore/HcalPlugins/plugins/HcalChannelQualityPyWrapper.cc

Go to the documentation of this file.
00001 #include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
00002 #include "CondCore/Utilities/interface/PayLoadInspector.h"
00003 #include "CondCore/Utilities/interface/InspectorPythonWrapper.h"
00004 
00005 #include <string>
00006 #include <fstream>
00007 #include <sstream>
00008 
00009 #include "TH1F.h"
00010 #include "TH2F.h"
00011 #include "DataFormats/DetId/interface/DetId.h"
00012 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00013 
00014 #include "TROOT.h"
00015 #include "TCanvas.h"
00016 #include "TStyle.h"
00017 #include "TColor.h"
00018 #include "TLine.h"
00019 
00020 
00021 //functions for correct representation of data in summary and plot:
00022 #include "CondCore/HcalPlugins/interface/HcalObjRepresent.h"
00023 using namespace HcalObjRepresent;
00024 
00025 namespace cond {
00026 
00027         template<>
00028         class ValueExtractor<HcalChannelQuality>: public  BaseValueExtractor<HcalChannelQuality> {
00029         public:
00030                 typedef HcalChannelQuality Class;
00031                 typedef ExtractWhat<Class> What;
00032                 static What what() { return What();}
00033 
00034                 ValueExtractor(){}
00035 
00036                 ValueExtractor(What const & what)
00037                 {
00038                         // here one can make stuff really complicated...
00039                 }
00040 
00041                 void compute(Class const & it){
00042                 }
00043         private:
00044 
00045         };
00046 
00047         template<>
00048         std::string PayLoadInspector<HcalChannelQuality>::summary() const {
00049                 std::stringstream ss;
00050 
00051                 //setting map for representing errors
00052                 std::string statusBitArray[20]; 
00053                 short unsigned int bitMap[9];
00054                 statusBitArray[0] = std::string("cell is off" );
00055                 statusBitArray[1] = std::string("cell is masked/to be masked at RecHit Level" );
00056                 statusBitArray[5] = std::string("cell is dead (from DQM algo)");
00057                 statusBitArray[6] = std::string("cell is hot (from DQM algo)" );
00058                 statusBitArray[7] = std::string("cell has stability error");
00059                 statusBitArray[8] = std::string("cell has timing error" );
00060                 statusBitArray[15] = std::string("cell is masked from the Trigger ");
00061                 statusBitArray[18] = std::string("cell is always excluded from the CaloTower regardless of other bit settings.");
00062                 statusBitArray[19] = std::string("cell is counted as problematic within the tower.");
00063                 bitMap[0] = 0; //{0, 1, 5, 6, 7, 8, 15, 18, 19};
00064                 bitMap[1] = 1;
00065                 bitMap[2] = 5;
00066                 bitMap[3] = 6;
00067                 bitMap[4] = 7;
00068                 bitMap[5] = 8;
00069                 bitMap[6] = 15;
00070                 bitMap[7] = 18;
00071                 bitMap[8] = 19;
00072 
00073                 // get all containers with names
00074                 HcalChannelQuality::tAllContWithNames allContainers = object().getAllContainers();
00075 
00076                 // initializing iterators
00077                 HcalChannelQuality::tAllContWithNames::const_iterator iter;
00078                 std::vector<HcalChannelStatus>::const_iterator contIter;
00079                 ss << "Total HCAL containers: " << allContainers.size() << std::endl;
00080 
00081                 //run trough all pair containers, print error values if any.
00082                 for (iter = allContainers.begin(); iter != allContainers.end(); ++iter){
00083                         ss << "---------------------------------------------" << std::endl;
00084                         ss << "Detector: " << (*iter).first << ";    Total values: "<< (*iter).second.size() << std::endl;
00085                         unsigned int j = 0;
00086                         for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
00087 
00088                                 //if not 0, it have error, print it:
00089                                 if ((*contIter).getValue() != 0){//HcalDetId::HcalDetId(uint32_t rawid)
00090                                         ss << "     Id["<< j << "]: " <<  
00091                                                 " rawId: " << (uint32_t)(*contIter).rawId() << " "<< HcalDetId((uint32_t)(*contIter).rawId())<<"; Channel bits: " <<
00092                                                 (uint32_t)(*contIter).getValue()<< "; Binary format: " << IntToBinary((uint32_t)(*contIter).getValue()) << "; Errors: "
00093                                                 << getBitsSummary((uint32_t)((*contIter).getValue()), statusBitArray, bitMap);
00094                                 }
00095                                 ++j;
00096                         }
00097                 }
00098                 return ss.str();
00099         }
00100 
00101         template<>
00102         std::string PayLoadInspector<HcalChannelQuality>::plot(std::string const & filename,//
00103                 std::string const &,
00104                 std::vector<int> const&,
00105                 std::vector<float> const& ) const 
00106         {
00107                 std::vector<TH2F> graphData;
00108                 setup(graphData, "ChannelStatus"); 
00109 
00110                 std::stringstream x;
00111                 // Change the titles of each individual histogram
00112                 for (unsigned int d=0;d < graphData.size();++d){
00113                         graphData[d].Reset();
00114                         x << "1+log2(status) for HCAL depth " << d+1;
00115 
00116                         //BUG CAN BE HERE:
00117                         //if (ChannelStatus->depth[d]) 
00118                         graphData[d].SetTitle(x.str().c_str());  // replace "setTitle" with "SetTitle", since you are using TH2F objects instead of MonitorElements
00119                         x.str("");
00120                 }
00121 
00122                 HcalDetId hcal_id;
00123                 int ieta, depth, iphi, channelBits;
00124                 double logstatus;
00125 
00126                 //main loop
00127                 // get all containers with names
00128                 HcalChannelQuality::tAllContWithNames allContainers = object().getAllContainers();
00129 
00130                 // initializing iterators
00131                 HcalChannelQuality::tAllContWithNames::const_iterator iter;
00132                 std::vector<HcalChannelStatus>::const_iterator contIter;
00133 
00134                 //run trough all pair containers
00135                 for (iter = allContainers.begin(); iter != allContainers.end(); ++iter){
00136                         for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
00137                                 hcal_id = HcalDetId((uint32_t)(*contIter).rawId());
00138 
00139                                 channelBits = (uint32_t)(*contIter).getValue();
00140                                 if (channelBits == 0) 
00141                                         continue;
00142 
00143                                 depth = hcal_id.depth();
00144                                 if (depth<1 || depth>4) 
00145                                         continue;
00146 
00147                                 ieta=hcal_id.ieta();
00148                                 iphi=hcal_id.iphi();
00149 
00150                                 if (hcal_id.subdet() == HcalForward)
00151                                         ieta>0 ? ++ieta : --ieta;
00152 
00153                                 logstatus = log2(1.*channelBits)+1;
00154                                 //FILLING GOES HERE:
00155                                 graphData[depth-1].Fill(ieta,iphi,logstatus);
00156 
00157                                 //FOR DEBUGGING:
00158                                 //std::cout << "ieta: " << ieta << "; iphi: " << iphi << "; logstatus: " << logstatus << "; channelBits: " << channelBits<< std::endl;
00159                         }
00160                 }
00161                 FillUnphysicalHEHFBins(graphData);
00162 
00163 
00164 
00165                 //Drawing...
00166                 // use David's palette
00167                 gStyle->SetPalette(1);
00168                 const Int_t NCont = 999;
00169                 gStyle->SetNumberContours(NCont);
00170                 TCanvas canvas("CC map","CC map",840,369*4);
00171 
00172                 TPad pad1("pad1","pad1", 0.0, 0.75, 1.0, 1.0);
00173                 pad1.Draw();
00174                 TPad pad2("pad2","pad2", 0.0, 0.5, 1.0, 0.75);
00175                 pad2.Draw();
00176                 TPad pad3("pad3","pad3", 0.0, 0.25, 1.0, 0.5);
00177                 pad3.Draw();
00178                 TPad pad4("pad4","pad4", 0.0, 0.0, 1.0, 0.25);
00179                 pad4.Draw();
00180 
00181 
00182                 pad1.cd();
00183                 graphData[0].SetStats(0);
00184                 graphData[0].Draw("colz");
00185 
00186                 pad2.cd();
00187                 graphData[1].SetStats(0);
00188                 graphData[1].Draw("colz");
00189 
00190                 pad3.cd();
00191                 graphData[2].SetStats(0);
00192                 graphData[2].Draw("colz");
00193 
00194                 pad4.cd();
00195                 graphData[3].SetStats(0);
00196                 graphData[3].Draw("colz");
00197 
00198 
00199                 std::stringstream ss;
00200                 ss <<filename << ".png";
00201 
00202                 canvas.SaveAs((ss.str()).c_str());
00203 
00204                 return (ss.str()).c_str();
00205         }
00206 
00207 
00208 }
00209 PYTHON_WRAPPER(HcalChannelQuality,HcalChannelQuality);