Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:32:25

0001 #include <sstream>
0002 #include <TH1>
0003 #include <TH1F>
0004 
0005 #include "ecalGrid.C"
0006 
0007 using namespace std;
0008 
0009 void fixcolz(){
0010    //to leave room for colz axis
0011    gPad->SetMargin(0.1,0.15,0.1,0.1);
0012 }
0013 
0014 //Fix z-axis of sparse TH2 map, excluding empty bin from axis range computation
0015 void fixcolzRange(TH1* h){
0016   double xmin = h->GetMinimum(0);
0017   double xmax = h->GetMaximum();
0018   double eps = 1.e-9;
0019   if(xmax-xmin > eps){
0020     h->GetZaxis()->SetRangeUser(xmin, xmax);
0021   }
0022 }
0023 
0024 /** Macro to plot histograms produce by the EcalSelectiveReadoutValidation package
0025  * @param inputfile path to the input ROOT file containing the histograms
0026  * @param output file format: see TH1::SaveAs. e.g. .gif, .ps
0027  * @param mode switch specifying part of the ECAL to include in the map drawing
0028  * Format is: 1000*eep+100*ebp+10*ebm+eem, where eep is 1 if EE+ endcap must be
0029  * included, 0 otherwise, etc.
0030  */
0031 void SRValidationPlots(TString inputfile = "srvalid_hists.root",
0032                        const char* ext = ".gif",
0033                        int mode_ = 1111){
0034 
0035   gStyle->SetPalette(1);
0036   Plot p;
0037   p.run(inputfile, ext, mode_);
0038 }
0039 
0040 struct Plot{
0041 
0042   bool sim;
0043   bool etsum;
0044   bool rec;
0045   bool barrel;
0046   bool endcap;
0047   bool autoLog;
0048   
0049   static TH1* h1Dummy;
0050   
0051   int mode = 1111;
0052 
0053   Plot(){
0054     sim = false;
0055     etsum = false;
0056     rec = true;
0057     autoLog = true; //false;
0058     mode = 1111;
0059     barrel = true; //overwritten in run(...)
0060     endcap = true; //overwritten in run(...)
0061   }
0062   
0063   int digit(int num, int idigit){
0064     for(int i = 0; i< idigit; ++i) num /= 10;
0065     return num  % 10;
0066   }
0067 
0068   void run(TString inputfile = "EcalSelectiveReadoutValidationHistos.root",
0069            const char* ext = ".gif",
0070            int mode_ = 1111){
0071 
0072     mode = mode_;
0073 
0074     barrel = digit(mode, 1) || digit(mode, 2);
0075 
0076     endcap = digit(mode, 0) || digit(mode, 3);
0077 
0078     gROOT ->Reset();
0079 
0080     gStyle->SetOptStat(111110);
0081     gStyle->SetStatFontSize(.025);
0082   
0083     gSystem->Exec("mkdir plots");
0084 
0085     TH1* h1Dummy = new TH1F("dummy","dummy", 100, 0, 1);
0086   
0087     TCanvas* c = new TCanvas();
0088   
0089     char*  rfilename = inputfile;
0090 
0091     delete gROOT->GetListOfFiles()->FindObject(rfilename);
0092 
0093     TFile * rfile = new TFile(rfilename);
0094     if(!rfile->cd("/DQMData/EcalDigisV/EcalDigiTask")){
0095       if(!rfile->cd("/DQMData/EcalDigiTask")){
0096         cout << "DQM plot directory not found in file " << rfilename << endl;
0097         if(!rfile->cd("/DQMData")){
0098           return;
0099         }
0100       }
0101     }
0102   
0103     plotAndSave("h2ChOcc", ext, "colz", false, false, 3);//("hChOcc", ext, "colz");
0104     plotAndSave("hEbEMean", ext);
0105     if(sim) plotAndSave("hEbNoZsRecVsSimE", ext, "colz");
0106     if(sim) plotAndSave("hEbNoise", ext, "", true);
0107     if(rec) plotAndSave("hEbRecE", ext, "", true);
0108     if(rec && sim) plotAndSave("hEbRecEHitXtal", ext);
0109     if(rec && sim) plotAndSave("hEbRecVsSimE", ext, "colz");
0110     if(sim) plotAndSave("hEbSimE", ext);
0111     plotAndSave("hEeEMean", ext);
0112     if(rec && sim) plotAndSave("hEeNoZsRecVsSimE", ext, "colz");
0113     if(sim) plotAndSave("hEeNoise", ext);
0114     if(rec) plotAndSave("hEeRecE", ext, "colz");
0115     if(rec && sim) plotAndSave("hEeRecEHitXtal", ext);
0116     if(sim) plotAndSave("hEeRecVsSimE", ext, "colz");
0117     if(sim) plotAndSave("hEeSimE", ext);
0118     plotAndSave("hTp", ext, "", true);
0119     if(etsum) plotAndSave("h2TpVsEtSum", ext, "colz", false, false);
0120     //plotAndSave("hTtFlag", ext, "", true);
0121     if(etsum) plotAndSave("h2TtfVsEtSum", ext, "colz", false, true);
0122     plotAndSave("h2TtfVsTp", ext, "colz", false, true);
0123 
0124     const char* dccVolHists[] = { "hDccVolFromData", "hDccVol", "hDccLiVol", "hDccHiVol" };
0125 
0126     for(unsigned i = 0; i < sizeof(dccVolHists)/sizeof(dccVolHists[0]); ++i){
0127       setAxisRange(hist(dccVolHists[i]), .5, 9.5, 27.5, 44.5, 54.5);
0128     }
0129     plotAndSave("hDccVolFromData", ext); //("vol");
0130     plotAndSave("hDccVol", ext);
0131     plotAndSave("hDccLiVol", ext);
0132     plotAndSave("hDccHiVol", ext);
0133     
0134 
0135     plotAndSave("hVol", ext);   //("volB");
0136     plotAndSave("hVolB", ext);//("volB");
0137     plotAndSave("hVolBHI", ext);//("volBHI");
0138     plotAndSave("hVolBLI", ext); //("volBLI");
0139     plotAndSave("hVolE", ext);//("volE");
0140     plotAndSave("hVolEHI", ext);//("volEHI");
0141     plotAndSave("hVolELI", ext);//("volELI");
0142     plotAndSave("hVolHI", ext);//("volHI");
0143     plotAndSave("hVolLI", ext);//("volLI");
0144   
0145     plotAndSave("h2Zs1Ru", ext, "colz", false, false, 1);
0146 
0147     plotAndSave("h2FRORu", ext, "colz", false, true, 1);
0148     plotAndSave("h2HiTtf", ext, "colz", false, true, 2);
0149     plotAndSave("h2LiTtf", ext, "colz", false, true, 2);
0150     plotAndSave("h2MiTtf", ext, "colz", false, true, 2);
0151     plotAndSave("h2ForcedTtf", ext, "colz", false, false, 2);
0152     plotAndSave("h2Tp", ext, "colz", false, true, 2);
0153     plotAndSave("hTtf", ext, "", true);
0154 
0155 
0156     plotAndSave("hCompleteZSMap", ext, "colz", false, true, 1);
0157     plotAndSave("hCompleteZSRate", ext, "colz", false, true, 1);
0158 
0159     hist("hCompleteZsCnt")->GetXaxis()->SetRangeUser(0,20);
0160     plotAndSave("hCompleteZsCnt", ext);
0161 
0162     hist("hDroppedFROCnt")->GetXaxis()->SetRangeUser(0,10);
0163     plotAndSave("hDroppedFROCnt", ext);
0164 
0165     plotAndSave("hDroppedFROMap", ext, "colz", false, true, 1);
0166     plotAndSave("hDroppedFRORateMap", ext, "colz", false, true, 1);
0167     plotAndSave("hEbEMean", ext);
0168     plotAndSave("hEbFROCnt", ext);
0169 
0170 
0171     plotAndSave("hEeFROCnt", ext, "", true);
0172     plotAndSave("hFROCnt", ext);
0173     plotAndSave("hIncompleteFROMap", ext, "colz", false, true, 1);
0174     plotAndSave("hIncompleteFRORateMap", ext, "colz", false, true, 1);
0175     plotAndSave("hSRAlgoErrorMap", ext, "colz", false, false, 1);
0176 
0177 
0178     plotAndSave("hEbZsErrCnt", ext, "", false, false, 0, true);
0179     plotAndSave("hEbZsErrType1Cnt", ext, "", false, false, 0, true);
0180     plotAndSave("hEeZsErrCnt", ext, "", false, false, 0, true);
0181     plotAndSave("hEeZsErrType1Cnt", ext, "", false, false, 0, true);
0182     plotAndSave("hIncompleteFROCnt", ext, "", false, false, 0, true);
0183     plotAndSave("hZsErrCnt", ext, "", false, false, 0, true);
0184     plotAndSave("hZsErrType1Cnt", ext, "", false, false, 0, true);
0185 
0186     plotAndSave("zsEbHiFIRemu", ext);
0187     plotAndSave("zsEbLiFIRemu", ext);
0188     plotAndSave("zsEeHiFIRemu", ext);
0189     plotAndSave("zsEeLiFIRemu", ext);
0190   }
0191 
0192 
0193   TH1* hist(const char* name){
0194     TH1* h = 0;
0195     gDirectory->GetObject(name, h);
0196     if(h==0){
0197       h = h1Dummy;
0198       cout << "Histo " << name << " was not found!" << endl;
0199     }
0200     return h;
0201   }
0202 
0203   bool plotAndSave(const char* name, const char* fileExt = ".gif",
0204                    const char* opt = "", bool logy = false,
0205                    bool logz = false, int map=0, bool logx = false){
0206 
0207     if(!barrel 
0208        && (strncmp(name, "hEb", 3) == 0 || strncmp(name, "zsEb", 4) ==0)) return false;
0209 
0210     if(!endcap 
0211        && (strncmp(name, "hEe", 3) == 0 || strncmp(name, "zsEe", 4) ==0)) return false;
0212 
0213 
0214     int optStat = gStyle->GetOptStat();
0215     double optFontSize = gStyle->GetStatFontSize();
0216   
0217     TH1* h = 0;
0218     gDirectory->GetObject(name, h);
0219     if(h==0){
0220       cout << "Histogram " << name << " not found!" << endl;
0221       return false;
0222     }
0223 
0224     if(strcmp(opt, "colz")==0){
0225       fixcolz();
0226       fixcolzRange(h);
0227       gStyle->SetOptStat(110000);
0228       gStyle->SetStatFontSize(0.02);                       
0229     }
0230     
0231     if(autoLog){
0232       int useLog;
0233       if((h->GetMaximum() > 100*h->GetMinimum(0))){
0234 //          && (h->GetNbinsY() > 1
0235 //              || (h->GetNBinsX() > 1
0236 //                  && h->GetRMS() < h->GetXaxis()->GetBinWidth(1)))){
0237         useLog = 1;
0238       } else{
0239         useLog = 0;
0240       }
0241       if(h->GetNbinsY()>1){//2D histo
0242         gPad->SetLogy(0);
0243         gPad->SetLogz(useLog);
0244       } else{//assumes 1D histo
0245         gPad->SetLogy(useLog);
0246       }
0247     } else{
0248       gPad->SetLogy(logy?1:0);
0249       gPad->SetLogz(logz?1:0);
0250     }
0251     gPad->SetLogx(logx?1:0);
0252 
0253     h->Draw(opt);
0254 
0255     //no statistics box for maps
0256     if(map!=0) h->SetStats(kFALSE);
0257 
0258     if(map==1){
0259       setAxisRange(h, -40, -20.5, 0, 20.5, 40, 20);
0260       ruGrid(mode);
0261     }
0262     if(map==2){
0263       setAxisRange(h, -28.5, -17.5, 0, 17.5, 28.5, 72);
0264       tccGrid(mode);
0265     }
0266     if(map==3){
0267       setAxisRange(h, -200, -100, 0, 100, 200, 100);
0268       xtalGrid(mode);
0269     }
0270 
0271     TProfile* p = dynamic_cast<TProfile*>(h);
0272     if(p){
0273       char* err_opt = (char*) p->GetErrorOption();
0274       if(TString(err_opt).Contains("s", TString::kIgnoreCase)){
0275     TPaveLabel* lb = new TPaveLabel(0.55614, 0.939227, 0.698246, 0.98895, "Bars = spread", "NDC");
0276     lb->SetTextColor(4);
0277     lb->SetFillStyle(0);
0278     lb->Draw();
0279       }
0280     }
0281     
0282     stringstream s;
0283     s << "plots/" << name << fileExt;
0284     gPad->SaveAs(s.str().c_str());
0285 
0286     gStyle->SetOptStat(optStat);
0287     gStyle->SetStatFontSize(optFontSize);
0288   }
0289 
0290   void setAxisRange(TH1* h,
0291                     double xmin,
0292                     double eemEbm,
0293                     double ebmEbp,
0294                     double eepEem,
0295                     double xmax,
0296                     double yEeMax = -1.){
0297     double lb = xmin;
0298     double ub = xmax;
0299     if(!(mode & 1000)) lb = eemEbm;
0300     if(!(mode & 1100)) lb = ebmEbp;
0301     if(!(mode & 1110)) lb = eepEem;
0302     if(!(mode & 1))    ub = eepEem;
0303     if(!(mode & 11))   ub = ebmEbp;
0304     if(!(mode & 111))  ub = eemEbm;
0305 
0306     //to fix
0307     if(mode==110){ lb = eemEbm; }
0308     
0309     if(ub!=lb){
0310       h->GetXaxis()->SetRangeUser(lb, ub);
0311     }
0312     if(!(mode & 110) && yEeMax > 0 && h->GetDimension()>1){
0313       h->GetYaxis()->SetRangeUser(h->GetYaxis()->GetXmin(),
0314                                   yEeMax);
0315     }
0316   }
0317 };