Example #1
0
Label MakeLabel(TString str)
{
    if (str.CountChar(';') != 2)
        std::cout << "ERROR: Must contain 2 ';': " << str << std::endl;
    str.ReplaceAll(";;", "; ;");
    TStringToken token(str, ";");
    TString labeltype;
    Label label;

    if(token.NextToken())  label.xlabel = token;
    if(token.NextToken())  label.unit = token;
    if(token.NextToken())  labeltype = token;
    
    if (label.unit == " ")
        label.unit = "";
    if (labeltype != "F" && labeltype != "I")
        std::cout << "ERROR: Must be either 'F' or 'I': " << labeltype << std::endl;
    else
        label.type = (labeltype == "F") ? 'F' : 'I';
    
    return label;
}
Example #2
0
//_____________________________________________________________________________________________________________
void GeomDraw(const char *fzFile="complete",Float_t bombFactor=1.4, const char *out = "")
{
   // Read the ZEBRA file with GEANT geometry
   // Convert it to TVolume format 
   // draw it out with OpenGL Viewer
  TString geomAccess = fzFile;
  TString geomKuipCmd;
  if (gSystem->AccessPathName(geomAccess.Data()) ) 
  {
     // Check 
     geomAccess.Strip(TString::kBoth);
     if (!geomAccess.CountChar(' ') && (geomAccess.First('y')==0 || geomAccess.First("complete") == 0 ) ) {
       geomKuipCmd = "detp geometry ";
       geomKuipCmd += geomAccess; geomAccess = "" ;
     } else {
          printf("\n *** Error ***   Wrong input parameter: <%s>\n", fzFile);
          GeomDrawUsage();
          return;              
     }
   }
   
  // Workaroung of STAR bug with ROOT 4.00.04
  //- TString unixLDPath = "$ROOT/$ROOT_LEVEL.qt/.$STAR_HOST_SYS/rootdeb/lib:";
  //-  unixLDPath += gEnv->GetValue("Root.DynamicPath","");
  //- gEnv->SetValue("Root.DynamicPath",unixLDPath.Data());
  //- gSystem->Load("$ROOT/$ROOT_LEVEL.qt/.$STAR_HOST_SYS/rootdeb/lib/libRQTGL.so");
  //- end of workaroung
  
  gSystem->Load("St_base");
  gSystem->Load("StChain");
  gSystem->Load("St_Tables");
  gSystem->Load("St_g2t.so");
  gSystem->Load("StarMagField");
  gSystem->Load("St_geant_Maker");  
  gSystem->Load("StUtilities");
  chain = new StChain(); 
  geant = new St_geant_Maker();
  geant->SetActive(kFALSE);
  if (! geomAccess.IsNull() ) {
     printf("\n ----------------------------------------------------------\n");
     printf(" Draw the GEANT geometry from <%s> file\n", geomAccess.Data());
     printf(" ----------------------------------------------------------\n\n");
     geant->SetInputFile(geomAccess.Data());
  } else {
     printf("\n ----------------------------------------------------------\n");
     printf(" Draw the GEANT generated geometry <%s> \n", geomKuipCmd.Data());
     printf(" ----------------------------------------------------------\n\n");
     gSystem->Load("geometry");
     geant->LoadGeometry(geomKuipCmd.Data());            
  }
  chain->Init();
  TVolume *v = (TVolume *)geant->Work();
  if (v) {
     // Make CAVE invisible
     TVolume *cave = (TVolume *)v->FindByName("CAVE");
     if (cave) cave->SetVisibility(2);
     TVolume *hall = (TVolume *)v->FindByName("HALL");
     GeomDrawUsage();
     if (hall) {
        hall->SetVisibility(2);
        new TBrowser("STAR Geometry", hall);
        if (bombFactor < 1)  bombFactor = 1.;
        gGeometry->SetBomb(bombFactor);        
        hall->Draw("6");        
        gPad->SetFillColor(kBlack);
    }
    gPad->Modified();
    gPad->Update();
    if (out && out[0]) {
       TFile outFile(out,"RECREATE");
       v->Write();
       outFile.Write();
       outFile.Close();      
    }   
  } else {
     fprintf(stderr,"\n\n, ** Error **, No suitable STAR geometry has been found. Abort !!! \n");   
  }
//  delete chain; chain = 0;
}
Example #3
0
void fillHistoFromTreeVar(std::string& treedrawspec,
			  int  index,
			  wTH1 *&wth1)
{
  // Sample treedrawspec:
  // mytree:"TDCwinstart[%d]:runnum>>winstrt%d(70,202000,209000)","evtnum==1","prof P"
  //
  vector<string> v_tokens;
  string tid;
  TString drawspec;
  Tokenize(treedrawspec,v_tokens,":",true);
  if( (v_tokens.size() < 2) ||
      (!v_tokens[0].size())  ||
      (!v_tokens[2].size())    ) {
    cerr << "malformed root tree draw spec treeid:\"varexp\",\"selection\",option: " << treedrawspec << endl;
    return;
  }

  tid = v_tokens[0];
  for (size_t i=2; i<v_tokens.size(); i++) {
    drawspec += v_tokens[i];
  }
  int fmtcnt = drawspec.CountChar('%');

  if (fmtcnt) { // use index for tree array var
    switch(fmtcnt) {
    case 1: drawspec = Form(drawspec,index); break;
    case 2: drawspec = Form(drawspec,index,index); break;
    case 3: drawspec = Form(drawspec,index,index,index); break;
    case 4: drawspec = Form(drawspec,index,index,index,index); break;
    case 5: drawspec = Form(drawspec,index,index,index,index,index); break;
    case 6: drawspec = Form(drawspec,index,index,index,index,index,index); break;
    default:
      cerr << "More than six fmt specifiers in drawspec found, fix me! " << drawspec <<endl;
      exit(-1);
    }
  }
  if( gl_verbose)
    cout<<"drawspec="<<drawspec<<endl;

  TTree *tree = findTree(tid);
  assert (tree);

  // can't use comma as delimiter since histo with binning spec may be supplied
  TObjArray *tokens = drawspec.Tokenize("\"");
  TString hname;

  TString varexp = ((TObjString *)(*tokens)[0])->GetString();

  if (varexp.Contains(">>")) {
    TObjArray *rematches = TPRegexp(">>(\\w+)").MatchS(varexp); // get histo name
    assert(rematches->GetEntriesFast() ==2);
    hname = ((TObjString *)(*rematches)[1])->GetString();

    if (wth1 && !hname.EqualTo(wth1->histo()->GetName())) {
      cerr << "Error: histo name in treedraw spec "<<hname;
      cerr <<" doesn't match named histo "<<wth1->histo()->GetName()<<endl;
      exit(-1);
    }
  } else { // add histo name
    assert (wth1);
    hname = TString(wth1->histo()->GetName());
    varexp = varexp + ">>+" + hname; // append to pre-existing histo
  }

  if( gl_verbose)
    cout<<"varexp="<<varexp<<", hname="<<hname<<endl;
  switch(tokens->GetEntriesFast()) {
  case 1:
    tree->Draw(varexp,"","goff");
    break;
  case 3:
    {
      TString cut = ((TObjString *)(*tokens)[2])->GetString();
      tree->Draw(varexp,cut,"goff"); 
    }
    break;
  case 4: // assume the cut string is blank
    {
      TString gopt = ((TObjString *)(*tokens)[3])->GetString();
      gopt = gopt + " goff";
      tree->Draw(varexp,"",gopt);
    }
    break;
  case 5:
    {
      TString cut  = ((TObjString *)(*tokens)[2])->GetString();
      TString gopt = ((TObjString *)(*tokens)[4])->GetString();
      gopt = gopt + " goff";
      tree->Draw(varexp,cut,gopt);
    }
    break;
  default:
    cerr << "malformed root tree draw spec treeid:varexp,selection,option";
    for (int i=0; i<tokens->GetEntriesFast(); i++)
      cerr << i<<": "<< ((TObjString *)(*tokens)[i])->GetString() << " ";
    cerr << endl;
    break;
  }
  if (!wth1) {
    wth1 = new wTH1((TH1*)gDirectory->Get(hname));
    assert(wth1);
    wth1->histo()->UseCurrentStyle();
  }
}                                                // fillHistoFromTreeVar
Example #4
0
void fillGraphFromTreeVar(std::string& treedrawspec,int index,wGraph_t *&pwg)
{
  // Sample treedrawspec:
  // mytree:"TDCwinstart[%d]:runnum","evtnum==1","P"
  //
  vector<string> v_tokens;
  string tid;
  TString drawspec;
  Tokenize(treedrawspec,v_tokens,":",true);
  if( (v_tokens.size() < 2) ||
      (!v_tokens[0].size())  ||
      (!v_tokens[2].size())    ) {
    cerr << "malformed root tree draw spec treeid:\"varexp\",\"selection\",option: " << treedrawspec << endl;
    return;
  }

  tid = v_tokens[0];
  for (size_t i=2; i<v_tokens.size(); i++) {
    drawspec += v_tokens[i];
  }
  int fmtcnt = drawspec.CountChar('%');

  if (fmtcnt) { // use index for tree array var
    switch(fmtcnt) {
    case 1: drawspec = Form(drawspec,index); break;
    case 2: drawspec = Form(drawspec,index,index); break;
    case 3: drawspec = Form(drawspec,index,index,index); break;
    case 4: drawspec = Form(drawspec,index,index,index,index); break;
    case 5: drawspec = Form(drawspec,index,index,index,index,index); break;
    case 6: drawspec = Form(drawspec,index,index,index,index,index,index); break;
    default:
      cerr << "More than six fmt specifiers in drawspec found, fix me! " << drawspec <<endl;
      exit(-1);
    }
  }
  if( gl_verbose)
    cout<<"drawspec="<<drawspec<<endl;

  TTree *tree = findTree(tid);
  assert (tree);

  // can't use comma as delimiter since histo with binning spec may be supplied
  TObjArray *tokens = drawspec.Tokenize("\"");
  TString hname;

  TString varexp = ((TObjString *)(*tokens)[0])->GetString();

  if( gl_verbose)
    cout<<"varexp="<<varexp<<endl;
  switch(tokens->GetEntriesFast()) {
  case 1:
    tree->Draw(varexp,"","goff");
    break;
  case 3:
    {
      TString cut = ((TObjString *)(*tokens)[2])->GetString();
      tree->Draw(varexp,cut,"goff"); 
    }
    break;
  case 4: // assume the cut string is blank
    {
      TString gopt = ((TObjString *)(*tokens)[3])->GetString();
      gopt = gopt + " goff";
      tree->Draw(varexp,"",gopt);
    }
    break;
  case 5:
    {
      TString cut  = ((TObjString *)(*tokens)[2])->GetString();
      TString gopt = ((TObjString *)(*tokens)[4])->GetString();
      gopt = gopt + " goff";
      tree->Draw(varexp,cut,gopt);
    }
    break;
  default:
    cerr << "malformed root tree draw spec treeid:varexp,selection,option";
    for (int i=0; i<tokens->GetEntriesFast(); i++)
      cerr << i<<": "<< ((TObjString *)(*tokens)[i])->GetString() << " ";
    cerr << endl;
    break;
  }

  assert(tree->GetSelectedRows());

  if (!pwg)
    pwg = new wGraph_t();

  assert(pwg);
  pwg->gr = new TGraph(tree->GetSelectedRows(),
		       tree->GetV2(), tree->GetV1());

}                                                // fillGraphFromTreeVar