Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <iostream>
0002 #include <fstream>
0003 #include <sstream>
0004 #include <string>
0005 
0006 #include <TROOT.h>
0007 #include <TStyle.h>
0008 #include "TFile.h"
0009 #include "THStack.h"
0010 #include "TH1D.h"
0011 #include "TDirectoryFile.h"
0012 #include "TCanvas.h"
0013 #include "TLine.h"
0014 #include "TLegend.h"
0015 #include "TRint.h"
0016 
0017 int main(int argc, char *argv[]) {
0018 
0019   gROOT->SetStyle("Plain");
0020 
0021   char* filelist;
0022   char* modulelist;
0023 
0024   filelist= argv[1];
0025   modulelist= argv[2];
0026 
0027   int stripmin = 999;
0028   int stripmax = 999;
0029 
0030   if (argv[3] && argv[4]){
0031     stripmin=atoi(argv[3]);
0032     stripmax=atoi(argv[4]);
0033   }
0034 
0035   std::string detid;
0036   std::string hn;
0037 
0038   TLegend leg(0.1,0.7,0.2,0.9);
0039   leg.SetFillStyle(0);
0040 
0041   std::ifstream inmodules(modulelist);
0042 
0043   while(true){
0044     
0045     inmodules >> detid;
0046     if (!inmodules.good()) break;
0047 
0048     hn="ClusterDigiPosition__det__" + detid;//std::to_string(detid);
0049     
0050     TCanvas c1("c1","c1",1600,900);
0051   
0052     c1.SetBatch(kTRUE);
0053     c1.SetLogy(1);
0054     c1.SetGridy(1);
0055 
0056     //cout << detid << endl;
0057     std::ifstream fileToCountLines(filelist);
0058     std::size_t lines_count =0;
0059     std::string line;
0060 
0061     while (std::getline(fileToCountLines , line))
0062         ++lines_count;
0063 
0064     const float dim=lines_count;
0065 
0066     std::ifstream filesin(filelist);
0067 
0068     std::string filename;
0069     int k=0;
0070 
0071     TH1D* trend=new TH1D("trend","trend",int(dim),0.5,dim+0.5);
0072     trend->SetMarkerSize(3);
0073     trend->SetMarkerStyle(8);
0074     trend->SetMarkerColor(4);
0075 
0076     std::string ttitle=hn+"_trend";
0077     trend->SetTitle(ttitle.c_str());
0078 
0079     double max=-1;
0080     double min=1000000;
0081 
0082     leg.Clear();
0083     TFile* fin;
0084 
0085     THStack *hs = new THStack("hs","");
0086 
0087 
0088     while(true){
0089 
0090       filesin >> filename;
0091       if (!filesin.good()) break;      
0092 
0093       std::string runNum= filename.substr(filename.find("run_")+4, 6);
0094       //std::cout << runNum << std::endl;
0095      
0096       fin=TFile::Open(filename.c_str());
0097  
0098       if (!fin) {std::cout << "Cannot open file " << filename.c_str() << std::endl;
0099     return 0;
0100       }
0101       
0102       TH1D* Events=(TH1D*)fin->Get("TotEvents");
0103 
0104       double EvtNum=Events->GetBinContent(1);
0105 
0106       TH1D* histo=(TH1D*) fin->Get(hn.c_str());
0107       
0108       if (!histo) {std::cout << "Cannot open histo " << hn.c_str() << std::endl;
0109     return 0;
0110       }
0111 
0112       histo->SetDirectory(nullptr);
0113       histo->SetStats(kFALSE);
0114 
0115       if (hn.find("Summary")==std::string::npos) histo->Scale(1/EvtNum);
0116 
0117       double numberPerEvent;
0118       if (stripmin==999 && stripmax==999) numberPerEvent=histo->Integral();
0119       else numberPerEvent=histo->Integral(stripmin,stripmax);
0120 
0121       
0122       if (max<=histo->GetBinContent(histo->GetMaximumBin())) max=histo->GetBinContent(histo->GetMaximumBin());
0123       if (min>histo->GetBinContent(histo->GetMinimumBin())) min=histo->GetBinContent(histo->GetMinimumBin());
0124 
0125       histo->SetLineColor(k+1);
0126       histo->SetMarkerStyle(9);
0127       histo->SetMarkerColor(k+1);
0128            
0129       trend->SetBinContent(k+1,numberPerEvent);
0130       trend->GetXaxis()->SetBinLabel(k+1,runNum.c_str());
0131 
0132       leg.AddEntry(histo, runNum.c_str(), "L");
0133       hs->Add(histo);
0134       k++;
0135 
0136       fin->Close();
0137     }
0138 
0139     if (min==0) min=1.e-6;
0140 
0141     max=max*10;// in a way one can read the legend
0142 
0143     hs->SetMaximum(max);
0144     hs->SetMinimum(min);
0145     hs->SetTitle(hn.c_str());
0146 
0147     hs->Draw("nostack");
0148 
0149     TLine l;
0150     
0151     l.SetLineColor(4);
0152     l.SetLineStyle(2);
0153     l.SetLineWidth(3);
0154 
0155     l.DrawLine(128,min,128,max);
0156     l.DrawLine(256,min,256,max);
0157     l.DrawLine(384,min,384,max);
0158     l.DrawLine(384,min,384,max);
0159     l.DrawLine(512,min,512,max);
0160     l.DrawLine(640,min,640,max);
0161 
0162     leg.Draw();
0163     std::string outname= hn+"_Super.png";
0164     c1.SaveAs(outname.c_str());
0165     
0166     c1.SetGridx(1);
0167     
0168     double mintrend=0;
0169     if (trend->GetMinimum()==0) mintrend=1.e-4;
0170     else mintrend=trend->GetMinimum();
0171 
0172     trend->SetStats(kFALSE);
0173 
0174     trend->GetYaxis()->SetRangeUser(mintrend*0.5,trend->GetMaximum()*2);
0175     trend->Draw("P");
0176     outname=hn+"_Trend.png";
0177     c1.SaveAs(outname.c_str());
0178     c1.Clear();
0179 
0180     delete trend;      
0181     
0182   }  
0183   return 0;
0184 }
0185 
0186