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


C++ TDirectoryFile::GetListOfKeys方法代码示例

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


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

示例1: next

std::pair<TH3F*,TH3F*> getEffHists(const char *file, const char *dirC, 
				     const char *histN, const char *histD){

     TFile *efile = new TFile(file,"read");
     TDirectoryFile *efileDIR = (TDirectoryFile*) efile->GetDirectory(dirC);

     TIter next(efileDIR->GetListOfKeys());
     TKey *key;

     Char_t name[100];

     TH3F *hpneff3d=0;
     TH3F *hpdeff3d=0;

     while ((key=(TKey*)next())) {
	sprintf(name,"%s",key->GetName());
	if(strcmp((key->GetName()),(histN))==0){
	  //cout<<"[getEffHists] Your numerator for Eff "<<name<<endl; 
	   hpneff3d = (TH3F*) efileDIR->Get(name);
	}
	if(strcmp((key->GetName()),(histD))==0){
	  //cout<<"[getEffHists] Your denominator for Eff "<<name<<endl; 
	   hpdeff3d = (TH3F*) efileDIR->Get(name);
	}
     }

     //efileDIR->Close(); 
     //efile->Close(); 
     return std::pair<TH3F*,TH3F*>(hpneff3d,hpdeff3d);
  }
开发者ID:CmsHI,项目名称:CVS_ASYoon,代码行数:30,代码来源:HiCorrectTypeOneNSave.C

示例2: parseOptions

int
main (int argc, char *argv[])
{
  map<string, string> opt;
  vector<string> argVector;
  parseOptions (argc, argv, opt, argVector);
  if (argVector.size () != 1 || opt.count ("help"))
    {
      printHelp (argv[0]);
      return 0;
    }
  TFile *fin;
  if (!(fin = TFile::Open (argVector.at (0).c_str (), "update")))
    {
      cout << "Failed to open " << argVector.at (0) << "!" << endl;
      return 0;
    }
  TIter next0 (fin->GetListOfKeys ());
  TObject *obj0;
  TH1D *cutFlow = 0;
  TDirectoryFile *dir = 0;
  while ((obj0 = next0 ()))
    {
      string obj0Class = ((TKey *) obj0)->GetClassName (),
             obj0Name = obj0->GetName ();

      if (obj0Class == "TDirectoryFile")
        {
          dir = (TDirectoryFile *) fin->Get (obj0Name.c_str ());
          TIter next1 (dir->GetListOfKeys ());
          TObject *obj1;
          while ((obj1 = next1 ()))
            {
              string obj1Class = ((TKey *) obj1)->GetClassName (),
                     obj1Name = obj1->GetName ();

              if (obj1Class == "TH1D" && obj1Name.length () >= 7 && ((obj1Name.substr (obj1Name.length () - 7, 7) == "CutFlow" || obj1Name.substr (obj1Name.length () - 7, 7) == "cutFlow")
               || (obj1Name.length () >= 9 && (obj1Name.substr (obj1Name.length () - 9, 9) == "Selection" || obj1Name.substr (obj1Name.length () - 9, 9) == "selection"))
               || (obj1Name.length () >= 8 && (obj1Name.substr (obj1Name.length () - 8, 8) == "MinusOne" || obj1Name.substr (obj1Name.length () - 8, 8) == "minusOne")))
               && !dir->Get ((obj1Name + "LowerLimit").c_str ()) && !dir->Get ((obj1Name + "UpperLimit").c_str ()))
                {
                  cutFlow = (TH1D *) dir->Get (obj1Name.c_str ());
                  cutFlow->SetDirectory (0);
                  getLimits (cutFlow, dir);
                }
            }
        }
    }
  fin->Close ();

  return 0;
}
开发者ID:allenji,项目名称:OSUT3Analysis,代码行数:52,代码来源:cutFlowLimits.cpp

示例3: doHisto

