当前位置: 首页>>代码示例>>C++>>正文


C++ TNtuple::SetBranchAddress方法代码示例

本文整理汇总了C++中TNtuple::SetBranchAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ TNtuple::SetBranchAddress方法的具体用法?C++ TNtuple::SetBranchAddress怎么用?C++ TNtuple::SetBranchAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TNtuple的用法示例。


在下文中一共展示了TNtuple::SetBranchAddress方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: PixelMergeSmallFiles

void PixelMergeSmallFiles(){

    TFile * oFilebDist = new TFile("bDistr2.root", "RECREATE");
    TNtuple* SimEventsGlobal = new TNtuple("SimEventGlob", "SimEventGlob", "EvN:b");
    
    TFile * oFileLinks = new TFile("Links2.root", "RECREATE");
    TNtuple* LinksGlobal = new TNtuple("LinksGlob", "LinksGlob", "EvN:fedid:linkn:nHits");
    
    char FileInNumber[5];
    string FileInPath = "/net/pstore01/d00/scratch/icali/CMSSW_2_1_11/PixelAnalysis/PixelNTuple_hydjet_x2_mb_oldPL_d20081106/";
    string FileInNameRoot= "hydjet_x2_mb_oldPL_d20081106_r0";
    
    Float_t j = 0;    
    for(int FileN = 901; FileN <1801; ++FileN){
    
         sprintf(FileInNumber, "%.5d", FileN);
         string FileInName = FileInPath+FileInNameRoot+FileInNumber+".root";
         TFile *iFile = new TFile((const char*)FileInName.c_str());
         if(!iFile->IsZombie()){
           PixelAnalyzer->cd();
    
           TNtuple *FEDLinks = (TNtuple*)iFile->FindObjectAny("Links");
           TNtuple *SimEvents = (TNtuple*)iFile->FindObjectAny("SimEvent");
    
           Float_t FEDEvN, fedid, linkn, nHits;
           FEDLinks->SetBranchAddress("EventN",&FEDEvN);
           FEDLinks->SetBranchAddress("fedid",&fedid);
           FEDLinks->SetBranchAddress("linkn",&linkn);
           FEDLinks->SetBranchAddress("nHits",&nHits);
           Long64_t FEDLinkLenght =FEDLinks->GetEntries(); 
    
           Float_t SimEvN, b;
           SimEvents->SetBranchAddress("EventN",&SimEvN);
           SimEvents->SetBranchAddress("mult",&b);
           Long64_t SimEventLenght =SimEvents->GetEntries(); 
           
           Long64_t i;
           for(i=0; i < SimEventLenght; ++i){
             SimEvents->GetEntry(i);
             SimEventsGlobal->Fill(i, b);
           } 
           
          Float_t OldEvN= -1;        
          for(i=0; i < FEDLinkLenght; ++i){
             FEDLinks->GetEntry(i);
             if(OldEvN != FEDEvN){
                OldEvN= FEDEvN;
                ++j;
             }
             LinksGlobal->Fill(j, fedid, linkn, nHits);
             
          }
      }
    }
    oFilebDist->Write();
    oFileLinks->Write();
}
开发者ID:kandrosov,项目名称:psi46expert_bare,代码行数:57,代码来源:PixelMergeSmallFiles.C

示例2: ROCOccupancy

void ROCOccupancy(Int_t StartRun, Int_t EndRun){

    using namespace std;
       
   
   //string FileRoot = "/home/l_tester/log/bt05r";
   string FileInName = "ProcessedData.root";
   char RunNumber[6];
    
    
    Float_t j = 0;    
    for(int RunN = StartRun; RunN <=EndRun; ++RunN){
      string FileRoot = "/d00/icali/PixelHwStudies/PSIStuff/log/bt05r";        
      sprintf(RunNumber, "%.6d", RunN);
      FileRoot = FileRoot + RunNumber + "/";
      FileInName = FileRoot + FileInName;
        
      TFile *iFile = new TFile((const char*)FileInName.c_str());
      if(!iFile->IsZombie()){
        TNtuple *Digis = (TNtuple*)iFile->FindObjectAny("events");
        Int_t EvN, roc, ROCHits, MeanPh, NCols;
        Digis->SetBranchAddress("ROCHits", &ROCHits);
        Digis->SetBranchAddress("MeanPh", &MeanPh);
        Digis->SetBranchAddress("roc", &roc);
        Digis->SetBranchAddress("NCols", &NCols);
        Digis->SetBranchAddress("EvN", &EvN);
        Int_t iNTlenght = Digis->GetEntries();
        
        Int_t MaxROCHits =0;
        for(int i =0 ; i < iNTlenght; ++i){
          Digis->GetEntry(i);
          if(ROCHits > MaxROCHits) MaxROCHits = ROCHits;
        }
        cout << "Run: " << RunN << " MaxROCHits: " << MaxROCHits << endl;
      }
   }
}
开发者ID:chwissing,项目名称:psi46expert,代码行数:37,代码来源:ROCOccupancy.C

示例3: fitBjetJES

void fitBjetJES(int ppPbPb=1, int cbinlo=12, int cbinhi=40){

  if(!ppPbPb){
    cbinlo=0;
    cbinhi=40;
  }

  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);

  TFile *fL;
  
  if(!ppPbPb)fL=new TFile("histos/ppMC_hiReco_jetTrig_highPurity_JEC.root");
  else     fL=new TFile("histos/PbPbQCDMC_pt30by3_ipHICalibCentWeight.root");

  // these are dummy files for pp
  TFile *fB=new TFile("histos/PbPbBMC_pt30by3_ipHICalibCentWeight.root");
  TFile *fC=new TFile("histos/PbPbCMC_pt30by3_ipHICalibCentWeight.root");


  TNtuple *tL = (TNtuple*) fL->Get("nt");
  TNtuple *tB = (TNtuple*) fB->Get("nt");
  TNtuple *tC = (TNtuple*) fC->Get("nt");
  
  float jtptL, refptL, jtetaL, weightL, refparton_flavorForBL, binL;

  tL->SetBranchAddress("jtpt",&jtptL);
  tL->SetBranchAddress("jteta",&jtetaL);
  tL->SetBranchAddress("refpt",&refptL);
  tL->SetBranchAddress("weight",&weightL);
  if(ppPbPb)tL->SetBranchAddress("bin",&binL);
  tL->SetBranchAddress("refparton_flavorForB",&refparton_flavorForBL);

  float jtptB, refptB, jtetaB, weightB, refparton_flavorForBB, binB;

  tB->SetBranchAddress("jtpt",&jtptB);
  tB->SetBranchAddress("jteta",&jtetaB);
  tB->SetBranchAddress("refpt",&refptB);
  tB->SetBranchAddress("weight",&weightB);
  if(ppPbPb)tB->SetBranchAddress("bin",&binB);
  tB->SetBranchAddress("refparton_flavorForB",&refparton_flavorForBB);

  float jtptC, refptC, jtetaC, weightC, refparton_flavorForBC, binC;

  tC->SetBranchAddress("jtpt",&jtptC);
  tC->SetBranchAddress("jteta",&jtetaC);
  tC->SetBranchAddress("refpt",&refptC);
  tC->SetBranchAddress("weight",&weightC);
  if(ppPbPb)tC->SetBranchAddress("bin",&binC);
  tC->SetBranchAddress("refparton_flavorForB",&refparton_flavorForBC);

  TProfile  *hL = new TProfile("hL","hL",250,50,300,0,10);
  TProfile  *hB = new TProfile("hB","hB",250,50,300,0,10);
  TProfile  *hC = new TProfile("hC","hC",250,50,300,0,10);
  hL->Sumw2(),hB->Sumw2(),hC->Sumw2();


  for(int i=0;i<tL->GetEntries();i++){
    tL->GetEntry(i);
    if(!ppPbPb) binL=39;

    if(fabs(jtetaL)<2 && binL>=cbinlo && binL<cbinhi)
      hL->Fill(refptL,jtptL/refptL,weightL); 


    if(!ppPbPb){
      if(fabs(jtetaL)<2 && binL>=cbinlo && binL<cbinhi && abs(refparton_flavorForBL)==5)
	hB->Fill(refptL,jtptL/refptL,weightL);
      
      if(fabs(jtetaL)<2 && binL>=cbinlo && binL<cbinhi && abs(refparton_flavorForBL)==4)
	hC->Fill(refptL,jtptL/refptL,weightL);      
    }
  }

  if(ppPbPb){
    for(int i=0;i<tB->GetEntries();i++){
      tB->GetEntry(i);
      if(fabs(jtetaB)<2 && binB>=cbinlo && binB<cbinhi && abs(refparton_flavorForBB)==5)
	hB->Fill(refptB,jtptB/refptB,weightB);
    }
    for(int i=0;i<tC->GetEntries();i++){
      tC->GetEntry(i);
      if(fabs(jtetaC)<2 && binC>=cbinlo && binC<cbinhi && abs(refparton_flavorForBC)==4)
	hC->Fill(refptC,jtptC/refptC,weightC);
    }
  }

  
 
  hL->SetMinimum(0.);
  
  hL->SetLineColor(kBlue);
  hB->SetLineColor(kRed);
  hC->SetLineColor(kGreen);

  hL->SetMarkerColor(kBlue);
  hB->SetMarkerColor(kRed);
  hC->SetMarkerColor(kGreen);
  
  //hL->SetMarkerStyle(4);
