Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:53

0001 #include <iostream>
0002 #include <vector>
0003 #include <string>
0004 #include <map>
0005 #include <sstream>
0006 
0007 #include "TFile.h"
0008 #include "TH1F.h"
0009 #include "THStack.h"
0010 #include "TCanvas.h"
0011 #include "TLegend.h"
0012 #include "TPaveText.h"
0013 #include "TSystem.h"
0014 
0015 void setCanvasStyle(TCanvas* c, const bool logScale);
0016 void setHistoStyle(TH1* h);
0017 void setHistoStackStyle(TH1* h, const unsigned int lineColor);
0018 void setLegendStyle(TLegend* l, const unsigned int nColumns);
0019 void setPaveTextStyle(TPaveText* t, const bool isHorizontal=true);
0020 void fillNormFactorMaps();
0021 double findNormFactor(const std::string currentPlotType, const std::string currentPart, const bool stackOption);
0022 void makePlots(std::string inputFileName, std::string outputFileName);
0023 
0024 // Map with <name of tracker part, count of channels in the part>
0025 // It is static so it can be read by the functions fillNormFactorMaps() and findNormFactor(...)
0026 static std::map<std::string, unsigned int> modulesStackNormFactors;
0027 static std::map<std::string, unsigned int> modulesNoStackNormFactors;
0028 static std::map<std::string, unsigned int> fibersStackNormFactors;
0029 static std::map<std::string, unsigned int> fibersNoStackNormFactors;
0030 static std::map<std::string, unsigned int> APVsStackNormFactors;
0031 static std::map<std::string, unsigned int> APVsNoStackNormFactors;
0032 static std::map<std::string, unsigned int> stripsStackNormFactors;
0033 static std::map<std::string, unsigned int> stripsNoStackNormFactors;
0034 
0035 int main(int argc , char *argv[]) {
0036 
0037   if(argc==3) {
0038     char* inputFileName = argv[1];
0039     char* outputFileName = argv[2];
0040 
0041     std::cout << "ready to make plots from " << inputFileName << " to " << outputFileName << std::endl;
0042 
0043     
0044     int returncode = 0;
0045     makePlots(inputFileName,outputFileName);
0046 
0047     return  returncode;
0048 
0049   }
0050   else {std::cout << "Too few arguments: " << argc << std::endl; return -1; }
0051 
0052   return -9;
0053 
0054 }
0055 
0056 
0057 void makePlots(std::string inputFileName, std::string outputFileName)
0058 {
0059   //
0060   
0061   
0062   // Open input and output file
0063   TFile* inputFile = new TFile(inputFileName.c_str(),"READ");
0064   TFile* outputFile = new TFile(outputFileName.c_str(), "RECREATE");
0065   
0066   std::ostringstream oss;
0067   std::string histoName;
0068   std::vector< std::string > plotType;
0069   plotType.push_back("BadModules"); plotType.push_back("BadFibers"); plotType.push_back("BadAPVs"); plotType.push_back("BadStrips"); plotType.push_back("BadStripsFromAPVs"); plotType.push_back("AllBadStrips");
0070   std::vector< std::string > subDetName;
0071   subDetName.push_back("TIB"); subDetName.push_back("TID+"); subDetName.push_back("TID-"); subDetName.push_back("TOB"); subDetName.push_back("TEC+"); subDetName.push_back("TEC-");
0072   
0073   // Standard plot options for THStack and for standalone histograms
0074   const bool stackHistograms = true;
0075   
0076   std::string plotStackOptions;
0077   if(stackHistograms)
0078     plotStackOptions = "";
0079   else
0080     plotStackOptions = "nostack p";
0081   const std::string plotHistoOptions("p");
0082   
0083   // Defer the filling of the normFactor maps to this function
0084   // Conceptually trivial but lengthy
0085   fillNormFactorMaps();
0086 
0087 //   // Finds number of channels from above map
0088 //   std::string completePartName = subDetName;
0089 //   if(partName.compare("") != 0)
0090 //     completePartName += " " + partName;
0091 //   if(partNumber != 0)
0092 //   {
0093 //     oss.str("");
0094 //     oss << partNumber;
0095 //     completePartName += " " + oss.str();
0096 //   }
0097 //   
0098 //   // Total number of channels in currently processed map
0099 //   const unsigned int nModulesInPart = allModulesTK[completePartName.c_str()];
0100 //   const unsigned int nFibersInPart = allFibersTK[completePartName.c_str()];
0101 //   const unsigned int nAPVsInPart = allAPVsTK[completePartName.c_str()];
0102 //   const unsigned int nStripsInPart = allStripsTK[completePartName.c_str()];
0103   
0104   
0105   TH1F* hTracker;
0106   TH1F* hTIB;
0107   TH1F* hTID;
0108   TH1F* hTOB;
0109   TH1F* hTEC;
0110   TH1F* histo;
0111   TH1F* histo2;
0112   THStack* histoStack;
0113   TCanvas* c1;
0114   TCanvas* c2;
0115   TLegend* legend;
0116   TLegend* legend2;
0117   TPaveText* textX;
0118   TPaveText* textY;
0119   std::string entryLabel;
0120   std::vector<TH1F*> hLayers;
0121 //   unsigned int normFactor;
0122   
0123   for(std::vector< std::string >::iterator itPlot=plotType.begin(); itPlot!=plotType.end(); itPlot++)
0124   {
0125     // Put together the Tracker histograms with the TIB, TID, TOB and TEC ones
0126     
0127     histoName = "h" + *itPlot + "Tracker";
0128     hTracker = (TH1F*)inputFile->Get(histoName.c_str());
0129     if(hTracker) {
0130       hTracker->Scale(1/findNormFactor(*itPlot,"Tracker",stackHistograms));
0131     }
0132     else {std::cout << histoName << " not found" << std::endl;}
0133 
0134     histoStack = new THStack(histoName.c_str(), histoName.c_str());
0135 
0136     histoName = "h" + *itPlot + "TIB";
0137     hTIB = (TH1F*)inputFile->Get(histoName.c_str());
0138     if(hTIB) {
0139       hTIB->Scale(1/findNormFactor(*itPlot,"TIB",stackHistograms));
0140     }
0141     else {std::cout << histoName << " not found" << std::endl;}
0142     
0143     histoName = "h" + *itPlot + "TID";
0144     hTID = (TH1F*)inputFile->Get(histoName.c_str());
0145     if(hTID) {
0146       hTID->Scale(1/findNormFactor(*itPlot,"TID",stackHistograms));
0147     }
0148     else {std::cout << histoName << " not found" << std::endl;}
0149 
0150     histoName = "h" + *itPlot + "TOB";
0151     hTOB = (TH1F*)inputFile->Get(histoName.c_str());
0152     if(hTOB) {
0153       hTOB->Scale(1/findNormFactor(*itPlot,"TOB",stackHistograms));
0154     }
0155     else {std::cout << histoName << " not found" << std::endl;}
0156 
0157     histoName = "h" + *itPlot + "TEC";
0158     hTEC = (TH1F*)inputFile->Get(histoName.c_str());
0159     if(hTEC) {
0160       hTEC->Scale(1/findNormFactor(*itPlot,"TEC",stackHistograms));
0161     }
0162     else {std::cout << histoName << " not found" << std::endl;}
0163     
0164     c1 = new TCanvas(("c"+*itPlot+"Tracker").c_str(), "", 1200, 600);
0165     setCanvasStyle(c1, false);
0166     //     hTracker->Draw();
0167     if(hTracker) setHistoStackStyle(hTracker,1);
0168     //     hTIB->Draw("same");
0169     if(hTIB) {
0170       setHistoStackStyle(hTIB,2);
0171       histoStack->Add(hTIB);
0172     }
0173     //     hTID->Draw("same");
0174     if(hTID) {
0175       setHistoStackStyle(hTID,3);
0176       histoStack->Add(hTID);
0177     }
0178     //     hTOB->Draw("same");
0179     if(hTOB) {
0180       setHistoStackStyle(hTOB,4);
0181       histoStack->Add(hTOB);
0182     }
0183     //     hTEC->Draw("same");
0184     if(hTEC) {
0185       setHistoStackStyle(hTEC,6);
0186       histoStack->Add(hTEC);
0187     }
0188     // Bug in ROOT? If we plot a stack with the "stack" option and the Y axis is in log scale,
0189     // but there are no entries in any of the histograms of the stack, then ROOT crashes
0190     // Workaround: at this stage, check that at least one histogram has >0 entries,
0191     // otherwise, switch back to linear Y scale
0192     // Curiously, there is no crash if the "nostack" option is chosen...
0193     double histoStackMaximum = histoStack->GetMaximum();
0194     if(histoStackMaximum==0)
0195     {
0196       c1->SetLogy(0);
0197     }
0198     histoStack->Draw(plotStackOptions.c_str());
0199     if(histoStack->GetYaxis()->GetXmax() > 0.9)
0200       histoStack->GetYaxis()->SetRangeUser(0.,0.1);
0201     legend = new TLegend(0.4,0.9,0.9,1);
0202     legend->AddEntry(hTIB, "TIB");
0203     legend->AddEntry(hTID, "TID");
0204     legend->AddEntry(hTOB, "TOB");
0205     legend->AddEntry(hTEC, "TEC");
0206     setLegendStyle(legend, 2);
0207     legend->Draw();
0208     textX = new TPaveText();
0209     textY = new TPaveText();
0210     setPaveTextStyle(textX);
0211     setPaveTextStyle(textY, false);
0212     textX->Draw();
0213     textY->Draw();
0214     gSystem->ProcessEvents();
0215     c1->Update();
0216     outputFile->cd();
0217     c1->Write();
0218     c1->SaveAs((*itPlot+"Tracker.png").c_str());
0219     
0220     delete histoStack;
0221     delete textX;
0222     delete textY;
0223     delete legend;
0224     delete c1;
0225 
0226    
0227     
0228     // Put together the histograms for the different layers of the detectors
0229     for(std::vector< std::string >::iterator itSub=subDetName.begin(); itSub!=subDetName.end(); itSub++)
0230     {
0231       unsigned int nLayers = 0;
0232       std::string layerName;
0233 //       std::cout << "itSub = " << (*itSub).c_str() << std::endl;
0234       if((*itSub)=="TIB")
0235       {
0236         nLayers=4;
0237         layerName="Layer";
0238         legend = new TLegend(0.4,0.9,0.9,1);
0239         setLegendStyle(legend,2);
0240       }
0241       else if((*itSub)=="TID+" || (*itSub)=="TID-")
0242       {
0243         nLayers=3;
0244         layerName="Disk";
0245         legend = new TLegend(0.35,0.9,0.9,1);
0246         setLegendStyle(legend,3);
0247       }
0248       else if((*itSub)=="TOB")
0249       {
0250         nLayers=6;
0251         layerName="Layer";
0252         legend = new TLegend(0.35,0.9,0.9,1);
0253         setLegendStyle(legend,3);
0254       }
0255       else if((*itSub)=="TEC+" || (*itSub)=="TEC-")
0256       {
0257         nLayers=9;
0258         layerName="Disk";
0259         legend = new TLegend(0.35,0.9,1,1);
0260         setLegendStyle(legend,5);
0261       }
0262       
0263       c1 = new TCanvas(("c" + *itPlot + *itSub).c_str(),"", 1200, 600);
0264       setCanvasStyle(c1, false);
0265 //       if((*itSub).compare("TEC+")==0 || (*itSub).compare("TEC-")==0)
0266 //       {
0267 //         histoName = "h" + *itPlot + "TEC";
0268 //       }
0269 //       else
0270 //       {
0271       histoName = "h" + *itPlot + *itSub;
0272 //       }
0273 //       hSubDet = (TH1F*)inputFile->Get(histoName.c_str());
0274 //       setHistoStackStyle(hSubDet,1);
0275       //       hSubDet->Draw();
0276       histoStack = new THStack(histoName.c_str(), histoName.c_str());
0277       
0278       for(unsigned int iLayer = 1; iLayer<=nLayers; iLayer++)
0279       {
0280         oss.str("");
0281         oss << iLayer;
0282 //         // TIB and TOB have no plus/minus side division
0283 //         // While TEC has it but I plot them separately
0284 //         // TID has plus/minus side division but I plot everything in a single plot
0285 //         if((*itSub).compare("TID")==0)
0286 //         {
0287 //           histoName = "h" + *itPlot + *itSub + "+" + layerName + oss.str();
0288 // //           std::cout << "histoName = " << histoName.c_str() << std::endl;
0289 //           histo = (TH1F*)inputFile->Get(histoName.c_str());
0290 //           
0291 //           // First: plot histogram separately
0292 //           setHistoStyle(histo);
0293 //           c2 = new TCanvas(("c" + *itPlot + *itSub + "+" + layerName + oss.str()).c_str(), "", 1200, 600);
0294 //           setCanvasStyle(c2, true);
0295 //           histo->Draw(plotHistoOptions.c_str());
0296 //           legend2 = new TLegend(0.6,0.92,0.9,0.97);
0297 //           legend2->AddEntry(histo,(*itSub + "+" + layerName + oss.str()).c_str());
0298 //           setLegendStyle(legend2, 1);
0299 //           legend2->Draw();
0300 //           gSystem->ProcessEvents();
0301 //           c2->Update();
0302 //           outputFile->cd();
0303 //           c2->Write();
0304 //           c2->SaveAs((*itPlot + *itSub + "+" + layerName + oss.str() + ".png").c_str());
0305 //           delete legend2;
0306 //           delete c2;
0307 //           
0308 //           // Second: add histogram to THStack
0309 //           hLayers.push_back(histo);
0310 //           setHistoStackStyle(hLayers.back(), iLayer);
0311 //           histoStack->Add(hLayers.back());
0312 //           entryLabel = *itSub + "+ " + layerName + " " + oss.str();
0313 //           legend->AddEntry(hLayers.back(), entryLabel.c_str());
0314 //           
0315 //           
0316 //           histoName = "h" + *itPlot + *itSub + "-" + layerName + oss.str();
0317 // //           std::cout << "histoName = " << histoName.c_str() << std::endl;
0318 //           histo = (TH1F*)inputFile->Get(histoName.c_str());
0319 //           
0320 //           // First: plot histogram separately
0321 //           setHistoStyle(histo);
0322 //           c2 = new TCanvas(("c" + *itPlot + *itSub + "-" + layerName + oss.str()).c_str(), "", 1200, 600);
0323 //           setCanvasStyle(c2, true);
0324 //           histo->Draw(plotHistoOptions.c_str());
0325 //           legend2 = new TLegend(0.6,0.92,0.9,0.97);
0326 //           legend2->AddEntry(histo,(*itSub + "-" + layerName + oss.str()).c_str());
0327 //           setLegendStyle(legend2, 1);
0328 //           legend2->Draw();
0329 //           gSystem->ProcessEvents();
0330 //           c2->Update();
0331 //           outputFile->cd();
0332 //           c2->Write();
0333 //           c2->SaveAs((*itPlot + *itSub + "-" + layerName + oss.str() + ".png").c_str());
0334 //           delete legend2;
0335 //           delete c2;
0336 //           
0337 //           // Second: add histogram to THStack
0338 //           hLayers.push_back(histo);
0339 //           setHistoStackStyle(hLayers.back(), iLayer+nLayers);
0340 //           histoStack->Add(hLayers.back());
0341 //           entryLabel = *itSub + "- " + layerName + " " + oss.str();
0342 //           legend->AddEntry(hLayers.back(), entryLabel.c_str());
0343 // //           hLayers.back()->Draw("same");
0344 //         }
0345 //         else
0346 //         {
0347           histoName = "h" + *itPlot + *itSub + layerName + oss.str();
0348 //           std::cout << "histoName = " << histoName.c_str() << std::endl;
0349           histo = (TH1F*)inputFile->Get(histoName.c_str());
0350       if(histo) {
0351         histo2 = new TH1F(*histo);
0352         histo->Scale(1/findNormFactor(*itPlot, *itSub + " " + layerName + " " + oss.str(), false));
0353         histo2->Scale(1/findNormFactor(*itPlot, *itSub + " " + layerName + " " + oss.str(), stackHistograms));
0354         // First: plot histogram separately
0355         setHistoStyle(histo);
0356         c2 = new TCanvas(("c" + *itPlot + *itSub +  layerName + oss.str()).c_str(), "", 1200, 600);
0357         setCanvasStyle(c2, true);
0358         histo->Draw(plotHistoOptions.c_str());
0359         double histoMaximum = histo->GetMaximum();
0360         // Otherwise it does not draw the pad
0361         if(histoMaximum==0)
0362           {
0363         c2->SetLogy(0);
0364           }
0365         legend2 = new TLegend(0.6,0.92,0.9,0.97);
0366         legend2->AddEntry(histo,(*itSub + layerName + oss.str()).c_str());
0367         setLegendStyle(legend2, 1);
0368         legend2->Draw();
0369         textX = new TPaveText();
0370         textY = new TPaveText();
0371         setPaveTextStyle(textX);
0372         setPaveTextStyle(textY,false);
0373         textX->Draw();
0374         textY->Draw();
0375         gSystem->ProcessEvents();
0376         c2->Update();
0377         outputFile->cd();
0378         c2->Write();
0379         c2->SaveAs((*itPlot + *itSub + layerName + oss.str() + ".png").c_str());
0380         delete textX;
0381         delete textY;
0382         delete legend2;
0383         delete c2;
0384         
0385         // Second: add histogram to THStack
0386         setHistoStyle(histo2);
0387         hLayers.push_back(histo2);
0388         setHistoStackStyle(hLayers.back(), iLayer);
0389         histoStack->Add(hLayers.back());
0390         entryLabel = *itSub + " " + layerName + " " + oss.str();
0391         legend->AddEntry(hLayers.back(), entryLabel.c_str());
0392         //           hLayers.back()->Draw("same");
0393         //         }
0394         //           delete histo2;
0395       }
0396       else {std::cout << histoName << " not found" << std::endl;}
0397       }
0398       histoStack->Draw(plotStackOptions.c_str());
0399 
0400       // Bug in ROOT? If we plot a stack with the "stack" option and the Y axis is in log scale,
0401       // but there are no entries in any of the histograms of the stack, then ROOT crashes
0402       // Workaround: at this stage, check that at least one histogram has >0 entries,
0403       // otherwise, switch back to linear Y scale
0404       // Curiously, there is no crash if the "nostack" option is chosen...
0405       double histoStackMaximum = histoStack->GetMaximum();
0406       if(histoStackMaximum==0)
0407       {
0408         c1->SetLogy(0);
0409       }
0410       if(histoStackMaximum > 0.01)
0411         histoStack->SetMaximum(0.01);
0412       textX = new TPaveText();
0413       textY = new TPaveText();
0414       setPaveTextStyle(textX);
0415       setPaveTextStyle(textY,false);
0416       textX->Draw();
0417       textY->Draw();
0418       legend->Draw();
0419       gSystem->ProcessEvents();
0420       c1->Update();
0421       outputFile->cd();
0422       c1->Write();
0423       c1->SaveAs((*itPlot + *itSub + ".png").c_str());
0424       delete histoStack;
0425       delete textX;
0426       delete textY;
0427       delete legend;
0428       delete c1;
0429     }
0430   }
0431   
0432   inputFile->Close();
0433   outputFile->Close();
0434   
0435 }
0436 
0437 
0438 
0439 void setCanvasStyle(TCanvas* c, const bool logScale)
0440 {
0441   c->SetFillColor(0);
0442   c->SetFrameBorderMode(0);
0443   if(logScale)
0444     c->SetLogy(1);
0445   else
0446     c->SetLogy(0);
0447   c->SetCanvasSize(1200,600);
0448   c->SetWindowSize(1200,600);
0449 }
0450 
0451 
0452 
0453 void setHistoStyle(TH1* h)
0454 {
0455   h->SetLineStyle(0);
0456   h->SetMarkerStyle(3);
0457   h->SetMarkerSize(1);
0458   h->SetMarkerColor(1);
0459   h->SetStats(kFALSE);
0460 //   h->GetYaxis()->SetTitle("Fraction of total");
0461 //   h->GetXaxis()->SetTitle("IOV");
0462 //   h->GetXaxis()->SetTitleOffset(-0.3);
0463   // Avoid having too many bins with labels
0464   if(h->GetNbinsX() > 25)
0465     for(int i = 1; i < h->GetNbinsX()-1; i++)
0466       if((i%(h->GetNbinsX()/25+1)))
0467         h->GetXaxis()->SetBinLabel(i+1,"");
0468 }
0469 
0470 
0471 
0472 void setHistoStackStyle(TH1* h, const unsigned int lineColor)
0473 {
0474   h->SetLineStyle(0);
0475   //   h->SetDrawOption("e1p");
0476   // Best marker types are 20-23 - use them with different colors
0477   h->SetMarkerStyle(lineColor%4+20);
0478   h->SetMarkerSize(1);
0479   h->SetMarkerColor(lineColor);
0480   h->SetLineColor(lineColor);
0481   h->SetFillColor(lineColor);
0482   h->SetLineWidth(2);
0483   h->SetStats(kFALSE);
0484   h->GetYaxis()->SetTitle("Fraction of total");
0485 //   h->GetXaxis()->SetTitle("IOV");
0486 //   h->GetXaxis()->SetTitleOffset(1.2);
0487   // Avoid having too many bins with labels
0488   if(h->GetNbinsX() > 25)
0489     for(int i = 1; i < h->GetNbinsX()-1; i++)
0490       if(i%(h->GetNbinsX()/25+1))
0491         h->GetXaxis()->SetBinLabel(i+1,"");
0492 }
0493 
0494 
0495 
0496 void setLegendStyle(TLegend* l, const unsigned int nColumns)
0497 {
0498   l->SetNColumns(nColumns);
0499   l->SetFillColor(0);
0500 }
0501 
0502 
0503 
0504 void setPaveTextStyle(TPaveText* t, const bool isHorizontal)
0505 {
0506   t->SetLineStyle(0);
0507   t->SetFillColor(0);
0508   t->SetFillStyle(0);
0509   t->SetBorderSize(0);
0510   if(isHorizontal)
0511   {
0512     t->SetX1NDC(0.905);
0513     t->SetX2NDC(0.975);
0514     t->SetY1NDC(0.062);
0515     t->SetY2NDC(0.095);
0516     t->AddText("IOV");
0517   }
0518   else
0519   {
0520     t->SetX1NDC(0.03);
0521     t->SetX2NDC(0.05);
0522     t->SetY1NDC(0.33);
0523     t->SetY2NDC(0.68);
0524     TText* t1 = t->AddText("Fraction of total");
0525     t1->SetTextAngle(90.);
0526   }
0527 }
0528 
0529 
0530 
0531 void fillNormFactorMaps()
0532 {
0533   // Number of modules, fibers, APVs, strips for each tracker part
0534   std::vector< std::string > tkParts;
0535   tkParts.push_back("Tracker");
0536   tkParts.push_back("TIB");
0537   tkParts.push_back("TID");
0538   tkParts.push_back("TOB");
0539   tkParts.push_back("TEC");
0540   tkParts.push_back("TIB Layer 1");
0541   tkParts.push_back("TIB Layer 2");
0542   tkParts.push_back("TIB Layer 3");
0543   tkParts.push_back("TIB Layer 4");
0544   tkParts.push_back("TID+ Disk 1");
0545   tkParts.push_back("TID+ Disk 2");
0546   tkParts.push_back("TID+ Disk 3");
0547   tkParts.push_back("TID- Disk 1");
0548   tkParts.push_back("TID- Disk 2");
0549   tkParts.push_back("TID- Disk 3");
0550   tkParts.push_back("TOB Layer 1");
0551   tkParts.push_back("TOB Layer 2");
0552   tkParts.push_back("TOB Layer 3");
0553   tkParts.push_back("TOB Layer 4");
0554   tkParts.push_back("TOB Layer 5");
0555   tkParts.push_back("TOB Layer 6");
0556   tkParts.push_back("TEC+ Disk 1");
0557   tkParts.push_back("TEC+ Disk 2");
0558   tkParts.push_back("TEC+ Disk 3");
0559   tkParts.push_back("TEC+ Disk 4");
0560   tkParts.push_back("TEC+ Disk 5");
0561   tkParts.push_back("TEC+ Disk 6");
0562   tkParts.push_back("TEC+ Disk 7");
0563   tkParts.push_back("TEC+ Disk 8");
0564   tkParts.push_back("TEC+ Disk 9");
0565   tkParts.push_back("TEC- Disk 1");
0566   tkParts.push_back("TEC- Disk 2");
0567   tkParts.push_back("TEC- Disk 3");
0568   tkParts.push_back("TEC- Disk 4");
0569   tkParts.push_back("TEC- Disk 5");
0570   tkParts.push_back("TEC- Disk 6");
0571   tkParts.push_back("TEC- Disk 7");
0572   tkParts.push_back("TEC- Disk 8");
0573   tkParts.push_back("TEC- Disk 9");
0574   
0575   std::vector<unsigned int> nModulesStack;
0576   nModulesStack.push_back(15148);
0577   nModulesStack.push_back(15148);
0578   nModulesStack.push_back(15148);
0579   nModulesStack.push_back(15148);
0580   nModulesStack.push_back(15148);
0581   nModulesStack.push_back(2724);
0582   nModulesStack.push_back(2724);
0583   nModulesStack.push_back(2724);
0584   nModulesStack.push_back(2724);
0585   nModulesStack.push_back(408);
0586   nModulesStack.push_back(408);
0587   nModulesStack.push_back(408);
0588   nModulesStack.push_back(408);
0589   nModulesStack.push_back(408);
0590   nModulesStack.push_back(408);
0591   nModulesStack.push_back(5208);
0592   nModulesStack.push_back(5208);
0593   nModulesStack.push_back(5208);
0594   nModulesStack.push_back(5208);
0595   nModulesStack.push_back(5208);
0596   nModulesStack.push_back(5208);
0597   nModulesStack.push_back(3200);
0598   nModulesStack.push_back(3200);
0599   nModulesStack.push_back(3200);
0600   nModulesStack.push_back(3200);
0601   nModulesStack.push_back(3200);
0602   nModulesStack.push_back(3200);
0603   nModulesStack.push_back(3200);
0604   nModulesStack.push_back(3200);
0605   nModulesStack.push_back(3200);
0606   nModulesStack.push_back(3200);
0607   nModulesStack.push_back(3200);
0608   nModulesStack.push_back(3200);
0609   nModulesStack.push_back(3200);
0610   nModulesStack.push_back(3200);
0611   nModulesStack.push_back(3200);
0612   nModulesStack.push_back(3200);
0613   nModulesStack.push_back(3200);
0614   nModulesStack.push_back(3200);
0615   
0616   std::vector<unsigned int> nModulesNoStack;
0617   nModulesNoStack.push_back(15148);
0618   nModulesNoStack.push_back(2724);
0619   nModulesNoStack.push_back(816);
0620   nModulesNoStack.push_back(5208);
0621   nModulesNoStack.push_back(6400);
0622   nModulesNoStack.push_back(672);
0623   nModulesNoStack.push_back(864);
0624   nModulesNoStack.push_back(540);
0625   nModulesNoStack.push_back(648);
0626   nModulesNoStack.push_back(136);
0627   nModulesNoStack.push_back(136);
0628   nModulesNoStack.push_back(136);
0629   nModulesNoStack.push_back(136);
0630   nModulesNoStack.push_back(136);
0631   nModulesNoStack.push_back(136);
0632   nModulesNoStack.push_back(1008);
0633   nModulesNoStack.push_back(1152);
0634   nModulesNoStack.push_back(648);
0635   nModulesNoStack.push_back(720);
0636   nModulesNoStack.push_back(792);
0637   nModulesNoStack.push_back(888);
0638   nModulesNoStack.push_back(408);
0639   nModulesNoStack.push_back(408);
0640   nModulesNoStack.push_back(408);
0641   nModulesNoStack.push_back(360);
0642   nModulesNoStack.push_back(360);
0643   nModulesNoStack.push_back(360);
0644   nModulesNoStack.push_back(312);
0645   nModulesNoStack.push_back(312);
0646   nModulesNoStack.push_back(272);
0647   nModulesNoStack.push_back(408);
0648   nModulesNoStack.push_back(408);
0649   nModulesNoStack.push_back(408);
0650   nModulesNoStack.push_back(360);
0651   nModulesNoStack.push_back(360);
0652   nModulesNoStack.push_back(360);
0653   nModulesNoStack.push_back(312);
0654   nModulesNoStack.push_back(312);
0655   nModulesNoStack.push_back(272);
0656 
0657   //
0658   std::vector<unsigned int> nFibersStack;
0659   nFibersStack.push_back(36392);
0660   nFibersStack.push_back(36392);
0661   nFibersStack.push_back(36392);
0662   nFibersStack.push_back(36392);
0663   nFibersStack.push_back(36392);
0664   nFibersStack.push_back(6984);
0665   nFibersStack.push_back(6984);
0666   nFibersStack.push_back(6984);
0667   nFibersStack.push_back(6984);
0668   nFibersStack.push_back(1104);
0669   nFibersStack.push_back(1104);
0670   nFibersStack.push_back(1104);
0671   nFibersStack.push_back(1104);
0672   nFibersStack.push_back(1104);
0673   nFibersStack.push_back(1104);
0674   nFibersStack.push_back(12096);
0675   nFibersStack.push_back(12096);
0676   nFibersStack.push_back(12096);
0677   nFibersStack.push_back(12096);
0678   nFibersStack.push_back(12096);
0679   nFibersStack.push_back(12096);
0680   nFibersStack.push_back(7552);
0681   nFibersStack.push_back(7552);
0682   nFibersStack.push_back(7552);
0683   nFibersStack.push_back(7552);
0684   nFibersStack.push_back(7552);
0685   nFibersStack.push_back(7552);
0686   nFibersStack.push_back(7552);
0687   nFibersStack.push_back(7552);
0688   nFibersStack.push_back(7552);
0689   nFibersStack.push_back(7552);
0690   nFibersStack.push_back(7552);
0691   nFibersStack.push_back(7552);
0692   nFibersStack.push_back(7552);
0693   nFibersStack.push_back(7552);
0694   nFibersStack.push_back(7552);
0695   nFibersStack.push_back(7552);
0696   nFibersStack.push_back(7552);
0697   nFibersStack.push_back(7552);
0698   
0699   std::vector<unsigned int> nFibersNoStack;
0700   nFibersNoStack.push_back(36392);
0701   nFibersNoStack.push_back(6984);
0702   nFibersNoStack.push_back(2208);
0703   nFibersNoStack.push_back(12096);
0704   nFibersNoStack.push_back(15104);
0705   nFibersNoStack.push_back(2016);
0706   nFibersNoStack.push_back(2592);
0707   nFibersNoStack.push_back(1080);
0708   nFibersNoStack.push_back(1296);
0709   nFibersNoStack.push_back(368);
0710   nFibersNoStack.push_back(368);
0711   nFibersNoStack.push_back(368);
0712   nFibersNoStack.push_back(368);
0713   nFibersNoStack.push_back(368);
0714   nFibersNoStack.push_back(368);
0715   nFibersNoStack.push_back(2016);
0716   nFibersNoStack.push_back(2304);
0717   nFibersNoStack.push_back(1296);
0718   nFibersNoStack.push_back(1440);
0719   nFibersNoStack.push_back(2376);
0720   nFibersNoStack.push_back(2664);
0721   nFibersNoStack.push_back(992);
0722   nFibersNoStack.push_back(992);
0723   nFibersNoStack.push_back(992);
0724   nFibersNoStack.push_back(848);
0725   nFibersNoStack.push_back(848);
0726   nFibersNoStack.push_back(848);
0727   nFibersNoStack.push_back(704);
0728   nFibersNoStack.push_back(704);
0729   nFibersNoStack.push_back(624);
0730   nFibersNoStack.push_back(992);
0731   nFibersNoStack.push_back(992);
0732   nFibersNoStack.push_back(992);
0733   nFibersNoStack.push_back(848);
0734   nFibersNoStack.push_back(848);
0735   nFibersNoStack.push_back(848);
0736   nFibersNoStack.push_back(704);
0737   nFibersNoStack.push_back(704);
0738   nFibersNoStack.push_back(624);
0739   
0740   //
0741   std::vector<unsigned int> nAPVsStack;
0742   nAPVsStack.push_back(72784);
0743   nAPVsStack.push_back(72784);
0744   nAPVsStack.push_back(72784);
0745   nAPVsStack.push_back(72784);
0746   nAPVsStack.push_back(72784);
0747   nAPVsStack.push_back(13968);
0748   nAPVsStack.push_back(13968);
0749   nAPVsStack.push_back(13968);
0750   nAPVsStack.push_back(13968);
0751   nAPVsStack.push_back(2208);
0752   nAPVsStack.push_back(2208);
0753   nAPVsStack.push_back(2208);
0754   nAPVsStack.push_back(2208);
0755   nAPVsStack.push_back(2208);
0756   nAPVsStack.push_back(2208);
0757   nAPVsStack.push_back(24192);
0758   nAPVsStack.push_back(24192);
0759   nAPVsStack.push_back(24192);
0760   nAPVsStack.push_back(24192);
0761   nAPVsStack.push_back(24192);
0762   nAPVsStack.push_back(24192);
0763   nAPVsStack.push_back(15104);
0764   nAPVsStack.push_back(15104);
0765   nAPVsStack.push_back(15104);
0766   nAPVsStack.push_back(15104);
0767   nAPVsStack.push_back(15104);
0768   nAPVsStack.push_back(15104);
0769   nAPVsStack.push_back(15104);
0770   nAPVsStack.push_back(15104);
0771   nAPVsStack.push_back(15104);
0772   nAPVsStack.push_back(15104);
0773   nAPVsStack.push_back(15104);
0774   nAPVsStack.push_back(15104);
0775   nAPVsStack.push_back(15104);
0776   nAPVsStack.push_back(15104);
0777   nAPVsStack.push_back(15104);
0778   nAPVsStack.push_back(15104);
0779   nAPVsStack.push_back(15104);
0780   nAPVsStack.push_back(15104);
0781   
0782   std::vector<unsigned int> nAPVsNoStack;
0783   nAPVsNoStack.push_back(72784);
0784   nAPVsNoStack.push_back(13968);
0785   nAPVsNoStack.push_back(4416);
0786   nAPVsNoStack.push_back(24192);
0787   nAPVsNoStack.push_back(30208);
0788   nAPVsNoStack.push_back(4032);
0789   nAPVsNoStack.push_back(5184);
0790   nAPVsNoStack.push_back(2160);
0791   nAPVsNoStack.push_back(2592);
0792   nAPVsNoStack.push_back(736);
0793   nAPVsNoStack.push_back(736);
0794   nAPVsNoStack.push_back(736);
0795   nAPVsNoStack.push_back(736);
0796   nAPVsNoStack.push_back(736);
0797   nAPVsNoStack.push_back(736);
0798   nAPVsNoStack.push_back(4032);
0799   nAPVsNoStack.push_back(4608);
0800   nAPVsNoStack.push_back(2592);
0801   nAPVsNoStack.push_back(2880);
0802   nAPVsNoStack.push_back(4752);
0803   nAPVsNoStack.push_back(5328);
0804   nAPVsNoStack.push_back(1984);
0805   nAPVsNoStack.push_back(1984);
0806   nAPVsNoStack.push_back(1984);
0807   nAPVsNoStack.push_back(1696);
0808   nAPVsNoStack.push_back(1696);
0809   nAPVsNoStack.push_back(1696);
0810   nAPVsNoStack.push_back(1408);
0811   nAPVsNoStack.push_back(1408);
0812   nAPVsNoStack.push_back(1248);
0813   nAPVsNoStack.push_back(1984);
0814   nAPVsNoStack.push_back(1984);
0815   nAPVsNoStack.push_back(1984);
0816   nAPVsNoStack.push_back(1696);
0817   nAPVsNoStack.push_back(1696);
0818   nAPVsNoStack.push_back(1696);
0819   nAPVsNoStack.push_back(1408);
0820   nAPVsNoStack.push_back(1408);
0821   nAPVsNoStack.push_back(1248);
0822   
0823   //
0824   std::vector<unsigned int> nStripsStack;
0825   nStripsStack.push_back(9316352);
0826   nStripsStack.push_back(9316352);
0827   nStripsStack.push_back(9316352);
0828   nStripsStack.push_back(9316352);
0829   nStripsStack.push_back(9316352);
0830   nStripsStack.push_back(1787904);
0831   nStripsStack.push_back(1787904);
0832   nStripsStack.push_back(1787904);
0833   nStripsStack.push_back(1787904);
0834   nStripsStack.push_back(282624);
0835   nStripsStack.push_back(282624);
0836   nStripsStack.push_back(282624);
0837   nStripsStack.push_back(282624);
0838   nStripsStack.push_back(282624);
0839   nStripsStack.push_back(282624);
0840   nStripsStack.push_back(3096576);
0841   nStripsStack.push_back(3096576);
0842   nStripsStack.push_back(3096576);
0843   nStripsStack.push_back(3096576);
0844   nStripsStack.push_back(3096576);
0845   nStripsStack.push_back(3096576);
0846   nStripsStack.push_back(1933312);
0847   nStripsStack.push_back(1933312);
0848   nStripsStack.push_back(1933312);
0849   nStripsStack.push_back(1933312);
0850   nStripsStack.push_back(1933312);
0851   nStripsStack.push_back(1933312);
0852   nStripsStack.push_back(1933312);
0853   nStripsStack.push_back(1933312);
0854   nStripsStack.push_back(1933312);
0855   nStripsStack.push_back(1933312);
0856   nStripsStack.push_back(1933312);
0857   nStripsStack.push_back(1933312);
0858   nStripsStack.push_back(1933312);
0859   nStripsStack.push_back(1933312);
0860   nStripsStack.push_back(1933312);
0861   nStripsStack.push_back(1933312);
0862   nStripsStack.push_back(1933312);
0863   nStripsStack.push_back(1933312);
0864   
0865   std::vector<unsigned int> nStripsNoStack;
0866   nStripsNoStack.push_back(9316352);
0867   nStripsNoStack.push_back(1787904);
0868   nStripsNoStack.push_back(565248);
0869   nStripsNoStack.push_back(3096576);
0870   nStripsNoStack.push_back(3866624);
0871   nStripsNoStack.push_back(516096);
0872   nStripsNoStack.push_back(663552);
0873   nStripsNoStack.push_back(276480);
0874   nStripsNoStack.push_back(331776);
0875   nStripsNoStack.push_back(94208);
0876   nStripsNoStack.push_back(94208);
0877   nStripsNoStack.push_back(94208);
0878   nStripsNoStack.push_back(94208);
0879   nStripsNoStack.push_back(94208);
0880   nStripsNoStack.push_back(94208);
0881   nStripsNoStack.push_back(516096);
0882   nStripsNoStack.push_back(589824);
0883   nStripsNoStack.push_back(331776);
0884   nStripsNoStack.push_back(368640);
0885   nStripsNoStack.push_back(608256);
0886   nStripsNoStack.push_back(681984);
0887   nStripsNoStack.push_back(253952);
0888   nStripsNoStack.push_back(253952);
0889   nStripsNoStack.push_back(253952);
0890   nStripsNoStack.push_back(217088);
0891   nStripsNoStack.push_back(217088);
0892   nStripsNoStack.push_back(217088);
0893   nStripsNoStack.push_back(180224);
0894   nStripsNoStack.push_back(180224);
0895   nStripsNoStack.push_back(159744);
0896   nStripsNoStack.push_back(253952);
0897   nStripsNoStack.push_back(253952);
0898   nStripsNoStack.push_back(253952);
0899   nStripsNoStack.push_back(217088);
0900   nStripsNoStack.push_back(217088);
0901   nStripsNoStack.push_back(217088);
0902   nStripsNoStack.push_back(180224);
0903   nStripsNoStack.push_back(180224);
0904   nStripsNoStack.push_back(159744);
0905   
0906   for(unsigned int i = 0; i < tkParts.size(); i++)
0907   {
0908     modulesStackNormFactors[tkParts[i]] = nModulesStack[i];
0909     modulesNoStackNormFactors[tkParts[i]] = nModulesNoStack[i];
0910     fibersStackNormFactors[tkParts[i]] = nFibersStack[i];
0911     fibersNoStackNormFactors[tkParts[i]] = nFibersNoStack[i];
0912     APVsStackNormFactors[tkParts[i]] = nAPVsStack[i];
0913     APVsNoStackNormFactors[tkParts[i]] = nAPVsNoStack[i];
0914     stripsStackNormFactors[tkParts[i]] = nStripsStack[i];
0915     stripsNoStackNormFactors[tkParts[i]] = nStripsNoStack[i];
0916   }
0917   
0918   //   for(std::map< std::string, unsigned int>::iterator it = allStripsTK.begin(); it != allStripsTK.end(); it++)
0919   //   {
0920     //     std::cout << it->first.c_str() << " " << it->second << std::endl;
0921     //   }
0922     
0923   
0924 }
0925 
0926 
0927 
0928 double findNormFactor(const std::string currentPlotType, const std::string currentPart, const bool stackOption)
0929 {
0930 
0931 //   std::cout << "findNormFactor(): Finding normalization factor for this part: \"" << currentPart.c_str() << "\".\n";
0932 //   std::cout << "                  Plot type is: \"" << currentPlotType.c_str() << "\".\n";
0933 //   std::cout << "                  stack option is: " << stackOption << std::endl;
0934   if(stackOption)
0935   {
0936     if(currentPlotType == "BadModules")
0937     {
0938       return modulesStackNormFactors[currentPart];
0939     }
0940     else if(currentPlotType == "BadFibers")
0941     {
0942       return fibersStackNormFactors[currentPart];
0943     }
0944     else if(currentPlotType == "BadAPVs")
0945     {
0946       return APVsStackNormFactors[currentPart];
0947     }
0948     else if(currentPlotType == "AllBadStrips" || 
0949             currentPlotType == "BadStripsFromAPVs" || 
0950             currentPlotType == "BadStrips")
0951     {
0952       return stripsStackNormFactors[currentPart];
0953     }
0954     else
0955     {
0956       std::cout << "findNormFactor(): ERROR! Requested a non supported plot type: " << currentPlotType.c_str() << std::endl;
0957       std::cout << "                  Add this to the function body or correct the error\n";
0958       return 0; // This should trigger a divByZero error...
0959     }
0960   }
0961   else
0962   {
0963     if(currentPlotType == "BadModules")
0964     {
0965       return modulesNoStackNormFactors[currentPart];
0966     }
0967     else if(currentPlotType == "BadFibers")
0968     {
0969       return fibersNoStackNormFactors[currentPart];
0970     }
0971     else if(currentPlotType == "BadAPVs")
0972     {
0973       return APVsNoStackNormFactors[currentPart];
0974     }
0975     else if(currentPlotType == "BadStrips" || 
0976             currentPlotType == "BadStripsFromAPVs" || 
0977             currentPlotType == "AllBadStrips")
0978     {
0979       return stripsNoStackNormFactors[currentPart];
0980     }
0981     else
0982     {
0983       std::cout << "findNormFactor(): ERROR! Requested a non supported plot type: \"" << currentPlotType.c_str() << "\"\n";
0984       std::cout << "                  Add this to the function body or correct the error otherwise.\n";
0985       return 0; // This should trigger a divByZero error...
0986     }
0987   }
0988 }