// Noise section
Stat_t AnalysisClass::doHisto(Char_t * Variable, Char_t *SubDetName, Char_t *Layer,Char_t *label){
  TH1 *hHisto=0; 
  if (debug)   cout << d1->GetTitle() << " " << Variable << " " << SubDetName << endl;
  pPar[0]=0; pPar[1]=0;
  TIter it(d1->GetListOfKeys());
  TObject * o;
  while ( (o = it()))  
    {
      TObject * d =  d1->Get(o->GetName());
      if(d->IsA()->InheritsFrom("TDirectory") && strstr(d->GetName(),SubDetName)){
	if (debug) 	cout << "Found SubDet " << SubDetName << endl;
	TIter it2(((TDirectoryFile * )d)->GetListOfKeys());
	TObject *o2;
	while( ( o2 = it2()) ){
	  TObject *d2 = ((TDirectoryFile * )d)->Get(o2->GetName());
	  if(d2->IsA()->InheritsFrom("TDirectory") && strstr(d2->GetName(),Layer) ){
	    if (debug) cout << "Found Layer" << Layer << endl;
	    TIter it3(((TDirectoryFile * )d2)->GetListOfKeys());
	    TObject *o3;
	    while( ( o3 = it3()) ){
	      TObject *d3 = ((TDirectoryFile * )d2)->Get(o3->GetName());
	      if(strstr(d3->GetName(),Variable) && strstr(d3->GetName(),label)){
		hHisto = (TH1*) d3;
		if(hHisto->GetEntries()!=0) {
		  pPar[0]=hHisto->GetMean();
		  pPar[1]=hHisto->GetRMS();  
		  if (debug) cout << "Histo Title " << hHisto->GetTitle() << " mean: " << hHisto->GetMean() << " rms: " << hHisto->GetRMS() << " " << hHisto->GetEntries() << endl;
		}
		else{
		  cout<<"Empty Histogram "<< hHisto->GetTitle() << endl;
		  pPar[0]=-10; pPar[1]=-10;
		}
	      }
	    }
	  }
	}
      }
    }
  return hHisto->GetEntries();  
}
开发者ID:Andrej-CMS,项目名称:cmssw,代码行数:41,代码来源:LayerTree.cpp

示例4: GenerateTDiffPlots

// This will generate the following PDFs:
// -- hDQ_muScTDiff_[DetName]_[BankName].png
void GenerateTDiffPlots(std::string filename) {

  std::cout << "Generating pulse shape plots..." << std::endl;

  gROOT->Reset();
  gROOT->SetStyle("Plain");
  gStyle->SetCanvasBorderMode(0); // turn off canvas borders


  TFile* file = new TFile(filename.c_str(), "READ");

  // The histograms
  TH1F *hDQ_muScTDiff;

  // Loop through the histograms in the file and get the island histograms (bank and channel names may differ between runs)
  TDirectoryFile* dir = (TDirectoryFile*) file->Get("DataQuality_LowLevel");
  
  TIter nextDirKey(dir->GetListOfKeys()); // get the list of keys in the directory (all histograms should be in this folder)
  TKey *dirKey;
  
  while ( (dirKey = (TKey*)nextDirKey()) ) {
    // Get the names of all the histograms and count them up
    if (strcmp(dirKey->ReadObj()->ClassName(), "TH1F") == 0) {

      TCanvas *c1 = new TCanvas();

      std::string histogram_name = dirKey->ReadObj()->GetName();
      std::string histogram_location = "DataQuality_LowLevel/" + histogram_name;
      std::string pngname = "data_quality_figs/" + histogram_name + ".png";

      if (histogram_name.find("muScTDiff") != std::string::npos) {
	file->GetObject(histogram_location.c_str(),hDQ_muScTDiff);

	hDQ_muScTDiff->GetYaxis()->SetTitleOffset(1.3);
	hDQ_muScTDiff->Draw();
	c1->Print(pngname.c_str());
      }
    }
  }
}
开发者ID:alcap-org,项目名称:AlcapDAQ,代码行数:42,代码来源:GenerateTDiffPlots.C

示例5: advancedNoiseAnalysis

