Example #1
0
void RecoQA(const char* inFile) {
  gROOT->LoadMacro("bfcread_hist_prefixes_add_to_ps.C");

  TString baseName = inFile;
  if (baseName.EndsWith(".daq"))
    baseName.ReplaceAll(".daq",".hist.root");
  else if (baseName.EndsWith(".event.root"))
    baseName.ReplaceAll(".event.root",".hist.root");
  else if (baseName.EndsWith(".MuDst.root"))
    baseName.ReplaceAll(".MuDst.root",".hist.root");

  TString histFile = baseName;

  baseName.Remove(0,baseName.Last('/')+1);

  TString outputName = baseName;
  outputName.ReplaceAll(".root",".CC");

  TString histList = "StRoot/St_QA_Maker/QAhlist_Reco.h";
  if (! gSystem->Which(".",histList.Data()))
    histList.Prepend(gSystem->ExpandPathName("$STAR/"));
  
  bfcread_hist_prefixes_add_to_ps(histFile.Data(),"EventQA",
    "bfcTree",outputName.Data(),baseName.Data(),histList.Data());
}
Example #2
0
//______________________________________________________________________________
Int_t GetMode(TString inputFileName)
{
  if ( inputFileName.EndsWith(".xml") ) return kInteractif_xml;
  else if ( inputFileName.EndsWith(".txt") ) return kInteractif_ESDList;
  else if ( inputFileName.EndsWith(".root") ) return kLocal;
  return -1;
}
void KVElasticCountRates::PrintResults(Double_t beam_intensity)
{
   // Print mean energy deposit & counting rate for given beam intensity in particles per second

   TIter it(&fHistos);
   TH1F* h;
   fRates.clear();

   std::vector<count_rate> count_rates;

   while ((h = (TH1F*)it())) {
      TString name = h->GetName();
      if (!name.EndsWith("_dW") && !name.EndsWith("_map")) {
         TH2F* map = (TH2F*)fHistos.FindObject(name + "_map");
         double rate = h->Integral() * fAtomicDensity * beam_intensity * fVolume / fNtirages;
         double emean = h->GetMean();
         KVDetector* det = gMultiDetArray->GetDetector(name);
         double fluence = rate / det->GetEntranceWindowSurfaceArea();
         double dissipation = emean * rate / det->GetEntranceWindowSurfaceArea();
         count_rates.push_back(
            count_rate(name, rate, emean, map->GetMean(), map->GetMean(2), fluence, dissipation)
         );
         fRates[name.Data()] = KVElasticCountRate(rate, emean, fluence, dissipation);
      }
   }
   std::sort(count_rates.begin(), count_rates.end(), compare_count_rates);

   for (std::vector<count_rate>::iterator it = count_rates.begin(); it != count_rates.end(); ++it) {
      it->print();
   }
}
void make_histos_syst_rawyield(TString file_syst, TString file_default, TString out_tag){

  TFile *f1 = new TFile(file_syst.Data(),"read");
  TFile *f2 = new TFile(file_default.Data(),"read");
  TDirectoryFile *dir1 = (TDirectoryFile*)(f1->Get("effunf"));
  TDirectoryFile *dir2 = (TDirectoryFile*)(f2->Get("effunf"));
  TList *list = dir1->GetListOfKeys();

  TFile *f = new TFile(Form("plots/ratiosyst_%s.root",out_tag.Data()),"recreate");

  for (int i=0; i<list->GetSize(); i++){
    TString name = dir1->GetListOfKeys()->At(i)->GetName();
    if (!(name.Contains("hreco_"))) continue;
    TObject *obj1 = dir1->Get(name.Data());
    assert(obj1);
    TObject *obj2 = dir2->Get(name.Data());
    assert(obj2);
    TString newname = name;
    newname.Append("_ratiosyst");
    if (name.EndsWith("_0")) newname.ReplaceAll("_0_","_EBEB_");
    if (name.EndsWith("_1")) newname.ReplaceAll("_1_","_EBEE_");
    if (name.EndsWith("_2")) newname.ReplaceAll("_2_","_EEEE_");
    TH1F *h = (TH1F*)(((TH1F*)obj1)->Clone(newname.Data()));
    h->SetTitle(h->GetName());
    h->Divide((TH1F*)obj2);
    for (int j=0; j<h->GetNbinsX(); j++) h->SetBinError(j+1,0);
    for (int j=0; j<h->GetNbinsX(); j++) h->SetBinContent(j+1,1+fabs(1-h->GetBinContent(j+1)));
    f->cd();
    h->Write();
  }

}
Example #5
0
void takeDirectlyFromMC(TFile* fin, TFile* fout, TString gentype) {

  TList* listOfDirs = fin->GetListOfKeys();
  for (auto k : *listOfDirs) {
    TString srname = k->GetName();
    if (!srname.Contains("sr")) continue;
    if (srname.Contains("base") || srname.Contains("incl") || srname.Contains("sb")) continue;
    if (gentype == "_1lepW" && !srname.EndsWith("2") && !srname.EndsWith("3")) continue;

    auto indir = (TDirectoryFile*) fin->Get(srname);
    auto outdir = (TDirectory*) fout->mkdir(srname);
    auto hlist = indir->GetListOfKeys();

    for (auto h : *hlist) {
      TString hname = h->GetName();
      if (!hname.BeginsWith("h_metbins" + gentype)) continue;
      TH1D* hin = (TH1D*) indir->Get(hname);
      outdir->cd();
      TH1D* hout = (TH1D*) hin->Clone(TString(hname).ReplaceAll(gentype, ""));
      for (int i = 1; i <= hout->GetNbinsX(); ++i) {
        // zero out negative yields
        if (hout->GetBinContent(i) < 0) {
          hout->SetBinContent(i, 0);
          hout->SetBinError(i, 0);
        }
      }
      hout->Write();

      if (yearSeparateSyst && (hname.EndsWith("Up") || hname.EndsWith("Dn"))) {
        for (int i = 1; i < 4; ++i) {
          TH1D* hcen_yi = (TH1D*) fbkgs[i]->Get(srname+"/h_metbins"+gentype);
          TH1D* hsys_yi = (TH1D*) fbkgs[i]->Get(srname+"/"+hname);
          if (hsys_yi && !hcen_yi) {
            cout << "Find " << srname+"/"+hname << " from " << fbkgs[i]->GetName() << " but not hcen " << srname+"/h_metbins"+gentype << " Should not happen?" << endl;
          }
          TH1D* hout_yi = (TH1D*) fin->Get(srname+"/h_metbins"+gentype)->Clone(TString(hname).Insert(hname.Length()-2, Form("%d", 15+i)).ReplaceAll(gentype, ""));
          if (hcen_yi) hout_yi->Add(hcen_yi, -1);
          if (hsys_yi) hout_yi->Add(hsys_yi);
          hout_yi->Write();
        }
      }
    }
    if (!outdir->Get("h_metbins")) {
      cout << "Didn't find yield hist for " << gentype << " in " << fin->GetName() << ":" << srname << "/. Faking a 0 one!" << endl;
      outdir->cd();
      // Get the MET binning from h_metbins, which shall always exist, and then set all bins to 0
      TH1D* hout = (TH1D*) fin->Get(srname + "/h_metbins")->Clone("h_metbins");
      for (int i = 1; i <= hout->GetNbinsX(); ++i) {
        hout->SetBinContent(i, 0);
        hout->SetBinError(i, 0);
      }
      hout->Write();
    }
  }
}
Example #6
0
void FindAny(bool found, const TString& fsname, TClass* cl, TString baseexpected, const char* ext, const char* tag) {

   if (baseexpected == "") {
      baseexpected = cl->GetName();
      Ssiz_t posCol = baseexpected.First('<');
      if (posCol != -1) {
         baseexpected.Remove(posCol, baseexpected.Length());
      }
      posCol = baseexpected.Last(':');
      if (posCol != -1) {
         baseexpected.Remove(0, posCol + 1);
      }
      baseexpected += ext;
   }

   if (!found) {
      if (baseexpected != "FAIL") {
         printf("FAIL: %s file for class %s not found\n", tag, cl->GetName());
      }
      return;
   } else {
      if (baseexpected == "FAIL") {
         printf("FAIL: expected to not find %s file for class %s but got %s\n",
                tag, cl->GetName(), fsname.Data());
         return;
      }
   }
   if (!fsname.EndsWith(baseexpected)) {
      printf("FAIL: class %s expected %s file %s, got %s\n",
             cl->GetName(), tag, baseexpected.Data(), fsname.Data());
      return;
   }
}
int getTriggerTowerMap(TString src, std::map<unsigned, std::vector<unsigned> >& ttmap) {
   if (!src.EndsWith(".csv")) {
      std::cout << "Input filename must be .csv" << std::endl;
      return 1;
   }
   std::vector<unsigned> values;
   unsigned j = 0;
   std::string line, issline;
   std::ifstream ifs(src.Data());
   while (std::getline(ifs, line)) {
      std::istringstream iss(line);
      while (std::getline(iss, issline, ',')) { // split by commas
         if (j == 0) continue; // skip the first line
         values.push_back(std::stoi(issline));
      }
      ++j;
   }
   if (values.empty()) {
      std::cout << "Failed to read any trigger tower" << std::endl;
      return 1;
   }
   ttmap.clear();
   unsigned ttId = 0;
   for (unsigned i=0; i<values.size(); ++i) {
      if (i == 0) continue; // skip the first index
      if (values.at(i-1) <= 6 && values.at(i) <= 8) { // eta_idx, phi_idx
         ttId = (values.at(i-1)-1) * 8 + (values.at(i)-1); // mapped to 0-47
         ttmap.insert(std::make_pair(ttId, std::vector<unsigned>()));
      } else if (values.at(i) > 10000) {
         ttmap.at(ttId).push_back(values.at(i));
      }
   }
   return 0;
}
Example #8
0
/** 
 * Compare results  
 * 
 * @param argv Commmand line parameters 
 *
 * @relates Compare 
 * @ingroup pwglf_forward_tracklets
 */
