Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:32:19

0001 #include "TF1.h"
0002 #include "TProfile.h"
0003 #include "Validation/DTRecHits/interface/utils.h"
0004 //#include "TLine.h"
0005 void Tutils::drawGFit(TH1 *h1, float min, float max, float minfit, float maxfit) {
0006   setStyle(h1);
0007   static int i = 0;
0008   i++;
0009   // h1->SetGrid(1,1);
0010   // h1->SetGridColor(15);
0011   h1->GetXaxis()->SetRangeUser(min, max);
0012   TString fitName = "g";
0013   fitName += i;
0014   TF1 *g1 = new TF1(fitName.Data(), "gaus", minfit, maxfit);
0015   g1->SetLineColor(2);
0016   g1->SetLineWidth(2);
0017   h1->Fit(g1, "RQ");
0018   h1->Draw();
0019   //   TPaveStats *st =
0020   //   (TPaveStats*)h1->GetListOfFunctions()->FindObject("stats");
0021   //   st->SetX2NDC(0.905);
0022   //   st->SetY2NDC(0.905);
0023 }
0024 void Tutils::setStyle(TH1 *histo) {
0025   mystyle = getStyle("tdr");
0026   histo->GetXaxis()->SetTitleFont(mystyle->GetTitleFont());
0027   histo->GetXaxis()->SetTitleSize(mystyle->GetTitleFontSize());
0028   histo->GetXaxis()->SetLabelFont(mystyle->GetLabelFont());
0029   histo->GetXaxis()->SetLabelSize(mystyle->GetLabelSize());
0030 
0031   histo->GetYaxis()->SetTitleFont(mystyle->GetTitleFont());
0032   histo->GetYaxis()->SetTitleSize(mystyle->GetTitleFontSize());
0033   histo->GetYaxis()->SetLabelFont(mystyle->GetLabelFont());
0034   histo->GetYaxis()->SetLabelSize(mystyle->GetLabelSize());
0035 }
0036 
0037 void Tutils::setStyle(TH2 *histo) {
0038   mystyle = getStyle("tdr");
0039   histo->GetXaxis()->SetTitleFont(mystyle->GetTitleFont());
0040   histo->GetXaxis()->SetTitleSize(mystyle->GetTitleFontSize());
0041   histo->GetXaxis()->SetLabelFont(mystyle->GetLabelFont());
0042   histo->GetXaxis()->SetLabelSize(mystyle->GetLabelSize());
0043 
0044   histo->GetYaxis()->SetTitleFont(mystyle->GetTitleFont());
0045   histo->GetYaxis()->SetTitleSize(mystyle->GetTitleFontSize());
0046   histo->GetYaxis()->SetLabelFont(mystyle->GetLabelFont());
0047   histo->GetYaxis()->SetLabelSize(mystyle->GetLabelSize());
0048 }
0049 
0050 TStyle *Tutils::getStyle(const TString &name) {
0051   TStyle *theStyle;
0052   if (name == "mstyle") {
0053     theStyle = new TStyle("mstyle", "mstyle");
0054     //    theStyle->SetOptStat(0);
0055     theStyle->SetPadBorderMode(0);
0056     theStyle->SetCanvasBorderMode(0);
0057     theStyle->SetPadColor(0);
0058     theStyle->SetCanvasColor(0);
0059     theStyle->SetMarkerStyle(8);
0060     theStyle->SetMarkerSize(0.7);
0061     theStyle->SetStatH(0.3);
0062     theStyle->SetStatW(0.15);
0063     //   theStyle->SetTextFont(132);
0064     //   theStyle->SetTitleFont(132);
0065     theStyle->SetTitleBorderSize(1);
0066     theStyle->SetPalette(1);
0067 
0068   } else if (name == "tdr") {
0069     theStyle = new TStyle("tdrStyle", "Style for P-TDR");
0070 
0071     // For the canvas:
0072     theStyle->SetCanvasBorderMode(0);
0073     theStyle->SetCanvasColor(kWhite);
0074     theStyle->SetCanvasDefH(600);  // Height of canvas
0075     theStyle->SetCanvasDefW(600);  // Width of canvas
0076     theStyle->SetCanvasDefX(0);    // POsition on screen
0077     theStyle->SetCanvasDefY(0);
0078 
0079     // For the Pad:
0080     theStyle->SetPadBorderMode(0);
0081     // theStyle->SetPadBorderSize(Width_t size = 1);
0082     theStyle->SetPadColor(kWhite);
0083     theStyle->SetPadGridX(true);
0084     theStyle->SetPadGridY(true);
0085     theStyle->SetGridColor(0);
0086     theStyle->SetGridStyle(3);
0087     theStyle->SetGridWidth(1);
0088 
0089     // For the frame:
0090     theStyle->SetFrameBorderMode(0);
0091     theStyle->SetFrameBorderSize(1);
0092     theStyle->SetFrameFillColor(0);
0093     theStyle->SetFrameFillStyle(0);
0094     theStyle->SetFrameLineColor(1);
0095     theStyle->SetFrameLineStyle(1);
0096     theStyle->SetFrameLineWidth(1);
0097 
0098     // For the histo:
0099     // theStyle->SetHistFillColor(1);
0100     // theStyle->SetHistFillStyle(0);
0101     theStyle->SetHistLineColor(1);
0102     theStyle->SetHistLineStyle(0);
0103     theStyle->SetHistLineWidth(1);
0104     // theStyle->SetLegoInnerR(Float_t rad = 0.5);
0105     // theStyle->SetNumberContours(Int_t number = 20);
0106 
0107     theStyle->SetEndErrorSize(2);
0108     //     theStyle->SetErrorMarker(20);
0109     theStyle->SetErrorX(0.);
0110 
0111     theStyle->SetMarkerStyle(20);
0112 
0113     // For the fit/function:
0114     theStyle->SetOptFit(1);
0115     theStyle->SetFitFormat("5.4g");
0116     theStyle->SetFuncColor(2);
0117     theStyle->SetFuncStyle(1);
0118     theStyle->SetFuncWidth(1);
0119 
0120     // For the date:
0121     theStyle->SetOptDate(0);
0122     // theStyle->SetDateX(Float_t x = 0.01);
0123     // theStyle->SetDateY(Float_t y = 0.01);
0124 
0125     // For the statistics box:
0126     theStyle->SetOptFile(0);
0127     //     theStyle->SetOptStat(0); // To display the mean and RMS:
0128     //     SetOptStat("mr");
0129     theStyle->SetOptStat(10);
0130     theStyle->SetStatColor(kWhite);
0131     theStyle->SetStatFont(42);
0132     theStyle->SetStatFontSize(0.07);
0133     theStyle->SetStatTextColor(1);
0134     theStyle->SetStatFormat("6.4g");
0135     theStyle->SetStatBorderSize(1);
0136     theStyle->SetStatH(0.3);
0137     theStyle->SetStatW(0.2);
0138     // theStyle->SetStatStyle(Style_t style = 1001);
0139     // theStyle->SetStatX(Float_t x = 0);
0140     // theStyle->SetStatY(Float_t y = 0);
0141 
0142     // Margins:
0143     theStyle->SetPadTopMargin(0.05);
0144     theStyle->SetPadBottomMargin(0.13);
0145     theStyle->SetPadLeftMargin(0.16);
0146     theStyle->SetPadRightMargin(0.02);
0147 
0148     // For the Global title:
0149 
0150     theStyle->SetOptTitle(0);
0151     theStyle->SetTitleFont(42);
0152     theStyle->SetTitleColor(1);
0153     theStyle->SetTitleTextColor(1);
0154     theStyle->SetTitleFillColor(10);
0155     theStyle->SetTitleFontSize(0.05);
0156     // theStyle->SetTitleH(0); // Set the height of the title box
0157     // theStyle->SetTitleW(0); // Set the width of the title box
0158     // theStyle->SetTitleX(0); // Set the position of the title box
0159     // theStyle->SetTitleY(0.985); // Set the position of the title box
0160     // theStyle->SetTitleStyle(Style_t style = 1001);
0161     // theStyle->SetTitleBorderSize(2);
0162 
0163     // For the axis titles:
0164 
0165     theStyle->SetTitleColor(1, "XYZ");
0166     theStyle->SetTitleFont(42, "XYZ");
0167     theStyle->SetTitleSize(0.06, "XYZ");
0168     // theStyle->SetTitleXSize(Float_t size = 0.02); // Another way to set the
0169     // size? theStyle->SetTitleYSize(Float_t size = 0.02);
0170     theStyle->SetTitleXOffset(0.9);
0171     theStyle->SetTitleYOffset(1.25);
0172     // theStyle->SetTitleOffset(1.1, "Y"); // Another way to set the Offset
0173 
0174     // For the axis labels:
0175 
0176     theStyle->SetLabelColor(1, "XYZ");
0177     theStyle->SetLabelFont(42, "XYZ");
0178     theStyle->SetLabelOffset(0.007, "XYZ");
0179     theStyle->SetLabelSize(0.045, "XYZ");
0180 
0181     // For the axis:
0182 
0183     theStyle->SetAxisColor(1, "XYZ");
0184     theStyle->SetStripDecimals(kTRUE);
0185     theStyle->SetTickLength(0.03, "XYZ");
0186     theStyle->SetNdivisions(510, "XYZ");
0187     theStyle->SetPadTickX(1);  // To get tick marks on the opposite side of the frame
0188     theStyle->SetPadTickY(1);
0189 
0190     // Change for log plots:
0191     theStyle->SetOptLogx(0);
0192     theStyle->SetOptLogy(0);
0193     theStyle->SetOptLogz(0);
0194 
0195     // Postscript options:
0196     theStyle->SetPaperSize(20., 20.);
0197     // theStyle->SetLineScalePS(Float_t scale = 3);
0198     // theStyle->SetLineStyleString(Int_t i, const char* text);
0199     // theStyle->SetHeaderPS(const char* header);
0200     // theStyle->SetTitlePS(const char* pstitle);
0201 
0202     // theStyle->SetBarOffset(Float_t baroff = 0.5);
0203     // theStyle->SetBarWidth(Float_t barwidth = 0.5);
0204     // theStyle->SetPaintTextFormat(const char* format = "g");
0205     // theStyle->SetPalette(Int_t ncolors = 0, Int_t* colors = 0);
0206     // theStyle->SetTimeOffset(Double_t toffset);
0207     // theStyle->SetHistMinimumZero(kTRUE);
0208 
0209     //   style->SetOptFit(101);
0210     //   style->SetOptStat(1111111);
0211 
0212   } else {
0213     // Avoid modifying the default style!
0214     theStyle = gStyle;
0215   }
0216   return theStyle;
0217 }
0218 
0219 void Tutils::plotAndProfileX(TH2 *h2, float min, float max, bool profile) {
0220   setStyle(h2);
0221   //  gPad->SetGrid(1,1);
0222   // gStyle->SetGridColor(15);
0223   h2->GetYaxis()->SetRangeUser(min, max);
0224   h2->Draw();
0225   if (profile) {
0226     TProfile *prof = h2->ProfileX();
0227     prof->SetMarkerColor(2);
0228     prof->SetLineColor(2);
0229     prof->Draw("same");
0230   }
0231   // TLine * l = new
0232   // TLine(h2->GetXaxis()->GetXmin(),0,h2->GetXaxis()->GetXmax(),0);
0233   // l->SetLineColor(3);
0234   // l->Draw();
0235 }