Added scripts
authorcholm <cholm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 1 Nov 2010 11:15:20 +0000 (11:15 +0000)
committercholm <cholm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 1 Nov 2010 11:15:20 +0000 (11:15 +0000)
FMD/scripts/DrawTrackRefs.C [new file with mode: 0644]
FMD/scripts/FixOCDBEntries.C [new file with mode: 0644]

diff --git a/FMD/scripts/DrawTrackRefs.C b/FMD/scripts/DrawTrackRefs.C
new file mode 100644 (file)
index 0000000..4152994
--- /dev/null
@@ -0,0 +1,261 @@
+//____________________________________________________________________
+//
+// $Id: DrawHits.C 30718 2009-01-22 16:07:40Z cholm $
+//
+// Script that contains a class to draw hits, using the
+// AliFMDInputHits class in the util library. 
+//
+// It draws the energy loss versus the p/(mq^2).  It can be overlayed
+// with the Bethe-Bloc curve to show how the simulation behaves
+// relative to the expected. 
+//
+// Use the script `Compile.C' to compile this class using ACLic. 
+//
+#include <TH2D.h>
+#include <AliFMDHit.h>
+#include <AliFMDInput.h>
+#include <iostream>
+#include <TStyle.h>
+#include <TArrayF.h>
+#include <TParticle.h>
+#include <TCanvas.h>
+#include <TGraphErrors.h>
+#include <TDatabasePDG.h>
+#include <TParticlePDG.h>
+#include <TLegend.h>
+#include <TArrow.h>
+#include <TLatex.h>
+#include <TF1.h>
+#include <AliStack.h>
+#include <AliTrackReference.h>
+#include <AliFMDStripIndex.h>
+#include <AliFMDGeometry.h>
+#include <AliGenEventHeader.h>
+#include <AliHeader.h>
+#include <THStack.h>
+
+/** @class DrawHits
+    @brief Draw hit energy loss
+    @code 
+    Root> .L Compile.C
+    Root> Compile("DrawHits.C")
+    Root> DrawHits c
+    Root> c.Run();
+    @endcode
+    @ingroup FMD_script
+ */
+class DrawTrackRefs : public AliFMDInput
+{
+private:
+  struct Hists 
+  {
+    TString fPrefix;
+    TString fWhere;
+    TH2* fAll;
+    TH2* fPrimary;
+    TH2* fSecondary;
+    THStack* fStack;
+
+    //__________________________________________________________________
+    Hists(const char* prefix, const char* where)
+      : fPrefix(prefix), fWhere(where), 
+       fAll(0), fPrimary(0), fSecondary(0), fStack(0)
+    {
+      fAll       = MakeHist(Form("%sAll", prefix), 
+                           Form("All tracks in %s", where));
+      fPrimary   = MakeHist(Form("%sPrimary", prefix), 
+                           Form("All primaries in %s", where));
+      fSecondary = MakeHist(Form("%sSecondary", prefix), 
+                           Form("All secondaries in %s", where));
+    }
+     //__________________________________________________________________
+    TH2* MakeHist(const char* name, const char* title) 
+    {
+      TH2D* ret = new TH2D(name, title, 200, -4, 6, 40, 0, 2*TMath::Pi());
+      ret->SetDrawOption("colz");
+      return ret;
+    }
+    //__________________________________________________________________
+    void Draw(TVirtualPad* pad, Bool_t stack=false, Option_t* option="colz") 
+    {
+      if (stack) { 
+       pad->cd();
+       pad->Divide(1,2, 0, 0);
+       pad->cd(1);
+       fStack = new THStack(Form("%sDisplay", fPrefix.Data()), 
+                            Form("2nd over 1st particles in %s", 
+                                 fWhere.Data()));
+       TH1D* prim = 0;
+       TH1D* sec = 0;
+       fStack->Add((prim = fPrimary->ProjectionX()));
+       fStack->Add((sec  = fSecondary->ProjectionX()));
+       prim->SetFillColor(kGray);
+       sec->SetFillColor(kRed);
+       sec->SetFillStyle(3001);
+       fStack->Draw();
+
+       pad->cd(2);
+       TH1* ratio = new TH1D(*sec);
+       ratio->SetName(Form("%sRatio", fPrefix.Data()));
+       ratio->SetTitle(Form("2nd over 1st particles in %s", fWhere.Data()));
+       ratio->Divide(prim);
+       ratio->SetFillColor(kRed);
+       ratio->SetFillStyle(3001);
+       ratio->Draw();
+
+       return;
+      }
+      pad->Divide(1,3,0,0);
+      TVirtualPad* p1 = pad->cd(1);
+      p1->SetLogz();
+      fAll->Draw(option);
+      p1 = pad->cd(2);
+      p1->SetLogz();
+      fPrimary->Draw(option);
+      p1 = pad->cd(3);
+      p1->SetLogz();
+      fSecondary->Draw(option);
+      pad->Modified();
+      pad->Update();
+      pad->cd();
+    }
+  };
+  Hists fTotal;
+  Hists fFMD1I;
+  Hists fFMD2I;
+  Hists fFMD2O;
+  Hists fFMD3I;
+  Hists fFMD3O;
+public:
+  //__________________________________________________________________
+  DrawTrackRefs() 
+    : AliFMDInput("galice.root"), 
+      fTotal("total", "ALICE"), 
+      fFMD1I("fmd1I", "FMD1i"),
+      fFMD2I("fmd2I", "FMD2i"),
+      fFMD2O("fmd2O", "FMD2o"),
+      fFMD3I("fmd3I", "FMD3i"),
+      fFMD3O("fmd3O", "FMD3o")
+  { 
+    AddLoad(kKinematics);
+    AddLoad(kTrackRefs);
+    AddLoad(kGeometry);
+    AddLoad(kHeader);
+  }
+  //__________________________________________________________________
+  Bool_t ProcessTrackRef(AliTrackReference* trackRef, TParticle* p)
+  {
+    if (trackRef->DetectorId() != AliTrackReference::kFMD) return kTRUE;
+
+    if (!p->GetPDG() || p->GetPDG()->Charge() == 0) return kTRUE;
+
+    // Double_t eta = p->Eta();
+    // Double_t phi = p->Phi();
+
+    UShort_t d   = 0;
+    Char_t   r   = '\0';
+    UShort_t s   = 0;
+    UShort_t t   = 0;
+    AliFMDStripIndex::Unpack(trackRef->UserId(),d,r,s,t);
+    
+    Double_t x, y, z;
+    AliFMDGeometry::Instance()->Detector2XYZ(d,r,s,t,x,y,z);
+
+    AliGenEventHeader* genHeader = fHeader->GenEventHeader();
+    TArrayF v;
+    genHeader->PrimaryVertex(v);
+    z -= v.fArray[2];
+    
+    Double_t eta, phi, theta, rr;
+    AliFMDGeometry::XYZ2REtaPhiTheta(x, y, z, rr, eta, phi, theta);
+    if (phi < 0)               phi += 2*TMath::Pi();
+    if (phi > 2 * TMath::Pi()) phi -= 2*TMath::Pi();
+
+    Hists* hists = 0;
+    switch (d) { 
+    case 1: hists = &fFMD1I; break;
+    case 2: hists = (r == 'I' || r == 'i') ? &fFMD2I : &fFMD2O; break;
+    case 3: hists = (r == 'I' || r == 'i') ? &fFMD3I : &fFMD3O; break;
+    }
+    if (!hists) return kTRUE;
+
+    hists->fAll->Fill(eta, phi);
+    
+    if (fStack->IsPhysicalPrimary(trackRef->GetTrack())) 
+      hists->fPrimary->Fill(eta,phi); 
+    else
+      hists->fSecondary->Fill(eta, phi);
+
+    return kTRUE;
+  }
+  //__________________________________________________________________
+  Bool_t ProcessParticle(Int_t id, TParticle* p)
+  {
+    if (!p) return kTRUE;
+
+    if (!p->GetPDG() || p->GetPDG()->Charge() == 0) return kTRUE;
+    // std::cout << p->GetPDG()->GetName() << std::endl;
+
+    Double_t eta = p->Eta();
+    Double_t phi = p->Phi();
+
+    fTotal.fAll->Fill(eta, phi);
+    
+    if (fStack->IsPhysicalPrimary(id)) fTotal.fPrimary->Fill(eta,phi); 
+    else                               fTotal.fSecondary->Fill(eta, phi);
+
+    return kTRUE;
+  }
+
+  //__________________________________________________________________
+  Bool_t Finish()
+  {
+    gStyle->SetPalette(1);
+    // gStyle->SetOptTitle(0);
+    gStyle->SetTitleBorderSize(1);
+    gStyle->SetTitleFillColor(0);
+    gStyle->SetCanvasColor(0);
+    gStyle->SetCanvasColor(0);
+    gStyle->SetCanvasBorderSize(0);
+    gStyle->SetPadColor(0);
+    gStyle->SetPadBorderSize(0);
+
+    TCanvas* c2d = new TCanvas("c2d", "2D plots", 1200, 700);
+    c2d->Divide(6);
+    fTotal.Draw(c2d->cd(1));   c2d->cd();
+    fFMD1I.Draw(c2d->cd(6));   c2d->cd();
+    fFMD2I.Draw(c2d->cd(5));   c2d->cd();
+    fFMD2O.Draw(c2d->cd(4));   c2d->cd();
+    fFMD3I.Draw(c2d->cd(2));   c2d->cd();
+    fFMD3O.Draw(c2d->cd(3));   c2d->cd();
+
+    c2d->Modified();
+    c2d->Update();
+    c2d->cd();
+    c2d->SaveAs("kine_etaphi.png");
+
+    TCanvas* c1d = new TCanvas("c1d", "1D plots", 1200, 700);
+    c1d->Divide(6);
+    fTotal.Draw(c1d->cd(1), kTRUE);   c1d->cd();
+    fFMD1I.Draw(c1d->cd(6), kTRUE);   c1d->cd();
+    fFMD2I.Draw(c1d->cd(5), kTRUE);   c1d->cd();
+    fFMD2O.Draw(c1d->cd(4), kTRUE);   c1d->cd();
+    fFMD3I.Draw(c1d->cd(2), kTRUE);   c1d->cd();
+    fFMD3O.Draw(c1d->cd(3), kTRUE);   c1d->cd();
+
+    c1d->Modified();
+    c1d->Update();
+    c1d->cd();
+    c1d->SaveAs("kine_eta.png");
+
+
+    return kTRUE;
+  }
+  
+  ClassDef(DrawTrackRefs,0);
+};
+
+//____________________________________________________________________
+//
+// EOF
+//
diff --git a/FMD/scripts/FixOCDBEntries.C b/FMD/scripts/FixOCDBEntries.C
new file mode 100644 (file)
index 0000000..f799f20
--- /dev/null
@@ -0,0 +1,109 @@
+Bool_t
+GetInfoFromFileName(const char* path, 
+                   Int_t& firstRun, Int_t& lastRun, 
+                   Int_t& version, Int_t& subVersion)
+{
+  TString fn(gSystem->BaseName(path));
+  int ret = sscanf(fn.Data(), "Run%d_%d_v%d_s%d.root", 
+                  &firstRun, &lastRun, &version, &subVersion);
+  return ret == 4;
+}
+
+void 
+FixOne(const char* path, const char* id, const char* fn) 
+{
+  TFile* file = TFile::Open(Form("%s/%s/%s", path, id, fn));
+  if (!file) { 
+    Warning("FixOne", "%s/%s/%s not found", path, id, fn);
+    return;
+  }
+
+  AliCDBEntry* entry = static_cast<AliCDBEntry*>(file->Get("AliCDBEntry"));
+  if (!entry) { 
+    Warning("FixOne", "Did not find an entry in the file");
+    return;
+  }
+
+  Int_t firstRun, lastRun, version, subVersion;
+  if (!GetInfoFromFileName(fn, firstRun, lastRun, version, subVersion)) { 
+    Warning("FixOne", "Could not get info from file name");
+    return;
+  }
+
+  if (firstRun    == entry->GetId().GetFirstRun() && 
+      lastRun     == entry->GetId().GetLastRun()  && 
+      version     == entry->GetId().GetVersion()  && 
+      subVersion  == entry->GetId().GetSubVersion()) { 
+    Info("FixOne", "Entry run range and version %d->%d %d.%d match "
+        "filename run range and version %d->%d %d.%d, not creating %s in %s", 
+        entry->GetId().GetFirstRun(), entry->GetId().GetLastRun(), 
+        entry->GetId().GetVersion(),  entry->GetId().GetSubVersion(), 
+        firstRun, lastRun, version, subVersion, fn, 
+        gSystem->WorkingDirectory());
+    return;
+  }
+
+  AliCDBId cid(id, firstRun, lastRun, version, subVersion);
+  entry->SetId(cid);
+
+  Info("FixOne", "Creating %s", fn);
+  TFile* out = TFile::Open(fn, "RECREATE");
+  out->cd();
+  entry->Write();
+  out->ls();
+  out->Close();
+  file->Close();
+}
+
+FixCategory(const char* path, const char* id)
+{
+  TSystemDirectory dir(Form("%s/%s", path, id), Form("%s/%s", path, id));
+  TList*       fl = dir.GetListOfFiles();
+  TIter        next(fl);
+  TSystemFile* file = 0;
+  while ((file = static_cast<TSystemFile*>(next()))) { 
+    if (file->IsDirectory()) { 
+      Info("FixCategory", " skipping %s", file->GetName());
+      continue;
+    }
+
+    TString fn(gSystem->BaseName(file->GetName()));
+    if (!fn.EndsWith(".root")) { 
+      Info("FixCategory", " Skipping %s", fn.Data());
+      continue; 
+    }
+
+    Info("FixCategory", " Now processing %s/%s @ %s", id, fn.Data(), path);
+    FixOne(path, id, fn.Data());
+  }
+}
+
+FixOCDBEntries()
+{
+  const char* path = gSystem->ExpandPathName("$ALICE_ROOT/OCDB");
+
+  AliCDBManager* cdb = AliCDBManager::Instance();
+  cdb->SetDefaultStorage(Form("local://%s", path));
+  cdb->SetRun(0);
+
+  AliFMDParameters* fmdp = AliFMDParameters::Instance();
+  fmdp->Init(kTRUE);
+  
+  const char* ids[] = { AliFMDParameters::PulseGainPath(), 
+                       AliFMDParameters::PedestalPath(),
+                       AliFMDParameters::DeadPath(),
+                       AliFMDParameters::ZeroSuppressionPath(),
+                       AliFMDParameters::SampleRatePath(),
+                       AliFMDParameters::StripRangePath(),    
+                       AliFMDParameters::AltroMapPath(),
+                       0 };
+  const char** ptr = ids;
+  while (*ptr) { 
+    Info("FixOCDBEntries", "Now processing %s", *ptr);
+    FixCategory(path, *ptr);
+    ptr++;
+  }
+}
+
+
+