From 728f5c7afc6371e438eef6d72542ef7d7207526f Mon Sep 17 00:00:00 2001 From: kread Date: Sat, 17 Oct 2009 19:11:47 +0000 Subject: [PATCH] Macros to facilitate merging by PYTHIA pt hard bin. --- PWG4/macros/electrons/MergeFileInBins.C | 92 +++++++++++++++++++++++ PWG4/macros/electrons/mergeoutscaledi.jdl | 8 ++ PWG4/macros/electrons/mymerger.C | 83 ++++++++++++++++++++ 3 files changed, 183 insertions(+) create mode 100755 PWG4/macros/electrons/MergeFileInBins.C create mode 100644 PWG4/macros/electrons/mergeoutscaledi.jdl create mode 100644 PWG4/macros/electrons/mymerger.C diff --git a/PWG4/macros/electrons/MergeFileInBins.C b/PWG4/macros/electrons/MergeFileInBins.C new file mode 100755 index 00000000000..fd6afacda1c --- /dev/null +++ b/PWG4/macros/electrons/MergeFileInBins.C @@ -0,0 +1,92 @@ + +// +// Author: G. Balbastre +// Modified by K. Read +// +// Usage: +// After previously using mymerger.C to merge each PYHIA hard bin, +// do the following to download one file per pt bin: +// aliensh; cp histoss* file: +// Then, adjust binlist below to reflect which histograms are non-empty. +// Then, locally: +// root -b -x MergeFileInBins.C +// +// Note: This macro overwrites the downloaded histograms with the same names. +// It may be appropriate to make a backup of the histograms before running +// this macro. +// + +void MergeFileInBins() +{ + char name[128] ; + TFile * mfile; + TFile * sfile; + TList* list; + TList* newlist; + TString binlist = "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"; + + if (binlist.Length()) { + arr = binlist.Tokenize(" "); + TObjString *os; + TIter next(arr); + while ((os=(TObjString*)next())) { + printf("Rescaling histosscaled-merged%s.root\n",os->GetString().Data()); + + //Rescale histograms + sprintf(name,"histosscaled-merged%s.root",os->GetString().Data()); + mfile = new TFile(name,"read"); + list = (TList*) mfile->Get("histosscaled"); + mfile->Close(); + + TObject * h ; + Int_t split = ((TH1F*) list->FindObject("hCount"))->GetEntries(); + cout<<"scale with factor "<GetEntries()<GetName()); + newlist->SetName(name); + + for(Int_t iter = 0; iter < list->GetEntries(); iter++){ + h = list->At(iter); + if(h && (h->GetName()!="hCount")){ + if ( !strncmp(h->ClassName(),"TH",2) ) { + char name[128] ; + sprintf(name, "%s", h->GetName()) ; + //cout< (h->Clone(name)) ; + //if(fSumw2) hout->Sumw2(); + hout->Scale(1./split) ; + newlist->Add(hout) ; + } + } + } + + sprintf(name,"histosscaled-merged%s.root",os->GetString().Data()); + sfile = new TFile(name,"recreate"); + newlist->Write(); + sfile->Close(); + cout<GetString().Data()); + sprintf(name,"histosscaled-merged%s.root",os->GetString().Data()); + m.AddFile(name); + } + m.Merge(); + } + +} diff --git a/PWG4/macros/electrons/mergeoutscaledi.jdl b/PWG4/macros/electrons/mergeoutscaledi.jdl new file mode 100644 index 00000000000..ba02d884d05 --- /dev/null +++ b/PWG4/macros/electrons/mergeoutscaledi.jdl @@ -0,0 +1,8 @@ +Packages ={"VO_ALICE@ROOT::v5-24-00","VO_ALICE@APISCONFIG::V2.4"}; + +Arguments = "27498605 histosscaled.root histosscaled-merged$2.root kread /alice/cern.ch/user/k/kread/$1/output/$2"; +Executable = "/alice/bin/mergerootfile"; +Email = ""; +OutputFile = "histosscaled-merged$2.root@ALICE::CERN::ALICEDISK"; +InputFile = "LF:/alice/macros/mergerootfile.C"; +OutputDir = "/alice/cern.ch/user/k/kread/$1/output/merged"; diff --git a/PWG4/macros/electrons/mymerger.C b/PWG4/macros/electrons/mymerger.C new file mode 100644 index 00000000000..fabf83d0e01 --- /dev/null +++ b/PWG4/macros/electrons/mymerger.C @@ -0,0 +1,83 @@ + +// +// AliEn Initial PYTHIA pt hard bin-by-bin merging to prepare for rescaling +// Author: K. Read +// + +void mymerger() +{ + TString filename; + TString jdlfilename = "mergeoutscaledi.jdl"; + //TString worksubdir = "LHC09b4b"; + //Int_t maxbin = 15; + TString worksubdir = "LHC09b2ESDb"; + Int_t maxbin = 16; + + //Later do: aliensh; cd worksubdir/output/merged; cp histoss* file: + //And then process files locally with MergeFileInBins.C. + + gSystem->Load("libNetx.so") ; + gSystem->Load("libRAliEn.so"); + + TGrid::Connect("alien://") ; + if (gGrid && gGrid->IsConnected()) { + TString homedir = gGrid->GetHomeDirectory(); // has a trailing slash + TString workdir = homedir + worksubdir; + if (gGrid->Cd(workdir)) { + + // Upload and submit JDL if listed + if (jdlfilename.Length()) { + filename = Form("%s/%s", workdir.Data(), jdlfilename.Data()); + if (FileExists(filename)) gGrid->Rm(filename); + Info("Grid Upload", "Copying JDL file %s to your AliEn work directory", jdlfilename.Data()); + TFile::Cp(Form("file:%s",jdlfilename.Data()), Form("alien://%s", filename.Data())); + + for (Int_t index = 0; index <= maxbin; index++) { + TGridResult *res; + TString jobID = ""; + res = gGrid->Command(Form("submit %s %s %d", jdlfilename.Data(),worksubdir.Data(),index)); + Info("Launcher:", "Submitting %s %s %d", jdlfilename.Data(),worksubdir.Data(),index); + if (res) { + const char *cjobId = res->GetKey(0,"jobId"); + if (!cjobId) { + Error("Launcher:", "Your JDL %s could not be submitted", jdlfilename.Data()); + return; + } + else { + Info("Launcher:", "Your JDL %s was successfully submitted.\n\n\t\t\t THE JOB ID IS: %s\n", + jdlfilename.Data(), cjobId); + } + delete res; + } + } + } + + // Launch alien shell + gSystem->Exec("aliensh"); + + } + } +} + +Bool_t FileExists(const char *lfn) const +{ +// Returns true if file exists. + if (!gGrid) { + Error("FileExists", "No connection to grid"); + return kFALSE; + } + TGridResult *res = gGrid->Ls(lfn); + if (!res) return kFALSE; + TMap *map = dynamic_cast(res->At(0)); + if (!map) { + delete res; + return kFALSE; + } + TObjString *objs = dynamic_cast(map->GetValue("name")); + if (!objs || !objs->GetString().Length()) { + delete res; + return kFALSE; + } + delete res; + return kTRUE; +} -- 2.39.3