CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HTMLGenerator.cc
Go to the documentation of this file.
1 #include "RecoLuminosity/ROOTSchema/interface/HTMLGenerator.hh"
3 
4 // STL Headers
5 #include <sstream>
6 #include <fstream>
7 #include <iomanip>
8 
9 // ROOT Headers
10 #include <TH1F.h>
11 #include <TH2F.h>
12 #include <TCanvas.h>
13 #include <TChain.h>
14 #include <TStyle.h>
15 
16 // Lumi Headers
17 #include "RecoLuminosity/TCPReceiver/interface/LumiStructures.hh"
18 
19 HCAL_HLX::HTMLGenerator::HTMLGenerator(){
20 
21  RFReader_ = new ROOTFileReader;
22  lumiSection_ = new LUMI_SECTION;
23 
24  // TODO: read config file
25 
26  plotExt_ = "png"; // config file
27  outputDir_ = "./"; // config file
28  writeMode_ = 0775;
29 
30  previousRunNumber = 0;
31 
32  HistoNames.push_back("ETSum");
33  HistoNames.push_back("OccBelowSet1");
34  HistoNames.push_back("OccBetweenSet1");
35  HistoNames.push_back("OccAboveSet1");
36  HistoNames.push_back("OccBelowSet2");
37  HistoNames.push_back("OccBetweenSet2");
38  HistoNames.push_back("OccAboveSet2");
39  HistoNames.push_back("LHC");
40 
41  std::vector< std::string > HLXToHFMap;
42 
43  HLXToHFMap.push_back("HLX 1 - hf- s26,27 - iPhi 51");
44  HLXToHFMap.push_back("HLX 2 - hf- s28,29 - iPhi 55");
45  HLXToHFMap.push_back("HLX 3 - hf- s30,31 - iPhi 59");
46  HLXToHFMap.push_back("HLX 4 - hf- s32,33 - iPhi 63");
47  HLXToHFMap.push_back("HLX 5 - hf- s34,35 - iPhi 67");
48  HLXToHFMap.push_back("HLX 6 - hf- s36,1 - iPhi 71");
49  HLXToHFMap.push_back("HLX 7 - hf+ s26,27 - iPhi 51");
50  HLXToHFMap.push_back("HLX 8 - hf+ s28,29 - iPhi 55");
51  HLXToHFMap.push_back("HLX 9 - hf+ s30,31 - iPhi 59");
52  HLXToHFMap.push_back("HLX 10 - hf+ s32,33 - iPhi 63");
53  HLXToHFMap.push_back("HLX 11 - hf+ s34,35 - iPhi 67");
54  HLXToHFMap.push_back("HLX 12 - hf+ s36,1 - iPhi 71");
55  HLXToHFMap.push_back("HLX 13 - hf- s14,15 - iPhi 27");
56  HLXToHFMap.push_back("HLX 14 - hf- s16,17 - iPhi 31");
57  HLXToHFMap.push_back("HLX 15 - hf- s18,19 - iPhi 35");
58  HLXToHFMap.push_back("HLX 16 - hf- s20,21 - iPhi 39");
59  HLXToHFMap.push_back("HLX 17 - hf- s22,23 - iPhi 43");
60  HLXToHFMap.push_back("HLX 18 - hf- s24,25 - iPhi 47");
61  HLXToHFMap.push_back("HLX 19 - hf+ s14,15 - iPhi 27");
62  HLXToHFMap.push_back("HLX 20 - hf+ s16,17 - iPhi 31");
63  HLXToHFMap.push_back("HLX 21 - hf+ s18,19 - iPhi 35");
64  HLXToHFMap.push_back("HLX 22 - hf+ s20,21 - iPhi 39");
65  HLXToHFMap.push_back("HLX 23 - hf+ s22,23 - iPhi 43");
66  HLXToHFMap.push_back("HLX 24 - hf+ s24,25 - iPhi 47");
67  HLXToHFMap.push_back("HLX 25 - hf- s2,3 - iPhi 3");
68  HLXToHFMap.push_back("HLX 26 - hf- s4,5 - iPhi 7");
69  HLXToHFMap.push_back("HLX 27 - hf- s6,7 - iPhi 11");
70  HLXToHFMap.push_back("HLX 28 - hf- s8,9 - iPhi 15");
71  HLXToHFMap.push_back("HLX 29 - hf- s10,11 - iPhi 19");
72  HLXToHFMap.push_back("HLX 30 - hf- s12,13 - iPhi 23");
73  HLXToHFMap.push_back("HLX 31 - hf+ s2,3 - iPhi 3");
74  HLXToHFMap.push_back("HLX 32 - hf+ s4,5 - iPhi 7");
75  HLXToHFMap.push_back("HLX 33 - hf+ s6,7 - iPhi 11");
76  HLXToHFMap.push_back("HLX 34 - hf+ s8,9 - iPhi 15");
77  HLXToHFMap.push_back("HLX 35 - hf+ s10,11 - iPhi 19");
78  HLXToHFMap.push_back("HLX 36 - hf+ s12,13 - iPhi 23");
79 
80  int iEta[] = {-41,-41,-41,-41,-41,-41,
81  29, 29, 29, 29, 29, 29,
82  -41,-41,-41,-41,-41,-41,
83  29, 29, 29, 29, 29, 29,
84  -41,-41,-41,-41,-41,-41,
85  29, 29, 29, 29, 29, 29};
86 
87  int iPhi[] = { 51,55,59,63,67,71,
88  51,55,59,63,67,71,
89  27,31,35,39,43,47,
90  27,31,35,39,43,47,
91  3,7,11,15,19,23,
92  3,7,11,15,19,23};
93 
94  for( unsigned int iHLX = 0; iHLX < 36; ++iHLX ){
95  HLXToHFMap_[iHLX] = HLXToHFMap[iHLX];
96  iEta_[iHLX] = iEta[iHLX];
97  iPhi_[iHLX] = iPhi[iHLX];
98  }
99 
100  // allocate memory for histograms
101 
102  c1_ = new TCanvas("c1","c1",700,500);
103  c1_->SetTicks(1,1);
104 
105  NBins_ = 3400;
106  XMin_ = 100;
107  XMax_ = 3500;
108  BinWidth_ = (unsigned int)(XMax_ - XMin_)/NBins_;
109 
110  for( unsigned int iHisto = 0; iHisto < 8; ++iHisto ){
111  HLXHistos_[iHisto] = new TH1F(HistoNames[iHisto].c_str(),"", NBins_, XMin_, XMax_);
112  HLXHistos_[iHisto]->GetXaxis()->SetTitle("Bunch Crossing");
113  HLXHistos_[iHisto]->GetYaxis()->SetTitleOffset(1.3);
114  HLXHistos_[iHisto]->SetFillColor(kBlue);
115  }
116 
117  HLXHistos_[0]->GetYaxis()->SetTitle("Et Sum (1 LS)");
118  HLXHistos_[7]->GetYaxis()->SetTitle("LHC (1 LS)");
119  for( unsigned int iHisto = 0; iHisto < 6; ++iHisto ){
120  HLXHistos_[iHisto+1]->GetYaxis()->SetTitle("Occupancy (1 LS)");
121  }
122 
123  EtSummary_ = new TH2F("EtSummary", "Avg Et Sum Per Wedge", 12, -42, 42, 18, 0, 72);
124  EtSummary_->GetXaxis()->SetTitle("i #eta");
125  EtSummary_->GetYaxis()->SetTitle("i #phi");
126  OccSummary_ = new TH2F("OccSummary", "Avg Occupancy Per Wedge", 12, -42, 42, 18, 0, 72);
127  OccSummary_->GetXaxis()->SetTitle("i #eta");
128  OccSummary_->GetYaxis()->SetTitle("i #phi");
129 
130  MaxEtSummary_ = new TH2F("MaxEtSummary", "BX with Max Et Sum Per Wedge", 12, -42, 42, 18, 0, 72);
131  MaxEtSummary_->GetXaxis()->SetTitle("i #eta");
132  MaxEtSummary_->GetYaxis()->SetTitle("i #phi");
133  MaxLHCSummary_ = new TH2F("MaxLHCSummary", "BX with Max LHC Occupancy Per Wedge", 12, -42, 42, 18, 0, 72);
134  MaxLHCSummary_->GetXaxis()->SetTitle("i #eta");
135  MaxLHCSummary_->GetYaxis()->SetTitle("i #phi");
136 
137  ETLumiHisto_ = new TH1F("ETLumi", "E_{T} Lumi", NBins_, XMin_, XMax_);
138  ETLumiHisto_->GetXaxis()->SetTitle("Bunch Crossing");
139  OccLumiSet1Histo_ = new TH1F("OccLumiSet1", "Occupancy Lumi Set1", NBins_, XMin_, XMax_);
140  OccLumiSet1Histo_->GetXaxis()->SetTitle("Bunch Crossing");
141  OccLumiSet2Histo_ = new TH1F("OccLumiSet2", "Occupancy Lumi Set2", NBins_, XMin_, XMax_);
142  OccLumiSet2Histo_->GetXaxis()->SetTitle("Bunch Crossing");
143 
144 }
145 
146 HCAL_HLX::HTMLGenerator::~HTMLGenerator(){
147 
148  delete RFReader_;
149  delete lumiSection_;
150 
151  delete c1_;
152 
153  delete HLXHistos_[0];
154  delete HLXHistos_[1];
155  delete HLXHistos_[2];
156  delete HLXHistos_[3];
157  delete HLXHistos_[4];
158  delete HLXHistos_[5];
159  delete HLXHistos_[6];
160  delete HLXHistos_[7];
161 
162  delete ETLumiHisto_;
163  delete OccLumiSet1Histo_;
164  delete OccLumiSet2Histo_;
165 
166  delete EtSummary_;
167  delete OccSummary_;
168 
169  delete MaxEtSummary_;
170  delete MaxLHCSummary_;
171 
172 }
173 
174 // ******** Configuration *******
175 
176 void HCAL_HLX::HTMLGenerator::SetEtSumOnly( const bool bEtSumOnly ){
177  bEtSumOnly_ = bEtSumOnly;
178  RFReader_->SetEtSumOnly( bEtSumOnly );
179 }
180 
181 void HCAL_HLX::HTMLGenerator::SetHistoBins(unsigned int NBins, double XMin, double XMax){
182 
183  NBins_ = NBins;
184 
185  if( XMax < XMin){
186  XMax_ = XMin;
187  XMin_ = XMax;
188  }else{
189  XMax_ = XMax;
190  XMin_ = XMin;
191  }
192 
193  for( unsigned int iHisto = 0; iHisto < 8; ++iHisto){
194  HLXHistos_[iHisto]->SetBins(NBins_, XMin_, XMax_);
195  }
196  ETLumiHisto_->SetBins(NBins_, XMin_, XMax_);
197  OccLumiSet1Histo_->SetBins(NBins_, XMin_, XMax_);
198  OccLumiSet2Histo_->SetBins(NBins_, XMin_, XMax_);
199 
200  BinWidth_ = (unsigned int )(XMax_ - XMin_)/NBins_;
201 
202 }
203 
204 // ******** Main function ******
205 void HCAL_HLX::HTMLGenerator::CreateWebPage(const std::string &fileName, const unsigned int iEntry){
206 
207  RFReader_->SetFileName( fileName );
208  RFReader_->GetEntry( iEntry );
209  RFReader_->GetLumiSection( *lumiSection_ );
210 
211  MakeDir( outputDir_ + GetRunDir() + GetLSDir(), writeMode_ );
212 
213  for(unsigned int iHLX = 0; iHLX < 36; ++iHLX){
214  MakeDir(outputDir_ + GetRunDir() + GetLSDir() + GetHLXDir(iHLX), writeMode_ );
215  GenerateHLXPage(iHLX);
216  MakeDir(outputDir_ + GetRunDir() + GetLSDir() + GetHLXDir(iHLX) + GetHLXPicDir(iHLX), writeMode_ );
217  GenerateHLXPlots(iHLX);
218  }
219 
220  GenerateAveragePlots();
221  GenerateAveragePage();
222 
223  GenerateComparePlots();
224  GenerateComparePage();
225 
226  if( !bEtSumOnly_ ){
227  GenerateLumiPage();
228  }
229 
230  for(unsigned int iHisto = 0; iHisto < 8; ++iHisto){
231  GenerateHistoGroupPage(HistoNames[iHisto]);
232  }
233 
234  GenerateSectionPage();
235  GenerateRunPage();
236  GenerateIndexPage();
237 }
238 
239 // *********** Set Functions *************
240 
241 void HCAL_HLX::HTMLGenerator::SetInputDir(const std::string &inDir ){
242 
243  RFReader_->SetDir( inDir );
244 }
245 
246 void HCAL_HLX::HTMLGenerator::SetFileType( const std::string &fileType){
247 
248  RFReader_->SetFileType( fileType );
249 }
250 
251 // ************* Get Directory name functions ****************
252 
253 std::string HCAL_HLX::HTMLGenerator::GetRunDir(){
254  // convert from up to 9 digit integer to XXX/YYY/ZZZ
255 
256  std::stringstream dirName;
257 
258  dirName.str(std::string());
259  dirName << std::setw(3) << std::setfill('0') << (lumiSection_->hdr.runNumber / 1000000)
260  << "/" << std::setw(3) << std::setfill('0') << (lumiSection_->hdr.runNumber % 1000000) / 1000
261  << "/" << std::setw(3) << std::setfill('0') << (lumiSection_->hdr.runNumber % 1000)
262  << "/";
263 
264  return dirName.str();
265 }
266 
267 std::string HCAL_HLX::HTMLGenerator::GetLSDir(){
268 
269  std::stringstream dirName;
270  dirName.str(std::string());
271  dirName << std::setw(4) << std::setfill('0') << lumiSection_->hdr.sectionNumber << "/";
272 
273  return dirName.str();
274 }
275 
276 std::string HCAL_HLX::HTMLGenerator::GetHLXDir(const unsigned short int &HLXID){
277 
278  std::stringstream dirName;
279  dirName.str(std::string());
280  dirName << "HLX" << std::setw(2) << std::setfill('0') << HLXID << "/";
281 
282  return dirName.str();
283 }
284 
285 std::string HCAL_HLX::HTMLGenerator::GetHLXPicDir( const unsigned short int &HLXID ){
286 
287  return "Pics/";
288 }
289 
290 // ************ Generate Pages *******
291 
292 void HCAL_HLX::HTMLGenerator::GenerateIndexPage(){
293 
294  std::string fileName;
295  fileName = outputDir_ + "index.html";
296 
297  if( !fileExists(fileName) ){
298  std::string fileTitle = "Luminosity Monitoring System";
299 
300  MakeEmptyWebPage( fileName, fileTitle);
301  InsertLineAfter( fileName, "<H1>\nLuminosity Monitoring System\n</H1>", "<body>");
302  }
303 
304 
305  if( lumiSection_->hdr.runNumber != previousRunNumber ){
306  std::stringstream runLine;
307  runLine << "<a href = \""
308  << GetRunDir()
309  << "index.html\"> Run - "
310  << lumiSection_->hdr.runNumber << "</a> "
311  << TimeStampLong()
312  << "</br>";
313  previousRunNumber = lumiSection_->hdr.runNumber;
314  InsertLineBefore( fileName, runLine.str(), "</body>");
315  }
316 }
317 
318 void HCAL_HLX::HTMLGenerator::GenerateRunPage(){
319 
320  std::string fileName;
321 
322  fileName = outputDir_ + GetRunDir() + "index.html";
323 
324  if(!fileExists(fileName)){
325  std::stringstream fileTitle;
326 
327  fileTitle << "Luminosity File Reader - Run " << lumiSection_->hdr.runNumber;
328  MakeEmptyWebPage(fileName, fileTitle.str());
329  }
330 
331  std::stringstream sectionLine;
332 
333  sectionLine << "<a href = \""
334  << GetLSDir()
335  << "index.html\"> Run - "
336  << lumiSection_->hdr.runNumber << " Section "
337  << lumiSection_->hdr.sectionNumber << "</a> "
338  << TimeStampLong() << "</br>";
339 
340  InsertLineBefore( fileName, sectionLine.str(), "</body>");
341 }
342 
343 void HCAL_HLX::HTMLGenerator::GenerateSectionPage(){
344  // list all the individual HLX pages
345  // make section directory
346 
347  std::ofstream fileStr;
348  std::string fileName;
349 
350  fileName = outputDir_ + GetRunDir() + GetLSDir() + "index.html";
351  fileStr.open(fileName.c_str());
352 
353  fileStr << "<html>" << std::endl;
354  fileStr << "<title>" << std::endl;
355  fileStr << "Luminosity File Reader - " << "Run " << lumiSection_->hdr.runNumber << " - "
356  << " Lumi Section - " << lumiSection_->hdr.sectionNumber << std::endl;
357  fileStr << "</title>" << std::endl;
358  fileStr << "<body>" << std::endl;
359 
360  fileStr << "<a href=\""
361  << HistoNames[0]
362  << "/index.html\" >"
363  << HistoNames[0] << "</a></br>" << std::endl;
364 
365  if( !bEtSumOnly_ ){
366  for(int unsigned iHisto = 1; iHisto < 8; ++iHisto){
367  fileStr << "<a href=\""
368  << HistoNames[iHisto]
369  << "/index.html\" >"
370  << HistoNames[iHisto] << "</a></br>" << std::endl;
371  }
372  fileStr << "<a href=\"Luminosity/index.html\">Luminosity</a>" << std::endl;
373  }
374 
375  fileStr << "</br>" << std::endl;
376  fileStr << "</br>" << std::endl;
377 
378  fileStr << "<hr>" << std::endl;
379  fileStr << "Summary" << std::endl;
380  fileStr << "<hr>" << std::endl;
381 
382  c1_->cd();
383  gStyle->SetOptStat(0);
384  gStyle->SetPalette(1);
385 
386  // Et Sum Summary
387  EtSummary_->Reset();
388  MaxEtSummary_->Reset();
389 
390  float MaxAvgEt = 0.0;
391  float MinAvgEt = 1000000000.0;
392  for( unsigned int iHLX = 0; iHLX < 36; ++iHLX ){
393 
394  float MaxEt = -1.0;
395  unsigned int MaxEtBX = 0;
396  float AvgEtSum = 0.0;
397 
398  for( unsigned int iBX = static_cast<unsigned int>(XMin_); iBX < XMax_; ++iBX){
399  // Total Et Sum from all BX for each HLX.
400  AvgEtSum += lumiSection_->etSum[iHLX].data[iBX];
401 
402  // Find the BX with the max Et sum for each HLX.
403  if( lumiSection_->etSum[iHLX].data[iBX] > MaxEt ){
404  MaxEt = lumiSection_->etSum[iHLX].data[iBX];
405  MaxEtBX = iBX;
406  }
407  }
408  // Divide by the number of bunch crossings times the number of orbits
409  // to get the average et sum per wedge.
410  AvgEtSum /= ((XMax_ - XMin_)*lumiSection_->hdr.numOrbits);
411 
412  if( AvgEtSum > MaxAvgEt ) MaxAvgEt = AvgEtSum;
413  if( AvgEtSum < MinAvgEt ) MinAvgEt = AvgEtSum;
414 
415  EtSummary_->Fill( iEta_[iHLX], iPhi_[iHLX], AvgEtSum );
416  EtSummary_->Fill( iEta_[iHLX] +7, iPhi_[iHLX], AvgEtSum );
417 
418  MaxEtSummary_->Fill( iEta_[iHLX], iPhi_[iHLX], MaxEtBX );
419  MaxEtSummary_->Fill( iEta_[iHLX] +7, iPhi_[iHLX], MaxEtBX );
420  }
421 
422  fileStr << "<img src=\"EtSummary.png\" usemap=\"#HLXSummary\" border=\"0\" width=\"45%\">" << std::endl;
423  fileStr << "<img src=\"MaxEtSummary.png\" usemap=\"#HLXSummary\" border=\"0\" width=\"45%\">" << std::endl;
424 
425  std::string picName = outputDir_ + GetRunDir() + GetLSDir() + "EtSummary." + plotExt_;
426  EtSummary_->GetZaxis()->SetRangeUser( MinAvgEt - 0.0000001, MaxAvgEt + 0.0000001 );
427  EtSummary_->Draw("colz");
428  c1_->SaveAs(picName.c_str());
429 
430  picName = outputDir_ + GetRunDir() + GetLSDir() + "MaxEtSummary." + plotExt_;
431  MaxEtSummary_->GetZaxis()->SetRangeUser( 0, 3564 );
432  MaxEtSummary_->Draw("colz");
433  c1_->SaveAs(picName.c_str());
434 
435  if( !bEtSumOnly_ ){
436  // LHC and Occ Summary
437  MaxLHCSummary_->Reset();
438  OccSummary_->Reset();
439 
440  float MaxOcc = 0.0;
441  float MinOcc = 1000000000.0;
442 
443  for( int iHLX = 0; iHLX < 36; ++iHLX){
444  float MaxLHC = -1;
445  unsigned int MaxLHCBX = 0;
446 
447  // Find average occupancy.
448  float AvgOccSet1 = 0.0;
449  float AvgOccSet2 = 0.0;
450 
451  for( int iBX = 100; iBX < 3500; ++iBX){
452  AvgOccSet1 += lumiSection_->occupancy[iHLX].data[0][iBX];
453  AvgOccSet2 += lumiSection_->occupancy[iHLX].data[3][iBX];
454  if( lumiSection_->lhc[iHLX].data[iBX] > MaxLHC ){
455  MaxLHC = lumiSection_->lhc[iHLX].data[iBX];
456  MaxLHCBX = iBX;
457  }
458  }
459 
460  AvgOccSet1 /= (3400.0*lumiSection_->hdr.numOrbits);
461  AvgOccSet2 /= (3400.0*lumiSection_->hdr.numOrbits);
462 
463  // Find the range of occupancy set 1.
464  if( AvgOccSet1 > MaxOcc ){
465  MaxOcc = AvgOccSet1;
466  }
467  if( AvgOccSet1 < MinOcc ){
468  MinOcc = AvgOccSet1;
469  }
470 
471  // Find the range of occupancy set 1.
472  if( AvgOccSet2 > MaxOcc ){
473  MaxOcc = AvgOccSet2;
474  }
475  if( AvgOccSet1 < MinOcc ){
476  MinOcc = AvgOccSet1;
477  }
478 
479  if( iEta_[iHLX] > 0 ){
480  OccSummary_->Fill( iEta_[iHLX] +7 , iPhi_[iHLX], AvgOccSet1 );
481  OccSummary_->Fill( iEta_[iHLX], iPhi_[iHLX], AvgOccSet2 );
482  }
483 
484  if( iEta_[iHLX] < 0 ){
485  OccSummary_->Fill( iEta_[iHLX], iPhi_[iHLX], AvgOccSet1 );
486  OccSummary_->Fill( iEta_[iHLX] + 7, iPhi_[iHLX], AvgOccSet2 );
487  }
488 
489  MaxLHCSummary_->Fill( iEta_[iHLX], iPhi_[iHLX], MaxLHCBX );
490  MaxLHCSummary_->Fill( iEta_[iHLX] +7, iPhi_[iHLX], MaxLHCBX );
491  }
492 
493  picName = outputDir_ + GetRunDir() + GetLSDir() + "MaxLHCSummary." + plotExt_;
494  MaxLHCSummary_->GetZaxis()->SetRangeUser( 0, 3564 );
495  MaxLHCSummary_->Draw("colz");
496  c1_->SaveAs(picName.c_str());
497 
498  picName = outputDir_ + GetRunDir() + GetLSDir() + "OccSummary.png";
499  OccSummary_->GetZaxis()->SetRangeUser( MinOcc - 0.0000001, MaxOcc + 0.0000001 );
500  OccSummary_->Draw("colz");
501  c1_->SaveAs(picName.c_str());
502 
503  fileStr << "<img src=\"OccSummary.png\" usemap=\"#HLXSummary\" border=\"0\" width=\"45%\"></br>" << std::endl;
504  fileStr << "<img src=\"MaxLHCSummary.png\" usemap=\"#HLXSummary\" border=\"0\" width=\"45%\"></br>" << std::endl;
505  }
506 
507  fileStr << "<hr>" << std::endl;
508  fileStr << "<H2>" << std::endl;
509  fileStr << "HLX ID </br>" << std::endl;
510  fileStr << "<hr>" << std::endl;
511  fileStr << "</H2>" << std::endl;
512  fileStr << "<H3>" << std::endl;
513  fileStr << "<verbatim>" << std::endl;
514 
515  for(unsigned int iHLX = 0; iHLX < 36; ++iHLX){
516  fileStr << "<a href=\"HLX"
517  << std::setw(2) << std::setfill('0') << iHLX
518  << "/index.html\" >"
519  << HLXToHFMap_[iHLX]
520  << "</a> </br>" << std::endl;
521  }
522 
523  fileStr << "</verbatim>" << std::endl;
524  fileStr << "</H3>" << std::endl;
525 
526  // Create HTML map. Get it to scale.....
527  unsigned int HFPlusLeftEdge = 532;
528  unsigned int HFPlusRightEdge = 625;
529  unsigned int HFMinusLeftEdge = 70;
530  unsigned int HFMinusRightEdge = 160;
531 
532  unsigned int BoxTop = 47;
533  unsigned int BoxHeight = 20;
534 
535  unsigned int HTMLMap_[] = { 5,4,3,2,1,0,
536  17,16,15,14,13,12,
537  29,28,27,26,25,24,
538  11,10,9,8,7,6,
539  23,22,21,20,19,18,
540  35,34,33,32,31,30 };
541 
542  fileStr << "<map name='HLXSummary'>" << std::endl;
543  for( unsigned int iBox = 0; iBox < 18; ++iBox ){
544  fileStr << "<area shape='rect' coords='" << HFMinusLeftEdge << "," << BoxTop + iBox*(BoxHeight + 1)
545  << "," << HFMinusRightEdge << "," << BoxTop + (iBox + 1)*(BoxHeight + 1) -1 << "' href='HLX"
546  << std::setw(2) << std::setfill('0') << HTMLMap_[iBox] << "/index.html' >" << std::endl;
547 
548  fileStr << "<area shape='rect' coords='" << HFPlusLeftEdge << "," << BoxTop + iBox*(BoxHeight + 1)
549  << "," << HFPlusRightEdge << "," << BoxTop + (iBox + 1)*(BoxHeight + 1) -1 << "' href='HLX"
550  << std::setw(2) << std::setfill('0') << HTMLMap_[iBox + 18] << "/index.html' >" << std::endl;
551  }
552 
553  fileStr << "</map>" << std::endl;
554 
555  fileStr << "</body>" << std::endl;
556  fileStr << "</html>" << std::endl;
557 
558  fileStr.close();
559 }
560 
561 void HCAL_HLX::HTMLGenerator::GenerateHLXPage(const unsigned short int &HLXID){
562 
563  // make HLX directory
564  std::stringstream fileName;
565  fileName.str(std::string());
566  fileName << outputDir_ << GetRunDir() << GetLSDir() << GetHLXDir(HLXID) << "index.html";
567 
568  std::ofstream fileStr;
569  fileStr.open(fileName.str().c_str());
570 
571  fileStr << "<html>" << std::endl;
572  fileStr << "<title>" << std::endl;
573  fileStr << "Luminosity File Reader - "
574  << "Run " << lumiSection_->hdr.runNumber
575  << " Lumi Section " << lumiSection_->hdr.sectionNumber
576  << HLXToHFMap_[HLXID]
577  << std::endl;
578  fileStr << "</title>" << std::endl;
579  fileStr << "<body>" << std::endl;
580 
581  fileStr << "<H1>" << std::endl;
582  fileStr << "Luminosity File Reader - "
583  << "Run " << lumiSection_->hdr.runNumber << " - "
584  << " Lumi Section " << lumiSection_->hdr.sectionNumber << " - "
585  << HLXToHFMap_[HLXID]
586  << std::endl;
587  fileStr << "</H1>" << std::endl;
588  fileStr << "<hr>" << std::endl;
589 
590  // Et Sum
591  fileStr << "<a href=\"Pics/"<< HistoNames[0] << "." << plotExt_ << "\"><img src=\"Pics/"
592  << HistoNames[0] << "." << plotExt_ << "\" width=\"30%\"></a>" << std::endl;
593 
594  if( !bEtSumOnly_ ){
595  // LHC
596  fileStr << "<a href=\"Pics/"<< HistoNames[7] << "." << plotExt_ << "\"><img src=\"Pics/"
597  << HistoNames[7] << "." << plotExt_ << "\" width=\"30%\"></a></br>"<< std::endl;
598 
599  // Occupancy Set 1
600  fileStr << "<a href=\"Pics/"<< HistoNames[1] << "." << plotExt_ << "\"><img src=\"Pics/"
601  << HistoNames[1] << "." << plotExt_ << "\" width=\"30%\"></a>" << std::endl;
602  fileStr << "<a href=\"Pics/"<< HistoNames[2] << "." << plotExt_ << "\"><img src=\"Pics/"
603  << HistoNames[2] << "." << plotExt_ << "\" width=\"30%\"></a>" << std::endl;
604  fileStr << "<a href=\"Pics/"<< HistoNames[3] << "." << plotExt_ << "\"><img src=\"Pics/"
605  << HistoNames[3] << "." << plotExt_ << "\" width=\"30%\"></a></br>" << std::endl;
606 
607  // Occupancy Set 2
608  fileStr << "<a href=\"Pics/"<< HistoNames[4] << "." << plotExt_ << "\"><img src=\"Pics/"
609  << HistoNames[4] << "." << plotExt_ << "\" width=\"30%\"></a>" << std::endl;
610  fileStr << "<a href=\"Pics/"<< HistoNames[5] << "." << plotExt_ << "\"><img src=\"Pics/"
611  << HistoNames[5] << "." << plotExt_ << "\" width=\"30%\"></a>" << std::endl;
612  fileStr << "<a href=\"Pics/"<< HistoNames[6] << "." << plotExt_ << "\"><img src=\"Pics/"
613  << HistoNames[6] << "." << plotExt_ << "\" width=\"30%\"></a></br>"<< std::endl;
614  }
615 
616  fileStr << "</body>" << std::endl;
617  fileStr << "</html>" << std::endl;
618  fileStr.close();
619 }
620 
621 
622 void HCAL_HLX::HTMLGenerator::GenerateHLXPlots(const unsigned short int & HLXID){
623 
624  for(unsigned int iHisto = 0; iHisto < 8; ++iHisto ){
625  HLXHistos_[iHisto]->Reset();
626  std::stringstream HistoTitle;
627  HistoTitle.str(std::string());
628  HistoTitle << HistoNames[iHisto] << " - " << HLXToHFMap_[HLXID];
629  HLXHistos_[iHisto]->SetTitle(HistoTitle.str().c_str());
630  }
631 
632  if( lumiSection_->hdr.numOrbits > 0 ){
633 
634  double EtSumNoise[4];
635 
636  EtSumNoise[0] = 0;
637  EtSumNoise[1] = 0;
638  EtSumNoise[2] = 0;
639  EtSumNoise[3] = 0;
640 
641  // The noise range is arbitrary.
642  for( unsigned int iBX = 2750; iBX < 3250; ++iBX ){
643  EtSumNoise[iBX % 4] += lumiSection_->etSum[HLXID].data[iBX];
644  }
645 
646  EtSumNoise[0] /= 125.0;
647  EtSumNoise[1] /= 125.0;
648  EtSumNoise[2] /= 125.0;
649  EtSumNoise[3] /= 125.0;
650 
651  for(unsigned int iBX = 0; iBX < 3564; ++iBX ){
652 
653  HLXHistos_[0]->Fill( iBX, (lumiSection_->etSum[HLXID].data[iBX] - EtSumNoise[iBX % 4]) / (float)(lumiSection_->hdr.numOrbits));
654  }
655 
656  if( !bEtSumOnly_ ){
657  for(unsigned int iBX = 0; iBX < 3564; ++iBX ){
658  HLXHistos_[7]->Fill( iBX, lumiSection_->lhc[HLXID].data[iBX]);
659 
660  for(unsigned int k = 0; k < 6; ++k){
661  HLXHistos_[k+1]->Fill(iBX, ((float)(lumiSection_->occupancy[HLXID].data[k][iBX]) / (float)(lumiSection_->hdr.numOrbits)));
662  }
663  }
664  }
665  }
666 
667  const std::string HLXPicsDir = outputDir_ + GetRunDir() + GetLSDir() + GetHLXDir(HLXID) + GetHLXPicDir(HLXID);
668 
669  //c1->SetLogy();
670  // Draw Histograms and make pngs
671  c1_->cd();
672 
673  // Draw and save Et Sum histogram.
674  HLXHistos_[0]->Draw();
675  std::string plotFileName = HLXPicsDir + HistoNames[0 ] + "." + plotExt_;
676  c1_->SaveAs(plotFileName.c_str());
677 
678  // Draw and save LHC and occupancy histograms.
679  if( !bEtSumOnly_ ){
680  for(unsigned int iHisto = 1; iHisto < 8; ++iHisto ){
681  HLXHistos_[iHisto]->Draw();
682  std::string plotFileName = HLXPicsDir + HistoNames[ iHisto ] + "." + plotExt_;
683  c1_->SaveAs(plotFileName.c_str());
684  }
685  }
686 }
687 
688 void HCAL_HLX::HTMLGenerator::GenerateComparePlots(){}
689 
690 void HCAL_HLX::HTMLGenerator::GenerateComparePage(){}
691 
692 void HCAL_HLX::HTMLGenerator::GenerateAveragePlots(){}
693 
694 void HCAL_HLX::HTMLGenerator::GenerateAveragePage(){}
695 
696 void HCAL_HLX::HTMLGenerator::GenerateHistoGroupPage(const std::string &HistoName){
697 
698  std::string fileName;
699  std::string pageDir;
700 
701  pageDir = outputDir_ + GetRunDir() + GetLSDir() + HistoName;
702  MakeDir(pageDir, writeMode_);
703 
704  fileName = pageDir + "/index.html";
705 
706  std::ofstream fileStr;
707  fileStr.open(fileName.c_str());
708 
709  fileStr << "<html>" << std::endl;
710  fileStr << "<title>" << std::endl;
711  fileStr << "Luminosity File Reader - "
712  << "Run " << lumiSection_->hdr.runNumber
713  << " Lumi Section " << lumiSection_->hdr.sectionNumber
714  << " - " << HistoName
715  << std::endl;
716  fileStr << "</title>" << std::endl;
717  fileStr << "<body>" << std::endl;
718 
719  fileStr << "<H1>" << std::endl;
720  fileStr << "Luminosity File Reader - "
721  << "Run " << lumiSection_->hdr.runNumber
722  << " Lumi Section " << lumiSection_->hdr.sectionNumber
723  << " - " << HistoName
724  << std::endl;
725  fileStr << "</H1>" << std::endl;
726  fileStr << "<hr>" << std::endl;
727 
728  for(int HLXID = 0; HLXID < 36; HLXID++){
729  fileStr << "<a href=\"../HLX" << std::setw(2) << std::setfill('0') << HLXID
730  << "/Pics/" << HistoName << "." << plotExt_ << "\"><img src=\"../HLX"
731  << std::setw(2) << std::setfill('0') << HLXID << "/Pics/" << HistoName << "."
732  << plotExt_ << "\" width=\"15%\" ></a>" << std::endl;
733  }
734  fileStr << "</body>" << std::endl;
735  fileStr << "</html>" << std::endl;
736  fileStr.close();
737 }
738 
739 void HCAL_HLX::HTMLGenerator::GenerateLumiPage(){
740 
741  std::string fileName;
742  std::string pageDir;
743 
744  pageDir = outputDir_ + GetRunDir() + GetLSDir() + "Luminosity/";
745  MakeDir(pageDir + "/Pics" , writeMode_ );
746 
747  fileName = pageDir + "index.html";
748 
749  std::ofstream fileStr;
750 
751  fileStr.open(fileName.c_str());
752 
753  fileStr << "<html>" << std::endl;
754  fileStr << "<title>" << std::endl;
755  fileStr << "Luminosity File Reader - "
756  << "Run " << lumiSection_->hdr.runNumber
757  << " Lumi Section " << lumiSection_->hdr.sectionNumber
758  << " Luminosity"
759  << std::endl;
760  fileStr << "</title>" << std::endl;
761  fileStr << "<body>" << std::endl;
762 
763  fileStr << "<H1>" << std::endl;
764  fileStr << "Luminosity File Reader - "
765  << "Run " << lumiSection_->hdr.runNumber
766  << " Lumi Section " << lumiSection_->hdr.sectionNumber
767  << " - Luminosity "
768  << std::endl;
769  fileStr << "</H1>" << std::endl;
770  fileStr << "<hr>" << std::endl;
771 
772  fileStr << "<a href=\"Pics/EtSumLumi.png\"\"><img src=\"Pics/EtSumLumi.png\" width=\"30%\" ></a>" << std::endl;
773  fileStr << "<a href=\"Pics/OccLumiSet1.png\"\"><img src=\"Pics/OccLumiSet1.png\" width=\"30%\" ></a>" << std::endl;
774  fileStr << "<a href=\"Pics/OccLumiSet2.png\"\"><img src=\"Pics/OccLumiSet2.png\" width=\"30%\" ></a>" << std::endl;
775 
776  fileStr.close();
777 
778  //c1->SetLogy();
779  c1_->cd();
780 
781  for( unsigned int iBX = 0; iBX < 3564; ++iBX ){
782  int Bin = (int)(iBX - XMin_)/BinWidth_ + 1;
783  if( Bin < 1 ) Bin = 0;
784  if( Bin > (int)NBins_ ) Bin = NBins_ + 1;
785 
786  ETLumiHisto_-> Fill(iBX, lumiSection_->lumiDetail.ETLumi[iBX]);
787  ETLumiHisto_-> SetBinError( Bin, lumiSection_->lumiDetail.ETLumiErr[iBX]);
788  OccLumiSet1Histo_->Fill(iBX, lumiSection_->lumiDetail.OccLumi[0][iBX]);
789  OccLumiSet1Histo_->SetBinError( Bin, lumiSection_->lumiDetail.OccLumiErr[0][iBX]);
790  OccLumiSet2Histo_->Fill(iBX, lumiSection_->lumiDetail.OccLumi[1][iBX]);
791  OccLumiSet2Histo_->SetBinError( Bin, lumiSection_->lumiDetail.OccLumiErr[1][iBX]);
792  }
793 
794  ETLumiHisto_->Draw();
795  c1_->SaveAs( (pageDir + "/Pics/EtSumLumi.png").c_str() );
796 
797  OccLumiSet1Histo_->Draw();
798  c1_->SaveAs( (pageDir + "/Pics/OccLumiSet1.png").c_str() );
799 
800  OccLumiSet2Histo_->Draw();
801  c1_->SaveAs( (pageDir + "/Pics/OccLumiSet2.png").c_str() );
802 }
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
int k[5][pyjets_maxn]
std::string HistoName