Ejemplo n.º 1
0
void ScaleAll1file( TDirectory *target, FileInfo_t& source ) {

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

  source.fp->cd( path );
  TDirectory *current_sourcedir = gDirectory;

  // loop over all keys in this directory

  bool newdir = true;

  TIter nextkey( current_sourcedir->GetListOfKeys() );
  TKey *key;
  while ( (key = (TKey*)nextkey())) {

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

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

      if (newdir) {
	newdir=false;
	cout << "Scaling histograms: " << endl;
      }

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

      h1->Scale(source.weight);

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

      newdir = true;

      cout << "\n=====> Found subdirectory " << obj->GetName();
      cout << "<=====\n" << 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
      ScaleAll1file( newdir, source );

    } else {

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

    // now write the scaledd histogram (which is "in" obj) to the target file
    // note that this will just store obj in the current directory level,
    // which is not persistent until the complete directory itself is stored
    // by "target->Write()" below
    if ( obj ) {
      target->cd();

      obj->Write( key->GetName() );
    }

  } // while ( ( TKey *key = (TKey*)nextkey() ) )

  cout << endl;

  // save modifications to target file
  target->Write();

}
Ejemplo n.º 2
0
void drawLoop( TDirectory *target, TList *sourcelist, TCanvas *c1 )
{

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

  TString sysString(path);sysString.Prepend(baseName->Data());

  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
  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" ) 
	 && !obj->IsA()->InheritsFrom("TH2") ) {

      // descendant of TH1 -> merge it
      gLegend = new TLegend(.7,.15,.95,.4,"");
      gLegend->SetHeader(gDirectory->GetName());
      Color_t color = 1;
      Style_t style = 22;
      TH1 *h1 = (TH1*)obj;
      h1->SetLineColor(color);
      h1->SetMarkerStyle(style);
      h1->SetMarkerColor(color);
      h1->Draw();
      TString tmpName(first_source->GetName());
      gLegend->AddEntry(h1,tmpName,"LP");
      c1->Update();

      // 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 );
      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();
	   color++;
	   style++;
	   h2->SetLineColor(color);
	   h2->SetMarkerStyle(style);
	   h2->SetMarkerColor(color);
           h2->Draw("same");
	   TString tmpName(nextsource->GetName());
	   gLegend->AddEntry(h2,tmpName,"LP");
	   gLegend->Draw("same");
	   c1->Update();
           //- delete h2;
        }

        nextsource = (TFile*)sourcelist->After( nextsource );
      }
    }
    else if ( obj->IsA()->InheritsFrom( "TH2" ) ) {
      // descendant of TH2 -> merge it
      gLegend = new TLegend(.85,.15,1.0,.30,"");
      gLegend->SetHeader(gDirectory->GetName());
      Color_t color = 1;
      Style_t style = 22;
      TH2 *h1 = (TH2*)obj;
      h1->SetLineColor(color);
      h1->SetMarkerStyle(style);
      h1->SetMarkerColor(color);
      h1->Draw();
      TString tmpName(first_source->GetName());
      gLegend->AddEntry(h1,tmpName,"LP");
      c1->Update();

      // 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 );
      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) {
           TH2 *h2 = (TH2*)key2->ReadObj();
	   color++;
	   style++;
	   h2->SetLineColor(color);
	   h2->SetMarkerStyle(style);
	   h2->SetMarkerColor(color);
	   h2->Draw("same");
	   TString tmpName(nextsource->GetName());
	   gLegend->AddEntry(h2,tmpName,"LP");
	   gLegend->Draw("same");
	   c1->Update();
           //- delete h2;
        }
        nextsource = (TFile*)sourcelist->After( nextsource );
      }
    }
    else if ( obj->IsA()->InheritsFrom( "TGraph" ) ) {
      obj->IsA()->Print();
      gLegend = new TLegend(.7,.15,.95,.4,"");
      gLegend->SetHeader(gDirectory->GetName());
      Color_t color = 1;
      Style_t style = 22;
      TGraph *h1 =(TGraph*)obj;
      h1->SetLineColor(color);
      h1->SetMarkerStyle(style);
      h1->SetMarkerColor(color);
      h1->GetHistogram()->Draw();
      h1->Draw();
      TString tmpName(first_source->GetName());
      gLegend->AddEntry(h1,tmpName,"LP");
      c1->Update();

      // 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 );
      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) {
           TGraph *h2 = (TGraph*)key2->ReadObj();
	   color++;
	   style++;
	   h2->SetLineColor(color);
	   h2->SetMarkerStyle(style);
	   h2->SetMarkerColor(color);
           h2->Draw("same");
	   TString tmpName(nextsource->GetName());
	   gLegend->AddEntry(h2,tmpName,"LP");
	   gLegend->Draw("same");
	   c1->Update();
           //- delete h2;
        }

        nextsource = (TFile*)sourcelist->After( nextsource );
      }
    }
    else if ( obj->IsA()->InheritsFrom( "TTree" ) ) {
      std::cout << "I don't draw trees" << std::endl;
    } else if ( obj->IsA()->InheritsFrom( "TDirectory" ) ) {
      // it's a subdirectory
      std::cout << "Found subdirectory " << obj->GetName() << std::endl;

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

      // create a new subdir of same name in the file system
      TString newSysString(sysString+"/"+obj->GetName());
      if(makeGraphic) gSystem->mkdir(newSysString.Data(),kTRUE);

      // 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
      drawLoop( newdir, sourcelist, c1 );

    } else {
      // object is of no type that we know or can handle
      std::cout << "Unknown object type, name: " 
           << obj->GetName() << " title: " << obj->GetTitle() << std::endl;
    }
 
    // now write the merged TCanvas (which is "in" obj) to the target file
    // note that this will just store obj in the current directory level,
    // which is not persistent until the complete directory itself is stored
    // by "target->Write()" below
    if ( obj ) {
      target->cd();

	if ( obj->IsA()->InheritsFrom( "TH1") || obj->IsA()->InheritsFrom("TGraph")) {
	  //	 && !obj->IsA()->InheritsFrom("TH2") ) {
	  TString newName(obj->GetName());
	  newName.ReplaceAll("(",1,"_",1);
	  newName.ReplaceAll(")",1,"_",1);
	  c1->SetName(newName);
	  c1->Write( c1->GetName(),TObject::kOverwrite );
	  
	  if(makeGraphic) {
	    if (gROOT->IsBatch()) {
	      c1->Print("temp.eps");
	      gSystem->Exec("pstopnm -ppm -xborder 0 -yborder 0 -portrait temp.eps");
	      char tempCommand[200];
	      sprintf(tempCommand,"ppmtogif temp.eps001.ppm > %s/%s.gif",sysString.Data(),c1->GetName());
	      gSystem->Exec(tempCommand);
	    } else {	    
	      c1->Print(sysString + "/" + TString(c1->GetName())+".gif");
	    }
	  }
	  
	}
    }
    //if(gLegend) delete gLegend;
  } // while ( ( TKey *key = (TKey*)nextkey() ) )

  // save modifications to target file
  target->SaveSelf(kTRUE);
  TH1::AddDirectory(status);
}
Ejemplo n.º 3
0
void MergeRootfile( TFile *source ) {
   TString path(gDirectory->GetPath());
   source->cd( path );
   cerr << "Browsing " << path << endl;

   //gain time, do not add the objects in the list in memory
   TH1::AddDirectory(kFALSE);

   // loop over all keys in this directory
   TIter nextkey( gDirectory->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
      TObject *obj = key->ReadObj();

      cerr << "NAME IS " << obj->GetName() << endl;

      if ( obj->IsA()->InheritsFrom( TH1::Class() ) ) {
         cerr << "   HELLO, we have the histogram " << obj->GetName() << endl;
         TH1 *h = (TH1*)obj;
         ProcessHisto(h);
      } else if ( obj->IsA()->InheritsFrom( THnBase::Class() )) {
         cerr << "   HELLO-SPARSE " << obj->GetName() << endl;
         THnBase *h = (THnBase*)obj;
         ProcessSparse(h);
      } else if ( obj->IsA()->InheritsFrom( TDirectory::Class() ) ) {
         // it's a subdirectory

         //cerr << "Found subdirectory " << obj->GetName() << endl;
	 source->cd( path + "/" + obj->GetName() );
         MergeRootfile(source);
         source->cd( path );
      } else if ( obj->IsA()->InheritsFrom( TCollection::Class() )) {
        TCollection *coll = (TCollection *)obj;
        //cerr << "List of something in " << obj->GetName() << endl;
        TIter nextelem(coll);
        TObject *elem;
        while ((elem = nextelem())) {
          if (elem->IsA()->InheritsFrom( TH1::Class() )) {
            cerr << "   HELLO, we have the histogram " << elem->GetName() << endl;
            TH1 *h = (TH1 *)elem;
            ProcessHisto(h);
          } else if (elem->IsA()->InheritsFrom( THnBase::Class() )) {
            cerr << "   HELLO-SPARSE " << elem->GetName() << endl;
            THnBase *h = (THnBase *)elem;
            ProcessSparse(h);
          }
        }
      } else {

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

   } // while ( ( TKey *key = (TKey*)nextkey() ) )
}
Ejemplo n.º 4
0
Archivo: hadd.C Proyecto: Y--/root
void MergeRootfile( TDirectory *target, TList *sourcelist ) {

   //  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::Class() ) ) {
         // descendant of TH1 -> merge it

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

         // 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 );
         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();
               h1->Add( h2 );
               delete h2;
            }

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

         // 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::Class() ) ) {
         // 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 );

      } 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,
      // which is not persistent until the complete directory itself is stored
      // by "target->Write()" below
      if ( obj ) {
         target->cd();

         //!!if the object is a tree, it is stored in globChain...
         if(obj->IsA()->InheritsFrom( TTree::Class() ))
            globChain->Merge(target->GetFile(),0,"keep");
         else
            obj->Write( key->GetName() );
      }

   } // while ( ( TKey *key = (TKey*)nextkey() ) )

   // save modifications to target file
   target->SaveSelf(kTRUE);
   TH1::AddDirectory(status);
}
Ejemplo n.º 5
0
void dataMCplots(std::string outputFolder, std::string pdfName){

  std::vector<string> infiles;
 
  TSystemDirectory *base = new TSystemDirectory("root","root");
  base->SetDirectory(outputFolder.data());
  TList *listOfFiles = base->GetListOfFiles();
  TIter fileIt(listOfFiles);
  TFile *fileH = new TFile();
  Long64_t nfiles = 0;

  while( (fileH = (TFile*)fileIt()) ){
    
    std::string fileN = fileH->GetName();
    std::string baseString = "root";
    if( fileN.find(baseString) == std::string::npos ) continue;
    infiles.push_back(Form("%s/%s",outputFolder.data(),fileN.data()));
    nfiles++;
    
  }

  TFile *f_DY100 = NULL;
  TFile *f_DY200 = NULL;
  TFile *f_DY400 = NULL;
  TFile *f_DY600 = NULL;
  TFile *f_TTbar = NULL;
  TFile *f_WW    = NULL;
  TFile *f_WZ    = NULL;
  TFile *f_ZZ    = NULL;
  TFile *f_data0 = NULL;
  TFile *f_data1 = NULL;

  Double_t xSecDY100 = 147.4;
  Double_t xSecDY200 = 40.99;
  Double_t xSecDY400 = 5.678;
  Double_t xSecDY600 = 2.198;
  Double_t xSecTTbar = 831.76;
  Double_t xSecWW    = 118.7;
  Double_t xSecWZ    = 47.13;
  Double_t xSecZZ    = 16.523;

  Double_t scaleDY100 = 0;
  Double_t scaleDY200 = 0;
  Double_t scaleDY400 = 0;
  Double_t scaleDY600 = 0;
  Double_t scaleTTbar = 0;
  Double_t scaleWW    = 0;
  Double_t scaleWZ    = 0;
  Double_t scaleZZ    = 0;

  Double_t dummy = -1;

  for(unsigned int i = 0; i < infiles.size(); i++){

    cout << "Input file: " << infiles[i] << endl;

    if( infiles[i].find("HT-100") != std::string::npos )    
      f_DY100 = getFile(infiles[i].data(), xSecDY100, &scaleDY100);

    if( infiles[i].find("HT-200") != std::string::npos )
      f_DY200 = getFile(infiles[i].data(), xSecDY200, &scaleDY200);

    if( infiles[i].find("HT-400") != std::string::npos )
      f_DY400 = getFile(infiles[i].data(), xSecDY400, &scaleDY400); 

    if( infiles[i].find("HT-600") != std::string::npos )
      f_DY600 = getFile(infiles[i].data(), xSecDY600, &scaleDY600);

    if( infiles[i].find("TT_") != std::string::npos )
      f_TTbar = getFile(infiles[i].data(), xSecTTbar, &scaleTTbar);

    if( infiles[i].find("WW_") != std::string::npos )
      f_WW = getFile(infiles[i].data(), xSecWW, &scaleWW);

    if( infiles[i].find("WZ_") != std::string::npos )
      f_WZ = getFile(infiles[i].data(), xSecWZ, &scaleWZ);

    if( infiles[i].find("ZZ_") != std::string::npos )
      f_ZZ = getFile(infiles[i].data(), xSecZZ, &scaleZZ);

    if( infiles[i].find("V12015") != std::string::npos )
      f_data0 = getFile(infiles[i].data(), dummy, &dummy);

    if( infiles[i].find("V42015") != std::string::npos )
      f_data1 = getFile(infiles[i].data(), dummy, &dummy);

  }

  setNCUStyle(true);
  
  Double_t up_height     = 0.8;
  Double_t dw_correction = 1.455;
  Double_t dw_height     = (1-up_height)*dw_correction;

  TCanvas c("c","",0,0,1000,900);
  c.Divide(1,2);

  TPad* c_up = (TPad*) c.GetListOfPrimitives()->FindObject("c_1");
  TPad* c_dw = (TPad*) c.GetListOfPrimitives()->FindObject("c_2"); 

  c_up->SetPad(0,1-up_height,1,1);
  c_dw->SetPad(0,0,1,dw_height);
  c_dw->SetBottomMargin(0.25);

  // To get the name of histograms
  
  TFile *f_ = TFile::Open(infiles[0].data());
  f_->cd();
  
  TDirectory *current_sourcedir = gDirectory;
  TIter nextkey( current_sourcedir->GetListOfKeys() );
  TKey *key;

  vector<std::string> h_name;

  while ( (key = (TKey*)nextkey()) ) {

    TObject *obj = key->ReadObj();

    if ( obj->IsA()->InheritsFrom("TH1") ) 
      h_name.push_back(obj->GetTitle());

  }

  // Draw and output
  
  for(unsigned int i = 0; i < h_name.size()-1; i++){

    if( h_name[i]=="eleHoverE" || h_name[i]=="eleMiniIsoEA" || h_name[i]=="muMiniIsoEA" )
      c_up->cd()->SetLogy(1);
    else
      c_up->cd()->SetLogy(0);
    
    TH1D *h_data = (TH1D*)(f_data1->Get(h_name[i].data()))->Clone("h_data");
    TH1D *h_bkg  = (TH1D*)(f_data1->Get(h_name[i].data()))->Clone("h_bkg");

    myPlot(((TH1D*)(f_DY100->Get(h_name[i].data()))),
	   ((TH1D*)(f_DY200->Get(h_name[i].data()))),
	   ((TH1D*)(f_DY400->Get(h_name[i].data()))),
	   ((TH1D*)(f_DY600->Get(h_name[i].data()))),
	   ((TH1D*)(f_TTbar->Get(h_name[i].data()))),
	   ((TH1D*)(f_WW->Get(h_name[i].data()))),
	   ((TH1D*)(f_WZ->Get(h_name[i].data()))),
	   ((TH1D*)(f_ZZ->Get(h_name[i].data()))),
	   ((TH1D*)(f_data0->Get(h_name[i].data()))),
	   ((TH1D*)(f_data1->Get(h_name[i].data()))),
	   scaleDY100,
	   scaleDY200,
	   scaleDY400,
	   scaleDY600,
	   scaleTTbar,
	   scaleWW,
	   scaleWZ,
	   scaleZZ,
	   h_data,
	   h_bkg);

    c_up->RedrawAxis();

    c_dw->cd();

    myRatio(h_data, h_bkg);

    c.Draw();
    
    if( i == 0 ) c.Print(Form("%s.pdf(", pdfName.data()), "pdf");
    else if( i == h_name.size()-2 ) c.Print(Form("%s.pdf)", pdfName.data()), "pdf");
    else c.Print(Form("%s.pdf", pdfName.data()), "pdf");
    
  }

}
Ejemplo n.º 6
0
void bfcread_histBranch(
 Int_t nevents=1, 
 const char *MainFile=
 "/afs/rhic.bnl.gov/star/data/samples/gstar.dst.root",
  const char *fname="qa_hist.out")
{
//
  cout << " events to process  = " << nevents << endl;
  cout << " Input File Name = " << MainFile << endl;
  cout << " Output file containing printouts = " << fname << endl;

  ofstream fout(fname);

  fout << " Running: bfcread_histBranch.C " << endl;
  fout << " events to process  = " << nevents << endl;
  fout << " Input File Name = " << MainFile << endl;
  fout << " Output file containing printouts = " << fname << endl;
  fout << endl << endl;

    gSystem->Load("St_base");
    gSystem->Load("StChain");
    gSystem->Load("StIOMaker");
    gSystem->Load("libglobal_Tables");

//  Setup top part of chain
    chain = new StChain("bfc");
    chain->SetDebug();
   
  StIOMaker *IOMk = new StIOMaker("IO","r",MainFile,"bfcTree");
  IOMk->SetDebug();
  IOMk->SetIOMode("r");
  IOMk->SetBranch("*",0,"0");                 //deactivate all branches
  IOMk->SetBranch("histBranch",0,"r"); //activate hist Branch

// --- now execute chain member functions
  chain->Init();

  TDataSet *ds=0;
  TDataSet *obj=0;

  int istat=0;
  int i=0;
  int countev=0;
  int countevhds=0;

// Event loop
EventLoop: if (i < nevents && !istat) {

    chain->Clear();
    istat = chain->Make(i);

//  count # times Make is called
    i++;

// Now look at the data in the event:
    int countObj=0;
    int countHist=0;

    if (!istat) {

    countev++;

    cout << " start event # " << countev << endl;

      ds=chain->GetDataSet("hist");
      TDataSetIter tabiter(ds);
      if (ds) {

        countevhds++;

        TDataSetIter nextHistList(ds);
        St_ObjectSet *histContainer = 0;
        TList *dirList = 0;

// loop over directories:
        while (histContainer = (St_ObjectSet *)nextHistList()) {
          dirList = (TList *) histContainer->GetObject();

	  cout << " QAInfo: found directory: " << 
                    histContainer->GetName() << endl;
	  fout << " QAInfo: found directory: " << 
                    histContainer->GetName() << endl;

          countObj++;

// Notes for future reference (if we want to generalize this...)
//    dirList is returned  0 for non-histogram file
//       in that case, use GetList instead of GetObject 

         TIter nextHist(dirList);
         TObject  *o = 0;

// loop over histograms in the directory:
          while (o= nextHist()) {
           countHist++;
           cout << " QAInfo:   Hist name: " << o->GetName() << 
                     " ==> Title: " << o->GetTitle() << endl; 
           fout << " QAInfo:   Hist name: " << o->GetName() << 
                     " ==> Title: " << o->GetTitle() << endl; 

          } // nextHist
        } // histContainer
      } // ds

    cout << " QAInfo: event # " << countev
            << ", # directories found = " << countObj 
            << ", # hist found = " << countHist
            << endl << endl;


    fout << " QAInfo: event # " << countev
            << ", # directories found = " << countObj 
            << ", # hist found = " << countHist
            << endl << endl;


    } // istat

    else   // if (istat)
      {
      cout << "Last event processed. Status = " << istat << endl;
    }


    goto EventLoop;
} //EventLoop

  cout << endl;
  cout << "QAInfo: End of Job " << endl; 
  cout << "QAInfo: # times Make called = " << i << endl;
  cout << "QAInfo:  # events read = " << countev << endl;
  cout << "QAInfo:   # events with hist dataset = " << countevhds << endl;

  fout << endl;
  fout << "QAInfo: End of Job " << endl;
  fout << "QAInfo: # times Make called = " << i << endl;
  fout << "QAInfo:  # events read = " << countev << endl;
  fout << "QAInfo:   # events with hist dataset = " << countevhds << endl;

 chain->Finish();   
}
Ejemplo n.º 7
0
void generatePlots(Files *inputs, const string &path)
{
    Files::const_iterator first_source = inputs->begin();
    TDirectory *folder = dynamic_cast<TDirectory *>(first_source->second->Get(path.c_str()));
    if (!folder)
    {
        cerr << "Failed to extract folder: " << path << endl;

        return;
    }
    //
    //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
    TIter nextkey(folder->GetListOfKeys() );

    for(TKey *key, *oldkey=0; 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
        //
        TObject *obj = key->ReadObj();

        if ( obj->IsA()->InheritsFrom(TH1::Class()))
        {
            cout << obj->GetName() << endl;

            TCanvas *canvas = new TCanvas();

            canvas->SetWindowSize(640, 480);

            THStack *stack = new THStack();
            TLegend  *legend = new TLegend(.6, .98, .98, .58);
            legend->SetBorderSize(1);
            legend->SetLineStyle(1);
            legend->SetTextFont(43);
            legend->SetTextSizePixels(12);
            legend->SetFillColor(0);

            TH1 *h1 = dynamic_cast<TH1*>(obj);
            legend->AddEntry(h1, style(h1, first_source->first).c_str(), "pl");
            h1->Scale(1.0 / h1->Integral());

            stack->Add(h1);

            // loop over all source files and add the content of the
            // correspondant histogram to the one pointed to by "h1"
            for(Files::const_iterator input = ++inputs->begin();
                    inputs->end() != input;
                    ++input)
            {
                TH1 *h2 = dynamic_cast<TH1*>(input->second->Get((path + "/" + obj->GetName()).c_str()));
                if (!h2)
                {
                    cerr << "Failed to extract plot from input: " << endl;

                    continue;
                }

                h2->Scale(1. / h2->Integral());
                legend->AddEntry(h2, style(h2, input->first).c_str(), "pl");
                stack->Add(h2);
            }

            stack->Draw("h nostack");
            legend->Draw();
            stack->GetXaxis()->SetTitle(h1->GetXaxis()->GetTitle());

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

    // save modifications to target file
    TH1::AddDirectory(status);
}
Ejemplo n.º 8
0
//-----------------------------------------------------------------------------
StatusCode
RootHistCnv::RDirectoryCnv::fillObjRefs(IOpaqueAddress* pAddr,DataObject* pObj)  {
  MsgStream log(msgSvc(), "RDirectoryCnv");
  IRegistry* pReg = pObj->registry();
  std::string full  = pReg->identifier();
  const std::string& fname = pAddr->par()[0];

  TFile *tf;
  findTFile(full,tf).ignore();

  // cd to TFile:
  setDirectory(full);
  TIter nextkey(gDirectory->GetListOfKeys());
  while (TKey *key = (TKey*)nextkey()) {
    IOpaqueAddress* pA = 0;
    TObject *obj = key->ReadObj();
    std::string title = obj->GetTitle();
    std::string sid = obj->GetName();
    std::string f2 = full + "/" + sid;
    int idh = ::strtol(sid.c_str(),NULL,10);
    // introduced by Grigori Rybkine
    std::string clname = key->GetClassName();
    std::string clnm = clname.substr(0,3);
    TClass* isa = obj->IsA();
    if (isa->InheritsFrom("TTree")) {
      createAddress(full, CLID_ColumnWiseTuple, idh, obj, pA).ignore();
      TTree* tree = (TTree*) obj;
      tree->Print();
      log << MSG::DEBUG << "Reg CWNT \"" << obj->GetTitle()
       	  << "\" as " << f2 << endmsg;
      title = "/" + sid;
    } else if (isa->InheritsFrom("TDirectory")) {
      createAddress(full,CLID_NTupleDirectory, title, obj, pA).ignore();
    } else if ( isa == TProfile::Class() ) {
      createAddress(full,CLID_ProfileH,idh,obj,pA).ignore();
      title = sid;
    } else if ( isa == TProfile2D::Class() ) {
      createAddress(full,CLID_ProfileH2,idh,obj,pA).ignore();
      title = sid;
    } else if ( isa == TH1C::Class() ) {
      createAddress(full,CLID_H1D,idh,obj,pA).ignore();
      title = sid;
    } else if ( isa == TH1S::Class() ) {
      createAddress(full,CLID_H1D,idh,obj,pA).ignore();
      title = sid;
    } else if ( isa == TH1I::Class() ) {
      createAddress(full,CLID_H1D,idh,obj,pA).ignore();
      title = sid;
    } else if ( isa == TH1F::Class() ) {
      createAddress(full,CLID_H1D,idh,obj,pA).ignore();
      title = sid;
    } else if ( isa == TH1D::Class() ) {
      createAddress(full,CLID_H1D,idh,obj,pA).ignore();
      title = sid;
    } else if ( isa == TH2C::Class() ) {
      createAddress(full,CLID_H2D,idh,obj,pA).ignore();
      title = sid;
    } else if ( isa == TH2S::Class() ) {
      createAddress(full,CLID_H2D,idh,obj,pA).ignore();
      title = sid;
    } else if ( isa == TH2I::Class() ) {
      createAddress(full,CLID_H2D,idh,obj,pA).ignore();
      title = sid;
    } else if ( isa == TH2F::Class() ) {
      createAddress(full,CLID_H2D,idh,obj,pA).ignore();
      title = sid;
    } else if ( isa == TH2D::Class() ) {
      createAddress(full,CLID_H2D,idh,obj,pA).ignore();
      title = sid;
    } else if ( isa == TH3C::Class() ) {
      createAddress(full,CLID_H3D,idh,obj,pA).ignore();
      title = sid;
    } else if ( isa == TH3S::Class() ) {
      createAddress(full,CLID_H3D,idh,obj,pA).ignore();
      title = sid;
    } else if ( isa == TH3I::Class() ) {
      createAddress(full,CLID_H3D,idh,obj,pA).ignore();
      title = sid;
    } else if ( isa == TH3F::Class() ) {
      createAddress(full,CLID_H3D,idh,obj,pA).ignore();
      title = sid;
    } else if ( isa == TH3D::Class() ) {
      createAddress(full,CLID_H3D,idh,obj,pA).ignore();
      title = sid;
    } else {
      log << MSG::ERROR << "Encountered an unknown object with key: "
      	  << obj->GetName() << " in ROOT file " << fname << endmsg;
      return StatusCode::FAILURE;
    }
    if ( 0 != pA )    {
      StatusCode sc = dataManager()->registerAddress(pReg, title, pA);
      if ( !sc.isSuccess() )  {
        log << MSG::ERROR << "Failed to register address for " << full  << endmsg;
        return sc;
      }
      log << MSG::VERBOSE << "Created address for " << clnm
          << "'" << title << "' in " << full << endmsg;
    }
  }
  return StatusCode::SUCCESS;
}