void CompareResults(const char** argv)
{
  TString newFile;
  TString oldFile;
  TString newTit("");
  TString oldTit("");
  const char** ptr = argv;
  while ((*ptr)) {
    TString argi = *ptr;
    ptr++;
    if (argi.Contains("help")) {
      Printf("Usage: CompareResults AFILE BFILE [ATITLTE [BTITLE]]");
      return;
    }
    if (argi.Contains("CompareResults.C")) continue;
    if (argi.BeginsWith("-")) continue;
    if (argi.EndsWith(".root")) {
      if (newFile.IsNull()) newFile = argi;
      else                  oldFile = argi;
    }
    else {
      if (newTit.IsNull())  newTit = argi;
      else  	            oldTit = argi;
    }
  }
  if (newTit.IsNull()) newTit = "New";
  if (oldTit.IsNull()) oldTit = "Old";
  
      
  CompareResults(newFile, oldFile, newTit, oldTit);
}
Example #9
0
Bool_t SETUP_LoadLibraries(const TString &libs) {

  // Loads a list of colon-separated libraries. Returns kTRUE on success, kFALSE
  // if at least one library couldn't load properly. Does not check for double
  // loads (but ROOT does).

  TString l;
  Ssiz_t from;

  while ( libs.Tokenize(l, from, ":") ) {
    if (l.IsNull()) continue;
    if (!l.BeginsWith("lib")) l.Prepend("lib");
    if (l.EndsWith(".so")) l.Remove(l.Length()-3, l.Length());

    ::Info(gMessTag.Data(), ">> Loading library %s...", l.Data());

    if (gSystem->Load(l.Data()) < 0) {
       ::Error(gMessTag.Data(), "Error loading %s, aborting", l.Data());
       return kFALSE;  // failure
    }
  }

  return kTRUE;  // success

  return 0;
}
Example #10
0
vector <TString> OnlineConfig::SplitString(TString instring,TString delim) 
{
  // Utility to split up a string on the deliminator.
  //  returns a vector of strings.

  vector <TString> v;

  TString remainingString = instring;
  TString tempstring = instring;
  int i;

  while (remainingString.Index(delim) != -1) {
    i = remainingString.Index(delim);
    tempstring.Remove(i);
    v.push_back(tempstring);
    remainingString.Remove(0,i+1);
    while(remainingString.Index(delim) == 0) {
      remainingString.Remove(0,1);
    }
    tempstring = remainingString;
  }

  while(tempstring.EndsWith(delim)) {
    tempstring.Chop();
  }
     
  if(!tempstring.IsNull()) v.push_back(tempstring);

  return v;
}
Example #11
0
void Finish(TString sDir = "")
{

  // Finishing Macro for running with Worker
  printf("Events: %d      Events Accepted: %d\n", 
	gAN->GetNEvent(), gAN->GetNEvAnalysed() );

  printf("\nEnd-of-Run macro executing\n");

  // If user has not specified output directory, pull from AR
  if(sDir.Length() == 0) sDir = gAR->GetTreeDir();
  if(sDir.Length() == 0) sDir = "~/";
  
  // Append "/" to Directory if unspecified
  if(!(sDir.EndsWith("/"))) sDir.Append("/");

  // Create output filename from input file name
  TString sFile;
  if (gAR->IsOnline()) sFile = gAR->GetFileName();
  else sFile = gAR->GetTreeFile()->GetName();
  while(sFile.Contains("/")) sFile.Remove(0,1+sFile.Index("/"));
  sFile.ReplaceAll(".dat",".root");
  sFile.Prepend("Hist_");
  sFile.Prepend(sDir);

  // Save histograms to file and close it
  TFile f(sFile, "recreate");
  f.SetCompressionLevel(4);
  gROOT->GetList()->Write();
  f.Close();
  cout << "All histograms saved to " << sFile << endl;

  gSystem->Exit(0);

}
Example #12
0
void mergeFiles(const char* outputFile, const char* inputFilesDirectory) {
  // In an interactive ROOT session
  // Do the following
  // root > .L mergeFiles.C
  // root > mergeFiles("<outputFile>", "<inputFilesDirectory>")

  Target = TFile::Open(outputFile, "RECREATE");

  if(strncmp(inputFilesDirectory,"list-in-file:",13)==0) {
	  // Read input file list from a file
	  char const *list_in_file = inputFilesDirectory+13;
	  FILE *fp = fopen(list_in_file,"r");
	  if( !fp ) {
		  int the_errno = errno;
		  cerr << "Failed to open " << list_in_file << ": errno=" << the_errno << " " << strerror(errno) << endl;
		  return;
	  }
	  char fname[2048];
	  while( fgets(fname,sizeof(fname),fp)!=NULL ) {
		  char *newline = strchr(fname,'\n');
		  if( newline ) *newline = '\0';
		  if( !fname[0] ) continue;

          cout << "Merging root file: " << fname << endl;
          MergeRootfile( Target, fname );
	  }
	  fclose(fp);
  }
  else {
	void* dirp = gSystem->OpenDirectory(inputFilesDirectory);
	const char *entry = gSystem->GetDirEntry(dirp);
	while(entry != 0)
	{
		int len = strlen(entry);
		if(len >= 5 && strcmp(&entry[len - 5], ".root") == 0)
		{
			TString fileName;
			if(strncmp(inputFilesDirectory, "/pnfs", 5) == 0)
			{
				fileName = "dcap://";
            }
			fileName += inputFilesDirectory;
			if( !fileName.EndsWith("/") ) fileName += "/";
			fileName += entry;

			cout << "Merging root file: " << fileName << endl;
			MergeRootfile( Target, fileName );
        }
		entry = gSystem->GetDirEntry(dirp);
    }
  }

  // save modifications to target file
  WriteMergeObjects( Target );

  delete Target;
  Target = NULL;
}
Example #13
0
///
/// Perform a couple of consistency checks to make it easier
/// to find bugs:
/// - check if all observables end with '_obs'
/// - check if all predicted observables end with '_th'
/// - check if the 'observables' and 'theory' lists are correctly ordered
///
bool PDF_Abs::checkConsistency()
{
	if ( m_isCrossCorPdf ) return true;
	bool allOk = true;

	// check if all observables end with '_obs'
	TIterator* it = observables->createIterator();
	while ( RooRealVar* p = (RooRealVar*)it->Next() ){
		TString pObsName = p->GetName();
		pObsName.ReplaceAll(uniqueID,"");
		if ( !pObsName.EndsWith("_obs") ){
			cout << "PDF_Abs::checkConsistency() : " << name << " : observable " << p->GetName() << " doesn't end with '_obs'" << endl;
			allOk = false;
		}
	}

	// check if all predicted observables end with '_th'
	delete it; it = theory->createIterator();
	while ( RooRealVar* p = (RooRealVar*)it->Next() ){
		TString pThName = p->GetName();
		pThName.ReplaceAll(uniqueID,"");
		if ( !pThName.EndsWith("_th") ){
			cout << "PDF_Abs::checkConsistency() : " << name << " : theory " << p->GetName() << " doesn't end with '_th'" << endl;
			allOk = false;
		}
	}

	// check if the 'observables' and 'theory' lists are correctly ordered
	for ( int i=0; i<nObs; i++ ){
		RooAbsArg* pTh = theory->at(i);
		TString base = pTh->GetName();
		base.ReplaceAll("_th","");
		base.ReplaceAll(uniqueID,"");
		TString pObsName = observables->at(i)->GetName();
		pObsName.ReplaceAll(uniqueID,"");
		if ( pObsName != base+"_obs"){
			cout << "PDF_Abs::checkConsistency() : " << name << " : " << pTh->GetName() << " doesn't match its observable." << endl;
			cout << "                              Expected '" << base+"_obs" << "'. Found '" << pObsName << "'." << endl;
			cout << "                              Check ordering of the 'theory' and 'observables' lists!" << endl;
			allOk = false;
		}
	}

	return allOk;
}
Example #14
0
inline TString MakeOutputDir(TString dir){
  if(!dir.EndsWith("/")) dir += "/";
  // Create directory if needed
  //  >> NOTE: This function needs to be called before the booking functions!
  char cmd[100];
  sprintf(cmd,"mkdir -p %s", dir.Data());
  system(cmd);
  return dir;
}
Example #15
0
void runTree(char* dir="hist_pAu2", char* filter="16142010", unsigned int neventsIn = 0){  
  // If nEvents is negative, reset to the maximum possible value for an Int_t
  if( neventsIn <= 0 ) neventsIn = 1<<31-1;

  TSystemDirectory DIR(dir, dir);
  TList *files = DIR.GetListOfFiles();
  TChain* trees = new TChain();
  int nfile=0;
  if (files) {
      TSystemFile *file;
      TString fname;
      TIter next(files);
      while ((file=(TSystemFile*)next())) {
	  fname = file->GetName();
	  if (!file->IsDirectory() && fname.BeginsWith(filter) && fname.EndsWith("tree.root")) {
	      cout << Form("Adding %s/%s to TChain",dir,fname.Data())<<endl;
	      trees->AddFile(Form("%s/%s/dipi0",dir,fname.Data()));
	      nfile++;
	  }
      }
  }
  cout << Form("%d files added",nfile) << endl;

  // load the shared libraries
  std::cout << "***** Loading libraries *****" << endl;
  LoadLibs();

  // Create the analysis chain
  analysisChain = new StChain("dipi0Chain");
  
  //cout << "Constructing StFmsDbMaker" << endl;
  //StFmsDbMaker* fmsDbMkr = new StFmsDbMaker( "fmsDb" );
  //fmsDbMkrName = fgtDbMkr->GetName();

  gSystem->Load("StFmsDiPi0");
  StFmsDiPi0* dipi0=new StFmsDiPi0;
  TString filenameDiPi0(Form("%s/%s.dipi0.root",dir,filter));
  cout << "DiPi0 outfile name = " << filenameDiPi0.Data()<<endl;
  dipi0->setFileName(filenameDiPi0.Data());
  dipi0->setReadTree(trees);

  analysisChain->Init();

  Int_t ierr  = kStOK;  // err flag
  Int_t nevents = 0;    // cumulative number of events in
  for( ; nevents < neventsIn && !ierr; ++nevents ){
    if(nevents%10000==0) cout <<"event: "<< nevents <<endl;
    analysisChain->Clear();
    ierr = analysisChain->Make();
  } 
  analysisChain->Finish(); 

  analysisChain->Delete();
  return;
};
Example #16
0
long selectevents(const TString &fileName) {
    TChain* chain = new TChain("MVATree");
    if( fileName.EndsWith(".root") ) {
        chain->Add(fileName);
    }

    int N_Jets;
    chain->SetBranchAddress("N_Jets",&N_Jets);
    float* Jet_Pt = new float[120];
    chain->SetBranchAddress("Jet_Pt",Jet_Pt);
    float* Jet_Phi = new float[120];
    chain->SetBranchAddress("Jet_Phi",Jet_Phi);
    float DeltaPhi;
    chain->SetBranchAddress("DeltaPhi",&DeltaPhi);
    float PtAve;
    chain->SetBranchAddress("PtAve",&PtAve);
    float* Jet_Eta = new float[120];
    chain->SetBranchAddress("Jet_Eta",Jet_Eta);
    float* Jet_CSV = new float[120];
    chain->SetBranchAddress("Jet_CSV",Jet_CSV);
    float* Jet_HadFlav = new float[120];
    chain->SetBranchAddress("Jet_HadronFlav",Jet_HadFlav);
    float* Jet_PartFlav = new float[120];
    chain->SetBranchAddress("Jet_PartonFlav",Jet_PartFlav);
    float Weight_XS;
    chain->SetBranchAddress("Weight_XS",&Weight_XS);

    long nentries=0;
    long n_selected=0;
    float dphicut=2.7;
    float pt3cut=0.1;
    float etamin=2.1;

    nentries = chain->GetEntries();
    cout <<"counting events in "<< fileName << endl;
    cout << "total number of MC events: " << nentries << endl;
    for (long iEntry=0; iEntry<nentries; iEntry++) {
        if(iEntry%100000==0) cout << "analyzing event " << iEntry << endl;
//     if(iEntry>1000000) break;
        chain->GetEntry(iEntry);
        double ptave=PtAve;
        if(N_Jets >=2) {
            if (DeltaPhi> dphicut ) {
                if (abs(Jet_Eta[0])<etamin && abs(Jet_Eta[1])<etamin) {
                    if (N_Jets >=3) {
                        if (Jet_Pt[2]/ptave < pt3cut) n_selected++;
                    }
                    else if (N_Jets==2) n_selected++;
                }
            }
        }
    }
    cout << n_selected<< " Events selected" << endl;
    return n_selected;
}
Example #17
0
// Helper functions to set argument
inline TString parseArg(const TString& input, TString arg, const TString dfval="") {
  if (!arg.EndsWith("=")) arg += "=";
  if (input.Contains(arg)) {
    int sidx = input.Index(arg) + arg.Sizeof() - 1;
    int eidx = input.Index(",", sidx);
    if (eidx < 0) eidx = input.Sizeof();
    return input(sidx, eidx-sidx);
  } else {
    return dfval;
  }
}
Example #18
0
//============================================================
// <T>存储文件。</T>
//
// @param pFileName 文件名称
// @return 处理结果
//============================================================
TResult FFbxResModel::SaveFile(TCharC* pFileName){
   // 存储数据文件
   TString dataFileName = pFileName;
   SaveDataFile(dataFileName);
   if(dataFileName.EndsWith(TC(".model"))){
      // 存储配置文件
      //TString configFileName = dataFileName.LeftStrC(dataFileName.Length() - 6);
      //configFileName.Append((TCharC*)TC(".xml"));
      //SaveConfigFile(configFileName);
   }
   return ESuccess;
}
TH1* getHistogram(TFile* inputFile, const TString& dqmDirectory, const TString& meName)
{
    TString histogramName = dqmDirectory;
    if ( histogramName.Length() > 0 && !histogramName.EndsWith("/") ) histogramName.Append("/");
    histogramName.Append(meName);
    std::cout << "histogramName = " << histogramName.Data() << std::endl;

    TH1* histogram = (TH1*)inputFile->Get(histogramName.Data());
    std::cout << "histogram = " << histogram << std::endl;

    return histogram;
}
Example #20
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 #21
0
/**
 * Returns a suitable epsFilename build from a file or directory name and
 * histogram name.
 *
 * @param fileOrDirectoryName
 *                            name of the file or directory
 * @param histogramNamw
 *                            name of the histogram
 * @return
 *                            a suitable epsFilename
 */
