CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/DQM/SiStripCommon/src/TkHistoMap.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripCommon/interface/TkHistoMap.h"
00002 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
00003 
00004 //#define debug_TkHistoMap
00005 
00006 TkHistoMap::TkHistoMap():
00007   HistoNumber(35){
00008   LogTrace("TkHistoMap") <<"TkHistoMap::constructor without parameters"; 
00009   loadServices();
00010 }
00011 
00012 
00013 TkHistoMap::TkHistoMap(std::string path, std::string MapName,float baseline, bool mechanicalView): 
00014   HistoNumber(35),
00015   MapName_(MapName)
00016 {
00017   LogTrace("TkHistoMap") <<"TkHistoMap::constructor with parameters"; 
00018   loadServices();
00019   createTkHistoMap(path,MapName_, baseline, mechanicalView);
00020 }
00021 
00022 void TkHistoMap::loadServices(){
00023   if(!edm::Service<DQMStore>().isAvailable()){
00024     edm::LogError("TkHistoMap") << 
00025       "\n------------------------------------------"
00026       "\nUnAvailable Service DQMStore: please insert in the configuration file an instance like"
00027       "\n\tprocess.load(\"DQMServices.Core.DQMStore_cfg\")"
00028       "\n------------------------------------------";
00029   }
00030   dqmStore_=edm::Service<DQMStore>().operator->();
00031   if(!edm::Service<TkDetMap>().isAvailable()){
00032     edm::LogError("TkHistoMap") << 
00033       "\n------------------------------------------"
00034       "\nUnAvailable Service TkHistoMap: please insert in the configuration file an instance like"
00035       "\n\tprocess.TkDetMap = cms.Service(\"TkDetMap\")"
00036       "\n------------------------------------------";
00037   }
00038   tkdetmap_=edm::Service<TkDetMap>().operator->();
00039 }
00040 
00041 void TkHistoMap::save(std::string filename){
00042   dqmStore_->save(filename);
00043 }
00044 
00045 void TkHistoMap::loadTkHistoMap(std::string path, std::string MapName, bool mechanicalView){
00046   MapName_=MapName;
00047   std::string fullName, folder;
00048   tkHistoMap_.resize(HistoNumber);    
00049   for(int layer=1;layer<HistoNumber;++layer){
00050     folder=folderDefinition(path,MapName_,layer,mechanicalView,fullName);
00051 
00052 #ifdef debug_TkHistoMap
00053     LogTrace("TkHistoMap")  << "[TkHistoMap::loadTkHistoMap] folder " << folder << " histoName " << fullName << " find " << folder.find_last_of("/") << "  length " << folder.length();
00054 #endif
00055     if(folder.find_last_of("/")!=folder.length()-1)
00056       folder+="/";
00057     tkHistoMap_[layer]=dqmStore_->get(folder+fullName);
00058 #ifdef debug_TkHistoMap
00059     LogTrace("TkHistoMap")  << "[TkHistoMap::loadTkHistoMap] folder " << folder << " histoName " << fullName << " layer " << layer << " ptr " << tkHistoMap_[layer] << " find " << folder.find_last_of("/") << "  length " << folder.length();
00060 #endif
00061   }
00062 }
00063 
00064 void TkHistoMap::createTkHistoMap(std::string& path, std::string& MapName, float& baseline, bool mechanicalView){
00065   
00066   int nchX;
00067   int nchY;
00068   double lowX,highX;
00069   double lowY, highY;
00070   std::string fullName, folder;
00071 
00072   tkHistoMap_.resize(HistoNumber);    
00073   for(int layer=1;layer<HistoNumber;++layer){
00074     folder=folderDefinition(path,MapName,layer,mechanicalView,fullName);
00075     tkdetmap_->getComponents(layer,nchX,lowX,highX,nchY,lowY,highY);
00076     MonitorElement* me  = dqmStore_->bookProfile2D(fullName.c_str(),fullName.c_str(),
00077                                                    nchX,lowX,highX,
00078                                                    nchY,lowY,highY,
00079                                                    0.0, 0.0);
00080     //initialize bin content for the not assigned bins
00081     if(baseline!=0){
00082       for(size_t ix = 1; ix <= (unsigned int) nchX; ++ix)
00083         for(size_t iy = 1;iy <= (unsigned int) nchY; ++iy)
00084           if(!tkdetmap_->getDetFromBin(layer,ix,iy))
00085             me->Fill(1.*(lowX+ix-.5),1.*(lowY+iy-.5),baseline);   
00086     }
00087 
00088     tkHistoMap_[layer]=me;
00089 #ifdef debug_TkHistoMap
00090     LogTrace("TkHistoMap")  << "[TkHistoMap::createTkHistoMap] folder " << folder << " histoName " << fullName << " layer " << layer << " ptr " << tkHistoMap_[layer];
00091 #endif
00092   }
00093 }
00094 
00095 std::string TkHistoMap::folderDefinition(std::string& path, std::string& MapName, int layer , bool mechanicalView,std::string& fullName ){
00096   
00097   std::string folder=path;
00098   std::string name=MapName+std::string("_");
00099   fullName=name+tkdetmap_->getLayerName(layer);
00100   
00101   if(mechanicalView){
00102     std::stringstream ss;
00103 
00104     SiStripFolderOrganizer folderOrg;
00105     
00106     SiStripDetId::SubDetector subDet;
00107     uint32_t subdetlayer, side;
00108     tkdetmap_->getSubDetLayerSide(layer,subDet,subdetlayer,side);
00109     folderOrg.getSubDetLayerFolderName(ss,subDet,subdetlayer,side);
00110     
00111     folder = ss.str();
00112   }
00113   dqmStore_->setCurrentFolder(folder);
00114   return folder;
00115 }
00116 
00117 #include "iostream"
00118 void TkHistoMap::fillFromAscii(std::string filename){
00119   ifstream file;
00120   file.open(filename.c_str());
00121   float value;
00122   uint32_t detid;
00123   while (file.good()){
00124     file >> detid >> value;
00125     fill(detid,value);
00126   }
00127   file.close();
00128 }
00129 
00130 void TkHistoMap::fill(uint32_t& detid,float value){
00131   int16_t layer=tkdetmap_->FindLayer(detid);
00132   TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid);
00133 #ifdef debug_TkHistoMap
00134   LogTrace("TkHistoMap") << "[TkHistoMap::fill] Fill detid " << detid << " Layer " << layer << " value " << value << " ix,iy "  << xybin.ix << " " << xybin.iy  << " " << xybin.x << " " << xybin.y << " " << tkHistoMap_[layer]->getTProfile2D()->GetName();
00135 #endif
00136   tkHistoMap_[layer]->getTProfile2D()->Fill(xybin.x,xybin.y,value);
00137 
00138 #ifdef debug_TkHistoMap
00139   LogTrace("TkHistoMap") << "[TkHistoMap::fill] " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(xybin.ix,xybin.iy);
00140   for(size_t ii=0;ii<4;ii++)
00141     for(size_t jj=0;jj<11;jj++)
00142       LogTrace("TkHistoMap") << "[TkHistoMap::fill] " << ii << " " << jj << " " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(ii,jj);
00143 #endif
00144 }
00145 
00146 void TkHistoMap::setBinContent(uint32_t& detid,float value){
00147   int16_t layer=tkdetmap_->FindLayer(detid);
00148   TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid);
00149   tkHistoMap_[layer]->getTProfile2D()->SetBinEntries(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy),1);
00150   tkHistoMap_[layer]->getTProfile2D()->SetBinContent(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy),value);
00151 
00152 #ifdef debug_TkHistoMap
00153   LogTrace("TkHistoMap") << "[TkHistoMap::setbincontent]  setBinContent detid " << detid << " Layer " << layer << " value " << value << " ix,iy "  << xybin.ix << " " << xybin.iy  << " " << xybin.x << " " << xybin.y << " " << tkHistoMap_[layer]->getTProfile2D()->GetName() << " bin " << tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy);
00154 
00155   LogTrace("TkHistoMap") << "[TkHistoMap::setbincontent] " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(xybin.ix,xybin.iy);
00156   for(size_t ii=0;ii<4;ii++)
00157     for(size_t jj=0;jj<11;jj++){
00158       LogTrace("TkHistoMap") << "[TkHistoMap::setbincontent] " << ii << " " << jj << " " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(ii,jj);
00159     }
00160 #endif
00161 }
00162 
00163 void TkHistoMap::add(uint32_t& detid,float value){
00164 #ifdef debug_TkHistoMap
00165   LogTrace("TkHistoMap") << "[TkHistoMap::add]";
00166 #endif
00167   int16_t layer=tkdetmap_->FindLayer(detid);
00168   TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid);
00169   setBinContent(detid,tkHistoMap_[layer]->getTProfile2D()->GetBinContent(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy))+value);
00170   
00171 }
00172 
00173 float TkHistoMap::getValue(uint32_t& detid){
00174   int16_t layer=tkdetmap_->FindLayer(detid);
00175   TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid);
00176   return tkHistoMap_[layer]->getTProfile2D()->GetBinContent(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy));
00177 }
00178 float TkHistoMap::getEntries(uint32_t& detid){
00179   int16_t layer=tkdetmap_->FindLayer(detid);
00180   TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid);
00181   return tkHistoMap_[layer]->getTProfile2D()->GetBinEntries(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy));
00182 }
00183 
00184 void TkHistoMap::dumpInTkMap(TrackerMap* tkmap,bool dumpEntries){
00185   for(int layer=1;layer<HistoNumber;++layer){
00186     std::vector<uint32_t> dets;
00187     tkdetmap_->getDetsForLayer(layer,dets);
00188     for(size_t i=0;i<dets.size();++i){
00189       if(dets[i]>0){
00190         if(getEntries(dets[i])>0) {
00191           tkmap->fill(dets[i],
00192                       dumpEntries ? getEntries(dets[i]) : getValue(dets[i])
00193                       );
00194         }
00195       }
00196     }
00197   } 
00198 }
00199 
00200 #include "TCanvas.h"
00201 #include "TFile.h"
00202 void TkHistoMap::saveAsCanvas(std::string filename,std::string options,std::string mode){
00203   //  TCanvas C(MapName_,MapName_,200,10,900,700);
00204   TCanvas* CTIB=new TCanvas(std::string("Canvas_"+MapName_+"TIB").c_str(),std::string("Canvas_"+MapName_+"TIB").c_str());
00205   TCanvas* CTOB=new TCanvas(std::string("Canvas_"+MapName_+"TOB").c_str(),std::string("Canvas_"+MapName_+"TOB").c_str());
00206   TCanvas* CTIDP=new TCanvas(std::string("Canvas_"+MapName_+"TIDP").c_str(),std::string("Canvas_"+MapName_+"TIDP").c_str());
00207   TCanvas* CTIDM=new TCanvas(std::string("Canvas_"+MapName_+"TIDM").c_str(),std::string("Canvas_"+MapName_+"TIDM").c_str());
00208   TCanvas* CTECP=new TCanvas(std::string("Canvas_"+MapName_+"TECP").c_str(),std::string("Canvas_"+MapName_+"TECP").c_str());
00209   TCanvas* CTECM=new TCanvas(std::string("Canvas_"+MapName_+"TECM").c_str(),std::string("Canvas_"+MapName_+"TECM").c_str());
00210   CTIB->Divide(2,2);
00211   CTOB->Divide(2,3);
00212   CTIDP->Divide(1,3);
00213   CTIDM->Divide(1,3);
00214   CTECP->Divide(3,3);
00215   CTECM->Divide(3,3);
00216 
00217 
00218   int i;
00219   i=0;
00220   CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L1]->getTProfile2D()->Draw(options.c_str());
00221   CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L2]->getTProfile2D()->Draw(options.c_str());
00222   CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L3]->getTProfile2D()->Draw(options.c_str());
00223   CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L4]->getTProfile2D()->Draw(options.c_str());
00224   
00225   i=0;
00226   CTIDP->cd(++i);tkHistoMap_[TkLayerMap::TIDP_D1]->getTProfile2D()->Draw(options.c_str());
00227   CTIDP->cd(++i);tkHistoMap_[TkLayerMap::TIDP_D2]->getTProfile2D()->Draw(options.c_str());
00228   CTIDP->cd(++i);tkHistoMap_[TkLayerMap::TIDP_D3]->getTProfile2D()->Draw(options.c_str());
00229 
00230   i=0;
00231   CTIDM->cd(++i);tkHistoMap_[TkLayerMap::TIDM_D1]->getTProfile2D()->Draw(options.c_str());
00232   CTIDM->cd(++i);tkHistoMap_[TkLayerMap::TIDM_D2]->getTProfile2D()->Draw(options.c_str());
00233   CTIDM->cd(++i);tkHistoMap_[TkLayerMap::TIDM_D3]->getTProfile2D()->Draw(options.c_str());
00234  
00235   i=0;
00236   CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L1]->getTProfile2D()->Draw(options.c_str());
00237   CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L2]->getTProfile2D()->Draw(options.c_str());
00238   CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L3]->getTProfile2D()->Draw(options.c_str());
00239   CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L4]->getTProfile2D()->Draw(options.c_str());
00240   CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L5]->getTProfile2D()->Draw(options.c_str());
00241   CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L6]->getTProfile2D()->Draw(options.c_str());
00242 
00243   i=0;
00244   CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W1]->getTProfile2D()->Draw(options.c_str());
00245   CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W2]->getTProfile2D()->Draw(options.c_str());
00246   CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W3]->getTProfile2D()->Draw(options.c_str());
00247   CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W4]->getTProfile2D()->Draw(options.c_str());
00248   CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W5]->getTProfile2D()->Draw(options.c_str());
00249   CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W6]->getTProfile2D()->Draw(options.c_str());
00250   CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W7]->getTProfile2D()->Draw(options.c_str());
00251   CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W8]->getTProfile2D()->Draw(options.c_str());
00252   CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W9]->getTProfile2D()->Draw(options.c_str());
00253 
00254   i=0;
00255   CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W1]->getTProfile2D()->Draw(options.c_str());
00256   CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W2]->getTProfile2D()->Draw(options.c_str());
00257   CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W3]->getTProfile2D()->Draw(options.c_str());
00258   CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W4]->getTProfile2D()->Draw(options.c_str());
00259   CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W5]->getTProfile2D()->Draw(options.c_str());
00260   CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W6]->getTProfile2D()->Draw(options.c_str());
00261   CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W7]->getTProfile2D()->Draw(options.c_str());
00262   CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W8]->getTProfile2D()->Draw(options.c_str());
00263   CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W9]->getTProfile2D()->Draw(options.c_str());
00264  
00265   TFile *f = new TFile(filename.c_str(),mode.c_str());
00266   CTIB->Write();
00267   CTIDP->Write();
00268   CTIDM->Write();
00269   CTOB->Write();
00270   CTECP->Write();
00271   CTECM->Write();
00272   f->Close();
00273   delete f;
00274 }
00275 
00276