Macros to facilitate merging by PYTHIA pt hard bin.
authorkread <kread@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 17 Oct 2009 19:11:47 +0000 (19:11 +0000)
committerkread <kread@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 17 Oct 2009 19:11:47 +0000 (19:11 +0000)
PWG4/macros/electrons/MergeFileInBins.C [new file with mode: 0755]
PWG4/macros/electrons/mergeoutscaledi.jdl [new file with mode: 0644]
PWG4/macros/electrons/mymerger.C [new file with mode: 0644]

diff --git a/PWG4/macros/electrons/MergeFileInBins.C b/PWG4/macros/electrons/MergeFileInBins.C
new file mode 100755 (executable)
index 0000000..fd6afac
--- /dev/null
@@ -0,0 +1,92 @@
+\r
+//\r
+// Author: G. Balbastre\r
+// Modified by K. Read\r
+//\r
+// Usage: \r
+// After previously using mymerger.C to merge each PYHIA hard bin,\r
+// do the following to download one file per pt bin:\r
+// aliensh; cp histoss* file:       \r
+// Then, adjust binlist below to reflect which histograms are non-empty.\r
+// Then, locally:\r
+// root -b -x MergeFileInBins.C\r
+//\r
+// Note: This macro overwrites the downloaded histograms with the same names.\r
+// It may be appropriate to make a backup of the histograms before running\r
+// this macro.\r
+//\r
+\r
+void MergeFileInBins()\r
+{\r
+  char name[128] ;\r
+  TFile * mfile;\r
+  TFile * sfile;\r
+  TList* list;\r
+  TList* newlist;\r
+  TString binlist = "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15";\r
+\r
+  if (binlist.Length()) {\r
+    arr = binlist.Tokenize(" ");\r
+    TObjString *os;\r
+    TIter next(arr);\r
+    while ((os=(TObjString*)next())) {\r
+      printf("Rescaling histosscaled-merged%s.root\n",os->GetString().Data());\r
+       \r
+      //Rescale histograms\r
+      sprintf(name,"histosscaled-merged%s.root",os->GetString().Data());\r
+      mfile = new TFile(name,"read");\r
+      list = (TList*) mfile->Get("histosscaled");\r
+      mfile->Close();\r
+       \r
+      TObject * h ; \r
+      Int_t split =  ((TH1F*) list->FindObject("hCount"))->GetEntries();\r
+      cout<<"scale with factor "<<split<< " histograms "<<list->GetEntries()<<endl;\r
+      newlist = new TList();\r
+      sprintf(name,"%s2",list->GetName());\r
+      newlist->SetName(name);\r
+\r
+      for(Int_t iter = 0; iter < list->GetEntries(); iter++){\r
+        h = list->At(iter);\r
+        if(h && (h->GetName()!="hCount")){\r
+         if ( !strncmp(h->ClassName(),"TH",2) ) {\r
+             char name[128] ; \r
+             sprintf(name, "%s", h->GetName()) ; \r
+             //cout<<iter<<" histo scaled : "<<name<<endl;\r
+             TH1 * hout = dynamic_cast<TH1*> (h->Clone(name)) ; \r
+              //if(fSumw2) hout->Sumw2();\r
+             hout->Scale(1./split) ;  \r
+              newlist->Add(hout) ; \r
+         }\r
+        } \r
+      }\r
+\r
+      sprintf(name,"histosscaled-merged%s.root",os->GetString().Data());\r
+      sfile =  new TFile(name,"recreate");\r
+      newlist->Write();\r
+      sfile->Close();  \r
+      cout<<name<<"  has been recreated "<<endl;\r
+    }//while\r
+  }\r
+\r
+\r
+  //Merge all histos\r
+\r
+  cout<<"Merge all bins "<<endl;\r
+\r
+  TFileMerger m;\r
+  sprintf(name,"TOTALhistosscaled.root");\r
+\r
+  if (binlist.Length()) {\r
+    m.OutputFile(name);\r
+    arr = binlist.Tokenize(" ");\r
+    TObjString *os;\r
+    TIter next(arr);\r
+    while ((os=(TObjString*)next())) {\r
+      printf("Adding bin histosscaled-merged%s.root\n",os->GetString().Data());\r
+      sprintf(name,"histosscaled-merged%s.root",os->GetString().Data());\r
+      m.AddFile(name);\r
+    }\r
+    m.Merge();\r
+  }\r
+\r
+}\r
diff --git a/PWG4/macros/electrons/mergeoutscaledi.jdl b/PWG4/macros/electrons/mergeoutscaledi.jdl
new file mode 100644 (file)
index 0000000..ba02d88
--- /dev/null
@@ -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 (file)
index 0000000..fabf83d
--- /dev/null
@@ -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<TMap*>(res->At(0));
+   if (!map) {
+      delete res;
+      return kFALSE;
+   }   
+   TObjString *objs = dynamic_cast<TObjString*>(map->GetValue("name"));
+   if (!objs || !objs->GetString().Length()) {
+      delete res;
+      return kFALSE;
+   }
+   delete res;   
+   return kTRUE;
+}