Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:30:56

0001 // prttools - useful functions
0002 // original author: Roman Dzhygadlo - GSI Darmstadt
0003 
0004 #ifndef prttools_h
0005 #define prttools_h 1
0006 
0007 #include "TROOT.h"
0008 #include "TSystem.h"
0009 #include "TStyle.h"
0010 #include "TCanvas.h"
0011 #include "TPad.h"
0012 #include "TH1.h"
0013 #include "TH2.h"
0014 #include "TGraph.h"
0015 #include "TMultiGraph.h"
0016 #include "TSpline.h"
0017 #include "TF1.h"
0018 #include "TFile.h"
0019 #include "TTree.h"
0020 #include "TClonesArray.h"
0021 #include "TVector3.h"
0022 #include "TMath.h"
0023 #include "TChain.h"
0024 #include "TGaxis.h"
0025 #include "TColor.h"
0026 #include "TString.h"
0027 #include "TArrayD.h"
0028 //#include "TSpectrum.h"
0029 //#include "TSpectrum2.h"
0030 #include "Math/Minimizer.h"
0031 #include "Math/Factory.h"
0032 #include "Math/Functor.h"
0033 #include "TRandom2.h"
0034 #include "TError.h"
0035 #include "TPaveStats.h"
0036 #include "TObjString.h"
0037 #include "TApplication.h"
0038 #include <TLegend.h>
0039 #include <TAxis.h>
0040 #include <TPaletteAxis.h>
0041 #include <TRandom.h>
0042 #include <TCutG.h>
0043 #include <TKey.h>
0044 #include "TPRegexp.h"
0045 #include "TFitResult.h"
0046 
0047 #include <iostream>
0048 #include <fstream>
0049 #include <sstream>
0050 
0051 using std::array;
0052 
0053 class PrtTools {
0054 
0055  public:
0056   PrtTools();
0057   PrtTools(TString in);
0058   ~PrtTools() {}
0059   void init();
0060 
0061   bool init_run(TString in = "", int bdigi = 0, TString savepath = "", int setupid = 2019);
0062   void init_digi();
0063   TCanvas *draw_digi(double maxz = 0, double minz = 0, TCanvas *cdigi = NULL);
0064   TString pix_digi(TString header = "m,p,v\n");
0065   bool next(int i, int printstep = 1000);
0066   bool next();
0067   int get_pid(int pdg);
0068   void fill_digi(int pmt, int pix);
0069   
0070   void set_palette(int p = 1);
0071   void create_maps(int setupid = 2019);
0072   TString get_inpath();
0073   TString get_outpath();
0074   TString get_lutpath();  
0075   TString rand_str(int len = 10);
0076   TVector3 fit(TH1 *h, double range = 3, double threshold = 20, double limit = 2,
0077                int peakSearch = 1, int bkg = 0, TString opt = "MQ");
0078   TGraph *fit_slices(TH2F *h, double minrange = 0, double maxrange = 0, double fitrange = 1,
0079                      int rebin = 1, int ret = 0);
0080   void style_graph(TGraph *g, int id);
0081   double integral(TH1F *h, double xmin, double xmax);
0082   void normalize(TH1F *h1, TH1F *h2);
0083   void normalize(TH1F *hists[], int size);
0084   void normalize_to(TH1F *hists[], int size, double max = 1);
0085   TGraph *smooth(TGraph *g, int smoothness = 1);
0086   int shift_hist(TH1 *hist, double double_shift);
0087 
0088   TString dir(TString path);
0089   TString create_dir(TString inpath = "");
0090   void write_info(TString filename);
0091   void write_string(TString filename, TString str);
0092   
0093   void set_style();
0094   void set_style(TCanvas *c);
0095   void save(TPad *c= NULL,TString path="", int what=0, int style=0);
0096 
0097 
0098   void add_canvas(TString name="c",int w=800, int h=400);
0099   void add_canvas(TCanvas *c);
0100   TCanvas *get_canvas(TString name="c");
0101   void del_canvas(TString name="c");
0102 
0103   // style = 0 - for web blog
0104   // style = 1 - for talk
0105   // what = 0 - save in png
0106   // what = 1 - save in png, C
0107   // what = 2 - save in png, C, pdf
0108   // what = 3 - save in png, C, pdf, eps
0109   void save_canvas(int what=1, int style=0, bool rm=false);
0110   void save_canvas(TString path, int what=1, int style=0, bool rm=false);
0111   void print_canvas(TPad *c, TString name = "", TString path = "", int what = 0);
0112 
0113   void wait_primitive(TString name, TString prim="");
0114   
0115   // accessors
0116   int pdg(int v) { return _pdg[v]; }
0117   int pid() { return _pid; }
0118   int i( ) { return _iter; }
0119   int entries(){ return _entries;}
0120   double mass(int v) { return _mass[v]; }
0121   int color(int v) { return _color[v]; }
0122   TString name(int v) { return _name[v]; }
0123   TString lname(int v) { return _lname[v]; }
0124   int maxdircch(){ return _maxdircch;}
0125   TH2F *get_digi(int v){ return _hdigi[v];}
0126 
0127   // mutators
0128   void set_path(TString v) { _savepath = v; }
0129 
0130   array<int, 10000> map_pmt{}, map_pix{}, map_row{}, map_col{}, map_tdc{};
0131   array<array<int, 1000>, 100> map_pmtpix{};
0132 
0133  private:
0134   TChain *_chain;
0135   PrtEvent *_event;
0136   TString _dbpath, _savepath;
0137   TString _info;
0138   array<int, 5> _pdg = {11, 13, 211, 321, 2212};
0139   array<double, 5> _mass = {0.000511, 0.1056584, 0.139570, 0.49368, 0.9382723};
0140   array<TString, 5> _name = {"e", "muon", "pion", "kaon", "proton"};
0141   array<TString, 5> _lname = {"e", "#mu", "#pi", "K", "p"};
0142   array<int, 5> _color = {kOrange + 6, kCyan + 1, kBlue + 1, kRed + 1, kRed + 1};
0143 
0144   array<TH2F *, 21> _hdigi{};
0145   int _entries;
0146   int _iter = -1;
0147   int _printstep = 1000;
0148   int _pid;
0149   int _maxch, _maxdircch;
0150   int _npmt, _npix;
0151   int _pmtlayout;
0152   int _nmaxpmt = 28;
0153   int _last_max, _last_maxz, _last_minz;
0154   TF1 *_fgaus;
0155   //TSpectrum *_spectrum;
0156   TList *_canvaslist;
0157 };
0158 
0159 #endif
0160 
0161 
0162