Example #1
0
Int_t getXrootdPid(Int_t port, const char *subdir)
{
#ifdef WIN32
   // No support for Xrootd/Proof on Win32 (yet; the optimized local Proof will work there too)
   Printf("getXrootdPid: Xrootd/Proof not supported on Windows, sorry!");
   return -1;
#else
   // Get the pid of the started xrootd process
   Int_t pid = -1;
#if defined(__sun)
   const char *com = "-eo pid,comm";
#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
   const char *com = "ax -w -w";
#else
   const char *com = "-w -w -eo pid,command";
#endif
   TString cmd;
   if (subdir && strlen(subdir) > 0) {
      cmd.Form("ps %s | grep xrootd | grep \"\\-p %d\" | grep %s", com, port, subdir);
   } else {
      cmd.Form("ps %s | grep xrootd | grep \"\\-p %d\"", com, port);
   }
   FILE *fp = gSystem->OpenPipe(cmd.Data(), "r");
   if (fp) {
      char line[2048], rest[2048];
      while (fgets(line, sizeof(line), fp)) {
         sscanf(line,"%d %s", &pid, rest);
         break;
      }
      gSystem->ClosePipe(fp);
   }
   // Done
   return pid;
#endif
}
Example #2
0
void SampleDiagnostics::report(TString tablesPrefix, const Char_t* errata) const
{
  if (passedRate == 0) {
    std::cerr << "WARNING :  No accumulated rate for " << name << ". Maybe you just didn't run over it/them?" << std::endl;
    return;
  }


  TString           blurb;        blurb.Form("These results are for %s. %s", name.Data(), errata ? errata : "");
  std::ofstream     tablesFile    (tablesPrefix + ".tex");
  tablesFile << "\\documentclass[amsmath,amssymb]{revtex4}" << std::endl;
  tablesFile << "\\usepackage{longtable}" << std::endl;
  tablesFile << "\\usepackage{color}" << std::endl;
  tablesFile << "\\begin{document}" << std::endl;
  tablesFile << "\\tableofcontents" << std::endl;
  tablesFile << "\\clearpage" << std::endl << std::endl << std::endl;

  const UInt_t      numDatasets   = size();
  for (UInt_t iSet = 0; iSet < numDatasets; ++iSet)
    if (at(iSet).isNewTrigger)    at(iSet).report(tablesFile, *this, blurb);

  tablesFile << std::endl << std::endl << "\\end{document}" << std::endl;
  tablesFile.close();
  TString     pdfIt;
  pdfIt.Form("latex %s.tex ; latex %s.tex ; latex %s.tex ; dvipdf %s.dvi %s.pdf", tablesPrefix.Data(), tablesPrefix.Data(), tablesPrefix.Data(), tablesPrefix.Data(), tablesPrefix.Data());
  //pdfIt       += TString::Format(" & (rm %s.aux %s.dvi %s.tex %s.log %s.toc)", tablesPrefix.Data(), tablesPrefix.Data(), tablesPrefix.Data(), tablesPrefix.Data(), tablesPrefix.Data(), tablesPrefix.Data());
  pdfIt       += TString::Format(" ; rm %s.aux %s.dvi %s.log %s.toc", tablesPrefix.Data(), tablesPrefix.Data(), tablesPrefix.Data(), tablesPrefix.Data(), tablesPrefix.Data());
	//RR commenting the latex compilation for now
//   if (gSystem->Exec(pdfIt) == 0)   std::clog << "  +  " << tablesPrefix << ".pdf" << std::endl;
//   else  std::clog << "  -  " << tablesPrefix << ".pdf  ---  FAILED to compile tex file!" << std::endl;
}
Example #3
0
void
Correct(UShort_t    flags=0x3,
	const char* side="middle",
	const char* var="none",
	Bool_t      forceK=false)
{
  const char* fwd = "$ALICE_PHYSICS/PWGLF/FORWARD/analysis2";
  if (gSystem->Getenv("ANA_SRC")) fwd = gSystem->Getenv("ANA_SRC");
  CorrectNS::AddPath(TString::Format("%s/dndeta/tracklets", fwd));
  if (!gROOT->GetListOfGlobals()->FindObject("kSimpleCorrectLoaded"))
    gROOT->LoadMacro("SimpleCorrect.C");
  TString v(var);
  if (v.EqualTo("PtPidStrK")) { forceK = true; v = "PtPidStr"; }
  Printf("Processing dt_%s_%s/trdt.root and mc_%s_%s/trmc.root",
	 side, "none", side, v.Data());
  SimpleCorrect(flags, TString(var).EqualTo("none") || forceK ? 2 : 3,
		Form("dt_%s_%s/trdt.root", side, "none"),
		Form("mc_%s_%s/trmc.root", side, v.Data()),
		9,
		"");
  TString resFile;
  resFile.Form("result_0x%x.root", flags & 0x3);
  TObject* resObj = gROOT->GetListOfFiles()->FindObject(resFile);
  if (resObj) {
    TFile* tmp = static_cast<TFile*>(resObj);
    Printf("Closing %s", tmp->GetName());
    tmp->Close();
  }
  gSystem->mkdir("partial", 1);
  TString dest;
  dest.Form("partial/%s_%s_0x%x.root", side, var, flags&0x3);
  Printf("%s -> %s", resFile.Data(), dest.Data());
  gSystem->Rename(resFile, dest);
}
void make_scan_results()
{
  TFile *f = TFile::Open("scan_results.root", "UPDATE");

  f->Delete("SR;*");

  T = new TTree("SR", "Scanning results");

  TClonesArray* ts = new TClonesArray("IlcESDtrack", 32);
  TBranch * tb = T->Branch("T", &ts);
  delete ts;

  IlcMultiplicity *ms = 0;
  TBranch *mb = T->Branch("M", &ms);

  for (Int_t v = 0; v < 3; ++v)
  {
    vvv[v].vert   = 0;
    vvv[v].branch = T->Branch(vvv[v].bname, &vvv[v].vert);
  }

  for (Int_t i=0; i<=9999; ++i)
  {
    TString name;

    name.Form("Tracks_%04d", i);
    ts = (TClonesArray*) f->Get(name);
    if (ts == 0)
      continue;

    name.Form("Tracklets_%04d", i);
    ms = (IlcMultiplicity*) f->Get(name);
    if (ms == 0)
      Error("make_scan_results", "'%s' not found.", name.Data());

    tb->SetAddress(&ts);
    mb->SetAddress(&ms);

    for (Int_t v = 0; v < 3; ++v)
    {
      name.Form("%s_%04d", vvv[v].oname, i);
      vvv[v].vert = (IlcESDVertex*) f->Get(name);
      if (vvv[v].vert == 0)
        Error("make_scan_results", "'%s' not found.", name.Data());
      vvv[v].branch->SetAddress(&vvv[v].vert);
    }

    T->Fill();

    delete ts;
    delete ms;
    for (Int_t v = 0; v < 3; ++v) delete vvv[v].vert;
  }

  T->Write();

  f->Close();
  delete f;
}
Example #5
0
void plot_mc(string name="g", double q2=1.9, Int_t n=0)
{
//    SetAtlasStyle();
    TGraphErrors *p;

    TString nn;
    nn.Form("ave_%s_vs_x_for_Q2=%g",name.c_str(),q2);
    gDirectory->GetObject(nn,p);

//    p->Print();

    Double_t ratsize = 0.0;

    TCanvas *c = new TCanvas("PDF","pdf",600,600);
    TPad *pad1 = new TPad("pad1","pad1",0.,ratsize,1.,1.);
    pad1->SetLogx();
    pad1->Draw();
    pad1->cd();
    p->GetXaxis()->Set(101,0.0001,1.);
    p->SetFillColor(kRed-2);
    p->SetFillStyle(3001);
    p->SetLineWidth(1);
    p->SetLineColor(kRed);
    p->GetYaxis()->SetTitle(name.c_str());

    p->GetYaxis()->SetTitleSize(0.06);
    p->GetYaxis()->SetTitleOffset(1.);
    p->GetXaxis()->Set(101,0.0001,1.);
    p->Draw("ALE3");

    Double_t av = 0;
    Double_t av2 = 0;

    for (Int_t i = 1; i<n+1 ; i++) {
        nn.Form("%s_vs_x_for_Q^{2}=%g_%i",name.c_str(),q2,i);
        TGraph *pp = NULL;
        gDirectory->GetObject(nn,pp);
        if (pp != NULL) {
            pp->SetLineColor(kGreen);
            pp->Draw("L");

            av  += pp->GetY()[0];
            av2 += pp->GetY()[0]*pp->GetY()[0];
            cout << i << " "<<pp->GetY()[0] << endl;


        }
    }

    av  /= n;
    av2 = sqrt(av2/n - av*av);
//    cout << n << " "<<av << " "<< av2<<endl;


    p->Draw("E3C");


}
Example #6
0
Bool_t RawFileReader::readBoard(Entry &entry,RawData &rdata,Int_t N){
	if(N!=0 && N!=1){
		throw RDKException("Index out of range");
	}
	if(!bboard[N].good()){
		return false;
	}
	bboard[N].read();
	Bool_t startEntry=true;
	TString line;
	for(Int_t j=0;j<2;j++){
		if(!startEntry){
			break;
		}
		line=bboard[N].getString(4);
		startEntry&=line=="****";
	}
	if(!startEntry){
		return false;
	}
	entry.nseries=nseries;
	entry.nrun=nrun;
	bboard[N].getInt();
	entry.timestamp[N]=bboard[N].getDouble();
	Int_t n=bboard[N].getInt();
	if(n!=NCHANNELS/2){
		TString temp;
		temp.Form("Unknown file format: %X != %X in board %i at %X",n,NCHANNELS/2,N+1,(Int_t)bboard[N].tellg()-4);
		throw RDKException(temp);
	}
	Int_t hp=bboard[N].getInt();
	if(hp!=0xFF){
		TString temp;
		temp.Form("Unknown file format: %X != FF in board %i at %X",hp,N+1,(Int_t)bboard[N].tellg()-4);
		throw RDKException(temp);
	}
	Int_t min,max;
	if(N==0){
		min=0;
		max=NGAMMA/2;
	}else{
		min=NGAMMA/2;
		max=NGAMMA;
	}
	for(Int_t i=min;i<max;i++){
		bboard[N].copyShort(rdata.ch[i],NPOINTS);
	}
	Int_t mult=(NCHANNELS-NGAMMA)/2;
	for(Int_t i=0;i<mult;i++){
		bboard[N].copyShort(rdata.ch[NGAMMA+2*i+1-N],NPOINTS);
	}
	return true;
}
Example #7
0
Bool_t RDKReader::readBoard(Entry &entry,RawData &rdata,Int_t N){
	if(N!=0 && N!=1){
		throw RDKException("Index out of range");
	}
	if(!board[N]->good()){
		return false;
	}
	Bool_t startEntry=true;
	TString line;
	for(Int_t j=0;j<2;j++){
		if(!startEntry){
			break;
		}
		line=board[N]->readString(4);
		startEntry&=line=="****";
	}
	if(!startEntry){
		return false;
	}
	entry.nseries=nseries;
	entry.nrun=nrun;
	entry.nevent=board[N]->readInt();
	entry.timestamp[N]=board[N]->readDouble();
	//Double_t timestamp=board[1]->readDouble();
	Int_t n=board[N]->readInt();	//number of waves=8
	if(n!=NCHANNELS/2){
		TString temp;
		temp.Form("Unknown file format: %X != %X in board %i at %X",n,NCHANNELS/2,N+1,(Int_t)board[N]->tellg()-4);
		throw RDKException(temp);
	}
	Int_t hp=board[N]->readInt();
	if(hp!=0xFF){
		TString temp;
		temp.Form("Unknown file format: %X != FF in board %i at %X",hp,N+1,(Int_t)board[N]->tellg()-4);
		throw RDKException(temp);
	}
	Int_t min,max;
	if(N==0){
		min=0;
		max=NGAMMA/2;
	}else{
		min=NGAMMA/2;
		max=NGAMMA;
	}
	for(Int_t i=min;i<max;i++){
		board[N]->readData(NPOINTS,rdata.ch[i]);
	}
	Int_t mult=(NCHANNELS-NGAMMA)/2;
	for(Int_t i=0;i<mult;i++){
		board[N]->readData(NPOINTS,rdata.ch[NGAMMA+2*i+1-N]);
	}
	return true;
}
Example #8
0
const Char_t *KVSpectroDetector::GetDetectorEnv(const Char_t * type, const Char_t* defval, TEnv *env) const
{
   //Will look for env->GetValue "name_of_detector.type" if defined or "type_of_detector.type" if not.
   //If neither resource is defined, return the "defval" default value (="" by default).
   //If env is null then it looks for in gEnv.

	if( !env ) env = gEnv;

   TString temp;
   temp.Form("%s.%s", GetName(), type);
   if( !env->Defined(temp.Data()) )  temp.Form("%s.%s", GetType(), type);
   return env->GetValue(temp.Data(), defval);
}
Example #9
0
void RawFileReader::open(Char_t t,Int_t series,Int_t run){
	if(isOpen){
		close();
	}
	bboard=new BufferedReader[2];
	bboard[0].resize(eventSize);
	bboard[1].resize(eventSize);
	header=new Header[2];
	size=new Long64_t[2];
	foot_size=new Long64_t[2];
	nseries=series;
	nrun=run;
	type=t;
	if(type=='S'){
		current=-1;
	}else if(type=='C' || type=='D'){
		current=0;
	}
	TString path;
	if(type){
		FileStat_t stats;
		for(Int_t i=0;i<2;i++){
			path.Form("%s/ss%i/%c%ir%ib%i.dat",RDKRAW,nseries,type,nseries,nrun,i+1);
			if(!gSystem->GetPathInfo(path,stats)){
				size[i]=stats.fSize;
				bboard[i].open(path);
				header[i].getHeader()->DeleteAll();
			}else{
				path.Form("Unable to stat ss%i/%c%ir%ib%i.dat",nseries,type,nseries,nrun,i+1);
				throw RDKException(path);
			}
		}
		if(type=='S' && size[0]!=size[1]){
			close();
			path.Form("File error: sizes of ss%i/S%ir%i*.dat do not match",nseries,nseries,nrun);
			throw RDKException(path);
		}
		for(Int_t i=0;i<2;i++){
			foot_size[i]=size[i];
			size[i]=(size[i]-5000)/eventSize;
			foot_size[i]-=5000+size[i]*eventSize;
		}
		isOpen=kTRUE;
		readHeader();
	}else{
		path.Form("Unable to type ss%i/*%ir%i",nseries,nseries,nrun);
		throw RDKException(path);
	}
}
Example #10
0
KVTGID *KVRTGIDManager::GetTGID(const Char_t * ,
                               const Char_t * id_type,
                               const Char_t * grid_type){
   //Overrides the same method of KVTGIDManager. This method
   //Retrieve the identification object using:
   //      id_type   = type of identification ("Z", "A", "A_for_Z=3", etc.)
   //      grid_type = type of identification grid ("GG", "PG1", etc.)
   // but the name of ID telescope is not used anymore because identification
   // object can be associated to several ID telescopes.
   // If any object is found then it returns the first:
   //      - KVTGIDZA object if id_type contains "A"
   //      - KVTGIDZ  object else.

	Char_t  cname[9] = "KVTGIDZ";
	TString buff     = id_type;

	if(buff.Contains("A")) strcpy(cname,"KVTGIDZA");

	buff.Form("_%s_%s",id_type, grid_type);

	TIter next(&fIDList);
	KVTGID *tgid  = NULL;
	KVTGID *tgid2 = NULL;
	TString name;

	while( (tgid = (KVTGID *)next()) ){
		name = tgid->GetName();
		if(name.Contains(buff)) return tgid;
		if(!tgid2 && !strcmp(tgid->ClassName(),cname)) tgid2 = tgid;
	}

   return tgid2;
}
Example #11
0
void KVHarpeeIC::SetACQParams()
{
   // Setup acquisition parameters of this ionisation chamber.
   // ACQ parameters with type 'E':
   // E[detector type]_[A,B,C]_[detector number]
   //
   // WARNING: actually only the acquisition parameters with indice 'A'
   // are defined ('B' and 'C' were not coded in e494s and e503 experiment ).

   TString name;
   Char_t idx[] = {'A', 'B', 'C'};

   for (Int_t num = 1; num <= ARPEEIC_NSEG; num++) {
//    for(Int_t i = 0; i<3; i++){
      for (Int_t i = 0; i < 1; i++) {
         KVACQParam* par = new KVACQParam;
         name.Form("E%s_%c_%d", GetType(), idx[i], num);
         par->SetName(name);
         par->SetType("E");
         par->SetLabel(Form("%c", idx[i]));
         par->SetNumber(num);
         par->SetUniqueID(CalculateUniqueID(par));
         AddACQParam(par);
      }
   }
}
Example #12
0
Bool_t RawFileReader::seek(Int_t i){
	Bool_t success=kFALSE;
	if(type=='S'){
		if(i>=0 && i<=size[0]){
			Long64_t position=5000+eventSize*i;
			bboard[0].seekg(position);
			bboard[1].seekg(position);
			success=kTRUE;
		}
	}else if(type=='C' || type=='D'){
		if(i>=0 && i<size[0]){
			current=0;
			Long64_t position=5000+eventSize*i;
			bboard[0].seekg(position);
			bboard[1].seekg(5000);
		}else if(i<=size[0]+size[1]){
			current=1;
			Long64_t position0=5000+size[0]*eventSize;
			Long64_t position1=5000+(i-size[0])*eventSize;
			bboard[0].seekg(position0);
			bboard[1].seekg(position1);
		}else{
			current=-1;
			TString temp;
			temp.Form("Out of bounds error: %ll",i);
			throw RDKException(temp);
		}
		success=kTRUE;
	}
	return success;
}
Example #13
0
void pulseHeights(Int_t board=112, TString file="latest.root", 
		  Int_t xmin=300, Int_t xmax=50){

  TFile *f = new TFile(file);
  // create a pointer to an event object for reading the branch values.
  TBEvent *event = new TBEvent();
  TTree *t1041 = (TTree*) f->Get("t1041");
  TBranch *bevent = t1041->GetBranch("tbevent");
  bevent->SetAddress(&event);
  
  TH1F *hpulse[32];
  for (int i=0; i<32; i++){
    TString name;
    name.Form("h%d_%2d",board,i);
    hpulse[i]=new TH1F(name,name,xmax-xmin,xmin,xmax);
  }


  // loop over events
  for (Int_t i=0; i< t1041->GetEntries(); i++) {
    t1041->GetEntry(i);
    // loop over PADE channels
    for (Int_t j=0; j<event->NPadeChan(); j++){
      if (event->GetPadeChan(j).GetBoardID() != board) continue;
      int chan=event->GetPadeChan(j).GetChannelID();
      hpulse[chan]->Fill(event->GetPadeChan(j).GetMax());
    }
  }
  
}
Example #14
0
std::vector<int> getruns(const char * inputdir, int chip, string list = "") {

  std::vector<int> runs;

  gSystem->OpenDirectory(inputdir);
  ifstream in;
  string line;
  TString name;
  name.Form("runlist-%i%s.csv",chip,list.c_str());
  std::cout << "Opening " << name << endl;
  in.open(name);

  // Skip first line:
  getline(in,line);

  while(std::getline(in,line)){
    // Skip reading comments:
    if (line[0] == '#') continue;
    if(line.empty()) continue;

    istringstream s( line );
    int i = 0;
    int run;
    while (s) {
      string str;
      if(!getline( s, str, ',' )) break;
      if(i == 0) run = atoi(str.c_str()); // Read run number
      if(i == 4 && chip == atoi(str.c_str())) { runs.push_back(run); } // Read DUT chip id
      i++;
    }
  }

  in.close();
  return runs;
}
Example #15
0
  /** 
   * Start a unique XRootd server and return it's access URL 
   * 
   * @param url On return, the access url 
   * 
   * @return true if successful, false otherwise 
   */
  static Bool_t StartXrootd(TString& url)
  {
    url = "";
    Int_t port = FindPort();
    if (port < 0) return false;

    // Get host, current directory, and user name for unique name
    TString host(gSystem->HostName());
    TString dir(gSystem->WorkingDirectory());
    TString name(gSystem->GetUserInfo()->fUser.Data());

    // Form the command line.  Note, we put the PID file one level up,
    // so we know where to look for it. Otherwise it would be put in a
    // sub-directory based on the name of the server.  Since we later
    // on don't know the name of the server we wouldn't now where to
    // look for the PID file
    TString exec;
    exec.Form("xrootd -p %d -l xrd.log -s ../xrd.pid -b -n %s %s",
	      port, name.Data(), dir.Data());
    Info("StartXrootd", "Starting XRootD to serve %s on port %d",
	 dir.Data(), port);
    Info("StartXrootd", "%s", exec.Data());
    int ret = gSystem->Exec(exec);
    if (ret != 0) {
      Warning("StartXrootd", "Failed to start XRootd server");
      return false;
    }
    
    // Form the access URL
    url = Form("root://%[email protected]%s:%d/%s",
	       name.Data(), host.Data(), port, dir.Data());
    Info("StartXrootd", "Access URL is \"%s\"", url.Data());

    return true;
  }
