CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/CondCore/EcalPlugins/plugins/EcalTPGStripStatusPyWrapper.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/ESHandle.h"
00002 #include "FWCore/ParameterSet/interface/FileInPath.h"
00003 #include "CondFormats/EcalObjects/interface/EcalTPGStripStatus.h"
00004 #include "CondFormats/EcalObjects/interface/EcalMappingElectronics.h"
00005 #include "CondTools/Ecal/interface/EcalTPGStripStatusXMLTranslator.h"
00006 #include "CondTools/Ecal/interface/EcalCondHeader.h"
00007 #include "TROOT.h"
00008 #include "TH2F.h"
00009 #include "TCanvas.h"
00010 #include "TStyle.h"
00011 #include "TColor.h"
00012 #include "TLine.h"
00013 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00014 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00015 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
00016 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
00017 #include "CaloOnlineTools/EcalTools/interface/EcalFedMap.h"
00018 
00019 #include "CondCore/Utilities/interface/PayLoadInspector.h"
00020 #include "CondCore/Utilities/interface/InspectorPythonWrapper.h"
00021 
00022 #include <string>
00023 #include <sstream>
00024 #include <algorithm>
00025 #include <numeric>
00026 #include <iterator>
00027 #include <boost/ref.hpp>
00028 #include <boost/bind.hpp>
00029 #include <boost/function.hpp>
00030 #include <boost/iterator/transform_iterator.hpp>
00031 
00032 #include <fstream>
00033 
00034 namespace cond {
00035 
00036   template<>
00037   std::string PayLoadInspector<EcalTPGStripStatus>::dump() const {
00038     std::stringstream ss;
00039     EcalCondHeader h;
00040     ss << EcalTPGStripStatusXMLTranslator::dumpXML(h,object());
00041     return ss.str();
00042   }
00043 
00044   template<>
00045   std::string PayLoadInspector<EcalTPGStripStatus>::summary() const {
00046     std::stringstream ss;
00047     const EcalTPGStripStatusMap &stripMap = object().getMap();
00048     std::cout << " tower map size " << stripMap.size() << std::endl;
00049     ss <<" Endcap : Number of masked Trigger Strips " << stripMap.size() << std::endl;
00050     return ss.str();
00051   }
00052 
00053   template<>
00054   std::string PayLoadInspector<EcalTPGStripStatus>::plot(std::string const & filename,
00055                                                          std::string const &, 
00056                                                          std::vector<int> const&, 
00057                                                          std::vector<float> const& ) const {
00058     gStyle->SetPalette(1);
00059 
00060     const Int_t NRGBs = 5;
00061     const Int_t NCont = 255;
00062 
00063     Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
00064     Double_t red[NRGBs]   = { 0.00, 0.00, 0.87, 1.00, 0.51 };
00065     Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
00066     Double_t blue[NRGBs]  = { 0.51, 1.00, 0.12, 0.00, 0.00 };
00067     TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
00068     gStyle->SetNumberContours(NCont);
00069  
00070     TCanvas canvas("CC map","CC map",1200, 600);
00071     TPad** pad = new TPad*[2];
00072     float xmi[2] = {0.0, 0.5};
00073     float xma[2] = {0.5, 1.0};
00074     for (int obj = 0; obj < 2; obj++) {
00075       pad[obj] = new TPad(Form("p_%i", obj),Form("p_%i", obj),
00076                           xmi[obj], 0.0, xma[obj], 1.0);
00077       pad[obj]->Draw();
00078     }
00079 
00080     TH2F** hEEStrip = new TH2F*[2];
00081     for (int iz = 0; iz < 2; iz++) {
00082       int izz = iz;
00083       if(iz == 0) izz = -1;
00084       hEEStrip[iz] = new TH2F(Form("EEStrip_%i", iz),
00085                               Form("EE masked strips side %i", izz),101,1.,101.,101,1.,101.);
00086       hEEStrip[iz]->SetStats(0);
00087     }
00088 
00089     //    EcalMappingElectronics *mapping = new EcalMappingElectronics ;
00090     std::string mappingFile = "Geometry/EcalMapping/data/EEMap.txt";
00091    
00092     std::ifstream f(edm::FileInPath(mappingFile).fullPath().c_str());
00093     if (!f.good()) {
00094       std::cout << "EcalTPGStripStatusPyWrapper File not found" << std::endl;
00095       throw cms::Exception("FileNotFound");
00096     }
00097 
00098     int ix, iy, iz, CL;
00099     int dccid, towerid, pseudostrip_in_SC, xtal_in_pseudostrip;
00100     int tccid, tower, pseudostrip_in_TCC, pseudostrip_in_TT;
00101     uint32_t rawEE[108][28][5][5];
00102     int NbrawEE[108][28][5];
00103     for(int TCC = 0; TCC < 108; TCC++)
00104       for(int TT = 0; TT < 28; TT++)
00105         for(int ST = 0; ST < 5; ST++)
00106           NbrawEE[TCC][TT][ST] = 0;
00107     while ( ! f.eof()) {
00108       f >> ix >> iy >> iz >> CL >> dccid >> towerid >> pseudostrip_in_SC >> xtal_in_pseudostrip 
00109         >> tccid >> tower >> pseudostrip_in_TCC >> pseudostrip_in_TT ;
00110       
00111       EEDetId detid(ix,iy,iz,EEDetId::XYMODE);
00112       uint32_t rawId = detid.denseIndex();
00113       if(tccid > 108 || tower > 28 || pseudostrip_in_TT > 5 || xtal_in_pseudostrip > 5)
00114         std::cout << " tccid " << tccid <<  " tower " << tower << " pseudostrip_in_TT "<< pseudostrip_in_TT
00115                   <<" xtal_in_pseudostrip " << xtal_in_pseudostrip << std::endl;
00116       else {
00117         rawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1][xtal_in_pseudostrip - 1] = rawId;
00118         NbrawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1]++;
00119       }
00120       /*
00121       //      if(ix%10 == 0 && iy%10 == 0) std::cout << " dcc tower ps_in_SC xtal_in_ps " << dccid << " " << towerid << " " << pseudostrip_in_SC << " " << xtal_in_pseudostrip << std::endl;
00122       EcalElectronicsId elecid(dccid,towerid, pseudostrip_in_SC, xtal_in_pseudostrip);
00123       //      if(ix%10 == 0 && iy%10 == 0) std::cout << " tcc tt ps_in_TT xtal_in_ps " << tccid << " " << tower << " " << pseudostrip_in_TT << " " << xtal_in_pseudostrip << std::endl;
00124       EcalTriggerElectronicsId triggerid(tccid, tower, pseudostrip_in_TT, xtal_in_pseudostrip);
00125       EcalMappingElement aElement;
00126       aElement.electronicsid = elecid.rawId();
00127       aElement.triggerid = triggerid.rawId();
00128       (*mapping).setValue(detid, aElement);
00129       */
00130     }
00131 
00132     f.close();
00133 
00135     const EcalTPGStripStatusMap &stripMap = object().getMap();
00136     std::cout << " tower map size " << stripMap.size() << std::endl;
00137     double wei[2] = {0., 0.};
00138     EcalTPGStripStatusMapIterator itSt;
00139     for(itSt = stripMap.begin(); itSt != stripMap.end(); ++itSt) {
00140       if(itSt->second > 0) {
00141         // let's decode the ID
00142         int strip = itSt->first/8;
00143         int pseudostrip = strip & 0x7;
00144         strip /= 8;
00145         int tt = strip & 0x7F;
00146         strip /= 128;
00147         int tccid = strip & 0x7F;
00148         int NbXtalInStrip = NbrawEE[tccid - 1][tt - 1][pseudostrip - 1];
00149         if(NbXtalInStrip != 5) std::cout << " Strip TCC " << tccid << " TT " << tt << " ST " << pseudostrip
00150                                          << " Nx Xtals " << NbXtalInStrip << std::endl;
00151         for(int Xtal = 0; Xtal < NbXtalInStrip; Xtal++) {
00152           uint32_t rawId = rawEE[tccid - 1][tt - 1][pseudostrip - 1][Xtal];
00153           //    std::cout << " rawid " << rawId << std::endl;
00154           EEDetId detid = EEDetId::detIdFromDenseIndex(rawId);
00155           float x = (float)detid.ix();
00156           float y = (float)detid.iy();
00157           int iz = detid.zside();
00158           if(iz == -1) iz++;
00159           if(Xtal == 0)   wei[iz] += 1.;
00160           hEEStrip[iz]->Fill(x + 0.5, y + 0.5, wei[iz]);
00161           //    std::cout << " x " << ix << " y " << iy << " z " << iz << std::endl;
00162         }
00163       }
00164     }
00165 
00166     TLine* l = new TLine(0., 0., 0., 0.);
00167     l->SetLineWidth(1);
00168     int ixSectorsEE[202] = {
00169       62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 
00170       41, 41, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 46, 46, 56, 56, 58, 58, 59, 59, 
00171       60, 60, 61, 61, 62, 62,  0,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 
00172       81, 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14,  9,
00173       9,  6,  6,  4,  4,  1,  1,  4,  4,  6,  6,  9,  9, 14, 14, 16, 16, 21, 21, 26, 
00174       26, 36, 36, 41, 41, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 93, 93, 96, 
00175       96, 98, 98,101,101,  0, 62, 66, 66, 71, 71, 81, 81, 91, 91, 93,  0, 62, 66, 66, 
00176       91, 91, 98,  0, 58, 61, 61, 66, 66, 71, 71, 76, 76, 81, 81,  0, 51, 51,  0, 44, 
00177       41, 41, 36, 36, 31, 31, 26, 26, 21, 21,  0, 40, 36, 36, 11, 11,  4,  0, 40, 36, 
00178       36, 31, 31, 21, 21, 11, 11,  9,  0, 46, 46, 41, 41, 36, 36,  0, 56, 56, 61, 61, 66, 66};
00179 
00180     int iySectorsEE[202] = {
00181       51, 56, 56, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 61, 61, 60, 60, 59, 59, 58, 
00182       58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 41, 41, 40, 40, 41, 41, 42, 42, 43, 
00183       43, 44, 44, 46, 46, 51,  0, 51, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 
00184       93, 93, 96, 96, 98, 98,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 81, 
00185       76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14,  9,  9, 
00186       6,  6,  4,  4,  1,  1,  4,  4,  6,  6,  9,  9, 14, 14, 16, 16, 21, 21, 26, 26, 
00187       36, 36, 41, 41, 51,  0, 46, 46, 41, 41, 36, 36, 31, 31, 26, 26,  0, 51, 51, 56, 
00188       56, 61, 61,  0, 61, 61, 66, 66, 71, 71, 76, 76, 86, 86, 88,  0, 62,101,  0, 61, 
00189       61, 66, 66, 71, 71, 76, 76, 86, 86, 88,  0, 51, 51, 56, 56, 61, 61,  0, 46, 46, 
00190       41, 41, 36, 36, 31, 31, 26, 26,  0, 40, 31, 31, 16, 16,  6,  0, 40, 31, 31, 16, 16,  6};
00191 
00192     pad[0]->cd();
00193     hEEStrip[0]->Draw("col");
00194     for ( int i=0; i<201; i=i+1) {
00195       if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) && 
00196            (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00197         l->DrawLine(ixSectorsEE[i], iySectorsEE[i], 
00198                     ixSectorsEE[i+1], iySectorsEE[i+1]);
00199         l->SetLineWidth(0.2);
00200       }
00201     }
00202 
00203     pad[1]->cd();
00204     hEEStrip[1]->Draw("col");
00205     for ( int i=0; i<201; i=i+1) {
00206       if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) && 
00207            (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00208         l->DrawLine(ixSectorsEE[i], iySectorsEE[i], 
00209                     ixSectorsEE[i+1], iySectorsEE[i+1]);
00210         l->SetLineWidth(0.2);
00211       }
00212     }
00213 
00214     canvas.SaveAs(filename.c_str());
00215     return filename;
00216   }  // plot
00217 }
00218 PYTHON_WRAPPER(EcalTPGStripStatus,EcalTPGStripStatus);