Example #1
0
//________________________________________________________________________________
TChain* CreateChainTXT(const char* inpData)
{
  const char* chName="esdTree";
  TChain* chain = new TChain(chName);
  //
  TString inpDtStr = inpData;
  if (inpDtStr.EndsWith(".root")) {
    chain->AddFile(inpData);
  }
  else {
    //
    ifstream inpf(inpData);
    if (!inpf.good()) {
      printf("Failed on input filename %s\n",inpData);
      return kFALSE;
    }
    //
    TString flName;
    flName.ReadLine(inpf);
    while ( !flName.IsNull() ) {
      flName = flName.Strip(TString::kBoth,' ');
      if (flName.BeginsWith("//") || flName.BeginsWith("#")) {flName.ReadLine(inpf); continue;}
      flName = flName.Strip(TString::kBoth,',');
      flName = flName.Strip(TString::kBoth,'"');
      if (flName.EndsWith("Barrel.root")) barrelFlag = kTRUE;
      printf("Adding %s\n",flName.Data());
      chain->AddFile(flName.Data());
      flName.ReadLine(inpf);
    }
  }
  //
  int n = chain->GetEntries();
  if (n<1) {
    printf("Obtained chain is empty\n");
    return kFALSE;
  }
  printf("Created chain with %d entries in %d trees from %s\n",chain->GetEntries(),chain->GetNtrees(),inpData);
  return chain;
}
Example #2
0
// Helper function to avoid code mess with TString's Tokenize
inline vector<TString> tokenize(TString line, const char* delim=" ") {
  vector<TString> retvec;
  line = line.Strip();
  // Tokenize the string, use blank as delimiter
  TObjArray* tokens = line.Tokenize(delim);
  for (int i=0; i<tokens->GetSize(); i++) {
    // For some reasons Tokenize produces an awfull lot of Null-pointers  
    if (tokens->At(i)!=0) {
      // We need to explicitly cast the array contents to TObjString  
      TString t = dynamic_cast<TObjString *>(tokens->At(i))->GetString();
      retvec.push_back(t);
    }
  }
  return retvec;
}
Example #3
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 #4
0
//-------------------------------------------------------------------------------------------------
void makeBranchFile(std::string branchNamesFile, std::string treeName) {
  
    ifstream branchesF(branchNamesFile.c_str());
    vector<TString> v_datatypes;
    vector<TString> v_varNames;
    while(!branchesF.eof()) {
        string temp;
        getline(branchesF, temp);
        TString line(temp);
        // do not use commented lines
        if(line.BeginsWith("//"))
            continue;
        vector<TString> v_line;
        TIter objIt((TObjArray*)line.Tokenize(" "));
        while(TObject *obj = (TObject*)objIt.Next()) {
            if(obj==NULL) 
                continue;
            v_line.push_back(obj->GetName());
        }
    
        if(v_line.size() == 0)
            continue;
        TString varName;
        //loop over v_line until you get to the first element thats not a space
        for(vector<TString>::iterator it = v_line.begin();
            it != v_line.end(); it++) {
            if( *it != " " ) {
                varName = *it;
            }
        }
    
        v_varNames.push_back(varName.Strip());  //paranoid....strips trailing spaces
        TString datatype("");
        for(unsigned int i = 0; i < v_line.size()-1; i++) {
            TString temp2 = v_line[i];
            if(temp2.Contains("vector") && !temp2.Contains("std::")) temp2.ReplaceAll("vector", "std::vector");
            if(temp2.Contains("LorentzVector") && !temp2.Contains("ROOT::Math::LorentzVector")) temp2.ReplaceAll("LorentzVector", "ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> >");
            temp2.ReplaceAll(">>", "> >");
            temp2.ReplaceAll(">>>", "> > >");
            if(i!=0) datatype = datatype+" " + temp2;
            else datatype = datatype+temp2;
        }
        v_datatypes.push_back(datatype);
    
    } 
    branchfile.open("branches.h");
    branchfile << "#ifndef BRANCHES_H" << endl << "#define BRANCHES_H" << endl;
    branchfile << "#include <vector>" << endl;
    branchfile << "#include \"TFile.h\"" << endl;
    branchfile << "#include \"TTree.h\"" << endl << endl << endl << endl;

    for(unsigned int i = 0; i < v_datatypes.size(); i++) {
        TString temp2(v_varNames.at(i));
        if(v_datatypes.at(i).Contains("vector") || v_datatypes.at(i).Contains("LorentzVector")) {
            branchfile << v_datatypes.at(i) << " *" << temp2.ReplaceAll("_","")+"_;" << endl;
            continue;
        }
        branchfile << v_datatypes.at(i) << " " << temp2.ReplaceAll("_","")+"_;" << endl;
    }


    branchfile << "TFile *outFile_;" << endl;
    branchfile << "TTree *outTree_;" << endl;

    //now declare the branches and set aliases in the InitSkimmedTree function
    branchfile << "void InitSkimmedTree(std::string skimFilePrefix=\"\") {\n\n";
    branchfile << "   if(skimFilePrefix != \"\")" << endl;
    branchfile << "      outFile_ = TFile::Open(string(skimFilePrefix + \"_skimmednTuple.root\").c_str(),\"RECREATE\");\n";
    branchfile << "   else outFile_ = TFile::Open(\"skimmednTuple.root\", \"RECREATE\");\n";
    branchfile << "   outFile_->cd();" << endl;
    branchfile << "   outTree_ = new TTree(\"" << treeName << "\", \"\");\n\n";
    branchfile << "   //book the branches\n";
    for(unsigned int i = 0; i < v_datatypes.size(); i++) {
        TString varName = v_varNames[i];
        varName = varName.ReplaceAll("_", "") + "_";
        TString varType = v_datatypes[i];
        if(varType.BeginsWith("std::vector") 
           || varType.BeginsWith("ROOT::Math") ) {
            TString prefix = "";
            if(varType.BeginsWith("std::vector<float>") )
                prefix = "floats";
            if(varType.BeginsWith("std::vector<int>") ) 
                prefix = "ints";
            if(varType.BeginsWith("std::vector<unsigned int>") ) 
                prefix = "uints";
            if(varType.BeginsWith("ROOT::Math::LorentzVector<") )
                prefix = "floatROOTMathPxPyPzE4DROOTMathLorentzVector";
            if(varType.BeginsWith("std::vector<ROOT::Math::LorentzVector<") )
                prefix = "floatROOTMathPxPyPzE4DROOTMathLorentzVectors";
            if(varType.Contains("std::vector<std::vector<ROOT::Math::LorentzVector<") )
                prefix = "floatROOTMathPxPyPzE4DROOTMathLorentzVectorss";
            branchfile << "   outTree_->Branch(\"" << prefix + "_" +varName << "\",   \"" 
                       << varType << "\",   &" << varName << ");" << endl;
            branchfile << "   outTree_->SetAlias(\"" << v_varNames[i] << "\",   " 
                       << "\"" << prefix+"_"+varName << "\");" << endl;
            continue;
        }
        if(varType=="float" || varType == "Float_t") {
            branchfile << "   outTree_->Branch(\"" << varName << "\",   &" << varName;
            branchfile << ",   \"" << varName + "/F\");" << endl;
            branchfile << "   outTree_->SetAlias(\"" << v_varNames[i] << "\",   " 
                       << "\"" << varName << "\");" << endl;
            continue;
        }
        if(varType=="unsigned int" || varType == "UInt_t") {
            branchfile << "   outTree_->Branch(\"" << varName << "\",   &" << varName;
            branchfile << ",   \"" << varName + "/i\");" << endl;
            branchfile << "   outTree_->SetAlias(\"" << v_varNames[i] << "\",   " 
                       << "\"" << varName << "\");" << endl;
            continue;
        }
        if(varType=="int" || varType == "Int_t") {
            branchfile << "   outTree_->Branch(\"" << varName << "\",   &" << varName;
            branchfile << ",   \"" << varName + "/I\");" << endl;
            branchfile << "   outTree_->SetAlias(\"" << v_varNames[i] << "\",   " 
                       << "\"" << varName << "\");" << endl;
            continue;
        }
    }
    branchfile << "} " <<  endl;
    branchfile << "#endif" << endl;
  
    branchfile.close();
}
void TDSPMultiEcho::SetOption(Option_t *o) {

  TString opt = o;
  opt.ToLower();

  Ssiz_t pos;

  UInt_t mg=0;
  UInt_t mo=0;
                        
  if ((pos = opt.Index("randomphases=yes"))!=kNPOS) {
    opt.Remove(pos,16);
    fRandomPhases=kTRUE;
  }
  if ((pos = opt.Index("randomphases=no"))!=kNPOS) {
    opt.Remove(pos,15);
    fRandomPhases=kFALSE;
  }

  if ((pos = opt.Index("std"))!= kNPOS) {
    opt.Remove(pos,3);
    mg = MODELGROUP_STD;
  }

  if ((pos = opt.Index("id"))!=kNPOS) {
    opt.Remove(pos,2);
    mo      = STD_ID;
    fRandomPhases=kFALSE;
    SetTitle("STD - Identity");
  }
 
  if ((pos = opt.Index("cost207"))!= kNPOS) {
    opt.Remove(pos,7);
    mg = MODELGROUP_COST207;
  }

  if ((pos = opt.Index("tu"))!=kNPOS) {
    opt.Remove(pos,2);
    mo      = COST207_TU;
    SetTitle("COST207 - Typical Urban  (non-hilly urban environment)");
  }
  if ((pos = opt.Index("ra"))!=kNPOS) {
    opt.Remove(pos,2);
    mo      = COST207_RA;
    SetTitle("COST207 - Rural Area     (non-hilly rural environment)");
  }
  if ((pos = opt.Index("bu"))!=kNPOS) {
    opt.Remove(pos,2);
    mo      = COST207_BU;
    SetTitle("COST207 - Bad Urban      (hilly urban environment)");
  }
  if ((pos = opt.Index("ht"))!=kNPOS) {
    opt.Remove(pos,2);
    mo      = COST207_HT;
    SetTitle("COST207 - Hilly Terrain  (hilly rural environment)");
  }
  
  if ((mg)&&(mo)) SetModel(mg,mo);

  if (opt.Strip().Length())
    Error("SetOption","Unknown Option(s) \"%s\" !!",opt.Strip().Data());
  
}