示例#1
0
static int which_partner (char *call, hadr_t *ha)
//*************************************************************************
//
// decide which partner should be used for fwd from HA entry
// call param just for -C fwd opt. checking, may be NULL
//
//*************************************************************************
{
  time_t upd = 0;
  time_t oldest = ad_time() - m.autofwdtime * DAY;
  int num = -1, i;
  int hops = 1000;
  time_t del = ad_time();
  char oldcall[CALLEN+1];
  fwdpara_t *ff;

  if (call) strcpy(oldcall, b->logincall);
  for (i = 0; i < ADJNUM; i++)
  {
    if (   ha->adjacent[i][0] && isforwardpartner (ha->adjacent[i]) != NOTFOUND
        && ha->rel_mails[i] > 2 //at least two mails
        && ha->lastupdate[i] > oldest  //new enough
        && ha->delay[i] < del     //path with minimal delay, 5min tolerance
        && (ha->hops[i] < hops   //and minimal number of hops
            || (ha->hops[i] == hops && ha->lastupdate[i] > upd)))
                                      //or newer entry for same hop count
    {
      if (call)
      {
        strcpy(b->logincall, ha->adjacent[i]);
        ff = fpara();
        if (ff->options & o_c)
        {
#ifdef _LCF
          if (! fwdcallok(call, ff->fwdcallformat)
              || (*b->herkunft && ! fwdcallok(b->herkunft, ff->fwdcallformat)))
#else
          if (! mbcallok(call)
              || (*b->herkunft && ! mbcallok(b->herkunft)))
#endif
            continue;
        }
      }
      upd = ha->lastupdate[i];
      del = ha->delay[i] + 300; //5min tolerance
      hops = ha->hops[i];
      num = i;
    }
  }
  if (call) strcpy(b->logincall, oldcall);
  return num;
}
示例#2
0
int fitfunc(int *energy, int *gopt, int append, char* addname){
  if(setlogy==0){
    //double labelx[6]={380,800,1200,1700,2400,5000}, labely[6]={80,45,25,21,25,15}; //Position
  }else{
    //double labelx[6]={300,750,1400,1800,2700,5000}, labely[6]={130,75,50,30,25,5}; //Position
  }

  //void fitfunc(int energy[5], int gopt[5]){
  for(int i=0; i<6; i++){
    cout<<energy[i]<<" "<<gopt[i]<<endl;
  }
  
  if(histname=="p2p"){
    char* dirsim = "../output/rec";
  }else if(histname=="p3p"){
    //char* dirsim = "../output/rec_p3p";
    char* dirsim = "../output/rec";
    //char* direxp = "../expout/Feb12/h_SpectrumMINOS_wAdBk.root";
    //char* outname = Form("../output/fit/%i%i%i%i%i_%s%i",gopt[0],gopt[1],gopt[2],gopt[3],gopt[4],histname,energy[4]); // .pdf .png .C .root will be created
  }else{// if(histname=="h23"){
    char* dirsim = "../output/rec";
    //char* direxp = "../expout/Feb12/h_SpectrumMINOS_wAdBk.root";
    //char* outname = Form("../output/fit/%i%i%i%i%i_%s%i",gopt[0],gopt[1],gopt[2],gopt[3],gopt[4],histname,energy[4]); // .pdf .png .C .root will be created
  }

  char* outname = Form("../output/fit/%s_%i_%i_%i_%i_%i_%i%s",histname, energy[0],energy[1],energy[2],energy[3],energy[4],energy[5],addname); // .pdf .png .C .root will be created


  ofstream fpara(Form("%s_fitresult.txt",outname));
  if(append == 1){
    ofstream fitlist(Form("../output/fit/fitlist_%s%s.csv",histname,addname),ios_base::app);
  }else{
    ofstream fitlist(Form("../output/fit/fitlist_%s%s.csv",histname,addname));    
  fitlist<<"E0, E1, E2, E3, E4, E5, CS0, CS1, CS2, CS3, CS4, CS5, ER0, ER1, ER2, ER3, ER4, ER5, Chi-sq"<<endl;
  }
  
  gStyle->SetOptStat(kFALSE);
  
  gROOT->ProcessLine( ".L fit78Ni.h" );
  gStyle->SetOptStat(kFALSE);
  gStyle->SetPadGridX(false);
  gStyle->SetPadGridY(false);
  //gStyle->SetOptLogy(1);

  char temp[300];
  int minBin = 0;
  //int maxBin = 5500;
  int maxBin = 6000;
  int binning = 100;
  int numBin = (maxBin-minBin)/binning;
  
  //Id starts with one!!!
  int daliIDMin = 1;
  int daliIDMax = 186;

  //****************************************************************************
  // The simulated peaks
  TFile *sim[6];
  for(int i=0; i<6; i++){
    if(energy[i]>0){
      sim[i] = new TFile(Form("%s/%ikeV.root",dirsim,energy[i]));
    }else{
      sim[i] = new TFile(Form("%s/%ikeV.root",dirsim,2620));//dummy
      gopt[i] = 0;
    }
  }

  //The experimental data:
  TFile *exp[1];
  //exp[0] = new TFile(Form("%s/MINOStest.root",direxp));
  exp[0] = new TFile(direxp);

  TCanvas *fCanvas=new TCanvas("Canvas","Response function",700,700);
  fCanvas->SetBorderSize(0);
  fCanvas->SetBorderMode(0);
  fCanvas->SetFrameBorderMode(0);
  fCanvas->SetFrameFillColor(0);
  fCanvas->SetBottomMargin(0.15);
  fCanvas->SetLeftMargin(0.15);
  fCanvas->cd();

  TFile *fout = new TFile(Form("%s.root",outname),"RECREATE");
  fout->cd();

  // Main
  TPad *c_m = new TPad("c_m", "c_m",0.0,0.0,1.0,1.0);
  c_m->Draw();
  c_m->cd();
  c_m->SetFillColor(0);
  //c_m->SetFillStyle(0);
  c_m->SetBorderSize(0);
  c_m->SetRightMargin(0.05);
  c_m->SetTopMargin(0.03);
  c_m->SetBottomMargin(0.15);
  c_m->SetLeftMargin(0.15);
  if(setlogy>0) c_m->SetLogy();
  fCanvas->cd();

  //****************************************************************************
  //The simulated spectra:
  TH1F *hsim[6];
  for(int i=0;i<6;i++) {
    sprintf(temp,"hsim[%i]",i);  
    hsim[i] = new TH1F(temp,temp,numBin,minBin,maxBin);
    hsim[i] = (TH1F*)sim[i]->Get("h_doppler_addback[0]");
  }
  /*
  hsim[0] = (TH1F*)sim[0]->Get("h_doppler_addback[0]");
  hsim[1] = (TH1F*)sim[1]->Get("h_doppler_addback[0]");
  hsim[2] = (TH1F*)sim[2]->Get("h_doppler_addback[0]");
  hsim[3] = (TH1F*)sim[3]->Get("h_doppler_addback[0]");
  hsim[4] = (TH1F*)sim[4]->Get("h_doppler_addback[0]");
  */

  //The experimental spectra:
  TH1F *hexp[1];
  for(int i=0;i<1;i++) {
    sprintf(temp,"hexp[%i]",i);  
    hexp[i] = new TH1F(temp,temp,numBin,minBin,maxBin);
  }

  //Getting the experimental spectrum
  //78Ni
  hexp[0] = (TH1F*)exp[0]->Get(histname);
  //hexp[0] = (TH1F*)exp[0]->Get("h23;1");
  //hexp[0]->Rebin(2);

  
  for(int i=0;i<1;i++) {
    hexp[i]->SetStats(0);
    hexp[i]->SetFillColor(0);
    hexp[i]->SetLineColor(kBlue);
    hexp[i]->SetLineStyle(0);
    
    //hexp[i]->GetXaxis()->SetRangeUser(0,maxBin);
    hexp[i]->GetXaxis()->SetRangeUser(minBin,maxBin);
    //hexp[i]->GetXaxis()->SetRangeUser(0,6000);
    if(setlogy==0){
      hexp[i]->GetYaxis()->SetRangeUser(0,yrangemax);
    }else {
      hexp[i]->GetYaxis()->SetRangeUser(0.5,yrangemax);
    }

    hexp[i]->GetXaxis()->SetNdivisions(305);
    hexp[i]->GetYaxis()->SetNdivisions(305);
  
    hexp[i]->GetYaxis()->SetTitle(Form("Counts / %i keV",binning));
     hexp[i]->GetXaxis()->SetTitle("Energy (keV)");
    
    hexp[i]->GetXaxis()->SetTitleOffset(0.9);  
    hexp[i]->GetYaxis()->SetTitleOffset(0.9);
    
    hexp[i]->GetXaxis()->SetTitleFont(132);
    hexp[i]->GetYaxis()->SetTitleFont(132);
    
    /*
    hexp[i]->GetXaxis()->SetTitleSize(0.08);
    hexp[i]->GetYaxis()->SetTitleSize(0.08);
    
    hexp[i]->GetXaxis()->SetLabelSize(0.08);
    hexp[i]->GetYaxis()->SetLabelSize(0.08);
    */
    hexp[i]->GetXaxis()->SetTitleSize(0.05);
    hexp[i]->GetYaxis()->SetTitleSize(0.05);
    
    hexp[i]->GetXaxis()->SetLabelSize(0.05);
    hexp[i]->GetYaxis()->SetLabelSize(0.05);

    //How to get error bar for each bin
    hexp[i]->SetDefaultSumw2(kTRUE);
    

    hexp[i]->SetTitle("");
  }   
   
  //*****************************************************************************
  peak1g = new TGraph(hsim[0]);
  peak2g = new TGraph(hsim[1]);
  peak3g = new TGraph(hsim[2]);
  peak4g = new TGraph(hsim[3]);
  peak5g = new TGraph(hsim[4]);
  peak6g = new TGraph(hsim[5]);
  /*TGraph *peak1g = new TGraph(hsim[0]);
  TGraph *peak2g = new TGraph(hsim[1]);
  TGraph *peak3g = new TGraph(hsim[2]);
  TGraph *peak4g = new TGraph(hsim[3]);
  TGraph *peak5g = new TGraph(hsim[4]);
  */
  //******************Function Definition****************************************
  //*****************************************************************************
  const Double_t fitmin=300.;
  const Double_t fitmax=(Double_t)maxBin;//4000.;
   
  c_m->cd();
  TF1 *whole = new TF1( "whole", ex_respf,fitmin,fitmax,10);
  whole->SetParameters(0.0001,0.01,0.00,0.0001,0.001,0.001,3.,-1e-03,3,-1.e-3);
  //whole->SetParameters(0.0001,0.0001,0.0001, 5.9,-0.00080 );

  for(int i=0; i<6; i++){
    if(gopt[i]==1){
      whole->SetParLimits(i,0.0,parlimit[i]);
    }else{
      whole->FixParameter(i,0.0);
    }
  }
  whole->SetParLimits(6,0,10);
  whole->SetParLimits(7,-1e-02,0.);
  whole->SetParLimits(8,0,5);
  whole->SetParLimits(9,-1e-02,-1e-5);
  //whole->FixParameter(8,1.426);
  //whole->FixParameter(9,-8.1e-5);
  whole->SetLineColor(1);
  whole->SetLineWidth(2);
  whole->SetNpx(200); 
  hexp[0]->Fit(whole,"R LL");
  //hexp[0]->Fit(whole,"");
  //cout<<"test"<<endl;
  //hexp[0]->Draw("");

  //hexp[0]->GetXaxis()->SetRangeUser(0,5000);


  //fCanvas->Print(Form("%s.png",outname));

  fpara<<"Chisquare\t"<< whole->GetChisquare()<<endl;
  fpara<<"para\tvalue\terror\tfilename"<<endl;
  for(int para=0;para<10;para++){
    fpara<<para<<"\t"<<whole->GetParameter(para)<<"\t"<<whole->GetParError(para);
    if(para<6) {
      string strenergy =sim[para]->GetName();
      int itr = strenergy.find_last_of("/");
      strenergy.erase(0,itr+1);
      fpara<<"\t"<<strenergy;
    }
    fpara<<endl;
  }
  
  // fitlist<<"E0, E1, E2, E3, E4, CS0, CS1, CS2, CS3, CS4, ER0, ER1, ER2, ER3, ER4, Chi-sq"<<endl;
  for(int i=0; i<6; i++) gopt[i]==1? fitlist<<energy[i]<<", ": fitlist<<"0, ";
  for(int i=0; i<6; i++) gopt[i]==1? fitlist<<genevts*whole->GetParameter(i)*CSincl/tot78Ni<<", ": fitlist<<"0, ";
  for(int i=0; i<6; i++){gopt[i]==1?
      fitlist<<sqrt(pow(whole->GetParError(i)*CSincl,2.) //Error from fitting
		    //+whole->GetParameter(i)*pow(CSincl,2) //Statistical error for the events (included?
		    //+pow(whole->GetParameter(i)*CSinclerr,2) // Inclusive cross section error
		    )*genevts/tot78Ni<<", " 
      :fitlist<<"0, ";
      }
  fitlist<<whole->GetChisquare()<<endl;

  //RT end


  TF1 *peak1f= new TF1( "peak1f", resp1,fitmin,fitmax,1);
  peak1f->SetParameter(0,whole->GetParameter(0) );
  peak1f->SetLineColor(2);
  peak1f->SetLineWidth(2);
  peak1f->SetLineStyle(9);
  peak1f->Draw("same");

  TF1 *peak2f= new TF1( "peak2f", resp2,fitmin,fitmax,1);
  peak2f->SetParameter(0,whole->GetParameter(1) );
  peak2f->SetLineColor(2);
  peak2f->SetLineWidth(2);
  peak2f->SetLineStyle(9);
  peak2f->Draw("same");

  //
  TF1 *peak3f= new TF1( "peak3f", resp3,fitmin,fitmax,1);
  peak3f->SetParameter(0,whole->GetParameter(2) );
  peak3f->SetLineColor(2);
  peak3f->SetLineWidth(2);
  peak3f->SetLineStyle(9);
  peak3f->Draw("same");
  
  TF1 *peak4f= new TF1( "peak4f", resp4,fitmin,fitmax,1);
  peak4f->SetParameter(0,whole->GetParameter(3) );
  peak4f->SetLineColor(2);
  peak4f->SetLineWidth(2);
  peak4f->SetLineStyle(9);
  peak4f->Draw("same");
  
  TF1 *peak5f= new TF1( "peak5f", resp5,fitmin,fitmax,1);
  peak5f->SetParameter(0,whole->GetParameter(4) );
  peak5f->SetLineColor(2);
  peak5f->SetLineWidth(2);
  peak5f->SetLineStyle(9);
  peak5f->Draw("same");

  TF1 *peak6f= new TF1( "peak6f", resp6,fitmin,fitmax,1);
  peak6f->SetParameter(0,whole->GetParameter(5) );
  peak6f->SetLineColor(2);
  peak6f->SetLineWidth(2);
  peak6f->SetLineStyle(9);
  peak6f->Draw("same");


  TF1 *expon= new TF1( "expon",expf ,fitmin,fitmax,4);
  //expon->SetParameters(whole->GetParameter(5),whole->GetParameter(6),whole->GetParameter(7),whole->GetParameter(8));
  expon->SetParameters(whole->GetParameter(6),whole->GetParameter(7),whole->GetParameter(8),whole->GetParameter(9));
  expon->SetLineColor(4);
  expon->SetLineWidth(2);
  expon->SetLineStyle(7);
  expon->Draw("same");

  //hexp[0]->Draw("same");
  hexp[0]->Draw("EL same");
  
  /*TLatex *tex = new TLatex(2000,setlogy?130:60,Form("^{78}Ni (%s)",histname));
  tex->SetTextFont(132);
  tex->SetTextSize(0.07);
  tex->SetLineWidth(2);
  tex->Draw();
  */
  /*TLatex *tex = new TLatex(2700,setlogy?80:55,Form("Incl: %2.1f mbarn for %d cnts", CSincl, (int)tot78Ni));
  tex->SetTextFont(132);
  tex->SetTextSize(0.04);
  tex->SetLineWidth(2);
  tex->Draw();
  */
  for(int i =0; i<6; i++){
  if(gopt[i]==1){
    TLatex *tex = new TLatex(labelx[i],labely[i],
			     //Form("#splitline{%d keV }{%2.2f mbarn (%3.1f cnts)}",energy[i], genevts*whole->GetParameter(i)*CSincl/tot78Ni, genevts*whole->GetParameter(i)));
			     Form("%d keV",energy[i]));
    tex->SetTextFont(132);
    tex->SetTextSize(0.05);
    tex->SetLineWidth(2);
    tex->Draw();
    }
  }
    
  fCanvas->Print(Form("%s.C",outname));
  fCanvas->Print(Form("%s.png",outname));
  fCanvas->Print(Form("%s.pdf",outname));
  
  fCanvas->Write();
  hexp[0]->Write();
  fout->Write();
  fout->Close();

}