Hi Chris,
On Wed, 2007-05-02 at 07:08 +0530, suneel_at_puhep.res.in wrote:
> Dear rooters,
> I want to be a smart coder but now have a very limited knowledge of
> c++ and coding techniques that is why running for help.
> I an interested in plotting few similar two dimensional histograms for a
> very large number of variables .All the histograms are going to have same
> thing along one of the axis(let us take x-axis(pt))Idea is to define the
> other axis as a variable(y) as then I can make a common fill loop.(like
> Fill(pt,y).Then I am left with only specifying value for y and get all
> the histograms.This thing will also need to define one other variable
> which could represent the histograms for different y-variables.
> To provide more clarity of what I am doing I am enclosing following three
> steps.
> 1.Defining histograms
> 2.define the loop which tells for a particular value of y fill which set
> of histograms.
> 3.Common fill.
> I am finding myself clueless in answering "how to code it".
> If some-one could provide me some help or hints regarding this then it
> could be a great help.
I'm not sure exactly what you mean by `... particular value of y fill which set of histograms ...', but I'm going to assume the worst case, which is where you have different quantities you want to put on the Y-axis (say eta, rapidity, m^2, etc):
struct MyHists { typedef std::multimap<int,TH2*> Map_t; typedef Map_t::value_type Elem_t; Map_t fMap; int fNPt; int fMinPt; int fMaxPt; MyHists(int npt, double minpt, double maxpt) : fNPt(npt), fMinPt(minpt), fMaxPt(maxPt) {} virtual ~MyHists() { for (Map_t::iterator i = fMap.begin(); i != fMap.end(); ++i) delete i->second; } TH2* AddHistogram(int type, int nbins, double min, double max) { std::string n(Form("hist_%d_%d", type, fMap.count(type))); TH2* r = new TH2D(n.c_str(), n.c_str(), fNPt, fMinPt, fMaxPt, nbins, min, max); fMap.insert(Elem_t(type, r)); return r; } bool Fill(int type, double pt, double v) { for (Map_t::iterator i = fMap.begin(); i != fMap.end(); ++i) { if (i->first != type) continue; i->second->Fill(pt, v); } } }; void test() { enum { kRapidity, kEta }; TFile f("foo.root", "RECREATE"); MyHists h(100, 0, 100); h->Add(kRapidity, 10, -3, -1); h->Add(kRapidity, 10, -1, 0); h->Add(kRapidity, 10, 0, 5); h->Add(kEta, 10, -3, -1); h->Add(kEta, 10, -1, 0); h->Add(kEta, 10, 0, 5); for (size_t i = 0; i < 10000; i++) { int t = (gRandom->Uniform() > .5 ? kEta : kRapidity); double pt = (gRandom->Exp(30)); double v = gRandom->Gaus(0, 3); h->Fill(t, pt, v); } f.Write(); f.Close(); }
Hope that helped.
Yours,
-- ___ | Christian Holm Christensen |_| | ------------------------------------------------------------- | | Address: Sankt Hansgade 23, 1. th. Phone: (+45) 35 35 96 91 _| DK-2200 Copenhagen N Cell: (+45) 24 61 85 91 _| Denmark Office: (+45) 353 25 404 ____| Email: cholm_at_nbi.dk Web: www.nbi.dk/~cholm | |Received on Thu May 10 2007 - 20:27:52 CEST
This archive was generated by hypermail 2.2.0 : Fri May 11 2007 - 23:50:01 CEST