CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/Validation/DTRecHits/src/utils.cc

Go to the documentation of this file.
00001 #include "Validation/DTRecHits/interface/utils.h"
00002 #include "TF1.h"
00003 #include "TProfile.h"
00004 //#include "TLine.h"
00005 void Tutils::drawGFit(TH1 * h1, float min, float max, float minfit, float maxfit) {
00006   setStyle(h1);
00007   static int i = 0;
00008   i++;
00009   //h1->SetGrid(1,1);
00010   //h1->SetGridColor(15);
00011   h1->GetXaxis()->SetRangeUser(min,max);
00012   TString  fitName = "g";
00013   fitName += i;
00014     TF1* g1 = new TF1(fitName.Data(),"gaus",minfit,maxfit);
00015   g1->SetLineColor(2);
00016   g1->SetLineWidth(2);
00017   h1->Fit(g1,"RQ");
00018   h1->Draw();
00019 //   TPaveStats *st = (TPaveStats*)h1->GetListOfFunctions()->FindObject("stats");
00020 //   st->SetX2NDC(0.905);
00021 //   st->SetY2NDC(0.905);
00022 }
00023 void Tutils::setStyle(TH1 *histo) {
00024   mystyle = getStyle("tdr");
00025   histo->GetXaxis()->SetTitleFont(mystyle->GetTitleFont());
00026   histo->GetXaxis()->SetTitleSize(mystyle->GetTitleFontSize());
00027   histo->GetXaxis()->SetLabelFont(mystyle->GetLabelFont());
00028   histo->GetXaxis()->SetLabelSize(mystyle->GetLabelSize());
00029 
00030   histo->GetYaxis()->SetTitleFont(mystyle->GetTitleFont());
00031   histo->GetYaxis()->SetTitleSize(mystyle->GetTitleFontSize());
00032   histo->GetYaxis()->SetLabelFont(mystyle->GetLabelFont());
00033   histo->GetYaxis()->SetLabelSize(mystyle->GetLabelSize());
00034 }
00035 
00036 void Tutils::setStyle(TH2 *histo) {
00037   mystyle = getStyle("tdr");
00038   histo->GetXaxis()->SetTitleFont(mystyle->GetTitleFont());
00039   histo->GetXaxis()->SetTitleSize(mystyle->GetTitleFontSize());
00040   histo->GetXaxis()->SetLabelFont(mystyle->GetLabelFont());
00041   histo->GetXaxis()->SetLabelSize(mystyle->GetLabelSize());
00042 
00043   histo->GetYaxis()->SetTitleFont(mystyle->GetTitleFont());
00044   histo->GetYaxis()->SetTitleSize(mystyle->GetTitleFontSize());
00045   histo->GetYaxis()->SetLabelFont(mystyle->GetLabelFont());
00046   histo->GetYaxis()->SetLabelSize(mystyle->GetLabelSize());
00047 }
00048 
00049 TStyle * Tutils::getStyle(TString name)
00050 {
00051   TStyle *theStyle;
00052   if ( name == "mstyle" ) {
00053     theStyle = new TStyle("mstyle", "mstyle");
00054     //    theStyle->SetOptStat(0);
00055     theStyle->SetPadBorderMode(0);
00056     theStyle->SetCanvasBorderMode(0);
00057     theStyle->SetPadColor(0);
00058     theStyle->SetCanvasColor(0);
00059     theStyle->SetMarkerStyle(8);
00060     theStyle->SetMarkerSize(0.7);
00061     theStyle->SetStatH(0.3);
00062     theStyle->SetStatW(0.15);
00063     //   theStyle->SetTextFont(132);
00064     //   theStyle->SetTitleFont(132);
00065     theStyle->SetTitleBorderSize(1);
00066     theStyle->SetPalette(1);
00067 
00068   } else if( name == "tdr" ) {
00069     theStyle = new TStyle("tdrStyle","Style for P-TDR");
00070 
00071     // For the canvas:
00072     theStyle->SetCanvasBorderMode(0);
00073     theStyle->SetCanvasColor(kWhite);
00074     theStyle->SetCanvasDefH(600); //Height of canvas
00075     theStyle->SetCanvasDefW(600); //Width of canvas
00076     theStyle->SetCanvasDefX(0);   //POsition on screen
00077     theStyle->SetCanvasDefY(0);
00078 
00079     // For the Pad:
00080     theStyle->SetPadBorderMode(0);
00081     // theStyle->SetPadBorderSize(Width_t size = 1);
00082     theStyle->SetPadColor(kWhite);
00083     theStyle->SetPadGridX(true);
00084     theStyle->SetPadGridY(true);
00085     theStyle->SetGridColor(0);
00086     theStyle->SetGridStyle(3);
00087     theStyle->SetGridWidth(1);
00088 
00089     // For the frame:
00090     theStyle->SetFrameBorderMode(0);
00091     theStyle->SetFrameBorderSize(1);
00092     theStyle->SetFrameFillColor(0);
00093     theStyle->SetFrameFillStyle(0);
00094     theStyle->SetFrameLineColor(1);
00095     theStyle->SetFrameLineStyle(1);
00096     theStyle->SetFrameLineWidth(1);
00097 
00098     // For the histo:
00099     // theStyle->SetHistFillColor(1);
00100     // theStyle->SetHistFillStyle(0);
00101     theStyle->SetHistLineColor(1);
00102     theStyle->SetHistLineStyle(0);
00103     theStyle->SetHistLineWidth(1);
00104     // theStyle->SetLegoInnerR(Float_t rad = 0.5);
00105     // theStyle->SetNumberContours(Int_t number = 20);
00106 
00107     theStyle->SetEndErrorSize(2);
00108 //     theStyle->SetErrorMarker(20);
00109     theStyle->SetErrorX(0.);
00110   
00111     theStyle->SetMarkerStyle(20);
00112 
00113     //For the fit/function:
00114     theStyle->SetOptFit(1);
00115     theStyle->SetFitFormat("5.4g");
00116     theStyle->SetFuncColor(2);
00117     theStyle->SetFuncStyle(1);
00118     theStyle->SetFuncWidth(1);
00119 
00120     //For the date:
00121     theStyle->SetOptDate(0);
00122     // theStyle->SetDateX(Float_t x = 0.01);
00123     // theStyle->SetDateY(Float_t y = 0.01);
00124 
00125     // For the statistics box:
00126     theStyle->SetOptFile(0);
00127 //     theStyle->SetOptStat(0); // To display the mean and RMS:   SetOptStat("mr");
00128     theStyle->SetOptStat(10);
00129     theStyle->SetStatColor(kWhite);
00130     theStyle->SetStatFont(42);
00131     theStyle->SetStatFontSize(0.07);
00132     theStyle->SetStatTextColor(1);
00133     theStyle->SetStatFormat("6.4g");
00134     theStyle->SetStatBorderSize(1);
00135     theStyle->SetStatH(0.3);
00136     theStyle->SetStatW(0.2);
00137     // theStyle->SetStatStyle(Style_t style = 1001);
00138     // theStyle->SetStatX(Float_t x = 0);
00139     // theStyle->SetStatY(Float_t y = 0);
00140 
00141     // Margins:
00142     theStyle->SetPadTopMargin(0.05);
00143     theStyle->SetPadBottomMargin(0.13);
00144     theStyle->SetPadLeftMargin(0.16);
00145     theStyle->SetPadRightMargin(0.02);
00146 
00147     // For the Global title:
00148 
00149     theStyle->SetOptTitle(0);
00150     theStyle->SetTitleFont(42);
00151     theStyle->SetTitleColor(1);
00152     theStyle->SetTitleTextColor(1);
00153     theStyle->SetTitleFillColor(10);
00154     theStyle->SetTitleFontSize(0.05);
00155     // theStyle->SetTitleH(0); // Set the height of the title box
00156     // theStyle->SetTitleW(0); // Set the width of the title box
00157     // theStyle->SetTitleX(0); // Set the position of the title box
00158     // theStyle->SetTitleY(0.985); // Set the position of the title box
00159     // theStyle->SetTitleStyle(Style_t style = 1001);
00160     // theStyle->SetTitleBorderSize(2);
00161 
00162     // For the axis titles:
00163 
00164     theStyle->SetTitleColor(1, "XYZ");
00165     theStyle->SetTitleFont(42, "XYZ");
00166     theStyle->SetTitleSize(0.06, "XYZ");
00167     // theStyle->SetTitleXSize(Float_t size = 0.02); // Another way to set the size?
00168     // theStyle->SetTitleYSize(Float_t size = 0.02);
00169     theStyle->SetTitleXOffset(0.9);
00170     theStyle->SetTitleYOffset(1.25);
00171     // theStyle->SetTitleOffset(1.1, "Y"); // Another way to set the Offset
00172 
00173     // For the axis labels:
00174 
00175     theStyle->SetLabelColor(1, "XYZ");
00176     theStyle->SetLabelFont(42, "XYZ");
00177     theStyle->SetLabelOffset(0.007, "XYZ");
00178     theStyle->SetLabelSize(0.045, "XYZ");
00179 
00180     // For the axis:
00181 
00182     theStyle->SetAxisColor(1, "XYZ");
00183     theStyle->SetStripDecimals(kTRUE);
00184     theStyle->SetTickLength(0.03, "XYZ");
00185     theStyle->SetNdivisions(510, "XYZ");
00186     theStyle->SetPadTickX(1);  // To get tick marks on the opposite side of the frame
00187     theStyle->SetPadTickY(1);
00188 
00189     // Change for log plots:
00190     theStyle->SetOptLogx(0);
00191     theStyle->SetOptLogy(0);
00192     theStyle->SetOptLogz(0);
00193 
00194     // Postscript options:
00195     theStyle->SetPaperSize(20.,20.);
00196     // theStyle->SetLineScalePS(Float_t scale = 3);
00197     // theStyle->SetLineStyleString(Int_t i, const char* text);
00198     // theStyle->SetHeaderPS(const char* header);
00199     // theStyle->SetTitlePS(const char* pstitle);
00200 
00201     // theStyle->SetBarOffset(Float_t baroff = 0.5);
00202     // theStyle->SetBarWidth(Float_t barwidth = 0.5);
00203     // theStyle->SetPaintTextFormat(const char* format = "g");
00204     // theStyle->SetPalette(Int_t ncolors = 0, Int_t* colors = 0);
00205     // theStyle->SetTimeOffset(Double_t toffset);
00206     // theStyle->SetHistMinimumZero(kTRUE);
00207 
00208 
00209     //   style->SetOptFit(101);
00210     //   style->SetOptStat(1111111); 
00211 
00212   } else {
00213     // Avoid modifying the default style!
00214     theStyle = gStyle;
00215   }
00216   return theStyle;
00217 }
00218 
00219 void Tutils::plotAndProfileX (TH2* h2, float min, float max,bool profile) {
00220   setStyle(h2);
00221   //  gPad->SetGrid(1,1);
00222   //gStyle->SetGridColor(15);
00223   h2->GetYaxis()->SetRangeUser(min,max);
00224   h2->Draw();
00225   if (profile) {
00226     TProfile* prof = h2->ProfileX();
00227     prof->SetMarkerColor(2);
00228     prof->SetLineColor(2);
00229     prof->Draw("same");
00230   }
00231   //TLine * l = new TLine(h2->GetXaxis()->GetXmin(),0,h2->GetXaxis()->GetXmax(),0);
00232   //l->SetLineColor(3);
00233   //l->Draw();
00234 }