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


C++ TFile::GetName方法代码示例

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


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

示例1: plotVBFVHReweighted

void plotVBFVHReweighted(){
  gROOT->ProcessLine(".x tdrstyle.cc");
  gStyle->SetOptStat(0);

  TString INPUT_NAME = "HtoZZ4l_Phantom_125p6_VHDistributions_GenLevel.root";
  TString OUTPUT_NAME = "HtoZZ4l_Phantom_125p6_VHReweightingPlots_GenLevel.root";

  double mPOLE = 125.6;
  float ZZMass_PeakCut[2] ={ 125.1, 126.1 }; // Spin 0 analysis

  float templateWeight = 1;
  float GenDiJetMass;
  float MC_weight;
  float ZZMass = 0;

  TString coutput_common = user_TemplateswithTrees_dir + "../VHContributions/Plots/GenLevel/";
  gSystem->Exec("mkdir -p " + coutput_common);
  TString coutput = coutput_common + OUTPUT_NAME;
  TFile* foutput = new TFile(coutput, "recreate");

  const int kNumTemplates = 3;
  TString templatetitles[kNumTemplates] ={ "VBF Sig", "VBF Bkg", "VBF Int" };
  TString templatenames[kNumTemplates] ={ "VBF_Sig", "VBF_Bkg", "VBF_Int" };
  TH1F* hVBF_onshell_LC[kNumTemplates] ={ 0 };
  TH1F* hVBF_offshell_LC[kNumTemplates] ={ 0 };
  TH1F* hVBF_onshell_scaled[kNumTemplates] ={ 0 };
  TH1F* hVBF_offshell_scaled[kNumTemplates] ={ 0 };
  TH1F* hVBF_onshell_scaled_wVBF[kNumTemplates] ={ 0 };
  TH1F* hVBF_offshell_scaled_wVBF[kNumTemplates] ={ 0 };

  for (int erg_tev=7; erg_tev<=8; erg_tev++){
    for (int folder=0; folder<3; folder++){
      TString comstring;
      comstring.Form("%i", erg_tev);
      TString erg_dir;
      erg_dir.Form("LHC_%iTeV/", erg_tev);
      int EnergyIndex = 1;
      if (erg_tev == 7) EnergyIndex = 0;
      TString cinput_common = user_TemplateswithTrees_dir + "../VHContributions/" + erg_dir;
      cinput_common += user_folder[folder] + "/";
      TString cinput = cinput_common + INPUT_NAME;
      TFile* finput = new TFile(cinput, "read");
      if (finput->IsZombie()){
        delete finput;
        continue;
      }
      else if (finput==0) continue;

      cout << "Opened file " << finput->GetName() << endl;
      for (int tr=0; tr<kNumTemplates; tr++){
        TString templatename = "VBF_";
        templatename += templatenames[tr];

        TH1F* hVBF_onshell_LC_temp = (TH1F*)finput->Get(Form("%s_onshell_LC", templatename.Data()));
        TH1F* hVBF_offshell_LC_temp = (TH1F*)finput->Get(Form("%s_offshell_LC", templatename.Data()));
        TH1F* hVBF_onshell_scaled_temp = (TH1F*)finput->Get(Form("%s_onshell_scaled", templatename.Data()));
        TH1F* hVBF_offshell_scaled_temp = (TH1F*)finput->Get(Form("%s_offshell_scaled", templatename.Data()));
        TH1F* hVBF_onshell_scaled_wVBF_temp = (TH1F*)finput->Get(Form("%s_onshell_scaled_wVBF", templatename.Data()));
        TH1F* hVBF_offshell_scaled_wVBF_temp = (TH1F*)finput->Get(Form("%s_offshell_scaled_wVBF", templatename.Data()));

        foutput->cd();
        gStyle->SetOptStat(0);
        if (hVBF_onshell_LC[tr]==0) hVBF_onshell_LC[tr] = (TH1F*)hVBF_onshell_LC_temp->Clone(Form("%s_clone", hVBF_onshell_LC_temp->GetName()));
        else hVBF_onshell_LC[tr]->Add(hVBF_onshell_LC_temp);
        delete hVBF_onshell_LC_temp;

        if (hVBF_onshell_scaled[tr]==0) hVBF_onshell_scaled[tr] = (TH1F*)hVBF_onshell_scaled_temp->Clone(Form("%s_clone", hVBF_onshell_scaled_temp->GetName()));
        else hVBF_onshell_scaled[tr]->Add(hVBF_onshell_scaled_temp);
        delete hVBF_onshell_scaled_temp;

        if (hVBF_onshell_scaled_wVBF[tr]==0) hVBF_onshell_scaled_wVBF[tr] = (TH1F*)hVBF_onshell_scaled_wVBF_temp->Clone(Form("%s_clone", hVBF_onshell_scaled_wVBF_temp->GetName()));
        else hVBF_onshell_scaled_wVBF[tr]->Add(hVBF_onshell_scaled_wVBF_temp);
        delete hVBF_onshell_scaled_wVBF_temp;

        if (hVBF_offshell_LC[tr]==0) hVBF_offshell_LC[tr] = (TH1F*)hVBF_offshell_LC_temp->Clone(Form("%s_clone", hVBF_offshell_LC_temp->GetName()));
        else hVBF_offshell_LC[tr]->Add(hVBF_offshell_LC_temp);
        delete hVBF_offshell_LC_temp;

        if (hVBF_offshell_scaled[tr]==0) hVBF_offshell_scaled[tr] = (TH1F*)hVBF_offshell_scaled_temp->Clone(Form("%s_clone", hVBF_offshell_scaled_temp->GetName()));
        else hVBF_offshell_scaled[tr]->Add(hVBF_offshell_scaled_temp);
        delete hVBF_offshell_scaled_temp;

        if (hVBF_offshell_scaled_wVBF[tr]==0) hVBF_offshell_scaled_wVBF[tr] = (TH1F*)hVBF_offshell_scaled_wVBF_temp->Clone(Form("%s_clone", hVBF_offshell_scaled_wVBF_temp->GetName()));
        else hVBF_offshell_scaled_wVBF[tr]->Add(hVBF_offshell_scaled_wVBF_temp);
        delete hVBF_offshell_scaled_wVBF_temp;
      }
      finput->Close();
    }
  }

  TH1F* hVBF_sig[2][3]={
    { hVBF_onshell_LC[0], hVBF_onshell_scaled[0], hVBF_onshell_scaled_wVBF[0] },
    { hVBF_offshell_LC[0], hVBF_offshell_scaled[0], hVBF_offshell_scaled_wVBF[0] }
  };
  TH1F* hVBF_bkg[2][3]={
    { hVBF_onshell_LC[1], hVBF_onshell_scaled[1], hVBF_onshell_scaled_wVBF[1] },
    { hVBF_offshell_LC[1], hVBF_offshell_scaled[1], hVBF_offshell_scaled_wVBF[1] }
  };
  TH1F* hVBF_int[2][3]={
    { hVBF_onshell_LC[2], hVBF_onshell_scaled[2], hVBF_onshell_scaled_wVBF[2] },
//.........这里部分代码省略.........
开发者ID:usarica,项目名称:HiggsWidth_PostICHEP,代码行数:101,代码来源:getLeptonicVHWeights_GenLevel.c

示例2: ZinvVisualization


//.........这里部分代码省略.........
		histos[mapname]->SetBinContent(1, 16.86); histos[mapname]->SetBinError(1,sqrt(pow( 1.14,2)+pow( 3.89,2)));
		histos[mapname]->SetBinContent(2, 15.66); histos[mapname]->SetBinError(2,sqrt(pow( 1.16,2)+pow( 3.62,2)));
		histos[mapname]->SetBinContent(3, 16.99); histos[mapname]->SetBinError(3,sqrt(pow( 1.18,2)+pow( 3.92,2)));
		histos[mapname]->SetBinContent(4, 13.70); histos[mapname]->SetBinError(4,sqrt(pow( 1.13,2)+pow( 3.17,2)));
		histos[mapname]->SetBinContent(5,  8.91); histos[mapname]->SetBinError(5,sqrt(pow( 0.89,2)+pow( 2.87,2)));
		histos[mapname]->SetBinContent(6,  2.27); histos[mapname]->SetBinError(6,sqrt(pow( 0.45,2)+pow( 0.73,2)));
	   } if(i3==1&&i2==6){//mHT,6j,1b
		histos[mapname]->SetBinContent(1,  2.41); histos[mapname]->SetBinError(1,sqrt(pow( 0.70,2)+pow( 1.39,2)));
		histos[mapname]->SetBinContent(2,  1.55); histos[mapname]->SetBinError(2,sqrt(pow( 0.52,2)+pow( 0.89,2)));
		histos[mapname]->SetBinContent(3,  1.11); histos[mapname]->SetBinError(3,sqrt(pow( 0.45,2)+pow( 0.64,2)));
		histos[mapname]->SetBinContent(4,  0.85); histos[mapname]->SetBinError(4,sqrt(pow( 0.42,2)+pow( 0.53,2)));
	   } if(i3==2&&i2==1){//hHT,2j,1b
		histos[mapname]->SetBinContent(1,  2.69); histos[mapname]->SetBinError(1,sqrt(pow( 0.31,2)+pow( 1.80,2)));
		histos[mapname]->SetBinContent(2,  2.25); histos[mapname]->SetBinError(2,sqrt(pow( 0.31,2)+pow( 1.51,2)));
	   } if(i3==2&&i2==3){//hHT,35j,1b
		histos[mapname]->SetBinContent(1,  2.16); histos[mapname]->SetBinError(1,sqrt(pow( 0.41,2)+pow( 0.61,2)));
		histos[mapname]->SetBinContent(2,  2.40); histos[mapname]->SetBinError(2,sqrt(pow( 0.43,2)+pow( 0.67,2)));
		histos[mapname]->SetBinContent(3,  2.57); histos[mapname]->SetBinError(3,sqrt(pow( 0.49,2)+pow( 0.72,2)));
		histos[mapname]->SetBinContent(4,  1.70); histos[mapname]->SetBinError(4,sqrt(pow( 0.40,2)+pow( 0.61,2)));
	   } if(i3==2&&i2==6){//hHT,6j,1b
		histos[mapname]->SetBinContent(1,  1.06); histos[mapname]->SetBinError(1,sqrt(pow( 0.44,2)+pow( 0.84,2)));
		histos[mapname]->SetBinContent(2,  0.92); histos[mapname]->SetBinError(2,sqrt(pow( 0.53,2)+pow( 0.73,2)));
	//	histos[mapname]->SetBinContent(3,); histos[mapname]->SetBinError(3,sqrt(pow(,2)+pow(,2)));
	   }
	}}

	cout << "Saving." << endl;
    	TFile *fsavefile = new TFile("../Results/Filtered/GammaJetsPrediction/20130617_test/ZinvPredictionNumbers.root","RECREATE");
	fsavefile->cd();
	for(map<string,TH1D*>::iterator h=histos.begin(); h!=histos.end();++h){
		h->second->Write();
	}
	fsavefile->Close();
	cout << "Saved histograms in " << fsavefile->GetName() << endl;

	//make the plots - not TDR style
    TLatex TitleBox;
	TitleBox.SetNDC();
    TitleBox.SetNDC();
    TitleBox.SetTextAlign(12);
    TitleBox.SetTextFont(42);
    TitleBox.SetTextSize(0.04219409);
    TitleBox.SetLineWidth(2);
	TString text;
    string outname;
    double max = 0.;
    double max1,max2;
    string outputdir = "../Results/Filtered/GammaJetsPrediction/20130617_test/ZinvPredictionPlots/";
    	Util::MakeOutputDir(outputdir);

   TCanvas *c1 = new TCanvas("c1", "c1",485,220,700,504);
   c1->Range(82.71719,-0.4425771,532.9945,2.212885);
    c1->SetFillColor(0);
    c1->SetBorderMode(0);
    c1->SetBorderSize(2);
   c1->SetLeftMargin(0.1494253);
   c1->SetRightMargin(0.07327586);
   c1->SetTopMargin(0.08016878);
   c1->SetBottomMargin(0.1666667);
    c1->SetFrameBorderMode(0);
    c1->SetFrameBorderMode(0);
	for(int i3 = 0; i3<HTbinsize;        ++i3){
	for(int i2 = 0; i2<signalregionsize; ++i2){
	   string hs = string("_") + HT_bin[i3] + string("_") + signal_region[i2];// + string("_") + sample_type[i1];
	   string mapname   = "MT2pred"  + hs;
	   string mapnameMC = "MT2truth" + hs;
开发者ID:MT2Analysis,项目名称:MT2Analysis,代码行数:67,代码来源:ZinvVisualization.C

示例3: main


//.........这里部分代码省略.........
   // ---------------------------------------------------------------

   std::cout << std::endl;
   std::cout << "==> Start TMVAClassification" << std::endl;

   // Create a new root output file.
   TString outfileName( "TMVA_output.root" );
   TFile* outputFile = TFile::Open( outfileName, "RECREATE" );

   TMVA::Factory *factory = new TMVA::Factory( "TMVAClassification", outputFile, 
                                               "!V:!Silent:Color:DrawProgressBar:Transformations=I;D;P;G,D" );

    // Add the variables you want to consider 
    
    //factory->AddVariable( "MT := MT",  'F' );
    //factory->AddVariable( "nJets := nJets",  'F' );
    factory->AddVariable( "MET := MET",                   'F' );
    factory->AddVariable( "MT2W := MT2W",                 'F' );
    factory->AddVariable( "dPhiMETjet := dPhiMETjet",     'F' );
    factory->AddVariable( "HTratio := HTratio",           'F' );
    factory->AddVariable( "HadronicChi2 := HadronicChi2", 'F' );
    factory->AddVariable( "nWTag := nWTag",               'I' );
    
    // Open samples
    
    TFile* f_signal = TFile::Open((string(MICROTUPLES_FOLDER)+"signal.root").c_str());
    TFile* f_ttbar  = TFile::Open((string(MICROTUPLES_FOLDER)+"ttbar.root" ).c_str());
    //TFile* f_W2Jets = TFile::Open((string(MICROTUPLES_FOLDER)+"W2Jets.root").c_str());
    //TFile* f_W3Jets = TFile::Open((string(MICROTUPLES_FOLDER)+"W3Jets.root").c_str());
    //TFile* f_W4Jets = TFile::Open((string(MICROTUPLES_FOLDER)+"W4Jets.root").c_str());
    
    TTree* signal = (TTree*) f_signal->Get("microTuple");
    TTree* ttbar  = (TTree*) f_ttbar ->Get("microTuple");
    //TTree* W2Jets = (TTree*) f_W2Jets->Get("microTuple");
    //TTree* W3Jets = (TTree*) f_W3Jets->Get("microTuple");
    //TTree* W4Jets = (TTree*) f_W4Jets->Get("microTuple");

    // Register the trees

//    float weightSignal     = 1.0   * 20000.0 / getNumberOfEvent(signal);
//    float weightBackground = 225.2 * 20000.0 / getNumberOfEvent(ttbar);
    float weightSignal     = 1.0;
    float weightBackground = 1.0;

    factory->AddSignalTree    ( signal, weightSignal    );
    factory->AddBackgroundTree( ttbar,  weightBackground);

    /*
    cout << " signal ; w = " << 1.0   * 20000.0 / getNumberOfEvent(signal) << endl;
    factory->AddSignalTree    ( signal, 1.0   * 20000.0 / getNumberOfEvent(signal));
    cout << " ttbar ; w = "  << 225.2 * 20000.0 / getNumberOfEvent(ttbar) << endl;
    factory->AddBackgroundTree( ttbar,  234.0 * 20000.0 / getNumberOfEvent(ttbar));
    cout << " W2Jets ; w = " << 2159  * 20000.0 / getNumberOfEvent(W2Jets) << endl;
    factory->AddBackgroundTree( W2Jets, 2159  * 20000.0 / getNumberOfEvent(W2Jets));
    cout << " W3Jets ; w = " << 640   * 20000.0 / getNumberOfEvent(W3Jets) << endl;
    factory->AddBackgroundTree( W3Jets, 640   * 20000.0 / getNumberOfEvent(W3Jets));
    cout << " W4Jets ; w = " << 264   * 20000.0 / getNumberOfEvent(W4Jets) << endl;
    factory->AddBackgroundTree( W4Jets, 264   * 20000.0 / getNumberOfEvent(W4Jets));
    */

    // Add preselection cuts
   
    std::string preselectionCutsSig("nJets > 4 && MET > 80 && MT > 100");
    std::string preselectionCutsBkg("nJets > 4 && MET > 80 && MT > 100");

    // Prepare the training

    factory->PrepareTrainingAndTestTree( preselectionCutsSig.c_str(), preselectionCutsBkg.c_str(),
                    "nTrain_Signal=40000:nTrain_Background=300000:nTest_Signal=40000:nTest_Background=300000:SplitMode=Random:NormMode=EqualNumEvents:!V" );

    // Cut optimisation
    //if (Use["Cuts"])     factory->BookMethod( TMVA::Types::kCuts, "Cuts",
    //                     "!H:!V:FitMethod=MC:EffSel:SampleSize=200000:VarProp=FSmart" );
    if (Use["BDT"])      factory->BookMethod( TMVA::Types::kBDT, "BDT", 
                         "!H:!V:NTrees=400:nEventsMin=400:MaxDepth=3:BoostType=AdaBoost:SeparationType=GiniIndex:nCuts=20:PruneMethod=NoPruning");
   
   // --------------------------------------------------------------

   // Train MVAs using the set of training events
   factory->TrainAllMethodsForClassification();

   // Evaluate all MVAs using the set of test events
   factory->TestAllMethods();

   // Evaluate and compare performance of all configured MVAs
   factory->EvaluateAllMethods();    

   // --------------------------------------------------------------
   
   // Save the output
   outputFile->Close();

   std::cout << "==> Wrote root file: " << outputFile->GetName() << std::endl;
   std::cout << "==> TMVAClassification is done!" << std::endl;      

   delete factory;

   // Launch the GUI for the root macros
   //if (!gROOT->IsBatch()) TMVAGui( outfileName );
}
开发者ID:jgomezca,项目名称:combinedOneLeptonStopAnalysis,代码行数:101,代码来源:trainMVA_AdaBoost.C

示例4: createCorrectedBackgroundModel

void createCorrectedBackgroundModel(std::string fileName, int nsidebands=6, bool makePlots=false, std::string defaultPrepend="CMS-HGG" ){

     if (makePlots){
       system("mkdir -p BMplots/ada");
       system("mkdir -p BMplots/grad");
       gStyle->SetPalette(1);
       gStyle->SetOptStat(0);
     }

     global_nMassBins=nsidebands;

     double massMin = 120;
     double massMax = 130;
     double dM  = 0.1;
	
     // Open the original Workspace
     TFile *in = TFile::Open(fileName.c_str(),"UPDATE");
     RooWorkspace *work = (RooWorkspace*)in->Get("cms_hgg_workspace");
 
     std::string types[2]={"grad","ada"};

     for (int ty=0;ty<2;ty++){

	std::string type = types[ty];
	// Create An output file for the TF1 Sideband Fits
  	std::string pathToFile=fileName.substr(0,fileName.find(defaultPrepend.c_str()));
 	std::string fName=fileName.substr(fileName.find(defaultPrepend.c_str()),fileName.size());
	TFile *out = new TFile(Form("%sbdtSidebandFits_%s_%s",pathToFile.c_str(),type.c_str(),fName.c_str()),"RECREATE");
	for (double mH=massMin;mH<=massMax;mH+=dM){

		//TH1F *originalHist      = (TH1F*) in->Get(Form("th1f_bkg_%s_%3.1f_cat0",type.c_str(),mH)); // This histogram is normalized to the inclusive fit (will not include VBF cat)
		RooRealVar *nSignalVar = (RooRealVar*)work->var(Form("NBkgInSignal_mH%3.1f",mH));
		TH1F *dataHist  = (TH1F*) in->Get(Form("th1f_data_%s_%3.1f_cat0",type.c_str(),mH)); // Data Histogram, includes VBF category
		int nBins = dataHist->GetNbinsX();

		// Want to make a "corrected" histogram 
		TH1F *correctedHist = new TH1F(Form("th1f_bkg_%s_%3.1f_cat0_fitsb_biascorr",type.c_str(),mH),Form("th1f_bkg_%s_%3.1f_cat0_fitsb_biascorr",type.c_str(),mH),nBins,0,nBins);		     
		TH1F *correctedHistFR = new TH1F(Form("th1f_bkg_%s_%3.1f_cat0_fitsb_biascorr_frac",type.c_str(),mH),Form("th1f_bkg_%s_%3.1f_cat0_fitsb_biascorr_frac",type.c_str(),mH),nBins,0,nBins);		     
      	        TH2F *hFCovar=new TH2F(Form("fCovar_%3.1f",mH),
			 Form("Fraction covariance matrix m %3.1f",mH),
			 nBins,0.0,nBins,nBins,0.0,nBins);
		TH2F *uCorrErr = new TH2F(Form("fUncorrErr_%s_%3.1f",type.c_str(),mH),
			 Form("Uncorrelated Errors m %3.1f",mH),
			 nBins,0.0,nBins,nBins,0.0,nBins);
	
		TDirectory *mass_dir = out->mkdir(Form("mH_%3.1f",mH));

		// For a given mass point, need to set up globals
		global_nBdtBins=nBins;		
		global_mH=mH;
		global_nSignalRegion=nSignalVar->getVal();

		fillData(mH,in,type);
		paulFit(mass_dir,correctedHistFR,correctedHist,hFCovar,makePlots,type);
		
		// Finally Get the uncorrleated errors from the covariance matrix
		diagonalizeMatrix(hFCovar,uCorrErr);

		std::cout << "Final Check of Normalizations at mH="<<mH <<std::endl;
		std::cout << "Original - "<< global_nSignalRegion <<  ", After - " <<correctedHist->Integral() <<std::endl;
		
		// Write out the Hists into the original File
		in->cd();
		correctedHist->Write(correctedHist->GetName(),TObject::kOverwrite);
		correctedHistFR->Write(correctedHistFR->GetName(),TObject::kOverwrite);
		//hFCovar->Write();
		uCorrErr->Write(uCorrErr->GetName(),TObject::kOverwrite);
    out->cd();
    mass_dir->cd();
    uCorrErr->Write(uCorrErr->GetName(),TObject::kOverwrite);

    if (makePlots){
      TCanvas *canv = new TCanvas();
      uCorrErr->SetMarkerColor(kGray);
      gPad->SetRightMargin(2.);
      uCorrErr->Draw("colz text");
      canv->Print(Form("BMplots/%s/uncorrErr_m%3.1f.png",type.c_str(),mH));
      canv->Print(Form("BMplots/%s/uncorrErr_m%3.1f.pdf",type.c_str(),mH));
    }
	}
	std::cout << "Saving Fits to file -> " << out->GetName() << std::endl;
        out->Close();
     }
    
    std::cout << "Updated (with corrected background model) -> " << in->GetName() << std::endl;
    in->Close();
}
开发者ID:ArnabPurohit,项目名称:h2gglobe,代码行数:87,代码来源:createCorrectedBackgroundModel.C

示例5: combinePreFullTests

void combinePreFullTests( string rootFullName, string rootPreTest, string rootOutputName)
{

  // open output file 
  TFile *_fileSave = TFile::Open( rootOutputName.c_str(), "new" );
  // open existing files
  TFile * fileFullTest = TFile::Open( rootFullName.c_str(),"read" );  
  TFile * filePreTest = TFile::Open( rootPreTest.c_str(),"read" );

  fileFullTest->cd();
  if( ! fileFullTest ) continue;
  
  TIter nextkey( gDirectory->GetListOfKeys() );
  TKey * key;

  cout << "Copy Subdirectory/histograms from " << fileFullTest->GetName() << endl;
  cout << "into the file: " << _fileSave->GetName() << endl;

  while( ( key = (TKey*)nextkey() ) ) {
    
    TObject * obj = key->ReadObj();
    if (obj->IsA()->InheritsFrom( "TDirectory" )){
      cout << "----- Subdir " << obj->GetName() <<  "  " << obj->GetUniqueID() << endl;
      // create same structure
      _fileSave->mkdir(obj->GetName());
      
      // loop over all histograms in subdirectory
      fileFullTest->cd(obj->GetName());
      TIter nextkey2( gDirectory->GetListOfKeys() );
      TKey * key2;
       
      string objName = obj->GetName(); 
      if (objName.substr(0,3) == "BB2"){
	cout << "for Subdirectory BB2 in file " << fileFullTest->GetName() << " do nothing"  << endl;
      }
      else{
	while( ( key2 = (TKey*)nextkey2() ) ) {
	  _fileSave->cd();	
	  TObject * obj2 = key2->ReadObj();
	  
	  if( obj2->IsA()->InheritsFrom( "TH2D" )) {
	    //cout << "2d histograms " << obj2->GetName() << endl;
	    TH2D * h2 = (TH2D*)obj2;	  
	    _fileSave->cd(obj->GetName());
	    h2->Write();	  
	  }
	  else if ( obj2->IsA()->InheritsFrom( "TH1D" )) {	  
	    //cout << "1d histograms " << obj2->GetName() << endl;
	    TH1D * h1 = (TH1D*)obj2;
	    _fileSave->cd(obj->GetName());
	    h1->Write();	  
	  }	
	}
      } // do not save BB2 from Fulltest but from next file
      // here please save BB2 to final file

    }
    else{
      // store Histograms which are not in a subdirectory HA and HD
      _fileSave->cd();
      if ( obj->IsA()->InheritsFrom( "TH1D" )) {	  
	//cout << "1d histograms " << obj->GetName() << endl;
	TH1D * h1 = (TH1D*)obj;
	_fileSave->cd();
	h1->Write();	  
      }	
      //cout << obj->GetName() <<  " this is a histogram " << endl;
    }

  }

  // Now use BB2 from Pretest and store it in the outputfile _fileSave

  if( ! filePreTest ) continue;

  filePreTest->cd();
  filePreTest->cd("BB2");
  cout << "copy BB2 histograms from file " << filePreTest->GetName() << " into " << _fileSave->GetName() << endl;
 
  TIter nextkey3( gDirectory->GetListOfKeys() );
  TKey * key3;
  while( ( key3 = (TKey*)nextkey3() ) ) {    
    TObject * obj3 = key3->ReadObj();
    if( obj3->IsA()->InheritsFrom( "TH2D" )) {
      //cout << "2d histograms " << obj3->GetName() << endl;
      TH2D * h2 = (TH2D*)obj3;	  
      _fileSave->cd("BB2");
      h2->Write();	  
    }
    else if ( obj3->IsA()->InheritsFrom( "TH1D" )) {	  
      //cout << "1d histograms " << obj3->GetName() << endl;
      TH1D * h1 = (TH1D*)obj3;
      _fileSave->cd("BB2");
      h1->Write();	  
    }
    //cout << "----- " << obj3->GetName() << endl;
  }


  fileFullTest->Close();
//.........这里部分代码省略.........
开发者ID:chrisjcc,项目名称:PixelScripts,代码行数:101,代码来源:combinePreFullTests.C

示例6: Ana

int Ana(const char *filename, const char* outdir, TFile *fileout)
{
  //TFile *file = new TFile("mc_KPI_22324.root");
  TFile *file;
  if (filename==0) file= new TFile("KK_22324.root");
  else file = new TFile(filename);
  std::cout<<"File name is "<<file->GetName()<<std::endl;
  if (file==0) return -1;
  TTree *tree = (TTree*)file->Get("TwoProng");
  if (tree==0) return -2;

  double ene[22];
  double pcut[22];
  double epcut[22];
  double thecut[22];
  double m_pcut;
  double m_epcut;
  double m_thecut;
  ifstream cutin("cutpar");
  char line[1000];
  if (cutin.is_open()) cutin.getline(line,1000);
  int iene=0;
  // set E/p and p cut, mark: set cut
  while (!cutin.eof()){
    cutin.getline(line,1000);
    istringstream iss;
    iss.str(line);
    iss>>ene[iene]>>pcut[iene]>>epcut[iene];
    iene++;
    if (iene==22) break;
  }
  for (int i=0;i<22;i++) epcut[i] = 1.64295 - 0.629622*ene[i] + 0.104755 *pow(ene[i],2);
  //for (int i=0;i<21;i++) thecut[i] = 173.946 + 1.74736*ene[i];
  for (int i=0;i<22;i++) thecut[i] = 179;

  double kappx,kappy,kappz,kampx,kampy,kampz;
  int nneu;
  int run;
  int idxmc;
  int pdgid[100];
  int motheridx[100];
  int emcstatusInt;
  short emcstatusShort;
  double emctrk1;
  double emctrk2;
  double epratio1;
  double epratio2;
  int ntof1;
  int ntof2;
  int tofl1[5];
  int tofl2[5];
  double tof1[5];
  double tof2[5];
  tree->SetBranchAddress("run",&run);
  tree->SetBranchAddress("indexmc",&idxmc);
  tree->SetBranchAddress("pdgid",pdgid);
  tree->SetBranchAddress("motheridx",motheridx);
  tree->SetBranchAddress("kappx",&kappx);
  tree->SetBranchAddress("kappy",&kappy);
  tree->SetBranchAddress("kappz",&kappz);
  tree->SetBranchAddress("kampx",&kampx);
  tree->SetBranchAddress("kampy",&kampy);
  tree->SetBranchAddress("kampz",&kampz);
  //tree->SetBranchAddress("costheta",&costheta);
  tree->SetBranchAddress("nneu",&nneu);
  if (strncmp(tree->GetBranch("emcstatus")->GetLeaf("emcstatus")->GetTypeName(),"Short_t",7)==0)
  	tree->SetBranchAddress("emcstatus",&emcstatusShort);
  else 
  	tree->SetBranchAddress("emcstatus",&emcstatusInt);
  tree->SetBranchAddress("epratio1",&epratio1);
  tree->SetBranchAddress("epratio2",&epratio2);
  tree->SetBranchAddress("emctrk1",&emctrk1);
  tree->SetBranchAddress("emctrk2",&emctrk2);
  tree->SetBranchAddress("ntof1",&ntof1);
  tree->SetBranchAddress("toflayer1",tofl1);
  tree->SetBranchAddress("tof1",tof1);
  tree->SetBranchAddress("ntof2",&ntof2);
  tree->SetBranchAddress("toflayer2",tofl2);
  tree->SetBranchAddress("tof2",tof2);
  double pi = TMath::Pi();
  double mka = 0.493677;
  //double mka = 0.13957;
  //double mka = 0.1057;
  

  tree->GetEntry(0);
  double Ebeam = GetEnergy(run);
  if (Ebeam<1.0) Ebeam = getEne(filename);
  //Ebeam = 3.08;

  for (int iene=0;iene<22;iene++){
    if (fabs(Ebeam-ene[iene])<1e-4) {
      m_pcut = pcut[iene];
      m_epcut = epcut[iene];
      m_thecut = thecut[iene];
      break;
    }
  }
  //m_epcut = m_epcut +0.05; // change E/p to determine uncertainty from this cut
  //m_thecut = 179+0.2; // uncertainty from theta cut
//.........这里部分代码省略.........
开发者ID:dannielliu,项目名称:KKcross,代码行数:101,代码来源:anaTrack.C

示例7: RunEbyEFlowAnalysisFWLite


//.........这里部分代码省略.........
    cerr << "Could not retrieve fileset: " << gFilesetname << endl;
    return;
  }

  vector<string> fileNames = GetDataVector(files,gFfrom,gFto);
  fwlite::ChainEvent event(fileNames);  

  //Initialize the analyzer      
  EbyEFlowAnalyzerFWLite* corr = new EbyEFlowAnalyzerFWLite(event);
  corr->SetCutParameters(gCut);

  TString strtrgid = "Track";
  if(gSystem->Getenv("TRGID")) strtrgid = gSystem->Getenv("TRGID");
  DiHadronCorrelationMultiBaseFWLite::ParticleType gTrgID = corr->GetParticleID(strtrgid);
  TString strassid = "Track";
  if(gSystem->Getenv("ASSID")) strassid = gSystem->Getenv("ASSID");
  DiHadronCorrelationMultiBaseFWLite::ParticleType gAssID = corr->GetParticleID(strassid);
  corr->SetTrgID(gTrgID);
  corr->SetAssID(gAssID);

  if(gCentfilename.Contains("root"))
  {
    cout<<"Running correlation analysis in Heavy Ion!"<<endl;
    TFile* fcentfile = new TFile(gCentfilename.Data());
    if(fcentfile->IsOpen()) corr->SetCentrality(fcentfile,gCenttablename,gNCentBins,gCentRunnum);
    else cout<<"Centrality table cannot be opened!"<<endl;
  }
  else cout<<"Running correlation analysis in pp!"<<endl;

  if(gEffhistname.Contains("root"))
  {
    TFile* feffhist = new TFile(gEffhistname.Data());    
    if(feffhist->IsOpen())
    {
      TH3D* htotaleff = 0;
      if(!gCut.IsHI) htotaleff = (TH3D*)feffhist->Get("rTotalEff3D");
      else
      {
        int histcentbin = -1;
        if((gCut.centmin>=0 && gCut.centmax<=2) || gCut.centmin>=50) histcentbin = 0;
        if(gCut.centmin>=2 && gCut.centmax<=4) histcentbin = 1;
        if(gCut.centmin>=4 && gCut.centmax<=12) histcentbin = 2;
        if(gCut.centmin>=12 && gCut.centmax<=20) histcentbin = 3;
        if(gCut.centmin>=20 && gCut.centmax<=40) histcentbin = 4;
        if(gCut.centmin==-1 && gCut.centmax==-1) histcentbin = 4;

        htotaleff = (TH3D*)feffhist->Get(Form("Tot_%d",histcentbin));
      }
      corr->LoadEffWeight(htotaleff);
      cout<<"Tracking efficiency weighting histogram is loaded!"<<endl;
    }
    else cout<<"Tracking efficiency weighting file cannot be opened!"<<endl;
  }
  else cout<<"No Tracking efficiency weighting histogram is found, or it's running MC!"<<endl;

  if(gTrghistname.Contains("root"))
  {
    TFile* ftrghist = new TFile(gTrghistname.Data());
    if(ftrghist->IsOpen())
    {
      corr->LoadTrgWeight((TH1D*)ftrghist->Get("trgEff"));
      cout<<"Triggering efficiency weighting histogram is loaded!"<<endl;
    }
    else cout<<"Triggering efficiency weighting file cannot be opened!"<<endl;
  }
  else cout<<"No Triggering efficiency weighting histogram is found, or it's running MC!"<<endl;

  if(gPileupdistfunchistname.Contains("root"))
  {
    TFile* fpileupdistfunchist = new TFile(gPileupdistfunchistname.Data());
    if(fpileupdistfunchist->IsOpen())
    {
      corr->LoadPileUpDistFunc((TH1D*)fpileupdistfunchist->Get("distfunc"));
      cout<<"Pileup distfunc histogram is loaded!"<<endl;
    }
    else cout<<"Pileup distfunc file cannot be opened!"<<endl;
  }

  corr->Process();

  // open output file
  TString outputfilename = Form("%s/%s/unmerged/%s_%s_ffrom%d_fto%d_vtxmin%.1f_vtxmax%.1f_nmin%d_nmax%d_etatrg%.1f-%.1f_etaass%.1f-%.1f_centmin%d_centmax%d.root",gOutputDir.Data(),gEventtype.Data(),gEventtype.Data(),gTag.Data(),gFfrom,gFto,gCut.zvtxmin,gCut.zvtxmax,gCut.nmin,gCut.nmax,gCut.etatrgmin,gCut.etatrgmax,gCut.etaassmin,gCut.etaassmax,gCut.centmin,gCut.centmax);
  TFile* outf = new TFile(outputfilename.Data(),"recreate");

  // Save the outputs
  TList* output = corr->GetOutputs();
  if(outf && output) {
    outf->cd();
    output->Write();
    cout << "Output file " <<  outf->GetName()
    << " written: " << endl;
    outf->ls();
    outf->Close();
    if(outf) delete outf;
  }  
  delete output;

  watch->Stop();
  watch->Print();
}
开发者ID:SangeonPark,项目名称:RiceHIG,代码行数:101,代码来源:RunEbyEFlowAnalysisFWLite.C

示例8: TMVAClassification


//.........这里部分代码省略.........
      TFile *input_F_ZH145 = TFile::Open( fname_F_ZH145 );

      TFile *input_SingleTbar_s = TFile::Open( fname_SingleTbar_s );

      TFile *input_WJetsToLNu = TFile::Open( fname_WJetsToLNu );

      TFile *input_Data7TeV_DoubleElectron2011A_1 = TFile::Open( fname_Data7TeV_DoubleElectron2011A_1 );

      TFile *input_F_ZH125 = TFile::Open( fname_F_ZH125 );

      TFile *input_ZZ = TFile::Open( fname_ZZ );

      TFile *input_Data7TeV_MuEG2011B_1 = TFile::Open( fname_Data7TeV_MuEG2011B_1 );

      TFile *input_F_ZH135 = TFile::Open( fname_F_ZH135 );

      TFile *input_WW = TFile::Open( fname_WW );

      TFile *input_Data7TeV_DoubleMu2011A_0 = TFile::Open( fname_Data7TeV_DoubleMu2011A_0 );

      TFile *input_SingleTbar_tW = TFile::Open( fname_SingleTbar_tW );

      TFile *input_WZ = TFile::Open( fname_WZ );

      TFile *input_Data7TeV_MuEG2011A_0 = TFile::Open( fname_Data7TeV_MuEG2011A_0 );

      TFile *input_Data7TeV_DoubleMu2011B_1 = TFile::Open( fname_Data7TeV_DoubleMu2011B_1 );

      TFile *input_F_ZH115 = TFile::Open( fname_F_ZH115 );

      TFile *input_SingleT_t = TFile::Open( fname_SingleT_t );


      std::cout << "--- TMVAClassification       : Using input_Data7TeV_DoubleElectron2011B_0 file: " << input_Data7TeV_DoubleElectron2011B_0->GetName() << std::endl;

      std::cout << "--- TMVAClassification       : Using input_Data7TeV_MuEG2011B_0 file: " << input_Data7TeV_MuEG2011B_0->GetName() << std::endl;

      std::cout << "--- TMVAClassification       : Using input_SingleT_tW file: " << input_SingleT_tW->GetName() << std::endl;

      std::cout << "--- TMVAClassification       : Using input_SingleT_s file: " << input_SingleT_s->GetName() << std::endl;

      std::cout << "--- TMVAClassification       : Using input_Data7TeV_DoubleMu2011B_0 file: " << input_Data7TeV_DoubleMu2011B_0->GetName() << std::endl;

      std::cout << "--- TMVAClassification       : Using input_F_ZH150 file: " << input_F_ZH150->GetName() << std::endl;

      std::cout << "--- TMVAClassification       : Using input_F_ZH105 file: " << input_F_ZH105->GetName() << std::endl;

      std::cout << "--- TMVAClassification       : Using input_Data7TeV_DoubleElectron2011A_0 file: " << input_Data7TeV_DoubleElectron2011A_0->GetName() << std::endl;

      std::cout << "--- TMVAClassification       : Using input_DYJetsToLL file: " << input_DYJetsToLL->GetName() << std::endl;

      std::cout << "--- TMVAClassification       : Using input_SingleTbar_t file: " << input_SingleTbar_t->GetName() << std::endl;

      std::cout << "--- TMVAClassification       : Using input_Data7TeV_DoubleElectron2011B_1 file: " << input_Data7TeV_DoubleElectron2011B_1->GetName() << std::endl;

      std::cout << "--- TMVAClassification       : Using input_Data7TeV_DoubleMu2011A_1 file: " << input_Data7TeV_DoubleMu2011A_1->GetName() << std::endl;

      std::cout << "--- TMVAClassification       : Using input_Data7TeV_MuEG2011A_1 file: " << input_Data7TeV_MuEG2011A_1->GetName() << std::endl;

      std::cout << "--- TMVAClassification       : Using input_TTJets file: " << input_TTJets->GetName() << std::endl;

      std::cout << "--- TMVAClassification       : Using input_F_ZH145 file: " << input_F_ZH145->GetName() << std::endl;

      std::cout << "--- TMVAClassification       : Using input_SingleTbar_s file: " << input_SingleTbar_s->GetName() << std::endl;

      std::cout << "--- TMVAClassification       : Using input_WJetsToLNu file: " << input_WJetsToLNu->GetName() << std::endl;
开发者ID:beknapp,项目名称:usercode,代码行数:67,代码来源:TMVAClassification_F_ZH105.C

示例9: bfcread_tagsBranch

void bfcread_tagsBranch( 
  const char *MainFile="/afs/rhic.bnl.gov/star/data/samples/gstar.tags.root",
  Int_t printEvent=1,
  const char *fname="qa_tags.out",
  Int_t fullPrint=0) 
{
  // start timer
  TStopwatch timer;
  timer.Start();

  cout << endl << endl;
  cout << " bfcread_tagsBranch.C: input file  = " << MainFile << endl;
  cout << " bfcread_tagsBranch.C: print event # " << printEvent << endl;
  cout << " bfcread_tagsBranch.C: output file = " << fname << endl;
  cout << " bfcread_tagsBranch.C: full printout = " << fullPrint << endl;
  cout << endl;

  ofstream fout(fname);

  fout << endl << endl;
  fout << " bfcread_tagsBranch.C: input file  = " << MainFile << endl;
  fout << " bfcread_tagsBranch.C: print evt#  = " << printEvent << endl;
  fout << " bfcread_tagsBranch.C: output file = " << fname << endl;
  fout << " bfcread_tagsBranch.C: full printout = " << fullPrint << endl;
  fout << endl;

  TFile *file = TFile::Open(MainFile);
  TTree *tree = (TTree*)file->Get("Tag");

  cout <<" read file: " << file->GetName() << endl << endl;

  Int_t nEntries = tree->GetEntries();
  cout << " Total # events  = " << nEntries << endl;

  TObjArray *leaves = tree->GetListOfLeaves();
  Int_t nLeaves = leaves->GetEntriesFast();

  cout << "  Total # leaves  = " << nLeaves << endl;

  TString *tName = new TString(" ");
  TNamed *tableName=0;
  TObjArray *tagTable = new TObjArray;
  Int_t tableCount = 0;
  Int_t *tableIndex = new Int_t[nLeaves];
  Int_t tagCount = 0;

  TBranch *branch=0;
  TLeaf *leaf=0;
  Int_t ndim =0;

//count number of tag tables encoded in the TTree branch names
  for (Int_t l=0;l<nLeaves;l++) {
    leaf = (TLeaf*)leaves->UncheckedAt(l);
    tagCount+=leaf->GetNdata();
    branch = leaf->GetBranch();
      cout << "leaf #  " << l << "  br name = " <<  
                                     branch->GetName() << endl;
    //new tag table name
    if ( strstr(branch->GetName(), tName->Data()) == 0 ) {
      tName = new TString(branch->GetName());
      tName->Resize(tName->Index("."));
      //the tableName is encoded in the branch Name before the "."
      tableName = new TNamed(tName->Data(),"Tag");
      tagTable->AddLast(tableName);
      tableCount++;
    }
    tableIndex[l]=tableCount-1;
  }

  cout << endl << "  Total num tables(branches),tags = " 
              << tableCount << "   " << tagCount << endl << endl;

  Int_t *countTagsTable = new Int_t[tableCount];
  Int_t *countLeavesTable = new Int_t[tableCount];
  Float_t *sumTagsLeaf = new Float_t[nLeaves];
  Int_t *countTagsLeaf = new Int_t[nLeaves];

// Now loop over leaves (to get values of tags)

   Int_t setBranch = -1;
   Int_t nowBranch = -1;

   for (Int_t l=0;l<nLeaves;l++) {

      leaf = (TLeaf*)leaves->UncheckedAt(l);
      branch = leaf->GetBranch();
      ndim = leaf->GetNdata();

      nowBranch = tableIndex[l];

      //cout << " nowbranch, setBranch = " << 
      //  nowBranch << ", "<< setBranch << endl;

      Float_t RtableIndex=tableIndex[l];

      if (nowBranch !=  setBranch){ 
          setBranch=nowBranch;
          cout << " QAInfo: branch ";
            cout.width(2);
            cout << tableIndex[l] << " = ";
//.........这里部分代码省略.........
开发者ID:star-bnl,项目名称:star-macros,代码行数:101,代码来源:bfcread_tagsBranch.C

示例10: writentuple_pp

int writentuple_pp(char *ksp="ppJet40")
{
    
    timer.Start();
    
    //LoadLib();
    
    TString inname="";
    if(strcmp(ksp,"ppJet40")==0)inname = "/hadoop/store/user/belt/hiForest2/PP2013_HiForest_PromptReco_JSon_Jet40Jet60_ppTrack_forestv84.root";
    else if(strcmp(ksp,"ppJet80")==0)inname = "/hadoop/store/user/belt/hiForest2/PP2013_HiForest_PromptReco_JsonPP_Jet80_PPReco_forestv82.root";
    
    //! Load Lib
    //gSystem->Load("/afs/cern.ch/user/p/pawan/scratch0/CMSSW_6_2_0/src/work/pPb/HiForest/V3/hiForest_h.so");
    
    //! Define the input file and HiForest
    //! CMSSW_5_3_3
    HiForest *c = new HiForest(inname,Form("Forest%s",ksp),cPP);
    cout<<"Loaded the hiforest tree : "<<c->GetName()<<endl;
    ShutoffBranches(c);
    
    
    DuplicateEvents dupEvt(inname);
    dupEvt.MakeList();

    //! Output file
    //! HIHighPt
    TFile *fout = new TFile(Form("ntuple_2013_%s.root",ksp),"RECREATE");
    
    std::cout<<"\t"<<std::endl;
    std::cout<<"\t"<<std::endl;
    std::cout<<"**************************************************** "<<std::endl;
    std::cout<<Form("Running for %s ",ksp)<<std::endl;
    std::cout<<Form("pT  cut for %0.3f ",kptrecocut)<<std::endl;
    std::cout<<Form("eta cut for %0.3f ",ketacut)<<std::endl;
    std::cout<<"My hiForest Tree : " <<c->GetName()<<"\t Entries "<<c->GetEntries()<<std::endl;
    std::cout<<"Output file  "<<fout->GetName()<<std::endl;
    std::cout<<"**************************************************** "<<std::endl;
    std::cout<<"\t"<<std::endl;
    std::cout<<"\t"<<std::endl;
    
    //! shut off jet trees
    //c->hasAk2CaloJetTree=0;
    //c->hasAk4CaloJetTree=0;
    //c->hasAk3CaloJetTree=0;
    //c->hasAk5CaloJetTree=0;
    
    c->hasAkPu2CaloJetTree=0;
    c->hasAkPu4CaloJetTree=0;
    c->hasAkPu3CaloJetTree=0;
    //c->hasAkPu5CaloJetTree=0;
    
    //c->hasAk2PFJetTree=0;
    //c->hasAk4PFJetTree=0;
    //c->hasAk5PFJetTree=0;
    
    //c->hasAkPu2PFJetTree=0;
    //c->hasAkPu4PFJetTree=0;
    //c->hasAkPu5PFJetTree=0;
    
    c->hasTrackTree=0;
    
    //! For jets
    Jets *mJets=0;
    Long64_t nentries = c->GetEntries();
    std::cout<<Form("# of entries in TTree for %s : ",ksp)<<nentries<<std::endl;
    
    string jetVars = "";
    jetVars += "evt:run:vz:trig:jet40:jet60:jet80:jet100:ntrk:nrefe:pt:raw:eta:phi:chMax:trkMax:chSum:phSum:neSum";
    TNtuple *ntjet=0;
    ntjet = new TNtuple("ntjet","",jetVars.data());
    
    for (Long64_t ievt=0; ievt<nentries;ievt++) {//! event loop
        //for (Long64_t ievt=0; ievt<100;ievt++) {//! event loop
        //! load the hiForest event
        c->GetEntry(ievt);
        
        if(dupEvt.occurence[ievt] == 2)continue;


        //! events with Single vertex
        bool evSel = false;
        float trig=-9;
        if(strcmp(ksp,"ppJet40")==0){
            evSel = fabs(c->evt.vz)<15. && c->skim.pHBHENoiseFilter  && c->skim.pPAcollisionEventSelectionPA && (c->hlt.HLT_PAJet40_NoJetID_v1 || c->hlt.HLT_PAJet60_NoJetID_v1);
            trig=1;
        }
        else if(strcmp(ksp,"ppJet80")==0){
            evSel = fabs(c->evt.vz)<15. && c->skim.pHBHENoiseFilter  && c->skim.pPAcollisionEventSelectionPA && (c->hlt.HLT_PAJet80_NoJetID_v1 || c->hlt.HLT_PAJet100_NoJetID_v1);
            trig=2;
        }
        if(!evSel)continue;
        
        float pt = -9,raw    = -9,eta    = -9,phi    = -9,chMax  = -9,trkMax=-9,chSum  = -9,phSum  = -9,neSum  = -9,nrefe = 0;

        
        
        float run   = c->evt.run;
        float evt   = c->evt.evt;
        float vz    = c->evt.vz;
        
//.........这里部分代码省略.........
开发者ID:rkunnawa,项目名称:usercode,代码行数:101,代码来源:writentuple_pp.C

示例11: UTMplots


//.........这里部分代码省略.........
Data->Draw("misc.MT2>>DataWVSPT40", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=40&&misc.Vectorsumpt<50","goff");
cout << "DataWVSPT50" << endl;
Data->Draw("misc.MT2>>DataWVSPT50", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=50&&misc.Vectorsumpt<70","goff");
cout << "DataWVSPT70" << endl;
Data->Draw("misc.MT2>>DataWVSPT70", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=70&&misc.Vectorsumpt<100","goff");
cout << "DataWVSPT100" << endl;
Data->Draw("misc.MT2>>DataWVSPT100","NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=100","goff");

cout << "DataWVSPT0" << endl;
Data->Draw("misc.MT2>>DataTopVSPT0",  "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM>=1&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=0&&misc.Vectorsumpt<20","goff");
cout << "DataTopVSPT20" << endl;
Data->Draw("misc.MT2>>DataTopVSPT20", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM>=1&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=20&&misc.Vectorsumpt<30","goff");
cout << "DataTopVSPT30" << endl;
Data->Draw("misc.MT2>>DataTopVSPT30", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM>=1&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=30&&misc.Vectorsumpt<40","goff");
cout << "DataTopVSPT40" << endl;
Data->Draw("misc.MT2>>DataTopVSPT40", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM>=1&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=40&&misc.Vectorsumpt<50","goff");
cout << "DataTopVSPT50" << endl;
Data->Draw("misc.MT2>>DataTopVSPT50", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM>=1&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=50&&misc.Vectorsumpt<70","goff");
cout << "DataTopVSPT70" << endl;
Data->Draw("misc.MT2>>DataTopVSPT70", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM>=1&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=70&&misc.Vectorsumpt<100","goff");
cout << "DataTopVSPT100" << endl;
Data->Draw("misc.MT2>>DataTopVSPT100","NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM>=1&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=100","goff");

TLegend *leg = new TLegend(.6,.6,.90,.90);
leg->SetName("leg");
leg -> SetFillColor(0);
leg -> SetBorderSize(0);
leg->AddEntry(LM6VSPT0,"0 #leq VSPT < 20 GeV", "l");
leg->AddEntry(LM6VSPT20,"20 #leq VSPT < 30 GeV", "l");
leg->AddEntry(LM6VSPT30,"30 #leq VSPT < 40 GeV", "l");
leg->AddEntry(LM6VSPT40,"40 #leq VSPT < 50 GeV", "l");
leg->AddEntry(LM6VSPT50,"50 #leq VSPT < 70 GeV", "l");
leg->AddEntry(LM6VSPT70,"70 #leq VSPT < 100 GeV", "l");
leg->AddEntry(LM6VSPT100,"100 GeV #leq VSPT", "l");

//store the file
TFile *file = new TFile("UTMfile.root","RECREATE");
file->cd();
LM6VSPT0  ->Write();
LM6VSPT20 ->Write();
LM6VSPT30 ->Write();
LM6VSPT40 ->Write();
LM6VSPT50 ->Write();
LM6VSPT70 ->Write();
LM6VSPT100->Write();
WJetsVSPT0  ->Write();
WJetsVSPT20 ->Write();
WJetsVSPT30 ->Write();
WJetsVSPT40 ->Write();
WJetsVSPT50 ->Write();
WJetsVSPT70 ->Write();
WJetsVSPT100->Write();
ZJetsVSPT0  ->Write();
ZJetsVSPT20 ->Write();
ZJetsVSPT30 ->Write();
ZJetsVSPT40 ->Write();
ZJetsVSPT50 ->Write();
ZJetsVSPT70 ->Write();
ZJetsVSPT100->Write();
TTbarVSPT0  ->Write();
TTbarVSPT20 ->Write();
TTbarVSPT30 ->Write();
TTbarVSPT40 ->Write();
TTbarVSPT50 ->Write();
TTbarVSPT70 ->Write();
TTbarVSPT100->Write();
DataQCDVSPT0  ->Write();
DataQCDVSPT20 ->Write();
DataQCDVSPT30 ->Write();
DataQCDVSPT40 ->Write();
DataQCDVSPT50 ->Write();
DataQCDVSPT70 ->Write();
DataQCDVSPT100->Write();
DataWVSPT0  ->Write();
DataWVSPT20 ->Write();
DataWVSPT30 ->Write();
DataWVSPT40 ->Write();
DataWVSPT50 ->Write();
DataWVSPT70 ->Write();
DataWVSPT100->Write();
DataZVSPT0  ->Write();
DataZVSPT20 ->Write();
DataZVSPT30 ->Write();
DataZVSPT40 ->Write();
DataZVSPT50 ->Write();
DataZVSPT70 ->Write();
DataZVSPT100->Write();
DataTopVSPT0  ->Write();
DataTopVSPT20 ->Write();
DataTopVSPT30 ->Write();
DataTopVSPT40 ->Write();
DataTopVSPT50 ->Write();
DataTopVSPT70 ->Write();
DataTopVSPT100->Write();
leg->Write();
file->Close();

cout << "File saved: " << file->GetName() << endl;

}
开发者ID:MT2Analysis,项目名称:MT2Analysis,代码行数:101,代码来源:UTMplots.C

示例12: main


//.........这里部分代码省略.........
    xPos = xPosition;
    yPos = yPosition;
    
    if(Ehodo11>0.1){
       nHodoClustersX=1;
      hodoEff++;
    } else{   nHodoClusters1X=0;}

    if(Ehodo12>0.1){
      nHodoClustersY=1; 
      hodoEff++;
    } else{   nHodoClusters1Y=0; }
   
    
    if(Escint1>0.25){
      isSingleEle_scintFront_=1;
      scintEff++;
    } else{       isSingleEle_scintFront_=0;}
    
   
 
   


    if(Ehodo>0.1){
       nHodoClustersX=1; nHodoClustersY=1;
      hodoEff++;
    } else{   nHodoClustersX=0;  nHodoClustersY=0;}
  
    /*
    if(Escint>0.25 && Escint< 1.5){
      isSingleEle_scintFront_=1;
      scintEff++;
    } else{       isSingleEle_scintFront_=0;}     
    */ 
    
    E_abs= Eabs;


    
    std::vector<float> cef3_corr;
    for( int i=0; i<CEF3_CHANNELS; ++i ) cef3_corr.push_back(-1.);
    
    std::vector<float> bgo_corr;
    for( int i=0; i<BGO_CHANNELS; ++i ) bgo_corr.push_back(-1.);
 
    /*
     
     for(int i=0; i<10; ++i){
     cef3_corr[0]= (LYSF[0]*Eact_0+LYSF[1]*Eact_1+LYSF[2]*Eact_2 +LYSF[3]*Eact_3 +LYSF[4]*Eact_4 +LYSF[5]*Eact_5 +LYSF[6]*Eact_6 +LYSF[7]*Eact_7 +LYSF[8]*Eact_8 +LYSF[9]*Eact_9)/4. ; //yes not very elegant, but it didn't want to work otherwise
     // cef3_corr[0] = Eact /4.;
     }
    */
      
  
    
    for(int i=0; i<15; ++i){
      cef3_corr[0]= (LYSFH[0]*Eact_0+LYSFH[1]*Eact_1+LYSFH[2]*Eact_2 +LYSFH[3]*Eact_3 +LYSFH[4]*Eact_4 +LYSFH[5]*Eact_5 +LYSFH[6]*Eact_6 +LYSFH[7]*Eact_7 +LYSFH[8]*Eact_8 +LYSFH[9]*Eact_9 +LYSFH[10]*Eact_10  +LYSFH[11]*Eact_11 +LYSFH[12]*Eact_12 +LYSFH[13]*Eact_13  +LYSFH[14]*Eact_14 )/4. ; //yes not very elegant, but it didn't want to work otherwise

      //  cef3_corr[0] = Eact /4.;
     }   
    

    
    bgo_corr[0] = Ebgo/8.;
    bgo_corr[1] = Ebgo/8.;
    bgo_corr[2] = Ebgo/8.;
    bgo_corr[3] = Ebgo/8.;
    bgo_corr[4] = Ebgo/8.;
    bgo_corr[5] = Ebgo/8.;
    bgo_corr[6] = Ebgo/8.;
    bgo_corr[7] = Ebgo/8.;
    
    
    for(int k=0; k<CEF3_CHANNELS; ++k){
      cef3_corr_[k] = cef3_corr[0];
    }
    
    for (int k=0; k<BGO_CHANNELS; ++k){ 
      bgo_corr_[k] = bgo_corr[k];
    }
    
    
    outTree->Fill();
  }
  
  
  outfile->cd();
  outTree->Write();
  outfile->Close();
  
  std::cout << "-> Simulated Analysis Tree saved in: " << outfile->GetName() << std::endl;

  std::cout << "Scintillator efficiency = " << scintEff/nentries << std::endl;
  std::cout << "Hodoscope efficiency = " << hodoEff/nentries << std::endl;
 

  return 0;

}
开发者ID:CeF3TB,项目名称:BTFAnalysis,代码行数:101,代码来源:makeSimulationToAnalysisTree.cpp

示例13: ZTMVAClassification


//.........这里部分代码省略.........
    TMVA::Factory *factory = new TMVA::Factory( "TMVAClassification", outputFile,
                                               "!V:!Silent:Color:DrawProgressBar:Transformations=I;D;P;G,D:AnalysisType=Classification" );


// ADD IN OUR VARIABLES HERE
    
    factory->AddVariable("log(kaon_IPCHI2_OWNPV)", "log(kaon_IPCHI2_OWNPV)", "", 'D');
    //factory->AddVariable("kaon_TRACK_GhostProb", "kaon_TRACK_GhostProb", "", 'D');
    factory->AddVariable("kaon_PT", "kaon_PT", "", 'D');
    
    factory->AddVariable("log(proton_IPCHI2_OWNPV)", "log(proton_IPCHI2_OWNPV)", "", 'D');
    //factory->AddVariable("proton_TRACK_GhostProb", "proton_TRACK_GhostProb", "", 'D');
    factory->AddVariable("proton_PT", "proton_PT", "", 'D');
    
    //factory->AddVariable("gamma_PT", "gamma_PT", "", 'D');
    //factory->AddVariable("gamma_CL", "gamma_CL", "", 'D');  
  
    factory->AddVariable("muminus_ProbNNmu", "muminus_ProbNNmu", "", 'D');  
    //factory->AddVariable("muminus_TRACK_GhostProb", "muminus_TRACK_GhostProb", "", 'D');  

    factory->AddVariable("muplus_ProbNNmu", "muplus_ProbNNmu", "", 'D');  
    //factory->AddVariable("muplus_TRACK_GhostProb", "muplus_TRACK_GhostProb", "", 'D');  

    factory->AddVariable("Lambda_b0_DTF_CHI2NDOF", "Lambda_b0_DTF_CHI2NDOF", "", 'D');
    //factory->AddVariable("log(Lambda_b0_IPCHI2_OWNPV)", "log(Lambda_b0_IPCHI2_OWNPV)", "", 'D');
    factory->AddVariable("Lambda_b0_FDS", "Lambda_b0_FDS", "", 'D');  
    factory->AddVariable("Lambda_b0_PT", "Lambda_b0_PT", "", 'D');
    


    //   TFile * input_Background = new TFile("../back.root");
    TFile * input_Signal = new TFile("/afs/cern.ch/work/a/apmorris/public/Lb2chicpK/signal_samples/reduced_Lb2chicpK_MC_2011_2012_signal.root");                                  //
    TFile * input_Background = new TFile("/afs/cern.ch/work/a/apmorris/public/Lb2chicpK/signal_samples/background.root");                                                  //
    std::cout << "--- TMVAClassification       : Using input file for signal    : " << input_Signal->GetName() << std::endl;
    std::cout << "--- TMVAClassification       : Using input file for background : " << input_Background->GetName() << std::endl;
   
    // --- Register the training and test trees

    TTree *signal     = (TTree*)input_Signal->Get("DecayTree");
    TTree *background = (TTree*)input_Background->Get("DecayTree");
   
    // global event weights per tree (see below for setting event-wise weights)
    Double_t signalWeight     = 1.0;
    Double_t backgroundWeight = 1.0;
   
    // You can add an arbitrary number of signal or background trees
    factory->AddSignalTree    ( signal,     signalWeight     );
    factory->AddBackgroundTree( background, backgroundWeight );
   

    // Apply additional cuts on the signal and background samples (can be different)
    TCut mycuts = ""; // for example: TCut mycuts = "abs(var1)<0.5 && abs(var2-0.5)<1";
    TCut mycutb = ""; // for example: TCut mycutb = "abs(var1)<0.5";

   
    factory->PrepareTrainingAndTestTree( mycuts, mycutb,
                                         "nTrain_Signal=0:nTrain_Background=0:SplitMode=Random:NormMode=NumEvents:!V" );

    // ---- Book MVA methods
    //
    // Please lookup the various method configuration options in the corresponding cxx files, eg:
    // src/MethoCuts.cxx, etc, or here: http://tmva.sourceforge.net/optionRef.html
    // it is possible to preset ranges in the option string in which the cut optimisation should be done:
    // "...:CutRangeMin[2]=-1:CutRangeMax[2]=1"...", where [2] is the third input variable

    // Cut optimisation
开发者ID:apmorris,项目名称:project,代码行数:67,代码来源:ZTMVAClassification.C

示例14: TMVAClassification_ttV


//.........这里部分代码省略.........
   //    (TMVA::gConfig().GetVariablePlotting()).fTimesRMS = 8.0;
   //    (TMVA::gConfig().GetIONames()).fWeightFileDir = "myWeightDirectory";

   // Define the input variables that shall be used for the MVA training
   // note that you may also use variable expressions, such as: "3*var1/var2*abs(var3)"
   // [all types of expressions that can also be parsed by TTree::Draw( "expression" )]
   factory->AddVariable(" Mqq := Mqq", 'F');
   factory->AddVariable(" Pt_qq := Pt_qq", 'F');
   //factory->AddVariable( "myvar1 := var1+var2", 'F' );
   //factory->AddVariable( "myvar2 := var1-var2", "Expression 2", "", 'F' );
   //factory->AddVariable( "var3",                "Variable 3", "units", 'F' );
   //factory->AddVariable( "var4",                "Variable 4", "units", 'F' );
   //factory->AddVariable( "Mqq", 'F' );
   //factory->AddVariable( "Pt_qq", 'F' );

   // You can add so-called "Spectator variables", which are not used in the MVA training,
   // but will appear in the final "TestTree" produced by TMVA. This TestTree will contain the
   // input variables, the response values of all trained MVAs, and the spectator variables
   //factory->AddSpectator( "spec1 := var1*2",  "Spectator 1", "units", 'F' );
   //factory->AddSpectator( "spec2 := var1*3",  "Spectator 2", "units", 'F' );

   // Read training and test data
   // (it is also possible to use ASCII format as input -> see TMVA Users Guide)
   
   //Change the input files
   /*
   TString fname = "./tmva_class_example.root";
   
   if (gSystem->AccessPathName( fname ))  // file does not exist in local directory
      gSystem->Exec("wget http://root.cern.ch/files/tmva_class_example.root");
   
   TFile *input = TFile::Open( fname );
   
   std::cout << "--- TMVAClassification       : Using input file: " << input->GetName() << std::endl;
   
   // --- Register the training and test trees

   TTree *signal     = (TTree*)input->Get("TreeS");
   TTree *background = (TTree*)input->Get("TreeB");
   */
   VCandStruct vcand;
   AsymetryStruct asym;
   
   //TFile* fsignal = TFile::Open("/opt/sbg/data/data1/cms/echabert/ttbarMET/ProdAlexMars13/CMSSW_5_3_2_patch4/src/NTuple/NTupleAnalysis/macros/TTbarMET/backup_outputProof08-04-13_18-01-24/proof_ttW.root");
   TFile* fsignal = TFile::Open("/opt/sbg/data/data1/cms/echabert/ttbarMET/ProdAlexMars13/CMSSW_5_3_2_patch4/src/NTuple/NTupleAnalysis/macros/TTbarMET/backup_outputProof10-04-13_16-00-57/proof_ttW.root");
   TTree *signal     = (TTree*)fsignal->Get("theTree2");
   //TTree *signal_orig     = (TTree*)fsignal->Get("theTree2");
   //TTree *signal = signal_orig->CloneTree(0);
   //signal->SetDirectory(0);
   TFile* fbackground = TFile::Open("/opt/sbg/data/data1/cms/echabert/ttbarMET/ProdAlexMars13/CMSSW_5_3_2_patch4/src/NTuple/NTupleAnalysis/macros/TTbarMET/backup_outputProof10-04-13_16-00-57/proof_tt-dilepton.root");
   TTree *background = (TTree*)fbackground->Get("theTree2");
   //TTree *background_orig = (TTree*)fbackground->Get("theTree");
   //TTree *background = background_orig->CloneTree(0);
   //background->SetDirectory(0);

   // global event weights per tree (see below for setting event-wise weights)
   Double_t signalWeight     = 0.30*20/185338;
   Double_t backgroundWeight = 222.*0.1*20/9982625;
   
   // You can add an arbitrary number of signal or background trees
   //Commented by Eric
   factory->AddSignalTree    ( signal,     signalWeight     );
   factory->AddBackgroundTree( background, backgroundWeight );
   
   // To give different trees for training and testing, do as follows:
       //factory->AddSignalTree( signalTrainingTree, signalTrainWeight, "Training" );
开发者ID:jgomezca,项目名称:combinedOneLeptonStopAnalysis,代码行数:67,代码来源:TMVAClassification_ttV.C

示例15: MergeRootfile

void MergeRootfile( TDirectory *target, TList *sourcelist, double crossArray[] ) {

  cout << "Target path: " << target->GetPath() << endl;
  TString path( (char*)strstr( target->GetPath(), ":" ) );
  path.Remove( 0, 2 );

  TFile *first_source = (TFile*)sourcelist->First();

  first_source->cd( path );
  TDirectory *current_sourcedir = gDirectory;
  //gain time, do not add the objects in the list in memory
  Bool_t status = TH1::AddDirectoryStatus();
  TH1::AddDirectory(kFALSE);

  // loop over all keys in this directory
  TChain *globChain = 0;
  TIter nextkey( current_sourcedir->GetListOfKeys() );
  TKey *key, *oldkey=0;
  while ( (key = (TKey*)nextkey())) {

    //keep only the highest cycle number for each key
    if (oldkey && !strcmp(oldkey->GetName(),key->GetName())) continue;

    // read object from first source file
    first_source->cd( path );
    TObject *obj = key->ReadObj();

    if ( obj->IsA()->InheritsFrom( "TH1" ) ) {
      // descendant of TH1 -> merge it

      cout << "Merging histogram " << obj->GetName() << endl;
      TH1 *h1 = (TH1*)obj;

      // Scale by the cross-section factor
      h1->Scale(crossArray[0]);
      h1->Sumw2();

      // loop over all source files and add the content of the
      // correspondant histogram to the one pointed to by "h1"
      TFile *nextsource = (TFile*)sourcelist->After( first_source );

      int q = 1; // This keeps track of which
                 // cross section factor to use
      while ( nextsource ) {
        // make sure we are at the correct directory level by cd'ing to path
        nextsource->cd( path );
        TKey *key2 = (TKey*)gDirectory->GetListOfKeys()->FindObject(h1->GetName());
        if (key2) {
           TH1 *h2 = (TH1*)key2->ReadObj();

           // Scale by the cross section factor
           // before adding.
           h2->Scale(crossArray[q]);
           h1->Add( h2 );
           q++;
           delete h2;
        }

        nextsource = (TFile*)sourcelist->After( nextsource );
      }
    }
    else if ( obj->IsA()->InheritsFrom( "TTree" ) ) {

      // loop over all source files create a chain of Trees "globChain"
      const char* obj_name= obj->GetName();

      globChain = new TChain(obj_name);
      globChain->Add(first_source->GetName());
      TFile *nextsource = (TFile*)sourcelist->After( first_source );
      //      const char* file_name = nextsource->GetName();
      // cout << "file name  " << file_name << endl;
     while ( nextsource ) {

       globChain->Add(nextsource->GetName());
       nextsource = (TFile*)sourcelist->After( nextsource );
     }

    } else if ( obj->IsA()->InheritsFrom( "TDirectory" ) ) {
      // it's a subdirectory

      cout << "Found subdirectory " << obj->GetName() << endl;

      // create a new subdir of same name and title in the target file
      target->cd();
      TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );

      // newdir is now the starting point of another round of merging
      // newdir still knows its depth within the target file via
      // GetPath(), so we can still figure out where we are in the recursion
      MergeRootfile( newdir, sourcelist, crossArray );

    } else {

      // object is of no type that we know or can handle
      cout << "Unknown object type, name: "
           << obj->GetName() << " title: " << obj->GetTitle() << endl;
    }

    // now write the merged histogram (which is "in" obj) to the target file
    // note that this will just store obj in the current directory level,
//.........这里部分代码省略.........
开发者ID:Hosein47,项目名称:usercode,代码行数:101,代码来源:merge_hadd_TT.C


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