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 }
int reader_wrapper::getTree(TString infile, TString treename, TString outfile) { m_infile = TFile::Open(infile,"update"); if (nullptr == m_infile || m_infile->IsZombie() || m_infile->GetNkeys() <= 0) { std::cerr << "File " << infile << " could not be opened properly." << std::endl; return 1; } m_intree = dynamic_cast<TTree*>(m_infile->Get(treename.Data())); if (nullptr == m_intree) { std::cerr << "Tree " << treename << " could not be opened properly." << std::endl; return 2; } m_outfile = TFile::Open(outfile,"create"); if (nullptr == m_outfile || m_outfile->IsZombie()) { std::cerr << "File " << outfile << " could not be opened properly." << std::endl; return 3; } return 0; }
void plotr(int top){ if (setup("vm","","pol__")==kFALSE) return; c = new TCanvas("R", "R"); ct = new TCanvas("ct","ct"); c->AddExec("tnail","tnail()"); int itop = top-1; TFile* fy = _fyexp[itop]; int nq2wbins = fy->GetNkeys(); int nrows = 4; int ncols = nq2wbins/nrows; c->Divide(nrows, ncols); TIter nextkey(fy->GetListOfKeys()); TKey *key; int iq2wbin = 0; while (key = (TKey*)nextkey()) { TString Q2Wdirname = key->GetName(); if(Q2Wdirname.EqualTo("hYW_Dir") || Q2Wdirname.EqualTo("hYW"))continue; cout << "Q2Wdirname = " << Q2Wdirname << endl; TString hname_pos = TString::Format("%s/hPhi_POS/Varset1/theta/hRvVar",Q2Wdirname.Data()); TString hname_neg = TString::Format("%s/hPhi_NEG/Varset1/theta/hRvVar",Q2Wdirname.Data()); cout << "hname_pos = " << hname_pos << endl; cout << "hname_neg = " << hname_neg << endl; TH1D* hpos = (TH1D*)fy->Get(hname_pos); TH1D* hneg = (TH1D*)fy->Get(hname_neg); if (hpos==NULL || hneg==NULL) cout << "histogram not found" << endl; //cosmetics and display hpos->SetLineColor(kRed); hneg->SetLineColor(kBlue); c->cd(iq2wbin+1); hpos->Draw(); hneg->Draw("sames"); iq2wbin+=1; } c->Update(); }
void MainWindow::initROOT() { // resultFile = new TFile(resultFileLineEdit->text().toStdString().c_str(), "RECREATE"); QString inputFileList = this->inputFileListLineEdit->text(); QFile file(inputFileList); if (!file.open(QFile::ReadOnly | QFile::Text)) { std::cout << "Can not open file for reading: " << qPrintable(file.errorString()) << std::endl; } chain = new TChain("AMPT"); QTextStream in(&file); while (!in.atEnd()) { QString eachRootFile = in.readLine(); TFile *testRootFile = new TFile(eachRootFile.toStdString().c_str()); if (!testRootFile || !testRootFile->IsOpen() || !testRootFile->GetNkeys()) { std::cout << "The root file is bad :" << qPrintable(eachRootFile) << std::endl; } else { chain->Add(eachRootFile.toStdString().c_str()); } delete testRootFile; } file.close(); }
// ------------------ Here is the actual method ----------------------------------------- void doEvents(const Char_t *fileList, const Char_t *outputname) { Int_t nEvents = 1000; Int_t nfiles = 100; // // First load some shared libraries we need // if (gClassTable->GetID("TTable") < 0) { gSystem->Load("libStar"); gSystem->Load("libPhysics"); } gROOT->LoadMacro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C"); loadSharedLibraries(); gSystem->Load("StarMagField"); gSystem->Load("StMagF"); gSystem->Load("StTpcDb"); // gSystem->Load("StDbUtilities"); gSystem->Load("StDaqLib"); gSystem->Load("StDbBroker"); gSystem->Load("StDetectorDbMaker"); gSystem->Load("StDbUtilities"); gSystem->Load("St_db_Maker"); gSystem->Load("StEvent"); gSystem->Load("StEventMaker"); gSystem->Load("StarMagField"); gSystem->Load("StTofUtil"); gSystem->Load("StVpdAnalysisMaker"); // // Handling depends on whether file is a ROOT file or XDF file // chain = new StChain("StChain"); delete setFiles; setFiles =0; if (fileList) { //Normal case setFiles= new StFile(); } else { // return; } ifstream* inputStream = new ifstream; inputStream->open(fileList); if (!(inputStream)) { cout << "can not open list file" << endl; return; } cout<<"Open file list: --- "<<fileList<<endl; char line[512]; for (;inputStream->good();) { inputStream->getline(line,512); if ( inputStream->good() ) { //cout<<" root file "<<line<<endl; TFile *ftmp = new TFile(line); //---------- if (!(ftmp->IsOpen())) { cout<<line<<" open failed ! not chained"<<endl; continue; } if (ftmp->IsZombie()) { cout<<"sth. very wrong with "<<line<<", not chained "<<endl; continue; } if (ftmp->TestBit(1024)) { cout<<"revocer procedure applied to "<<line<<endl; continue; } //-------------------------- if( ftmp && ftmp->IsOpen() && ftmp->GetNkeys()) { cout << "add file " << line << endl; setFiles->AddFile(line); } else { cout << " cannot open file " << line << endl; } delete ftmp; } } StMuDstMaker* muDstMaker = new StMuDstMaker(0,0,"",fileList,"MuDst.root",nfiles); muDstMaker->SetStatus("*",0); muDstMaker->SetStatus("MuEvent",1); muDstMaker->SetStatus("TofRawData",1); cout<<endl<<"============ Data Base ========="<<endl; dbMk = new St_db_Maker("db","MySQL:StarDb","$STAR/StarDb","StarDb"); StVpdAnalysisMaker *vpdAna = new StVpdAnalysisMaker(); vpdAna->SetDebug(); // // Initialize chain // Int_t iInit = chain->Init(); if (iInit) chain->Fatal(iInit,"on init"); chain->PrintInfo(); // // Event loop // int istat = 0, i = 1; EventLoop: if (i <= nEvents && istat != 2) { cout << endl << "============================ Event " << i << " start ============================" << endl; chain->Clear(); istat = chain->Make(i); if (istat == 2) {cout << "Last event processed. Status = " << istat << endl;} if (istat == 3) {cout << "Error event processed. Status = " << istat << endl;} // gObjectTable->Print(); i++; goto EventLoop; } i--; cout<<endl<<"============================ Event "<<i<<" finish ============================"<<endl; // // Chain Finish // if (nEvents > 1) { chain->Finish(); } }
int main(int argc, char ** argv) { TStopwatch comulativeWatch; comulativeWatch.Start(true); readInputs(argc,argv); cout<<"Currrent Subversion Revision: "<<SVN_REV<<endl; cout << "starting main loop.." << endl; RunListOK = ReadRunList(); if(!RunListOK)exit(-1); TSystem* sys = gSystem; std::string currentDir = sys->pwd(); for (unsigned int i = 0; i < RunParameters.size(); i++) { cout << RunParameters[i].getRunNumber(); if (i+1 < RunParameters.size()) cout << ", "; } cout << " will be analysed.." << endl; if (!RunListOK) return 0; /**Start with Analyising, read RunParameteres of the Run and start analysis with that parameters */ for (unsigned int i = 0; i < RunParameters.size(); i++) { TStopwatch runWatch; runWatch.Start(true); RunParameters[i].Print(); bool DO_ALIGNMENT = RunParameters[i].doAlignment(); bool DO_ALIGNMENTANALYSIS = RunParameters[i].doAlignmentAnalysis(); bool DO_TRANSPARENT_ANALYSIS = RunParameters[i].doTransparentAnalysis(); time_t rawtime; tm *timestamp; time (&rawtime); timestamp = gmtime(&rawtime); ostringstream logfilename; logfilename << "analyse_log_" << RunParameters[i].getRunNumber() << "_" << timestamp->tm_year << "-" << timestamp->tm_mon << "-" << timestamp->tm_mday << "." << timestamp->tm_hour << "." << timestamp->tm_min << "." << timestamp->tm_sec << ".log"; // // FILE *log; // log = freopen(logfilename.str().c_str(), "w", stdout); TSettings *settings = 0; cout<<"settings"<<endl; settings = new TSettings((TRunInfo*)&RunParameters[i]); TResults *currentResults =new TResults(settings); currentResults->Print(); TRawEventSaver *eventSaver; eventSaver = new TRawEventSaver(settings); eventSaver->saveEvents(RunParameters[i].getEvents()); delete eventSaver; //Calculate Pedestal sys->cd(currentDir.c_str()); TPedestalCalculation* pedestalCalculation; pedestalCalculation = new TPedestalCalculation(settings); pedestalCalculation->calculateSlidingPedestals(RunParameters[i].getEvents()); delete pedestalCalculation; if(RunParameters[i].doPedestalAnalysis()){ sys->cd(currentDir.c_str()); TAnalysisOfPedestal *analysisOfPedestal; analysisOfPedestal = new TAnalysisOfPedestal(settings); analysisOfPedestal->setResults(currentResults); analysisOfPedestal->doAnalysis(RunParameters[i].getEvents()); delete analysisOfPedestal; } THTMLGenerator *htmlGen = new THTMLGenerator(settings); htmlGen->setFileGeneratingPath(settings->getAbsoluteOuputPath(true)); htmlGen->setMainPath("./"); htmlGen->setSubdirPath(""); htmlGen->setFileName("overview.html"); htmlGen->addSection("Pedestal","<a href=\"./pedestalAnalysis/pedestal.html\">PEDESTAL</a>"); htmlGen->addSection("Clustering","<a href=\"./clustering/clustering.html\">CLUSTERING</a>"); htmlGen->addSection("Selection","<a href=\"./selections/selection.html\">SELECTION</a>"); htmlGen->addSection("Alignment","<a href=\"./alignment/alignment.html\">ALIGNMENT</a>"); htmlGen->addSection("Landau","<a href=\"./selectionAnalysis/landaus.html\">LANDAU-DISTRIBUTIONS</a>"); htmlGen->generateHTMLFile(); delete htmlGen; sys->cd(currentDir.c_str()); TClustering* clustering; clustering=new TClustering(settings);//int seedDetSigma=10,int hitDetSigma=7,int seedDiaSigma=5, int hitDiaSigma=3); clustering->ClusterEvents(RunParameters[i].getEvents()); delete clustering; if(RunParameters[i].doClusterAnalysis()){ sys->cd(currentDir.c_str()); TAnalysisOfClustering* analysisClustering; analysisClustering = new TAnalysisOfClustering(settings); analysisClustering->setResults(currentResults); analysisClustering->doAnalysis(RunParameters[i].getEvents()); delete analysisClustering; } sys->cd(currentDir.c_str()); TSelectionClass* selectionClass = new TSelectionClass(settings); selectionClass->SetResults(currentResults); selectionClass->MakeSelection(RunParameters[i].getEvents()); delete selectionClass; if(RunParameters[i].doSelectionAnalysis()){ sys->cd(currentDir.c_str()); TAnalysisOfSelection *analysisSelection=new TAnalysisOfSelection(settings); analysisSelection->doAnalysis(RunParameters[i].getEvents()); delete analysisSelection; } if (DO_ALIGNMENT){ sys->cd(currentDir.c_str()); TAlignment *alignment = new TAlignment(settings); // alignment->setSettings(settings); //alignment->PrintEvents(1511,1501); alignment->Align(RunParameters[i].getEvents()); delete alignment; } if(DO_ALIGNMENTANALYSIS){ sys->cd(currentDir.c_str()); TAnalysisOfAlignment *anaAlignment; anaAlignment=new TAnalysisOfAlignment(settings); anaAlignment->doAnalysis(RunParameters[i].getEvents()); delete anaAlignment; } if (DO_TRANSPARENT_ANALYSIS) { TTransparentAnalysis *transpAna; transpAna = new TTransparentAnalysis(settings); transpAna->setResults(currentResults); transpAna->analyze(RunParameters[i].getEvents(),RunParameters.at(i).getStartEvent()); delete transpAna; } if (settings && settings->doTransparentAlignmnet()){ sys->cd(currentDir.c_str()); TAlignment *alignment = new TAlignment(settings,TSettings::transparentMode); alignment->createTransparentEventVectors(RunParameters[i].getEvents()); // alignment->setSettings(settings); //alignment->PrintEvents(1511,1501); alignment->Align(RunParameters[i].getEvents(),0,TAlignment::diaAlignment); delete alignment; TTransparentAnalysis *transpAna; transpAna = new TTransparentAnalysis(settings,TSettings::transparentMode); transpAna->setResults(currentResults); transpAna->analyze(RunParameters[i].getEvents(),RunParameters.at(i).getStartEvent()); delete transpAna; } cout<<"PRINT RESULTS"<<endl; currentResults->Print(); cout<<"SAVE RESULTS"<<endl; // currentResults->saveResults(settings->getResultsRootFilePath()); TFile* file = new TFile (settings->getResultsRootFilePath().c_str(),"RECREATE"); file->Print(); file->ls(); file->SetName("fileName"); file->cd(); cout<<"KEYS: "<<file->GetNkeys()<<endl; file->GetListOfKeys()->Print(); cout<<"Write"<<endl; currentResults->Write("test"); cout<<"CLOSE FILE"<<endl; file->Close(); // if (currentResults){ // cout<<"DELETE RESULTS"<<endl; // delete currentResults; // cout<<"#"<<endl;; // } cout<<"saved results..."<<endl; runWatch.Stop(); cout<<"needed Time for Run "<<RunParameters[i].getRunNumber()<<":"<<endl; runWatch.Print(); cout<<"needed Time for Run "<<RunParameters[i].getRunNumber()<<":\n\t"<<flush; runWatch.Print(); if (settings!=NULL){ cout<<"delete Settings..."<<endl; delete settings; cout<<"DONE_SETTINGS"<<endl; } cout<<"DONE with Analysis of Run "<< RunParameters[i].getRunNumber(); cout<<": "<<i+1<<"/"<<RunParameters.size()<<endl; } cout<<"DONE with Analysis of all "<<RunParameters.size()<<" Runs from RunList.ini"<<endl; cout<<"total time for all analysis:\n\t"<<flush; cout<<"time for all analysis:"<<endl; comulativeWatch.Print(); cout<<"DONE_ALL"<<endl; return 0; }
void plotphi(int top, bool phi=kFALSE){ if (setup("vm","","pol__")==kFALSE) return; gStyle->SetOptFit(1111); //pcev = 1111 //gStyle->SetTitleW(1.5); int itop = top-1; TFile* fy = _fyexp[itop]; int nq2wbins = fy->GetNkeys(); TIter nextkey(fy->GetListOfKeys()); TKey *key; int iq2wbin = 0; while (key = (TKey*)nextkey()) { TString Q2Wdirname = key->GetName(); if(Q2Wdirname.EqualTo("hYW_Dir") || Q2Wdirname.EqualTo("hYW"))continue; cout << "Q2Wdirname = " << Q2Wdirname << endl; THStack* hs[10]; TF1 *fphi = new TF1("fphi", "([0] + [1]*cos(x*TMath::DegToRad()) + [2]*cos(2*x*TMath::DegToRad()) + [3]*sin(x*TMath::DegToRad()))",0, 360); fphi->SetParameter(0,1); fphi->SetParameter(1,10); fphi->SetParameter(2,20); fphi->SetParameter(3,100); fphi->SetParName(0, "A"); fphi->SetParName(1, "B"); fphi->SetParName(2, "C"); fphi->SetParName(3, "hPR"); for (int i = 0; i < 10; i++) { TString hname_unp = TString::Format("%s/hPhi/Varset1/theta/hphi_%02d",Q2Wdirname.Data(),i+1); TString hname_pos = TString::Format("%s/hPhi_POS/Varset1/theta/hphi_%02d",Q2Wdirname.Data(),i+1); TString hname_neg = TString::Format("%s/hPhi_NEG/Varset1/theta/hphi_%02d",Q2Wdirname.Data(),i+1); cout << "hname_unp = " << hname_unp << endl; cout << "hname_pos = " << hname_pos << endl; cout << "hname_neg = " << hname_neg << endl; TH1D* hunp = (TH1D*)fy->Get(hname_unp); TH1D* hpos = (TH1D*)fy->Get(hname_pos); TH1D* hneg = (TH1D*)fy->Get(hname_neg); if (hunp==NULL || hpos==NULL || hneg==NULL) cout << "histogram not found" << endl; hunp->SetLineColor(kBlack); hpos->SetLineColor(kRed); hneg->SetLineColor(kBlue); hunp->Fit(fphi); hpos->Fit(fphi); hneg->Fit(fphi); //! Modify titles TObjArray *tarr; char t[100]; TPaveText *ptunp = new TPaveText(0.0, 0.9, 1.0, 1, "NDC"); TString tunp = hunp->GetTitle(); tarr = tunp.Tokenize("|"); sprintf(t, "%s:%s:%s", tarr->At(1)->GetName(), tarr->At(2)->GetName(), tarr->At(3)->GetName()); ptunp->AddText(tarr->At(0)->GetName()); ptunp->AddText(t); hunp->SetTitle(""); TPaveText *ptpos = new TPaveText(0.0, 0.9, 1.0, 1, "NDC"); TString tpos = hpos->GetTitle(); tarr = tpos.Tokenize("|"); sprintf(t, "%s:%s:%s", tarr->At(1)->GetName(), tarr->At(2)->GetName(), tarr->At(3)->GetName()); ptpos->AddText(tarr->At(0)->GetName()); ptpos->AddText(t); hpos->SetTitle(""); TPaveText *ptneg = new TPaveText(0.0, 0.9, 1.0, 1, "NDC"); TString tneg = hneg->GetTitle(); tarr = tneg.Tokenize("|"); sprintf(t, "%s:%s:%s", tarr->At(1)->GetName(), tarr->At(2)->GetName(), tarr->At(3)->GetName()); ptneg->AddText(tarr->At(0)->GetName()); ptneg->AddText(t); hneg->SetTitle(""); //! Draw histograms TCanvas *c = new TCanvas(hpos->GetName(),hpos->GetName(),900, 600); c->Divide(3,1); c->cd(1); hunp->Draw(); ptunp->Draw(); c->cd(2); hpos->Draw(); ptpos->Draw(); c->cd(3); hneg->Draw(); ptneg->Draw(); TString dir = TString::Format("./polobs/top%d/%s/Varset1/theta", top, Q2Wdirname.Data()); gSystem->mkdir(dir,1); c->SaveAs(TString::Format("%s/%s.png", dir.Data(), c->GetName())); c->Close(); c->Delete(); } } }