void advancedNoiseAnalysis( unsigned int runNumber, unsigned int loop = 1) {
  
  string inputFileName = "./histo/run00" + toString( runNumber ) + "-ped-histo.root";
  string outputFileName = "./histo/run00" + toString( runNumber ) + "-adv-noise.root";
  

  // before opening the input and the output files, try to see if they
  // are not opened yet and in case close them before continue   
  TList * listOfOpenedFile = (TList*) gROOT->GetListOfFiles();
  for ( int i = 0; i < listOfOpenedFile->GetSize() ; ++i ) {
    TFile * file = (TFile*) listOfOpenedFile->At( i ) ;
    TString fileName(file->GetName());
    TString inputFileName1( inputFileName.c_str() );
    TString outputFileName1( outputFileName.c_str() );

    if (  ( fileName.Contains( inputFileName1 ) ) ||
	  ( inputFileName1.Contains( fileName ) ) ||
	  ( fileName.Contains( outputFileName1 ) ) ||
	  ( outputFileName1.Contains( fileName ) ) ) {
      cout << "Closing " << fileName << " before reopen " << endl;
      file->Close();
    }
  }


  // close also all the previously opened canvas
  TList * listOfOpenedCanvas = (TList*) gROOT->GetListOfCanvases();
  for ( int i = 0 ; i < listOfOpenedCanvas->GetSize() ; ++i ) {
    TCanvas * canvas = (TCanvas*) listOfOpenedCanvas->At( i );
    TString canvasName2 = canvas->GetName();
    if ( canvasName2.Contains( "det" ) ) {
      canvas->Close();
    }
  }

	 
  // now safely open the file
  TFile * inputFile = TFile::Open( inputFileName.c_str() ) ;
  TFile * outputFile = TFile::Open( outputFileName.c_str(), "RECREATE") ;
  TList * outputHistoList = new TList;

  // look into the inputFile for a folder named
  string pedeProcessorFolderName = "PedestalAndNoiseCalculator";
  TDirectoryFile * pedeProcessorFolder = (TDirectoryFile*) inputFile->Get( pedeProcessorFolderName.c_str() );
  
  if ( pedeProcessorFolder == 0 ) { 
    cerr << "No pedestal processor folder found in file " << inputFileName << endl;
    return ;
  }

  // this folder should contain one folder for each loop.
  string loopFolderName = "loop-" + toString( loop );
  TDirectoryFile * loopFolder = (TDirectoryFile *) pedeProcessorFolder->Get( loopFolderName.c_str() );
  
  if ( loopFolder == 0 ) {
    cerr << "No " << loopFolderName << " found in file " << inputFileName << endl;
    return ;
  }

  // guess the number of sensors from the number of subfolder in the loopfolder
  size_t nDetector = loopFolder->GetListOfKeys()->GetSize();
  cout << "This file contains " << nDetector << " detectors" << endl;

  // prepare arrays to store the mean and the rms of the noise distribution
  if ( noiseMean == NULL ) {
    delete [] noiseMean;
    noiseMean = NULL;
  }
  if ( noiseRMS == NULL ) {
    delete [] noiseRMS;
    noiseRMS = NULL;
  }
  if ( channel == NULL ) {
    delete [] channel;
    channel = NULL;
  }

  noiseMean = new double[ nDetector * kNChan ];
  noiseRMS  = new double[ nDetector * kNChan ];
  channel   = new double[ kNChan ];

  string canvasName = "comparison";
  string canvasTitle = "Noise comparison";

  TCanvas * comparisonCanvas = new TCanvas( canvasName.c_str(), canvasTitle.c_str(), 1000, 500 );
  comparisonCanvas->Divide(1,2);
  
  TPad * topPad = (TPad*) comparisonCanvas->cd(1);
  topPad->Divide( nDetector );
  
  TPad * middlePad = (TPad *) comparisonCanvas->cd(2);
  middlePad->Divide( kNChan );


  // for each detector we have to get the noise map and to prepare 4
  // separe histos and maps
  for ( unsigned int iDetector = 0; iDetector < nDetector; iDetector++ ) {

    // get the noise map.
    string noiseMapName = "detector-" + toString( iDetector ) ;
//.........这里部分代码省略.........
开发者ID:AlexanderMorton,项目名称:eutelescope,代码行数:101,代码来源:advancedNoiseAnalysis.C

示例6: CreatePictureBooks

void CreatePictureBooks(const char* data_dir, int first_run, const int n_runs) {

  gROOT->Reset();
  gROOT->SetStyle("Plain");
  gStyle->SetCanvasBorderMode(0); // turn off canvas borders



  // Create the canvases
  TCanvas* trend_canvas = new TCanvas("trend_canvas", "trend_canvas");

  TFile* files[n_runs];
  TCanvas* individual_canvases[n_runs];

  // Names for opening, closing and saving to PDFs
  std::stringstream individual_basepdfname[n_runs];
  std::string individual_openpdfname[n_runs];
  std::string individual_closepdfname[n_runs];

  for (int iRun = 0; iRun < n_runs; ++iRun) {

    int run_number = first_run + iRun;

    // Open up the file for this run
    std::stringstream filename;
    filename << data_dir << "/hist/hist0" << run_number << ".root";
    files[iRun] = new TFile(filename.str().c_str(), "READ");

    // Create an individual canvas for this run
    std::stringstream canvasname;
    canvasname << "individual_canvas_run0" << run_number;
    individual_canvases[iRun] = new TCanvas(canvasname.str().c_str(),canvasname.str().c_str());

    // Open a PDF for each run
    individual_basepdfname[iRun].str("");
    individual_basepdfname[iRun] << "DQ_LowLevel_RunPlots_Run0" << run_number << ".pdf";
    
    individual_openpdfname[iRun] =  individual_basepdfname[iRun].str() + "[";
    individual_closepdfname[iRun] = individual_basepdfname[iRun].str() + "]";
    individual_canvases[iRun]->Print(individual_openpdfname[iRun].c_str());
  }



  // Get the names of all the histograms
  std::vector<std::string> histogram_names;

  TIter nextFileKey(files[0]->GetListOfKeys()); // get the list of keys for the top level in the first file (all files should be the same)
  TKey *fileKey;
        
  while (fileKey = (TKey*)nextFileKey()) {

    // Get the directory for low-level data quality plots first
    if (strcmp(fileKey->ReadObj()->ClassName(), "TDirectoryFile") == 0) {
      // Check that the directory has the correct name
      if (strcmp(fileKey->ReadObj()->GetName(), "DataQuality_LowLevel") == 0) {

	TDirectoryFile* dir = (TDirectoryFile*) fileKey->ReadObj();
	
	TIter nextDirKey(dir->GetListOfKeys()); // get the list of keys in the directory (all histograms should be in this folder)
	TKey *dirKey;
        
	while (dirKey = (TKey*)nextDirKey()) {

	  // Get the names of all the histograms and count them up
	  if (strcmp(dirKey->ReadObj()->ClassName(), "TH1F") == 0 ||
	      strcmp(dirKey->ReadObj()->ClassName(), "TH2F") == 0) {

	    histogram_names.push_back(dirKey->ReadObj()->GetName());
	  } // end if (class is TH1F)

	} // end while loop (through keys in the directory)
      } // end if (directory is DataQuality_LowLevel)
    } // end if (class is TDirectoryFile)
  } // end while loop (through keys in file)

  // Reorder the histogram names so that channels from the same board are next to each other (might make it easier to print 4 plots on the same page)
  std::vector<std::string> ordered_histogram_names = OrderHistogramNames(histogram_names);

  std::stringstream trend_basepdfname;
  trend_basepdfname << "DQ_LowLevel_TrendPlots_Runs0" << first_run << "-" << first_run + n_runs << ".pdf";
  std::string trend_openpdfname = trend_basepdfname.str() + "[";
  std::string trend_closepdfname = trend_basepdfname.str() + "]";

  trend_canvas->Print(trend_openpdfname.c_str());



  // Now we have the histogram names, so loop though them
  for (int iHist = 0; iHist < ordered_histogram_names.size(); ++iHist) {

    std::string histname = ordered_histogram_names.at(iHist);
    std::string fullhistname = "DataQuality_LowLevel/" + histname;

    // Check to see if we actually want this plot
    if ( !WantPlot(histname)) {
      continue;
    }


//.........这里部分代码省略.........
开发者ID:alcap-org,项目名称:AlcapDAQ,代码行数:101,代码来源:CreatePictureBooks.C

示例7: makeMuonTimingPlot

void makeMuonTimingPlot (std::string fname)
{
    TFile file(fname.c_str());
    TDirectoryFile *dir = (TDirectoryFile*)file.Get("Muons");

    TList *hlist = dir->GetListOfKeys();
    TH1F *h1;
    bool foundHist = false;
    for (auto hist : *hlist)    
    {
        TString name = hist->GetName();
        if (!name.Contains("hMuTimeP")) continue;

        TH1F *h0 = (TH1F*)dir->Get(name.Data());        
        if (!foundHist)
        {
            h1 = (TH1F*)h0->Clone();
            h1->Sumw2();
            foundHist = true;
        }
        else
        {
            h1->Add(h0);
        }        
    }

    TH1F *h2 = new TH1F("h2", "h2", 200, -100, 100);
    h2->GetXaxis()->SetTitle("muon time (ns)");
    h2->GetYaxis()->SetTitle("Fraction of Muons/ns");
    h2->GetYaxis()->SetTitleOffset(1.1);
    h2->GetXaxis()->SetTitleOffset(0.8);        
    h2->SetTitle("CSC Muon Time");
    h2->SetTitleFont(42);
    h2->SetTitleSize(0.052);    
 
    h2->Sumw2();
    h2->SetLineColor(kCyan+3);
    h2->SetFillColor(kCyan+3);

    for (int ibin = 1; ibin <= 200; ibin++)
    {
        h2->SetBinContent(ibin, h1->GetBinContent(ibin));
        h2->SetBinError(ibin, h1->GetBinError(ibin));
        if (ibin == 200)
            h2->SetEntries(h1->GetEntries());
    }
    
    TCanvas c1("c1", "c1", 600, 400);
    gStyle->SetOptStat("");

    double rms = h2->GetRMS();
    double avg = h2->GetMean();
    
    TLatex cms(0.17, 0.83, "CMS");
    cms.SetNDC();
    cms.SetTextFont(61);
    cms.SetTextSize(0.06);

    TLatex prelim(0.17, 0.81, "Preliminary");
    prelim.SetNDC();
    prelim.SetTextAlign(13);
    prelim.SetTextFont(52);
    prelim.SetTextSize(0.0456);

    TLatex data(0.17, 0.76, "Data 2016");
    data.SetNDC();
    data.SetTextAlign(13);
    data.SetTextFont(52);
    data.SetTextSize(0.0456);

    TLatex lumi(0.9, 0.93, "4.0 fb^{-1} (13 TeV)");
    lumi.SetNDC();
    lumi.SetTextAlign(31);
    lumi.SetTextFont(42);
    lumi.SetTextSize(0.052);    

    TLatex mean(0.7, 0.81, Form("Mean  %2.1f", avg));
    mean.SetNDC();
    mean.SetTextAlign(11);
    mean.SetTextFont(61);
    mean.SetTextSize(0.06);

    TLatex stdev(0.7, 0.76, Form("RMS   %2.1f", rms));
    stdev.SetNDC();
    stdev.SetTextAlign(11);
    stdev.SetTextFont(61);
    stdev.SetTextSize(0.06);

    h2->GetXaxis()->SetRangeUser(-6*rms,6*rms);   
    TH1F* h2norm = (TH1F*)h2->DrawNormalized("hist");
    gPad->Update();
    cms.Draw();
    prelim.Draw();
    data.Draw();
    lumi.Draw();
    mean.Draw();
    stdev.Draw();
    
    TPaveText *title = (TPaveText*)gPad->GetPrimitive("title");
    title->SetBorderSize(0);
//.........这里部分代码省略.........
开发者ID:fgolf,项目名称:CSCOfflineTiming,代码行数:101,代码来源:makeMuonTimingPlot.C

示例8: doNoiseFit

//Noise section
Stat_t AnalysisClass::doNoiseFit(Int_t RunNumber, Char_t *Variable, Char_t *SubDetName, Char_t *Layer, Char_t *label){
  TH1 *hNtoFit=0;
  if (debug) cout << d1->GetTitle() << " " << Variable << " " << SubDetName << endl;
  pPar[0]=0; pPar[1]=0;
  TIter it(d1->GetListOfKeys());
  TObject * o;
  while ( (o = it()))  
    {
      TObject * d =  d1->Get(o->GetName());
      if(d->IsA()->InheritsFrom("TDirectory") && strstr(d->GetName(),SubDetName)){
	if (debug) cout << "Found " << SubDetName << endl;
	TIter it2(((TDirectoryFile * )d)->GetListOfKeys());
	TObject *o2;
	while( ( o2 = it2()) ){
	  TObject *d2 = ((TDirectoryFile * )d)->Get(o2->GetName());
	  if(d2->IsA()->InheritsFrom("TDirectory") && strstr(d2->GetName(),Layer) ){
	    if (debug) cout << "Found Layer" << Layer << endl;
	    TIter it3(((TDirectoryFile * )d2)->GetListOfKeys());
	    TObject *o3;
	    while( ( o3 = it3()) ){
	      TObject *d3 = ((TDirectoryFile * )d2)->Get(o3->GetName());
	      if(strstr(d3->GetName(),Variable) && strstr(d3->GetName(),label)){
		hNtoFit = (TH1*) d3;
		if (debug) cout << "Found " << Variable << endl;
		if (hNtoFit->GetEntries()!=0) {
		  cout<<"Fitting "<< hNtoFit->GetTitle() <<endl;
		  // Setting fit range and start values
		  Double_t fr[2];
		  Double_t sv[3], pllo[3], plhi[3];
		  fr[0]=hNtoFit->GetMean()-5*hNtoFit->GetRMS();
		  fr[1]=hNtoFit->GetMean()+5*hNtoFit->GetRMS();
		  
		  Int_t imax=hNtoFit->GetMaximumBin();
		  Double_t xmax=hNtoFit->GetBinCenter(imax);
		  Double_t ymax=hNtoFit->GetBinContent(imax);
		  Int_t i[2];
		  Int_t iArea[2];
		  
		  i[0]=hNtoFit->GetXaxis()->FindBin(fr[0]);
		  i[1]=hNtoFit->GetXaxis()->FindBin(fr[1]);
		  
		  iArea[0]=hNtoFit->GetXaxis()->FindBin(fr[0]);
		  iArea[1]=hNtoFit->GetXaxis()->FindBin(fr[1]);
		  Double_t AreaFWHM=hNtoFit->Integral(iArea[0],iArea[1],"width");
		  
		  sv[2]=AreaFWHM/(4*ymax);
		  sv[1]=xmax;
		  sv[0]=hNtoFit->Integral(i[0],i[1],"width");
		  
		  plhi[0]=1000000.0; plhi[1]=10.0; plhi[2]=10.;
		  pllo[0]=1.5 ; pllo[1]=0.1; pllo[2]=0.3;
		  Char_t FunName[100];
		  sprintf(FunName,"FitfcnLG_%s%d",hNtoFit->GetName(),fRun);
		  TF1 *ffitold = (TF1*)gROOT->GetListOfFunctions()->FindObject(FunName);
		  if (ffitold) delete ffitold;
		  
		  gausFit = new TF1(FunName,Gauss,fr[0],fr[1],3);
		  gausFit->SetParameters(sv);
		  gausFit->SetParNames("Constant","GaussPeak","Sigma");
		  
		  for (Int_t i=0; i<3; i++) {
		    gausFit->SetParLimits(i,pllo[i],plhi[i]);
		  }
		  hNtoFit->Fit(gausFit,"R0");
		  
		  gausFit->SetRange(fr[0],fr[1]);
		  pGausS=gausFit->GetParameters();
		  epGausS=gausFit->GetParErrors();
		  
		  chi2GausS =langausFit->GetChisquare(); // obtain chi^2
		  nDofGausS = langausFit->GetNDF();// obtain ndf
		  
		  TCanvas *cAllN = new TCanvas("NoiseFit",hNtoFit->GetTitle(),1);
		  Char_t fitFileName[60];
		  sprintf(fitFileName,"Fits/Run_%d/%s/Fit_%s.png",RunNumber,SubDetName,hNtoFit->GetTitle());
		  hNtoFit->Draw("pe");
		  gStyle->SetOptFit(1111111);
		  gausFit->Draw("lsame");
   
		  cAllN->Print(fitFileName,"png");
		}else {
		  pGausS[0]=-10; pGausS[1]=-10; pGausS[2]=-10;
		  epGausS[0]=-10; epGausS[1]=-10; epGausS[2]=-10;
		}
	      }
	    }
	  }
	}
      }
    }
 
  return hNtoFit->GetEntries();
}
开发者ID:Andrej-CMS,项目名称:cmssw,代码行数:94,代码来源:LayerTree.cpp

示例9: doFit

Stat_t AnalysisClass::doFit(Int_t RunNumber,Char_t *Variable, Char_t *SubDetName, Char_t *Layer,Char_t *label){
  TH1 *htoFit=0; 
  pLanGausS[0]=0; pLanGausS[1]=0; pLanGausS[2]=0; pLanGausS[3]=0;
  epLanGausS[0]=0; epLanGausS[1]=0; epLanGausS[2]=0; epLanGausS[3]=0;

  if (debug)   cout << d1->GetTitle() << " " << Variable << " " << SubDetName << endl;
  pPar[0]=0; pPar[1]=0;
  TIter it(d1->GetListOfKeys());
  TObject * o;
  while ( (o = it()))  
    {
      TObject * d =  d1->Get(o->GetName());
      if(d->IsA()->InheritsFrom("TDirectory") && strstr(d->GetName(),SubDetName)){
	if (debug) cout << "Found " << SubDetName << endl;
	TIter it2(((TDirectoryFile * )d)->GetListOfKeys());
	TObject *o2;
	while( ( o2 = it2()) ){
	  TObject *d2 = ((TDirectoryFile * )d)->Get(o2->GetName());
	  if(d2->IsA()->InheritsFrom("TDirectory") && strstr(d2->GetName(),Layer) ){
	    if (debug) cout << "Found Layer" << Layer << endl;
	    TIter it3(((TDirectoryFile * )d2)->GetListOfKeys());
	    TObject *o3;
	    while( ( o3 = it3()) ){
	      TObject *d3 = ((TDirectoryFile * )d2)->Get(o3->GetName());
	      if(strstr(d3->GetName(),Variable) && strstr(d3->GetName(),label)){
		htoFit = (TH1*) d3;
		if (debug) cout << "Found " << Variable << endl;
		
		if (htoFit->GetEntries()!=0) {
		  cout<<"Fitting "<< htoFit->GetTitle() <<endl;
		  // Setting fit range and start values
		  Double_t fr[2];
		  Double_t sv[4], pllo[4], plhi[4];
		  fr[0]=0.5*htoFit->GetMean();
		  fr[1]=3.0*htoFit->GetMean();
	      
		  // (EM) parameters setting good for signal only 
		  Int_t imax=htoFit->GetMaximumBin();
		  Double_t xmax=htoFit->GetBinCenter(imax);
		  Double_t ymax=htoFit->GetBinContent(imax);
		  Int_t i[2];
		  Int_t iArea[2];
	      
		  i[0]=htoFit->GetXaxis()->FindBin(fr[0]);
		  i[1]=htoFit->GetXaxis()->FindBin(fr[1]);
		  
		  iArea[0]=htoFit->GetXaxis()->FindBin(fr[0]);
		  iArea[1]=htoFit->GetXaxis()->FindBin(fr[1]);
		  Double_t AreaFWHM=htoFit->Integral(iArea[0],iArea[1],"width");
		  
		  sv[1]=xmax;
		  sv[2]=htoFit->Integral(i[0],i[1],"width");
		  sv[3]=AreaFWHM/(4*ymax);
		  sv[0]=sv[3];
		  
		  plhi[0]=25.0; plhi[1]=200.0; plhi[2]=1000000.0; plhi[3]=50.0;
		  pllo[0]=1.5 ; pllo[1]=10.0 ; pllo[2]=1.0      ; pllo[3]= 1.0;
		  
		  // create different landau+gaussians for different runs
		  Char_t FunName[100];
		  sprintf(FunName,"FitfcnLG_%s%d",htoFit->GetName(),fRun);  
		  TF1 *ffitold = (TF1*)gROOT->GetListOfFunctions()->FindObject(FunName);
		  if (ffitold) delete ffitold;
		  
		  langausFit = new TF1(FunName,langaufun,fr[0],fr[1],4);
		  langausFit->SetParameters(sv);
		  langausFit->SetParNames("Width","MP","Area","GSigma");
		  
		  for (Int_t i=0; i<4; i++) {
		    langausFit->SetParLimits(i,pllo[i],plhi[i]);
		  }  
		  
		  htoFit->Fit(langausFit,"R0");  // "R" fit in a range,"0" quiet fit
		  
		  langausFit->SetRange(fr[0],fr[1]);
		  pLanGausS=langausFit->GetParameters();
		  epLanGausS=langausFit->GetParErrors();
		  
		  chi2GausS =langausFit->GetChisquare();  // obtain chi^2
		  nDofGausS = langausFit->GetNDF();           // obtain ndf
		  
		  Double_t sPeak, sFWHM;
		  langaupro(pLanGausS,sPeak,sFWHM);
		  pLanConv[0]=sPeak;
		  pLanConv[1]=sFWHM;
		  cout << "langaupro:  max  " << sPeak << endl;
		  cout << "langaupro:  FWHM " << sFWHM << endl;
		  
		  TCanvas *cAll = new TCanvas("Fit",htoFit->GetTitle(),1);
		  Char_t fitFileName[60];
		  sprintf(fitFileName,"Fits/Run_%d/%s/Fit_%s.png",RunNumber,SubDetName,htoFit->GetTitle());
		  htoFit->Draw("pe");
		  htoFit->SetStats(100);
		  langausFit->Draw("lsame");
		  gStyle->SetOptFit(1111111);
		  
		  cAll->Print(fitFileName,"png");
		}
		else {  
		  pLanGausS[0]=-10; pLanGausS[1]=-10; pLanGausS[2]=-10; pLanGausS[3]=-10;
//.........这里部分代码省略.........
开发者ID:Andrej-CMS,项目名称:cmssw,代码行数:101,代码来源:LayerTree.cpp

示例10: mergeForest

void mergeForest(TString fname = "/data/jisun/temp/*.root",
		 TString outfile="/data/jisun/pp_2015_HeavyFlavor_AOD_tkpt1_D0pt1_eta2p5_D3d1_Prob0p05_1202.root",
		 bool failOnError = true)
{
  // First, find on of the files within 'fname' and use it to make a
  // list of trees. Unfortunately we have to know in advance at least
  // one of the tree names. hiEvtAnalyzer/HiTree is a safe choice for
  // HiForests. We also assume that every TTree is inside a
  // TDirectoryFile which is in the top level of the root file.
  TChain *dummyChain = new TChain("hltanalysis/HltTree");
  dummyChain->Add(fname);
  TFile *testFile = dummyChain->GetFile();
  TList *topKeyList = testFile->GetListOfKeys();

  std::vector<TString> trees;
  std::vector<TString> dir;

  for(int i = 0; i < topKeyList->GetEntries(); ++i)
  {
    TDirectoryFile *dFile = (TDirectoryFile*)testFile->Get(topKeyList->At(i)->GetName());
    if(strcmp(dFile->ClassName(), "TDirectoryFile") != 0) continue;
    
    TList *bottomKeyList = dFile->GetListOfKeys();

    for(int j = 0; j < bottomKeyList->GetEntries(); ++j)
    {
      TString treeName = dFile->GetName();
      treeName += "/";
      treeName += bottomKeyList->At(j)->GetName();

      TTree* tree = (TTree*)testFile->Get(treeName);
      if(strcmp(tree->ClassName(), "TTree") != 0 && strcmp(tree->ClassName(), "TNtuple") != 0) continue;

      trees.push_back(treeName);
      dir.push_back(dFile->GetName());
    }
  }

  testFile->Close();
  delete dummyChain;

  // Now use the list of tree names to make a new root file, filling
  // it with the trees from 'fname'.
  const int Ntrees = trees.size();
  TChain* ch[Ntrees];

  Long64_t nentries = 0;
  for(int i = 0; i < Ntrees; ++i){
    ch[i] = new TChain(trees[i]);
    ch[i]->Add(fname);
    std::cout << "Tree loaded : " << trees[i] << std::endl;
    std::cout << "Entries : " << ch[i]->GetEntries() << std::endl;

    // If the number of entries in this tree is different from other
    // trees there is a problem. Quit and inform the user without
    // producing output.
    if(failOnError)
    {
      if(strcmp(trees[i],"HiForest/HiForestVersion") == 0) continue;
      if(i == 0) nentries = ch[i]->GetEntries();
      else if (nentries != ch[i]->GetEntries())
      {
	std::cout << "ERROR: number of entries in this tree does not match." << std::endl;
	std::cout << "First inconsistent file: " <<ch[i]->GetFile()->GetName()<<std::endl;
	std::cout << "Exiting. Please check input." << std::endl;
	return;
      }
    }
    else
    {
      std::cout << "WARN: error checking disabled" << std::endl;
    }
  }

  TFile* file = new TFile(outfile, "RECREATE");

  for(int i = 0; i < Ntrees; ++i)
  {
    file->cd();
    std::cout << trees[i] << std::endl;
    if (i==0)
    {
      file->mkdir(dir[i])->cd();
    }
    else
    {
      if ( dir[i] != dir[i-1] )
  	file->mkdir(dir[i])->cd();
      else
  	file->cd(dir[i]);
    }
    ch[i]->Merge(file,0,"keep");
    delete ch[i];
  }
  //file->Write();
  file->Close();

  std::cout << "Done. Output: " << outfile << std::endl;
}
开发者ID:jiansunpurdue,项目名称:RunIIAna,代码行数:99,代码来源:mergeForest.C

示例11: RunPlots

void RunPlots(const char* data_dir, int first_run, const int n_runs) {

  gROOT->Reset();
  gROOT->SetStyle("Plain");
  gStyle->SetCanvasBorderMode(0); // turn off canvas borders

  TCanvas* c1 = new TCanvas("c1", "c1");

  // Go through the runs and create a PDF for each one
  for (int iRun = 0; iRun < n_runs; ++iRun) {

    // Open up the file for this run
    std::stringstream filename;
    filename << data_dir << "/hist/hist0" << first_run + iRun << ".root";
    TFile* file = new TFile(filename.str().c_str(), "READ");

    // Create the output PDF file to save all the plots to
    std::stringstream basepdfname;
    basepdfname << "DQ_LowLevel_RunPlots_Run0" << first_run + iRun << ".pdf";
    
    std::string openpdfname = basepdfname.str() + "[";
    std::string closepdfname = basepdfname.str() + "]";
    c1->Print(openpdfname.c_str());

    TIter nextFileKey(file->GetListOfKeys()); // get the list of keys in this file
    TKey *fileKey;
        
    while (fileKey = (TKey*)nextFileKey()) {

      // Get the directory for low-level data quality plots
      if (strcmp(fileKey->ReadObj()->ClassName(), "TDirectoryFile") == 0) {
	// Check that the directory has the correct name
	if (strcmp(fileKey->ReadObj()->GetName(), "DataQuality_LowLevel") == 0) {

	  TDirectoryFile* dir = (TDirectoryFile*) fileKey->ReadObj();

	  TIter nextDirKey(dir->GetListOfKeys()); // get the list of keys in the directory (all histograms should be in this folder)
	  TKey *dirKey;
        
	  while (dirKey = (TKey*)nextDirKey()) {
	    
	    if (strcmp(dirKey->ReadObj()->ClassName(), "TH1F") == 0) {

	      // Get histogram and print
	      TH1F* hist = (TH1F*) dirKey->ReadObj();
	      hist->Draw();
	      c1->Update();
	      c1->Print(basepdfname.str().c_str());
	    }
	    else if (strcmp(dirKey->ReadObj()->ClassName(), "TH2F") == 0) {

	      TH2F* hist = (TH2F*) dirKey->ReadObj();
	      
	      // Search through the histogram name
	      if (strstr(hist->GetName(), "PulseShapes") != NULL) {
		c1->SetLogz();
	      }

	      hist->Draw("COLZ");
	      c1->Update();
	      c1->Print(basepdfname.str().c_str());
	    } // end if statements

	    // Undo any c1 log scales
	    c1->SetLogz(0);
	  } // end while loop through histograms in directory
	} // end if correctly name directory
      } // end if the key is a directory
    } // end while loop through keys in file

    // Close the PDF file
    c1->Print(closepdfname.c_str());

  } // end loop through each run file
}
开发者ID:alcap-org,项目名称:AlcapDAQ,代码行数:75,代码来源:RunPlots.C


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