//______________________________________________________________________________ void drawsparse() { // create a THnSparse and draw it. #ifdef __CINT__ printf("For performance reasons we advise to run \".x drawsparse.C+\"\n"); #endif const Int_t ndims = 8; Int_t bins[ndims] = {10, 10, 5, 30, 10, 4, 18, 12}; Double_t xmin[ndims] = {-5., -10., -1000., -3., 0., 0., 0., 0.}; Double_t xmax[ndims] = {10., 70., 3000., 3., 5., 2., 2., 5.}; THnSparse* hs = new THnSparseD("hs", "Sparse Histogram", ndims, bins, xmin, xmax); // fill it Double_t x[ndims]; for (Long_t i = 0; i < 100000; ++i) { for (Int_t d = 0; d < ndims; ++d) { switch (d) { case 0: x[d] = gRandom->Gaus()*2 + 3.; break; case 1: case 2: case 3: x[d] = (x[d-1]*x[d-1] - 1.5)/1.5 + (0.5*gRandom->Rndm()); break; default: x[d] = sin(gRandom->Gaus()*i/1000.) + 1.; } } hs->Fill(x); } TFile* f = new TFile("drawsparse.root","RECREATE"); TCanvas* canv = new TCanvas("hDrawSparse", "Drawing a sparse hist"); canv->Divide(2); // draw it canv->cd(1); drawsparse_draw(hs); // project it canv->cd(2); TH3D* h3proj = hs->Projection(2, 3, 6); h3proj->SetLineColor(kOrange); h3proj->SetDirectory(0); h3proj->Draw("lego1"); // save everything to a file canv->Write(); hs->Write(); h3proj->Write(); delete f; }
void TTimeHists::Fill(EHist hist) { for (Long_t n = 0; n < fNum; ++n) { NextValues(); if (fgDebug > 1) { printf("%ld: fill %s", n, hist == kHist? (fDim < 4 ? "hist" : "arr") : "sparse"); for (Int_t d = 0; d < fDim; ++d) printf("[%g]", fValue[d]); printf("\n"); } if (hist == kHist) { switch (fDim) { case 1: fHist->Fill(fValue[0]); break; case 2: ((TH2F*)fHist)->Fill(fValue[0], fValue[1]); break; case 3: ((TH3F*)fHist)->Fill(fValue[0], fValue[1], fValue[2]); break; default: fHn->Fill(fValue); break; } } else { fSparse->Fill(fValue); } } }
void doit(bool small) { Int_t blowup = 1; if (!small) blowup = 4; Int_t nbins[] = {10 * blowup, 20 * blowup, 14 * blowup}; Double_t xmin[] = {0., -1., 0.}; Double_t xmax[] = {1., 1., 10.}; THnSparse* sparse = new THnSparseF("sparse" ,"sparse TH3", 3, nbins, xmin, xmax); sparse->Sumw2(); TH3F* h = new TH3F("h", "nonsparse TH3", nbins[0], xmin[0], xmax[0], nbins[1], xmin[1], xmax[1], nbins[2], xmin[2], xmax[2]); h->Sumw2(); for (Int_t entries = 0; entries < 10000; ++entries) { Double_t x[3]; for (Int_t d = 0; d < 3; ++d) // 10% overshoot to tests overflows x[d] = gRandom->Rndm()*(xmax[d]*1.2 - xmin[d]*1.2) + xmin[d]*1.1; sparse->Fill(x); h->Fill(x[0], x[1], x[2]); } CheckFillProjection(h, sparse); CheckProjection1(h, sparse); CheckProjection2(h, sparse); CheckScale(h, sparse); CheckClone(h, sparse); CheckSubtract(h, sparse); CheckDivide(h, sparse); CheckErrors(h, sparse); CheckBinomial(h, sparse); CheckMerge(h, sparse); delete h; delete sparse; }
void UnitTestAliTPCcalibAlignStreamer(const char *fname="/hera/alice/local/benchmark/vAN-20140518/000128503/cpass1/CalibObjects.root"){ // // test streamer of the AliTPCcalibAlign::Streamer // 0.) Read old data part // 1.) Fill part // 2.) Write part // 3.) Read back - consistency check // 4.) Destructor check // 5.) Memory usage print // AliLog::SetClassDebugLevel("AliTPCcalibAlign",1); AliTPCcalibAlign * align=0; Int_t nPoints=1000000; // // 0.) Read old data part // TFile *fin= TFile::Open(fname); if (fin){ AliSysInfo::AddStamp("LoadFile"); align = (AliTPCcalibAlign * )fin->Get("TPCAlign/alignTPC"); AliSysInfo::AddStamp("LoadAlign"); fin->Close(); delete fin; if (align->GetClusterDelta(0)==NULL){ ::Error("UnitTestAliTPCcalibAlignStreamer","Not back compatible class- GetClusterDelta"); align->MakeResidualHistos(); } if (align->GetTrackletDelta(0)==NULL){ ::Error("UnitTestAliTPCcalibAlignStreamer","Not back compatible class- GetTrackletDelta"); align->MakeResidualHistosTracklet(); } }else{ } // // 1.) Fill part test // for (Int_t ipoint=0; ipoint<nPoints; ipoint++){ Double_t xxx[10]={0}; for (Int_t ihis=0; ihis<2; ihis++){ THn* his = align->GetClusterDelta(ihis); for (Int_t iaxis=0; iaxis<his->GetNdimensions(); iaxis++) { xxx[iaxis]=his->GetAxis(iaxis)->GetXmin()+gRandom->Rndm()*(his->GetAxis(iaxis)->GetXmax()-his->GetAxis(iaxis)->GetXmin()); } his->Fill(xxx); } for (Int_t ihis=0; ihis<4; ihis++){ THnSparse* his = align->GetTrackletDelta(ihis); for (Int_t iaxis=0; iaxis<his->GetNdimensions(); iaxis++) { xxx[iaxis]=his->GetAxis(iaxis)->GetXmin()+gRandom->Rndm()*(his->GetAxis(iaxis)->GetXmax()-his->GetAxis(iaxis)->GetXmin()); } his->Fill(xxx); } } AliSysInfo::AddStamp("FillTrees"); // // 2.) Write part // TFile * fout=new TFile("testAliTPCcalibAlignStreamer.root","recreate"); AliSysInfo::AddStamp("WriteAlignStart"); align->Write("alignTPC"); AliSysInfo::AddStamp("WriteAlignEnd"); fout->ls(); fout->Close(); delete fout; // // 3.) Read back - consistency check // fin=new TFile("testAliTPCcalibAlignStreamer.root"); AliTPCcalibAlign * align2 = (AliTPCcalibAlign *)fin->Get("alignTPC"); AliSysInfo::AddStamp("ReadAlign2"); if (align2==NULL){ ::Fatal("UnitTestAliTPCcalibAlignStreamer","Alignemnt not read"); }else{ ::Info("UnitTestAliTPCcalibAlignStreamer","Alignemnt read-OK"); } if (align2->GetClusterDelta(0)==NULL){ ::Fatal("UnitTestAliTPCcalibAlignStreamer","histogram GetClusterDelta(0) not read"); }else{ ::Info("UnitTestAliTPCcalibAlignStreamer","histogram read GetClusterDelta(0) -OK"); } if (align2->GetTrackletDelta(0)==NULL){ ::Fatal("UnitTestAliTPCcalibAlignStreamer","histogram GetTrackletDelta(0)not read"); }else{ ::Info("UnitTestAliTPCcalibAlignStreamer","histogram read GetTrackletDelta(0) -OK"); } if (align2->GetClusterDelta(0)->GetEntries()!=align->GetClusterDelta(0)->GetEntries()){ ::Fatal("UnitTestAliTPCcalibAlignStreamer","histogram with different entries"); }else{ ::Info("UnitTestAliTPCcalibAlignStreamer","histogram cont. GettrackletDelta(0) -OK"); } if (align2->GetTrackletDelta(0)->GetEntries()!=align->GetTrackletDelta(0)->GetEntries()){ ::Fatal("UnitTestAliTPCcalibAlignStreamer","histogram with different entries"); } // // 4.) Destructor check // delete align2; AliSysInfo::AddStamp("deleteAlign2"); delete align; AliSysInfo::AddStamp("deleteAlign"); // // 5.) Memory usage print // TTree * treeSys =AliSysInfo::MakeTree("syswatch.log"); treeSys->Scan("sname:deltaVM:VM:pI.fMemResident","","colsize=30:15:15:20"); }