void anachain( const Char_t *ddname = "/star/data05/scratch/jwebb/checkin/", const Char_t *pref="R5", const Char_t *ffname = ".root", Int_t nmax=50000 ) { gROOT->LoadMacro("macros/loadlibs.C"); loadlibs(); c = new TCanvas("c","A canvas",500,500); mTree = new TChain("mTree","A pi0 tree"); TSystemDirectory *dir = new TSystemDirectory("pwd",ddname); TList *files = dir->GetListOfFiles(); TIter next( files ); TSystemFile *file = 0; Int_t nf = 0; TList *listOfEmpties=new TList(); while ( (file = (TSystemFile *)next() ) ) { //-- Get the filename -- TString fname = file -> GetName(); if ( !fname.Contains(ffname) ) continue; if ( !fname.Contains(pref) ) continue; Bool_t pi0tree = 0; /// Open the file and determine if it contains /// a TTree TFile pfile( fname ); TTree *mytree = (TTree *)pfile.Get("mTree"); if ( mytree ) pi0tree = 1; pfile.Close(); //-- If we have the trees, add them if ( pi0tree ) { std::cout << "Adding " << fname << " npi0tree=" << mTree->GetEntries() << std::endl; mTree -> Add(fname+"/mTree"); nf++; } if ( nf > nmax ) break; } std::cout << "-- anachain -----------------------------------" << std::endl; std::cout << std::endl; std::cout << "loaded " << nf << " files" << std::endl; }
void stack_temp(std::string outputFolder){ setNCUStyle(); gStyle->SetOptFit(0); gStyle->SetMarkerSize(0); gStyle->SetTitleSize(0.04,"XYZ"); gStyle->SetLabelSize(0.03,"XYZ"); gStyle->SetHistLineWidth(2); std::vector<string> infiles; TSystemDirectory *base = new TSystemDirectory("root","root"); base->SetDirectory(outputFolder.data()); TList *listOfFiles = base->GetListOfFiles(); TIter fileIt(listOfFiles); TFile *fileH = new TFile(); Long64_t nfiles = 0; while( (fileH = (TFile*)fileIt()) ){ std::string fileN = fileH->GetName(); std::string baseString = "root"; if( fileN.find(baseString) == std::string::npos ) continue; infiles.push_back(Form("%s/%s",outputFolder.data(),fileN.data())); nfiles++; } TFile *f_DY100 = NULL; TFile *f_DY200 = NULL; TFile *f_DY400 = NULL; TFile *f_DY600 = NULL; TFile *f_TTbar = NULL; TFile *f_WW = NULL; TFile *f_WZ = NULL; TFile *f_ZZ = NULL; TCanvas* c = new TCanvas("c","",0,0,1000,800); c->cd(); stackSamples(infiles,"corrPRmassAll_pDA","Corrected pruned mass",f_DY100,f_DY200,f_DY400,f_DY600,f_TTbar,f_WW,f_WZ,f_ZZ); c->Print("stackCorrPRmass.pdf("); c->cd(); stackSamples(infiles,"PRmassAll_pDA","Uncorrected pruned mass",f_DY100,f_DY200,f_DY400,f_DY600,f_TTbar,f_WW,f_WZ,f_ZZ); c->Print("stackCorrPRmass.pdf)"); }
void add_periods(const char *newname, const char *perioddir) { int i, j, K, N, L; char str[1024]; TList *keys; TFile *fIn; TFile *f0; TSystemFile *fSys; char prefix[128]; char *ptr; TNamed *obj; TH1D *h; TH1D *hist[MAXHIST]; TSystemDirectory *dir = new TSystemDirectory("MyDir", perioddir); TList *files = dir->GetListOfFiles(); if (!files) { printf("%s - nothing to do(files)\n", perioddir); delete dir; return; } N = files->GetEntries() - 2; if (N <= 1) { printf("%s - nothing to do\n", perioddir); delete dir; return; } TFile *fNew = new TFile(newname, "RECREATE"); if (!fNew->IsOpen()) { delete dir; delete files; return; } fSys = (TSystemFile *) files->At(2); if (!fSys) { printf("Can not open the first file\n"); delete dir; delete files; return; } sprintf(str, "%s/%s", perioddir, fSys->GetName()); f0 = new TFile(str); if (!f0->IsOpen()) { printf("Can not open the first file\n"); delete dir; delete files; return; } keys = f0->GetListOfKeys(); K = keys->GetEntries(); if (K <= 0) { printf("Nothing to do: K=0\n"); delete dir; delete files; return; } L = 0; for (j=0; j<K; j++) { obj = (TNamed *) keys->At(j); if (!obj) continue; obj = (TNamed *) f0->Get(obj->GetName()); if (!obj) continue; if (strcmp(obj->ClassName(), "TH1D")) continue; hist[L] = (TH1D *)obj; L++; } if (!L) { printf("Nothing to do: L=0\n"); f0->Close(); delete dir; delete files; return; } for (i=1; i<N; i++) { fSys = (TSystemFile *) files->At(i+2); // skip . and .. if (!fSys) continue; sprintf(str, "%s/%s", perioddir, fSys->GetName()); fIn = new TFile(str); if (!fIn->IsOpen()) continue; for (j=0; j<L; j++) { h = (TH1D *) fIn->Get(hist[j]->GetName()); if (!h) continue; hist[j]->Add(h); } // printf("%s\n", fSys->GetName()); fIn->Close(); } fNew->cd(); for (j=0; j<L; j++) hist[j]->Write(); fNew->Close(); f0->Close(); delete files; delete dir; }
TChain* CreateESDChain(const char* aDataDir = "ESDfiles.txt", Int_t aRuns = 20, Int_t offset = 0, Bool_t addFileName = kFALSE, Bool_t addFriend = kFALSE, const char* check = 0) { // creates chain of files in a given directory or file containing a list. // In case of directory the structure is expected as: // <aDataDir>/<dir0>/AliESDs.root // <aDataDir>/<dir1>/AliESDs.root // ... // // if addFileName is true the list only needs to contain the directories that contain the AliESDs.root files // if addFriend is true a file AliESDfriends.root is expected in the same directory and added to the chain as friend // if check is != 0 the files that work are written back into the textfile with the name check if (!aDataDir) return 0; Long_t id, size, flags, modtime; if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime)) { printf("%s not found.\n", aDataDir); return 0; } TChain* chain = new TChain("esdTree"); TChain* chainFriend = 0; if (addFriend) chainFriend = new TChain("esdFriendTree"); if (flags & 2) { TString execDir(gSystem->pwd()); TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir); TList* dirList = baseDir->GetListOfFiles(); Int_t nDirs = dirList->GetEntries(); gSystem->cd(execDir); Int_t count = 0; for (Int_t iDir=0; iDir<nDirs; ++iDir) { TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir); if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0) continue; if (offset > 0) { --offset; continue; } if (count++ == aRuns) break; TString presentDirName(aDataDir); presentDirName += "/"; presentDirName += presentDir->GetName(); chain->Add(presentDirName + "/AliESDs.root/esdTree"); } } else { // Open the input stream ifstream in; in.open(aDataDir); ofstream outfile; if (check) outfile.open(check); Int_t count = 0; // Read the input list of files and add them to the chain TString line; while (in.good()) { in >> line; if (line.Length() == 0) continue; if (offset > 0) { offset--; continue; } if (count++ == aRuns) break; TString esdFile(line); if (addFileName) esdFile += "/AliESDs.root"; TString esdFileFriend(esdFile); esdFileFriend.ReplaceAll("AliESDs.root", "AliESDfriends.root"); if (check) { TFile* file = TFile::Open(esdFile); if (!file) continue; file->Close(); if (chainFriend) { TFile* file = TFile::Open(esdFileFriend); if (!file) continue; file->Close(); } outfile << line.Data() << endl; printf("%s\n", line.Data()); } // add esd file chain->Add(esdFile); // add file if (chainFriend) chainFriend->Add(esdFileFriend); } in.close(); if (check) outfile.close(); } if (chainFriend) chain->AddFriend(chainFriend); return chain; }
void dataMCplots(std::string outputFolder, std::string pdfName){ std::vector<string> infiles; TSystemDirectory *base = new TSystemDirectory("root","root"); base->SetDirectory(outputFolder.data()); TList *listOfFiles = base->GetListOfFiles(); TIter fileIt(listOfFiles); TFile *fileH = new TFile(); Long64_t nfiles = 0; while( (fileH = (TFile*)fileIt()) ){ std::string fileN = fileH->GetName(); std::string baseString = "root"; if( fileN.find(baseString) == std::string::npos ) continue; infiles.push_back(Form("%s/%s",outputFolder.data(),fileN.data())); nfiles++; } TFile *f_DY100 = NULL; TFile *f_DY200 = NULL; TFile *f_DY400 = NULL; TFile *f_DY600 = NULL; TFile *f_TTbar = NULL; TFile *f_WW = NULL; TFile *f_WZ = NULL; TFile *f_ZZ = NULL; TFile *f_data0 = NULL; TFile *f_data1 = NULL; Double_t xSecDY100 = 147.4; Double_t xSecDY200 = 40.99; Double_t xSecDY400 = 5.678; Double_t xSecDY600 = 2.198; Double_t xSecTTbar = 831.76; Double_t xSecWW = 118.7; Double_t xSecWZ = 47.13; Double_t xSecZZ = 16.523; // xSecDY100 = xSecDY100 * 1.23; // xSecDY200 = xSecDY200 * 1.23; // xSecDY400 = xSecDY400 * 1.23; // xSecDY600 = xSecDY600 * 1.23; xSecDY100 = xSecDY100 * 1.588; xSecDY200 = xSecDY200 * 1.438; xSecDY400 = xSecDY400 * 1.494; xSecDY600 = xSecDY600 * 1.139; Double_t scaleDY100 = 0; Double_t scaleDY200 = 0; Double_t scaleDY400 = 0; Double_t scaleDY600 = 0; Double_t scaleTTbar = 0; Double_t scaleWW = 0; Double_t scaleWZ = 0; Double_t scaleZZ = 0; Double_t dummy = -1; for(unsigned int i = 0; i < infiles.size(); i++){ cout << "Input file: " << infiles[i] << endl; if( infiles[i].find("HT-100") != std::string::npos ) f_DY100 = getFile(infiles[i].data(), xSecDY100, &scaleDY100); if( infiles[i].find("HT-200") != std::string::npos ) f_DY200 = getFile(infiles[i].data(), xSecDY200, &scaleDY200); if( infiles[i].find("HT-400") != std::string::npos ) f_DY400 = getFile(infiles[i].data(), xSecDY400, &scaleDY400); if( infiles[i].find("HT-600") != std::string::npos ) f_DY600 = getFile(infiles[i].data(), xSecDY600, &scaleDY600); if( infiles[i].find("TT_") != std::string::npos ) f_TTbar = getFile(infiles[i].data(), xSecTTbar, &scaleTTbar); if( infiles[i].find("WW_") != std::string::npos ) f_WW = getFile(infiles[i].data(), xSecWW, &scaleWW); if( infiles[i].find("WZ_") != std::string::npos ) f_WZ = getFile(infiles[i].data(), xSecWZ, &scaleWZ); if( infiles[i].find("ZZ_") != std::string::npos ) f_ZZ = getFile(infiles[i].data(), xSecZZ, &scaleZZ); if( infiles[i].find("V12015") != std::string::npos ) f_data0 = getFile(infiles[i].data(), dummy, &dummy); if( infiles[i].find("V42015") != std::string::npos ) f_data1 = getFile(infiles[i].data(), dummy, &dummy); } setNCUStyle(true); Double_t up_height = 0.8; Double_t dw_correction = 1.455; Double_t dw_height = (1-up_height)*dw_correction; TCanvas c("c","",0,0,1000,900); c.Divide(1,2); TPad* c_up = (TPad*) c.GetListOfPrimitives()->FindObject("c_1"); TPad* c_dw = (TPad*) c.GetListOfPrimitives()->FindObject("c_2"); c_up->SetPad(0,1-up_height,1,1); c_dw->SetPad(0,0,1,dw_height); c_dw->SetBottomMargin(0.25); // To get the name of histograms TFile *f_ = TFile::Open(infiles[0].data()); f_->cd(); TDirectory *current_sourcedir = gDirectory; TIter nextkey( current_sourcedir->GetListOfKeys() ); TKey *key; vector<std::string> h_name; while ( (key = (TKey*)nextkey()) ) { TObject *obj = key->ReadObj(); if ( obj->IsA()->InheritsFrom("TH1") ) h_name.push_back(obj->GetTitle()); } // Draw and output for(unsigned int i = 0; i < h_name.size()-1; i++){ if( h_name[i]=="eleHoverE" || h_name[i]=="eleMiniIsoEA" || h_name[i]=="muMiniIsoEA" ) c_up->cd()->SetLogy(1); else c_up->cd()->SetLogy(0); TH1D *h_data = (TH1D*)(f_data1->Get(h_name[i].data()))->Clone("h_data"); TH1D *h_bkg = (TH1D*)(f_data1->Get(h_name[i].data()))->Clone("h_bkg"); myPlot(((TH1D*)(f_DY100->Get(h_name[i].data()))), ((TH1D*)(f_DY200->Get(h_name[i].data()))), ((TH1D*)(f_DY400->Get(h_name[i].data()))), ((TH1D*)(f_DY600->Get(h_name[i].data()))), ((TH1D*)(f_TTbar->Get(h_name[i].data()))), ((TH1D*)(f_WW->Get(h_name[i].data()))), ((TH1D*)(f_WZ->Get(h_name[i].data()))), ((TH1D*)(f_ZZ->Get(h_name[i].data()))), ((TH1D*)(f_data0->Get(h_name[i].data()))), ((TH1D*)(f_data1->Get(h_name[i].data()))), scaleDY100, scaleDY200, scaleDY400, scaleDY600, scaleTTbar, scaleWW, scaleWZ, scaleZZ, h_data, h_bkg); c_up->RedrawAxis(); c_dw->cd(); myRatio(h_data, h_bkg); c.Draw(); if( i == 0 ) c.Print(Form("%s.pdf(", pdfName.data()), "pdf"); else if( i == h_name.size()-2 ) c.Print(Form("%s.pdf)", pdfName.data()), "pdf"); else c.Print(Form("%s.pdf", pdfName.data()), "pdf"); } }
TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset) { // creates chain of files in a given directory or file containing a list. // In case of directory the structure is expected as: // <aDataDir>/<dir0>/AliAOD.root // <aDataDir>/<dir1>/AliAOD.root // ... if (!aDataDir) return 0; Long_t id, size, flags, modtime; if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime)) { printf("%s not found.\n", aDataDir); return 0; } TChain* chain = new TChain("aodTree"); TChain* chaingAlice = 0; if (flags & 2) { TString execDir(gSystem->pwd()); TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir); TList* dirList = baseDir->GetListOfFiles(); Int_t nDirs = dirList->GetEntries(); gSystem->cd(execDir); Int_t count = 0; for (Int_t iDir=0; iDir<nDirs; ++iDir) { TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir); if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0) continue; if (offset > 0) { --offset; continue; } if (count++ == aRuns) break; TString presentDirName(aDataDir); presentDirName += "/"; presentDirName += presentDir->GetName(); chain->Add(presentDirName + "/AliAOD.root/aodTree"); // cerr<<presentDirName<<endl; } } else { // Open the input stream ifstream in; in.open(aDataDir); Int_t count = 0; // Read the input list of files and add them to the chain TString aodfile; while(in.good()) { in >> aodfile; if (!aodfile.Contains("root")) continue; // protection if (offset > 0) { --offset; continue; } if (count++ == aRuns) break; // add aod file chain->Add(aodfile); } in.close(); } return chain; } // end of TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)