CMS 3D CMS Logo

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