TString
epsFilename(const TString& fileOrDirectoryName, const TString& histogramName)
{
// {{{
    TString s = fileOrDirectoryName;
    if (s.EndsWith("/")) s.Remove(s.Length()-1);
    s = gSystem->BaseName(s);
    s.ReplaceAll(".root", "");
    s.Append(".").Append(histogramName);
    s.ReplaceAll(".", "_");
    return s;
// }}}
};
Example #22
0
void CheckDirFiles(const char *dir, TList *files)
{
  void *pdir = gSystem->OpenDirectory(dir);
  if (!pdir || !files) return;

  const char *file;
  while ((file = gSystem->GetDirEntry(pdir))) {
    TString dirFile = TString::Format("%s/%s", dir, file);
    if (!dirFile.EndsWith(".np")) continue;   // only data file
    if (files->FindObject(dirFile)) continue; // no duplicate
    files->Add(new TObjString(dirFile));
  }
  files->Sort();
}
void get_filenames(vector<TString> &names, const char *dirname=".", const char *ext=".root", const char *prefix = "uhh2")
{
  TSystemDirectory dir(dirname, dirname);
  TList *files = dir.GetListOfFiles();
  if (files) {
    TSystemFile *file;
    TString fname;
    TIter next(files);
    while ((file=(TSystemFile*)next())) {
      fname = file->GetName();
      if (!file->IsDirectory() && fname.EndsWith(ext) && fname.BeginsWith(prefix)) {
	names.push_back(TString(fname.Data()));
      }
    }
  }
}
Example #24
0
void addPerformance(const Int_t it)
{ 
  if(!narr[it]){
    narr[it] = (TObjArray*)arr->Clone(); narr[it]->SetOwner();
    gDirectory->ls();
    return;
  }

  TObject *oo(NULL);
  TH1 *h1(NULL), *H1(NULL);  
  THnSparse *h(NULL), *H(NULL);
  Int_t nplots(plots[it]->GetEntries());
  TString sname;
  for(Int_t ih(0); ih<nplots; ih++){
    sname= ((TObjString*)(*plots[it])[ih])->String();
    if(!mc && sname.EndsWith("MC")) continue;

    if(!(oo = (TObject*)arr->FindObject(sname.Data()))) {
      Warning("addPerformance", "Missing %s from \"%s\"", sname.Data(), file->GetName());
      continue;
    }
    if(strstr(oo->IsA()->GetName(), "THnSparse")){ 
      h = dynamic_cast<THnSparse*>(oo);
      if(!(H = (THnSparse*)narr[it]->FindObject(sname.Data()))) {
        Error("addPerformance", "Missing %s from Merging.", sname.Data());
        return;
      }
      H->Add(h);
      if(kWrite) printf("  -> %s[%d]\n", sname.Data(), (Int_t)H->GetEntries());
    } else if(strstr(oo->IsA()->GetName(), "TH")){ 
      h1 = dynamic_cast<TH1*>(oo);
      if(!(H1 = (TH1*)narr[it]->FindObject(sname.Data()))) {
        Error("addPerformance", "Missing %s. from Merging.", sname.Data());
        return;
      }
      H1->Add(h1);
      if(kWrite) printf("  -> %s[%d]\n", sname.Data(), (Int_t)H1->GetEntries());
    } else{
      Warning("addPerformance", "Object %s. from \"%s\" of unknown class %s", sname.Data(), file->GetName(), oo->IsA()->GetName());
      continue;
    }
  }
  if(kWrite){
    narr[it]->Write(taskName[it], /*TObject::kOverwrite|*/TObject::kSingleKey);
    narr[it]->Delete(); delete narr[it]; narr[it] = NULL;
  }
}
TH1* getHistogram(TFile* inputFile, const TString& dqmDirectory, const TString& meName)
{  
  TString histogramName = dqmDirectory;
  if ( histogramName.Length() > 0 && !histogramName.EndsWith("/") ) histogramName.Append("/");
  histogramName.Append(meName);

  TH1* histogram = (TH1*)inputFile->Get(histogramName.Data());
  std::cout << "histogramName = " << histogramName.Data() << ": histogram = " << histogram;
  if ( histogram ) std::cout << ", integral = " << histogram->Integral();
  std::cout << std::endl; 

  if ( !histogram->GetSumw2N() ) histogram->Sumw2();

  if ( histogram->GetDimension() == 1 ) histogram->Rebin(5);

  return histogram;
}
Example #26
0
void profileUE(TString outUrl)
{
  //prepare output
  if(outUrl!=""){
    gSystem->ExpandPathName(outUrl);
    if(!outUrl.EndsWith("/")) outUrl = outUrl +"/";
    gSystem->Exec("mkdir -p " + outUrl);
    outDir=outUrl;
  }

  profileDistributions("nchprofpt");
  profileDistributions("ptfluxprofpt");
  profileDistributions("avgptfluxprofpt");
  profileDistributions("nchprofmt");
  profileDistributions("ptfluxprofmt");
  profileDistributions("avgptfluxprofmt");
  profileDistributions("ptfluxprofphi");
}
Example #27
0
//______________________________________________________________________________
TChain* CreateChainFromESDList(const char *esdList)
{
  // Create a chain using tags from the run list.
  TChain* chain = new TChain("esdTree");
  ifstream inFile(esdList);
  TString inFileName;
  if (inFile.is_open()) {
    while (! inFile.eof() ) {
      inFileName.ReadLine(inFile,kFALSE);
      if(!inFileName.EndsWith(".root")) continue;
      chain->Add(inFileName.Data());
    }
  }
  inFile.close();
  if (!chain->GetNtrees()) return NULL;
  chain->ls();
  return chain;
}
void BrowseHistograms(const char* histname) {

    fHistName=histname;

  TSystemDirectory dir(".",".");
  TList *files = dir.GetListOfFiles();
  if (!files) {
    cerr << "Error: No files found in " << fFileDir << endl;
    return;
  }
  files->Sort();


  histograms = new TList();
  saved = new TList();

  c = new TCanvas("canvas","Browse Histograms");

  TSystemFile *file;
  TIter next(files);
  Int_t n=0;
  TString fname;
  while ((file=(TSystemFile*)next())) {
    fname = file->GetName();
    if (!file->IsDirectory() && fname.EndsWith(".root")) {

      histograms->Add(new TObjString(fname));
      n++;
      //if(n>10)
      //	break;
    }
  }

  DrawCurrHistogram();

  TControlBar *bar = new TControlBar("vertical", "Control", 10, 10);
  bar->AddButton("Next","ProcessClick(1);", "Show next run");
  bar->AddButton("Next And Save","NextAndSave();", "Show previous run");
  bar->AddButton("Next And Forget","NextAndForget();", "Show previous run");
  bar->AddButton("Prev","ProcessClick(-1);", "Show previous run");
  bar->AddButton("Print saved","PrintSaved();", "Show previous run");
  bar->SetButtonWidth(90);
  bar->Show();
}
Example #29
0
TChain* CreateChain(const char* treeName, const char* aDataDir, Int_t aRuns, Int_t offset = 0)
{
  // creates chain of files in a given directory or file containing a list.

  if (!treeName || !aDataDir)
    return 0;

  TChain* chain = new TChain(treeName);
  
  // Open the input stream
  ifstream in;
  in.open(aDataDir);

  Int_t count = 0;

  // Read the input list of files and add them to the chain
  TString line;
  while(in.good()) 
  {
    in >> line;
      
    if (line.Length() == 0)
      continue;
    
    if (offset > 0)
    {
      --offset;
      continue;
    }

    if (count++ == aRuns)
      break;

    if (line.EndsWith(".zip"))
      line += "#AliAOD.root";

    chain->Add(line);
  }

  in.close();

  return chain;
}
//_____________________________________________________________________________
TChain *CreateAODFriendChain(TString sDataset)
{ 
  if (!sDataset.EndsWith(".txt")) return 0;

  TChain *chain = new TChain("aodTree");
  TChain *cFrid = new TChain("aodTree");

  TString dataFile;
  ifstream dataList(sDataset.Data(), ios::in); 
  while (!dataList.eof()) {
    dataFile.ReadLine(dataList,kFALSE);
    if (!dataFile.EndsWith("AliAOD.root")) continue;
    if (!gSystem->AccessPathName(dataFile.Data())) chain->Add(dataFile.Data());

    dataFile.ReplaceAll("AliAOD.root","AliAOD.VertexingHF.root");
    if (!gSystem->AccessPathName(dataFile.Data())) cFrid->Add(dataFile.Data());
  } dataList.close();

  chain->AddFriend(cFrid);
  return chain;
}