Bool_t KVDataSetManager::ReadDataSetList() { //Initialise list of all known datasets from informations in $KVROOT/KVFIles/.kvrootrc //(and user's .kvrootrc) KVString manip_list = gEnv->GetValue("DataSet", ""); fDataSets.Clear(); TObjArray *manips = manip_list.Tokenize(" "); TIter next(manips); TObjString* manip; while ( (manip = (TObjString*)next()) ) { KVDataSet *ds = NewDataSet(); ds->SetName(manip->GetString().Data()); ds->SetTitle( gEnv->GetValue( Form("%s.DataSet.Title", manip->GetString().Data()), "Experimental dataset" ) ); ds->SetDataPathSubdir( gEnv->GetValue( Form("%s.DataSet.RepositoryDir", manip->GetString().Data()), manip->GetString().Data() ) ); ds->SetUserGroups( gEnv->GetValue( Form("%s.DataSet.UserGroup", manip->GetString().Data()), "") ); ds->SetRepository(fRepository); fDataSets.Add(ds); } delete manips; return kTRUE; }
void TBDataParser::OnCharacters(const char *characters) { if(_currentElement != NULL && !strcmp(_currentElement->Data(),"vector")) { TString *string = new TString(characters); TObjArray *values = string->Tokenize(", "); for(Int_t i = 0; i < values->GetEntries(); i++) { TObjString *object = (TObjString *) values->At(i); TString value = object->GetString().ReplaceAll("\n", "").ReplaceAll("\t", "").ReplaceAll(" ", "").ReplaceAll("\0", ""); if(value.IsFloat()) { _vector->Fill(value.Atof()); } } if(_vectorsStack->GetEntries() == 1) { _motherVecEntries = _vector->GetEntries(); } else if(_currentMethod != NULL && !strcmp(_currentMethod->Data(),"all")) { for(Int_t i = 1; i < _motherVecEntries; i++) { TObjString *object = (TObjString *) values->First(); TString value = object->GetString().ReplaceAll("\n", "").ReplaceAll("\t", "").ReplaceAll(" ", "").ReplaceAll("\0", ""); if(value.IsFloat()) _vector->Fill(value.Atof()); } } values->Delete(); } }
void DrawCurrHistogram() { TObjString* filename = histograms->At(currPos); TString f(fFileDir); f.Append("/"); f.Append(filename->GetString()); TFile* file = new TFile(f, "read"); // check file if (!file) return; if (file->IsZombie()) return; TH2D* hist = (TH2D*) gFile->Get(fHistName); if (!hist) continue; if (!hist->GetEntries()) continue; // copy the histogram to the root memory //gROOT->cd(); //TH2D* hist_copy = new TH2D(*hist); TString t(filename->GetString()); t.Append(": "); t.Append(hist->GetTitle()); hist->SetTitle(t); //histograms->Add(hist_copy); //TH1* h = histograms->At(currPos); c->cd(1); //gPad->cd(); hist->Draw("colz"); // file can be closed now... //file->Close(); if(currHist != 0) { PreserveAxis(currHist->GetXaxis(), hist->GetXaxis()); PreserveAxis(currHist->GetYaxis(), hist->GetYaxis()); } if(currFile != 0) currFile->Close(); currFile = file; currHist = hist; //gPad->Modified(); //gPad->Update(); //cout << "Added histogram from " << filename << endl; }
//______________________________________________________________________________ void AODmerge() { // Merging method. No staging and no terminate phase. TStopwatch timer; timer.Start(); TString outputDir = "wn.xml"; TString outputFiles = VAR_AOD_MERGE_FILES; TString mergeExcludes = ""; TObjArray *list = outputFiles.Tokenize(","); TIter *iter = new TIter(list); TObjString *str; TString outputFile; Bool_t merged = kTRUE; while((str=(TObjString*)iter->Next())) { outputFile = str->GetString(); // Skip already merged outputs if (!gSystem->AccessPathName(outputFile)) { printf("Output file <%s> found. Not merging again.",outputFile.Data()); continue; } if (mergeExcludes.Contains(outputFile.Data())) continue; merged = AliAnalysisAlien::MergeOutput(outputFile, outputDir, 10, 0); if (!merged) { printf("ERROR: Cannot merge %s\n", outputFile.Data()); return; } } // all outputs merged, validate ofstream out; out.open("outputs_valid_merge", ios::out); out.close(); timer.Print(); }
Bool_t KVDataSetManager::ReadTaskList() { //Initialise list of all known analysis tasks from informations in $KVROOT/KVFIles/.kvrootrc //(and user's .kvrootrc) KVString task_list = gEnv->GetValue("DataAnalysisTask", ""); fTasks.Clear(); TObjArray *tasks = task_list.Tokenize(" "); TIter next(tasks); TObjString* task; while ( (task = (TObjString*)next()) ) { KVDataAnalysisTask *dat = new KVDataAnalysisTask; TString name = task->GetString(); dat->SetName( name.Data() ); dat->SetTitle( gEnv->GetValue( Form("%s.DataAnalysisTask.Title", name.Data()), "") ); dat->SetPrereq( gEnv->GetValue( Form("%s.DataAnalysisTask.Prereq", name.Data()), "") ); dat->SetDataAnalyser( gEnv->GetValue( Form("%s.DataAnalysisTask.Analyser", name.Data()), "KVDataAnalyser") ); dat->SetWithUserClass( gEnv->GetValue( Form("%s.DataAnalysisTask.UserClass", name.Data()), kFALSE) ); dat->SetUserBaseClass( gEnv->GetValue( Form("%s.DataAnalysisTask.UserClass.Base", name.Data()), "") ); dat->SetStatusUpdateInterval( gEnv->GetValue( Form("%s.DataAnalysisTask.StatusUpdateInterval", name.Data()), 1000) ); fTasks.Add(dat); } delete tasks; return kTRUE; }
void formatForCmsPublic(TPad * c, TLegend *leg, TString title, int nsamp, float legx, float legy, float legw, float legh, TString legopt) { if(title.Length()!=0) { TPaveText *pave = new TPaveText(0.5,0.96,0.94,0.99,"NDC"); pave->SetBorderSize(0); pave->SetFillStyle(0); pave->SetTextAlign(32); pave->SetTextFont(42); TObjArray * tokens = title.Tokenize("\\\\"); int nt = tokens->GetEntries(); for(int it=0; it<nt; ++it) { TObjString * t = (TObjString *)tokens->At(it); pave->AddText(t->GetString()); } pave->Draw("same"); } float legx1=legx, legx2=legx+legw; float legy1 = legy, legy2 = legy-legh*(float)(nsamp); if(leg==0) leg = ((TPad *)c)->BuildLegend(legx1,legy1,legx2,legy2); leg->SetBorderSize(0); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetLineWidth(1); leg->SetTextFont(42); leg->SetEntryOption(legopt); leg->SetX1NDC(legx1); leg->SetY1NDC(legy1);//-nsamp*legh); leg->SetX2NDC(legx2); leg->SetY2NDC(legy2); }
//______________________________________________________________________________ void ButtonWindow::StartModule() { // Start the selected module. // get the selected module Int_t module = fCBox_Module->GetSelected(); // get the selected runsets TList set_list; fLB_RunSet->GetSelectedEntries(&set_list); // fill sets Int_t nSet = set_list.GetSize(); Int_t set[999]; for (Int_t i = 0; i < nSet; i++) { TGLBEntry* e = (TGLBEntry*) set_list.At(i); set[i] = e->EntryId(); } // get the calibration module gCurrentModule = (TCCalib*) gCaLibModules->At(module); // get the selected calibration TObjString* calibration = (TObjString*) gCalibrations->At(fCBox_Calibration->GetSelected()); // start the module ((TCCalib*)gCurrentModule)->Start(calibration->GetString().Data(), nSet, set); }
float *getwq(TH1 *h) { TString delim = "_"; TString hn = h->GetName(); TObjArray *tokens = hn.Tokenize(delim); TObjString *wstro = (TObjString*)tokens->At(1); TObjString *qstro = (TObjString*)tokens->At(2); TString wstr = wstro->GetString(); TString qstr = qstro->GetString(); double wval = wstr.Atof(); double qval = qstr.Atof(); float *ret = new float[2]; ret[0] = wval; ret[1] = qval; delete tokens; return ret; }
void PrintSaved() { TIter next(saved); TObjString* title; cout << endl << "Saved histograms: " << saved->GetEntries() << endl << endl; while ((title=(TObjString*)next())) { cout << title->GetString() << endl; } }
void LoadLibsSara() { // Load configuration gROOT->LoadMacro("ConfigurationVAF.C"); // Set paths gSystem->SetIncludePath(includepath.Data()); gSystem->AddDynamicPath(local_fastjet_path.Data()); // Load libraries locally TString loadLibraries="LoadLibraries.C"; loadLibraries.Prepend(loadMacroPath.Data()); gROOT->LoadMacro(loadLibraries.Data()); LoadLibraries(kFALSE); // for FastJet TObjArray *arr; TObjString *objstr; arr = loaddylibs.Tokenize(" "); TIter next(arr); while ((objstr=(TObjString*)next())){ TString str=(objstr->GetString()).Append(".dylib"); Printf("Loading %s", str.Data()); gSystem->Load(str.Data()); } // standard AliRoot arr = loadlibs.Tokenize(" "); TIter next(arr); while ((objstr=(TObjString*)next())){ TString str=objstr->GetString(); Printf("Loading %s", str.Data()); gSystem->Load(str.Data()); } // Load analysis sources locally arr = sources.Tokenize(" "); TIter next(arr); while ((objstr=(TObjString*)next())){ //TString str=(objstr->GetString()).Append(".cxx++g"); TString str=(objstr->GetString()).Append(".cxx+"); gROOT->LoadMacro(str.Data()); } return; }
void transferxSecFromTextToROOT(std::string inputStr="xSec_T3G.txt"){ ifstream fin(inputStr.c_str()); char line[200]; TFile *xSecProspinoFile =0; TH1D *xSecProspino =0; int minMom = 1000000, maxMom = 0; int nBins = 0; std::vector<int> momVec; std::vector<double> xSecVec, xSecErrVec; while( fin.getline(line, 200) ){ TString lineT(line); if( lineT.Contains("Interactions") ) continue; TObjArray *vlist = lineT.Tokenize(" "); int nEntries = vlist->GetEntries(); int mMom; double xSec =0, xSecRelErr =0; for(int ie=0; ie<nEntries; ie++){ TObjString* perObj = dynamic_cast<TObjString*>(vlist->At(ie)); TString perStr = perObj->GetString(); if( ie==0 ){ mMom = perStr.Atoi(); if( minMom > mMom ) minMom = mMom; if( maxMom < mMom ) maxMom = mMom; } if( ie==1 ) xSec = perStr.Atof(); if( ie==2 ) xSecRelErr = perStr.Atof(); } nBins ++; momVec.push_back(mMom); xSecVec.push_back(xSec); xSecErrVec.push_back(xSec*xSecRelErr/100.); // std::cout<<"mMom : "<<mMom<<" xSec : "<<xSec<<" xSecRelErr : "<<xSecRelErr<<std::endl; } double divBin = 1.0*(maxMom - minMom)/(nBins-1); double lowMom = minMom-divBin/2.0, highMom = maxMom+divBin/2.0; std::cout<<"nBins : "<<nBins<<" minMom : "<<minMom<<" maxMom : "<<maxMom<<" divBin : "<<divBin<<" lowMom : "<<lowMom<<" highMom : "<<highMom<<std::endl; TString rootStrT(inputStr); rootStrT.ReplaceAll("txt", "root"); std::cout<<"root file : "<<rootStrT<<std::endl; xSecProspinoFile = new TFile(rootStrT, "RECREATE"); if( rootStrT.Contains("T1") ) xSecProspino = new TH1D("gluino_xsection", "gluino_xsection", nBins, lowMom, highMom); if( rootStrT.Contains("T2") ) xSecProspino = new TH1D("squark_xsection", "squark_xsection", nBins, lowMom, highMom); if( rootStrT.Contains("T3G") ) xSecProspino = new TH1D("stop_xsection", "stop_xsection", nBins, lowMom, highMom); for(int iv=0; iv<(int)momVec.size(); iv++){ double mMom = (double)momVec[iv]; int ib = xSecProspino->FindFixBin(mMom); xSecProspino->SetBinContent(ib, xSecVec[iv]); xSecProspino->SetBinError(ib, xSecErrVec[iv]); } // xSecProspino->Write(); xSecProspinoFile->Write(); xSecProspinoFile->Close(); }
//______________________________________________________________________________ void ButtonWindow::ReadRunsets(Int_t i) { // Read the runsets for the calibration data of the 'i'-th module // in the module selection combo box // check if calibration was selected if (!gCalibSelected) { TGMsgBox* msg = new TGMsgBox(gClient->GetRoot(), gMainWindow, "Error", "Please select first " "the calibration you want to work with!", kMBIconStop, kMBOk, 0, kFitWidth | kFitHeight, kTextLeft); return; } // get the selected calibration TObjString* calibration = (TObjString*) gCalibrations->At(fCBox_Calibration->GetSelected()); // get the calibration data of the module TCCalib* c = (TCCalib*) gCaLibModules->At(i); TString data = c->GetCalibData(); // get the number of runsets Int_t nsets = TCMySQLManager::GetManager()->GetNsets(data.Data(), calibration->GetString().Data()); // fill the runsets into the list fLB_RunSet->RemoveAll(); for (Int_t i = 0; i < nsets; i++) { // get the first and last runs Char_t ctime[256]; Int_t first_run = TCMySQLManager::GetManager()->GetFirstRunOfSet(data.Data(), calibration->GetString().Data(), i); Int_t last_run = TCMySQLManager::GetManager()->GetLastRunOfSet(data.Data(), calibration->GetString().Data(), i); TCMySQLManager::GetManager()->GetChangeTimeOfSet(data.Data(), calibration->GetString().Data(), i, ctime); ctime[strlen(ctime)-3] = '\0'; // add list entry Char_t tmp[256]; sprintf(tmp, "Set %d (Run %d to %d) of %s", i, first_run, last_run, ctime); fLB_RunSet->AddEntry(tmp, i); } // update list box fLB_RunSet->Layout(); }
void GetOptionFromString(TString str,TString &outStr1,TString &outStr2,TString d=":") { // TStringO TObjArray *tokens = str.Tokenize(d.Data()); TObjString *objStr = (TObjString *)tokens->At(0); if (!objStr) { outStr1 = "err"; outStr2 = ""; return; } outStr1 = objStr->GetString(); objStr = (TObjString *) tokens->At(1); if (!objStr) { outStr2 = ""; return; } outStr2 = objStr->GetString(); }
//====================================================================== // Regex match a histo name in a directory // void regexMatchHisto( TObject *obj, TDirectory *dir, TObjArray *Args, // list of regexes to match TObjArray *Matches) { for (int i=0; i<Args->GetEntriesFast(); i++) { TObjString *sre = (TObjString *)(*Args)[i]; TRegexp re(sre->GetString(),kFALSE); if (re.Status() != TRegexp::kOK) { cerr << "The regexp " << sre->GetString() << " is invalid, Status() = "; cerr << re.Status() << endl; exit(-1); } TString path( (char*)strstr( dir->GetPath(), ":" ) ); path.Remove( 0, 2 ); // gets rid of ":/" TString fullspec = TString(dir->GetPath()) + "/" + obj->GetName(); if ((fullspec.Index(re) != kNPOS) && (obj->InheritsFrom("TH1"))) { // we have a match // Check to see if it's already in memory map<string,string>::const_iterator it = glmap_objpath2id.find(dir->GetPath()); if (it != glmap_objpath2id.end()) { if (gl_verbose) cout << "Object " << fullspec << " already read in, here it is" << endl; map<string,wTH1 *>::const_iterator hit = glmap_id2histo.find(it->second); // Is this okay? It's going to get wrapped again... TObjString *rpath = new TObjString(fullspec); Matches->AddLast(rpath); Matches->AddLast(hit->second->histo()); } else { // success, record that you read it in. TObjString *rpath = new TObjString(fullspec); Matches->AddLast(rpath); Matches->AddLast(obj); } break; // don't let the object match more than one regex } // if we have a match } // Arg loop } // regexMatchHisto
TH1* getHistogram(TFile* inputFile, const TString& meName, TObjArray& processes, const TString& region) { TH1* histogram_sum = 0; int numProcesses = processes.GetEntries(); for ( int iProcess = 0; iProcess < numProcesses; ++iProcess ) { TObjString* process = dynamic_cast<TObjString*>(processes.At(iProcess)); assert(process); TH1* histogram = getHistogram(inputFile, meName, process->GetString(), region); if ( !histogram_sum ) { TString histogramName_sum = histogram->GetName(); histogramName_sum = histogramName_sum.ReplaceAll(process->GetString(), "sum"); histogram_sum = (TH1*)histogram->Clone(histogramName_sum.Data()); if ( !histogram_sum->GetSumw2N() ) histogram_sum->Sumw2(); } else { histogram_sum->Add(histogram); } } return histogram_sum; }
void QAmerge(const char *suffix, const char *dir, Int_t stage) { // Merging method TStopwatch timer; timer.Start(); TString outputDir = dir; TString outputFiles = Form("QAresults%s.root,EventStat_temp%s.root,RecoQAresults%s.root",suffix,suffix,suffix); TString mergeExcludes = ""; TObjArray *list = outputFiles.Tokenize(","); TIter *iter = new TIter(list); TObjString *str; TString outputFile; Bool_t merged = kTRUE; while((str=(TObjString*)iter->Next())) { outputFile = str->GetString(); // Skip already merged outputs if (!gSystem->AccessPathName(outputFile)) { printf("Output file <%s> found. Not merging again.",outputFile.Data()); continue; } if (mergeExcludes.Contains(outputFile.Data())) continue; merged = IlcAnalysisAlien::MergeOutput(outputFile, outputDir, 10, stage); if (!merged && !outputFile.Contains("RecoQAresults")) { printf("ERROR: Cannot merge %s\n", outputFile.Data()); return; } } // read the analysis manager from file if (!outputDir.Contains("Stage")) { ofstream out; out.open("outputs_valid", ios::out); out.close(); return; } IlcAnalysisManager *mgr = IlcAnalysisManager::GetAnalysisManager(); mgr->SetRunFromPath(mgr->GetRunFromAlienPath(dir)); mgr->SetSkipTerminate(kFALSE); if (!mgr->InitAnalysis()) return; mgr->PrintStatus(); IlcLog::SetGlobalLogLevel(IlcLog::kError); TTree *tree = NULL; mgr->StartAnalysis("gridterminate", tree); if (strlen(suffix)) { if (gSystem->Exec(Form("mv trending.root trending%s.root", suffix))) ::Error("QAmerge", "File trending.root was not produced"); if (gSystem->Exec(Form("mv event_stat.root event_stat%s.root", suffix))) ::Error("QAmerge", "File trending.root was not produced"); } ofstream out; out.open("outputs_valid", ios::out); out.close(); timer.Print(); }
//___________________________________________________________________ void MakeFileList(const char *searchdir, const char *pattern, const char* outputFileName="calib.list", Int_t timeOut=10) { gSystem->Setenv("XRDCLIENTMAXWAIT",Form("%d",timeOut)); gEnv->SetValue("XNet.RequestTimeout", timeOut); gEnv->SetValue("XNet.ConnectTimeout", timeOut); gEnv->SetValue("XNet.TransactionTimeout", timeOut); TFile::SetOpenTimeout(timeOut); TGrid::Connect("alien"); TString command; command = Form("find %s %s", searchdir, pattern); cerr<<"command: "<<command<<endl; TGridResult *res = gGrid->Command(command); if (!res) return; TIter nextmap(res); TMap *map = 0; ofstream outputFile; outputFile.open(Form(outputFileName)); //first identify the largest file and put it at the beginning Int_t largestFileSize=0; TString largestFile; TObject* largestObject; while((map=(TMap*)nextmap())) { TObjString *objs = dynamic_cast<TObjString*>(map->GetValue("turl")); TObjString *objsSize = dynamic_cast<TObjString*>(map->GetValue("size")); if (!objs || !objs->GetString().Length()) continue; if (!objsSize || !objsSize->GetString().Length()) continue; Int_t currentFileSize=objsSize->GetString().Atoi(); if (currentFileSize>largestFileSize) { largestFileSize=currentFileSize; largestFile=objs->GetString(); largestObject=map; } } outputFile << largestFile.Data()<< endl; res->Remove(largestObject); //then write the rest of the entries to the file nextmap.Reset(); while((map=(TMap*)nextmap())) { TObjString *objs = dynamic_cast<TObjString*>(map->GetValue("turl")); if (!objs || !objs->GetString().Length()) { delete res; break; } TString src=Form("%s",objs->GetString().Data()); outputFile << src.Data()<< endl; } outputFile.close(); return; }
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; }
bool getFileMultiStringValue( const char* inFile, const char* parameterName, int& nvals, char returnVals[][1000] ) { // Include a blank space at the end to avoid multiple // matches in grep when target is a substring found in other lines. char command[10000] ; sprintf( command, "grep \"%s \" %s\n", parameterName, inFile ) ; TString commandOutput = gSystem->GetFromPipe( command ) ; /// printf( " Output of command is : %s\n", commandOutput.Data() ) ; char label[1000] ; sscanf( commandOutput.Data(), "%s", label ) ; if ( strcmp( label, parameterName ) == 0 ) { printf(" Found %s. \n", parameterName ) ; TObjArray* strings = commandOutput.Tokenize(" ") ; printf(" Breaks into %d tokens.\n", strings -> GetEntries() ) ; nvals = strings -> GetEntries() - 1 ; for ( int i=0; i<nvals; i++ ) { TObjString* str = (TObjString*) (strings->At(i+1)) ; printf( " string %d : %s\n", i, str->GetString().Data() ) ; sprintf( returnVals[i], "%s", str->GetString().Data() ) ; } return true ; } printf("\n\n *** Could not find parameter %s in file %s.\n\n", parameterName, inFile ) ; return false ; }
void QAmerge(const char *dir, Int_t stage) { // Merging method TStopwatch timer; timer.Start(); TString outputDir = dir; TString outputFiles = "QAresults.root,EventStat_temp.root"; TString mergeExcludes = ""; TObjArray *list = outputFiles.Tokenize(","); TIter *iter = new TIter(list); TObjString *str; TString outputFile; Bool_t merged = kTRUE; while((str=(TObjString*)iter->Next())) { outputFile = str->GetString(); // Skip already merged outputs if (!gSystem->AccessPathName(outputFile)) { printf("Output file <%s> found. Not merging again.",outputFile.Data()); continue; } if (mergeExcludes.Contains(outputFile.Data())) continue; merged = AliAnalysisAlien::MergeOutput(outputFile, outputDir, 10, stage); if (!merged) { printf("ERROR: Cannot merge %s\n", outputFile.Data()); continue; } } TString infolog = "fileinfo.log"; AliAnalysisAlien::MergeInfo(infolog, dir); // read the analysis manager from file if (!outputDir.Contains("Stage")) { ofstream out; out.open("outputs_valid", ios::out); out.close(); return; } AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); mgr->SetRunFromPath(mgr->GetRunFromAlienPath(dir)); mgr->SetSkipTerminate(kFALSE); if (!mgr->InitAnalysis()) return; mgr->PrintStatus(); AliLog::SetGlobalLogLevel(AliLog::kError); TTree *tree = NULL; gROOT->cd(); mgr->StartAnalysis("gridterminate", tree); ofstream out; out.open("outputs_valid", ios::out); out.close(); timer.Print(); }
std::vector<int> Config::getVInt(const std::string& key, const std::string& delim) { s_accessed.insert(_name + '.' + key); TString s(get(key, "").c_str()); std::vector<int> result; TObjArray *tokens = s.Tokenize(delim.c_str()); TIter iter(tokens); while(TObject *p = iter.Next()) { TObjString *item = (TObjString*)p; result.push_back(strtol(item->GetString().Data(),0,0)); } delete tokens; return result; }
void ilceve_init_import_macros() { // Put macros in the list of browsables, add a macro browser to // top-level GUI. TString macdir("$(ILC_ROOT)/EVE/ilc-macros"); gSystem->ExpandPathName(macdir); TFolder* f = gEve->GetMacroFolder(); void* dirhandle = gSystem->OpenDirectory(macdir.Data()); if (dirhandle != 0) { char* filename; TPMERegexp re("\\.C$"); TObjArray names; while ((filename = gSystem->GetDirEntry(dirhandle)) != 0) { if (re.Match(filename)) names.AddLast(new TObjString(filename)); } names.Sort(); for (Int_t ii=0; ii<names.GetEntries(); ++ii) { TObjString * si = (TObjString*) names.At(ii); f->Add(new TEveMacro(Form("%s/%s", macdir.Data(), (si->GetString()).Data()))); } } gSystem->FreeDirectory(dirhandle); gROOT->GetListOfBrowsables()->Add(new TSystemDirectory(macdir.Data(), macdir.Data())); { TEveBrowser *br = gEve->GetBrowser(); TGFileBrowser *fb = 0; fb = br->GetFileBrowser(); fb->GotoDir(macdir); { br->StartEmbedding(0); fb = br->MakeFileBrowser(); fb->BrowseObj(f); fb->Show(); br->StopEmbedding(); br->SetTabTitle("Macros", 0); br->SetTab(0, 0); } } }
/*inline vector<TString> Tokens(TString aline,TString aDelim=" "){{{*/ inline vector<TString> Tokens(TString aline,TString aDelim=" ") { Int_t i; TObjArray* InObjArray; TObjString* os; TString s; vector<TString> OutStringVec; OutStringVec.clear(); InObjArray=aline.Tokenize(aDelim); for ( i=0; i<InObjArray->GetEntriesFast(); i++ ) { os=(TObjString*)InObjArray->At(i); s=os->GetString(); OutStringVec.push_back(s); } return OutStringVec; }
Bool_t h10looper::Notify() { // The Notify() function is called when a new file is opened. This // can be either for a new TTree in a TChain or when when a new TTree // is started when using PROOF. It is normally not necessary to make changes // to the generated code, but the routine can be extended by the // user if needed. The return value is currently not used. int tn = fChain->GetTreeNumber(); if (tn != fTreeNumber) { TString fullfn = ((TChain*)fChain)->GetFile()->GetName(); TObjArray *tokens = fullfn.Tokenize("/"); TObjString *tok = (TObjString*)tokens->At(tokens->GetLast()); TString fn = tok->GetString(); data->run = ((TString)fn(*fRegExp_run)).Atoi(); data->file_anum = ((TString)((TString)fn(*fRegExp_Anum))(1,2)).Atoi(); data->filename = fn.Data(); delete tokens; } return kTRUE; }
//################################################## bool LoadLibList ( const TString& list, TString& listlibs, TString& listlibsextra ) { TObjArray* arr = list.Tokenize(" "); TObjString *objstr = NULL; cout << "Loading library list (-2 = version mismatch, -1 = not found or error, 0 = success, 1 = already loaded) :" << endl; TIter next(arr); while ( (objstr=(TObjString*)next()) ) { TString module = objstr->GetString(); if (module.IsNull()) { continue; } module.Prepend("lib"); if(module.EndsWith(".so")) { module.Remove( module.Index(".so")); } std::cout << "loading module :" << module.Data() << " ... " ; int result = gSystem->Load(module.Data(), "", kTRUE); std::cout << result << std::endl; ; if (result < 0) { std::cout << "EmcalJetCDF::LoadLibList - Could not load library >>>" << module.Data() << "<<< ; Error = " << result << std::endl; return false; } TString lib_in_list = module + ".so "; // blank after .so listlibs += lib_in_list; listlibsextra += lib_in_list; } delete arr; return true; }
//______________________________________________________________________________ void AODmerge() { // Merging method. No staging and no terminate phase. TStopwatch timer; timer.Start(); TString outputDir = "wn.xml"; TString outputFiles = "EventStat_temp.root,AODQA.root,AliAOD.root,AliAOD.VertexingHF.root,AliAODGammaConversion.root,FilterEvents_Trees.root,AliAOD.Muons.root"; TString mergeExcludes = ""; TObjArray *list = outputFiles.Tokenize(","); TIter *iter = new TIter(list); TObjString *str; TString outputFile; Bool_t merged = kTRUE; while((str=(TObjString*)iter->Next())) { outputFile = str->GetString(); // Skip already merged outputs if (!gSystem->AccessPathName(outputFile)) { printf("Output file <%s> found. Not merging again.",outputFile.Data()); continue; } if (mergeExcludes.Contains(outputFile.Data())) continue; merged = AliAnalysisAlien::MergeOutput(outputFile, outputDir, 10, 0); if (!merged) { printf("ERROR: Cannot merge %s\n", outputFile.Data()); continue; } } // all outputs merged, validate AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); mgr->InitAnalysis(); mgr->SetGridHandler(new AliAnalysisAlien); mgr->StartAnalysis("gridterminate",0); ofstream out; out.open("outputs_valid", ios::out); out.close(); timer.Print(); }
//_______________________________________________________________________________________________ // // Initialize plugin with all its common values // Bool_t CreatePlugin() { // create object plugin = new AliAnalysisAlien; // framework version plugin->SetROOTVersion(rootVersion.Data()); plugin->SetAliROOTVersion(aliVersion.Data()); // additional libraries/includes if (addLibs.Length() > 0) plugin->SetAdditionalLibs(addLibs.Data()); if (addIncludes.Length() > 0) plugin->AddIncludePath(addIncludes.Data()); // runtime tasks if (addTaskRuntime.Length() > 0) { TObjArray *list = addTaskRuntime.Tokenize(" "); TObjArrayIter next(list); TObjString *os = 0x0; TString sources(""); while ( (os = (TObjString*)next()) ) { const char *taskName = os->GetString().Data(); addLibs.Append(Form("%s.h %s.cxx", taskName, taskName)); sources.Append(Form("%s.cxx", taskName)); } plugin->SetAnalysisSource(sources.Data()); } // specific setups if (targetAlien) { ::Info("SetupPlugin::CreatePlugin()", "Setting up for ALIEN"); return SetupForAlien(); } else { ::Info("SetupPlugin::CreatePlugin()", "Setting up for PROOF"); return SetupForProof(); } }
void makeTauIsolationPlots() { TFile* inputFile = TFile::Open("../test/patTauIsolationAnalyzer.root"); TObjArray ptThresholds; ptThresholds.Add(new TObjString("0_50GeV")); ptThresholds.Add(new TObjString("1_00GeV")); ptThresholds.Add(new TObjString("1_50GeV")); ptThresholds.Add(new TObjString("2_00GeV")); ptThresholds.Add(new TObjString("2_50GeV")); ptThresholds.Add(new TObjString("3_00GeV")); unsigned numPtThresholds = ptThresholds.GetEntries(); TObjArray sigConeSizes; sigConeSizes.Add(new TObjString("0_05dRsig")); sigConeSizes.Add(new TObjString("0_10dRsig")); sigConeSizes.Add(new TObjString("0_15dRsig")); sigConeSizes.Add(new TObjString("0_20dRsig")); sigConeSizes.Add(new TObjString("0_25dRsig")); sigConeSizes.Add(new TObjString("0_30dRsig")); unsigned numSigConeSizes = sigConeSizes.GetEntries(); TString dqmDirectory = ""; TCanvas* canvas = new TCanvas("canvas", "canvas", 800, 600); canvas->SetFillColor(10); canvas->SetBorderSize(2); //------------------------------------------------------------------------------- // show distributions of isolation Pt sums **before** tight tau id. is applied //------------------------------------------------------------------------------- TPostScript* psBeforeTauId = new TPostScript("patTauIsolationPlots_beforeTauId.ps", 112); for ( unsigned iSigConeSize = 0; iSigConeSize < numSigConeSizes; ++iSigConeSize ) { TObjString* sigConeSize = (TObjString*)sigConeSizes.At(iSigConeSize); //--- show plots for PFCandidate Pt > XX GeV // (same threshold for all types of PFCandidates) for ( unsigned iPtThreshold = 0; iPtThreshold < numPtThresholds; ++iPtThreshold ) { TObjString* ptThreshold = (TObjString*)ptThresholds.At(iPtThreshold); TString meName = TString("PFCandIso").Append(sigConeSize->GetString()).Append(ptThreshold->GetString()).Append("_matched"); showTauIsolation(inputFile, dqmDirectory, meName, "TauPFIsolationQuantities/beforeTauId", "MuonPFIsolationQuantities", "ElectronPFIsolationQuantities", canvas, psBeforeTauId, "beforeTauId", true); } //--- show plots for PFChargedHadron Pt > 1.0 GeV, PFGamma Pt > 1.5 GeV TString meName = TString("PFCandIso").Append(sigConeSize->GetString()).Append("1_00_1_50GeV").Append("_matched"); showTauIsolation(inputFile, dqmDirectory, meName, "TauPFIsolationQuantities/beforeTauId", "MuonPFIsolationQuantities", "ElectronPFIsolationQuantities", canvas, psBeforeTauId, "beforeTauId", true); } delete psBeforeTauId; //------------------------------------------------------------------------------- // show distributions of isolation Pt sums **after** tight tau id. is applied //------------------------------------------------------------------------------- TPostScript* psAfterTauId = new TPostScript("patTauIsolationPlots_afterTauId.ps", 112); for ( unsigned iSigConeSize = 0; iSigConeSize < numSigConeSizes; ++iSigConeSize ) { TObjString* sigConeSize = (TObjString*)sigConeSizes.At(iSigConeSize); //--- show plots for PFCandidate Pt > XX GeV // (same threshold for all types of PFCandidates) for ( unsigned iPtThreshold = 0; iPtThreshold < numPtThresholds; ++iPtThreshold ) { TObjString* ptThreshold = (TObjString*)ptThresholds.At(iPtThreshold); TString meName = TString("PFCandIso").Append(sigConeSize->GetString()).Append(ptThreshold->GetString()).Append("_matched"); showTauIsolation(inputFile, dqmDirectory, meName, "TauPFIsolationQuantities/afterTauId", "", "", canvas, psAfterTauId, "afterTauId", true); } //--- show plots for PFChargedHadron Pt > 1.0 GeV, PFGamma Pt > 1.5 GeV TString meName = TString("PFCandIso").Append(sigConeSize->GetString()).Append("1_00_1_50GeV").Append("_matched"); showTauIsolation(inputFile, dqmDirectory, meName, "TauPFIsolationQuantities/afterTauId", "", "", canvas, psAfterTauId, "afterTauId", true); } delete psAfterTauId; delete canvas; delete inputFile; }
// main GUI void TMVAGui( const char* fName = "TMVA.root" ) ///usage: { //TMVA::gConfig().GetVariablePlotting().fNbins1D = 50.0; //TMVA::gConfig().GetVariablePlotting().fNbinsXOfROCCurve=50; // Use this script in order to run the various individual macros // that plot the output of TMVA (e.g. running TMVAClassification.C), // stored in the file "TMVA.root" TString curMacroPath(gROOT->GetMacroPath()); // uncomment next line for macros submitted to next root version gROOT->SetMacroPath(curMacroPath+":$ROOTSYS/tmva/test/:"); // for the sourceforge version, including $ROOTSYS/tmva/test in the // macro path is a mistake, especially if "./" was not part of path // add ../macros to the path (comment out next line for the ROOT version of TMVA) // gROOT->SetMacroPath(curMacroPath+":../macros:"); cout << "--- Launch TMVA GUI to view input file: " << fName << endl; // init TMVAGui_inactiveButtons.clear(); // check if file exist TFile* file = TFile::Open( fName ); if (!file) { cout << "==> Abort TMVAGui, please verify filename" << endl; return; } // find all references cout << "--- Reading keys ..." << endl; TMVAGui_keyContent = (TList*)file->GetListOfKeys()->Clone(); // close file file->Close(); TString defaultRequiredClassifier = ""; // gROOT->Reset(); // gStyle->SetScreenFactor(2); // if you have a large screen, select 1,2 or 1.4 // create the control bar TControlBar* cbar = new TControlBar( "vertical", "TMVA Plotting Macros for Classification", 0, 0 ); const TString buttonType( "button" ); // configure buttons Int_t ic = 1; // find all input variables types TList* keylist = GetKeyList( "InputVariables" ); TListIter it( keylist ); TObjString* str = 0; char ch = 'a'; while ((str = (TObjString*)it())) { TString tmp = str->GetString(); TString title = Form( "Input variables '%s'-transformed (training sample)", tmp.ReplaceAll("InputVariables_","").Data() ); if (tmp.Contains( "Id" )) title = "Input variables (training sample)"; ActionButton( cbar, Form( "(%i%c) %s", ic, ch++, title.Data() ), Form( ".x variables.C(\"%s\",\"%s\",\"%s\")", fName, str->GetString().Data(), title.Data() ), Form( "Plots all '%s'-transformed input variables (macro variables.C(...))", str->GetString().Data() ), buttonType, str->GetString() ); } ic++; // correlation scatter plots it.Reset(); ch = 'a'; while ((str = (TObjString*)it())) { TString tmp = str->GetString(); TString title = Form( "Input variable correlations '%s'-transformed (scatter profiles)", tmp.ReplaceAll("InputVariables_","").Data() ); if (tmp.Contains( "Id" )) title = "Input variable correlations (scatter profiles)"; ActionButton( cbar, Form( "(%i%c) %s", ic, ch++, title.Data() ), Form( ".x CorrGui.C(\"%s\",\"%s\",\"%s\")", fName, str->GetString().Data(), title.Data() ), Form( "Plots all correlation profiles between '%s'-transformed input variables (macro CorrGui.C(...))", str->GetString().Data() ), buttonType, str->GetString() ); } // coefficients ActionButton( cbar, Form( "(%i) Input Variable Linear Correlation Coefficients", ++ic ), Form( ".x correlations.C(\"%s\")", fName ), "Plots signal and background correlation summaries for all input variables (macro correlations.C)", buttonType ); ActionButton( cbar, Form( "(%ia) Classifier Output Distributions (test sample)", ++ic ), Form( ".x mvas.C(\"%s\",0)", fName ), "Plots the output of each classifier for the test data (macro mvas.C(...,0))", buttonType, defaultRequiredClassifier ); ActionButton( cbar, Form( " (%ib) Classifier Output Distributions (test and training samples superimposed) ", ic ), Form( ".x mvas.C(\"%s\",3)", fName ), "Plots the output of each classifier for the test (histograms) and training (dots) data (macro mvas.C(...,3))", buttonType, defaultRequiredClassifier ); ActionButton( cbar, Form( "(%ic) Classifier Probability Distributions (test sample)", ic ), Form( ".x mvas.C(\"%s\",1)", fName ), "Plots the probability of each classifier for the test data (macro mvas.C(...,1))", buttonType, defaultRequiredClassifier ); ActionButton( cbar, Form( "(%id) Classifier Rarity Distributions (test sample)", ic ), Form( ".x mvas.C(\"%s\",2)", fName ), "Plots the Rarity of each classifier for the test data (macro mvas.C(...,2)) - background distribution should be uniform", buttonType, defaultRequiredClassifier ); ActionButton( cbar, Form( "(%ia) Classifier Cut Efficiencies: S/sqrt(S+B)", ++ic ), Form( ".x mvaeffs.C+(\"%s\",\"S/sqrt(S+B)\")", fName), "Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.C)", buttonType, defaultRequiredClassifier ); ActionButton( cbar, Form( "(%ia) Classifier Before-Cut Efficiencies: B/sqrt(S+B)", ++ic ), Form( ".x mvaeffs_beforecut.C+(\"%s\",\"B/sqrt(S+B)\")", fName), "Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.C)", buttonType, defaultRequiredClassifier ); ActionButton( cbar, Form( "(%ia) Classifier Before-Cut Efficiencies: B/sqrt(S+B) @B_Purity=0.95", ++ic ), Form( ".x mvaeffs_beforecut.C+(\"%s\",\"B/sqrt(S+B)\",\"0.95\")", fName), "Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.C)", buttonType, defaultRequiredClassifier ); ActionButton( cbar, Form( "(%ia) Classifier Before-Cut Efficiencies: B/sqrt(S+B) @B_Purity=0.90", ++ic ), Form( ".x mvaeffs_beforecut.C+(\"%s\",\"B/sqrt(S+B)\",\"0.90\")", fName), "Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.C)", buttonType, defaultRequiredClassifier ); ActionButton( cbar, Form( "(%ia) Classifier Before-Cut Efficiencies: B/sqrt(S+B) @B_Purity=0.85", ++ic ), Form( ".x mvaeffs_beforecut.C+(\"%s\",\"B/sqrt(S+B)\",\"0.85\")", fName), "Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.C)", buttonType, defaultRequiredClassifier ); ActionButton( cbar, Form( "(%ia) Classifier Before-Cut Efficiencies: B/S", ++ic ), Form( ".x mvaeffs_beforecut.C+(\"%s\",\"B/S\")", fName), "Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.C)", buttonType, defaultRequiredClassifier ); ActionButton( cbar, Form( "(%ia) Classifier Before-Cut Efficiencies: B/S @B_Purity=0.95", ++ic ), Form( ".x mvaeffs_beforecut.C+(\"%s\",\"B/S\",\"0.95\")", fName), "Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.C)", buttonType, defaultRequiredClassifier ); ActionButton( cbar, Form( "(%ia) Classifier Before-Cut Efficiencies: B/S @B_Purity=0.90", ++ic ), Form( ".x mvaeffs_beforecut.C+(\"%s\",\"B/S\",\"0.90\")", fName), "Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.C)", buttonType, defaultRequiredClassifier ); ActionButton( cbar, Form( "(%ia) Classifier Before-Cut Efficiencies: B/S @B_Purity=0.85", ++ic ), Form( ".x mvaeffs_beforecut.C+(\"%s\",\"B/S\",\"0.85\")", fName), "Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.C)", buttonType, defaultRequiredClassifier ); ActionButton( cbar, Form( "(%ia) Classifier Before-Cut Efficiencies: B/S @B_Purity=0.80", ++ic ), Form( ".x mvaeffs_beforecut.C+(\"%s\",\"B/S\",\"0.80\")", fName), "Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.C)", buttonType, defaultRequiredClassifier ); ActionButton( cbar, Form( "(%ia) Classifier Cut Efficiencies: S/B ", ++ic ), Form( ".x mvaeffs.C+(\"%s\",\"S/B\")", fName), "Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.C)", buttonType, defaultRequiredClassifier ); ActionButton( cbar, Form( "(%ib) Classifier Background Rejection vs Signal Efficiency (ROC curve)", ic ), Form( ".x efficiencies.C(\"%s\")", fName ), "Plots background rejection vs signal efficiencies (macro efficiencies.C) [\"ROC\" stands for \"Receiver Operation Characteristics\"]", buttonType, defaultRequiredClassifier ); TString title = Form( "(%i) Parallel Coordinates (requires ROOT-version >= 5.17)", ++ic ); ActionButton( cbar, title, Form( ".x paracoor.C(\"%s\")", fName ), "Plots parallel coordinates for classifiers and input variables (macro paracoor.C, requires ROOT >= 5.17)", buttonType, defaultRequiredClassifier ); // parallel coordinates only exist since ROOT 5.17 #if ROOT_VERSION_CODE < ROOT_VERSION(5,17,0) TMVAGui_inactiveButtons.push_back( title ); #endif ActionButton( cbar, Form( "(%i) PDFs of Classifiers (requires \"CreateMVAPdfs\" option set)", ++ic ), Form( ".x probas.C(\"%s\")", fName ), "Plots the PDFs of the classifier output distributions for signal and background - if requested (macro probas.C)", buttonType, defaultRequiredClassifier ); ActionButton( cbar, Form( "(%i) Likelihood Reference Distributiuons", ++ic), Form( ".x likelihoodrefs.C(\"%s\")", fName ), "Plots to verify the likelihood reference distributions (macro likelihoodrefs.C)", buttonType, "Likelihood" ); ActionButton( cbar, Form( "(%ia) Network Architecture (MLP)", ++ic ), Form( ".x network.C(\"%s\")", fName ), "Plots the MLP weights (macro network.C)", buttonType, "MLP" ); ActionButton( cbar, Form( "(%ib) Network Convergence Test (MLP)", ic ), Form( ".x annconvergencetest.C(\"%s\")", fName ), "Plots error estimator versus training epoch for training and test samples (macro annconvergencetest.C)", buttonType, "MLP" ); ActionButton( cbar, Form( "(%i) Decision Trees (BDT)", ++ic ), Form( ".x BDT.C+(\"%s\")", fName ), "Plots the Decision Trees trained by BDT algorithms (macro BDT.C(itree,...))", buttonType, "BDT" ); ActionButton( cbar, Form( "(%i) Decision Tree Control Plots (BDT)", ++ic ), Form( ".x BDTControlPlots.C(\"%s\")", fName ), "Plots to monitor boosting and pruning of decision trees (macro BDTControlPlots.C)", buttonType, "BDT" ); // ActionButton( cbar, // Form( "(%i) Monitor Decision Tree Boosting", ++ic ), // Form( ".x BDTBoostWatch.C+(\"%s\")", fName ), // "Plots separation obtained by BDT method as function of boosting steps (macro BDTBoostWatch.C(itree,...))", // buttonType, "BDT" ); // ActionButton( cbar, // Form( "(%i) Rule Ensemble Importance Plots (RuleFit)", ++ic ), // Form( ".x rulevis.C(\"%s\",0)", fName ), // "Plots all input variables with rule ensemble weights, including linear terms (macro rulevis.C)", // buttonType, "RuleFit" ); ActionButton( cbar, Form( "(%i) Plot Foams (PDEFoam)", ++ic ), Form( ".x PlotFoams.C", fName ), "Plot Foams (macro PlotFoams.C)", buttonType, "PDEFoam" ); ActionButton( cbar, Form( "(%i) General Boost Control Plots", ++ic ), Form( ".x BoostControlPlots.C(\"%s\")", fName ), "Plots to monitor boosting of general classifiers (macro BoostControlPlots.C)", buttonType, "Boost" ); cbar->AddSeparator(); cbar->AddButton( Form( "(%i) Quit", ++ic ), ".q", "Quit", buttonType ); // set the style cbar->SetTextColor("black"); // there seems to be a bug in ROOT: font jumps back to default after pressing on >2 different buttons // cbar->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1"); // draw cbar->Show(); // indicate inactive buttons for (UInt_t i=0; i<TMVAGui_inactiveButtons.size(); i++) cbar->SetButtonState( TMVAGui_inactiveButtons[i], 3 ); if (TMVAGui_inactiveButtons.size() > 0) { cout << "=== Note: inactive buttons indicate that the corresponding classifiers were not trained ===" << endl; } gROOT->SaveContext(); }
void Drawfit(){ int sth=1, Gth=0; TFile *f = TFile::Open(outG); if(sth==0){TString dirname = "std";} else if(sth==1){TString dirname ="Gri055";} else {TString dirname ="Gri101";} TObjString* dataname = (TObjString*)f->Get(Form("dataname")); TObjString* histoname = (TObjString*)f->Get(Form("histoname")); TString name; if(Gth==0) name = "G0"; else if(Gth<nGlau) name = Form("Glau_%d",Gth); else name = Form("bin_%d",Gth-nGlau+1); TObjString* Glaubername = (TObjString*)f->Get(Form("%s/%s/Glaubername",dirname.Data(),name.Data())); TVectorD* xmin = (TVectorD*)f->Get(Form("%s/%s/xmin",dirname.Data(),name.Data())); TVectorD* xmax = (TVectorD*)f->Get(Form("%s/%s/xmax",dirname.Data(),name.Data())); TVectorD* mubest = (TVectorD*)f->Get(Form("%s/%s/mubest",dirname.Data(),name.Data())); TVectorD* kbest = (TVectorD*)f->Get(Form("%s/%s/kbest",dirname.Data(),name.Data())); TVectorD* Ndf = (TVectorD*)f->Get(Form("%s/%s/Ndf",dirname.Data(),name.Data())); TVectorD* chis = (TVectorD*)f->Get(Form("%s/%s/chis",dirname.Data(),name.Data())); TVectorD *kpoint = (TVectorD*)f->Get(Form("%s/%s/kpoint",dirname.Data(),name.Data())); TFile *fdata = TFile::Open(dataname->GetString()); TH1D *histo_obs = (TH1D*)fdata->Get(histoname->GetString()); TFile *fGlauber = TFile::Open(Glaubername->GetString()); int binnum = histo_obs->GetNbinsX(); double Minx = histo_obs->GetXaxis()->GetXmin(); double Maxx = histo_obs->GetXaxis()->GetXmax(); double binsize = (Double_t)(Maxx-Minx)/binnum; int xbinmin=(int)(((*xmin)[0]-Minx)/binsize); int xbinmax=(int)(((*xmax)[0]-Minx)/binsize); TH1D *histo_exp = new TH1D("histo_exp","Simulated distribution;Multiplicity;Event Fraction",binnum,Minx,Maxx); //histo_obs->Sumw2(); //histo_exp->Sumw2(); Int_t ibin; TH1D *histo_obs_norm = (TH1D*)histo_obs->Clone(); histo_obs_norm->Scale(1/histo_obs->Integral(xbinmin,xbinmax)); TF1 *NBD_fun = new TF1("NBD_fun","[0]*TMath::Gamma(x+[1])/(TMath::Gamma(x+1)*TMath::Gamma([1]))*TMath::Power([2]/[1],x)/TMath::Power([2]/[1]+1,x+[1])",0,100); NBD_fun->SetParameter(0,1); //[0]: Normalized constant NBD_fun->SetParameter(1,(*kbest)[0]); //[1]: k value NBD_fun->SetParameter(2,(*mubest)[0]); //[2]: mu value TTree *t = (TTree*) fGlauber->Get("nt_p_Pb"); Long_t Nevent; Nevent = (Long_t) t->GetEntries(); Long_t Ev; Int_t Bino; Double_t Para, Bi_Para, Mult; Float_t Ncoll; t->SetBranchAddress("Ncoll",&Ncoll); for(Ev=0; Ev<Nevent; Ev++){ if(Ev%100000==0) cout<<"Have run "<<Ev<<" events"<<endl; t->GetEntry(Ev); Para = 0; //make sure that Para doesn't accumulate through loops for(Bino=0; Bino<Ncoll; Bino++){ Bi_Para = NBD_fun->GetRandom(); Para += Bi_Para; } histo_exp->Fill(Para); } Double_t SumEvent, scale; SumEvent = histo_exp->Integral(xbinmin,xbinmax); scale = 1/SumEvent; TH1D *histo_exp_norm = (TH1D*) histo_exp->Clone(); histo_exp_norm->Scale(scale); gStyle->SetOptStat(kFALSE); TCanvas *c1 = new TCanvas(); c1->SetLogy(); histo_obs_norm->GetXaxis()->SetRangeUser(0,100); histo_obs_norm->SetMaximum(1.0); histo_obs_norm->GetXaxis()->SetTitle("HF #Sigma E_{T} |#eta|>4"); histo_obs_norm->GetYaxis()->SetTitle("Event Fraction"); histo_obs_norm->SetTitle(""); histo_obs_norm->SetLineColor(1); histo_obs_norm->SetMarkerStyle(24); histo_obs_norm->SetMarkerColor(1); histo_obs_norm->SetMarkerSize(1.5); histo_obs_norm->Draw("P"); TLegend *leg = new TLegend(0.56, 0.7, 0.8, 0.9); leg->SetFillColor(10); leg->SetFillStyle(0); leg->SetBorderSize(0.035); leg->SetTextFont(42); leg->SetTextSize(0.045); leg->AddEntry(histo_obs_norm,"CMS pPb real data","p"); leg->AddEntry(histo_exp_norm,Form("NBD Fit, #mu=%.3f, k=%.3f",(*mubest)[0],(*kbest)[0]),"l"); leg->Draw("same"); TLatex *tex1= new TLatex(0.2,0.8,Form("#chi^{2}/NDF=%.1f/%.f",(*chis)[0],(*Ndf)[0])); TLatex *tex2= new TLatex(0.6,0.65,Form("fit range %.f<x<%.f",(*xmin)[0],(*xmax)[0])); tex1->SetNDC(); tex2->SetNDC(); tex1->SetTextColor(1); tex2->SetTextColor(1); tex1->SetTextSize(0.045); tex2->SetTextSize(0.045); tex1->SetTextFont(42); tex2->SetTextFont(42); tex1->Draw("same"); tex2->Draw("same"); for(int i=0;i<N-1;i++){ TH1D *h2_Clone = (TH1D*)histo_exp_norm->Clone(); h2_Clone->SetFillColor(color_[i]); h2_Clone->GetXaxis()->SetRangeUser((*kpoint)[i],(*kpoint)[i+1]); h2_Clone->Draw("same"); } c1->SaveAs(Form("%sfit.png",dirname.Data())); }