//.........这里部分代码省略.........
开发者ID:kurtejung,项目名称:bJetTools,代码行数:101,代码来源:fitBjetJES.C

示例4: main

int main(int argc, char* argv[]){
TApplication* a = new TApplication("a", 0, 0);
 TStyle* style=  DrawTools::setStyle();
 style->cd();

  std::string outputdir = "CalibComparisonPlots/";
  std::string mkdir_command = "mkdir -p " + outputdir;
  system( mkdir_command.c_str() );

  std::string runName0 = "BTF_259_20140502-012847_beam";
  std::string runName1 = "BTF_259_20140502-012847_beam";
  std::string runName2 = "BTF_259_20140502-012847_beam";
  std::string runName3 = "BTF_259_20140502-012847_beam";
  std::string runName4 = "BTF_259_20140502-012847_beam";


  //std::string tag = "default";
  std::string tag = "V03";

  std::string inputDir = "./CeF3Calibration";


  if( argc == 5 ) {
    std::string runName_str0(argv[1]);
    runName0 = runName_str0;
    std::string runName_str1(argv[2]);
    runName1 = runName_str1;
    std::string runName_str2(argv[3]);
    runName2 = runName_str2;
    std::string tag_str(argv[4]);
    tag = tag_str;
  } else if(argc == 7){
       std::string runName_str0(argv[1]);
    runName0 = runName_str0;
    std::string runName_str1(argv[2]);
    runName1 = runName_str1;
    std::string runName_str2(argv[3]);
    runName2 = runName_str2;
    std::string runName_str3(argv[4]);
    runName3 = runName_str3;
    std::string runName_str4(argv[5]);
    runName4 = runName_str4;
    std::string tag_str(argv[6]);
    tag = tag_str;
  } else{
    std::cout<<"Usage:"<<std::endl;
    std::cout<<"./calibrateCef3 BTF_XX BTF_XX BTF_XX tag "<<std::endl;
    exit(12345);
  }




TCanvas* canny = new TCanvas("canny", "",200,200);
 canny->cd();

  ifstream in;

  float x;
  int nlines;
  TNtuple *ntuple = new TNtuple("ntuple","data from .txt file", "x");

  double corr0[4];
  double corr_uncert0[4];
  double corr1[4];
  double corr_uncert1[4];
  double corr2[4];
  double corr_uncert2[4];
  double corr3[4];
  double corr_uncert3[4];
  double corr4[4];
  double corr_uncert4[4];

 
    int const ntot = 10;
    TString openname[ntot] = {
      Form("%s/constants_%s_%s.txt",inputDir.c_str(),runName0.c_str(), tag.c_str() ), Form("%s/constants_uncert_%s_%s.txt", inputDir.c_str(),runName0.c_str(), tag.c_str()),   Form("%s/constants_%s_%s.txt", inputDir.c_str(),runName1.c_str(), tag.c_str()), Form("%s/constants_uncert_%s_%s.txt", inputDir.c_str(),runName1.c_str(), tag.c_str()),   Form("%s/constants_%s_%s.txt",inputDir.c_str(), runName2.c_str(), tag.c_str() ),Form("%s/constants_uncert_%s_%s.txt", inputDir.c_str(), runName2.c_str(), tag.c_str() ),  Form("%s/constants_%s_%s.txt", inputDir.c_str(), runName3.c_str(), tag.c_str() ), Form("%s/constants_uncert_%s_%s.txt", inputDir.c_str(), runName3.c_str(), tag.c_str() ),     Form("%s/constants_%s_%s.txt", inputDir.c_str(), runName4.c_str(), tag.c_str() ),Form("%s/constants_uncert_%s_%s.txt", inputDir.c_str(), runName4.c_str(), tag.c_str() ) };


  for(int i=0; i<ntot+1; ++i){

    in.open(openname[i-1]);


    while (nlines<4) {
      in>>x;
      if(!in.good()) break;
      ntuple->Fill(x);
      nlines++;
    }

in.close();
 nlines=0;
}

    ntuple->SetBranchAddress("x",&x);

    for(int j=0; j<4; ++j){
      ntuple->GetEntry(j);
      corr0[j]= x;
//.........这里部分代码省略.........
开发者ID:CeF3TB,项目名称:BTFAnalysis,代码行数:101,代码来源:drawCalibComparison.cpp

示例5: main

int main(int argc, char **argv)
{
	TFile *f;
	TFile *newf;
	TNtuple *ntuple;
	TNtuple *newntuple;
	TH1F *h1;
	TF1 *func;
	TString Metal;
	TString dataLoc;
	Int_t dataSL;
	
	if(argc < 5 || argc > 6){
		std::cout << "The number of arguments is incorrect" << std::endl;
		return 0;
	}
	
	dataLoc = argv[1];
	PHI_MIN = (Double_t) std::stod(argv[2]);
	PHI_MAX = (Double_t) std::stod(argv[3]);
	N_PHI = (Int_t) std::stoi(argv[4]);
	if(argc >= 6) Metal = argv[5];
		
	dataSL = dataLoc.Length();
	if(dataLoc(dataSL-1, 1) != "/"){
		dataLoc = dataLoc + "/";
	}	
	
	std::cout << "The following settings are being used" << std::endl;
	std::cout << "Data Directory = " << dataLoc << std::endl;
	std::cout << PHI_MIN << " < PHI < " << PHI_MAX << ", N_PHI = " << N_PHI << std::endl;
	if(argc == 6) std::cout << "Running only for Metal "<< Metal << std::endl;
	else std::cout << "Running all Metals" << std::endl;	
	
	Float_t Q2, Xb, Zh, Pt, Phi, Val, Err;
	Float_t A, Ac, Acc;
	Float_t AErr, AcErr, AccErr;
	Float_t ChiSQ;

	Int_t nentries, empty;

	if(Metal == "") N_METAL = 6;
	else N_METAL = 1;
	
	for(Int_t met = 0; met < N_METAL; met++){
		if(Metal == ""){
			if(met == 0) Metal = "C";
			else if(met == 1) Metal = "Fe";
			else if(met == 2) Metal = "Pb";
			else if(met == 3) Metal = "D_C";
			else if(met == 4) Metal = "D_Fe";
			else if(met == 5) Metal = "D_Pb";
		}
		if(dataLoc == "")
			f = new TFile("../Gen5DimData/" + Metal + "_5_dim_dist.root", "READ");
		else
			f = new TFile(dataLoc + Metal + "_5_dim_dist.root", "READ");
		ntuple = (TNtuple*) f->Get("fit_data");

		nentries = ntuple->GetEntries();
		ntuple->SetBranchAddress("Xb", &Xb);
		ntuple->SetBranchAddress("Q2", &Q2);
		ntuple->SetBranchAddress("Xb", &Xb);
		ntuple->SetBranchAddress("Zh", &Zh);
		ntuple->SetBranchAddress("Pt", &Pt);
		ntuple->SetBranchAddress("Phi", &Phi);
		ntuple->SetBranchAddress("Val", &Val);
		ntuple->SetBranchAddress("Err", &Err);

		newntuple = new TNtuple("AAcAcc_data", "AAcAcc_data", "Q2:Xb:Zh:Pt:A:AErr:Ac:AcErr:Acc:AccErr:ChiSQ");
		func = new TF1("fit", "[0]+TMath::Cos(x*TMath::Pi()/180)*[1]+TMath::Cos(2*x*TMath::Pi()/180)*[2]");

		newf = new TFile(Metal + "newphihist.root", "RECREATE");
		newf->cd();

		for(Int_t i = 0; i < nentries; i = i + N_PHI){
			ntuple->GetEntry(i);
			h1 = new TH1F((const char*) Form("PhiDist Q2=%.3f Xb=%.3f Zh=%.3f Pt=%.3f", Q2, Xb, Zh, Pt), 
							(const char*) Form("PhiDist Q2=%.3f Xb=%.3f Zh=%.3f Pt=%.3f", Q2, Xb, Zh, Pt), N_PHI, PHI_MIN, PHI_MAX);
			empty = 0;
			for(Int_t j = 1; j <= N_PHI; j++){
				ntuple->GetEntry(i+j-1);
				h1->SetBinContent(j, Val);
				if(h1->GetBinContent(j) == 0)
					empty++;
				h1->SetBinError(j, Err*1.04);
			}
			if(empty <= (N_PHI - MIN_BIN)){
				h1->Fit(func, "q");
				h1->Write();
				if(func->GetNDF() != 0){
					ChiSQ = func->GetChisquare();
					A = func->GetParameter(0);
					AErr = func->GetParError(0);
					Ac = func->GetParameter(1);
					AcErr = func->GetParError(1);
					Acc = func->GetParameter(2);
					AccErr = func->GetParError(2);
					newntuple->Fill(Q2, Xb, Zh, Pt, A, AErr, Ac, AcErr, Acc, AccErr, ChiSQ);
				}
//.........这里部分代码省略.........
开发者ID:rodmendezp,项目名称:PiPlusAnalysis,代码行数:101,代码来源:phihist.cpp

示例6: main


//.........这里部分代码省略.........
	TString gen_suffix = "_gen";
	TString Copy_Option = "fast";


	//	Strings that are relevent to this plot
	//	This is currently given by the user, but in time we can write an algorithm to determine this
	TString param1_gen = param1string + gen_suffix;
	TString param1_val = param1string + value_suffix;
	TString param1_err = param1string + error_suffix;
	TString param2_gen = param2string + gen_suffix;
	TString param2_val = param2string + value_suffix;
	TString param2_err = param2string + error_suffix;


	//	Get a list of ALL parameters within the file, this is given for free in the algorithms I wrote above

	//	Get a list of all branches in allresults
	vector<TString> all_parameters = get_branch_names( allresults );
	//	Get a list of all branches in allresults with '_value' in their name
	vector<TString> all_parameter_values = filter_names( all_parameters, value_suffix );
	vector<TString> all_parameter_errors = filter_names( all_parameters, error_suffix );
	vector<TString> all_parameter_pulls = filter_names( all_parameters, pull_suffix );


	//	Now to read in the Global Minima

	//	Store the Global fit corrdinate and value
	Float_t nll=0, Global_Best_NLL=0, x_point=0, y_point=0;

	//	Store the value of the 'nuisence' parameters as well
	Float_t* best_fit_values = new Float_t[all_parameter_values.size()];
	//	Construct an array to hold the best values for the rest of the parameters
	Float_t* best_fit_temp_values = new Float_t[all_parameter_values.size()];
	allresults->SetBranchAddress(NLL,&nll);

	//	Tell ROOT where to store the values
	for( unsigned short int i=0; i < all_parameter_values.size(); ++i )
	{
		allresults->SetBranchAddress(all_parameter_values[i],&best_fit_temp_values[i]);
	}


	//	Actually store the values in resident memory of the program
	cout << endl << "BEST FIT RESULTS AS DETERMINED FROM THE STANDARD FIT:" << endl;
	allresults->GetEntry(0);
	Global_Best_NLL = nll;
	for( unsigned short int i=0; i < all_parameter_values.size(); ++i )
	{
		cout << all_parameter_values[i] << ":\t" << best_fit_temp_values[i] << endl;
		best_fit_values[i] = best_fit_temp_values[i];
		if( string(all_parameter_values[i].Data()).compare(param1_val.Data()) == 0 ) x_point = best_fit_temp_values[i];
		if( string(all_parameter_values[i].Data()).compare(param2_val.Data()) == 0 ) y_point = best_fit_temp_values[i];
	}
	cout << endl;



	//	General Cuts to be applied for various plots

	//	Fit_Status == 3
	TString Fit_Cut = "(abs(" + Fit_Status + "-3.0)<"+Double_Tolerance+")";


	//	param1_gen == notgen	&&	param1_err == 0
	TString Param_1_Cut = "(abs(" + param1_gen + "-" + notgen +")<" + Double_Tolerance + ")&&(abs("+ param1_err + "-0.0)<"+ Double_Tolerance + ")";
	//	param2_gen == notgen	&&	param2_err == 0
开发者ID:abmorris,项目名称:RapidFit,代码行数:67,代码来源:RapidPlot_old.C

示例7: iterate

//iteration code
void iterate(TrkSettings s,int iter, int stepType, bool doCondor, bool testErrors = false)
{
  float pt, eta, phi, weight, centPU, rmin, maxJetPt,trkStatus,pNRec,mpt,mtrkQual,nEv; 
  
  TFile * histFile;
  std::string ifPP = "";
  if(s.nPb==0) ifPP = "pp_";
  if(iter==0) histFile = TFile::Open(Form("%scorrHists_job%d.root",ifPP.c_str(),s.job),"recreate");
  else        histFile = TFile::Open(Form("%scorrHists_job%d.root",ifPP.c_str(),s.job),"update");

  //make needed gen skim if it hasn't been done yet
  if(iter==0)
  {
    TH1D *genPre[20], *mrecoPre[20];
    TH2D *genPre2[20], *mrecoPre2[20];
    std::cout << "Denominator info not yet calculated; calculating and saving it..." << std::endl;
    for(int i = 0; i<8; i++)
    {
      if(i==6) continue;
      if(i != 1 && i!=7)
      {
        genPre[i] = makeTH1(s,i,"gen");
        mrecoPre[i] = makeTH1(s,i,"mreco");
      }
      else
      {
        genPre2[i] = makeTH2(s,i,"gen");
        mrecoPre2[i]= makeTH2(s,i,"mreco");
      }
    }
   
    TFile * skim;
    if(doCondor)
    {
      if(s.reuseSkim) skim = TFile::Open(Form("/mnt/hadoop/cms/store/user/abaty/tracking_Efficiencies/ntuples/%strackSkim_job%d.root",ifPP.c_str(),s.job),"read");
      else skim = TFile::Open(Form("%strackSkim_job%d.root",ifPP.c_str(),s.job),"read");
    }
    else skim = TFile::Open(Form("/export/d00/scratch/abaty/trackingEff/ntuples/%strackSkim_job%d.root",ifPP.c_str(),s.job),"read");
    //for efficiency
    std::cout << "Doing Efficiency denominator" << std::endl;   
    TNtuple * gen = (TNtuple*)  skim->Get("Gen");
    gen->SetBranchAddress("genPt",&pt);
    gen->SetBranchAddress("genEta",&eta); 
    gen->SetBranchAddress("genPhi",&phi);
    gen->SetBranchAddress("weight",&weight);
    gen->SetBranchAddress("centPU",&centPU);
    gen->SetBranchAddress("rmin",&rmin);
    gen->SetBranchAddress("jtpt",&maxJetPt);
    gen->SetBranchAddress("pNRec",&pNRec); 
    gen->SetBranchAddress("nEv",&nEv); 
	   
    for(int i = 0; i<gen->GetEntries(); i++)
    {
      gen->GetEntry(i);
      if(s.doSplit && nEv==1) continue;
      genPre[0]->Fill(pt,weight);
      genPre2[1]->Fill(eta,phi,weight); 
      genPre[2]->Fill(centPU,weight);
      genPre[3]->Fill(maxJetPt,weight);
      genPre[4]->Fill(eta,weight); 
      genPre[5]->Fill(rmin,weight);
      genPre2[7]->Fill(eta,pt,weight);
    }

    //for fake
    std::cout << "Doing Fake denominator" << std::endl;   
    TNtuple * reco = (TNtuple*)  skim->Get("Reco"); 
    reco->SetBranchAddress("trkPt",&pt);
    reco->SetBranchAddress("trkEta",&eta);
    reco->SetBranchAddress("trkPhi",&phi);
    reco->SetBranchAddress("weight",&weight);
    reco->SetBranchAddress("centPU",&centPU);
    reco->SetBranchAddress("rmin",&rmin);
    reco->SetBranchAddress("jtpt",&maxJetPt);
    reco->SetBranchAddress("trkStatus",&trkStatus);
    reco->SetBranchAddress("nEv",&nEv); 
    for(int i = 0; i<reco->GetEntries(); i++)
    {
      reco->GetEntry(i);
      if(s.doSplit && nEv==1) continue;
      if(trkStatus<-100) continue;
      mrecoPre[0]->Fill(pt,weight);
      mrecoPre2[1]->Fill(eta,phi,weight); 
      mrecoPre[2]->Fill(centPU,weight);
      mrecoPre[3]->Fill(maxJetPt,weight);
      mrecoPre[4]->Fill(eta,weight); 
      mrecoPre[5]->Fill(rmin,weight);
      mrecoPre2[7]->Fill(eta,pt,weight);
    }
  
    //Secondary calculation (no iterations)
    std::cout << "Quickly calculating the Secondary Rate from the reco tree (No further iterations needed)" << std::endl;
    TH2D * Secondary_Matched = new TH2D("Secondary_Matched",";pt;",s.multiRecoBins.at(s.job/s.nPtBinCoarse),s.ptMin,s.ptMax,24,-2.4,2.4); 
    TH2D * Secondary_Secondaries = new TH2D("Secondary_Secondaries",";pt;",s.multiRecoBins.at(s.job/s.nPtBinCoarse),s.ptMin,s.ptMax,24,-2.4,2.4); 
    for(int i = 0; i<reco->GetEntries(); i++)
    {
      reco->GetEntry(i);
      if(s.doSplit && nEv==1) continue;
      if(trkStatus>-100)
//.........这里部分代码省略.........
开发者ID:abaty,项目名称:TrackCorrRun2,代码行数:101,代码来源:iterate.C

示例8: n3HeSim

float n3HeSim(int nev_=0, float rfsf_phi_=300, int sev=0)
{
  // commandline option '-var=val' to change any global
  for (int i=1; i<gApplication->Argc(); ++i) 
  {
      TString opt(gApplication->Argv(i));
      if ((opt[0]=='-' || opt[0]=='+') && opt.Contains("="))
	  gROOT->ProcessLine(opt=opt.Append(";").Strip(TString::kLeading,'-'));
  }

  if (nev_) 
      nev = nev_;
  if (rfsf_phi_!=0) 
      rfsf_phi=rfsf_phi_/360.;
  TFile* f = new TFile("/home/siplu/GIT/n3He_Soft/Github/Simulation/data/mcstas.root");
  TNtuple* ntp = (TNtuple*)f->Get("mcstas");

  // set up ntuple
  BRANCH(l);
  BRANCH(pol);
  BRANCH(p5);
  BRANCH(p6);
  BRANCH(t6);
  BRANCH(x6);
  BRANCH(y6); 
  BRANCH(vx6);
  BRANCH(vy6);
  BRANCH(vz6);
  
  float chop[4]; 
  TBranch* b_chop[4];
  for (int j=0;j<nch;++j) 
  {
      b_chop[j]=ntp->GetBranch(vch[j]);
      ntp->SetBranchAddress(vch[j],&chop[j]);
  }

  // precalculate track projections
  float dwc = lwc/nz;			// WC parameters
  float da  = 2./na, a0=-1+da/2;	// polar [cos(theta)] integration
  float db  = 2*PI/nb, b0=-PI+db/2;	// azimuthal [phi] integration
  float cxyz[3], &cx=cxyz[0],&cy=cxyz[1],&cz=cxyz[2];	// projection cosines
  float ccz[NDIV], ccx[NDIV][NDIV], ccy[NDIV][NDIV], as; // cached values
  float aa=a0; 
  for (int ia=0; ia<na; ++ia, aa+=da) 
  {
      ccz[ia]=aa; 
      if (ccz[ia]==0) 
	  ccz[ia]=1e-11; 
      as=sqrt(1-aa*aa);
      float bb=b0; 
      for (int ib=0; ib<nb; ++ib, bb+=db) 
      {
	  ccx[ia][ib]=as*cos(bb); 
	  if (ccx[ia][ib]==0) 
	      ccx[ia][ib]=1e-11;
	  ccy[ia][ib]=as*sin(bb); 
	  if (ccy[ia][ib]==0) 
	      ccy[ia][ib]=1e-11;
      }
  }

  // cumulative beta distribution
  for (int i=0;i<nbet;++i) 
      beta_int[i+1]=beta_int[i]+beta_pt[i];

  // initialize WC response matrices
  double  n5 = 0;			// pre-polarizer neutrons
  double   N[NTOF]={0};			// chopped neutrons at end of SMpol
  double P2N[NTOF]={0};			//  " * P^2
  double  WN[NTOF]={0};			// captures in 3He target
  double  BN[NTOF][nwc]={{0}};		// N_i = N beta_i    = \sum{n_i} ions
  double GBN[NTOF][nwc]={{0}};		// M_i = N_i gamma_i = \sum{n_i gamma}
  double D2N[NTOF][nwc][nwc]={{{0}}};	// delta^2 N_ij = covariance
  double  GW[NTOF][nwc]={{0}};		// weight of each element

  // loop over events, fill "n","p2n" histograms, wc response matrices
  if (ntp->GetEntries()<nev) 
      nev=ntp->GetEntries();
  for (int iev=sev;iev<sev+nev;++iev) 
  {
      if (verbose && cnt) 
      {		// :........:....
	  if      (iev%(50*cnt)==0) 
	      cout<<endl<<" :"<<flush;
	  else if (iev%(10*cnt)==0) 
	      cout<<":"<<flush;
	  else if (iev%cnt==0) cout<<"."<<flush;
      }

      // read variables
      ntp->GetEntry(iev);
      hl5.Fill(l,p5*1.4/2*60); 
      n5 += p5;
      hl6.Fill(l,p6*1.4/2*60);

      // polarizer
      float tx = 1; //Transmission
      b_pol->GetEntry(iev);
      if (pol!=pol) 
//.........这里部分代码省略.........
开发者ID:latifkabir,项目名称:n3He_Soft,代码行数:101,代码来源:det3d_n3he.C

示例9: fragmentEnergyDistributionDifferentAngles

void fragmentEnergyDistributionDifferentAngles() {

gStyle->SetOptStat(0000000000); //remove the for this graphs totally redundant statbox

//   gROOT->SetStyle("clearRetro");

   TString pDepth, fragment, Znum, normToOneAtZeroAngle;
   cout << "Enter phantom depth (eg. 27.9, see experimentalData directory for choices): ";
   cin >> pDepth;  
   TString simulationDataPath = "IAEA_" + pDepth + ".root";
   TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
   dir.ReplaceAll("basic.C","");
   dir.ReplaceAll("/./","/");
   ifstream in;
   in.open(Form("experimentalData/iaeaBenchmark/fragmentEnergySpctra279mmWater0deg.dat",dir.Data()));
   Float_t f1,f2,f3, f4,f5,f6;
   Int_t nlines = 0;
   TFile *f = new TFile("fragmentEnergyWithAngularDistribution.root","RECREATE");
   TNtuple *ntuple = new TNtuple("ntuple","Data from ascii file","Energy:He:B:H:Li:Be");
	  
   Char_t DATAFLAG[4];
   Int_t NDATA;
   Char_t n1[6], n2[2], n3[2], n4[2], n5[2], n6[2];
   in >> DATAFLAG >> NDATA ; // Read EXFOR line: 'DATA 6'
   in >> n1 >> n2 >> n3 >> n4 >> n5 >> n6; // Read  column titles: 'Energy He B [...]'

   cout <<n1<<" "<<n2<<" "<<n3<<"    "<<n4<<"    "<<n5<<"   "<<n6<<"\n";
   while (1) {
      in >> f1 >> f2 >> f3 >>f4 >> f5 >> f6;
      if (!in.good()) break;
      if (nlines < 500 ) printf("%f  %0.2f %0.2f %0.2f %0.2f %0.2f \n",f1,f2,f3,f4,f5,f6);
      ntuple->Fill(f1,f2,f3,f4,f5,f6);
      nlines++;
   }
   

   //Let's pull in the simulation-data
   TFile *MCData = TFile::Open("IAEA_200000.root");
   TNtuple *fragments = (TNtuple*) MCData->Get("fragmentNtuple");

   //Block bellow pulls out the simulation's metadata from the metadata ntuple.
   TNtuple *metadata = (TNtuple*) MCData->Get("metaData");
   Float_t events, detectorDistance,waterThickness,beamEnergy,energyError,phantomCenterDistance;
   metadata->SetBranchAddress("events",&events);
   metadata->SetBranchAddress("waterThickness",&waterThickness);
   metadata->SetBranchAddress("detectorDistance",&detectorDistance);
   metadata->SetBranchAddress("beamEnergy",&beamEnergy);
   metadata->SetBranchAddress("energyError",&energyError);
   metadata->SetBranchAddress("phantomCenterDistance",&phantomCenterDistance);
   metadata->GetEntry(0); //there is just one row to consider.
   
	//good to keep for ref. G4 might give weird units due to change.
	metadata->Scan();
	std::cout << "Recieved metadata-row: " << events << " " <<  detectorDistance << " " << waterThickness << " " << beamEnergy << " " << energyError << " " << phantomCenterDistance;


//A lot of hardcoded histograms, ugly
   Double_t binAmount = 50.0; //casting from int failed somehow, so in float temporarily, fixme
   Double_t maxEnergy = 450.0;
   Double_t binWidth = maxEnergy / binAmount;
   TH1F *hist1 = new TH1F("hist1", "", binAmount, 0.0, maxEnergy);
   TH1F *hist2 = new TH1F("hist2", "", binAmount, 0.0, maxEnergy);   
   TH1F *hist3 = new TH1F("hist3", "", binAmount, 0.0, maxEnergy);
   TH1F *hist4 = new TH1F("hist4", "", binAmount, 0.0, maxEnergy);
   TH1F *hist5 = new TH1F("hist5", "", binAmount, 0.0, maxEnergy);
   TH1F *hist6 = new TH1F("hist6", "", binAmount, 0.0, maxEnergy);
   TH1F *hist7 = new TH1F("hist7", "", binAmount, 0.0, maxEnergy);
   TH1F *hist8 = new TH1F("hist8", "", binAmount, 0.0, maxEnergy);
   TH1F *hist9 = new TH1F("hist9", "", binAmount, 0.0, maxEnergy);
for(int k = 1; k <= 6; k++){
		TString Znum = Form("%i", k);
	hist1->SetTitle("Z=" + Znum);


	//ALL UNITS ARE cm!
	Double_t detectorSideLength = 4; //40mm, as e.haettner H1 detector
	Double_t scatteringDistance = detectorDistance - phantomCenterDistance; //temporarily hard-coded, should be distance from target-center to detector
	Double_t degrees; //< actually radians
	
	Double_t r, rMin, rMax, deltaOmega, normFloat;
	TString rMinString, rMaxString, normString;
	TString same = "";
	TString histName;
	TCanvas *c3 = new TCanvas("histograms", "Distribution (at different angles)");
	int i = 0; //so that the degree steps can be varied to unevenly spaced values separate counter is used

	std::cout << "The following numbers also make it possible to make number of fragments comparison to the graph in A1 of E.Haettner\n";
	for(Double_t j = 0.0; j <= 8.0; j=j+1.0){
		i++;
		degrees = j * TMath::DegToRad();
		//std::cout << "plotting for Z = " << Znum << " at " << j << " degrees\n";
		//Distance from straight beam at the requested angle
		r = scatteringDistance * TMath::Tan(degrees);
		//now the "detector is rotated around all possible perpendicularlynangle values to beamline".
		//This forms an annulus with rMin and RMax as otuer and inner radiuses
		//Notice this will give a bit of approximation at small angles where at 0 degrees this gives a round sensor.
		Double_t deltaPhi = TMath::ATan((TMath::Cos(degrees)*detectorSideLength)/(2*scatteringDistance));
		rMin = TMath::Max(0.0,r - (detectorSideLength/(2*TMath::Cos(degrees))));
		rMax = rMin + ((detectorSideLength*TMath::Sin(degrees))/TMath::Tan((TMath::Pi()/2) - degrees - deltaPhi)) + (detectorSideLength*TMath::Cos(degrees));
		rMinString = Form("%f", rMin);
//.........这里部分代码省略.........
开发者ID:C-D-D,项目名称:Geant4.9.6,代码行数:101,代码来源:fragmentEnergyDistributionDifferentAngles.C

示例10: DoTDeriMax1090Correction

void DoTDeriMax1090Correction(TString SpectrumFileInput = "/lustre/miifs05/scratch/him-specf/hyp/steinen/COSYBeamtestAna/COSYnewMogon/June2014/COSYJune2014Dataset11_200,100,0,5339_SR1.root", TString FitFileInput = "/lustre/miifs05/scratch/him-specf/hyp/steinen/COSYBeamtestAna/COSYnewMogon/Fit/FitCOSYJune2014Dataset11_200,100,0,5339_SR1.root")
{
	TH2D *hSpectrumTDeriMax1090_EnergyChannel;
	TH2D *hSpectrumTDeriMax1090Rel_EnergyChannel;
	
	TH2D *hSpectrumT1090_EnergyChannelCorr1;
	TNtuple *DataNTuple;
	TFile *SpectrumInput = new TFile(SpectrumFileInput.Data());
	
	hSpectrumTDeriMax1090_EnergyChannel = (TH2D*) SpectrumInput->Get("Histograms/Energy_DeriMaxT90/Energy_DeriMaxT90_01");
	hSpectrumTDeriMax1090_EnergyChannel->SetDirectory(0);
	hSpectrumTDeriMax1090Rel_EnergyChannel = (TH2D*) SpectrumInput->Get("Histograms/Energy_DeriMaxT90Rel/Energy_DeriMaxT90Rel_01");
	hSpectrumTDeriMax1090Rel_EnergyChannel->SetDirectory(0);
	hSpectrumT1090_EnergyChannelCorr1 = (TH2D*) SpectrumInput->Get("Histograms/EnergyRt1090/EnergyRt1090CorrectionRt_01");
	hSpectrumT1090_EnergyChannelCorr1->SetDirectory(0);
	SpectrumInput->Close();
	//hSpectrumTDeriMax1090_EnergyChannel->Draw("colz");
	
	
	TFile *FitInput = new TFile(FitFileInput.Data(),"Update");
	DataNTuple = (TNtuple*)FitInput->Get("DataNTuple");
	DataNTuple->Scan();
	
	Int_t entries = (Int_t)DataNTuple->GetEntries();
	cout<<"Number of Entries: "<<entries<< endl;
	const int entriesArrayValue =entries;
	TF1 *FitFunc[entriesArrayValue];
	float Energy=0;
	float ChannelPeakPos=0;
	float ChannelRangeMin=0;
	float ChannelRangeMax=0;
	DataNTuple->SetBranchAddress("Energy",&Energy);
	DataNTuple->SetBranchAddress("ChannelPeakPos",&ChannelPeakPos);
	DataNTuple->SetBranchAddress("ChannelRangeMin",&ChannelRangeMin);
	DataNTuple->SetBranchAddress("ChannelRangeMax",&ChannelRangeMax);
	
	TCanvas* can=new TCanvas();
	gPad->SetLogz();
	hSpectrumTDeriMax1090_EnergyChannel->GetXaxis()->SetRangeUser(-30,250);
	hSpectrumTDeriMax1090Rel_EnergyChannel->GetXaxis()->SetRangeUser(-0.1,0.95);
	
	for (Int_t ki=0;ki<entries;ki++)
	{
		DataNTuple->GetEntry(ki);
		//if (int(Energy) == 1332)
		//if (int(Energy) == 510)
		//if (ki == entries-1)
		{
			cout << ChannelRangeMin << " " << ChannelRangeMax << endl;
			
			
			//first correction via TDeriMaxT90Rel
			hSpectrumTDeriMax1090_EnergyChannel->GetYaxis()->SetRangeUser(ChannelRangeMin,ChannelRangeMax);
			hSpectrumTDeriMax1090Rel_EnergyChannel->GetYaxis()->SetRangeUser(ChannelRangeMin,ChannelRangeMax);
			//TF1* FitFuncSlices = new TF1("FitFuncSlices","gaus(0)+pol0(3)",ChannelRangeMin,ChannelRangeMax);
			//FitFuncSlices->SetParameters(1000,ChannelPeakPos-10,4,10);
			//FitFuncSlices->SetParLimits(1,ChannelRangeMin,ChannelRangeMax);
			//FitFuncSlices->SetParLimits(2,0,10);
			//FitFuncSlices->SetParLimits(3,0,100);
	
			//gDirectory->ls();
			
			TH1D *hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually=new TH1D("hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually","",hSpectrumTDeriMax1090Rel_EnergyChannel->GetNbinsX(),-0.3,1.3);
			//cout <<hSpectrumTDeriMax1090_EnergyChannel_MaxPos->GetEntries()<< endl;
			for(int binX = hSpectrumTDeriMax1090Rel_EnergyChannel->GetXaxis()->FindBin(-0.1);binX <= hSpectrumTDeriMax1090Rel_EnergyChannel->GetXaxis()->FindBin(0.90);binX++)
			{
				cout << "binx " << binX << endl;
				TH1D *hProfileY =hSpectrumTDeriMax1090Rel_EnergyChannel->ProjectionY("_py",binX,binX);	
				double MaxValue=hProfileY->GetBinCenter(hProfileY->GetMaximumBin());
				TF1* FitFuncSlices = new TF1("FitFuncSlices","gaus(0)+[3]",MaxValue-20,MaxValue+20);
				TF1* FitFuncGausSlices = new TF1("FitFuncGausSlices","gaus(0)",MaxValue-20,MaxValue+20);
				FitFuncGausSlices->SetParameters(hProfileY->GetBinContent(hProfileY->GetMaximumBin()),MaxValue,4);
				
				hProfileY->Fit(FitFuncGausSlices,"RNQ");
				
				FitFuncSlices->SetParameters(FitFuncGausSlices->GetParameter(0),FitFuncGausSlices->GetParameter(1),FitFuncGausSlices->GetParameter(2),10);
				
				FitFuncSlices->SetParLimits(0,0,10000);
				FitFuncSlices->SetParLimits(1,MaxValue-10,MaxValue+10);
				FitFuncSlices->SetParLimits(2,0,10);
				FitFuncSlices->SetParLimits(3,0,100);
				hProfileY->Fit(FitFuncSlices,"RNQ");
				
				cout <<MaxValue<<"  " << FitFuncSlices->GetParameter(1) << "   " << FitFuncSlices->GetParError(1) <<endl;
				hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->SetBinContent(binX, FitFuncSlices->GetParameter(1));
				hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->SetBinError(binX, FitFuncSlices->GetParError(1));
				
				
			}
			hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->GetYaxis()->SetRangeUser(ChannelPeakPos-100,ChannelPeakPos+50);
			hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->GetXaxis()->SetRangeUser(-0.05,0.9);
			TF1 * funcCorrConst = new TF1("funcCorrConst","pol0",-0.03,0.03);
			funcCorrConst->SetLineColor(kRed);
			TF1 * funcCorrPol = new TF1("funcCorrPol",PolPiecewise,-0.05,0.9,6);
			
			funcCorrPol->SetLineColor(kBlue);
			funcCorrPol->SetParameter(0,0.04);
			funcCorrPol->SetParameter(1,ChannelPeakPos);
			hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->Fit(funcCorrConst,"R");
			hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->Fit(funcCorrPol,"R+");
//.........这里部分代码省略.........
开发者ID:mstkph2011,项目名称:HypGeFADCAna,代码行数:101,代码来源:DoTDeriMax1090Correction.C

示例11: TakeDataAnalyzer

void TakeDataAnalyzer(Int_t RunN){
 
  //Int_t RunN = 4591;   
  //string FileRoot = "/d00/icali/PixelHwStudies/PSIStuff/log/bt05r";
 string FileRoot = "/home/l_tester/log/bt05r";
 string FileInName = "thistos.root";
 string FileOutName = "ProcessedData.root";
 char RunNumber[6];
 sprintf(RunNumber, "%.6d", RunN);
 FileRoot = FileRoot + RunNumber + "/";
 FileInName = FileRoot + FileInName;
 FileOutName = FileRoot + FileOutName;
 
 TFile *iFile = new TFile((const char*)FileInName.c_str());
 TNtuple *Digis = (TNtuple*)iFile->FindObjectAny("events");
 Int_t EvN, row, col, roc, ph;
 Float_t vcal;
 Digis->SetBranchAddress("row", &row);
 Digis->SetBranchAddress("col", &col);
 Digis->SetBranchAddress("roc", &roc);
 Digis->SetBranchAddress("ph", &ph);
 Digis->SetBranchAddress("vcal", &vcal);
 Digis->SetBranchAddress("eventNr", &EvN);
 Int_t iNTlenght = Digis->GetEntries();
 
 TFile *oFile = new TFile((const char*)FileOutName.c_str(), "RECREATE");
 TNtuple *Multiplicity = new TNtuple("ModMult", "ModMult", "EvN:roc:NModHits:NROCHits:NRows:NCols:MeanPh:MeanPhPuls",10000000);
 
 //******************Calculating Number of Events**************
 Digis->GetEntry(iNTlenght -1);
 std::cout << " MaxEvent " << EvN << std::endl;
  
 //*****************Creating Multiplicity NTuple***************
 
 ModuleMultiplicity  ModMult;
 Int_t OldEvN = 1;
 for(Int_t i =0; i< iNTlenght; ++i){
    Digis->GetEntry(i);
    if(OldEvN != EvN ||( i == iNTlenght -1) ){
      for(Int_t j=0; j < 16; ++j){ 
        Float_t NModHits = ModMult.ModMultiplicity();
        Float_t NROCHits = ModMult.ROCMultiplicity(j);
        Float_t NRows = ModMult.NumberOfRows(j);
        Float_t NCols = ModMult.NumberOfColumns(j);
        Float_t MeanPh = ModMult.MeanPh(j);  
        Float_t MeanPhPuls = ModMult.MeanPhPuls(j); 
        if(NROCHits >0) Multiplicity->Fill(EvN-1, j,NModHits ,NROCHits ,NRows ,NCols ,MeanPh, MeanPhPuls); 
      }
      ModMult.Clean();
      OldEvN = EvN;
    }
    
    bool SelPixel = 0;
    if(row ==5 && col ==5)SelPixel = 1;
    if(roc>-1&&col>-1)ModMult.Add(roc, row, col, ph, SelPixel);
 }
 
 oFile->Write();
 oFile->Close();          
 
}
开发者ID:kandrosov,项目名称:psi46expert_bare,代码行数:61,代码来源:TakeDataAnalyzer.C

示例12: jettrigger

void jettrigger()
{
  TFile *f = new TFile("jettrig.root");
  TNtuple *nt = (TNtuple *)f->Get("nt");

//Declaration of leaves types
   Float_t         pt;
   Float_t         eta;
   Float_t         phi;
   Float_t         mass;
   Float_t         jt40;
   Float_t         jt60;
   Float_t         jt80;
   Float_t         jt100;
   Float_t         pscl40;
   Float_t         pscl60;
   Float_t         pscl80;
   Float_t         pscl100;
  

   // Set branch addresses.
   nt->SetBranchAddress("pt",&pt);
   nt->SetBranchAddress("eta",&eta);
   nt->SetBranchAddress("phi",&phi);
   nt->SetBranchAddress("mass",&mass);
   nt->SetBranchAddress("jt40",&jt40);
   nt->SetBranchAddress("jt60",&jt60);
   nt->SetBranchAddress("jt80",&jt80);
   nt->SetBranchAddress("jt100",&jt100);
   nt->SetBranchAddress("pscl40",&pscl40);
   nt->SetBranchAddress("pscl60",&pscl60);
   nt->SetBranchAddress("pscl80",&pscl80);
   nt->SetBranchAddress("pscl100",&pscl100);
  
   TFile *fout = new TFile("jettrig_withweight.root","recreate");
   TNtuple *ntout = new TNtuple("ntweight","ntweight","pt:eta:phi:mass:jt40:jt60:jt80:jt100:pscl40:pscl60:pscl80:weightJet:weight12003");
   //TTree *ntout=new TTree("ntweight","ntweight");
   ntout->SetDirectory(fout);

   /*   ntout->Branch("pt",&pt);
   ntout->Branch("eta",&eta);
   ntout->Branch("phi",&phi);
   ntout->Branch("mass",&mass);
   ntout->Branch("jt40",&jt40);
   ntout->Branch("jt60",&jt60);
   ntout->Branch("jt80",&jt80);
   ntout->Branch("jt100",&jt100);
   ntout->Branch("pscl40",&pscl40);
   ntout->Branch("pscl60",&pscl60);
   ntout->Branch("pscl80",&pscl80);
   ntout->Branch("pscl100",&pscl100);
   ntout->Branch("weight",&weight);
   */
   Long64_t nentries = nt->GetEntries();
   cout<<nentries<<endl;

   int oneperc = nentries/100;
   Long64_t nbytes = 0;

   //#ifndef __CINT__
   //#pragma omp parallel for ordered schedule(dynamic)
   //#endif
   for (Long64_t i=0; i<nentries;i++) {
           nbytes += nt->GetEntry(i);

      if (i % oneperc == 0) cout<<"\r"<<i/oneperc<<"%   "<<flush;

      float weightJet = 0, weight12003 = 0;

      if (jt40 && !jt60 && !jt80 && !jt100) weight12003 = 1/pscl40;
      if (jt60 && !jt80 && !jt100) weight12003 = 1;
      if (jt80 && !jt100) weight12003 = 1;
      if (jt100) weight12003 = 1;

      if (jt40 && pt>40 && pt<60) weightJet = pscl40;
      if (jt60 && pt>60 && pt<80) weightJet = pscl60;
      if (jt80 && pt>80 && pt<100) weightJet = pscl80;
      if (jt100 && pt>100) weightJet = pscl100;

      //#ifndef __CINT__
      //#pragma omp ordered
      //#endif
	ntout->Fill(pt,eta,phi,mass,jt40,jt60,jt80,jt100,pscl40,pscl60,pscl80,weightJet,weight12003);

   }
   cout<<endl;
   cout<<ntout->GetEntries()<<endl;
   ntout->Write();
   fout->Close();
   f->Close();

   f = new TFile("jettrig_withweight.root");
   nt = (TNtuple *)f->Get("ntweight");
   cout<<nt->GetEntries()<<endl;
   f->Close();

}
开发者ID:istaslis,项目名称:pPbmacro,代码行数:97,代码来源:Add_Data_TriggerWeight.C

示例13: fragmentYieldsPlot

void fragmentYieldsPlot() {
   gStyle->SetOptStat(0000000000); //remove the for this graphs totally redundant statbox
   int ZNumGiven;
   cout << "Enter fragment Z-number (eg. 1): ";
   cin >> ZNumGiven;

   TCanvas *c1 = new TCanvas("fragmentYieldsPlot", "Total yield of fragments zero to ten degrees as function of depth");
   
   TString fragmentNameChoices[6] = {"H","He","Li","Be","B","C"};
   
   TString fragmentName = fragmentNameChoices[ZNumGiven-1];  
   
   std::cout << fragmentName << endl;
   
   TH1F* dummyHisto = new TH1F("dummyHisto", fragmentName + " yields 0-10 degrees" ,100, 0.0,40); //Dummyhisto fix for missing TNtuple methods.
   dummyHisto->SetXTitle("Depth (cm)");
   dummyHisto->SetYTitle("N/N0");

   ifstream in;
   TString experimentalDataPath = "experimentalData/iaeaBenchmark/yields/TDK" + fragmentName + ".dat";
   
   ifstream in;

   //Pull in ascii/exfor-style data
   in.open(experimentalDataPath);

   Float_t f1,f2;
   Int_t nlines = 0;
   TFile *f = new TFile("fragmentAngularDistribution.root","RECREATE");
   TNtuple *ntuple = new TNtuple("ntuple","Data from ascii file","x:y");
	  
   Char_t DATAFLAG[4];
   Int_t NDATA;
   Char_t n1[15], n2[15];
   in >> DATAFLAG >> NDATA ; // Read EXFOR line: 'DATA 6'
   in >> n1 >> n2; // Read  column titles: 'Energy He B [...]'

   cout <<n1<<"   "<<n2<<"\n";
   while (1) {
      in >> f1 >> f2;
      if (!in.good()) break;
      if (nlines < 500 ) printf("%f %f\n",f1,f2);
      ntuple->Fill(f1,f2);
      nlines++;
   }
   std::cout << "Imported " << nlines << " lines from data-file" << endl;




   TNtuple *simData = new TNtuple("ntuple","Data from ascii file","depth:H:He:Li:Be:B:C");
   
//   gROOT->SetStyle("clearRetro");
 //this will be used as base for pulling the experimental data
   TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
   dir.ReplaceAll("fragmentAngularDistribution.C","");
   dir.ReplaceAll("/./","/");
   ifstream in;
   simData->Fill(0.0,0.0,0.0,0.0,0.0,0.0,1.0);
for(int j = 1; j <= 40;j=j=j+1){
   TString pDepth, fragment, Znum, normToOneAtZeroAngle;
   pDepth = Form("%i",j);
/*
   cout << "Enter phantom depth (eg. 27.9, see experimentalData directory for choices): ";
   cin >> pDepth;
*/
   TString simulationDataPath = "IAEA_" + pDepth + ".root";

   //Let's pull in the simulation-data
   //TFile *MCData = TFile::Open("IAEA_" + pDepth + ".root");
   TFile *MCData = TFile::Open(simulationDataPath);
   TNtuple *fragments = (TNtuple*) MCData->Get("fragmentNtuple");

   //Block bellow pulls out the simulation's metadata from the metadata ntuple.
   TNtuple *metadata = (TNtuple*) MCData->Get("metaData");
   Float_t events, detectorDistance,waterThickness,beamEnergy,energyError,phantomCenterDistance;
   metadata->SetBranchAddress("events",&events);
   metadata->SetBranchAddress("waterThickness",&waterThickness);
   metadata->SetBranchAddress("detectorDistance",&detectorDistance);
   metadata->SetBranchAddress("beamEnergy",&beamEnergy);
   metadata->SetBranchAddress("energyError",&energyError);
   metadata->SetBranchAddress("phantomCenterDistance",&phantomCenterDistance);
   metadata->GetEntry(0); //there is just one row to consider.
	//ALL UNITS ARE cm!
	Double_t scatteringDistance = detectorDistance - phantomCenterDistance; //temporarily hard-coded, should be distance from target-center to detector

	Double_t degrees = 10.0;
	Double_t r, rMin, rMax, graphMaximum = 0.0;
	Double_t norming = events*.999;
	TString rMinString;
	TString rMaxString;

	rMinString = "0.00";
	rMaxString = Form("%f", scatteringDistance*TMath::ATan(degrees*TMath::DegToRad()));

		Double_t H = ((Double_t*) fragments->GetEntries("(Z == " + TString::Format("%i",1) + "  && sqrt(posY^2 + posZ^2) < " + rMaxString + "&& sqrt(posY*posY + posZ*posZ) > " + rMinString + ")")) / norming;
		Double_t He = ((Double_t*) fragments->GetEntries("(Z == " + TString::Format("%i",2) + "  && sqrt(posY^2 + posZ^2) < " + rMaxString + "&& sqrt(posY*posY + posZ*posZ) > " + rMinString + ")")) / norming;
		Double_t Li = ((Double_t*) fragments->GetEntries("(Z == " + TString::Format("%i",3) + "  && sqrt(posY^2 + posZ^2) < " + rMaxString + "&& sqrt(posY*posY + posZ*posZ) > " + rMinString + ")")) / norming;
		Double_t Be = ((Double_t*) fragments->GetEntries("(Z == " + TString::Format("%i",4) + "  && sqrt(posY^2 + posZ^2) < " + rMaxString + "&& sqrt(posY*posY + posZ*posZ) > " + rMinString + ")")) / norming;
		Double_t B = ((Double_t*) fragments->GetEntries("(Z == " + TString::Format("%i",5) + "  && sqrt(posY^2 + posZ^2) < " + rMaxString + "&& sqrt(posY*posY + posZ*posZ) > " + rMinString + ")")) / norming;
//.........这里部分代码省略.........
开发者ID:C-D-D,项目名称:Geant4.9.6,代码行数:101,代码来源:fragmentYieldsPlot.C


注:本文中的TNtuple::SetBranchAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。