Example #16
0
const Char_t *KVINDRAIDTelescope::GetArrayName()
{
   // Name of telescope given in the form Det1_Det2_Ring-numberTelescope-number
   //where ring and telescope numbers are those of the smallest (in angular terms)
   //detector of the telescope (if both are the same size, either one will do).
   // The detectors are signified by their TYPE names i.e. KVDetector::GetType

   //in order to access angular dimensions of detectors, we need their KVTelescopes
   KVINDRATelescope *de_det = dynamic_cast<KVINDRADetector*>(GetDetector(1))->GetTelescope();
   KVINDRATelescope *e_det = 0;
   if (GetSize() > 1)
      e_det = dynamic_cast<KVINDRADetector*>(GetDetector(2))->GetTelescope();
   UInt_t ring, mod;
   if (!e_det || de_det->IsSmallerThan(e_det)) {
      ring = de_det->GetRingNumber();
      mod = de_det->GetNumber();
   } else {
      ring = e_det->GetRingNumber();
      mod = e_det->GetNumber();
   }
   SetName(GetDetector(1)->GetType());
   if (e_det) {
      fName.Append("_");
      fName.Append(GetDetector(2)->GetType());
   }
   SetType(fName.Data());
   fName.Append("_");
   TString num;
   num.Form("%02d%02d", ring, mod);
   fName += num;

   return fName.Data();
}
void poissonPosterior(int nbg=1, int nsiglike_sideband = 10, int nsideband =100, int prior = JEFFREYS_PRIOR, int N = 100000) 
{
  //TH1D fillme("posterior","Posterior test", 1000,0,5*nbg*nsiglike_sideband/nsideband); 
  TH1D fillme("posterior","Posterior test", 1000,0,10); 
  fillABCD(nbg,nsiglike_sideband,nsideband,&fillme,prior, N); 
  fillme.Scale(1./N); 
  TString str;
  str.Form("NBG=%d, NSB_SIGLIKE = %d, NSB=%d, %s", nbg, nsiglike_sideband, nsideband, priors[prior]); 
  fillme.SetTitle(str.Data()); 
  fillme.DrawCopy(); 

  const double probsum[]={0.16,0.5,0.84} ; 
  double q[3]; 
  fillme.GetQuantiles(3,q,probsum); 

  printf(" Multiplying posteriors of individual poissons for: \n"); 
  printf("   (nbg=%d) * ( nsiglike_sideband=%d ) / (nsideband =%d)\n", nbg, nsiglike_sideband, nsideband); 
  printf(" %s\n", priors[prior]); 
  printf(" Mean: %g\n",fillme.GetMean()); 
  printf(" RMS: %g\n",fillme.GetRMS()); 
  printf(" Median: %g\n",q[1]); 
  printf(" 16th percentile: %g\n",q[0]); 
  printf(" 84th percentile: %g\n",q[2]); 
  printf(" Median-1 sigma: %g\n",q[1]-q[0]); 
  printf(" Median+1 sigma: %g\n",q[2]-q[1]); 
}
Example #18
0
// Reading CLAS data
// TString directory -> directory path 
// int Q2_flag_bin -> number of Q2 bins
// int z_flag_bin-> number of z bins
// int target_flag -> target
// int particle_flag -> particle 
// int flag_t -> 1->Colllins, 2->Sivers,3->Pretzelosity
int read_data_clas(char const * directory = "", int particle_flag=1){
	//particle_flag = 1->pip,2->pim

	TString particle = "X";
	if(particle_flag==1)
		particle ="pip";
	else if(particle_flag==2)
		particle ="pim";
	else{
		cerr<<"I don't know this particle flag!"<<endl;
	}
	TString filename;
	filename.Form("%s/projections_4D_%s_solid.out",directory,particle.Data());
	ifstream infile(filename);

	int ncount=0;
	int bin = -1;
	TString dum;
	infile >> dum >> dum >> dum >> dum >> dum >> dum >> dum >> dum;
	while(!(infile.eof())){
		infile >> bin >> xval[ncount] >> ptval[ncount] >> zval[ncount] >> Q2val[ncount] >> yval[ncount] >> N[ncount]>> Astat[ncount];
		if(Astat[ncount]>1.e-9){
			if(VERBOSE1) cout<<Form("---#%5d: bin=%d z=%f, Q=%f pt = %f, x = %f, Astat= %f",ncount,bin,zval[ncount],Q2val[ncount], ptval[ncount],xval[ncount], Astat[ncount])<<endl;
			ncount ++;
		}
	}
	infile.close();

	return ncount; // total number of bins
}
Example #19
0
//------------------------------
void KVINDRADB_e475s::ReadCalibrations()
//------------------------------
{

   ifstream finput;
   if (!OpenCalibFile("CalibFile", finput)) {
      Error("ReadCalibrations()", "Could not open file %s",
            GetCalibFileName("CalibFile"));
      return;
   }
   
	Info("ReadCalibrations()",
        "Reading calibration parameters...");
	
	TString sline;
   TString stit;
	TString calib_det,calib_gain,calib_file;
	TObjArray *toks=NULL;
	while (finput.good()) {
		sline.ReadLine(finput);
		if (!sline.IsNull()){
			cout << sline << endl;
			toks = sline.Tokenize(" ");
			calib_det = ((TObjString*)(*toks)[0])->GetString();
			calib_gain = ((TObjString*)(*toks)[1])->GetString();
			calib_file = ((TObjString*)(*toks)[2])->GetString();
			stit.Form("%s/%s",gDataSet->GetDataSetDir(),calib_file.Data());
			ifstream fin(stit.Data());
			ReadCalibFile(fin,calib_det,calib_gain);
			fin.close();
   	}
	}
	finput.close();

}
Example #20
0
void read_data(int target_flag=3, int particle_flag=1, int Q2_flag=1, int z_flag =1, int flag_t=0){
	//target_flag = 1->"p", 2->"d2" or 3->"3he"
	//particle_flag = 1->pip,2->pim
	//Q2_flag = 1 ~ 6
	//z_flag  = 1 ~ 8
	//flag_t: //1->Colllins, 2->Sivers,3->Pretzelosity

	TString target = "X";
	if(target_flag==1)
		target ="p";
	else if(target_flag==2)
		target ="d2";
	else if(target_flag==3)
		target ="3he";
	else{
		cerr<<"I don't know this particle flag!"<<endl;
	}
	TString particle = "X";
	if(particle_flag==1)
		particle ="pip";
	else if(particle_flag==2)
		particle ="pim";
	else{
		cerr<<"I don't know this particle flag!"<<endl;
	}
	TString filename;
	filename.Form("./result/%s_%s_%d_%d.dat",target.Data(),particle.Data(),z_flag,Q2_flag);
	ifstream infile(filename);

	gStyle->SetOptStat(0);
	int count1,count2;
	double Q2[5000],x[5000],z[5000],pt[5000],y[5000],Astat[5000],N[5000],coverage[5000],coef[3][5000];
	double Q2[5000],x[5000];
	double temp;
	int pt_flag = -1;
	int ncount=0;

	infile >> count1;
	int pt_temp,x_temp;
	while(infile >> pt_flag >> count2){
		for (int j1=0;j1<count2;j1++){
			infile >> pt_temp >> x_temp >> z[ncount] >> Q2[ncount] >> pt[ncount] >> x[ncount] >> y[ncount] >> Astat[ncount] >> N[ncount]>>
				coverage[ncount] >> coef[0][ncount] >> coef[1][ncount] >> coef[2][ncount];

			if(pt_temp==pt_flag && x_temp== j1){

				Astat[ncount] *= coef[2-flag_t][ncount]; //coef[0]->Sivers,coef[1]->Collins, coef[2]->Pretzelosity

				//Only use the data points with err<5%
				if (Astat[ncount]>0.&&Astat[ncount]<0.05){
					cerr<<Form("---z=%d, Q=%d pt = %f, x = %f, Asys= %f",z_flag,Q2_flag, pt[ncount],x[ncount], Astat[ncount])<<endl;
					ncount ++;
				}
			}
		}
	}

	infile.close();
}
Example #21
0
TString THSHisto::GetStrBin(Float_t ev1,Float_t ev2){
  //Function that finds the bin number and converts it to a string
  Int_t evBin=0;
  if(fHisbins)evBin=fHisbins->FindBin(ev1,ev2); //find bin
  TString sBin;
  sBin.Form("_Bin%d",evBin); //make label
  return sBin;
}
Example #22
0
File: fft.C Project: svn2github/Go4
///////////////////////////////////////////////////////////////////
//////// Go4 GUI example script fft.C
//          J.Adamczewski, gsi, 30 May 2012
// NOTE: to be run in Go4 GUI local command line only!
//       NEVER call this script in remote analysis process!!!
/////// Functionality:
// perfroms fft on histogram of name1 using the option as explained in root TVirtualFFT:FFT
/////// Usage:
// The draw flag switches if the results are displayed each time this macro is called
// if display is switched off, the result histogram is just updated in browser and existing displays
///////
Bool_t fft(const char* name1, Option_t*  opt = "R2C M", Bool_t draw=kTRUE)
{
   if(TGo4AbstractInterface::Instance()==0 || go4!=TGo4AbstractInterface::Instance()) {
      std::cout <<"FATAL: Go4 gui macro executed outside Go4 GUI!! returning." << std::endl;
      return kFALSE;
   }
   TString newname;
   TString fullname1 = go4->FindItem(name1);
   TObject* ob1 = go4->GetObject(fullname1,1000); // 1000=timeout to get object from analysis in ms

   if ((ob1==0) || !ob1->InheritsFrom("TH1")) {
     std::cout <<"fft could not get histogram "<<fullname1 << std::endl;
     return kFALSE;
   }

   if(ob1->InheritsFrom("TH2") || ob1->InheritsFrom("TH3")){  // 2d
      std::cout <<"fft does not support 2d/3d histogram "<<fullname1 << std::endl;
      return kFALSE;
   }

   TH1* his1=(TH1*)ob1;
   TString n1=his1->GetName();
   TString t1=his1->GetTitle();
   newname.Form("_fft_%s",opt);
   TString finalname = n1+newname;
   TString finaltitle = t1+newname;


   // do fft here:
   Int_t N = his1->GetNbinsX();
   TH1D* result = new TH1D(finalname, finaltitle,N,0,N);
   result->SetName(finalname);
   result->SetTitle(finaltitle);
   result->Reset("");
   Double_t *in = new Double_t[N];
   // since we do not know type of input histo, we copy contents to Double array:
   for(Int_t ix=0; ix<N;++ix)
   {
      in[ix]=his1->GetBinContent(ix+1);
   }
   TVirtualFFT *thefft = TVirtualFFT::FFT(1, &N, opt);
   thefft->SetPoints(in);
   thefft->Transform();
   Double_t re, im;
   for (Int_t i=0; i<N; i++) {
      thefft->GetPointComplex(i, re, im);
      result->SetBinContent(i+1,TMath::Sqrt(re*re + im*im));
   }
   result->SetDirectory(0);

   TString rname = go4->SaveToMemory("FFT", result, kTRUE);
   std::cout<< "Saved result histogram to " << rname.Data() <<std::endl;
   if(draw){
      ViewPanelHandle vpanel = go4->StartViewPanel();
      go4->DrawItem(rname, vpanel);
   }
   return kTRUE;
}
Example #23
0
Int_t IRODS::put(const Char_t* source, const Char_t* target)
{
   // put a new file into IRODS space.

   TString args;
   args.Form("%s %s", source, target);
   buildCommand("iput", args.Data(), "-N0");
   return execCommand();
}
Example #24
0
Int_t IRODS::get(const Char_t* source, const Char_t* target)
{
   // copy a file from IRODS space.

   TString args;
   args.Form("-P %s %s", source, target);
   buildCommand("iget", args.Data());
   return execCommand();
}
Example #25
0
  //____________________________________________________________________
  void Run(const char* newName,        const char* oldName,
	   const char* newTitle="New", const char* oldTitle="Old")
  {
    TFile* newFile = TFile::Open(newName,"READ");
    TFile* oldFile = TFile::Open(oldName,"READ");
    if (!newFile || !oldFile) return;

    TH1* newCent = GetH1(newFile, "realCent");
    TH1* oldCent = GetH1(oldFile, "realCent");
    if (!newCent || !oldCent) return;

    TString  t; t.Form("#it{R}=#frac{%s}{%s}", newTitle, oldTitle);
    TCanvas* c     = new TCanvas("c", t, 1200, 800);
    c->SetTopMargin(0.01);
    c->SetRightMargin(0.20);
    fLegend = new TLegend(1-c->GetRightMargin(),
			  c->GetBottomMargin(),
			  1, 1-c->GetTopMargin(),
			  t);
    fLegend->SetFillStyle(0);
    fLegend->SetBorderSize(0);
    THStack* stack = new THStack("ratios","");
			       
    fMin = +1e6;
    fMax = -1e6;
    TH1* one = 0;
    for (Int_t i = newCent->GetNbinsX(); i--;) {
      Double_t c1 = newCent->GetXaxis()->GetBinLowEdge(i+1);
      Double_t c2 = newCent->GetXaxis()->GetBinUpEdge(i+1);
      Info("", "c1=%f c2=%f", c1, c2);
      TH1*     r  = One(newFile, oldFile, c1, c2);    
      if (!r) continue;
      if (!one) {
	one = static_cast<TH1*>(r->Clone("one"));
	one->SetDirectory(0);
	one->Reset();
	for (Int_t j = 1; j <= one->GetNbinsX(); j++) {
	  one->SetBinContent(j,1);
	  one->SetBinError  (j,0);
	}
      }
      // r->Add(one, i-1);
      // r->Scale(TMath::Power(10,i));
      stack->Add(r);
    }
    stack->Draw("nostack");
    stack->SetMinimum(0.95*fMin);
    stack->SetMaximum(1.05*fMax);
    stack->GetHistogram()->SetXTitle("#eta");
    stack->GetHistogram()->SetYTitle("#it{R}");
    fLegend->Draw();
    c->Modified();
    c->Update();
    c->cd();
    c->SaveAs(Form("%sover%s.png", newTitle, oldTitle));
  }  
