Example #1
0
//________________________________________________________________________________
void MergeSimpleHistogramFile( const Char_t *TargetName=0, const Char_t *inputFilesPattern=0) 
{
   // This is the deprecated version. To be dleted after debugging
  if (TargetName && TargetName[0] && inputFilesPattern && inputFilesPattern[0] ) {
    TStopwatch time;
    Int_t fileCounter = 0;
    Int_t histogramCounter = 0;
     // Create the output file
     TFile *outFile = TFile::Open(TargetName,"RECREATE");     
     TDirIter listOfFiles(inputFilesPattern);
     const char *fileName = 0;
     while ( (fileName =  listOfFiles.NextFile() ) ) {
        printf(".");
        fileCounter++;
        TFileIter file(fileName);
        TObject *obj = 0;
        while ( (obj = *file) ) {
           if ( obj->IsA()->InheritsFrom( "TH1" ) ) {
              // descendant of TH1 -> merge it
              // printf("Merging histogram: %s\n",obj->GetName() ); 
//              std::cout << "Merging histogram " << obj->GetName() << std::endl;
              TH1 *h1 = (TH1*)obj;
              TH1 *dstHistogram = 0;
              // Check whether we found the new histogram
              if ( (dstHistogram = (TH1 *)outFile->FindObject(h1->GetName()))) {
                 // Accumulate  the  histogram
                  dstHistogram->Add(h1);
                  delete h1;  // Optional, to reduce the memory consumption
                  printf("+");
              } else {
                // First time - move the histogram
                h1->SetDirectory(outFile);
                printf(" The new Histogram found: %s \n", h1->GetName() );
                histogramCounter++;
              }
           } else {
              // printf("Skipping object: %s\n",obj->GetName() ); 
           }
           ++file;
        }
              
     }
     printf("\n Finishing  . . . \n");
     outFile->ls();
     outFile->Write();
     outFile->Close();     
     delete outFile;
     printf(" Total files merged: %d \n", fileCounter);
     printf(" Total histograms merged: %d \n", histogramCounter);
     time.Print("Merge");
  } else {
     printf("\nUsage: root MergeHistogramFile.C(\"DestinationFileName\",\"InputFilesPattern\",kTRUE)\n");     
     printf("------        where InputFilesPattern  ::= <regexp_pattern_for_the_input_files>|@indirect_file_list\n");
     printf("                    indirect_file_list ::= a text file with the list of the files\n");
     printf("                    indirect_file_list can be create by the shell command:\n");
     printf("                         ls -1 --color=never *.root>indirect_file_list \n\n");
  }
}
Example #2
0
TH1D *GetHisto(float ptcut = 0.15, char *name, char *filename, float etacut){
  TFile *file = new TFile(filename);
  TList *list = file->FindObject("out2");
  //TH2F *allhad = ((TH2F*) out2->FindObject("EtSimulatedAllHadron"))->Clone("allhad");
  TH2F *allhad = ((TH2F*) out2->FindObject("EtSimulatedChargedHadron"))->Clone("allhad");
  TH2F *ptlow = ((TH2F*) out2->FindObject("EtSimulatedChargedHadronAssumingNoPt"))->Clone("ptlow");
  TH2F *pthigh;
  if(ptcut>0.14){//TPC cut off
    (TH2F*)pthigh =(TH2F*) ((TH2F*) out2->FindObject("EtSimulatedChargedHadronAssumingPtTPCCut"))->Clone("pthigh");
  }
  else{
    (TH2F*)pthigh =(TH2F*) ((TH2F*) out2->FindObject("EtSimulatedChargedHadronAssumingPtITSCut"))->Clone("pthigh");
  }

  int lowbin = allhad->GetXaxis()->FindBin(0.0);//make sure we don't accidentally get the wrong bin
  int highbin = allhad->GetXaxis()->FindBin(ptcut);
  int nbins = allhad->GetXaxis()->GetNbins();
  cout<<"Projecting from "<<allhad->GetXaxis()->GetBinLowEdge(lowbin)<<" to "<<allhad->GetXaxis()->GetBinLowEdge(highbin+1)<<endl;
  cout<<"Projecting from "<<allhad->GetXaxis()->GetBinLowEdge(lowbin)<<" to "<<allhad->GetXaxis()->GetBinLowEdge(nbins)<<endl;

  //allhad->Sumw2();


  TH1D *numerator = allhad->ProjectionY("name",lowbin,highbin);
  TH1D *denominator = allhad->ProjectionY("denominator",lowbin,nbins);
  TH1D *numeratorLow = ptlow->ProjectionY("nameLow",lowbin,highbin);
  TH1D *denominatorLow = allhad->ProjectionY("denominatorLow",highbin,nbins);
  denominatorLow->Add(ptlow);
  TH1D *numeratorHigh = pthigh->ProjectionY("nameHigh",lowbin,highbin);
  TH1D *denominatorHigh = allhad->ProjectionY("denominatorHigh",highbin,nbins);
  denominatorHigh->Add(pthigh);

  numerator->Divide(denominator);
  numeratorLow->Divide(denominatorLow);
  numeratorHigh->Divide(denominatorHigh);

  TF1 *funcLow = new TF1("funcLow","[0]",-.7,.7);
  funcLow->SetParameter(0,0.01);
  numeratorLow->Fit(funcLow);
  TF1 *func = new TF1("func","[0]",-.7,.7);
  func->SetParameter(0,0.02);
  numerator->Fit(func);
  TF1 *funcHigh = new TF1("funcHigh","[0]",-.7,.7);
  funcHigh->SetParameter(0,0.02);
  numeratorHigh->Fit(funcHigh);

  mean = 1.0-func->GetParameter(0);
  lowbound = 1.0-funcHigh->GetParameter(0);
  highbound = 1.0-funcLow->GetParameter(0);
  cout<<"fpTcut = "<<mean<<","<<lowbound<<","<<highbound<<endl;
  cout<<"1/fpTcut = "<<1.0/mean<<","<<1.0/lowbound<<","<<1.0/highbound<<endl;
  //cout<<"fpTcut = "<<mean<<"-"<<mean-lowbound<<"+"<<highbound-mean<<endl;
  syserr = highbound-mean;
  if(mean-lowbound>syserr) syserr = mean-lowbound;
  cout<<Form("%2.4f^{+%2.4f}_{-%2.4f}",mean,highbound-mean,mean-lowbound)<<endl;
  cout<<"latex here ";
  cout<<Form("%2.4f \\pm %2.4f",mean,syserr)<<endl;
  cout<<"1/fpTcut = "<<1.0/mean<<"+"<<1.0/lowbound-1.0/mean<<"-"<<1.0/mean-1.0/highbound<<endl;
  numerator->SetYTitle("E_{T}^{had, p_{T}<cut-off}/E_{T}^{had, all p_{T}}");
  numerator->GetYaxis()->SetTitleOffset(1.);
  numerator->GetYaxis()->SetTitleSize(0.08);
  numerator->GetYaxis()->SetLabelSize(0.05);
  numerator->GetXaxis()->SetTitleSize(0.08);
  numerator->GetXaxis()->SetLabelSize(0.05);
  numerator->GetXaxis()->SetTitleOffset(.6);
  //numerator->Rebin(2);
  //numerator->Scale(0.5);
  //numerator->Draw("e");
  return numerator;

}