Back to home page

Project CMSSW displayed by LXR

 
 

    


Warning, /Validation/DTRecHits/test/plotHitEff.r is written in an unsupported language. File is not indexed.

0001 
0002 /*
0003  * Format plots of efficiency produced by DTRecHits validation package.
0004  * The root tree containing the histograms must be already open when 
0005  * executing this macro
0006  * 
0007  * G. Cerminara 2006
0008  */
0009 
0010 class HEff1DHit;
0011 class hEff2DHit;
0012 class hEff4DHit;
0013 
0014 void plotHitEff();
0015 void plotWWWHitEff(TString dirBase = "");
0016 void plot1DEffVsPos(HEff1DHit *hS1, HEff1DHit *hS2, HEff1DHit *hS3, bool ThreeIn1);
0017 void plot1DEffVsEta(HEff1DHit *hS1, HEff1DHit *hS2, HEff1DHit *hS3, bool ThreeIn1);
0018 void plot1DEffVsPhi(HEff1DHit *hS1, HEff1DHit *hS2, HEff1DHit *hS3, bool ThreeIn1);
0019 void plotHisto(TH1F *h1, TH1F *h2, bool ThreeIn1);
0020 
0021 bool setPreferences(bool& do1DRecHit, bool& do2DRecHit, bool& do2DSLPhiRecHit, bool& do4DRecHit, bool& ThreeIn1);
0022 // 
0023 void plotHitEff(){
0024   // Load needed macros and files
0025   gROOT->LoadMacro("macros.C");     // Load service macros
0026   gROOT->LoadMacro("../plugins/Histograms.h"); // Load definition of histograms
0027 
0028   // Get the style
0029   TStyle * style = getStyle();
0030 
0031   //Main switches
0032   bool do1DRecHit = false; 
0033   bool do2DRecHit = false; 
0034   bool do2DSLPhiRecHit = false; 
0035   bool do4DRecHit = false; 
0036   bool ThreeIn1 = false;  // Plot the 3 steps in a single canvas (where appl.)
0037 
0038   //--------------------------------------------------------------------------------------
0039   //-------------------- Set your preferences here ---------------------------------------
0040 
0041   // What plots should be produced:
0042   while(!setPreferences(do1DRecHit, do2DRecHit, do2DSLPhiRecHit, do4DRecHit, ThreeIn1));
0043   //   do1DRecHit = true; 
0044   //   do2DRecHit = true; 
0045   //   do2DSLPhiRecHit = true; 
0046   //   do4DRecHit = true; 
0047 
0048 
0049 
0050   int form = 2;          // Form factor of the canvases (where applicable)
0051                          //       1. For rectangular shape
0052                          //       2. For squared shape
0053 
0054 
0055   // Style options
0056   //  style->SetOptStat("OURMEN");
0057   style->SetOptStat("RME");
0058   style->SetOptFit(101);
0059 
0060   //--------------------------------------------------------------------------------------
0061 
0062   // Check the choice
0063   if(!do1DRecHit && !do2DRecHit && !do2DSLPhiRecHit && !do4DRecHit) {
0064     cout << "[plotHitEff]***Error: Nothing to do! Set do1DRecHit, do2DRecHit, do2DSLPhiRecHit, do4DRecHit correctly!"
0065          << endl;
0066     return;
0067   }
0068   style->cd();                      // Apply style 
0069 
0070   draw(do1DRecHit, do2DRecHit, do2DSLPhiRecHit, do4DRecHit, ThreeIn1, form);
0071 }
0072 
0073 
0074 void plotWWWHitEff(TString dirBase) {
0075   // Load needed macros and files
0076   gROOT->LoadMacro("macros.C");     // Load service macros
0077   gROOT->LoadMacro("../plugins/Histograms.h"); // Load definition of histograms
0078   
0079   // Get the style
0080   TStyle * style = getStyle();
0081   
0082   //Main switches
0083   bool do1DRecHit = true; 
0084   bool do2DRecHit = false; 
0085   bool do2DSLPhiRecHit = false; 
0086   bool do4DRecHit = false; 
0087   bool ThreeIn1 = false;  // Plot the 3 steps in a single canvas (where appl.)
0088 
0089   int form = 2;          // Form factor of the canvases (where applicable)
0090                          //       1. For rectangular shape
0091                          //       2. For squared shape
0092 
0093 
0094   // Style options
0095   //  style->SetOptStat("OURMEN");
0096   style->SetOptStat("RME");
0097   style->SetOptFit(101);
0098 
0099   //--------------------------------------------------------------------------------------
0100 
0101   // Check the choice
0102   if(!do1DRecHit && !do2DRecHit && !do2DSLPhiRecHit && !do4DRecHit) {
0103     cout << "[plotHitReso]***Error: Nothing to do! Set do1DRecHit, do2DRecHit, do2DSLPhiRecHit, do4DRecHit correctly!"
0104          << endl;
0105     return;
0106   }
0107   style->cd();                      // Apply style 
0108 
0109 
0110   draw(do1DRecHit, do2DRecHit, do2DSLPhiRecHit, do4DRecHit, ThreeIn1, form);
0111   cout << "Set the name of the www directory: " << endl;
0112   TString nameS;
0113   cin >> nameS;
0114 
0115   //gSystem->MakeDirectory(dirBase+nameS);
0116   gSystem->ChangeDirectory(dirBase+nameS);
0117 
0118 
0119   printCanvases("gif");
0120 }
0121 
0122 
0123 
0124 void draw(bool do1DRecHit, bool do2DRecHit, bool do2DSLPhiRecHit, bool do4DRecHit, bool ThreeIn1, int form) {
0125   
0126   // Retrieve histogram sets
0127   TFile *f = gROOT->GetListOfFiles()->Last();
0128   cout << "Loading file: " << f->GetName() << endl;
0129 
0130   if(do1DRecHit) {
0131     HEff1DHit *hN_S1RPhi = new HEff1DHit("S1RPhi", f);     // RecHits, 1. step, RPhi
0132     HEff1DHit *hN_S2RPhi = new HEff1DHit("S2RPhi", f);     // RecHits, 2. step, RPhi
0133     HEff1DHit *hN_S3RPhi = new HEff1DHit("S3RPhi", f);     // RecHits, 3. step, RPhi
0134 
0135     HEff1DHit *hN_S1RZ = new HEff1DHit("S1RZ", f);         // RecHits, 1. step, RZ
0136     HEff1DHit *hN_S2RZ = new HEff1DHit("S2RZ", f);          // RecHits, 2. step, RZ
0137     HEff1DHit *hN_S3RZ = new HEff1DHit("S3RZ", f);          // RecHits, 3. step, RZ
0138 
0139     HEff1DHit *hN_S1RZ_W0 = new HEff1DHit("S1RZ_W0", f);   // RecHits, 1. step, RZ, wheel 0
0140     HEff1DHit *hN_S2RZ_W0 = new HEff1DHit("S2RZ_W0", f);   // RecHits, 2. step, RZ, wheel 0
0141     HEff1DHit *hN_S3RZ_W0 = new HEff1DHit("S3RZ_W0", f);   // RecHits, 3. step, RZ, wheel 0
0142 
0143     HEff1DHit *hN_S1RZ_W1 = new HEff1DHit("S1RZ_W1", f);   // RecHits, 1. step, RZ, wheel +-1
0144     HEff1DHit *hN_S2RZ_W1 = new HEff1DHit("S2RZ_W1", f);   // RecHits, 2. step, RZ, wheel +-1
0145     HEff1DHit *hN_S3RZ_W1 = new HEff1DHit("S3RZ_W1", f);   // RecHits, 3. step, RZ, wheel +-1
0146 
0147     HEff1DHit *hN_S1RZ_W2 = new HEff1DHit("S1RZ_W2", f);   // RecHits, 1. step, RZ, wheel +-2
0148     HEff1DHit *hN_S2RZ_W2 = new HEff1DHit("S2RZ_W2", f);   // RecHits, 2. step, RZ, wheel +-2
0149     HEff1DHit *hN_S3RZ_W2 = new HEff1DHit("S3RZ_W2", f);   // RecHits, 3. step, RZ, wheel +-2
0150 
0151   }
0152 
0153   if(do2DRecHit) {
0154     HEff2DHit *h2DHitEff_RPhi = new HEff2DHit("RPhi", f);
0155     HEff2DHit *h2DHitEff_RZ = new HEff2DHit("RZ", f);
0156     HEff2DHit *h2DHitEff_RZ_W0 = new HEff2DHit("RZ_W0", f);
0157     HEff2DHit *h2DHitEff_RZ_W1 = new HEff2DHit("RZ_W1", f);
0158     HEff2DHit *h2DHitEff_RZ_W2 = new HEff2DHit("RZ_W2", f);
0159   }
0160 
0161   if(do2DSLPhiRecHit) {
0162     HEff2DHit *h2DSLPhiHitEff = new HEff2DHit("SuperPhi", f);
0163   }
0164 
0165   if(do4DRecHit) {
0166     HEff4DHit *hEff_All = new HEff4DHit("All", f);
0167     HEff4DHit *hEff_W0 = new  HEff4DHit("W0", f);
0168     HEff4DHit *hEff_W1 = new  HEff4DHit("W1", f);
0169     HEff4DHit *hEff_W2 = new  HEff4DHit("W2", f);
0170   }
0171 
0172 
0173   TCanvas * c1;
0174   int i = 1;
0175 
0176   
0177  eff:
0178 
0179     
0180   if(do1DRecHit) {
0181     plot1DEffVsPos(hN_S1RPhi, hN_S2RPhi, hN_S3RPhi, ThreeIn1);
0182     plot1DEffVsEta(hN_S1RPhi, hN_S2RPhi, hN_S3RPhi, ThreeIn1);
0183     plot1DEffVsPhi(hN_S1RPhi, hN_S2RPhi, hN_S3RPhi, ThreeIn1);
0184 
0185     plot1DEffVsPos(hN_S1RZ, hN_S2RZ, hN_S3RZ, ThreeIn1);
0186     plot1DEffVsEta(hN_S1RZ, hN_S2RZ, hN_S3RZ, ThreeIn1);
0187     plot1DEffVsPhi(hN_S1RZ, hN_S2RZ, hN_S3RZ, ThreeIn1);
0188 
0189     plot1DEffVsPos(hN_S1RZ_W0, hN_S2RZ_W0, hN_S3RZ_W0, ThreeIn1);
0190     plot1DEffVsEta(hN_S1RZ_W0, hN_S2RZ_W0, hN_S3RZ_W0, ThreeIn1);
0191     plot1DEffVsPhi(hN_S1RZ_W0, hN_S2RZ_W0, hN_S3RZ_W0, ThreeIn1);
0192 
0193     plot1DEffVsPos(hN_S1RZ_W1, hN_S2RZ_W1, hN_S3RZ_W1, ThreeIn1);
0194     plot1DEffVsEta(hN_S1RZ_W1, hN_S2RZ_W1, hN_S3RZ_W1, ThreeIn1);
0195     plot1DEffVsPhi(hN_S1RZ_W1, hN_S2RZ_W1, hN_S3RZ_W1, ThreeIn1);
0196 
0197     plot1DEffVsPos(hN_S1RZ_W2, hN_S2RZ_W2, hN_S3RZ_W2, ThreeIn1);
0198     plot1DEffVsEta(hN_S1RZ_W2, hN_S2RZ_W2, hN_S3RZ_W2, ThreeIn1);
0199     plot1DEffVsPhi(hN_S1RZ_W2, hN_S2RZ_W2, hN_S3RZ_W2, ThreeIn1);
0200   }
0201 
0202 
0203   if(do2DRecHit) {
0204     ThreeIn1 = false;
0205     plotHisto(h2DHitEff_RPhi->hEffVsEta, h2DHitEff_RPhi->hEffVsPhi, ThreeIn1);
0206     plotHisto(h2DHitEff_RZ->hEffVsEta, h2DHitEff_RZ->hEffVsPhi, ThreeIn1);
0207     plotHisto(h2DHitEff_RZ_W0->hEffVsEta, h2DHitEff_RZ_W0->hEffVsPhi, ThreeIn1);
0208     plotHisto(h2DHitEff_RZ_W1->hEffVsEta, h2DHitEff_RZ_W1->hEffVsPhi, ThreeIn1);
0209     plotHisto(h2DHitEff_RZ_W2->hEffVsEta, h2DHitEff_RZ_W2->hEffVsPhi, ThreeIn1);
0210 
0211     plotHisto(h2DHitEff_RPhi->hEffVsPos, h2DHitEff_RPhi->hEffVsAngle, ThreeIn1);
0212     plotHisto(h2DHitEff_RZ->hEffVsPos, h2DHitEff_RZ->hEffVsAngle, ThreeIn1);
0213     plotHisto(h2DHitEff_RZ_W0->hEffVsPos, h2DHitEff_RZ_W0->hEffVsAngle, ThreeIn1);
0214     plotHisto(h2DHitEff_RZ_W1->hEffVsPos, h2DHitEff_RZ_W1->hEffVsAngle, ThreeIn1);
0215     plotHisto(h2DHitEff_RZ_W2->hEffVsPos, h2DHitEff_RZ_W2->hEffVsAngle, ThreeIn1);
0216 
0217   }
0218 
0219   if(do2DSLPhiRecHit) {
0220     ThreeIn1 = false;
0221     plotHisto(h2DSLPhiHitEff->hEffVsEta, h2DSLPhiHitEff->hEffVsPhi, ThreeIn1);
0222     plotHisto(h2DSLPhiHitEff->hEffVsPos, h2DSLPhiHitEff->hEffVsAngle, ThreeIn1);
0223  }
0224 
0225   if(do4DRecHit) {
0226     ThreeIn1 = false;
0227     plotHisto(hEff_All->hEffVsEta, hEff_All->hEffVsPhi, ThreeIn1);
0228     plotHisto(hEff_W0->hEffVsEta, hEff_W0->hEffVsPhi, ThreeIn1);
0229     plotHisto(hEff_W1->hEffVsEta, hEff_W1->hEffVsPhi, ThreeIn1);
0230     plotHisto(hEff_W2->hEffVsEta, hEff_W2->hEffVsPhi, ThreeIn1);
0231 
0232     plotHisto(hEff_All->hEffVsX, hEff_All->hEffVsY, ThreeIn1);
0233     plotHisto(hEff_W0->hEffVsX, hEff_W0->hEffVsY, ThreeIn1);
0234     plotHisto(hEff_W1->hEffVsX, hEff_W1->hEffVsY, ThreeIn1);
0235     plotHisto(hEff_W2->hEffVsX, hEff_W2->hEffVsY, ThreeIn1);
0236 
0237     plotHisto(hEff_All->hEffVsAlpha, hEff_All->hEffVsBeta, ThreeIn1);
0238     plotHisto(hEff_W0->hEffVsAlpha, hEff_W0->hEffVsBeta, ThreeIn1);
0239     plotHisto(hEff_W1->hEffVsAlpha, hEff_W1->hEffVsBeta, ThreeIn1);
0240     plotHisto(hEff_W2->hEffVsAlpha, hEff_W2->hEffVsBeta, ThreeIn1);
0241     
0242   }
0243 
0244 
0245 
0246 
0247   return;
0248 
0249  
0250  end:
0251 
0252 }
0253 
0254 
0255 void plot1DEffVsPos(HEff1DHit *hS1, HEff1DHit *hS2, HEff1DHit *hS3, bool ThreeIn1) {
0256   int i = 2;
0257 
0258   TString N1 = "c_1D_" + hS1->name;
0259   TString N2 = "c_1D_" + hS2->name;
0260   TString N3 = "c_1D_" + hS3->name;
0261   int form = 2;
0262   if (ThreeIn1) c1 = newCanvas(N1.Remove(5,2)+"_hEffVsDist",3,1,1200,500);
0263   else newCanvas(N1+"_hEffVsDist",form);
0264   hS1->hEffVsDist->Draw("h");
0265 
0266   if (ThreeIn1) c1->cd(i++);
0267   else c1 = newCanvas(N2+"_hEffVsDist",form);
0268   hS2->hEffVsDist->Draw("h");
0269 
0270   if (ThreeIn1) c1->cd(i++);
0271   else c1 = newCanvas(N3+"_hEffVsDist",form);
0272   hS3->hEffVsDist->Draw("h");
0273 
0274 }
0275 
0276 
0277 void plot1DEffVsEta(HEff1DHit *hS1, HEff1DHit *hS2, HEff1DHit *hS3, bool ThreeIn1) {
0278   int i = 2;
0279 
0280   TString N1 = "c_1D_" + hS1->name;
0281   TString N2 = "c_1D_" + hS2->name;
0282   TString N3 = "c_1D_" + hS3->name;
0283   int form = 2;
0284   if (ThreeIn1) c1 = newCanvas(N1.Remove(5,2)+"_hEffVsEta",3,1,1200,500);
0285   else newCanvas(N1+"_hEffVsEta",form);
0286   hS1->hEffVsEta->Draw("h");
0287 
0288   if (ThreeIn1) c1->cd(i++);
0289   else c1 = newCanvas(N2+"_hEffVsEta",form);
0290   hS2->hEffVsEta->Draw("h");
0291 
0292   if (ThreeIn1) c1->cd(i++);
0293   else c1 = newCanvas(N3+"_hEffVsEta",form);
0294   hS3->hEffVsEta->Draw("h");
0295 
0296 }
0297 
0298 
0299 void plot1DEffVsPhi(HEff1DHit *hS1, HEff1DHit *hS2, HEff1DHit *hS3, bool ThreeIn1) {
0300   int i = 2;
0301 
0302   TString N1 = "c_1D_" + hS1->name;
0303   TString N2 = "c_1D_" + hS2->name;
0304   TString N3 = "c_1D_" + hS3->name;
0305   int form = 2;
0306   if (ThreeIn1) c1 = newCanvas(N1.Remove(5,2)+"_hEffVsPhi",3,1,1200,500);
0307   else newCanvas(N1+"_hEffVsPhi",form);
0308   hS1->hEffVsPhi->Draw("h");
0309 
0310   if (ThreeIn1) c1->cd(i++);
0311   else c1 = newCanvas(N2+"_hEffVsPhi",form);
0312   hS2->hEffVsPhi->Draw("h");
0313 
0314   if (ThreeIn1) c1->cd(i++);
0315   else c1 = newCanvas(N3+"_hEffVsPhi",form);
0316   hS3->hEffVsPhi->Draw("h");
0317 
0318 }
0319 
0320 
0321 void plotHisto(TH1F *h1, TH1F *h2, bool ThreeIn1) {
0322   int i = 2;
0323   
0324   TString N1 = "c_" + TString(h1->GetName());
0325   TString N2 = "c_" + TString(h2->GetName());
0326   int form = 2;
0327   if (ThreeIn1) c1 = newCanvas(N1 ,2,1,800,500);
0328   else newCanvas(N1, form);
0329   h1->Draw("h");
0330 
0331   if (ThreeIn1) c1->cd(i++);
0332   else c1 = newCanvas(N2, form);
0333   h2->Draw("h");
0334 }
0335 
0336 
0337 
0338 
0339 bool setPreferences(bool& do1DRecHit, bool& do2DRecHit, bool& do2DSLPhiRecHit, bool& do4DRecHit, bool& ThreeIn1) {
0340 
0341 
0342 
0343   int dimension = 0;
0344 
0345   cout << "===================================================" << endl;
0346   cout << "==== plotHitEff User Menu =====================" << endl;
0347   cout << "Chose the plot you want to produce:" << endl;
0348   cout << "1 - 1D RecHit Plots" << endl;
0349   cout << "2 - 2D RecHit Plots" << endl;
0350   cout << "3 - 2D RecHit Plots (only SLPhi from 4D RecHit)" << endl;
0351   cout << "4 - 4D RecHit Plots" << endl;
0352   cout << "-->";
0353   cin >> dimension;
0354 
0355   switch(dimension) 
0356     {
0357     case 1:
0358       {
0359         do1DRecHit = true;
0360         break;
0361       }
0362     case 2:
0363       {
0364         do2DRecHit = true;
0365         break;
0366       }
0367     case 3:
0368       {
0369         do2DSLPhiRecHit = true;
0370         break;
0371       }
0372     case 4:
0373       {
0374         do4DRecHit = true;
0375         break;
0376       }
0377     default:
0378       {
0379         cout << "Error: option not Valid, try again!" << endl;
0380         return false;
0381         break;
0382       }
0383     }
0384 
0385   int threeInOne = 0;
0386 
0387   cout << "" << endl;
0388   cout << "Do you want to Plot three histos in one?" << endl;
0389   cout << "0 - No" << endl;
0390   cout << "1 - Yes" << endl;
0391   cout << "-->";
0392 
0393   cin >> threeInOne;
0394 
0395   switch(threeInOne) 
0396     {
0397     case 0:
0398       {
0399         ThreeIn1 = false;
0400         break;
0401       }
0402     case 1:
0403       {
0404         ThreeIn1 = true;
0405         break;
0406       }
0407     default:
0408       {
0409         cout << "Not a valid option: default used!" << endl;    
0410         ThreeIn1 = true;
0411         break;
0412       }
0413     }
0414 
0415   return true;
0416 }
0417