/*************************************************************************** * -------------------------------------------------------------------------- * Template to exercise ROOT Introduction * -> Plot a normalized Gaussian with mean = 5.0 and sigma = 1.5 * and its derivative and integral in the range of 0 to 10 * -------------------------------------------------------------------------- * 13.06.2005, Klaus Rabbertz * * modification log: * kr, 28.06.2006: Removed explicit ex09 naming * as, 06.06.2008: Some small modifications * gq, 16.12.2010: small addition ***************************************************************************/ /* Note that this file can be either used as a compiled program * or as a ROOT macro. * If it is used as a compiled program, additional include statements * and the definition of the main program have to be made. This is * not needed if the code is used as a macro. */ #ifndef __CINT__ // These include-statements are needed if the program is #include "TFile.h" // run as a "stand-alone application", i.e. if it is not #include "TCanvas.h" // called from an interactive ROOT session. #include "TF1.h" #include "TMath.h" #include void gauss(); //______________________________________________________________________________ int main() { gauss(); return 0; } #endif //______________________________________________________________________________ // From here on, the code can also be used as a macro // Note though, that CINT may report errors where there are none // in C++. E.g. this happens here where CINT says that f1 is // out of scope ... // Define a new one-dimensional function of x[0], ngauss, // with two parameters par[0] and par[1] representing the mean // and standard deviation Double_t ngauss(Double_t *x, Double_t *par) { Double_t val = TMath::Pi(); return val; } void gauss() { /* Create a new ROOT binary machine independent file. * Note that this file may contain any kind of ROOT objects, histograms, * pictures, graphics objects, detector geometries, tracks, events, etc.. * But only histograms and trees are written by default. * This file is now becoming the current directory. */ TFile *f1 = new TFile("gauss.root","RECREATE","ROOT_Introduction"); // Create a new canvas and divide it up into 2 x 2 pads TCanvas* c1 = new TCanvas("c1","c1",-700,500); c1->Divide(2,2); // Version 1 // Create a new one-dimensional function myng1 in the limits 0 ... 10 // with two parameters //TF1 *myng1 = new TF1("myng1",ngauss, ... ); // Set the corresponding mean and sigma to 5.0 and 1.5 // Use SetParameters and SetParNames for this // Version 2 // Create a new one-dimensional function myng2 in the limits 0 ... 10 // with the two parameters [0] and [1] //TF1 *myng2 = new TF1("myng2","1/sqrt(2*pi)/[1]*exp((x-[0])/[1])^2)" ? ,...); // Set the corresponding mean and sigma to 5.0 and 1.5 // Use SetParameters and SetParNames for this // Goto first pad and draw function version 1 c1->cd(1); //myng1->Draw(); // Goto second pad and draw function version 2 c1->cd(2); //myng2->Draw(); // Goto third pad and draw derivative of version 1 c1->cd(3); //myng1->Draw???(); // Goto fourth pad and draw integral of version 2 c1->cd(4); //myng2->Draw???(); // Save canvas (by default this is not done!) c1->Write(); // Save other objects (histograms and trees by default) in this file f1->Write(); // Close the file. Note that this is automatically done when you leave // the application. f1->Close(); }