StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StHistUtil.h
1 // $Id: StHistUtil.h,v 2.20 2016/06/13 20:31:11 genevb Exp $
2 // $Log: StHistUtil.h,v $
3 // Revision 2.20 2016/06/13 20:31:11 genevb
4 // Resolve Coverity BUFFER_SIZE_WARNING with careful copy function
5 //
6 // Revision 2.19 2016/06/10 02:55:54 genevb
7 // Coverity: memory leaks, possible null pointer dereferences, over-write character buffers
8 //
9 // Revision 2.18 2014/08/06 11:42:52 jeromel
10 // Suffix on literals need to be space (later gcc compiler makes it an error) - first wave of fixes
11 //
12 // Revision 2.17 2014/02/20 20:16:19 genevb
13 // Adjust dE/dx slope hist range, handle ROOT change for 2D polar plots
14 //
15 // Revision 2.16 2012/01/31 22:14:54 genevb
16 // QA Shift Mode, optimized for AutoQA Browser
17 //
18 // Revision 2.15 2011/05/24 20:50:43 genevb
19 // Allow limited graphics file printing
20 //
21 // Revision 2.14 2011/02/19 02:43:39 genevb
22 // Fix those missing consts
23 //
24 // Revision 2.13 2011/02/19 02:22:18 genevb
25 // Allow for specification of histogram usage by the required detector sets
26 //
27 // Revision 2.12 2011/02/07 20:25:26 genevb
28 // Allow for limiting detectors
29 //
30 // Revision 2.11 2011/01/19 02:05:22 genevb
31 // Allow plain ROOT files with hists, and individual plot generation from 1 file
32 //
33 // Revision 2.10 2010/03/12 07:29:05 genevb
34 // Additional capability for saving images of each pad
35 //
36 // Revision 2.9 2010/01/14 19:29:53 genevb
37 // Fix ROOT quirk with 1 page print, fix string/char conversions, protect LOG calls
38 //
39 // Revision 2.8 2009/01/08 23:40:14 genevb
40 // Introduce analyses with reference histograms
41 //
42 // Revision 2.7 2008/05/28 05:16:06 genevb
43 // Allow summing over (ignoring) histogram prefixes
44 //
45 // Revision 2.6 2007/03/13 18:42:28 genevb
46 // Add Svt list, simplified hlist include files, handle StMultiH2F, store dirName
47 //
48 // Revision 2.5 2006/05/18 16:38:03 genevb
49 // Introduce StHistUtil::GetRunYear()
50 //
51 // Revision 2.4 2006/03/28 21:35:32 genevb
52 // Single page output capability for eps,jpg,png,gif,tiff,etc. [see TPad::Print()]
53 //
54 // Revision 2.3 2006/03/28 01:58:39 genevb
55 // Allow PDF (and other) output formats (was only PostScript)
56 //
57 // Revision 2.2 2002/09/06 02:51:34 genevb
58 // Remove limit on maximum number of histograms that can be copied
59 //
60 // Revision 2.1 2000/08/25 22:06:50 genevb
61 // Added histo descriptor in top right
62 //
63 // Revision 2.0 2000/08/25 15:47:38 genevb
64 // New revision: cleaned up, multiple PS files
65 //
66 //
68 // Histogram Utility methods for use with star makers and bfc output
70 
71 #ifndef STAR_StHistUtil
72 #define STAR_StHistUtil
73 
74 
75 #ifndef ROOT_TH1
76 #include "TH1.h"
77 #endif
78 
79 #ifndef ROOT_TH2
80 #include "TH2.h"
81 #endif
82 
83 #include "TList.h"
84 #include "TString.h"
85 
86 
87 // - if not using the methods of the class, then can just put class TCanvas;
88 // - however, if we are using the methods of TCanvas, then put include "TCanvas.h"
89 class TCanvas;
90 class StMaker;
91 class TPaveLabel;
92 class TPaveText;
93 class TDatime;
94 
95 const int maxPathLen = 1024;
96 
97 class StHistUtil {
98 
99  private:
100  // Data-members to make up the output Canvases and Postscript files
101  TCanvas* m_HistCanvas;
102  TCanvas* m_HistCanvasR;
103  Int_t m_PadColumns; // Number of the columns (TPad's) on the single Canvas
104  Int_t m_PadRows; // Number of the columns (TPad's) on the single Canvas
105  Int_t m_PaperWidth; // Paper size in cm
106  Int_t m_PaperHeight; // Paper size in cm
107  TString m_FirstHistName;
108  TString m_LastHistName;
109  TString m_OutFileName; // Base name of the output file to plot hists out
110  TString m_CurFileName; // Name of the current output file
111  TString m_CurFileNameR; // Name of the current ref output file
112  TString m_OutType; // Output file type
113  Bool_t m_OutMultiPage; // Output file is multipage
114  TString m_OutIndividuals; // Additional output of each pad
115  Bool_t m_QAShiftMode; // For the Offline QA Browser
116  Int_t m_CurPrefix;
117  Int_t m_CurPage;
118  TString m_GlobalTitle; // Title at top of each page of output
119  TPaveLabel* Ltitle;
120  TPaveText* Ldesc;
121  TList* m_ListOfLogY;
122  TList* m_ListOfLogX;
123  TList* m_ListOfPrint;
124  StMaker* m_PntrToMaker;
125  TFile* m_PntrToPlainFile;
126  Int_t maxHistCopy;
127  TH1** newHist;
128  Bool_t debug;
129  Int_t m_RunYear; // Run year
130  Char_t m_dirName[maxPathLen];
131  Bool_t ignorePrefixes;// whether or not to ignore prefixes when combining histograms
132  Int_t numOfPosPrefixes; // number of possible prefixes
133  const Char_t** possiblePrefixes;
134  const Char_t** possibleSuffixes;
135  TString m_Detectors; // List of detectors
136  UInt_t m_PrintMode; // Which output files to print
137  TList* m_ItemsToClear; // List of items to clear at some intervals
138 
139  // For reference analyses:
140  Bool_t m_analMode;
141  Char_t m_refResultsFile[maxPathLen];
142  Char_t m_refOutFile[maxPathLen];
143  TList* m_refCuts;
144  TFile* m_refInFile;
145 
146  protected:
147  virtual void CloseOutFile();
148  virtual TString StripPrefixes(const Char_t* histName, Int_t& prenum, Int_t mode=1);
149  virtual Bool_t CheckOutFile(const Char_t* histName);
150  virtual TList* TrimListByPrefix(TList* dList, const Char_t* withPrefix);
151  virtual TH1* FlipAxes(TH1* hist);
152  virtual void PathCopy(char *destination, const char* source);
153 
154 
155  public:
156  StHistUtil();
157  virtual ~StHistUtil();
158  virtual void Clear();
159  virtual void SetDebug(Bool_t dbg=kTRUE) { debug=dbg; }
160  virtual Bool_t Debug() { return debug; }
161  virtual Int_t DrawHists(const Char_t *dirName="EventQA");
162  virtual Int_t ListHists(const Char_t *dirName="EventQA");
163  virtual TList* FindHists(const Char_t *dirName="EventQA",
164  const Char_t *withPrefix=0);
165  virtual TList* FindHists(TFile* histFile, const Char_t* withPrefix=0);
166  virtual Int_t CopyHists(TList *dirList);
167  virtual Int_t AddHists(TList *dirList, Int_t nHistCopy=-1);
168  virtual void IgnorePrefixes(Bool_t ignore=kTRUE) {ignorePrefixes = ignore;}
169  virtual Int_t PrintInfoHists(TList *dirList, const Char_t *fname="printinfo.out");
170 
171  // Reference analyses:
172  virtual void SetRefAnalysis(const Char_t* refOutFile, const Char_t* refResultsFile,
173  const Char_t* refCutsFile=0, const Char_t* refInFile=0);
174 
175  virtual void SetDefaultLogYList(const Char_t *dirName="EventQA");
176  virtual Int_t AddToLogYList(const Char_t *HistName="");
177  virtual Int_t RemoveFromLogYList(const Char_t *HistName="");
178  virtual Int_t ExamineLogYList();
179 
180  virtual void SetDefaultLogXList(const Char_t *dirName="EventQA");
181  virtual Int_t AddToLogXList(const Char_t *HistName="");
182  virtual Int_t RemoveFromLogXList(const Char_t *HistName="");
183  virtual Int_t ExamineLogXList();
184 
185  virtual void SetDefaultPrintList(const Char_t *dirName="EventQA",
186  const Char_t *analType="FullTable");
187  virtual Int_t AddToPrintList(const Char_t *HistName="");
188  virtual Int_t RemoveFromPrintList(const Char_t *HistName="");
189  virtual Int_t ExaminePrintList();
190 
191  virtual Int_t Overlay1D(Char_t *dirName,Char_t *inHist1,Char_t *inHist2);
192  virtual Int_t Overlay2D(Char_t *dirName,Char_t *inHist1,Char_t *inHist2);
193 
194  virtual Int_t GetRunYear(const Char_t *filename);
195 
196  virtual void SetDetectors(const Char_t *detectors);
197  virtual Bool_t DetectorIn(const Char_t *detector);
198 
199 // Inline methods
200  void SetHistsNamesDraw(const Char_t *firstName="*", const Char_t *lastName="*");
201  void SetZones(Int_t columns=2, Int_t rows=3);
202  // SetPaperSize --> A4 is 20,26 US letter is 20,24
203  void SetPaperSize(Int_t width=20, Int_t height=24);
204 
205  // SetOutFile --> type="ps","pdf","jpg",etc...see TPad::Print()
206  void SetOutFile(const Char_t *fileName="", const Char_t* type=0);
207  void SetPostScriptFile(const Char_t *psFileName="");
208  void SetPDFFile(const Char_t *pdfFileName="");
209 
210  void SetPntrToMaker(StMaker *m1);
211  void SetPntrToPlainFile(TFile *m1);
212  void SetGlobalTitle(const Char_t *globalTitle="");
213  TH1** getNewHist();
214  Int_t getNewHistSize();
215 
216  Int_t GetNumOfPosPrefixes() {return numOfPosPrefixes;}
217  const Char_t* GetPrefix(Int_t n) {return possiblePrefixes[n];}
218  const Char_t* GetSuffix(Int_t n) {return possibleSuffixes[n];}
219 
220 // the following is a ROOT macro that is needed in all ROOT code
221  virtual const char *GetCVS() const
222  {static const char cvs[]="Tag $Name: $ $Id: StHistUtil.h,v 2.20 2016/06/13 20:31:11 genevb Exp $ built " __DATE__ " " __TIME__ ; return cvs;}
223 
224  ClassDef(StHistUtil, 1) //needed for all code that will be used in CINT
225  };
226 
227 inline void StHistUtil::SetHistsNamesDraw(const Char_t *firstName, const Char_t *lastName)
228  { m_FirstHistName = firstName; m_LastHistName = lastName; }
229 
230 inline void StHistUtil::SetZones(Int_t columns, Int_t rows)
231  { m_PadColumns =columns; m_PadRows = rows;}
232 
233 inline void StHistUtil::SetPaperSize(Int_t width, Int_t height)
234  { m_PaperWidth = width; m_PaperHeight = height;}
235 
236 inline void StHistUtil::SetPostScriptFile(const Char_t *psFileName)
237  { SetOutFile(psFileName,"ps"); }
238 
239 inline void StHistUtil::SetPDFFile(const Char_t *pdfFileName)
240  { SetOutFile(pdfFileName,"pdf"); }
241 
242 inline void StHistUtil::SetPntrToMaker(StMaker *m1)
243  {m_PntrToMaker = m1;}
244 
245 inline void StHistUtil::SetPntrToPlainFile(TFile *m1)
246  {m_PntrToPlainFile = m1;}
247 
248 inline void StHistUtil::SetGlobalTitle(const Char_t *globalTitle)
249  { m_GlobalTitle = globalTitle;}
250 
251 inline TH1** StHistUtil::getNewHist()
252  {return newHist;}
253 
254 inline Int_t StHistUtil::getNewHistSize()
255  {return maxHistCopy; }
256 
257 
258 class StHistUtilRef : public TNamed {
259  public:
260  StHistUtilRef(const char* name, const char* opts, const int mode, const double cut);
261  int Mode;
262  double Cut;
263  virtual const char* Options() { return GetTitle(); }
264  ClassDef(StHistUtilRef,1) //needed for all code that will be used in CINT
265 };
266 
267 #endif
Definition: Cut.h:18