Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:34:35

0001 void SiTrackerHitsCompareEnergy()
0002 {
0003 
0004  gROOT ->Reset();
0005  gStyle->SetNdivisions(504,"XYZ");
0006  gStyle->SetStatH(0.18);
0007  gStyle->SetStatW(0.35);
0008  
0009  char*  cfilename = "TrackerHitHisto.root"; //current
0010  char*  rfilename = "../TrackerHitHisto.root";  //reference
0011 
0012  delete gROOT->GetListOfFiles()->FindObject(rfilename);
0013  delete gROOT->GetListOfFiles()->FindObject(cfilename); 
0014 
0015  TText* te = new TText();
0016  TFile * rfile = new TFile(rfilename);
0017  TDirectory * rdir=gDirectory; 
0018  TFile * cfile = new TFile(cfilename);
0019  TDirectory * cdir=gDirectory; 
0020 
0021  if(rfile->cd("DQMData/Run 1/TrackerHitsV"))rfile->cd("DQMData/Run 1/TrackerHitsV/Run summary/TrackerHit");
0022  else rfile->cd("DQMData/TrackerHitsV/TrackerHit");
0023  rdir=gDirectory;
0024 
0025  if(cfile->cd("DQMData/Run 1/TrackerHitsV"))cfile->cd("DQMData/Run 1/TrackerHitsV/Run summary/TrackerHit");
0026  else cfile->cd("DQMData/TrackerHitsV/TrackerHit");
0027  cdir=gDirectory; 
0028  
0029   TLegend leg(0.3, 0.83, 0.55, 0.90);
0030  //Get list of Keys from the Reference file.
0031   TList* ref_list = rfile->GetListOfKeys() ;
0032   if (!ref_list) {
0033       std::cout<<"=========>> AutoComaprison:: There is no Keys available in the Reference file."<<std::endl;
0034       exit(1) ;
0035    }
0036 
0037   //Get list of Keys from the New file.
0038   TList* new_list = cfile->GetListOfKeys() ;
0039   if (!new_list) {
0040       std::cout<<"=========>> AutoComaprison:: There is no Keys available in New file."<<std::endl;
0041       exit(1) ;
0042    }
0043 
0044 
0045   //Iterate on the List of Keys of the  Reference file.
0046   TIter     refkey_iter( ref_list) ;
0047   TKey*     ref_key ;
0048   TObject*  ref_obj ;
0049 
0050   char rver[50];
0051   char cver[50];
0052   while ( ref_key = (TKey*) refkey_iter() ) {
0053       ref_obj = ref_key->ReadObj() ;
0054       if (strcmp(ref_obj->IsA()->GetName(),"TObjString")==0) {
0055 
0056          TObjString * rversion = dynamic_cast< TObjString*> (ref_obj);
0057          sprintf(rver, "%s", rversion->GetName());
0058          std::cout<<" Ref. version =" << rver<<std::endl;
0059          break;
0060       }
0061   }
0062 
0063   //Iterate on the List of Keys of the  Reference file.
0064   TIter     newkey_iter( new_list) ;
0065   TKey*     new_key ;
0066   TObject*  new_obj ;
0067   while ( new_key = (TKey*) newkey_iter() ) {
0068       new_obj = new_key->ReadObj() ;
0069       if (strcmp(new_obj->IsA()->GetName(),"TObjString")==0) {
0070 
0071          TObjString * cversion = dynamic_cast< TObjString*> (new_obj);
0072          sprintf(cver, "%s", cversion->GetName());
0073          std::cout<<" Cur version =" << cver<<std::endl;
0074          break;
0075 
0076       }
0077   }
0078 
0079 
0080  ofstream outfile("LowKS_energy_list.dat");
0081 
0082  string statp = "KS prob";
0083  Double_t ks1e[12],ks2e[12],ks3e[12],ks4e[12],ks5e[12],ks6e[12];
0084  
0085  gROOT->ProcessLine(".x HistoCompare.C");
0086  HistoCompare * PV = new HistoCompare();
0087  
0088  Char_t histo[200];
0089  std::strstream buf;
0090  std::string value;
0091  
0092  TH1F * hsum_st = new TH1F("ks_st", "KS summary eloss STRIPS", 22 , -0.05 , 1.05);
0093  TH1F * hsum_px = new TH1F("ks_px", "KS summary eloss PIXELS", 22 , -0.05 , 1.05);
0094  TH1F * hsum_TIB = new TH1F("ks_TIB", "KS summary eloss TIB", 22 , -0.05 , 1.05);
0095  TH1F * hsum_TOB = new TH1F("ks_TOB", "KS summary eloss TOB", 22 , -0.05 , 1.05);
0096  TH1F * hsum_TID = new TH1F("ks_TID", "KS summary eloss TID", 22 , -0.05 , 1.05);
0097  TH1F * hsum_TEC = new TH1F("ks_TEC", "KS summary eloss TEC", 22 , -0.05 , 1.05);
0098  TH1F * hsum_BPIX = new TH1F("ks_BPIX", "KS summary eloss BPIX", 22 , -0.05 , 1.05);
0099  TH1F * hsum_FPIX = new TH1F("ks_FPIX", "KS summary eloss FPIX", 22 , -0.05 , 1.05);
0100 
0101 
0102 // TIB
0103    TCanvas * TIB = new TCanvas("TIB","TIB",600,800);
0104    TIB->Divide(3,4);
0105 
0106    TH1F * ch1e[12];
0107    TH1F * rh1e[12];
0108    
0109    for (Int_t i=0; i<12; i++) {        
0110      sprintf(histo,"TIBHit/Eloss_TIB_%i",i+1);
0111      rh1e[i] = (TH1F*)rdir->Get(histo)->Clone();
0112      ch1e[i] = (TH1F*)cdir->Get(histo)->Clone();
0113       
0114      TIB->cd(i+1);
0115      if (PV->KSok(rh1e[i] , ch1e[i])) {
0116        ks1e[i] = PV->KSCompute(rh1e[i] , ch1e[i] , te );
0117        PV->KSdraw(rh1e[i] , ch1e[i]);
0118        rh1e[i]->Draw("h");      
0119        ch1e[i]->Draw("h same");             
0120        buf<<"KS="<<ks1e[i]<<std::endl;
0121        buf>>value;
0122        te->DrawTextNDC(0.5,0.7, value.c_str());
0123        hsum_TIB->Fill(ks1e[i]);
0124        leg.Clear();
0125        leg.AddEntry(rh1e[i],rver , "l");
0126        leg.AddEntry(ch1e[i],cver , "l");
0127        leg.Draw();
0128 
0129 
0130      }
0131 //     std::cout << " i =" << i << " KS = " << ks1e[i] << std::endl; 
0132      if (ks1e[i] < 0.1) outfile << ch1e[i]->GetName() <<" KS probability = "<< ks1e[i] <<" "<<endl;
0133    }
0134 
0135 // TOB
0136    TCanvas * TOB = new TCanvas("TOB","TOB",600,800);
0137    TOB->Divide(3,4);
0138    
0139    for (Int_t i=0; i<12; i++) {        
0140      sprintf(histo,"TOBHit/Eloss_TOB_%i",i+1);
0141      rh1e[i] = (TH1F*)rdir->Get(histo)->Clone();
0142      ch1e[i] = (TH1F*)cdir->Get(histo)->Clone();
0143       
0144      TOB->cd(i+1);
0145      if (PV->KSok(rh1e[i] , ch1e[i])) {
0146        ks1e[i] = PV->KSCompute(rh1e[i] , ch1e[i] , te );
0147        PV->KSdraw(rh1e[i] , ch1e[i]);
0148        rh1e[i]->Draw("h");      
0149        ch1e[i]->Draw("h same");             
0150        buf<<"KS="<<ks1e[i]<<std::endl;
0151        buf>>value;
0152        te->DrawTextNDC(0.5,0.7, value.c_str());
0153        hsum_TOB->Fill(ks1e[i]);
0154        leg.Clear();
0155        leg.AddEntry(rh1e[i],rver , "l");
0156        leg.AddEntry(ch1e[i],cver , "l");
0157        leg.Draw();
0158 
0159      }
0160      if (ks1e[i] < 0.1) outfile << ch1e[i]->GetName() <<" KS probability = "<< ks1e[i] <<" "<<endl;
0161    }
0162 
0163 // TID
0164    TCanvas * TID = new TCanvas("TID","TID",600,800);
0165    TID->Divide(3,4);
0166    
0167    for (Int_t i=0; i<12; i++) {        
0168      sprintf(histo,"TIDHit/Eloss_TID_%i",i+1);
0169      rh1e[i] = (TH1F*)rdir->Get(histo)->Clone();
0170      ch1e[i] = (TH1F*)cdir->Get(histo)->Clone();
0171       
0172      TID->cd(i+1);
0173      if (PV->KSok(rh1e[i] , ch1e[i])) {
0174        ks1e[i] = PV->KSCompute(rh1e[i] , ch1e[i] , te );
0175        PV->KSdraw(rh1e[i] , ch1e[i]);
0176        rh1e[i]->Draw("h");      
0177        ch1e[i]->Draw("h same");             
0178        buf<<"KS="<<ks1e[i]<<std::endl;
0179        buf>>value;
0180        te->DrawTextNDC(0.5,0.7, value.c_str());
0181        hsum_TID->Fill(ks1e[i]);
0182        leg.Clear();
0183        leg.AddEntry(rh1e[i],rver , "l");
0184        leg.AddEntry(ch1e[i],cver , "l");
0185        leg.Draw();
0186 
0187      }
0188      if (ks1e[i] < 0.1) outfile << ch1e[i]->GetName() <<" KS probability = "<< ks1e[i] <<" "<<endl;
0189    }
0190 
0191 // TEC
0192    TCanvas * TEC = new TCanvas("TEC","TEC",600,800);
0193    TEC->Divide(3,4);
0194    
0195    for (Int_t i=0; i<12; i++) {        
0196      sprintf(histo,"TECHit/Eloss_TEC_%i",i+1);
0197      rh1e[i] = (TH1F*)rdir->Get(histo)->Clone();
0198      ch1e[i] = (TH1F*)cdir->Get(histo)->Clone();
0199       
0200      TEC->cd(i+1);
0201      if (PV->KSok(rh1e[i] , ch1e[i])) {
0202        ks1e[i] = PV->KSCompute(rh1e[i] , ch1e[i] , te );
0203        PV->KSdraw(rh1e[i] , ch1e[i]);
0204        rh1e[i]->Draw("h");      
0205        ch1e[i]->Draw("h same");             
0206        buf<<"KS="<<ks1e[i]<<std::endl;
0207        buf>>value;
0208        te->DrawTextNDC(0.5,0.7, value.c_str());
0209        hsum_TEC->Fill(ks1e[i]);
0210        leg.Clear();
0211        leg.AddEntry(rh1e[i],rver , "l");
0212        leg.AddEntry(ch1e[i],cver , "l");
0213        leg.Draw();
0214 
0215      }
0216      if (ks1e[i] < 0.1) outfile << ch1e[i]->GetName() <<" KS probability = "<< ks1e[i] <<" "<<endl;
0217    }
0218 
0219 // BPIX
0220    TCanvas * BPIX = new TCanvas("BPIX","BPIX",600,800);
0221    BPIX->Divide(3,4);
0222    
0223    for (Int_t i=0; i<12; i++) {        
0224      sprintf(histo,"BPIXHit/Eloss_BPIX_%i",i+1);
0225      rh1e[i] = (TH1F*)rdir->Get(histo)->Clone();
0226      ch1e[i] = (TH1F*)cdir->Get(histo)->Clone();
0227       
0228      BPIX->cd(i+1);
0229      if (PV->KSok(rh1e[i] , ch1e[i])) {
0230        ks1e[i] = PV->KSCompute(rh1e[i] , ch1e[i] , te );
0231        PV->KSdraw(rh1e[i] , ch1e[i]);
0232        rh1e[i]->Draw("h");      
0233        ch1e[i]->Draw("h same");             
0234        buf<<"KS="<<ks1e[i]<<std::endl;
0235        buf>>value;
0236        te->DrawTextNDC(0.5,0.7, value.c_str());
0237        hsum_BPIX->Fill(ks1e[i]);
0238        leg.Clear();
0239        leg.AddEntry(rh1e[i],rver , "l");
0240        leg.AddEntry(ch1e[i],cver , "l");
0241        leg.Draw();
0242 
0243      }
0244      if (ks1e[i] < 0.1) outfile << ch1e[i]->GetName() <<" KS probability = "<< ks1e[i] <<" "<<endl;
0245    }
0246 
0247 // FPIX
0248    TCanvas * FPIX = new TCanvas("FPIX","FPIX",600,800);
0249    FPIX->Divide(3,4);
0250    
0251    for (Int_t i=0; i<12; i++) {        
0252      sprintf(histo,"FPIXHit/Eloss_FPIX_%i",i+1);
0253      rh1e[i] = (TH1F*)rdir->Get(histo)->Clone();
0254      ch1e[i] = (TH1F*)cdir->Get(histo)->Clone();
0255       
0256      FPIX->cd(i+1);
0257      if (PV->KSok(rh1e[i] , ch1e[i])) {
0258        ks1e[i] = PV->KSCompute(rh1e[i] , ch1e[i] , te );
0259        PV->KSdraw(rh1e[i] , ch1e[i]);
0260        rh1e[i]->Draw("h");      
0261        ch1e[i]->Draw("h same");             
0262        buf<<"KS="<<ks1e[i]<<std::endl;
0263        buf>>value;
0264        te->DrawTextNDC(0.5,0.7, value.c_str());
0265        hsum_FPIX->Fill(ks1e[i]);
0266        leg.Clear();
0267        leg.AddEntry(rh1e[i],rver , "l");
0268        leg.AddEntry(ch1e[i],cver , "l");
0269        leg.Draw();
0270 
0271      }
0272      if (ks1e[i] < 0.1) outfile << ch1e[i]->GetName() <<" KS probability = "<< ks1e[i] <<" "<<endl;
0273    }
0274 
0275  hsum_st -> Add (hsum_TIB);
0276  hsum_st -> Add (hsum_TOB);
0277  hsum_st -> Add (hsum_TID);
0278  hsum_st -> Add (hsum_TEC); 
0279  hsum_px -> Add (hsum_BPIX);
0280  hsum_px -> Add (hsum_FPIX);
0281  
0282  TCanvas * s = new TCanvas("s","s",600,800);
0283  s->Divide(2,4);
0284  
0285  s->cd (1);
0286  hsum_TIB -> Draw();
0287  s->cd (2);
0288  hsum_TOB -> Draw();
0289  s->cd (3);
0290  hsum_TID -> Draw();
0291  s->cd (4);
0292  hsum_TEC -> Draw();
0293  s->cd (5);
0294  hsum_BPIX -> Draw();
0295  s->cd (6);
0296  hsum_FPIX -> Draw();
0297  s->cd (7);
0298  hsum_st -> Draw();
0299  s->cd (8);
0300  hsum_px -> Draw();
0301  
0302  TIB->Print("eloss_TIB_KS.eps");
0303  TOB->Print("eloss_TOB_KS.eps");
0304  TID->Print("eloss_TID_KS.eps");
0305  TEC->Print("eloss_TEC_KS.eps");
0306  BPIX->Print("eloss_BPIX_KS.eps");
0307  FPIX->Print("eloss_FPIX_KS.eps");
0308  s->Print("eloss_summary_KS.eps");  
0309 
0310  TIB->Print("eloss_TIB_KS.gif");
0311  TOB->Print("eloss_TOB_KS.gif");
0312  TID->Print("eloss_TID_KS.gif");
0313  TEC->Print("eloss_TEC_KS.gif");
0314  BPIX->Print("eloss_BPIX_KS.gif");
0315  FPIX->Print("eloss_FPIX_KS.gif");
0316  s->Print("eloss_summary_KS.gif");  
0317 
0318 }