/************************************************************************************* * getKS: Searches through the histograms in the plotter output, adds the MC together * for each field, and compares the MC with the Data histogram using a KS test * input: the main() arguments array * output: writes to stdout the (human-readable) KS statistics of pairs of histograms * * Structure-wise: this is fine, can be implemented into class easily. ***********************************/ void getKS(const char* argv[]) { //open the input TFile TFile *f = new TFile(argv[2]); f->cd(); //get the filesystem information from the file TList *alokDirs = (TList*) f->GetListOfKeys(); //loop through the directories in the input file for(int idir=0; alokDirs->At(idir-1) != alokDirs->Last(); idir++) { TDirectory *cDir = (TDirectory*) f->Get(alokDirs->At(idir)->GetName()); TList *alokHistos = (TList*) cDir->GetListOfKeys(); // create the MC histogram and start collecting relevant MC histograms // from the current directory TList *aloh = new TList; // loop through keys (histograms) in current directory for(int ihisto=0; alokHistos->At(ihisto) != alokHistos->Last(); ihisto++) { if(TString(alokHistos->At(ihisto)->GetName()).Contains("MC8TeV")) { TH1F *cHisto = (TH1F*) cDir->Get(alokHistos->At(ihisto)->GetName()); aloh->Add(cHisto); } } //merge the data histograms into one histogram TH1F *MCHisto = (TH1F*) (aloh->Last())->Clone(TString(cDir->GetName()) + TString("MCHisto")); aloh->RemoveLast(); MCHisto->Merge(aloh); cout<<"-------------------- "<<cDir->GetName()<<" -----------------------"<<endl; //now create the data histogram and run the KS test TH1F *DataHisto = (TH1F*) cDir->Get(alokHistos->Last()->GetName()); cout<<" ---> KS Test: "<<cDir->GetName()<<" has probability "<<MCHisto->KolmogorovTest(DataHisto, "D")<<"\n"<<endl; } }
void cmpLRD(TFile* f1, TFile* f2, const char* dName, const char* patt = 0, unsigned int logmod=0, unsigned int dOpt=1){ // std::cout<<"cmpLRD In "<< dName<<std::endl; TDirectory* td = gROOT->GetDirectory(dName); if (td){ TList* tkl = td->GetListOfKeys(); unsigned int tklSize = tkl->GetEntries(); // std::cout<<"\t size "<<tklSize<<std::endl; for (unsigned int iK=0; iK< tklSize; ++iK){ // std::cout<<"at "<<iK<<"\t " <<tkl->At(iK)->GetName()<<std::endl; if (TClass(((TKey*)tkl->At(iK))->GetClassName()).InheritsFrom("TDirectory")){ TDirectory* tdc = (TDirectory*)((TKey*)tkl->At(iK))->ReadObj(); if (tdc ==0) continue; TString tdcPFull(tdc->GetPath()); TString pRel(tdcPFull.Tokenize(":")->At(1)->GetName()); // std::cout<<tdcPFull.Data()<<std::endl; //now execute compare // if(pRel.Index("/SiStrip/")>=0) continue; //this takes a huge time in alcareco and is irrelevant ///DQMData/Run 1/Btag if (patt==0 || (patt!=0 && pRel.Index(patt)>=0)){ // std::cout<<"Comparing in " <<pRel.Data()<<std::endl; compareInDir(f1, f2, pRel.Data(),logmod,dOpt); } cmpLRD(f1, f2, tdcPFull.Data(), patt,logmod,dOpt); } } } }
TList* extractObjectFromPad(TPad* pad, const char* name) { TList* objects = new TList(); TList* primitivesList = pad->GetListOfPrimitives(); assert(primitivesList); for (int i = 0; i < primitivesList->GetSize(); ++i) { TObject* object = primitivesList->At(i); std::cout << object->ClassName() << ' ' << object->GetName() << std::endl; if (object->InheritsFrom("TPad")) { TList* objectsFromPad = extractObjectFromPad(static_cast<TPad*>(object), name); for (int j = 0; j < objectsFromPad->GetSize(); ++j) objects->Add(objectsFromPad->At(j)); } else if (object->InheritsFrom("THStack")) { TList* hList = (static_cast<THStack*>(object))->GetHists(); for (int j = 0; j < hList->GetSize(); ++j) if (!strcmp(hList->At(j)->GetName(), name)) { objects->Add(hList->At(j)); } } else if (!strcmp(object->GetName(), name)) { std::cout << "--->" << name << std::endl; objects->Add(object); } } return objects; }
double AutoSetYRange(TCanvas& canv, double maxScale) { TList* list = canv.GetListOfPrimitives(); double maximum = 0; int firstHist = -1; // int isCanvasLogY = canv.GetLogy(); for (int iPrims = 0; iPrims <= list->LastIndex(); ++iPrims) { TH1* hist = dynamic_cast<TH1*>(list->At(iPrims)); if (hist) { //Remember histo to set maximum of, which is the first one drawn if (firstHist == -1) { firstHist = iPrims; } if (hist->GetMaximum() > maximum) { maximum = hist->GetMaximum(); } } } if (firstHist != -1) { dynamic_cast<TH1*>(list->At(firstHist))->SetMaximum(maximum * maxScale); return maximum * maxScale; } else { std::cout << __func__ << " No Histograms found" << std::endl; return -1; } }
void dumpToPDF(string inName, string fitName){ TFile *fin = TFile::Open(inName.c_str(), "read"); assert(fin); string outName = inName; outName.replace(outName.find(".root"), 5, ".pdf"); //fitName = "HLT_10LS_delivered_vs_rate_Run190949-191090.root"; TFile *fFit = TFile::Open(fitName.c_str(), "read"); assert(fFit); TCanvas c1; c1.Print(Form("%s[", outName.c_str()), "pdf"); //Open .pdf //get list of keys int nplots = fin->GetNkeys(); int nfits = fFit->GetNkeys(); printf("nplots: %i, nfits: %i\n", nplots, nfits); if(nplots != nfits){ cout<<" PDF output will be wrong since different number of triggers in fit and current run"<<endl; abort(); } TList* plots = fin->GetListOfKeys(); TList* fits = fFit->GetListOfKeys(); for(int i=0; i<nplots; ++i){ TKey* plot = (TKey*) plots->At(i); TKey* fit = (TKey*) fits->At(i);//assume they're in the same order for now if(!fin->GetKey(plot->GetName())){ cout<<"Didn't find "<<plot<<". Removing."<<endl; abort(); } if(!fFit->GetKey(fit->GetName())){ cout<<"Didn't find "<<fit<<". Removing."<<endl; abort(); } TCanvas* c = new TCanvas(); c->Divide(1,2); TCanvas* cPlot = (TCanvas*) fin->Get(plot->GetName()); c->cd(1); cPlot->DrawClonePad(); TCanvas* cFit = (TCanvas*) fFit->Get(fit->GetName()); c->cd(2); cFit->DrawClonePad(); string bookmarkName = "Title: "; bookmarkName += plot->GetName(); c->Print(outName.c_str(), bookmarkName.c_str()); } c1.Print(Form("%s]", outName.c_str()), "pdf"); //Close .pdf }
void Pick(Int_t canvas_index) { TObject *o; TCanvas* c = ((TCanvas*) gROOT->GetListOfCanvases()->At(canvas_index)); c->cd(); // std::cout << "______PICKED______\n\t" // << c->GetName() << " canvas_index=" << canvas_index << std::endl; // ((TCanvas*) gROOT->GetListOfCanvases()->At(canvas_index))->cd(); TList *ll = toolcanvas->GetListOfPrimitives(); // std::cout << ll->GetEntries() << std::endl; for (Int_t ii=ll->GetEntries()-1; ii>=0; ii--) { o = ll->At(ii); // std::cout << ii << " removing " << ll->At(ii)->GetName() << std::endl; ll->Remove(o); } toolcanvas->cd(); toolcanvas->SetWindowSize(toolw-28, toolh-8); // toolcanvas->SetCanvasSize(toolw, toolh); pt->Draw(); toolcanvas->Modified(); toolcanvas->Update(); canvas = ((TCanvas*) gROOT->GetListOfCanvases()->At(canvas_index)); //Enlarge(); SelectPad(); }
void KVClassFactory::AddAllBaseConstructors() { // Add constructors with the same signature as all base class constructors // (apart from the default ctor or any copy constructors, which are a special case) // By default, all constructors are 'public'. if(!fBaseClass) return; KVHashList clist; clist.AddAll(fBaseClass->GetListOfMethods()); KVSeqCollection* constructors = clist.GetSubListWithName(fBaseClassName); TIter next_ctor(constructors); TMethod* method; while( (method = (TMethod*)next_ctor()) ) { if(!method->GetNargs()) continue; // ignore default ctor TList* args = method->GetListOfMethodArgs(); TMethodArg* arg = (TMethodArg*)args->First(); TString typenam=arg->GetFullTypeName(); if(typenam.Contains(fBaseClassName)) continue; // ignore copy ctor KVClassMethod* ctor; if(arg->GetDefault()) ctor = AddConstructor( typenam, arg->GetName(), arg->GetDefault() ); else ctor = AddConstructor(typenam, arg->GetName()); for(int i=1; i<method->GetNargs(); i++){ arg = (TMethodArg*)args->At(i); if(arg->GetDefault()) ctor->AddArgument( arg->GetFullTypeName(), arg->GetName(), arg->GetDefault() ); else ctor->AddArgument(arg->GetFullTypeName(), arg->GetName()); } } delete constructors; }
// Save to .root file void SaveOutput(TString name,TList &list) { TFile *out = new TFile(name,"RECREATE"); TDirectory *pwd = gDirectory; for(int i=0;i<list.GetSize();i++) { TDecayMode *dm = list.At(i); TDirectory *subdir = out->mkdir(dm->GetName()); subdir->cd(); subdir->Append(dm); subdir->Append(dm->histograms); pwd->cd(); } if(!genDesc) cout<<"WARNING! No Generator description in files!"<<endl; else out->Append(genDesc); if(userHisto) { TDecayMode *uh = (TDecayMode*) userHisto; cout<<"INFO: Appending user histograms"<<endl; TDirectoryFile *histos = out->mkdir("USER_HISTOGRAMS"); TIter nexthist(uh->histograms); TKey *key_hist=0; TH1D *h; while(h=(TH1D*)nexthist()) histos->Append(h); } out->Write(); out->Close(); delete out; }
void dominik() { TH1* matHistogramRoman = static_cast<TH1*>(extractObjectFromFile("lyRoman.root", "lightYieldProjectionY")->At(0)); TList* objects = extractObjectFromFile("c.root", "chargeBins"); TH1* matHistogramDominik = new TH1D("matHistogramDominik", ";channel;light yield / pixels", 512, -0.5, 512-0.5); int sipmIt = 0; for (int i = 0; i < objects->GetSize(); ++i) { TH1* h = static_cast<TH1*>(objects->At(i)); if (h->GetLineColor() == 8) { for (int bin = 1; bin <= 128; ++bin) { matHistogramDominik->SetBinContent(512 - (sipmIt * 128 + bin - 1), h->GetBinContent(bin)); if (h->GetBinError(bin) > 0) matHistogramDominik->SetBinError(512 - (sipmIt * 128 + bin - 1), h->GetBinError(bin)); } ++sipmIt; } } TCanvas* c = new TCanvas; c->Divide(1, 2); c->cd(1); matHistogramDominik->Draw(); matHistogramRoman->Draw("SAME"); c->cd(2); TH1* h = static_cast<TH1*>(matHistogramDominik->Clone()); h->Add(matHistogramRoman, -1); h->Draw(); }
TList* contourFromTH2(TH2 *h2in, double threshold) { std::cout << "Getting contour at threshold " << threshold << " from " << h2in->GetName() << std::endl; //http://root.cern.ch/root/html/tutorials/hist/ContourList.C.html Double_t contours[1]; contours[0] = threshold; TH2D *h2 = frameTH2D((TH2D*)h2in); h2->SetContour(1, contours); // Draw contours as filled regions, and Save points h2->Draw("CONT Z LIST"); gPad->Update(); // Needed to force the plotting and retrieve the contours in TGraphs // Get Contours TObjArray *conts = (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours"); TList* contLevel = NULL; if (conts == NULL || conts->GetSize() == 0){ printf("*** No Contours Were Extracted!\n"); return 0; } TList *ret = new TList(); for(int i = 0; i < conts->GetSize(); i++){ contLevel = (TList*)conts->At(i); printf("Contour %d has %d Graphs\n", i, contLevel->GetSize()); for (int j = 0, n = contLevel->GetSize(); j < n; ++j) { TGraph *gr1 = (TGraph*) contLevel->At(j)->Clone(); ret->Add(gr1); } } return ret; }
void rdphi::Terminate() { //cout << "total event: " << NevtAll << "rejected: " << rejected_events << endl; TFile *f = new TFile("output.root","RECREATE"); //Write output Histograms TList *tl = GetOutputList(); int l = tl->GetEntries(); for ( int i = 0 ; i < l ; i++ ) { TObject *o = tl->At(i); if ( o->InheritsFrom("TH1") ) { cout << "TresChorros: Saving Histogram: " << " Class: " << o->ClassName() << " Name: "<< o->GetName() << " Title: " << o->GetTitle() << " " << endl << flush; o->Write(); } } f->Flush(); f->Close(); }
TGraph* getContourFilledX(TH2D* inputHisto, TCanvas* goodCanvas, int Width, int Style, int FillStyle, double X){ TCanvas* c1 = new TCanvas("temp", "temp",600,600); TH2D* histo = (TH2D*)inputHisto->Clone("temp"); double levels[] = {X}; histo->SetContour(1, levels); histo->Draw("CONT LIST"); c1->Update(); TObjArray* contours = (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours"); Int_t ncontours = contours->GetSize(); TList *list = (TList*)contours->At(0); delete c1; goodCanvas->cd(); printf("list size = %i\n", (int)list->GetSize()); if(list->GetSize()<=0)return new TGraph(0); for(unsigned int i=0;i<list->GetSize();i++){ TGraph* EXCLUSION = (TGraph*)(list->At(i)->Clone("copy")); EXCLUSION->SetLineColor(1); EXCLUSION->SetLineWidth(Width); EXCLUSION->SetLineStyle(Style); EXCLUSION->SetFillColor(kBlack); EXCLUSION->SetFillStyle(FillStyle); //EXCLUSION->Draw("CL F same"); } return EXCLUSION; }
//---------- Retrieve data histo ----------------- TH1F* GetData(TFile* fin, string region, string varname) { string cname = CHANNEL_NAME+string("/")+region+"/"+varname; TCanvas* c = (TCanvas*) fin->Get(cname.c_str()); TList* l = c->GetListOfPrimitives(); TPad* pad = (TPad*) l->At(0); string hname = "v:"+varname+"|r:"+region+string("|c:")+CHANNEL_NAME+string("|t:1DSumData"); TH1F* h = (TH1F*) pad->GetPrimitive(hname.c_str()); return (TH1F*) h->Clone(); }
TGraph* ContourGraph( TH2F* hist) { TGraph* gr0 = new TGraph(); TH2F* h = (TH2F*)hist->Clone(); gr = (TGraph*)gr0->Clone(h->GetName()); // cout << "==> Will dumb histogram: " << h->GetName() << " into a graph" <<endl; h->SetContour( 1 ); double pval = CombinationGlob::cl_percent[1]; double signif = TMath::NormQuantile(1-pval); h->SetContourLevel( 0, signif ); h->Draw("CONT LIST"); h->SetDirectory(0); gPad->Update(); TObjArray *contours = gROOT->GetListOfSpecials()->FindObject("contours"); Int_t ncontours = contours->GetSize(); TList *list = (TList*)contours->At(0); Int_t number_of_lists = list->GetSize(); gr = (TGraph*)list->At(0); TGraph* grTmp = new TGraph(); for (int k = 0 ; k<number_of_lists ; k++){ grTmp = (TGraph*)list->At(k); Int_t N = gr->GetN(); Int_t N_tmp = grTmp->GetN(); if(N < N_tmp) gr = grTmp; // mg->Add((TGraph*)list->At(k)); } gr->SetName(hist->GetName()); int N = gr->GetN(); double x0, y0; // for(int j=0; j<N; j++) { // gr->GetPoint(j,x0,y0); // cout << j << " : " << x0 << " : "<<y0 << endl; // } // // gr->SetMarkerSize(2.0); // gr->SetMarkerSize(2.0); // gr->SetMarkerStyle(21); // gr->Draw("LP"); // cout << "Generated graph " << gr << " with name " << gr->GetName() << endl; return gr; }
void MakeCutLog(const char *inputRootFile = "AnalysisResults",const char *path = "./", const char* outputDir="./Output/"){ fstream outputFile(Form("%sCutSelection.log",outputDir),ios::out); if(!outputFile.is_open()){ cout<<"Problem opening file"<<endl; return; } // Char_t filename_input1[200] = (Form("%s%s",path,input1)); TString filename = Form("%s%s.root",path,inputRootFile); TFile f(filename.Data()); TList *directories = f.GetListOfKeys(); // get the list of directories in the file for(Int_t entFile=0;entFile<directories->GetEntries();entFile++){ TObject * o = f.Get(directories->At(entFile)->GetName()); // get the object in the base directory if(TString(o->IsA()->GetName())=="TDirectoryFile"){ // means that this is a directory (PWGGA......) TDirectory *pwg4dir =(TDirectory*)o; TString baseDirName = pwg4dir->GetName(); TString reconstructionFlagString = ""; // this is for new scheme where also the flags are coded in numbers in the PWGGA.... name if(baseDirName.Length()>31){ reconstructionFlagString = baseDirName(baseDirName.Index("GammaConversion_")+16,8); } TList *pwg4list = pwg4dir->GetListOfKeys(); // list of the yeys inside the base directory for(Int_t entHist=0;entHist<pwg4list->GetEntries();entHist++){ TString name = pwg4list->At(entHist)->GetName(); if(name.Contains("container")==0){ // does not try to read the container (get errors if tried) TObject * oHist = pwg4dir->Get(pwg4list->At(entHist)->GetName()); // get the object if(TString(oHist->IsA()->GetName())=="TList"){ // check if the object is a TList TString listname = oHist->GetName(); cout<<"Reading: "<<listname.Data()<<endl; TString cutString = listname(listname.Index("_")+1,listname.Length()) + "\n";// get the Cut string from the name outputFile << cutString.Data(); } } } } } outputFile.close(); }
TPaveStats* GetStatPad(TH1* hst) { TList *lst = hst->GetListOfFunctions(); if (!lst) return 0; int nf = lst->GetSize(); for (int i=0;i<nf;i++) { TPaveStats *fnc = (TPaveStats*) lst->At(i); if (fnc->InheritsFrom("TPaveStats")) return fnc; } return 0; // }
void test5() { TFile file("test.root"); TTree* tree = (TTree *)file.Get("tree;1"); TList* list = tree->GetUserInfo() ; list->Print(); TObjString* objstr = (TObjString*)list->At(0); objstr->Print(); TString xmlstring = objstr->GetString(); cout << xmlstring << endl; }
TList* extractObjectFromFile(const char* fileName, const char* name) { TList* objects = new TList(); TFile file(fileName); gROOT->cd(); TList* keyList = file.GetListOfKeys(); for (int i = 0; i < keyList->GetSize(); ++i) { TKey* key = static_cast<TKey*>(keyList->At(i)); std::cout<< key->GetName()<< std::endl; if (!strcmp(key->GetName(), name)) { objects->Add(key->ReadObj()->Clone()); } else if (!strcmp(key->GetClassName(), "TCanvas")) { TCanvas* canvas = static_cast<TCanvas*>(key->ReadObj()); if (!strcmp(canvas->GetName(), name)) objects->Add(canvas->Clone()); TList* objectsFromPad = extractObjectFromPad(canvas, name); for (int j = 0; j < objectsFromPad->GetSize(); ++j) objects->Add(objectsFromPad->At(j)); } } file.Close(); return objects; }
void RootWImage::saveSummaryLoop(TPad* basePad, std::string baseName, TFile* myTargetFile) { TList* aList; TObject* anObject; TPad* myPad; std::string myClass; std::string myName; TNamed* aNamed; // TSystemFile* aFile; // string aFileName; // string aFileNameTail; // TFile* myRootFile; aList = basePad->GetListOfPrimitives(); for (int i=0; i<aList->GetEntries(); ++i) { anObject = aList->At(i); myClass = anObject->ClassName(); if (myClass=="TPad") { // Go one step inside myPad = (TPad*) anObject; saveSummaryLoop(myPad, baseName, myTargetFile); } else if ( (myClass=="TProfile") || (myClass=="TGraph") || (myClass=="TH1D") || (myClass=="TH2C") || (myClass=="TH2D") || (myClass=="THStack") ) { aNamed = (TNamed*) anObject; myTargetFile->cd(); myName = Form("%s.%s", baseName.c_str(), aNamed->GetName()); myName = RootWeb::cleanUpObjectName(myName); aNamed->SetName(myName.c_str()); aNamed->Write(); } else if ( (myClass=="TEllipse") || (myClass=="TFrame") || (myClass=="TLatex") || (myClass=="TLegend") || (myClass=="TLine") || (myClass=="TPaveText") || (myClass=="TPolyLine") || (myClass=="TText") ) { } else { std::cerr << Form("Unhandled class %s", myClass.c_str()) << std::endl; } } }
TH1* GetBaseHisto(TPad* pad) { if (!pad) pad = (TPad*)gPad; if (!pad) return 0; TList* lst = pad->GetListOfPrimitives(); int size = lst->GetSize(); TH1* hst=0; for (int i=0;i<size;i++) { TObject* obj = lst->At(i); if (!obj) continue; if (obj->InheritsFrom("TH1")) {hst = (TH1*)obj; break;} } return hst; }
TFrame* GetFrame(TPad* pad) { if (!pad) pad = (TPad*)gPad; if (!pad) return 0; TList* lst = pad->GetListOfPrimitives(); int size = lst->GetSize(); TFrame* frm=0; for (int i=0;i<size;i++) { TObject* obj = lst->At(i); if (!obj) continue; if (obj->InheritsFrom("TFrame")) {frm = (TFrame*)obj; break;} } return frm; }
/** * Merge all files in folder path with names matching the regular expression filematch into trees in a ROOT file. * * @param filematch Merge files whose names match this regular expression (default: read all) * @param path Merge files in this folder (default: current folder) */ void merge_all(const char *filematch = "[0-9]+[a-z]+.out", const char *path = ".") { TFile *outfile = new TFile("out.root","RECREATE"); // create ROOT file ifstream infile; TSystemDirectory dir(path,path); // open given folder TList *files = dir.GetListOfFiles(); // get all files in that folder TRegexp re(filematch); // create regular expression from given parameter outfile->cd(); // switch current directory to ROOT file Int_t n = 0; for (Int_t i = 0; ; i++){ // for loop incrementing index i TObject *f = files->At(i); // get file from folder with index i if (f){ // if next file was found TString filename = f->GetName(); // get filename TString fn = filename; fn.Resize(filename.Length() - 4); // shorten filename by extension ".out" ULong64_t jobnumber; char logtype[64]; double data[1024]; if ((re.Index(filename, &n) == 0) && (sscanf(fn.Data(), "%Ld%s", &jobnumber, logtype) == 2)){ // if filename matches regular expression and contains jobnumber infile.open(filename.Data()); // open file TNtupleD *tree = (TNtupleD*)outfile->Get(logtype); // get corresponding tree from file if (!tree) { // if tree does not yet exist TString bdescriptor; bdescriptor.ReadLine(infile); // read branch descriptor from file header bdescriptor.ReplaceAll(" ",":"); // format branch descriptor for root ("x y z" -> "x:y:z") tree = new TNtupleD(logtype, logtype, bdescriptor.Data()); // create new tree with name logtype from filename printf("%ss have %i columns\n", logtype, tree->GetNvar()); } else infile.ignore(9999, '\n'); // if tree already exists skip file header n = tree->GetNvar(); // get number of file columns cout << "Adding " << filename << '\n'; while (1){ for (int j = 0; j < n; j++) infile >> data[j]; // read values into data array if (!infile) break; // if something happened during reading: stop tree->Fill(data); // fill data into tree } infile.close(); // close file cout << "Entries: " << tree->GetEntries() << '\n'; } } else break;
// A macro to print out a TLegend - can be considered a smarter TLegend::ls(). // If no TLegend pointer is passed, it loops over the TLegends drawn on current TPad. void PrintLegend(TLegend *leg=0) { if ( leg==0 ) { if (gROOT->GetListOfCanvases()->GetEntries()==0) return; TList *padprim = gPad->GetListOfPrimitives(); for (int i=0; i<padprim->GetEntries(); i++) { TObject *myobj = gROOT->FindObject(padprim->At(i)->GetName()); if ( myobj != 0 && myobj->InheritsFrom("TLegend") ) PrintLegend((TLegend*)myobj); } return; } TList *ents = leg->GetListOfPrimitives(); for (int i=0; i<ents->GetEntries(); i++) { TLegendEntry *le = (TLegendEntry*)ents->At(i); TString s( le->GetLabel() ); TObject *obj = le->GetObject(); if (!obj) continue; // if no object, this can be the title line, so skip TString color = "???"; if ( obj->InheritsFrom("TH1") ) color = gROOT->GetListOfColors()->At(((TH1*)obj)->GetLineColor())->GetName(); cout << "Item "; cout.width(2); cout.fill('0'); cout << i << " plotted in "; cout.width(7); cout.fill(' '); cout << color << " : " << s << endl; } //leg->ls(); }
std::vector<TGraph *> SetupHist(TH2D *hist, TGraph2D *graph) { for (int i = 1; i <= hist->GetXaxis()->GetNbins(); ++i) { for (int j = 1; j <= hist->GetYaxis()->GetNbins(); ++j) { hist->SetBinContent( i, j, graph->Interpolate(hist->GetXaxis()->GetBinCenter(i), hist->GetYaxis()->GetBinCenter(j))); if (hist->GetBinContent(i, j) == 0.) hist->SetBinContent(i, j, 1E-6); } } TList *conts = contourFromTH2(hist, 0.05); std::vector<TGraph *> cgraphs; for (int i = 0; i < conts->GetSize(); ++i) { cgraphs.push_back((TGraph *)conts->At(i)); } return cgraphs; }
void SelectPad() { notDeleted = kTRUE; toolcanvas->cd(); // Clear buttons from toolcanvas TObject *o; TList *ll = toolcanvas->GetListOfPrimitives(); for (Int_t ii=ll->GetEntries()-1; ii>=0; ii--) { o = ll->At(ii); ll->Remove(o); } Double_t buttonheight = 50; TList *li = canvas->GetListOfPrimitives(); Int_t nentries = li->GetEntries(); if (nentries==1) return; toolcanvas->SetWindowSize(toolw,(nentries+1)*buttonheight); toolcanvas->Modified(); toolcanvas->Update(); pt->SetY1NDC(1.0-1.0/(nentries+1)); pt->Draw(); toolcanvas->Update(); // toolcanvas->cd(); if (b) {delete b;} Int_t count=0; b = new TObjArray(nentries); for (Int_t i=0; i<nentries; i++) { b->Add(new TButton(Form("pad%i",i+1),Form("Enlarge(%i);",i),0,(1-(count+1.)/(nentries+1)),1,(1-(count+2.)/(nentries+1)))); b->At(i)->Draw(); count++; } toolcanvas->Modified(); toolcanvas->Update(); // if (display) {display->Modified(); display->Update();} }
/////////////////////////////// // Return matching key names SEXP namesMatchingClass(SEXP fileForHists, SEXP directoryR, SEXP classTypeR) { TFile* f = checkForFileForHistsWrapper(fileForHists); const char* oldDirectory = setFileDirectory(f, directoryR); // Get the class type std::string classType = CHAR( STRING_ELT(classTypeR, 0) ); // Keep track of the ones we want std::vector<const char*> names; std::vector<int> cycles; // Loop over keys in this directory -- pull out names and cycles for classes // that match the ones we want. TList* l = gDirectory->GetListOfKeys(); for ( unsigned int i = 0; i < l->GetEntries(); ++i ) { TKey* k = (TKey*) l->At(i); if ( strcmp( k->GetClassName(), classType.c_str() ) == 0 ) { names.push_back( k->GetName() ); cycles.push_back( k->GetCycle() ); } } // Now we loop over the vectors to get the list of names SEXP rNames; PROTECT( rNames = NEW_CHARACTER( names.size() ) ); for ( unsigned int i = 0; i < names.size(); ++i ) { // Form the string char buf[BUFSIZE]; snprintf(buf, BUFSIZE, "%s;%d", names[i], cycles[i]); // Save this away SET_STRING_ELT( rNames, i, mkChar( buf ) ); } UNPROTECT(1); // Restore the old directory if ( ! f->cd(oldDirectory) ) { error("namesMatchingClass: cd to old directory failed"); } return rNames; }
TH1F* GetHisto(TFile* fin, string region, string process, string varname, float& norm, bool do_norm, float input_norm) { string cname = CHANNEL_NAME+string("/")+region+"/"+varname; TCanvas* c = (TCanvas*) fin->Get(cname.c_str()); string hname = "v:"+varname+"|p:"+process+"|r:"+region+string("|c:")+CHANNEL_NAME+string("|t:1DEntries"); TH1F* h = 0; if(VERBOSE>0){ cerr<<"cname :"<<cname<<endl; cerr<<"histo name: "<<hname<<endl; cerr<<"pointer: "<<c<<endl; } TList* l = c->GetListOfPrimitives(); TPad* pad = (TPad*) l->At(0); THStack* stack = (THStack*) pad->GetPrimitive(""); h = (TH1F*) stack->GetHists()->FindObject(hname.c_str()); if(do_norm) h->Scale(input_norm/h->Integral()); norm = h->Integral(); return (TH1F*) h->Clone(); }
TGraph* GetContour(TGraph2D *g, TString name){ TGraph *gnew; //cout << g->GetName() << " " << g->GetN() << endl; TH2D *temp = (TH2D*)g->GetHistogram();//need this for list to work? //g->Draw("alp");//need this for list to work? TList *glist = (TList*)g->GetContourList(1.0); if(glist == nullptr) return gnew; int max_points = -1; int nn = glist->GetSize(); //cout << "number of entries in list " << nn << endl; for(int i = 0; i<glist->GetSize(); ++i){ TGraph *gtemp = (TGraph*)glist->At(i); int Npoints = gtemp->GetN(); if(Npoints>max_points){ gnew = (TGraph*)gtemp->Clone(name); max_points = Npoints; } } return gnew; }
void testMergeCont() { // Macro to test merging of containers. gROOT->LoadMacro("$ROOTSYS/tutorials/hsimple.C"); TList *list = (TList *)GetCollection(); TList *inputs = new TList(); for (Int_t i=0; i<10; i++) { inputs->AddAt(GetCollection(),0); list->Merge(inputs); inputs->Delete(); f->Close(); } delete inputs; TH1F *hpx = (TH1F*)(((TList*)list->At(1))->At(0)); printf("============================================\n"); printf("Total hpx: %d entries\n", (int)hpx->GetEntries()); hpx->Draw(); list->Delete(); delete list; }
void SetGStyle(TGraph* hst,int col,int mark,float mrsize) { hst->SetLineColor(col); hst->SetMarkerColor(col); hst->SetFillColor(col); hst->SetMarkerStyle(mark); hst->SetMarkerSize(mrsize); TList *lst = hst->GetListOfFunctions(); if (lst) { int nf = lst->GetSize(); for (int i=0;i<nf;i++) { TObject *fnc = lst->At(i); if (fnc->InheritsFrom("TF1")) { ((TF1*)fnc)->SetLineColor(col); ((TF1*)fnc)->SetLineWidth(1); ((TF1*)fnc)->ResetBit(TF1::kNotDraw); } else if (fnc->InheritsFrom("TPaveStats")) { ((TPaveStats*)fnc)->SetTextColor(col); } } } }