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 
41 void TkHistoMap::save(std::string filename){
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 
95 std::string TkHistoMap::folderDefinition(std::string& path, std::string& MapName, int layer , bool mechanicalView,std::string& fullName ){
96 
97  std::string folder=path;
98  std::string name=MapName+std::string("_");
99  fullName=name+tkdetmap_->getLayerName(layer);
100 
101  if(mechanicalView){
102  std::stringstream ss;
103 
104  SiStripFolderOrganizer folderOrg;
105 
107  uint32_t subdetlayer, side;
108  tkdetmap_->getSubDetLayerSide(layer,subDet,subdetlayer,side);
109  folderOrg.getSubDetLayerFolderName(ss,subDet,subdetlayer,side);
110 
111  folder = ss.str();
112  }
113  dqmStore_->setCurrentFolder(folder);
114  return folder;
115 }
116 
117 #include "iostream"
119  ifstream file;
120  file.open(filename.c_str());
121  float value;
122  uint32_t detid;
123  while (file.good()){
124  file >> detid >> value;
125  fill(detid,value);
126  }
127  file.close();
128 }
129 
130 void TkHistoMap::fill(uint32_t& detid,float value){
131  int16_t layer=tkdetmap_->FindLayer(detid);
132  TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid);
133 #ifdef debug_TkHistoMap
134  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();
135 #endif
136  tkHistoMap_[layer]->getTProfile2D()->Fill(xybin.x,xybin.y,value);
137 
138 #ifdef debug_TkHistoMap
139  LogTrace("TkHistoMap") << "[TkHistoMap::fill] " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(xybin.ix,xybin.iy);
140  for(size_t ii=0;ii<4;ii++)
141  for(size_t jj=0;jj<11;jj++)
142  LogTrace("TkHistoMap") << "[TkHistoMap::fill] " << ii << " " << jj << " " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(ii,jj);
143 #endif
144 }
145 
146 void TkHistoMap::setBinContent(uint32_t& detid,float value){
147  int16_t layer=tkdetmap_->FindLayer(detid);
148  TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid);
149  tkHistoMap_[layer]->getTProfile2D()->SetBinEntries(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy),1);
150  tkHistoMap_[layer]->getTProfile2D()->SetBinContent(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy),value);
151 
152 #ifdef debug_TkHistoMap
153  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);
154 
155  LogTrace("TkHistoMap") << "[TkHistoMap::setbincontent] " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(xybin.ix,xybin.iy);
156  for(size_t ii=0;ii<4;ii++)
157  for(size_t jj=0;jj<11;jj++){
158  LogTrace("TkHistoMap") << "[TkHistoMap::setbincontent] " << ii << " " << jj << " " << tkHistoMap_[layer]->getTProfile2D()->GetBinContent(ii,jj);
159  }
160 #endif
161 }
162 
163 void TkHistoMap::add(uint32_t& detid,float value){
164 #ifdef debug_TkHistoMap
165  LogTrace("TkHistoMap") << "[TkHistoMap::add]";
166 #endif
167  int16_t layer=tkdetmap_->FindLayer(detid);
168  TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid);
169  setBinContent(detid,tkHistoMap_[layer]->getTProfile2D()->GetBinContent(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy))+value);
170 
171 }
172 
173 float TkHistoMap::getValue(uint32_t& detid){
174  int16_t layer=tkdetmap_->FindLayer(detid);
175  TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid);
176  return tkHistoMap_[layer]->getTProfile2D()->GetBinContent(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy));
177 }
178 float TkHistoMap::getEntries(uint32_t& detid){
179  int16_t layer=tkdetmap_->FindLayer(detid);
180  TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid);
181  return tkHistoMap_[layer]->getTProfile2D()->GetBinEntries(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix,xybin.iy));
182 }
183 
184 void TkHistoMap::dumpInTkMap(TrackerMap* tkmap,bool dumpEntries){
185  for(int layer=1;layer<HistoNumber;++layer){
186  std::vector<uint32_t> dets;
187  tkdetmap_->getDetsForLayer(layer,dets);
188  for(size_t i=0;i<dets.size();++i){
189  if(dets[i]>0){
190  if(getEntries(dets[i])>0) {
191  tkmap->fill(dets[i],
192  dumpEntries ? getEntries(dets[i]) : getValue(dets[i])
193  );
194  }
195  }
196  }
197  }
198 }
199 
200 #include "TCanvas.h"
201 #include "TFile.h"
202 void TkHistoMap::saveAsCanvas(std::string filename,std::string options,std::string mode){
203  // TCanvas C(MapName_,MapName_,200,10,900,700);
204  TCanvas* CTIB=new TCanvas(std::string("Canvas_"+MapName_+"TIB").c_str(),std::string("Canvas_"+MapName_+"TIB").c_str());
205  TCanvas* CTOB=new TCanvas(std::string("Canvas_"+MapName_+"TOB").c_str(),std::string("Canvas_"+MapName_+"TOB").c_str());
206  TCanvas* CTIDP=new TCanvas(std::string("Canvas_"+MapName_+"TIDP").c_str(),std::string("Canvas_"+MapName_+"TIDP").c_str());
207  TCanvas* CTIDM=new TCanvas(std::string("Canvas_"+MapName_+"TIDM").c_str(),std::string("Canvas_"+MapName_+"TIDM").c_str());
208  TCanvas* CTECP=new TCanvas(std::string("Canvas_"+MapName_+"TECP").c_str(),std::string("Canvas_"+MapName_+"TECP").c_str());
209  TCanvas* CTECM=new TCanvas(std::string("Canvas_"+MapName_+"TECM").c_str(),std::string("Canvas_"+MapName_+"TECM").c_str());
210  CTIB->Divide(2,2);
211  CTOB->Divide(2,3);
212  CTIDP->Divide(1,3);
213  CTIDM->Divide(1,3);
214  CTECP->Divide(3,3);
215  CTECM->Divide(3,3);
216 
217 
218  int i;
219  i=0;
220  CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L1]->getTProfile2D()->Draw(options.c_str());
221  CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L2]->getTProfile2D()->Draw(options.c_str());
222  CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L3]->getTProfile2D()->Draw(options.c_str());
223  CTIB->cd(++i);tkHistoMap_[TkLayerMap::TIB_L4]->getTProfile2D()->Draw(options.c_str());
224 
225  i=0;
226  CTIDP->cd(++i);tkHistoMap_[TkLayerMap::TIDP_D1]->getTProfile2D()->Draw(options.c_str());
227  CTIDP->cd(++i);tkHistoMap_[TkLayerMap::TIDP_D2]->getTProfile2D()->Draw(options.c_str());
228  CTIDP->cd(++i);tkHistoMap_[TkLayerMap::TIDP_D3]->getTProfile2D()->Draw(options.c_str());
229 
230  i=0;
231  CTIDM->cd(++i);tkHistoMap_[TkLayerMap::TIDM_D1]->getTProfile2D()->Draw(options.c_str());
232  CTIDM->cd(++i);tkHistoMap_[TkLayerMap::TIDM_D2]->getTProfile2D()->Draw(options.c_str());
233  CTIDM->cd(++i);tkHistoMap_[TkLayerMap::TIDM_D3]->getTProfile2D()->Draw(options.c_str());
234 
235  i=0;
236  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L1]->getTProfile2D()->Draw(options.c_str());
237  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L2]->getTProfile2D()->Draw(options.c_str());
238  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L3]->getTProfile2D()->Draw(options.c_str());
239  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L4]->getTProfile2D()->Draw(options.c_str());
240  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L5]->getTProfile2D()->Draw(options.c_str());
241  CTOB->cd(++i);tkHistoMap_[TkLayerMap::TOB_L6]->getTProfile2D()->Draw(options.c_str());
242 
243  i=0;
244  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W1]->getTProfile2D()->Draw(options.c_str());
245  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W2]->getTProfile2D()->Draw(options.c_str());
246  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W3]->getTProfile2D()->Draw(options.c_str());
247  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W4]->getTProfile2D()->Draw(options.c_str());
248  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W5]->getTProfile2D()->Draw(options.c_str());
249  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W6]->getTProfile2D()->Draw(options.c_str());
250  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W7]->getTProfile2D()->Draw(options.c_str());
251  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W8]->getTProfile2D()->Draw(options.c_str());
252  CTECP->cd(++i);tkHistoMap_[TkLayerMap::TECP_W9]->getTProfile2D()->Draw(options.c_str());
253 
254  i=0;
255  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W1]->getTProfile2D()->Draw(options.c_str());
256  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W2]->getTProfile2D()->Draw(options.c_str());
257  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W3]->getTProfile2D()->Draw(options.c_str());
258  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W4]->getTProfile2D()->Draw(options.c_str());
259  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W5]->getTProfile2D()->Draw(options.c_str());
260  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W6]->getTProfile2D()->Draw(options.c_str());
261  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W7]->getTProfile2D()->Draw(options.c_str());
262  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W8]->getTProfile2D()->Draw(options.c_str());
263  CTECM->cd(++i);tkHistoMap_[TkLayerMap::TECM_W9]->getTProfile2D()->Draw(options.c_str());
264 
265  TFile *f = new TFile(filename.c_str(),mode.c_str());
266  CTIB->Write();
267  CTIDP->Write();
268  CTIDM->Write();
269  CTOB->Write();
270  CTECP->Write();
271  CTECM->Write();
272  f->Close();
273  delete f;
274 }
275 
276 
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 save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2113
int HistoNumber
Definition: TkHistoMap.h:54
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:202
void getSubDetLayerFolderName(std::stringstream &ss, SiStripDetId::SubDetector subDet, uint32_t layer, uint32_t side=0)
float getEntries(uint32_t &detid)
Definition: TkHistoMap.cc:178
std::string MapName_
Definition: TkHistoMap.h:55
void loadTkHistoMap(std::string path, std::string MapName, bool mechanicalView=false)
Definition: TkHistoMap.cc:45
list path
Definition: scaleCards.py:51
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:130
float getValue(uint32_t &detid)
Definition: TkHistoMap.cc:173
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]
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:1468
void dumpInTkMap(TrackerMap *tkmap, bool dumpEntries=false)
Definition: TkHistoMap.cc:184
#define LogTrace(id)
void setBinContent(uint32_t &detid, float value)
Definition: TkHistoMap.cc:146
void fillFromAscii(std::string filename)
Definition: TkHistoMap.cc:118
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:163
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
void fill(int layer, int ring, int nmod, float x)
Definition: TrackerMap.cc:2549
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:1175