CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TkHistoMap.cc
Go to the documentation of this file.
3 
4 //#define debug_TkHistoMap
5 
7  HistoNumber(35){
8  LogTrace("TkHistoMap") <<"TkHistoMap::constructor without parameters";
9  loadServices();
10 }
11 
12 
13 TkHistoMap::TkHistoMap(std::string path, std::string MapName,float baseline, bool mechanicalView):
14  HistoNumber(35),
15  MapName_(MapName)
16 {
17  LogTrace("TkHistoMap") <<"TkHistoMap::constructor with parameters";
18  loadServices();
19  createTkHistoMap(path,MapName_, baseline, mechanicalView);
20 }
21 
23  if(!edm::Service<DQMStore>().isAvailable()){
24  edm::LogError("TkHistoMap") <<
25  "\n------------------------------------------"
26  "\nUnAvailable Service DQMStore: please insert in the configuration file an instance like"
27  "\n\tprocess.load(\"DQMServices.Core.DQMStore_cfg\")"
28  "\n------------------------------------------";
29  }
31  if(!edm::Service<TkDetMap>().isAvailable()){
32  edm::LogError("TkHistoMap") <<
33  "\n------------------------------------------"
34  "\nUnAvailable Service TkHistoMap: please insert in the configuration file an instance like"
35  "\n\tprocess.TkDetMap = cms.Service(\"TkDetMap\")"
36  "\n------------------------------------------";
37  }
39 }
40 
42  dqmStore_->save(filename);
43 }
44 
45 void TkHistoMap::loadTkHistoMap(std::string path, std::string MapName, bool mechanicalView){
46  MapName_=MapName;
47  std::string fullName, folder;
48  tkHistoMap_.resize(HistoNumber);
49  for(int layer=1;layer<HistoNumber;++layer){
50  folder=folderDefinition(path,MapName_,layer,mechanicalView,fullName);
51 
52 #ifdef debug_TkHistoMap
53  LogTrace("TkHistoMap") << "[TkHistoMap::loadTkHistoMap] folder " << folder << " histoName " << fullName << " find " << folder.find_last_of("/") << " length " << folder.length();
54 #endif
55  if(folder.find_last_of("/")!=folder.length()-1)
56  folder+="/";
57  tkHistoMap_[layer]=dqmStore_->get(folder+fullName);
58 #ifdef debug_TkHistoMap
59  LogTrace("TkHistoMap") << "[TkHistoMap::loadTkHistoMap] folder " << folder << " histoName " << fullName << " layer " << layer << " ptr " << tkHistoMap_[layer] << " find " << folder.find_last_of("/") << " length " << folder.length();
60 #endif
61  }
62 }
63 
64 void TkHistoMap::createTkHistoMap(std::string& path, std::string& MapName, float& baseline, bool mechanicalView){
65 
66  int nchX;
67  int nchY;
68  double lowX,highX;
69  double lowY, highY;
70  std::string fullName, folder;
71 
72  tkHistoMap_.resize(HistoNumber);
73  for(int layer=1;layer<HistoNumber;++layer){
74  folder=folderDefinition(path,MapName,layer,mechanicalView,fullName);
75  tkdetmap_->getComponents(layer,nchX,lowX,highX,nchY,lowY,highY);
76  MonitorElement* me = dqmStore_->bookProfile2D(fullName.c_str(),fullName.c_str(),
77  nchX,lowX,highX,
78  nchY,lowY,highY,
79  0.0, 0.0);
80  //initialize bin content for the not assigned bins
81  if(baseline!=0){
82  for(size_t ix = 1; ix <= (unsigned int) nchX; ++ix)
83  for(size_t iy = 1;iy <= (unsigned int) nchY; ++iy)
84  if(!tkdetmap_->getDetFromBin(layer,ix,iy))
85  me->Fill(1.*(lowX+ix-.5),1.*(lowY+iy-.5),baseline);
86  }
87 
88  tkHistoMap_[layer]=me;
89 #ifdef debug_TkHistoMap
90  LogTrace("TkHistoMap") << "[TkHistoMap::createTkHistoMap] folder " << folder << " histoName " << fullName << " layer " << layer << " ptr " << tkHistoMap_[layer];
91 #endif
92  }
93 }
94 
96 
97  std::string folder=path;
98  std::string name=MapName+std::string("_");
99  fullName=name+tkdetmap_->getLayerName(layer);
100  // std::cout << "[TkHistoMap::folderDefinition] fullName: " << fullName << std::endl;
101 
102  if(mechanicalView){
103  std::stringstream ss;
104 
105  SiStripFolderOrganizer folderOrg;
106  folderOrg.setSiStripFolderName(path);
107 
109  uint32_t subdetlayer, side;
110  tkdetmap_->getSubDetLayerSide(layer,subDet,subdetlayer,side);
111  folderOrg.getSubDetLayerFolderName(ss,subDet,subdetlayer,side);
112 
113  folder = ss.str();
114  // std::cout << "[TkHistoMap::folderDefinition] folder: " << folder << std::endl;
115  }
116  dqmStore_->setCurrentFolder(folder);
117  return folder;
118 }
119 
120 #include <iostream>
122  std::ifstream file;
123  file.open(filename.c_str());
124  float value;
125  uint32_t detid;
126  while (file.good()){
127  file >> detid >> value;
128  fill(detid,value);
129  }
130  file.close();
131 }
132 
133 void TkHistoMap::fill(uint32_t& detid,float value){
134  int16_t layer=tkdetmap_->FindLayer(detid);
135  TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid);
136 #ifdef debug_TkHistoMap
137  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();
138 #endif
139  tkHistoMap_[layer]->getTProfile2D()->Fill(xybin.x,xybin.y,value);
140 
141 #ifdef debug_TkHistoMap
142  LogTrace("TkHistoMap") << "[TkHistoMap::fill] " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(xybin.ix,xybin.iy);
143  for(size_t ii=0;ii<4;ii++)
144  for(size_t jj=0;jj<11;jj++)
145  LogTrace("TkHistoMap") << "[TkHistoMap::fill] " << ii << " " << jj << " " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(ii,jj);
146 #endif
147 }
148 
149 void TkHistoMap::setBinContent(uint32_t& detid,float value){
150  int16_t layer=tkdetmap_->FindLayer(detid);
151  TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid);
152  tkHistoMap_[layer]->getTProfile2D()->SetBinEntries(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy),1);
153  tkHistoMap_[layer]->getTProfile2D()->SetBinContent(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy),value);
154 
155 #ifdef debug_TkHistoMap
156  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);
157 
158  LogTrace("TkHistoMap") << "[TkHistoMap::setbincontent] " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(xybin.ix,xybin.iy);
159  for(size_t ii=0;ii<4;ii++)
160  for(size_t jj=0;jj<11;jj++){
161  LogTrace("TkHistoMap") << "[TkHistoMap::setbincontent] " << ii << " " << jj << " " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(ii,jj);
162  }
163 #endif
164 }
165 
166 void TkHistoMap::add(uint32_t& detid,float value){
167 #ifdef debug_TkHistoMap
168  LogTrace("TkHistoMap") << "[TkHistoMap::add]";
169 #endif
170  int16_t layer=tkdetmap_->FindLayer(detid);
171  TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid);
172  setBinContent(detid,tkHistoMap_[layer]->getTProfile2D()->GetBinContent(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy))+value);
173 
174 }
175 
176 float TkHistoMap::getValue(uint32_t& detid){
177  int16_t layer=tkdetmap_->FindLayer(detid);
178  TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid);
179  return tkHistoMap_[layer]->getTProfile2D()->GetBinContent(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy));
180 }
181 float TkHistoMap::getEntries(uint32_t& detid){
182  int16_t layer=tkdetmap_->FindLayer(detid);
183  TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid);
184  return tkHistoMap_[layer]->getTProfile2D()->GetBinEntries(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy));
185 }
186 
187 void TkHistoMap::dumpInTkMap(TrackerMap* tkmap,bool dumpEntries){
188  for(int layer=1;layer<HistoNumber;++layer){
189  std::vector<uint32_t> dets;
190  tkdetmap_->getDetsForLayer(layer,dets);
191  for(size_t i=0;i<dets.size();++i){
192  if(dets[i]>0){
193  if(getEntries(dets[i])>0) {
194  tkmap->fill(dets[i],
195  dumpEntries ? getEntries(dets[i]) : getValue(dets[i])
196  );
197  }
198  }
199  }
200  }
201 }
202 
203 #include "TCanvas.h"
204 #include "TFile.h"
206  // TCanvas C(MapName_,MapName_,200,10,900,700);
207  TCanvas* CTIB=new TCanvas(std::string("Canvas_"+MapName_+"TIB").c_str(),std::string("Canvas_"+MapName_+"TIB").c_str());
208  TCanvas* CTOB=new TCanvas(std::string("Canvas_"+MapName_+"TOB").c_str(),std::string("Canvas_"+MapName_+"TOB").c_str());
209  TCanvas* CTIDP=new TCanvas(std::string("Canvas_"+MapName_+"TIDP").c_str(),std::string("Canvas_"+MapName_+"TIDP").c_str());
210  TCanvas* CTIDM=new TCanvas(std::string("Canvas_"+MapName_+"TIDM").c_str(),std::string("Canvas_"+MapName_+"TIDM").c_str());
211  TCanvas* CTECP=new TCanvas(std::string("Canvas_"+MapName_+"TECP").c_str(),std::string("Canvas_"+MapName_+"TECP").c_str());
212  TCanvas* CTECM=new TCanvas(std::string("Canvas_"+MapName_+"TECM").c_str(),std::string("Canvas_"+MapName_+"TECM").c_str());
213  CTIB->Divide(2,2);
214  CTOB->Divide(2,3);
215  CTIDP->Divide(1,3);
216  CTIDM->Divide(1,3);
217  CTECP->Divide(3,3);
218  CTECM->Divide(3,3);
219 
220 
221  int i;
222  i=0;
223  CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L1]->getTProfile2D()->Draw(options.c_str());
224  CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L2]->getTProfile2D()->Draw(options.c_str());
225  CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L3]->getTProfile2D()->Draw(options.c_str());
226  CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L4]->getTProfile2D()->Draw(options.c_str());
227 
228  i=0;
229  CTIDP->cd(++i);tkHistoMap_[TkLayerMap::TIDP_D1]->getTProfile2D()->Draw(options.c_str());
230  CTIDP->cd(++i);tkHistoMap_[TkLayerMap::TIDP_D2]->getTProfile2D()->Draw(options.c_str());
231  CTIDP->cd(++i);tkHistoMap_[TkLayerMap::TIDP_D3]->getTProfile2D()->Draw(options.c_str());
232 
233  i=0;
234  CTIDM->cd(++i);tkHistoMap_[TkLayerMap::TIDM_D1]->getTProfile2D()->Draw(options.c_str());
235  CTIDM->cd(++i);tkHistoMap_[TkLayerMap::TIDM_D2]->getTProfile2D()->Draw(options.c_str());
236  CTIDM->cd(++i);tkHistoMap_[TkLayerMap::TIDM_D3]->getTProfile2D()->Draw(options.c_str());
237 
238  i=0;
239  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L1]->getTProfile2D()->Draw(options.c_str());
240  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L2]->getTProfile2D()->Draw(options.c_str());
241  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L3]->getTProfile2D()->Draw(options.c_str());
242  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L4]->getTProfile2D()->Draw(options.c_str());
243  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L5]->getTProfile2D()->Draw(options.c_str());
244  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L6]->getTProfile2D()->Draw(options.c_str());
245 
246  i=0;
247  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W1]->getTProfile2D()->Draw(options.c_str());
248  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W2]->getTProfile2D()->Draw(options.c_str());
249  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W3]->getTProfile2D()->Draw(options.c_str());
250  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W4]->getTProfile2D()->Draw(options.c_str());
251  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W5]->getTProfile2D()->Draw(options.c_str());
252  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W6]->getTProfile2D()->Draw(options.c_str());
253  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W7]->getTProfile2D()->Draw(options.c_str());
254  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W8]->getTProfile2D()->Draw(options.c_str());
255  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W9]->getTProfile2D()->Draw(options.c_str());
256 
257  i=0;
258  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W1]->getTProfile2D()->Draw(options.c_str());
259  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W2]->getTProfile2D()->Draw(options.c_str());
260  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W3]->getTProfile2D()->Draw(options.c_str());
261  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W4]->getTProfile2D()->Draw(options.c_str());
262  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W5]->getTProfile2D()->Draw(options.c_str());
263  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W6]->getTProfile2D()->Draw(options.c_str());
264  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W7]->getTProfile2D()->Draw(options.c_str());
265  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W8]->getTProfile2D()->Draw(options.c_str());
266  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W9]->getTProfile2D()->Draw(options.c_str());
267 
268  TFile *f = new TFile(filename.c_str(),mode.c_str());
269  CTIB->Write();
270  CTIDP->Write();
271  CTIDM->Write();
272  CTOB->Write();
273  CTECP->Write();
274  CTECM->Write();
275  f->Close();
276  delete f;
277 }
278 
279 
void loadServices()
Definition: TkHistoMap.cc:22
int i
Definition: DBlmapReader.cc:9
uint32_t getDetFromBin(int layer, int ix, int iy)
Definition: TkDetMap.h:126
void setSiStripFolderName(std::string name)
int HistoNumber
Definition: TkHistoMap.h:54
int ii
Definition: cuy.py:588
DQMStore * dqmStore_
Definition: TkHistoMap.h:51
std::vector< MonitorElement * > tkHistoMap_
Definition: TkHistoMap.h:53
void Fill(long long x)
void saveAsCanvas(std::string filename, std::string options="", std::string mode="RECREATE")
Definition: TkHistoMap.cc:205
void getSubDetLayerFolderName(std::stringstream &ss, SiStripDetId::SubDetector subDet, uint32_t layer, uint32_t side=0)
float getEntries(uint32_t &detid)
Definition: TkHistoMap.cc:181
std::string MapName_
Definition: TkHistoMap.h:55
void loadTkHistoMap(std::string path, std::string MapName, bool mechanicalView=false)
Definition: TkHistoMap.cc:45
void save(std::string filename)
Definition: TkHistoMap.cc:41
void getDetsForLayer(int layer, std::vector< uint32_t > &output)
Definition: TkDetMap.cc:677
void fill(uint32_t &detid, float value)
Definition: TkHistoMap.cc:133
float getValue(uint32_t &detid)
Definition: TkHistoMap.cc:176
TkDetMap * tkdetmap_
Definition: TkHistoMap.h:52
void createTkHistoMap(std::string &path, std::string &MapName, float &baseline, bool mechanicalView)
Definition: TkHistoMap.cc:64
double f[11][100]
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2296
TProfile2D * getTProfile2D(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1623
void dumpInTkMap(TrackerMap *tkmap, bool dumpEntries=false)
Definition: TkHistoMap.cc:187
#define LogTrace(id)
void setBinContent(uint32_t &detid, float value)
Definition: TkHistoMap.cc:149
void fillFromAscii(std::string filename)
Definition: TkHistoMap.cc:121
string fullName
int16_t FindLayer(uint32_t &detid)
Definition: TkDetMap.cc:646
void getSubDetLayerSide(int &in, SiStripDetId::SubDetector &, uint32_t &layer, uint32_t &side)
Definition: TkDetMap.cc:831
void getComponents(int &layer, int &nchX, double &lowX, double &highX, int &nchY, double &lowY, double &highY)
Definition: TkDetMap.cc:666
tuple filename
Definition: lut2db_cfg.py:20
const TkLayerMap::XYbin & getXY(uint32_t &)
Definition: TkDetMap.cc:633
std::string getLayerName(int &in)
Definition: TkDetMap.cc:684
std::string folderDefinition(std::string &path, std::string &MapName, int layer, bool mechanicalView, std::string &fullName)
Definition: TkHistoMap.cc:95
void add(uint32_t &detid, float value)
Definition: TkHistoMap.cc:166
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
void fill(int layer, int ring, int nmod, float x)
Definition: TrackerMap.cc:2776
MonitorElement * bookProfile2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ, const char *option="s")
Definition: DQMStore.cc:1330