Example #26
0
Bool_t KVINDRAPulserDataTree::OpenGeneData(Int_t run, ifstream &f)
{
	// Open gene data for one run
	// We look for file 'runXXXX.gene' in the directory given by
	// environment variable KVINDRAPulserDataTree.GeneDetDir.

	TString fname; fname.Form("/run%d.gene", run);
	fname.Prepend(gDataSet->GetDataSetEnv("KVINDRAPulserDataTree.GeneDetDir",""));
	return gDataSet->OpenDataSetFile(fname.Data(),f);
}
Example #27
0
void RawFile::createTree(){
	TString path;
	path.Form("%s/ss%i",RDKANAL,entry.nseries);
	FileStat_t stats;
	if(gSystem->GetPathInfo(path,stats)){
		gSystem->mkdir(path,true);
	}
	TString temp;
	temp.Form("%s/%c%ir%i.rdat",path.Data(),type,entry.nseries,entry.nrun);
	file=new TFile(temp,"recreate");
	temp.Form("rawData-%c%ir%i",type,entry.nseries,entry.nrun);
	rawData=new TTree(temp,"RDK raw data");
	Long64_t maxSize=Long64_t(1)<<54-Long64_t(1)<<16;
	if(TTree::GetMaxTreeSize()<maxSize){
		TTree::SetMaxTreeSize(maxSize);
	}
	temp.Form("ch[%i][%i]/S",NCHANNELS,NPOINTS);
	rawData->Branch("rdata",&rdata,temp);
	rawData->Branch("entry",&entry,"time/D:nevent/I:nrun:nseries");
}
Example #28
0
KVFunctionCal* KVVAMOSDetector::GetECalibrator() const
{
   // Returns the calibrator for the conversion channel->MeV of the energy
   // signal.
   // The method assumes that the calibrator is an instance of the class
   // KVFunctionCal.

   TString calname;
   calname.Form("channel->MeV %s", GetEBaseName());
   return (KVFunctionCal*)GetCalibrator(calname.Data());
}
Example #29
0
const Char_t *KVIDCsI::GetArrayName()
{
   // Name of telescope given in the form CSI_R_L_Ring-numberTelescope-number
   //where ring and telescope numbers are those of the smallest (in angular terms)
   //detector of the telescope (if both are the same size, either one will do).
   // The detectors are signified by their TYPE names i.e. KVDetector::GetType

   //in order to access angular dimensions of detectors, we need their KVTelescopes
   KVINDRATelescope *de_det = dynamic_cast<KVINDRADetector*>(GetDetector(1))->GetTelescope();
   UInt_t ring, mod;
   ring = de_det->GetRingNumber();
   mod = de_det->GetNumber();
   TString dummy;
   dummy.Form("%s_R_L", GetDetector(1)->GetType());
   SetType(dummy.Data());
   dummy.Form("%s_%02d%02d", GetType(), ring, mod);
   SetName(dummy.Data());

   return fName.Data();
}
Example #30
0
void THSHisto::LoadHistograms(){
  //Loads histograms for each defined bin and cut
  //The histograms required should be given in the users HistogramList Function
  //Note HistogramList should give the histograms to fOutput, which will take
  //responsibility for deleting them as SetOwner() is called in its contructor
  //GetKinematic bins
  Int_t Nbins=0;
  if(fHisbins){
    if(TString(fHisbins->ClassName()).Contains("1"))Nbins=(fHisbins->GetNbinsX()+2);//+2 for overflow and underflow;
    else if(TString(fHisbins->ClassName()).Contains("2"))Nbins=(fHisbins->GetNbinsX()+2)*(fHisbins->GetNbinsY()+2);//+2 for overflow and underflow;
    else if(TString(fHisbins->ClassName()).Contains("3"))Nbins=(fHisbins->GetNbinsX()+2)*(fHisbins->GetNbinsY()+2)*(fHisbins->GetNbinsZ()+2);//+2 for overflow and underflow;
  }
  
  Int_t ncut=0;
  if(!Nbins){  //Only 1 bin
    //iterate over cuts
    for(vector< TString >::iterator nextcut=fVecCuts.begin();nextcut!=fVecCuts.end();++nextcut){
      fVecBinNames.resize(1);
      fVecBinNames[0]=TString("_All");
      //Call the users Histogram list for each declared cut
      HistogramList(fVecCuts[ncut++] + fVecBinNames[0]); //cut + bin gets added to histogram name 
      fVecHistCut.push_back(fHistNameMap); //enter the histograms for this cut into a vector element
      fHistNameMap.clear(); //clear the previous cut histograms
    }
    fVecHistBin.push_back(fVecHistCut);//Add all the histograms for this kin bin
    fVecHistCut.clear(); //clear the previous bin histograms  
  }
  //keep a list of events in each bin
  fBinEntryLists=new TObjArray(Nbins);
  fBinEntryLists->SetName("HSKinBinsList");
  fBinEntryLists->SetOwner(kTRUE);
  //ifmultiple kinematic bins defined make a histogram for each bin
  TString sBin;
  for(Int_t ib=0;ib<Nbins;ib++){
    sBin.Form("_Bin%d",ib); //make bin label
    //Load all the cuts for this bin
    ncut=0;
    //iterate over cuts
    for(vector< TString >::iterator nextcut=fVecCuts.begin();nextcut!=fVecCuts.end();++nextcut){
      //Call the users Histogram list for each declared cut
      HistogramList(fVecCuts[ncut++]+fVecBinNames[ib]); //construct all histograms for this bin,
      fVecHistCut.push_back(fHistNameMap); //enter the histograms for this cut into a vector element
      fHistNameMap.clear(); //clear the previous cut histograms

     }
    fVecHistBin.push_back(fVecHistCut);//Add all the histograms for this kin bin
    fVecHistCut.clear(); //clear the previous bin histograms
    //Add an entry list for each kinematic bin
    TEntryList* el=new TEntryList(TString("HSBin_")+fVecBinNames[ib],TString("HSBin_")+fVecBinNames[ib]);
    fBinEntryLists->Add(el);
    if(dynamic_cast<TSelector*>(this)) dynamic_cast<TSelector*>(this)->GetOutputList()->Add(el);
  }
}