|
| 1 | +///@file |
| 2 | +/// |
| 3 | +/// This code contains the declaration and definition of the class TCmsCanvas |
| 4 | +/// that inherits from a normal TCanvas en ROOT but keep track of created |
| 5 | +/// objects that are not visible to the user, for its proper deletion as the |
| 6 | +/// TCanvas is destroyed. |
| 7 | +/// |
| 8 | +/// <PRE> |
| 9 | +/// Written by O. Gonzalez (2024_11_12) |
| 10 | +/// </PRE> |
| 11 | +/// |
| 12 | + |
| 13 | +#ifndef CMSSTYLE_TCMSCANVAS__H_ |
| 14 | +#define CMSSTYLE_TCMSCANVAS__H_ |
| 15 | + |
| 16 | +#include <TCanvas.h> |
| 17 | +#include <TASImage.h> |
| 18 | + |
| 19 | +#include <vector> |
| 20 | + |
| 21 | +namespace cmsstyle { |
| 22 | + |
| 23 | + |
| 24 | +/// This is the class that CMSStyle (in the C++ version) uses to handle the |
| 25 | +/// TCanvases that are defined to be plotted, but one has to keep in mind that |
| 26 | +/// externally |
| 27 | + |
| 28 | +class TCmsCanvas : public TCanvas { |
| 29 | + |
| 30 | + // Internal variables (pointers to keep track) |
| 31 | + |
| 32 | + TASImage *CMS_logo; ///< CMS Logo when used in the TCanvas. |
| 33 | + TPad *pad_logo; ///< TPad containing the CMS logo, when used. |
| 34 | + |
| 35 | + // Internal methods |
| 36 | + |
| 37 | + /// Initialization of the internal variables... |
| 38 | + void Initialize (void) { |
| 39 | + CMS_logo=nullptr; |
| 40 | + pad_logo=nullptr; |
| 41 | + } |
| 42 | + |
| 43 | +public: |
| 44 | + |
| 45 | + /// Normal constructor: It just creates the Canvas using the arguments and |
| 46 | + /// the corresponding constructor method ot eh TCanvas. It also initializes |
| 47 | + /// the values to keep track of when needed. |
| 48 | + /// |
| 49 | + /// Arguments: |
| 50 | + /// name: Name of the created object |
| 51 | + /// title: Title for the TCanvas |
| 52 | + /// wtopx: X position of the top left corner of the canvas in pixels. |
| 53 | + /// wtopy: Y position of the top left corner of the canvas in pixels |
| 54 | + /// ww: the window size in pixels along X. |
| 55 | + /// wh: the window size in pixels along Y. |
| 56 | + /// |
| 57 | + TCmsCanvas (const char *name, |
| 58 | + const char *title, |
| 59 | + Int_t wtopx, |
| 60 | + Int_t wtopy, |
| 61 | + Int_t ww, |
| 62 | + Int_t wh) : TCanvas(name,title,wtopx,wtopy,ww,wh) { |
| 63 | + Initialize(); |
| 64 | + } |
| 65 | + |
| 66 | + /// Destructor of the class, as the most important object since it handles |
| 67 | + /// the deletion of objects defined |
| 68 | + ~TCmsCanvas () { |
| 69 | + if (CMS_logo!=nullptr) delete CMS_logo; |
| 70 | + if (pad_logo!=nullptr) delete pad_logo; |
| 71 | + } |
| 72 | + |
| 73 | + |
| 74 | + /// Method to draw the CMS Logo in the defined TCanvas in a TPad set at the indicated location |
| 75 | + /// of the currently used TPad. |
| 76 | + void AddCmsLogo (Float_t x0, Float_t y0, Float_t x1, Float_t y1, const char *logofile) |
| 77 | + { |
| 78 | + if (CMS_logo!=nullptr) delete CMS_logo; |
| 79 | + CMS_logo = new TASImage(logofile); |
| 80 | + |
| 81 | + auto oldpad = gPad; |
| 82 | + |
| 83 | + if (pad_logo!=nullptr) delete pad_logo; |
| 84 | + pad_logo = new TPad("logo", "logo", x0, y0, x1, y1); |
| 85 | + pad_logo->Draw(); |
| 86 | + pad_logo->cd(); |
| 87 | + CMS_logo->Draw("X"); |
| 88 | + pad_logo->Modified(); |
| 89 | + |
| 90 | + oldpad->cd(); |
| 91 | + } |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +}; |
| 97 | + |
| 98 | +} // Namespace cmsstyle |
| 99 | +#endif |
| 100 | +///---------------------------------------------------------------------- |
0 commit comments