Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:02

0001 {
0002 #include <sstream>
0003 #include <iostream>
0004 #include <string.h> 
0005 #include <vector.h> 
0006 #include "triggerCscIdSector.h"
0007 
0008 gROOT->Reset();
0009 gROOT->SetStyle("Plain"); // to get rid of gray color of pad and have it white
0010 gStyle->SetPalette(1,0); // 
0011 std::ostringstream ss,ss1;
0012 
0013 /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
0014 
0015 // select run number
0016 std::string run="62232";
0017 
0018 //  input file with histograms
0019 ss.str("");
0020 ss<<"validationHists_"<<run<<".root";
0021 TFile f_in(ss.str().c_str());
0022 // output file with histograms
0023 ss.str("");
0024 ss<<"afeb_timing_"<<run<<".root";
0025 TFile f_out(ss.str().c_str(),"RECREATE");
0026 
0027 // folder in input file
0028 std::string in_folder="AFEBTiming/";
0029 
0030 /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
0031 
0032 /// common names and titles
0033 
0034 // for CSC in given ME+- station/ring
0035 std::vector<std::string> xTitle_ME_CSC;
0036 xTitle_ME_CSC.push_back("ME-1/1 and ME+1/1 CSC #");
0037 xTitle_ME_CSC.push_back("ME-1/2 and ME+1/2 CSC #");
0038 xTitle_ME_CSC.push_back("ME-1/3 and ME+1/3 CSC #"); 
0039 xTitle_ME_CSC.push_back("ME-2/1 and ME+2/1 CSC #");
0040 xTitle_ME_CSC.push_back("ME-2/2 and ME+2/2 CSC #");
0041 xTitle_ME_CSC.push_back("ME-3/1 and ME+3/1 CSC #");
0042 xTitle_ME_CSC.push_back("ME-3/2 and ME+3/2 CSC #");
0043 xTitle_ME_CSC.push_back("ME-4/1 and ME+4/1 CSC #");
0044 xTitle_ME_CSC.push_back("ME-4/2 and ME+4/2 CSC #");
0045 
0046 std::vector<std::string> xLabel_A_ME_CSC, xLabel_B_ME_CSC;
0047 Int_t flag=2;
0048 for(Int_t i=1;i<=36;i++) {
0049   
0050    ss.str("");
0051    if(flag==2) {
0052    Int_t cscnmb;
0053    if(i<19) cscnmb=i-19;
0054    if(i>18) cscnmb=i-18;
0055    if(cscnmb !=1) ss<<cscnmb;
0056    flag=0;
0057    if(cscnmb ==1) flag=1;
0058    }
0059    xLabel_A_ME_CSC.push_back(ss.str().c_str());
0060    flag++;
0061 }
0062 
0063 flag=4;
0064 for(Int_t i=1;i<=72;i++) {
0065   
0066    ss.str("");
0067    if(flag==5) {
0068    Int_t cscnmb;
0069    if(i<37) cscnmb=i-37;
0070    if(i>36) cscnmb=i-36;
0071    if(cscnmb !=1) ss<<cscnmb;
0072    flag=0;
0073    if(cscnmb ==1) flag=1;
0074    }
0075    xLabel_B_ME_CSC.push_back(ss.str().c_str());
0076    flag++;
0077 }
0078 
0079 // for CSC in all ME
0080 std::vector<std::string> yTitle_ME;
0081 yTitle_ME.push_back("ME- 4/2"); yTitle_ME.push_back("ME- 4/1");
0082 yTitle_ME.push_back("ME- 3/2"); yTitle_ME.push_back("ME- 3/1");
0083 yTitle_ME.push_back("ME- 2/2"); yTitle_ME.push_back("ME- 2/1");
0084 yTitle_ME.push_back("ME- 1/3"); yTitle_ME.push_back("ME- 1/2");
0085 yTitle_ME.push_back("ME- 1/1");
0086 yTitle_ME.push_back("ME+ 1/1");
0087 yTitle_ME.push_back("ME+ 1/2"); yTitle_ME.push_back("ME+ 1/3");
0088 yTitle_ME.push_back("ME+ 2/1"); yTitle_ME.push_back("ME+ 2/2");
0089 yTitle_ME.push_back("ME+ 3/1"); yTitle_ME.push_back("ME+ 3/2");
0090 yTitle_ME.push_back("ME+ 4/1"); yTitle_ME.push_back("ME+ 4/2");
0091 
0092 // input hist names
0093 std::vector<std::string> input_histName;
0094 input_histName.push_back("afeb_time_bin_vs_afeb_occupancy_ME_");
0095 input_histName.push_back("nmb_afeb_time_bins_vs_afeb_ME_");
0096 
0097 // common titles
0098 std::string title_afeb="AFEB";
0099 std::string title_time_bin="Time Bin";
0100 std::string title_nmb_time_bin="Nmb of Time Bins";
0101 std::string title_entries="Entries";
0102 
0103 // resulting hist names
0104 std::string result_histName = "mean_afeb_time_bin_vs_afeb_csc_ME_";
0105 std::string result_histTitle="AFEB Mean Time Bin";
0106 std::string result_title_Y="AFEB";
0107 
0108 std::string result_histNameEntries = "entries_afeb_time_bin_vs_afeb_csc_ME_";
0109 std::string result_histTitleEntries="Entries AFEB Time Bin";
0110 
0111 std::string result_histNameFr = "fraction_gt2_afeb_time_bin_vs_afeb_csc_ME_";
0112 std::string result_histTitleFr="Fraction of (Nmb of AFEB time bins > 2), %";
0113 
0114 std::string result_graphNameMean = "graph_mean_afeb_time_bin_vs_csc_ME_";
0115 std::string result_graphTitleMean ="CSC Anode Mean Time Bin"; 
0116 
0117 std::string result_histNameNmbAnodeTimeBins = "normal_nmb_afeb_time_bins_occupancy";
0118 std::string result_histTitleNmbAnodeTimeBins ="Number of AFEB time bins normalized occupancy, %";
0119 
0120 std::string result_graphNameMeanTrig = "graph_mean_afeb_time_bin_vs_trigger_csc_ME";
0121 std::string result_graphTitleMeanTrig ="CSC Anode Mean Time Bin";
0122 
0123 
0124 // folders in output hist file
0125 f_out.cd();
0126 f_out.mkdir("Summary");
0127 f_out.mkdir("Results");
0128 f_out.mkdir("Input_hists");
0129 f_out.mkdir("Y_projections");
0130 f_out.mkdir("Slices");
0131 
0132 
0133 TH1F *hnnmboc_all;
0134 TH2F *h2,*h2norm, *h_csc_me, *h2norm;
0135 TH2F *hmean[9],*hnoc[9],*hnnmboc[9],*hentr[9],*hfrgt2[9];
0136 TGraphErrors *gr_mean[9],*gr_mean_trig[2];
0137 TCanvas *cgraph[9],*cgr_mean_trig[2];
0138 
0139 Int_t gr_np[9];
0140 Float_t gr_x[9][72];
0141 Float_t gr_y[9][72];
0142 Float_t gr_x_er[9][72]={0.0};
0143 Float_t gr_y_er[9][72];
0144 
0145 vector<Float_t> gr_y_trg_minus, gr_y_trg_plus,
0146                 gr_y_trg_minus_er, gr_y_trg_plus_er,
0147                 gr_x_trg_minus,gr_x_trg_plus,
0148                 gr_x_trg_minus_er,gr_x_trg_plus_er;
0149 std::vector<std::string> trg_minus_cscid, trg_plus_cscid;
0150 
0151 // endcap, station, ring
0152 Int_t esr[18]={111,112,113,121,122,131,132,141,142,
0153                211,212,213,221,222,231,232,241,242};
0154 Int_t entries[18]={0,0,0,0,0,0,0,0,0,
0155                    0,0,0,0,0,0,0,0,0};
0156 
0157 // station, ring sequence, # of CSC and AFEB
0158 Int_t sr[9]={11,12,13,21,22,31,32,41,42};
0159 Int_t ncsc[9]={36,36,36,18,36,18,36,18,36};
0160 Int_t nafeb[9]={18,24,12,42,24,36,24,36,24};
0161 Int_t ncscmis=0;
0162 vector<int> cscmis; cscmis.push_back(0);
0163 
0164 /// book output histograms with all CSCs for given ME+- station,ring
0165 
0166 for(Int_t isr=0;isr<9;isr++) {
0167   std::vector<std::string> xLabel_ME_CSC; xLabel_ME_CSC.clear();
0168      Int_t ny=nafeb[isr];
0169      Float_t ylow=1.0; Float_t yhigh=ny; yhigh=yhigh+1.0;
0170      if(ncsc[isr]==36) {
0171        Int_t nx=72; Float_t xlow=-35.0; Float_t xhigh=37.0;
0172        xLabel_ME_CSC=xLabel_B_ME_CSC;
0173      }
0174      if(ncsc[isr]==18) {
0175        Int_t nx=36; Float_t xlow=-17.0; Float_t xhigh=19.0;
0176        xLabel_ME_CSC=xLabel_A_ME_CSC;
0177      }
0178      gr_np[isr]=nx;
0179      for(Int_t n=0;n<nx;n++) {
0180         if(n==0) gr_x[isr][n]=xlow-1.0;
0181         if(n>0) {
0182           gr_x[isr][n]=gr_x[isr][n-1]+1.0;
0183           if(gr_x[isr][n]==0.0) gr_x[isr][n]=1.0;
0184     }  
0185      }
0186       
0187   // 2D hists for mean afeb time bin vs afeb and csc in given ME+-
0188      
0189      ss.str("");
0190      ss<<result_histName.c_str()<<sr[isr];
0191      ss1.str("");
0192      ss1<<result_histTitle<<" in run "<<run.c_str();
0193      hmean[isr]=new TH2F(ss.str().c_str(),ss1.str().c_str(),nx,xlow,xhigh,ny,ylow,yhigh);
0194      for(Int_t i=1;i<=nx;i++) hmean[isr]->GetXaxis()->SetBinLabel(i,xLabel_ME_CSC[i-1].c_str());
0195      hmean[isr]->SetStats(kFALSE);
0196      hmean[isr]->GetXaxis()->SetTitle(xTitle_ME_CSC[isr].c_str());
0197      hmean[isr]->GetYaxis()->SetTitle(result_title_Y.c_str());
0198      hmean[isr]->GetZaxis()->SetLabelSize(0.03);
0199      hmean[isr]->SetOption("COLZ");
0200      hmean[isr]->SetMinimum(4.0);
0201      hmean[isr]->SetMaximum(12.0);
0202 
0203   // 2D hists for entries afeb time bin vs afeb and csc in given ME+-
0204      ss.str("");
0205      ss<<result_histNameEntries.c_str()<<sr[isr];
0206      ss1.str("");
0207      ss1<<result_histTitleEntries<<" in run "<<run.c_str();
0208      hentr[isr]=new TH2F(ss.str().c_str(),ss1.str().c_str(),nx,xlow,xhigh,ny,ylow,yhigh);
0209      for(Int_t i=1;i<=nx;i++) hentr[isr]->GetXaxis()->SetBinLabel(i,xLabel_ME_CSC[i-1].c_str());
0210      hentr[isr]->SetStats(kFALSE);
0211      hentr[isr]->GetXaxis()->SetTitle(xTitle_ME_CSC[isr].c_str());
0212      hentr[isr]->GetYaxis()->SetTitle(result_title_Y.c_str());
0213      hentr[isr]->GetZaxis()->SetLabelSize(0.03);
0214      hentr[isr]->SetOption("COLZ");
0215 
0216   // 2D hists for fraction of nmb of afeb time bins > 2 vs afeb and csc in ME+-
0217      ss.str("");
0218      ss<<result_histNameFr.c_str()<<sr[isr];
0219      ss1.str("");
0220      ss1<<result_histTitleFr<<" in run "<<run.c_str();
0221      hfrgt2[isr]=new TH2F(ss.str().c_str(),ss1.str().c_str(),nx,xlow,xhigh,ny,ylow,yhigh);
0222      for(Int_t i=1;i<=nx;i++) hfrgt2[isr]->GetXaxis()->SetBinLabel(i,xLabel_ME_CSC[i-1].c_str());
0223      hfrgt2[isr]->SetStats(kFALSE);
0224      hfrgt2[isr]->GetXaxis()->SetTitle(xTitle_ME_CSC[isr].c_str());
0225      hfrgt2[isr]->GetYaxis()->SetTitle(result_title_Y.c_str());
0226      hfrgt2[isr]->GetZaxis()->SetLabelSize(0.03);
0227      hfrgt2[isr]->SetOption("COLZ");
0228      hfrgt2[isr]->SetMinimum(0.0);
0229      hfrgt2[isr]->SetMaximum(20.0);
0230 
0231      // 2D hists for normalized AFEB time bin occupancy, % 
0232      // vs afeb and csc in ME+-
0233      ss.str(""); ss1.str("");
0234      ss<<"normal_afeb_time_bin_vs_csc_ME_"<<sr[isr];
0235      ss1<<"Normalized AFEB time bin occupancy, %"<<" in run "<<run.c_str();
0236      hnoc[isr]=new TH2F(ss.str().c_str(),ss1.str().c_str(),nx,xlow,xhigh,16,0.0,16.0);
0237      for(Int_t i=1;i<=nx;i++) hnoc[isr]->GetXaxis()->SetBinLabel(i,xLabel_ME_CSC[i-1].c_str());
0238      hnoc[isr]->SetStats(kFALSE);
0239      hnoc[isr]->GetXaxis()->SetTitle(xTitle_ME_CSC[isr].c_str());
0240      hnoc[isr]->GetYaxis()->SetTitle(title_time_bin.c_str());
0241      hnoc[isr]->GetZaxis()->SetLabelSize(0.03);
0242      hnoc[isr]->SetOption("COLZ");
0243      hnoc[isr]->SetMinimum(0.0);
0244      hnoc[isr]->SetMaximum(100.0);
0245  
0246      // 2D hists for normalized number of AFEB time bin occupancy, % 
0247      // vs afeb and csc in ME+ 
0248      ss.str(""); ss1.str("");
0249      ss<<"normal_nmb_afeb_time_bins_vs_csc_ME_"<<sr[isr];
0250      ss1<<"Normalized Nmb of AFEB time bins occupancy, %"<<" in run "<<run.c_str();
0251      hnnmboc[isr]=new TH2F(ss.str().c_str(),ss1.str().c_str(),nx,xlow,xhigh,16,0.0,16.0);
0252      for(Int_t i=1;i<=nx;i++) hnnmboc[isr]->GetXaxis()->SetBinLabel(i,xLabel_ME_CSC[i-1].c_str());
0253      hnnmboc[isr]->SetStats(kFALSE);
0254      hnnmboc[isr]->GetXaxis()->SetTitle(xTitle_ME_CSC[isr].c_str());
0255      hnnmboc[isr]->GetYaxis()->SetTitle(title_nmb_time_bin.c_str());
0256      hnnmboc[isr]->GetZaxis()->SetLabelSize(0.03);
0257      hnnmboc[isr]->SetOption("COLZ");
0258      hnnmboc[isr]->SetMinimum(0.0);
0259      hnnmboc[isr]->SetMaximum(100.0);
0260 } // end of for(Int_t isr=0
0261 
0262 /// Histogram of number of anode time bins ON for all afebs
0263      ss.str(""); ss1.str("");
0264      ss<<result_histNameNmbAnodeTimeBins.c_str();
0265      ss1<<result_histTitleNmbAnodeTimeBins.c_str()<<" in run "<<run.c_str();
0266      hnnmboc_all=new TH1F(ss.str().c_str(),ss1.str().c_str(),16,0.0,16.0);
0267      hnnmboc_all->GetXaxis()->SetTitle(title_nmb_time_bin.c_str());
0268      hnnmboc_all->GetYaxis()->SetTitle("Normalized occupancy, %");
0269      
0270      hnnmboc_all->SetFillColor(4);
0271      
0272 //***TCanvas *c1=new TCanvas("c1","canvas");
0273 
0274 //***c1->cd();
0275 
0276 /// get two types of input hists and analyze them
0277 
0278 for(Int_t inp=1;inp<=2;inp++) {
0279   ss.str("");
0280   if(inp==1) ss<<"mean_afeb_time_bin_vs_csc_ME";
0281   if(inp==2) ss<<"rel_max_nmb_afeb_time_bins_vs_csc_ME";
0282   ss1.str("");
0283   if(inp==1) ss1<<"Mean AFEB time bin vs CSC and ME"<<" in run "<<run.c_str();
0284   if(inp==2) ss1<<"Max. Fraction of (Nmb of AFEB time bins > 2), %"<<" in run "<<run.c_str();
0285   gStyle->SetOptStat(0);
0286 
0287   // book two output 2D hists for mean time and number of entris vs CSC and ME
0288   h_csc_me=new TH2F(ss.str().c_str(),ss1.str().c_str(),36,1.0,37.0,18,1.0,19.0);
0289   h_csc_me->SetStats(kFALSE);
0290   h_csc_me->GetXaxis()->SetTitle("CSC #");
0291   for(Int_t i=1;i<=18;i++) h_csc_me->GetYaxis()->SetBinLabel(i,yTitle_ME[i-1].c_str());
0292   h_csc_me->GetZaxis()->SetLabelSize(0.03);
0293   h_csc_me->SetOption("COLZ");
0294   if(inp==1) {
0295     h_csc_me->SetMinimum(4.0);
0296     h_csc_me->SetMaximum(12.0);
0297   }
0298   if(inp==2) {
0299     h_csc_me->SetMinimum(0.0);
0300     h_csc_me->SetMaximum(20.0);
0301   }
0302   // cycle over 18 endcap/station/ring combinations
0303 
0304 for(Int_t jesr=0;jesr<18;jesr++) {
0305   if(esr[jesr] != 142 && esr[jesr] != 242) {
0306   Int_t me;
0307   if(jesr<9) me=10+jesr;
0308   if(jesr>8) me=18-jesr;
0309 
0310   Int_t indisr;
0311   if(esr[jesr] < 200) indisr=esr[jesr]-100;
0312   if(esr[jesr] > 200) indisr=esr[jesr]-200;
0313 
0314   // define index for vector sr[9] (station,ring)
0315   for(Int_t i=0;i<8;i++) if(sr[i]==indisr) indisr=i; 
0316 
0317   // cycle over CSC 
0318   for(Int_t csc=1;csc<(ncsc[indisr]+1);csc++) {
0319      Int_t cscbin;
0320      // define bin cscbin in hists for ME+-
0321      if(esr[jesr]<200) cscbin=ncsc[indisr]+csc;
0322      if(esr[jesr]>200) cscbin=ncsc[indisr]-csc+1;
0323 
0324      Int_t idchamber=esr[jesr]*100+csc;
0325      ss.str("");
0326      ss<<in_folder.c_str()<<input_histName[inp-1].c_str()<<idchamber;
0327      f_in.cd();
0328      //gStyle->SetOptStat(0000011);
0329      TH2F *h2 = (TH2F*)f_in.Get(ss.str().c_str());
0330      if(h2 ==NULL && inp==1) {
0331        ncscmis++;
0332        cscmis.push_back(idchamber);
0333        //       std::cout<<"No chamber "<<idchamber<<std::endl;
0334      }
0335    if(h2 != NULL) {
0336      ss.str(""); ss1.str("");
0337      ss<<input_histName[inp-1].c_str()<<idchamber<<"_norm";
0338      ss1<<h2->GetTitle()<<" normalized, %"<<" in run "<<run.c_str();
0339      if(inp==1) {Int_t ny=16; Float_t ylow=0.0; Float_t yhigh=16.0;}
0340      if(inp==2) {Int_t ny=16; Float_t ylow=0.0; Float_t yhigh=16.0;}
0341      Int_t nx=nafeb[indisr]; Float_t xlow=1.0; Float_t xhigh=xlow+nx;
0342      h2norm=new TH2F(ss.str().c_str(),ss1.str().c_str(),nx,xlow,xhigh,ny,ylow,yhigh);
0343      h2norm->SetStats(kFALSE);
0344      
0345      f_out.cd("Input_hists");
0346 
0347      // saving original (modified to fraction in %), adding X,Y titles, 
0348      //color and "COLZ" option
0349 
0350      for(Int_t i=1;i<=h2->GetNbinsX();i++) {
0351        Float_t sum=0.0;
0352        for(Int_t j=1;j<=h2->GetNbinsY();j++) sum=sum+h2->GetBinContent(i,j);
0353        if(sum>0.0) {
0354          Float_t w;
0355          for(Int_t j=1;j<=h2->GetNbinsY();j++) {
0356         w=100.0*h2->GetBinContent(i,j)/sum;
0357         h2norm->SetBinContent(i,j,w);
0358      }
0359        }
0360      }
0361 
0362      h2norm->GetXaxis()->SetTitle(title_afeb.c_str());
0363      if(inp==1) h2norm->GetYaxis()->SetTitle(title_time_bin.c_str());
0364      if(inp==2) h2norm->GetYaxis()->SetTitle(title_nmb_time_bin.c_str());
0365      h2norm->GetYaxis()->SetTitleOffset(1.2);
0366      h2norm->SetOption("COLZ");
0367      h2norm->Write();
0368  
0369      // saving Y projection of the whole 2D hist for given chamber
0370 
0371      ss.str("");
0372      ss<<input_histName[inp-1].c_str()<<idchamber<<"_Y_all";
0373      TH1D *h1d = h2->ProjectionY(ss.str().c_str(),1,h2->GetNbinsX(),"");
0374      if(inp==1) h1d->GetXaxis()->SetTitle(title_time_bin.c_str());
0375      if(inp==2) h1d->GetXaxis()->SetTitle(title_nmb_time_bin.c_str());
0376      h1d->GetYaxis()->SetTitle(title_entries.c_str());
0377      h1d->GetYaxis()->SetTitleOffset(1.2);
0378      gStyle->SetOptStat(1001111);
0379      f_out.cd("Y_projections");
0380      h1d->SetFillColor(4);
0381      h1d->Write();
0382 
0383      if(h1d->GetEntries() > 0) {
0384        Float_t entr=h1d->GetEntries();
0385        for(Int_t m=1; m<=h1d->GetNbinsX();m++) {
0386      Float_t w=h1d->GetBinContent(m);
0387          if(inp==2) {
0388            Float_t fm=h1d->GetBinCenter(m);
0389            hnnmboc_all->Fill(fm,w);
0390          }
0391          w=100.0*w/entr;
0392          if(inp==1) hnoc[indisr]->SetBinContent(cscbin,m,w);
0393          if(inp==2) hnnmboc[indisr]->SetBinContent(cscbin,m,w);
0394        }
0395        
0396        Float_t mean=h1d->GetMean()-0.5;
0397 
0398        if(inp==1) {
0399          gr_y[indisr][cscbin-1]=mean;
0400          gr_y_er[indisr][cscbin-1]=h1d->GetMeanError(1);
0401          Float_t grmean=mean;
0402 
0403          if(mean<4.0) mean=4.0;
0404          if(mean>12.0) mean=12.0;
0405      Int_t imean=mean; mean=imean;
0406          h_csc_me->SetBinContent(csc,me,mean);
0407 
0408          // for trigger sector graphs
0409          Int_t station=sr[indisr]/10;
0410          Int_t ring=sr[indisr]-station*10;
0411          Int_t sector= triggerSector(station,ring,csc);
0412          if(esr[jesr] > 200) sector=sector+6;
0413          Int_t trigcscid=triggerCscId(station,ring,csc);
0414      /* Like in D. Wang presentation, though maybe different in ME1/1 */
0415          Float_t xtrigcsc = sector*100+station*20+trigcscid;
0416          ss.str("");
0417      if(esr[jesr] < 200) { // ME+
0418            gr_y_trg_plus.push_back(grmean);
0419            gr_y_trg_plus_er.push_back(h1d->GetMeanError(1));
0420            gr_x_trg_plus.push_back(xtrigcsc);
0421            gr_x_trg_plus_er.push_back(0.0);
0422            ss<<"ME+"<<station<<"/"<<ring<<"/"<<csc;
0423            trg_plus_cscid.push_back(ss.str().c_str());
0424            ss.str("");  
0425      }
0426      if(esr[jesr] > 200) { // ME-
0427            gr_y_trg_minus.push_back(grmean);
0428            gr_y_trg_minus_er.push_back(h1d->GetMeanError(1));
0429            gr_x_trg_minus.push_back(xtrigcsc);
0430            gr_x_trg_minus_er.push_back(0.0);
0431            ss<<"ME-"<<station<<"/"<<ring<<"/"<<csc;
0432            trg_minus_cscid.push_back(ss.str().c_str());
0433            ss.str("");  
0434      }
0435        }
0436      }
0437      delete h1d;   
0438 
0439      // saving slices, finding MEAN in each slice, fill 2D hist
0440      f_out.cd("Slices");
0441      Float_t maxsum=0.0;
0442      for(Int_t j=1;j<=h2->GetNbinsX();j++) {
0443         Int_t n=j;
0444         ss.str("");
0445         ss<<input_histName[inp-1].c_str()<<idchamber<<"_Y_"<<n;
0446         TH1D *h1d = h2->ProjectionY(ss.str().c_str(),j,j,"");
0447     //std::cout<<cscbin<<" "<<j<<" "<<h1d->GetEntries()<<std::endl;
0448         Float_t entr=h1d->GetEntries();
0449         if(entr > 0.0) {
0450           Float_t sum=entr-(h1d->GetBinContent(2)+h1d->GetBinContent(3));
0451           sum=100.0*sum/entr;
0452           if(sum>maxsum) maxsum=sum;
0453       //  Float_t mean=h1d->GetMean();
0454           Float_t mean=h1d->GetMean()-0.5; // since June 03, 2008
0455           entries[jesr]=entries[jesr]+1;
0456           if(inp==1) {
0457             if(mean<4.0) mean=4.0;
0458             if(mean>12.0) mean=12.0;
0459         Int_t imean=mean; mean=imean;
0460            hmean[indisr]->SetBinContent(cscbin,j,mean);
0461            hentr[indisr]->SetBinContent(cscbin,j,entr);
0462       }
0463           if(inp==2) {
0464             if(sum>20.0) sum=20.0;
0465             hfrgt2[indisr]->SetBinContent(cscbin,j,sum);
0466       }
0467           ss.str("");
0468           ss<<title_afeb<<" "<<n;
0469           h1d->GetXaxis()->SetTitle(ss.str().c_str());
0470           h1d->GetYaxis()->SetTitle(title_entries.c_str());
0471           h1d->GetYaxis()->SetTitleOffset(1.2);
0472           gStyle->SetOptStat(1001111);
0473           h1d->SetFillColor(4);
0474           h1d->Write();
0475     }
0476         delete h1d;
0477      }
0478      if(inp==2 && maxsum > 0.0) {
0479        if(maxsum > 20.0) maxsum=20.0;
0480        h_csc_me->SetBinContent(csc,me,maxsum);
0481      }
0482      delete h2norm;
0483    }
0484      delete h2;
0485   }
0486   } // end if not ME42
0487 } // end of for(jesr=0
0488    f_out.cd("Summary");
0489    h_csc_me->Write();
0490    delete h_csc_me;    
0491 
0492 } // end of for(inp=1
0493 
0494 /// Write others resulting hists
0495 
0496 f_out.cd("Results");
0497 for(Int_t isr=0;isr<8;isr++) {
0498   if(hmean[isr] != NULL) {
0499        hmean[isr]->SetStats(kFALSE);
0500        hmean[isr]->Write();
0501   }
0502   if(hentr[isr] != NULL) {
0503        hentr[isr]->SetStats(kFALSE);
0504        hentr[isr]->Write();
0505   }
0506   if(hnoc[isr] != NULL) hnoc[isr]->Write();
0507 
0508   if(hnnmboc[isr] != NULL)     hnnmboc[isr]->Write();
0509   if(hfrgt2[isr] != NULL)     hfrgt2[isr]->Write();
0510 }
0511 
0512 Int_t movf=hnnmboc_all->GetNbinsX()+1; // overflow bin    
0513 Double_t norm=100.0/(hnnmboc_all->Integral()+hnnmboc_all->GetBinContent(movf));
0514 hnnmboc_all->Scale(norm);
0515 
0516 c_hnnmboc_all_clone= new TCanvas(result_histNameNmbAnodeTimeBins.c_str());
0517 c_hnnmboc_all_clone->cd();
0518 c_hnnmboc_all_clone->SetLogy();
0519 hnnmboc_all->SetStats(kFALSE);
0520 
0521 hnnmboc_all->Draw();
0522 TText txt;
0523 txt.SetTextSize(0.05);
0524 
0525 Float_t fr=hnnmboc_all->Integral()+hnnmboc_all->GetBinContent(movf)-
0526                                    hnnmboc_all->GetBinContent(1)-
0527                                    hnnmboc_all->GetBinContent(2)-
0528                                    hnnmboc_all->GetBinContent(3);
0529 Int_t ifr=fr*1000.0;
0530 fr=ifr; fr=fr/1000.0;
0531 ss.str("");
0532 ss<<"Nmb of Time Bins > 2 = "<<fr<<" %";
0533 txt.DrawTextNDC(0.35,0.8,ss.str().c_str());
0534 
0535 c_hnnmboc_all_clone->Update();
0536 f_out.cd("Summary");
0537 c_hnnmboc_all_clone->Write();
0538 
0539 
0540 for(Int_t isr=0;isr<8;isr++) {
0541    delete hmean[isr]; delete hentr[isr]; delete hnoc[isr]; delete hnnmboc[isr];
0542    delete  hfrgt2[isr];
0543 }
0544 
0545 /// Report missing CSCs
0546 std::cout<<"Missing csc "<<ncscmis<<std::endl;
0547 if(ncscmis > 0) {
0548   for(Int_t jesr=0;jesr<18;jesr++) {
0549     Int_t n=0,npr=0;
0550     for(Int_t i=0;i<cscmis.size();i++) {
0551       Int_t idesr=cscmis[i]/100;
0552       if(esr[jesr]==idesr && n<10) {n++;npr++;std::cout<<cscmis[i]<<"   ";}
0553       if(n==10) {std::cout<<std::endl; n=0;} 
0554     }
0555     if(npr>0) std::cout<<std::endl;
0556   }
0557 }
0558 
0559 /// Plot and save graphs
0560 
0561 // mean anode time bin vs CSC in given ME+-
0562 for(Int_t isr=0;isr<8;isr++) {
0563      ss.str("");
0564      ss<<result_graphNameMean.c_str()<<sr[isr];
0565      std::cout<<isr+1<<" "<<ss.str().c_str()<<std::endl;
0566      cgraph[isr]= new TCanvas(ss.str().c_str());
0567      cgraph[isr]->cd();
0568      cgraph[isr]->SetGrid();
0569      Float_t x[72],y[72],ery[72],erx[72];
0570      if(gr_np[isr]>0) {
0571       for(Int_t n=0;n<gr_np[isr];n++) {
0572         x[n]=gr_x[isr][n];
0573         y[n]=gr_y[isr][n];
0574         erx[n]=0.0; 
0575         ery[n]=gr_y_er[isr][n];
0576       }
0577       gr_mean[isr]=new TGraphErrors(gr_np[isr],x,y,erx,ery);  
0578       ss1.str("");
0579       ss1<<result_graphTitleMean<<" in run "<<run.c_str();
0580       gr_mean[isr]->SetTitle(ss1.str().c_str());
0581       gr_mean[isr]->GetXaxis()->SetTitle(xTitle_ME_CSC[isr].c_str());
0582       gr_mean[isr]->GetYaxis()->SetTitle(title_time_bin.c_str());
0583       gr_mean[isr]->SetMinimum(4.0); 
0584       gr_mean[isr]->SetMaximum(12.0); 
0585       gr_mean[isr]->SetMarkerStyle(20);
0586       gr_mean[isr]->SetMarkerColor(4);
0587       gr_mean[isr]->SetMarkerSize(1.2);
0588       gr_mean[isr]->SetLineColor(4);    // Blue error bar
0589       gr_mean[isr]->Draw("APZ"); 
0590       cgraph[isr]->Update();
0591       f_out.cd("Results");
0592       cgraph[isr]->Write();
0593      }
0594 }
0595 
0596 // Text output for anode mean time vs CSC
0597 
0598 std::cout<<std::endl;
0599 for(Int_t i=0;i<trg_plus_cscid.size();i++) 
0600   //printf("%s %7.2f \n",trg_plus_cscid[i],gr_y_trg_plus[i]); 
0601   std::cout<<trg_plus_cscid[i]<<"   "<<gr_y_trg_plus[i]<<std::endl;
0602 for(Int_t i=0;i<trg_minus_cscid.size();i++) 
0603   std::cout<<trg_minus_cscid[i]<<"   "<<gr_y_trg_minus[i]<<std::endl;
0604 
0605 std::cout<<std::endl;
0606 std::cout<<"Total CSCs "<<trg_plus_cscid.size()+trg_minus_cscid.size()<<std::endl;
0607 std::cout<<std::endl;
0608 
0609 // mean anode time bin vs csc in trigger sector for ME+ and ME-
0610 
0611 Float_t x_tr[234],y_tr[234],ery_tr[234],erx_tr[234];
0612 for(Int_t i=0;i<2;i++) {
0613      ss.str("");
0614      if(i==0) ss<<result_graphNameMeanTrig.c_str()<<"+";
0615      if(i==1) ss<<result_graphNameMeanTrig.c_str()<<"-";    
0616      if(i==0) Int_t x_size=gr_x_trg_plus.size();
0617      if(i==1) Int_t x_size=gr_x_trg_minus.size();
0618      std::cout<<i+1<<" "<<x_size<<std::endl;
0619      if(x_size > 0) {
0620       cgr_mean_trig[i] = new TCanvas(ss.str().c_str());
0621       cgr_mean_trig[i]->cd();
0622       cgr_mean_trig[i]->SetGrid();
0623       for(Int_t n=0;n<x_size;n++) {
0624         if(i==0) {
0625          y_tr[n]=gr_y_trg_plus[n];
0626          ery_tr[n]=gr_y_trg_plus_er[n];
0627         }
0628         if(i==1) {
0629          y_tr[n]=gr_y_trg_minus[n];
0630          ery_tr[n]=gr_y_trg_minus_er[n];
0631         }
0632         x_tr[n]=n+1;
0633         erx_tr[n]=0.0; 
0634       }
0635       gr_mean_trig[i]=new TGraphErrors(x_size,x_tr,y_tr,erx_tr,ery_tr);  
0636       ss1.str("");
0637       if(i==0) ss1<<"ME+ "<<result_graphTitleMeanTrig<<" in run "<<run.c_str();
0638       if(i==1) ss1<<"ME- "<<result_graphTitleMeanTrig<<" in run "<<run.c_str();
0639       gr_mean_trig[i]->SetTitle(ss1.str().c_str());
0640       gr_mean_trig[i]->GetXaxis()->SetTitle("ChamberId=SectorId*100+StationId*10+CSCID in increasing order");
0641       gr_mean_trig[i]->GetYaxis()->SetTitle(title_time_bin.c_str());
0642       gr_mean_trig[i]->SetMinimum(4.0);
0643       gr_mean_trig[i]->SetMaximum(12.0);
0644       gr_mean_trig[i]->SetMarkerStyle(20);
0645       gr_mean_trig[i]->SetMarkerColor(4);
0646       gr_mean_trig[i]->SetMarkerSize(1.0);
0647       gr_mean_trig[i]->SetLineColor(4);    // Blue error bar
0648       gr_mean_trig[i]->Draw("APZ"); 
0649       cgr_mean_trig[i]->Update();
0650       f_out.cd("Summary");
0651       cgr_mean_trig[i]->Write();
0652      }
0653 }
0654 f_out.Close();
0655 }