robust drawing in TStatToolkit::DrawHistogram (1D only so far) and first drawing...
authormiweber <miweber@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 27 Jun 2013 17:42:15 +0000 (17:42 +0000)
committermiweber <miweber@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 27 Jun 2013 17:42:15 +0000 (17:42 +0000)
STAT/TStatToolkit.cxx
STAT/TStatToolkit.h
TPC/Upgrade/AliToyMCReconstruction.cxx
TPC/Upgrade/macros/toyMCRecPlots.C [new file with mode: 0644]

index 3948efd..b5acf2c 100644 (file)
@@ -1565,3 +1565,60 @@ void  TStatToolkit::DrawStatusGraphs(TObjArray* oaMultGr)
     ylabel->Draw();
   }
 }
+
+
+void TStatToolkit::DrawHistogram(TTree * tree, const char* drawCommand, const char* cuts, const char* histoname, const char* histotitle, Int_t nsigma, Float_t fraction )
+{
+  //
+  // Draw histogram from TTree with robust range
+  // Only for 1D so far!
+  // 
+  // Parameters:
+  // - histoname:  name of histogram
+  // - histotitle: title of histgram
+  // - fraction:   fraction of data to define the robust mean
+  // - nsigma:     nsigma value for range
+  //
+
+   TString drawStr(drawCommand);
+   TString cutStr(cuts);
+   Int_t dim = 1;
+
+   // TODO: more than 1D implementation!
+   // TString strVal(drawCommand);
+   // if ( strVal.Contains(":") ){
+     
+   //   // count ":", but do not take into account "::"
+   //   Int_t count = 0;
+   //   Int_t len   = strVal.Length();
+   //   const char *data  = strVal.Data();
+   //   for (Int_t n = 0; n < len; n++){     
+   //     if (data[n] == ':'){
+   //   if(n<len-1){
+   //     if(data[n+1] == ':') n++;
+   //     else count++;
+   //   }
+   //     }
+   //   }     
+   // }
+   // cout<<dim<<endl;
+
+   if(!tree) {
+     cerr<<" Tree pointer is NULL!"<<endl;
+     return;
+   }
+
+   Int_t entries = tree->Draw(drawStr.Data(), cutStr.Data(), "goff");
+   if (entries == -1) {
+     cerr<<"TTree draw returns -1"<<endl;
+     return;
+   }
+
+   Double_t mean, rms=0;
+   TStatToolkit::EvaluateUni(entries, tree->GetV1(),mean,rms, fraction*entries);
+   TH1* hOut = new TH1F(histoname, histotitle, 200, mean-nsigma*rms, mean+nsigma*rms);
+   for (Int_t i=0; i<entries; i++) hOut->Fill(tree->GetV1()[i]);
+   
+   hOut->Draw();
+
+}
index c0ca2a8..06499d4 100644 (file)
@@ -75,6 +75,10 @@ class TStatToolkit : public TObject
   static void  AddStatusPad(TCanvas* c1, Float_t padratio, Float_t bottommargin);
   static void  DrawStatusGraphs(TObjArray* oaMultGr);
   //
+  // TTree function for robust draw
+  //
+  static void DrawHistogram(TTree * tree, const char* drawCommand, const char* cuts = "1", const char* hname = "histo", const char* htitle = "histo", Int_t nsigma = 4, Float_t fraction = 0.75);
+  //
   // TestFunctions:
   //
  static  void TestGausFit(Int_t nhistos=5000);
index db7245b..7773806 100644 (file)
@@ -529,7 +529,7 @@ TTree* AliToyMCReconstruction::ConnectTrees (const char* files) {
     }
   }
 
-  tFirst->GetListOfFriends()->Print()
+  tFirst->GetListOfFriends()->Print();
   return tFirst;
 }
 
