Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:26

0001 void check_SiPixelCondObjects(){
0002 
0003  
0004   do_check("histos_HLT.root","histos_HLT_startup.root","HLT");
0005   do_check("histos_Offline.root","histos_Offline_startup.root","Offline");
0006 }
0007 
0008 
0009 void do_check(TString filename_official, TString filename_test,TString sampletype){
0010   
0011   TFile *file_official= new TFile(filename_official,"read");
0012   TFile *file_test= new TFile(filename_test,"read");
0013 
0014   TH1F *gain1_off = (TH1F*)file_official->Get("GainAll"); 
0015 
0016   if(!gain1_off){
0017     std::cout << "Histogram GainAll does not exist in file " << filename_official << std::endl;
0018     return;
0019   }
0020   TString newname1 = gain1_off->GetName();
0021   newname1+="official";
0022   gain1_off->SetName(newname1);
0023   gain1_off->SetTitle("Comparison all gain "+sampletype);
0024   gain1_off->GetXaxis()->SetTitle("gain");
0025   TH1F *gain2_off = (TH1F*)file_official->Get("Summary_Gain");
0026   if(!gain2_off){
0027     std::cout << "Histogram Summary_Gain does not exist in file " << filename_official << std::endl;
0028     return;
0029   }
0030   TString newname2 = gain2_off->GetName();
0031   newname2+="official";
0032   gain2_off->SetName(newname2);
0033   gain2_off->SetTitle("Comparison gain per module "+ sampletype);
0034   gain2_off->GetXaxis()->SetTitle("arbitrary module number");
0035   gain2_off->GetYaxis()->SetTitle("gain");
0036   TH1F *gain1_test = (TH1F*)file_test->Get("GainAll");
0037   if(!gain1_test){
0038     std::cout << "Histogram GainAll does not exist in file " << filename_test << std::endl;
0039     return;
0040   }
0041   TH1F *gain2_test = (TH1F*)file_test->Get("Summary_Gain");
0042   if(!gain2_test){
0043     std::cout << "Histogram Summary_Gain does not exist in file " << filename_test << std::endl;
0044     return;
0045   }
0046     
0047   TH1F *pedestal1_off = (TH1F*)file_official->Get("PedestalsAll"); 
0048   if(!pedestal1_off){
0049     std::cout << "Histogram PedestalsAll does not exist in file " << filename_official << std::endl;
0050     return;
0051   }
0052   TString newname3 = pedestal1_off->GetName();
0053   newname3+="official";
0054   pedestal1_off->SetName(newname3);
0055   pedestal1_off->SetTitle("Comparison all pedestal "+sampletype);
0056   pedestal1_off->GetXaxis()->SetTitle("pedestal");
0057   TH1F *pedestal2_off = (TH1F*)file_official->Get("Summary_Pedestal");
0058   if(!pedestal2_off){
0059     std::cout << "Histogram Summary_Pedestal does not exist in file " << filename_official << std::endl;
0060     return;
0061   }
0062   TString newname4 = pedestal2_off->GetName();
0063   newname4+="official";
0064   pedestal2_off->SetName(newname4);
0065   pedestal2_off->SetTitle("Comparison pedestal per module "+sampletype);
0066   pedestal2_off->GetXaxis()->SetTitle("arbitrary module number");
0067   pedestal2_off->GetYaxis()->SetTitle("pedestal");
0068   TH1F *pedestal1_test = (TH1F*)file_test->Get("PedestalsAll");  
0069   if(!pedestal1_test){
0070     std::cout << "Histogram PedestalsAll does not exist in file " << filename_test << std::endl;
0071     return;
0072   }
0073   TH1F *pedestal2_test = (TH1F*)file_test->Get("Summary_Pedestal");
0074   if(!pedestal2_test){
0075     std::cout << "Histogram Summary_Pedestal does not exist in file " << filename_test << std::endl;
0076     return;
0077   }
0078   // check for dead pixel histos:
0079   bool deadhists_exist=true;
0080   bool deadhists_ref_exist=true;
0081   
0082   TH1F *dead2_off = (TH1F*)file_official->Get("Summary_dead");
0083   TH1F *dead1_off = (TH1F*)file_official->Get("DeadAll");
0084   if(!dead1_off || !dead2_off){
0085     std::cout << "Histogram Summary_Dead/DeadAll does not exist in file " << filename_official << std::endl;
0086     deadhists_exist=false;
0087     deadhists_ref_exist=false;
0088   }
0089   else{
0090     TString newname5 = dead1_off->GetName();
0091     newname5+="official";
0092     TString newname6 = dead2_off->GetName();
0093     newname6+="official";
0094     
0095     dead1_off->SetName(newname5);
0096     dead1_off->SetTitle("Comparison dead fraction all modules "+sampletype);
0097     dead2_off->SetName(newname6);
0098     dead2_off->SetTitle("Comparison dead fraction per module "+sampletype);
0099     dead2_off->GetXaxis()->SetTitle("arbitrary module number");
0100     dead2_off->GetYaxis()->SetTitle("pedestal");
0101   }
0102   
0103   TH1F *dead2_test = (TH1F*)file_test->Get("Summary_dead");
0104   TH1F *dead1_test = (TH1F*)file_test->Get("DeadAll");
0105   if(!dead1_test || !dead2_test){
0106     std::cout << "Histogram Summary_Dead/DeadAll does not exist in file " << filename_test << std::endl;
0107     deadhists_exist=false;
0108   }
0109   else{
0110     TString newname5 = dead1_off->GetName();
0111     newname5+="official";
0112     TString newname6 = dead2_off->GetName();
0113     newname6+="official";
0114     
0115     dead1_off->SetName(newname5);
0116     dead1_off->SetTitle("Comparison dead fraction all modules "+sampletype);
0117     dead2_off->SetName(newname6);
0118     dead2_off->SetTitle("Comparison dead fraction per module "+sampletype);
0119     dead2_off->GetXaxis()->SetTitle("arbitrary module number");
0120     dead2_off->GetYaxis()->SetTitle("pedestal");
0121   }
0122   
0123   
0124    
0125   std::cout << "\n\n******\n" << sampletype << " comparison of the following files:" << std::endl;
0126   std::cout << "* reference:   " << filename_official << std::endl;
0127   std::cout << "* test:        " << filename_test << std::endl;
0128   TCanvas *cv= new TCanvas("comparison"+sampletype,"comparison"+sampletype);
0129   if(deadhists_exist)
0130     cv->Divide(2,3);
0131   else
0132     cv->Divide(2,2);
0133   cv->cd(1);
0134   double res1 = make_plot(gain1_off,gain1_test);
0135   std::cout << "match of " << gain1_off->GetTitle()<<" histograms: " << res1 << std::endl;
0136   cv->cd(2);
0137   double res2 = make_plot(gain2_off,gain2_test);
0138   std::cout << "match of " << gain2_off->GetTitle() << " histograms: " << res2 << std::endl;
0139   cv->cd(3);
0140   double res3 = make_plot(pedestal1_off,pedestal1_test);
0141   std::cout << "match of "<< pedestal1_off->GetTitle() << " histograms: " << res3 << std::endl;
0142   cv->cd(4);
0143   double res4 = make_plot(pedestal2_off,pedestal2_test);
0144   double res5=1;
0145   double res6=1;
0146   if(deadhists_ref_exist){
0147     cv->cd(5);
0148     if(deadhists_exist)
0149       res5=make_plot(dead1_off,dead1_test);
0150     else
0151       dead1_off->Draw();
0152     cv->cd(6);
0153     if(deadhists_exist)
0154       res6=make_plot(dead2_off,dead2_test);
0155     else
0156       dead2_off->Draw();
0157   }
0158  
0159   std::cout << "match of "<< pedestal1_off->GetTitle() << " histograms: " << res4 << std::endl;
0160   double compatbg = res1*res2*res3*res4;
0161   std::cout << "TOTAL compatibility: " << compatbg << " (1=completely identical, 0=not compatible at all)" << std::endl; 
0162   TString summaryplotname = filename_official+"_asRefvs_"+filename_test;
0163   summaryplotname.ReplaceAll(".root","");
0164   summaryplotname.ReplaceAll(".","");
0165   summaryplotname.ReplaceAll("/","");
0166   summaryplotname.ReplaceAll("~","");
0167   summaryplotname+=".pdf";
0168   cv->cd();
0169   cv->Update();
0170   cv->Print(summaryplotname);
0171   
0172 }
0173 
0174 double make_plot(TH1F* off, TH1F *test){
0175   if(off->GetSum()>0)
0176     off->Scale((float)test->GetSum()/(float)off->GetSum());
0177   else if (off->GetEntries()>0)
0178     off->Scale((float)test->GetEntries()/(float)off->GetEntries());
0179   if(off->GetMaximum()<test->GetMaximum())
0180     off->SetMaximum(1.3*test->GetMaximum());
0181   else
0182     off->SetMaximum(1.3*off->GetMaximum());
0183   off->SetLineColor(1);
0184   off->SetLineStyle(2);
0185   test->SetLineColor(2);
0186   test->SetMarkerColor(2);
0187   test->SetMarkerStyle(23);
0188   off->Draw("hist");
0189   test->Draw("psame");
0190   off->Draw("histsame");
0191   double kval = off->KolmogorovTest(test);
0192   TString matchstr = "K = ";
0193   matchstr+=kval;
0194   matchstr.ReplaceAll("  "," ");
0195   matchstr.ReplaceAll("  "," ");
0196   matchstr.ReplaceAll("  "," ");
0197 
0198   TLegend *leg = new TLegend(0.4,0.75,0.9,0.9);
0199   leg->SetFillStyle(0);
0200   leg->SetBorderSize(0);
0201   leg->AddEntry(test,"data","lp");
0202   leg->AddEntry(off,"reference","l");
0203   leg->AddEntry("",matchstr,"");
0204   leg->Draw("same");
0205   
0206   return kval;
0207 }
0208 
0209 
0210 
0211