Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:47

0001 #include "TROOT.h"
0002 #include "TSystem.h"
0003 #include "TH1D.h"
0004 #include "THStack.h"
0005 #include "TChain.h"
0006 #include "TTree.h"
0007 #include "TLegend.h"
0008 #include "TFile.h"
0009 #include "TCanvas.h"
0010 #include "TLorentzVector.h"
0011 #include <iostream>
0012 #include <sstream>
0013 #include <fstream.h>
0014 #include "TPostScript.h"
0015 using namespace std;
0016 
0017 void NoiseAnalyzer();
0018 
0019 void NoiseAnalyzer()
0020 {
0021 
0022   // the input file
0023   TFile *f1 = new TFile("DTNoiseCalib.root");
0024   
0025   // the output files
0026   TPostScript *ps = new TPostScript("DTNoise.ps", 112);
0027   ofstream summaryOutput("summaryNoise.txt");
0028   ofstream detailedOutput("detailedNoise.txt");
0029 
0030   TCanvas* c = new TCanvas("prova", "prova");
0031   TLegend *leg=new TLegend(0.2,0.75,0.9,0.88);
0032 
0033 
0034    for(int W=-2; W<=2; W++){
0035      std::stringstream wheel; wheel << W;
0036      for(int Sec=1; Sec<=14; Sec++){
0037        std::stringstream sector; sector << Sec;
0038        for(int St=1; St<=4; St++){
0039      double counterSomehowNoisyCells=0;
0040      double counterNoisyCells=0;
0041      bool StationHasData=false;
0042      std::stringstream station; station << St;
0043      for(int SL=1; SL<=3; SL++){
0044        leg->Clear();
0045        bool SLhasData=false;
0046        bool pageWritten=false;
0047        std::stringstream superlayer; superlayer << SL;
0048        TString newHistoName="AverageNoise_W"+wheel.str()+"_St"+station.str()+"_Sec"+sector.str()+"_SL"+superlayer.str();
0049        for(int L=1; L<=4; L++){
0050          std::stringstream layer; layer << L;
0051          
0052          // find the histo
0053          TString histoName="DigiOccupancy_W"+wheel.str()+"_St"+station.str()+"_Sec"+sector.str()+"_SL"+superlayer.str()+"_L"+layer.str();
0054          TH1F* h =((TH1F*) f1->Get(histoName));
0055          if(h){
0056            StationHasData=true;
0057            SLhasData=true;
0058            //overimpose the plot per SL
0059            c->cd();
0060            TString legend= "layer_"+layer.str();
0061            if(L==1){
0062          h->SetTitle(newHistoName);
0063          h->SetLineColor(L);
0064          h->SetLineWidth(2);
0065          h->Draw();
0066          leg->AddEntry(h,legend,"L");
0067            }
0068            else{
0069          h->SetLineColor(L);
0070          h->SetLineWidth(2);
0071          h->Draw("same");
0072          leg->AddEntry(h,legend,"L");
0073            }
0074            //count the numeber of noisy/someHow noisy cells
0075            int numBin = h->GetXaxis()->GetNbins();
0076            for (int bin=1; bin<=numBin; bin++){
0077          if(h->GetBinContent(bin)>100 && h->GetBinContent(bin)<500){
0078            counterSomehowNoisyCells++;
0079            detailedOutput<<"somehowNoisyCell: W"<<W<<" St"<<St<<" Sec"<<Sec<<" SL"<<SL<<" L"<<L<<" wire"<<bin<<endl;
0080          }
0081           if(h->GetBinContent(bin)>500){
0082             counterNoisyCells++;
0083             detailedOutput<<"noisyCell: W"<<W<<" St"<<St<<" Sec"<<Sec<<" SL"<<SL<<" L"<<L<<" wire"<<bin<<endl;
0084           }
0085            } 
0086          }
0087 
0088         } // loop on layer
0089         if(SLhasData && !(pageWritten)){
0090           pageWritten=true;
0091           leg->Draw("same");
0092           gPad->SetLogy();
0093           c->Update();
0094         }
0095 
0096      } // loop on SL
0097      if(StationHasData){
0098        summaryOutput<<" ------------ "<<endl;
0099        summaryOutput<<"MB"<<St<<"_W"<<W<<"_Sec"<<Sec<<endl;
0100        summaryOutput<<"# of somehow noisy cells: "<<counterSomehowNoisyCells<<endl;
0101        summaryOutput<<"# of noisy cells: "<<counterNoisyCells<<endl;
0102      }
0103 
0104        } // loop on stations
0105      } // loop on sectors
0106    } // loop on wheels
0107 
0108    ps->Close();
0109 }