diff --git a/TPC/Upgrade/macros/toyMCRecPlots.C b/TPC/Upgrade/macros/toyMCRecPlots.C
new file mode 100644 (file)
index 0000000..8b88920
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+
+root.exe -l $ALICE_ROOT/TPC/Upgrade/macros/{loadlibs.C,ConfigOCDB.C}
+.x $ALICE_ROOT/TPC/Upgrade/macros/toyMCRecPlots.C
+
+*/
+
+void toyMCRecPlots(TString inFileName = "toyMC.debug.root"){
+  //
+  // do all the plots for Toy MC Reconstruction for the TDR 
+  //
+
+  //gStyle->SetOptStat(0);
+
+  // parameters
+  const Int_t nT0          = 2;
+  const Int_t nT02D        = 2;
+  const Int_t nTrackParams = 9;
+
+  Int_t col = kBlack;
+
+  TString sT0[nT0] = {"fTime0-t0","fTime0-t0+z0*TMath::Sign(1,tOrig.Eta())/vdrift"};
+  TString sT02D[nT02D] = {"fTime0-t0+z0*TMath::Sign(1,tOrig.Eta())/vdrift:tOrig.fP[3]","fTime0-t0+z0*TMath::Sign(1,tOrig.Eta())/vdrift:tOrig.fP[4]"};
+  TString sTrackParams[nTrackParams] = {"track.fP[0]-tOrig.fP[0]","track.fP[1]-tOrig.fP[1]","track.fP[2]-tOrig.fP[2]","track.fP[3]-tOrig.fP[3]","track.fP[4]-tOrig.fP[4]","track.fAlpha-tOrig.fAlpha","track.fX/tOrig.fX","track.fY/tOrig.fY","track.fZ/tOrig.fZ"};
+
+  TString tT0[nT0] = {"T_{0} resolution","intrinsic T_{0} resolution"};
+  TString tT02D[nT0] = {"intrinsic T_{0} resolution vs. tan#lambda","intrinsic T_{0} resolution vs. 1/p_{T}"};
+  TString tTrackParams[nTrackParams] = {"local y","z","sin inclination angle","tan#lambda","1/p_{T}","#alpha","X","Y","Z"};
+
+  TString sSel = "fTime0>-1"; // seeding successful
+
+  // get file
+  TFile *fIn  = TFile::Open(inFileName.Data(),"READ");
+  if(!fIn){
+    Printf("No file %s found",inFileName.Data());
+    return;
+  }
+
+  // get tree
+  TTree *Tracks = fIn->Get("Tracks");
+  if(!Tracks){
+    Printf("No TTree found");
+    return;
+  }
+ // output canvases
+  TCanvas *cT0 = new TCanvas("cT0","cT0",1200,500);
+  cT0->Divide(2,1);
+
+  TCanvas *cT02D = new TCanvas("cT02D","cT02D",1200,500);
+  cT02D->Divide(2,1);
+
+  TCanvas *cTrackParams = new TCanvas("cTrackParams","cTrackParams",1200,900);
+  cTrackParams->Divide(3,3);
+
+
+  // output histograms
+  TH2D *hT02D[nT02D];
+  
+  // legends
+  TLegend *l[nT0];
+
+
+
+  // draw T0 resolution
+  for(Int_t iT0 = 0; iT0 < nT0; iT0 ++){
+
+    cT0->cd(iT0+1);
+    TStatToolkit::DrawHistogram(Tracks,sT0[iT0].Data(),sSel.Data(),Form("hT0%d",iT0),Form("%s",tT0[iT0].Data()),3);
+
+    //hT0[iT0]->Fit("gaus","","");
+    //l[iT0]= new TLegend(0.55,0.7,0.8,0.8,Form(""));
+    //myLegendSetUp(l[iT0],0.03);
+    //l[iT0]->AddEntry( hT0[iT0], Form("#sigma = (%.2f #pm %.2f) #mus",hT0[iT0]->GetFunction("gaus")->GetParameter(2)*1e6,hT0[iT0]->GetFunction("gaus")->GetParError(2)*1e6));
+    //l[iT0]->Draw();
+
+  }
+
+
+  // draw T0 resolution (2D)
+  for(Int_t iT02D = 0; iT02D < nT02D; iT02D ++){
+
+    hT02D[iT02D] = new TH2D(Form("hT02D%d",iT02D),Form("%s",tT02D[iT02D].Data()),200,-3,3,200,-1e-6,1e-6);
+
+    cT02D->cd(iT02D+1);
+    Tracks->Draw(Form("%s>>hT02D%d",sT02D[iT02D].Data(),iT02D),Form("%s",sSel.Data()),"colz");
+
+  }
+
+
+  // draw track parameters
+  for(Int_t iTrackParams = 0; iTrackParams < nTrackParams; iTrackParams ++){
+
+    cTrackParams->cd(iTrackParams+1);
+    TStatToolkit::DrawHistogram(Tracks,sTrackParams[iTrackParams].Data(),sSel.Data(),Form("hTrackParams%d",iTrackParams),Form("%s",tTrackParams[iTrackParams].Data()),3);
+
+  }
+
+
+  // plots
+  TString outFileName = inFileName;
+  outFileName.ReplaceAll(".root","");
+  cT0->SaveAs(Form("%s_T0.eps",outFileName.Data()));
+  cT02D->SaveAs(Form("%s_T02D.eps",outFileName.Data()));
+  cTrackParams->SaveAs(Form("%s_TrackParams.eps",outFileName.Data()));
+
+}
+
+void myLegendSetUp(TLegend *currentLegend = NULL,Float_t currentTextSize=0.07){
+  currentLegend->SetTextFont(42);
+  currentLegend->SetBorderSize(0);
+  currentLegend->SetFillStyle(1);
+  currentLegend->SetFillColor(0);
+  currentLegend->SetMargin(0.25);
+  currentLegend->SetTextSize(currentTextSize);
+  currentLegend->SetEntrySeparation(0.5);
+  return;
+}
+
+void myHistoSetUp( TH1 *h = NULL, Int_t col = kBlack, Int_t mar = 20){
+
+  h->SetLineColor(col);
+  h->SetMarkerColor(col);
+  h->SetMarkerStyle(mar);
+
+}
+