00001
00002
00003
00004
00005
00006
00007
00008
00009 TCanvas *ContourList(){
00010
00011 const Double_t PI = TMath::Pi();
00012
00013 TCanvas* c = new TCanvas("c","Contour List",0,0,600,600);
00014 c->SetRightMargin(0.15);
00015 c->SetTopMargin(0.15);
00016
00017 Int_t i, j, TotalConts;
00018
00019 Int_t nZsamples = 80;
00020 Int_t nPhiSamples = 80;
00021
00022 Double_t HofZwavelength = 4.0;
00023 Double_t dZ = HofZwavelength/(Double_t)(nZsamples - 1);
00024 Double_t dPhi = 2*PI/(Double_t)(nPhiSamples - 1);
00025
00026 TArrayD z(nZsamples);
00027 TArrayD HofZ(nZsamples);
00028 TArrayD phi(nPhiSamples);
00029 TArrayD FofPhi(nPhiSamples);
00030
00031
00032 for ( i = 0; i < nZsamples; i++) {
00033 z[i] = (i)*dZ - HofZwavelength/2.0;
00034 HofZ[i] = SawTooth(z[i], HofZwavelength);
00035 }
00036
00037 for(Int_t i=0; i < nPhiSamples; i++){
00038 phi[i] = (i)*dPhi;
00039 FofPhi[i] = sin(phi[i]);
00040 }
00041
00042
00043 TH2D *HistStreamFn = new TH2D("HstreamFn",
00044 "#splitline{Histogram with negative and positive contents. Six contours are defined.}{It is plotted with options CONT LIST to retrieve the contours points in TGraphs}",
00045 nZsamples, z[0], z[nZsamples-1], nPhiSamples, phi[0], phi[nPhiSamples-1]);
00046
00047
00048 for (Int_t i = 0; i < nZsamples; i++) {
00049 for(Int_t j = 0; j < nPhiSamples; j++){
00050 HistStreamFn->SetBinContent(i,j, HofZ[i]*FofPhi[j]);
00051 }
00052 }
00053
00054 gStyle->SetPalette(1);
00055 gStyle->SetOptStat(0);
00056 gStyle->SetTitleW(0.99);
00057 gStyle->SetTitleH(0.08);
00058
00059 Double_t contours[6];
00060 contours[0] = -0.7;
00061 contours[1] = -0.5;
00062 contours[2] = -0.1;
00063 contours[3] = 0.1;
00064 contours[4] = 0.4;
00065 contours[5] = 0.8;
00066
00067 HistStreamFn->SetContour(6, contours);
00068
00069
00070 HistStreamFn->Draw("CONT Z LIST");
00071 c->Update();
00072
00073
00074 TObjArray *conts = (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours");
00075 TList* contLevel = NULL;
00076 TGraph* curv = NULL;
00077 TGraph* gc = NULL;
00078
00079 Int_t nGraphs = 0;
00080 Int_t TotalConts = 0;
00081
00082 if (conts == NULL){
00083 printf("*** No Contours Were Extracted!\n");
00084 TotalConts = 0;
00085 return;
00086 } else {
00087 TotalConts = conts->GetSize();
00088 }
00089
00090 printf("TotalConts = %d\n", TotalConts);
00091
00092 for(i = 0; i < TotalConts; i++){
00093 contLevel = (TList*)conts->At(i);
00094 printf("Contour %d has %d Graphs\n", i, contLevel->GetSize());
00095 nGraphs += contLevel->GetSize();
00096 }
00097
00098 nGraphs = 0;
00099
00100 TCanvas* c1 = new TCanvas("c1","Contour List",610,0,600,600);
00101 c1->SetTopMargin(0.15);
00102 TH2F *hr = new TH2F("hr",
00103 "#splitline{Negative contours are returned first (highest to lowest). Positive contours are returned from}{lowest to highest. On this plot Negative contours are drawn in red and positive contours in blue.}",
00104 2, -2, 2, 2, 0, 6.5);
00105
00106 hr->Draw();
00107 Double_t x0, y0, z0;
00108 TLatex l;
00109 l.SetTextSize(0.03);
00110 char val[20];
00111
00112 for(i = 0; i < TotalConts; i++){
00113 contLevel = (TList*)conts->At(i);
00114 if (i<3) z0 = contours[2-i];
00115 else z0 = contours[i];
00116 printf("Z-Level Passed in as: Z = %f\n", z0);
00117
00118
00119 curv = (TGraph*)contLevel->First();
00120 for(j = 0; j < contLevel->GetSize(); j++){
00121 curv->GetPoint(0, x0, y0);
00122 if (z0<0) curv->SetLineColor(kRed);
00123 if (z0>0) curv->SetLineColor(kBlue);
00124 nGraphs ++;
00125 printf("\tGraph: %d -- %d Elements\n", nGraphs,curv->GetN());
00126
00127
00128
00129 gc = (TGraph*)curv->Clone();
00130 gc->Draw("C");
00131
00132 sprintf(val,"%g",z0);
00133 l.DrawLatex(x0,y0,val);
00134 curv = (TGraph*)contLevel->After(curv);
00135 }
00136 }
00137 c1->Update();
00138 printf("\n\n\tExtracted %d Contours and %d Graphs \n", TotalConts, nGraphs );
00139 gStyle->SetTitleW(0.);
00140 gStyle->SetTitleH(0.);
00141 return c1;
00142 }
00143
00144
00145 Double_t SawTooth(Double_t x, Double_t WaveLen){
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 Double_t y;
00164 if ( (x < -WaveLen/2) || (x > WaveLen/2)) y = -99999999;
00165 if (x <= -WaveLen/4) {
00166 y = x + 2.0;
00167 } else if ((x > -WaveLen/4) && (x <= WaveLen/4)) {
00168 y = -x ;
00169 } else if (( x > WaveLen/4) && (x <= WaveLen/2)) {
00170 y = x - 2.0;
00171 }
00172 return y;
00173 }