Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 class HRes1DHit;
0003 class HRes2DHit;
0004 class HRes4DHit;
0005 
0006 void plotHitPull();
0007 void draw(bool, bool, bool, bool, bool, bool ThreeInOne);
0008 void plot1DPulls(HRes1DHit * h1, HRes1DHit * h2, HRes1DHit * h3, bool ThreeInOne);
0009 void plot1DPullsVsPos(HRes1DHit * h1, HRes1DHit * h2, HRes1DHit * h3, bool ThreeInOne);
0010 bool setPreferences(bool& doPulls, bool& doPullsVsPos, bool& doPullsCloseWire, bool&, bool&, bool& ThreeIn1) ;
0011 
0012 // This is the main function
0013 void plotHit1DPull(){
0014   // Load needed macros and files
0015   gROOT->LoadMacro("macros.C");     // Load service macros
0016   gROOT->LoadMacro("Histograms.h"); // Load definition of histograms
0017 
0018   // Get the style
0019   TStyle * style = getStyle("tdr");
0020   /// TStyle * style = getStyle();
0021 
0022   // //style->SetOptStat("RME");
0023   // style->SetOptStat(0);
0024   // style->SetOptFit(11);
0025   style->SetFitFormat("4.4g");
0026   // style->SetStatFontSize(0.03);
0027   // style->SetStatColor(0);
0028   style->SetStatY(0.99);
0029   style->SetStatX(0.99);
0030   style->SetTitleYOffset(1.6);
0031   style->SetLabelSize(0.035, "XYZ");
0032   // style->SetStatH(0.3);
0033   // style->SetStatW(0.25);
0034   // // style->SetStatW(0.25);
0035   // // style->SetStatH(0.35);
0036   // style->SetTitleFillColor(0);
0037   // style->SetLabelSize(0.03);
0038 
0039   style->cd();                      // Apply style 
0040 
0041   //Main switches
0042   bool ThreeInOne = true;  // Plot the 3 steps in a single canvas (where appl.)
0043   bool doPulls = false; 
0044   bool doPullsVsPos = false; 
0045   bool doPullsCloseWire = false; 
0046   bool doPullsVsAngle = false; 
0047   bool doPullsVsFE = false; 
0048   // Read user input, namely what plots should be produced
0049   
0050   while(!setPreferences(doPulls, doPullsVsPos, doPullsCloseWire, doPullsVsAngle, doPullsVsFE, ThreeInOne));
0051 
0052   draw(doPulls, doPullsVsPos, doPullsCloseWire, doPullsVsAngle, doPullsVsFE, ThreeInOne);
0053 }
0054 
0055 void draw(bool doPulls, bool doPullsVsPos, bool doPullsCloseWire, bool doPullsVsAngle, bool doPullsVsFE, bool ThreeInOne) {
0056   // Retrieve histogram sets
0057   TFile *f = gROOT->GetListOfFiles()->Last();
0058   if (!f) {
0059     cout << "No file loaded" << endl;
0060     return;
0061   }
0062   cout << "Loading file: " << f->GetName() << endl;
0063 
0064   HRes1DHit *h1RPhi = new HRes1DHit("S1RPhi",f);     // RecHits, 1. step, RPhi
0065   HRes1DHit *h2RPhi = new HRes1DHit("S2RPhi",f);     // RecHits, 2. step, RPhi
0066   HRes1DHit *h3RPhi = new HRes1DHit("S3RPhi",f);     // RecHits, 3. step, RPhi
0067 
0068   HRes1DHit *h1RZ = new HRes1DHit("S1RZ",f);         // RecHits, 1. step, RZ
0069   HRes1DHit *h2RZ = new HRes1DHit("S2RZ",f);        // RecHits, 2. step, RZ
0070   HRes1DHit *h3RZ = new HRes1DHit("S3RZ",f);        // RecHits, 3. step, RZ
0071 
0072   HRes1DHit *h1RZ_W0 = new HRes1DHit("S1RZ_W0",f);   // RecHits, 1. step, RZ, wheel 0
0073   HRes1DHit *h2RZ_W0 = new HRes1DHit("S2RZ_W0",f);   // RecHits, 2. step, RZ, wheel 0
0074   HRes1DHit *h3RZ_W0 = new HRes1DHit("S3RZ_W0",f);   // RecHits, 3. step, RZ, wheel 0
0075 
0076   HRes1DHit *h1RZ_W1 = new HRes1DHit("S1RZ_W1",f);   // RecHits, 1. step, RZ, wheel +-1
0077   HRes1DHit *h2RZ_W1 = new HRes1DHit("S2RZ_W1",f);   // RecHits, 2. step, RZ, wheel +-1
0078   HRes1DHit *h3RZ_W1 = new HRes1DHit("S3RZ_W1",f);   // RecHits, 3. step, RZ, wheel +-1
0079 
0080   HRes1DHit *h1RZ_W2 = new HRes1DHit("S1RZ_W2",f);   // RecHits, 1. step, RZ, wheel +-2
0081   HRes1DHit *h2RZ_W2 = new HRes1DHit("S2RZ_W2",f);   // RecHits, 2. step, RZ, wheel +-2
0082   HRes1DHit *h3RZ_W2 = new HRes1DHit("S3RZ_W2",f);   // RecHits, 3. step, RZ, wheel +-2
0083 
0084   if (doPulls) {
0085     // Pull, Rphi
0086     plot1DPulls(h1RPhi,h2RPhi,h3RPhi,ThreeInOne);
0087 
0088     // Pull, RZ 
0089     plot1DPulls(h1RZ,h2RZ,h3RZ,ThreeInOne);
0090 
0091     // Pull, RZ, per wheel
0092     plot1DPulls(h1RZ_W0,h2RZ_W0,h3RZ_W0,ThreeInOne);
0093     plot1DPulls(h1RZ_W1,h2RZ_W1,h3RZ_W1,ThreeInOne);
0094     plot1DPulls(h1RZ_W2,h2RZ_W2,h3RZ_W2,ThreeInOne);
0095   }
0096 
0097   if (doPullsVsPos){
0098     // Pull, Rphi
0099     plot1DPullsVsPos(h1RPhi,h2RPhi,h3RPhi,ThreeInOne);
0100 
0101     // Pull, RZ 
0102     plot1DPullsVsPos(h1RZ,h2RZ,h3RZ,ThreeInOne);
0103 
0104     // // Pull, RZ, per wheel
0105     // plot1DPullsVsPos(h1RZ_W0,h2RZ_W0,h3RZ_W0,ThreeInOne);
0106     // plot1DPullsVsPos(h1RZ_W1,h2RZ_W1,h3RZ_W1,ThreeInOne);
0107     // plot1DPullsVsPos(h1RZ_W2,h2RZ_W2,h3RZ_W2,ThreeInOne);
0108   }
0109 
0110   if (doPullsCloseWire){
0111     // Pull, Rphi
0112     plot1DPullsCloseWire(h1RPhi,h2RPhi,h3RPhi,ThreeInOne);
0113 
0114     // Pull, RZ 
0115     plot1DPullsCloseWire(h1RZ,h2RZ,h3RZ,ThreeInOne);
0116 
0117     // Pull, RZ, per wheel
0118     plot1DPullsCloseWire(h1RZ_W0,h2RZ_W0,h3RZ_W0,ThreeInOne);
0119     plot1DPullsCloseWire(h1RZ_W1,h2RZ_W1,h3RZ_W1,ThreeInOne);
0120     plot1DPullsCloseWire(h1RZ_W2,h2RZ_W2,h3RZ_W2,ThreeInOne);
0121   }
0122   if (doPullsVsAngle){
0123     // Pull, Rphi
0124     plot1DPullsVsAngle(h1RPhi,h2RPhi,h3RPhi,ThreeInOne);
0125 
0126     // Pull, RZ 
0127     plot1DPullsVsAngle(h1RZ,h2RZ,h3RZ,ThreeInOne);
0128 
0129     // Pull, RZ, per wheel
0130     plot1DPullsVsAngle(h1RZ_W0,h2RZ_W0,h3RZ_W0,ThreeInOne);
0131     plot1DPullsVsAngle(h1RZ_W1,h2RZ_W1,h3RZ_W1,ThreeInOne);
0132     plot1DPullsVsAngle(h1RZ_W2,h2RZ_W2,h3RZ_W2,ThreeInOne);
0133   }
0134 
0135   if (doPullsVsFE){
0136     // Pull, Rphi
0137     plot1DPullsVsFE(h1RPhi,h2RPhi,h3RPhi,ThreeInOne);
0138 
0139     // Pull, RZ 
0140     plot1DPullsVsFE(h1RZ,h2RZ,h3RZ,ThreeInOne);
0141 
0142     // Pull, RZ, per wheel
0143     plot1DPullsVsFE(h1RZ_W0,h2RZ_W0,h3RZ_W0,ThreeInOne);
0144     plot1DPullsVsFE(h1RZ_W1,h2RZ_W1,h3RZ_W1,ThreeInOne);
0145     plot1DPullsVsFE(h1RZ_W2,h2RZ_W2,h3RZ_W2,ThreeInOne);
0146   }
0147 }
0148 
0149 void plot1DPulls(HRes1DHit* h1, HRes1DHit* h2, HRes1DHit* h3, bool ThreeInOne) {
0150   int i = 2;
0151 
0152   if(ThreeInOne)
0153     cout << "ThreeInOne = true!" << endl;
0154   else
0155     cout << "ThreeInOne = false!" << endl;
0156 
0157   TString N1 = "c_1D_" + h1->name;
0158   TString N2 = "c_1D_" + h2->name;
0159   TString N3 = "c_1D_" + h3->name;
0160   int form = 2;
0161   if (ThreeInOne) c1 = newCanvas(N1.Remove(5,2)+"_hPull",3,1,800,400);
0162   else newCanvas(N1+"_hPull",form);
0163   h1->hPull->SetXTitle("(d_{reco}-d_{sim})/#sigma_{reco}");
0164   h1->hPull->SetYTitle("# events");
0165   drawGFit(h1->hPull, -5.,5.,-5.,5.);
0166 
0167   if (ThreeInOne) c1->cd(i++);
0168   else c1 = newCanvas(N2+"_hPull",form);
0169   h2->hPull->SetXTitle("(d_{reco}-d_{sim})/#sigma_{reco}");
0170   h2->hPull->SetYTitle("# events");
0171   drawGFit(h2->hPull,  -5.,5.,-5.,5.);
0172 
0173   if (ThreeInOne) c1->cd(i++);
0174   else c1 = newCanvas(N3+"_hPull",form);
0175   h3->hPull->SetXTitle("(d_{reco}-d_{sim})/#sigma_{reco}");
0176   h3->hPull->SetYTitle("# events");
0177   drawGFit(h3->hPull,  -5.,5.,-5.,5.);
0178 
0179 }
0180 
0181 void plot1DPullsVsPos(HRes1DHit* h1, HRes1DHit* h2, HRes1DHit* h3, bool ThreeInOne) {
0182   int i = 2;
0183 
0184   if(ThreeInOne)
0185     cout << "ThreeInOne = true!" << endl;
0186   else
0187     cout << "ThreeInOne = false!" << endl;
0188 
0189   TString N1 = "c_1D_" + h1->name;
0190   TString N2 = "c_1D_" + h2->name;
0191   TString N3 = "c_1D_" + h3->name;
0192   int form = 2;
0193   if (ThreeInOne) c1 = newCanvas(N1.Remove(5,2)+"_hPullVsPos",3,1,800,400);
0194   else newCanvas(N1+"_hPullVsPos",form);
0195   plotAndProfileXSpread(h1->hPullVsPos,  0.,2.1 ,true);
0196 
0197   if (ThreeInOne) c1->cd(i++);
0198   else c1 = newCanvas(N2+"_hPullVsPos",form);
0199   plotAndProfileXSpread(h2->hPullVsPos, 0.,2.1 ,true);
0200 
0201   if (ThreeInOne) c1->cd(i++);
0202   else c1 = newCanvas(N3+"_hPullVsPos",form);
0203   plotAndProfileXSpread(h3->hPullVsPos, 0.,2.1 ,true);
0204 
0205 }
0206 
0207 void plot1DPullsCloseWire(HRes1DHit* h1, HRes1DHit* h2, HRes1DHit* h3, bool ThreeInOne) {
0208   int i = 2;
0209 
0210   if(ThreeInOne)
0211     cout << "ThreeInOne = true!" << endl;
0212   else
0213     cout << "ThreeInOne = false!" << endl;
0214 
0215   TString N1 = "c_1D_" + h1->name;
0216   TString N2 = "c_1D_" + h2->name;
0217   TString N3 = "c_1D_" + h3->name;
0218   int form = 2;
0219   if (ThreeInOne) c1 = newCanvas(N1.Remove(5,2)+"_hPullVsPos",3,1,800,400);
0220   else newCanvas(N1+"_hPullCloseWire",form);
0221   drawCloseWire(h1->hPullVsPos, 10);
0222 
0223   if (ThreeInOne) c1->cd(i++);
0224   else c1 = newCanvas(N2+"_hPullCloseWire",form);
0225   drawCloseWire(h2->hPullVsPos, 10);
0226 
0227   if (ThreeInOne) c1->cd(i++);
0228   else c1 = newCanvas(N3+"_hPullCloseWire",form);
0229   drawCloseWire(h3->hPullVsPos, 10);
0230 
0231 }
0232 
0233 void drawCloseWire(TH2* h2, int border) {
0234   gPad->SetGrid(1,1);
0235   gStyle->SetGridColor(15);
0236   TH1D* hall= h2->ProjectionY("_all",-1,-1);
0237   TH1D* hclose= h2->ProjectionY("_cl",-1,border);
0238   TH1D* hfar= h2->ProjectionY("_far",border+1,-1);
0239   //hfar->DrawNormalized("",hfar->GetEntries());
0240   hall->DrawCopy();
0241   hfar->SetLineColor(4);
0242   hfar->DrawCopy("same");
0243   //hclose->DrawNormalized("same",hfar->GetEntries()/2.);
0244   hclose->SetLineColor(2);
0245   hclose->DrawCopy("same");
0246 
0247 }
0248 
0249 void plot1DPullsVsAngle(HRes1DHit* h1, HRes1DHit* h2, HRes1DHit* h3, bool ThreeInOne) {
0250   int i = 2;
0251 
0252   TString N1 = "c_1D_" + h1->name;
0253   TString N2 = "c_1D_" + h2->name;
0254   TString N3 = "c_1D_" + h3->name;
0255   int form = 2;
0256   if (ThreeInOne) c1 = newCanvas(N1.Remove(5,2)+"_hPullVsAngle",3,1,800,400);
0257   else newCanvas(N1+"_hPullVsAngle",form);
0258   plotAndProfileXSpread(h1->hPullVsAngle,  0.,2. ,true);
0259 
0260   if (ThreeInOne) c1->cd(i++);
0261   else c1 = newCanvas(N2+"_hPullVsAngle",form);
0262   plotAndProfileXSpread(h2->hPullVsAngle, 0.,2. ,true);
0263 
0264   if (ThreeInOne) c1->cd(i++);
0265   else c1 = newCanvas(N3+"_hPullVsAngle",form);
0266   plotAndProfileXSpread(h3->hPullVsAngle, 0.,2. ,true);
0267 
0268 }
0269 
0270 void plot1DPullsVsFE(HRes1DHit* h1, HRes1DHit* h2, HRes1DHit* h3, bool ThreeInOne) {
0271   int i = 2;
0272 
0273   TString N1 = "c_1D_" + h1->name;
0274   TString N2 = "c_1D_" + h2->name;
0275   TString N3 = "c_1D_" + h3->name;
0276   int form = 2;
0277   if (ThreeInOne) c1 = newCanvas(N1.Remove(5,2)+"_hPullVsDistFE",3,1,800,400);
0278   else newCanvas(N1+"_hPullVsDistFE",form);
0279   plotAndProfileXSpread(h1->hPullVsDistFE,  0.,300. ,true, -5.,5.);
0280 
0281   if (ThreeInOne) c1->cd(i++);
0282   else c1 = newCanvas(N2+"_hPullVsDistFE",form);
0283   plotAndProfileXSpread(h2->hPullVsDistFE, 0.,300. ,true, -5.,5.);
0284 
0285   if (ThreeInOne) c1->cd(i++);
0286   else c1 = newCanvas(N3+"_hPullVsDistFE",form);
0287   plotAndProfileXSpread(h3->hPullVsDistFE, 0.,300. ,true, -5.,5.);
0288 
0289 }
0290 
0291 bool setPreferences(bool& doPulls,
0292                     bool& doPullsVsPos,
0293                     bool& doPullsCloseWire,
0294                     bool& doPullsVsAngle,
0295                     bool& doPullsVsFE,
0296                     bool& ThreeIn1) {
0297 
0298   int dimension = 0;
0299 
0300   cout << "===================================================" << endl;
0301   cout << "==== plotHitReso User Menu =====================" << endl;
0302   cout << "Chose the plot you want to produce:" << endl;
0303   cout << "1 - 1D RecHit Pulls" << endl;
0304   cout << "2 - 1D RecHit Pulls vs Pos" << endl;
0305   cout << "3 - 1D RecHit Pulls close wire" << endl;
0306   cout << "4 - 1D RecHit Pulls vs angle" << endl;
0307   cout << "5 - 1D RecHit Pulls vs FE distance" << endl;
0308   cout << "-->";
0309   cin >> dimension;
0310 
0311   switch(dimension) 
0312   {
0313     case 1:
0314       {
0315         doPulls = true;
0316         break;
0317       }
0318     case 2:
0319       {
0320         doPullsVsPos = true;
0321         break;
0322       }
0323     case 3:
0324       {
0325         doPullsCloseWire = true;
0326         break;
0327       }
0328     case 4:
0329       {
0330         doPullsVsAngle = true;
0331         break;
0332       }
0333     case 5:
0334       {
0335         doPullsVsFE = true;
0336         break;
0337       }
0338     default:
0339       {
0340         cout << "Error: option not Valid, try again!" << endl;
0341         return false;
0342         //setPreferences(do1DRecHit, do2DRecHit, do2DSLPhiRecHit, do4DRecHit, ThreeIn1);
0343         break;
0344       }
0345   }
0346   return true;
0347 
0348   int threeInOne = 0;
0349 
0350   cout << "" << endl;
0351   cout << "Do you want to Plot three histos in one?" << endl;
0352   cout << "0 - No" << endl;
0353   cout << "1 - Yes" << endl;
0354   cout << "-->";
0355 
0356   cin >> threeInOne;
0357 
0358   switch(threeInOne) 
0359   {
0360     case 0:
0361       {
0362         ThreeIn1 = false;
0363         break;
0364       }
0365     case 1:
0366       {
0367         ThreeIn1 = true;
0368         break;
0369       }
0370     default:
0371       {
0372         cout << "Not a valid option: default used!" << endl;    
0373         ThreeIn1 = true;
0374         break;
0375       }
0376   }
0377 
0378   return true;
0379 }