Exemplo n.º 1
0
void run(int nEvents = 100000) {

    TChain* fChain = new TChain("T");

    ifstream sourceFiles("input.txt");
    char line[128];
    int  count = 0;

    while (sourceFiles >> line) {
        fChain->Add(line);      
        ++count;
    }

    cout << count << " files added!" << endl;
    sourceFiles.close();

    TStopwatch timer;
    timer.Start();

    fChain->Process("adcAnalyzer.C+", "", 8*nEvents, 0);

    timer.Stop();

    cout << "\n\nDone!" << endl;
    cout << "CPU Time : " << timer.CpuTime() << " s (total), " << timer.CpuTime()/nEvents << " s (per event)" << endl;
    cout << "RealTime : " << timer.RealTime() << " s (total), " << timer.RealTime()/nEvents << " s (per event)" << endl;
    cout << "\n";
}
Exemplo n.º 2
0
Float_t read_tree(const char *filename = "data.root", Double_t bytes = 10000000)
{
        printf("Reading events from a root tree \n");
        
        TFile *filein = new TFile(filename,"READ");     
        if ( filein->IsZombie() ) {
                printf("Cannot open file \n");
                return 0.0;
        }
        
        Int_t nbgamma; Int_t e[1000]; // up to 1000 energies ..should be ok 
        
        TTree *treein; 
        treein = (TTree *)filein->Get("TEST");
        if ( treein == NULL ) return 0;
        else {
                treein->SetBranchAddress("mult",&nbgamma); 
                treein->SetBranchAddress("e",&e);
        }

        // write events and compute the needed time
        TStopwatch watch; 
        watch.Start();
        treein->Draw("e","","goff");
        watch.Stop();

        cout << "  --> Reading rate " << bytes / (1024*1024*watch.RealTime()) << " MB/s"<< endl ;
        
        filein->Close(); delete filein; return bytes / (1024*1024*watch.RealTime()) ;
}
Exemplo n.º 3
0
bool TTimeHists::Run()
{
   // run all tests with current settings, and check for identity of content.

   Double_t check[2];
   Long64_t rep[2];
   for (int h = 0; h < 2; ++h) {
      rep[h] = 0;
      SetupValues();
      try {
         TStopwatch w;
         w.Start();
         SetupHist((EHist) h);
         w.Stop();
         do {
            w.Start(kFALSE);
            Fill((EHist) h);
            check[h] = Check((EHist) h);
            w.Stop();
            ++rep[h];
         } while ((!h && w.RealTime() < 0.1)
            || (h && rep[0] > 0 && rep[1] < rep[0]));

         fTime[h][0] = (1.* fNum * rep[h]) / w.RealTime() / 1E6;
         fTime[h][1] = (1.* fNum * rep[h]) / w.CpuTime() / 1E6;

         if (h == 1 && (fTime[h][0] > 1E20 || fTime[h][1] > 1E20)) {
            do {
               // some more cycles:
               w.Start(kFALSE);
               Fill((EHist) h);
               Check((EHist) h);
               w.Stop();
               ++rep[h];
            } while (w.RealTime() < 0.1);

            fTime[h][0] = (1.* fNum * rep[h]) / w.RealTime() / 1E6;
            fTime[h][1] = (1.* fNum * rep[h]) / w.CpuTime() / 1E6;
         }

         if (fTime[h][0] > 1E20) fTime[h][0] = 1E20;
         if (fTime[h][1] > 1E20) fTime[h][1] = 1E20;
      }
      catch (std::exception&) {
         fTime[h][0] = fTime[h][1] = -1.;
         check[h] = -1.; // can never be < 1 without exception
         rep[h] = -1;
      }
   }
   if (check[0] != check[1])
      if (check[0] != -1.)
         printf("ERROR: mismatch of histogram (%g) and sparse histogram (%g) for dim=%d, bins=%d!\n",
                check[0], check[1], fDim, fBins);
      // else
      //   printf("ERROR: cannot allocate histogram for dim=%d, bins=%d - out of memory!\n",
      //          fDim, fBins);
   return (check[0] == check[1]);
}
Exemplo n.º 4
0
void read() {

   TRandom R;
   TStopwatch timer;

   TFile f1("mathcoreVectorIO_1.root");

   // create tree
   TTree *t1 = (TTree*)f1.Get("t1");

   XYZTVector *v1 = 0;
   t1->SetBranchAddress("LV branch",&v1);

   timer.Start();
   int n = (int) t1->GetEntries();
   std::cout << " Tree Entries " << n << std::endl;
   double etot=0;
   for (int i = 0; i < n; ++i) {
      t1->GetEntry(i);
      etot += v1->Px();
      etot += v1->Py();
      etot += v1->Pz();
      etot += v1->E();
   }
   timer.Stop();
   std::cout << " Time for new Vector " << timer.RealTime() << "  " << timer.CpuTime() << std::endl;

   std::cout << " TOT average : n = " << n << "\t " << etot/double(n) << endl;

   // create tree with old LV
   TFile f2("mathcoreVectorIO_2.root");
   TTree *t2 = (TTree*)f2.Get("t2");

   TLorentzVector * v2 = 0;
   t2->SetBranchAddress("TLV branch",&v2);

   timer.Start();
   n = (int) t2->GetEntries();
   std::cout << " Tree Entries " << n << std::endl;
   etot = 0;
   for (int i = 0; i < n; ++i) {
      t2->GetEntry(i);
      etot  += v2->Px();
      etot  += v2->Py();
      etot  += v2->Pz();
      etot  += v2->E();
   }

   timer.Stop();
   std::cout << " Time for old Vector " << timer.RealTime() << "  " << timer.CpuTime() << endl;
   std::cout << " TOT average:\t" << etot/double(n) << endl;
}
Exemplo n.º 5
0
void MCMonitoring(
    const UInt_t num_events,
    const TString base_name,
    const TString base_path = "."
)
{
    TStopwatch timer;
    timer.Start();


    const TString sim_file = base_path + "/r3bsim." + base_name + ".root";
    const TString par_file = base_path + "/r3bpar." + base_name + ".root";
    const TString out_file = base_path + "/mcmon."  + base_name + ".root";

    FairRunAna* run = new FairRunAna();
    run->SetInputFile(sim_file);
    run->SetOutputFile(out_file);
    ConnectParFileToRuntimeDb(par_file, run->GetRuntimeDb());

    run->AddTask(new R3BNeulandMCMon());

    run->Init();
    run->Run(0, num_events);


    timer.Stop();

    cout << endl;
    cout << "Macro finished succesfully!" << endl;
    cout << "Output file writen: " << out_file << endl;
    cout << "Parameter file writen: " << par_file << endl;
    cout << "Real time: " << timer.RealTime() << "s, CPU time: " << timer.CpuTime() << "s" << endl;
    cout << endl;
}
Exemplo n.º 6
0
void read() {




  TRandom R;
  TStopwatch timer;



  TFile f1("mathcoreVectorIO_F.root");

  // create tree
  TTree *t1 = (TTree*)f1.Get("t1");

  XYZTVectorF *v1 = 0;
  t1->SetBranchAddress("LV branch",&v1);

  timer.Start();
  int n = (int) t1->GetEntries();
  std::cout << " Tree Entries " << n << std::endl;
  double etot=0;
  for (int i = 0; i < n; ++i) {
    t1->GetEntry(i);
    etot += v1->E();
  }


  timer.Stop();
  std::cout << " Time for new Float Vector " << timer.RealTime() << "  " << timer.CpuTime() << std::endl;

  std::cout << " E average" << n<< "  " << etot << "  " << etot/double(n) << endl;


}
void ana_Main_MC_arg_winscan(string which_MC_to_use, string MCFileLocation) {

	gSystem->Load("libSusyEvent.so");

	// Look ../jec/JetMETObjects/README
	gSystem->Load("../jec/lib/libJetMETObjects.so");

	// Printing utility for ntuple variables
	gROOT->LoadMacro("SusyEventPrinter.cc+");

	// Main analysis code
	gROOT->LoadMacro("SusyMainAna_MC_arg_windowscan.cc+");

	// chain of inputs
	TChain* chain = new TChain("susyTree");

	//////////////// MC files /////////////////
	//MCpoint* thisMCpoint = setupMCpoint(which_MC_to_use);
	chain->Add(MCFileLocation.data());
	//chain->Add(thisMCpoint->filepath.c_str());


	//chain->Add("../susyEvents_AB_1M_ho200_v2.root");
	//chain->Add("../susyEvents_newNatural.root"); //last used!!
	//chain->Add("/eos/uscms/store/user/abarker/MC/newNat350_225/MC_AB_2500k_NEWnaturalHiggsinoNLSPout_mst_350_M3_5025_mu_225.root");//same thing as ../susyEvents_newNatural.root
	//chain->Add("/eos/uscms/store/user/abarker/MC/st_250_ho_150/MC_AB_2500k_st_250_ho_150.root");
	//chain->Add("/eos/uscms/store/user/abarker/MC/st_250_ho_200/MC_AB_2500k_st_250_ho_200.root");
	//chain->Add("/eos/uscms/store/user/abarker/MC/st_350_ho_200/MC_AB_2500k_mst_350_mu_200.root");
	//chain->Add("/eos/uscms/store/user/abarker/MC/ho_140/MC_AB_2500k_ho_140.root");
	//chain->Add("/eos/uscms/store/user/abarker/MC/ho_200/MC_AB_2500k_ho_200.root");
	//chain->Add("../susyEvents_newNatural.root");
	//chain->Add("dcache:/pnfs/cms/WAX/resilient/abarker/MC/MC_AB_2500k_NEWnaturalHiggsinoNLSPout_mst_350_M3_5025_mu_225.root");
	//chain->Add("dcache:/pnfs/cms/WAX/resilient/abarker/MC/MC_AB_2500k_st_250_ho_150.root");
	//chain->Add("dcache:/pnfs/cms/WAX/resilient/abarker/MC/MC_AB_2500k_st_250_ho_200.root");
	//chain->Add("dcache:/pnfs/cms/WAX/resilient/abarker/MC/MC_AB_2500k_mst_350_mu_200.root");
	//chain->Add("dcache:/pnfs/cms/WAX/resilient/abarker/MC/MC_AB_2500k_ho_140.root");
	//chain->Add("dcache:/pnfs/cms/WAX/resilient/abarker/MC/MC_AB_2500k_ho_200.root");


	SusyMainAna_MC_arg_windowscan* sea = new SusyMainAna_MC_arg_windowscan(chain);

	// configuration parameters
	// any values given here will replace the default values
	sea->SetDataset("ttbar_relval");        // dataset name
	sea->SetPrintInterval(1e4);             // print frequency
	sea->SetPrintLevel(0);                  // print level for event contents
	sea->SetUseTrigger(false);
	sea->SetFilter(false);                  // filter events passing final cuts
	sea->SetProcessNEvents(-1);             // number of events to be processed

	TStopwatch ts;
	ts.Start();

	sea->Loop(which_MC_to_use);

	ts.Stop();
	std::cout << "RealTime : " << ts.RealTime()/60.0 << " minutes" << std::endl;
	std::cout << "CPUTime  : " << ts.CpuTime()/60.0 << " minutes" << std::endl;

}
Exemplo n.º 8
0
Float_t write_tree(const char *filename = "data.root", Int_t nbevents = 10000000, Int_t compression = 0)
{
        printf("Writing %d events in a root tree with compression level %d \n",nbevents,compression);
        
        TFile *fileout = new TFile(filename,"recreate");        
        if ( fileout->IsZombie() ) {
                printf("Cannot open file \n");
                return 0.0;
        }
        fileout->SetCompressionLevel(compression);
        
        Double_t wbytes = 0.0;
        Int_t nbgamma; Int_t e[1000]; 
        for (Int_t i = 1; i < 1000; i++) e[i] = 200*i;
        
        TTree *treeout; 
        treeout = new TTree("TEST","TEST");
        treeout->Branch("mult",&nbgamma,"nbgamma/I"); treeout->Branch("e",e,"e[nbgamma]/I");
                
        // write events and compute the needed time
        TStopwatch watch; 
        watch.Start();
        for (int i = 0; i < nbevents; i++ ) {
                nbgamma = 2 + i % 5; wbytes += 4.0;  wbytes += nbgamma * 4.0;
                treeout->Fill();
        }
        watch.Stop();
        
        printf("  --> Writing rate %f MB/s [%f] \n",wbytes/(1024*1024*watch.RealTime()),wbytes/(1024*1024));
        
        fileout->Close(); delete fileout;
        
        return wbytes;
}
Exemplo n.º 9
0
void write(int n) {

   TRandom R;
   TStopwatch timer;

   TFile f1("mathcoreVectorIO_F.root","RECREATE");

   // create tree
   TTree t1("t1","Tree with new Float LorentzVector");

   XYZTVectorF *v1 = new XYZTVectorF();
   t1.Branch("LV branch","ROOT::Math::XYZTVectorF",&v1);

   timer.Start();
   for (int i = 0; i < n; ++i) {
      double Px = R.Gaus(0,10);
      double Py = R.Gaus(0,10);
      double Pz = R.Gaus(0,10);
      double E  = R.Gaus(100,10);
      v1->SetCoordinates(Px,Py,Pz,E);
      t1.Fill();
   }

   f1.Write();
   timer.Stop();
   std::cout << " Time for new Float Vector " << timer.RealTime() << "  " << timer.CpuTime() << std::endl;
   t1.Print();
}
Exemplo n.º 10
0
void seism() {

   TStopwatch sw; sw.Start();
   //set time offset
   TDatime dtime;
   gStyle->SetTimeOffset(dtime.Convert());

   TCanvas *c1 = new TCanvas("c1","Time on axis",10,10,1000,500);
   c1->SetFillColor(42);
   c1->SetFrameFillColor(33);
   c1->SetGrid();

   Float_t bintime = 1; //one bin = 1 second. change it to set the time scale
   TH1F *ht = new TH1F("ht","The ROOT seism",10,0,10*bintime);
   Float_t signal = 1000;
   ht->SetMaximum( signal);
   ht->SetMinimum(-signal);
   ht->SetStats(0);
   ht->SetLineColor(2);
   ht->GetXaxis()->SetTimeDisplay(1);
   ht->GetYaxis()->SetNdivisions(520);
   ht->Draw();

   for (Int_t i=1;i<2300;i++) {
      //======= Build a signal : noisy damped sine ======
      Float_t noise  = gRandom->Gaus(0,120);
      if (i > 700) noise += signal*sin((i-700.)*6.28/30)*exp((700.-i)/300.);
      ht->SetBinContent(i,noise);
      c1->Modified();
      c1->Update();
      gSystem->ProcessEvents(); //canvas can be edited during the loop
   }
   printf("Real Time = %8.3fs, Cpu Time = %8.3fs\n",sw.RealTime(),sw.CpuTime());
}
Exemplo n.º 11
0
void run(TString runNumber)
{
    TStopwatch timer;
    timer.Start();

    TString dirIn1 = "/Volumes/Data/kresan/s438/data/";
    TString dirIn2 = "/Volumes/Data/kresan/s438/tcal/";
    TString dirOut = "/Volumes/Data/kresan/s438/digi/";
    TString tdiffParName = "tdiff_" + runNumber + ".dat";
    TString inputFileName1 = dirIn2 + runNumber + "_tcal.root";             // name of input file
    TString parFileName    = dirIn1 + "params_" + runNumber + "_raw.root";  // name of parameter file
    TString outputFileName = dirOut + runNumber + "_digi.root";            // name of output file

    // Create analysis run -------------------------------------------------------
    FairRunAna* run = new FairRunAna();
    run->SetInputFile(inputFileName1.Data());
    run->SetOutputFile(outputFileName.Data());
    // ---------------------------------------------------------------------------

    // ----- Runtime DataBase info -----------------------------------------------
    FairRuntimeDb* rtdb = run->GetRuntimeDb();
    FairParRootFileIo* parIo1 = new FairParRootFileIo();
    parIo1->open(parFileName);
    rtdb->setFirstInput(parIo1);
    rtdb->setOutput(parIo1);
    rtdb->saveOutput();
    // ---------------------------------------------------------------------------

    // Tdiff calibration ---------------------------------------------------------
    R3BLandTdiff* landTdiff = new R3BLandTdiff("LandTdiff", 1);
    landTdiff->SetTdiffParName(tdiffParName.Data());
    run->AddTask(landTdiff);
    // ---------------------------------------------------------------------------

    // Analysis ------------------------------------------------------------------
    R3BLandAna* landAna = new R3BLandAna("LandAna", 1);
    landAna->SetNofBars(100);
    run->AddTask(landAna);
    // ---------------------------------------------------------------------------
    
    // Initialize ----------------------------------------------------------------
    run->Init();
    FairLogger::GetLogger()->SetLogScreenLevel("INFO");
    // ---------------------------------------------------------------------------

    // Run -----------------------------------------------------------------------
    run->Run();
    // ---------------------------------------------------------------------------

    timer.Stop();
    Double_t rtime = timer.RealTime();
    Double_t ctime = timer.CpuTime();
    cout << endl << endl;
    cout << "Macro finished succesfully." << endl;
    cout << "Output file is " << outputFileName << endl;
    cout << "Parameter file is " << parFileName << endl;
    cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
}
Exemplo n.º 12
0
void  testIntegPerf(double x1, double x2, int n = 100000){


   std::cout << "\n\n***************************************************************\n";
   std::cout << "Test integration performances in interval [ " << x1 << " , " << x2 << " ]\n\n";

  TStopwatch timer;

  double dx = (x2-x1)/double(n);

  //ROOT::Math::Functor1D<ROOT::Math::IGenFunction> f1(& TMath::BreitWigner);
  ROOT::Math::WrappedFunction<> f1(func);

  timer.Start();
  ROOT::Math::Integrator ig(f1 );
  double s1 = 0.0;
  nc = 0;
  for (int i = 0; i < n; ++i) {
     double x = x1 + dx*i;
     s1+= ig.Integral(x1,x);
  }
  timer.Stop();
  std::cout << "Time using ROOT::Math::Integrator        :\t" << timer.RealTime() << std::endl;
  std::cout << "Number of function calls = " << nc/n << std::endl;
  int pr = std::cout.precision(18);  std::cout << s1 << std::endl;  std::cout.precision(pr);



  //TF1 *fBW = new TF1("fBW","TMath::BreitWigner(x)",x1, x2);  //  this is faster but cannot measure number of function calls
  TF1 *fBW = new TF1("fBW",func2,x1, x2,0);

  timer.Start();
  nc = 0;
  double s2 = 0;
  for (int i = 0; i < n; ++i) {
     double x = x1 + dx*i;
     s2+= fBW->Integral(x1,x );
  }
  timer.Stop();
  std::cout << "Time using TF1::Integral :\t\t\t" << timer.RealTime() << std::endl;
  std::cout << "Number of function calls = " << nc/n << std::endl;
  pr = std::cout.precision(18);  std::cout << s1 << std::endl;  std::cout.precision(pr);


}
Exemplo n.º 13
0
void dmesondecaylength()
{


    //gStyle->SetOptStat("nemruoi");
    gStyle->SetTitleSize(.04,"S");
    gStyle->SetOptTitle(1);
    gStyle->SetTitleOffset(1.0,"X");
    gStyle->SetTitleOffset(.88,"Y");
    gStyle->SetTitleSize(.04,"X");
    gStyle->SetTitleSize(.04,"Y");
    gStyle->SetLabelSize(.035,"X");
    gStyle->SetLabelSize(.035,"Y");
    gStyle->SetHistLineWidth(2);
    gStyle->SetOptFit(1);
    gStyle->SetOptStat(0);
// -----   Timer   --------------------------------------------------------
    TStopwatch timer;
    timer.Start();
    // ------------------------------------------------------------------------
    double c= 3* std::pow(10.,8.);
    double mt= 1040*std::pow(10.,-15.); // mean decay time
    double mass= 1.869; // rest mass in GeV/c^2
//TCanvas* can = new TCanvas("can","Radiation Length for start detector",0,0,100,100);
    TCanvas *c1 = new TCanvas("c1", "c1",0,52,1191,692);
    TH1D* h = new TH1D("hist","D-meson, D-meson decay length",24,0,24);
    h->SetTitle("D^{+} meson decay length = c#tau#sqrt{(#gamma_{D^{+}}^{2}-1)};Momentum (GeV/c); Decay length (mm)");
    Int_t ci;   // for color index setting
    ci = TColor::GetColor("#000099");
    for (int p=1; p<=24; p++)
    {
        double E = p*p + mass*mass;
        E= std:: sqrt(E);

        double gamma = E/mass;
        double decaylength = c* std::sqrt(gamma*gamma -1)*mt*1000;
        std:: cout<<" Decay length=" <<decaylength<<std::endl;
        h->SetLineColor(ci);
        h->GetXaxis()->CenterTitle(true);
        h->GetYaxis()->CenterTitle(true);
        h->SetMarkerColor(2);
        h->SetMarkerStyle(20);
        h->SetBinContent(p,decaylength);
        h->Draw("E2-text");
    }
// -----  Finish   -------------------------------------------------------
    timer.Stop();
    Double_t rtime = timer.RealTime();
    Double_t ctime = timer.CpuTime();
    cout << endl << endl;
    cout << "Macro finished succesfully." << endl;
    cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
    cout << endl;
    // ------------------------------------------------------------------------

}
Exemplo n.º 14
0
Arquivo: run.C Projeto: naodell/FCNH
void run(Long64_t nEntries = 1e4, string args = "TEST muon 2012") 
{

    string libMake = gSystem->GetMakeSharedLib();
    const string delWarn("-Wshadow");
    int pos1 = libMake.find(delWarn);
    libMake= libMake.substr(0, pos1) + libMake.substr(pos1+delWarn.size()+1); 
    gSystem->SetMakeSharedLib(libMake.c_str());

    //container classes
    gROOT->LoadMacro("../src/TCPhysObject.cc+");
    gROOT->LoadMacro("../src/TCTrack.cc+");
    gROOT->LoadMacro("../src/TCEGamma.cc+");
    gROOT->LoadMacro("../src/TCJet.cc+");
    gROOT->LoadMacro("../src/TCMET.cc+");
    gROOT->LoadMacro("../src/TCElectron.cc+");
    gROOT->LoadMacro("../src/TCMuon.cc+");
    gROOT->LoadMacro("../src/TCTau.cc+");
    gROOT->LoadMacro("../src/TCPhoton.cc+");
    gROOT->LoadMacro("../src/TCGenJet.cc+");
    gROOT->LoadMacro("../src/TCGenParticle.cc+");
    gROOT->LoadMacro("../src/TCPrimaryVtx.cc+");
    gROOT->LoadMacro("../src/TCTriggerObject.cc+");

    //analysis plugins (selectors, utiltities, etc.)
    gROOT->LoadMacro("../plugins/HistManager.cc+");
    gROOT->LoadMacro("../plugins/EGammaMvaEleEstimator.cc+");
    gROOT->LoadMacro("../plugins/rochcor2012jan22.C+");
    gROOT->LoadMacro("../plugins/WeightUtils.cc+");
    gROOT->LoadMacro("../plugins/TriggerSelector.cc+");
    gROOT->LoadMacro("../plugins/Selector.cc+");

    TChain* fChain = new TChain("ntupleProducer/eventTree");

    ifstream sourceFiles("input.txt");
    char line[2048];
    int  count = 0;

    while (sourceFiles >> line) {
        fChain->Add(line);      
        ++count;
    }
    cout << count << " files added!"<<endl;
    sourceFiles.close();

    TStopwatch timer;
    timer.Start();

    fChain->Process("fcncAnalyzer.C+", args.c_str(), nEntries, 0);

    cout << "\n\nDone!" << endl;
    cout << "CPU Time : " << timer.CpuTime() << endl;
    cout << "RealTime : " << timer.RealTime() << endl;
    cout << "\n";
}
Exemplo n.º 15
0
double write(int n) {



  TRandom R;
  TStopwatch timer;


  TFile f1("mathcoreLV.root","RECREATE");

  // create tree
  TTree t1("t1","Tree with new LorentzVector");

  std::vector<ROOT::Math::XYZTVector>  tracks;
  std::vector<ROOT::Math::XYZTVector> * pTracks = &tracks;
  t1.Branch("tracks","std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >",&pTracks);

  double M = 0.13957;  // set pi+ mass

  timer.Start();
  double sum = 0;
  for (int i = 0; i < n; ++i) {
    int nPart = R.Poisson(5);
    pTracks->clear();
    pTracks->reserve(nPart);
    for (int j = 0; j < nPart; ++j) {
      double px = R.Gaus(0,10);
      double py = R.Gaus(0,10);
      double pt = sqrt(px*px +py*py);
      double eta = R.Uniform(-3,3);
      double phi = R.Uniform(0.0 , 2*TMath::Pi() );
      RhoEtaPhiVector vcyl( pt, eta, phi);
      // set energy
      double E = sqrt( vcyl.R()*vcyl.R() + M*M);
      XYZTVector q( vcyl.X(), vcyl.Y(), vcyl.Z(), E);
      // fill track vector
      pTracks->push_back(q);
      // evaluate sum of components to check
      sum += q.x()+q.y()+q.z()+q.t();
    }
    t1.Fill();
  }

  f1.Write();
  timer.Stop();
  std::cout << " Time for new Vector " << timer.RealTime() << "  " << timer.CpuTime() << std::endl;

  t1.Print();
  return sum;
}
Exemplo n.º 16
0
void countTriggers() {

  // Printing utility for ntuple variables
  gROOT->LoadMacro("/afs/cern.ch/user/y/yohay/scratch0/CMSSW_4_2_4_patch2/src/SusyAnalysis/SusyNtuplizer/macro/SusyEventPrinter.cc+");
//   gROOT->LoadMacro("SusyEventPrinter.cc+");

  // Main analysis code
//   gSystem->SetIncludePath("-I../../..");
  gSystem->SetIncludePath("-I/afs/cern.ch/user/y/yohay/scratch0/CMSSW_4_2_4_patch2/src");
  gROOT->LoadMacro("/afs/cern.ch/user/y/yohay/scratch0/CMSSW_4_2_4_patch2/src/SusyAnalysis/SusyNtuplizer/macro/EventAnalyzer.cc+");
//   gROOT->LoadMacro("EventAnalyzer.cc+");

  //configuration
  TChain chain("susyTree");
  chain.Add("susyEvent_ALL_1.root");
//   chain.Add("/data/ndpc3/c/dmorse/RA3/SusyNtuples/cms423v5_v1/Run2011A-May10ReReco-v1/Photon/Runs160442-163869/susyEvent_ALL_1.root");
//   chain.Add("/data/ndpc3/c/dmorse/RA3/SusyNtuples/cms423v5_v1/Run2011A-May10ReReco-v1/Photon/Runs160442-163869/susyEvent_ALL_2.root");
//   chain.Add("/data/ndpc3/c/dmorse/RA3/SusyNtuples/cms423v5_v1/Run2011A-PromptReco-v4/Photon/Run166438/susyEvent_ALL.root");
//   chain.Add("/data/ndpc3/c/dmorse/RA3/SusyNtuples/cms423v5_v1/Run2011A-PromptReco-v4/Photon/Runs165088-166346/susyEvent_ALL_1.root");
//   chain.Add("/data/ndpc3/c/dmorse/RA3/SusyNtuples/cms423v5_v1/Run2011A-PromptReco-v4/Photon/Runs165088-166346/susyEvent_ALL_2.root");
//   chain.Add("/data/ndpc3/c/dmorse/RA3/SusyNtuples/cms423v5_v1/Run2011A-PromptReco-v4/Photon/Runs166374-166486/susyEvent_ALL.root");
//   chain.Add("/data/ndpc3/c/dmorse/RA3/SusyNtuples/cms423v5_v1/Run2011A-PromptReco-v4/Photon/Runs166502-166530/susyEvent_ALL.root");
//   chain.Add("/data/ndpc3/c/dmorse/RA3/SusyNtuples/cms423v5_v1/Run2011A-PromptReco-v4/Photon/Runs166554-166787/susyEvent_ALL.root");
//   chain.Add("/data/ndpc3/c/dmorse/RA3/SusyNtuples/cms423v5_v1/Run2011A-PromptReco-v4/Photon/Runs166839-166911/susyEvent_ALL.root");
//   chain.Add("/data/ndpc3/c/dmorse/RA3/SusyNtuples/cms423v5_v1/Run2011A-PromptReco-v4/Photon/Runs166921-167078/susyEvent_ALL.root");
//   chain.Add("/data/ndpc3/c/dmorse/RA3/SusyNtuples/cms423v5_v1/Run2011A-PromptReco-v4/Photon/Runs167098-167284/susyEvent_ALL.root");
//   chain.Add("/data/ndpc3/c/dmorse/RA3/SusyNtuples/cms423v5_v1/Run2011A-PromptReco-v4/Photon/Runs167551-167913/susyEvent_ALL.root");
  EventAnalyzer treeReader(&chain);
  treeReader.SetPrintInterval(10000);
  treeReader.SetPrintLevel(0);
  treeReader.SetUseTrigger(true);
  treeReader.AddHltName("HLT_Photon32_CaloIdL_Photon26_CaloIdL");
  treeReader.AddHltName("HLT_Photon36_CaloIdL_Photon22_CaloIdL");
  treeReader.AddHltName("HLT_Photon40_CaloIdL_Photon28_CaloIdL");
  treeReader.SetFilter(false);
  treeReader.SetProcessNEvents(-1);
  treeReader.IncludeAJson("/afs/cern.ch/user/y/yohay/scratch0/CMSSW_4_2_4_patch2/src/SusyAnalysis/SusyNtuplizer/macro/Cert_160404-172255_7TeV_PromptReco_Collisions11_JSON.txt");
  treeReader.SetPhotonTag("photons");

  //run
  TStopwatch ts;
  ts.Start();
//   treeReader.countTriggers("/afs/cern.ch/user/y/yohay/scratch0/CMSSW_4_2_4_patch2/src/SusyAnalysis/SusyNtuplizer/count_May10ReReco_PromptRecov4_testv3");
  treeReader.countTriggers("count_May10ReReco_PromptRecov4_batchTest");
  ts.Stop();
  cout << "Real time : " << ts.RealTime()/60.0 << " minutes" << endl;
  cout << "CPU time  : " << ts.CpuTime()/60.0 << " minutes" << endl;
}
Exemplo n.º 17
0
void Generate_LS(int job){
	gROOT->SetBatch();
	int iy=int(job)/fNpt;
	int ipt=int(job)%fNpt;
	cout << "JOB: " << job << endl; 
	cout << "iy: " << iy << " ipt: " << ipt << endl; 
	cout << "y: " << fYbin[iy] << "-" << fYbin[iy+1] << endl; 
	cout << "pT: " << fPTbin[ipt] << "-" << fPTbin[ipt+1] << endl; 
	TStopwatch t; 
	t.Start();
	loop(iy, ipt); 
	t.Stop(); 
	cout << "Real Time: " << t.RealTime() << endl;
	cout << "CPU Time: " << t.CpuTime() << endl; 
	
}
void billtr(Int_t compress) {
   //read N histograms from a tree
   timer.Start();
   TFile f("billt.root");
   TH1F *h = 0;
   TTree *T = (TTree*)f.Get("T");
   T->SetBranchAddress("event",&h);
   TH1F *hmeant = new TH1F("hmeant","hist mean from tree",100,0,1);
   Long64_t nentries = T->GetEntries();
   for (Long64_t i=0;i<nentries;i++) {
      T->GetEntry(i);
      hmeant->Fill(h->GetMean());
   }
   timer.Stop();
   printf("billtr%d : RT=%7.3f s, Cpu=%7.3f s\n",compress,timer.RealTime(),timer.CpuTime());
}
Exemplo n.º 19
0
void RhoToolsTest(Int_t nTimes=1)
{
#ifdef __CINT__
    gROOT.Macro("$RHO/RhoMacros/LoadLibs.C");
#endif
    
    TRho Rho("RhoTools test");
    //cout << Rho; // Not possible until ROOT uses ANSI streams
    
    TStopwatch timer;					    // Measure the execution time
    timer.Start();
    for (int i=0;i<nTimes;i++) Sputnik revival;
    timer.Stop();
    
    cout<<" ----- Realtime:   "<<timer.RealTime()<<"sec"<<endl;
    cout<<" ----- Cputime:    "<<timer.CpuTime()<<"sec"<<endl;
}
Exemplo n.º 20
0
void DoFit(const char* fitter, TVirtualPad *pad, Int_t npass) {
   TStopwatch timer;
   TVirtualFitter::SetDefaultFitter(fitter);
   pad->SetGrid();
   fitFcn->SetParameters(100,0,0,2,7);
   fitFcn->Update();

   timer.Start();
   histo->Fit("fitFcn","0");
   timer.Stop();

   histo->Draw();
   Double_t cputime = timer.CpuTime();
   printf("%s, npass=%d  : RT=%7.3f s, Cpu=%7.3f s\n",fitter,npass,timer.RealTime(),cputime);
   TPaveLabel *p = new TPaveLabel(0.5,0.7,0.85,0.8,Form("%s CPU= %g s",fitter,cputime),"brNDC");
   p->Draw();
   pad->Update();
}
Exemplo n.º 21
0
void generate( R & r, TH1D * h) { 

  TStopwatch w; 

  r.SetSeed(0);
  //r.SetSeed(int(std::pow(2.0,28)));
  int m = NLOOP;
  int n = NEVT;
  for (int j = 0; j < m; ++j) { 

    //std::cout << r.GetSeed() << "   "; 

    w.Start();
//     if ( n < 40000000) iseed = std::rand();
//     iseed = 0;
    //TRandom3 r3(0);
    //r.SetSeed( 0 ); // generate random seeds
    //TRandom3 r3(0); 
    //r.SetSeed (static_cast<UInt_t> (4294967296.*r3.Rndm()) );

  // estimate PI
    double n1=0; 
    double rn[2000];
    double x; 
    double y; 
    for (int ievt = 0; ievt < n; ievt+=1000 ) { 
      r.RndmArray(2000,rn);
      for (int i=0; i < 1000; i++) { 
	x=rn[2*i];
	y=rn[2*i+1];
	if ( ( x*x + y*y ) <= 1.0 ) n1++;
      }
    }
    double piEstimate = 4.0 * double(n1)/double(n);
    double delta = piEstimate-PI; 
    h->Fill(delta); 
  }

  w.Stop();
  std::cout << std::endl; 
  std::cout << "Random:  " << typeid(r).name() 
	    << "\n\tTime = " << w.RealTime() << "  " << w.CpuTime() << std::endl;   
  std::cout << "Time/call:  " << w.CpuTime()/(2*n)*1.0E9 << std::endl; 
}
Exemplo n.º 22
0
void likelihood_fit_tim()
{
  TStopwatch timer;

  // Define histogarams

  gStyle->SetOptFit(0);
  gStyle->SetOptStat(111111);

  // Get data

  timer.Start();
  //getDataLft2();
  //getDataCLft();
  getDataLft();
  //genDataMs();

  // Do binned fit

  // Do unbinned likelihood fit

  //unbinFitg();
  //unbinFitgp();
  unbinFitlft();
  //unbinFitosc();
  //unbinFitosc_d();

  // stop timer and print results
  timer.Stop();
  Double_t rtime = timer.RealTime();
  Double_t ctime = timer.CpuTime();

  cout << "Real time " << rtime << endl;
  cout << "CPU time  " << ctime << endl;

  // Draw histograms

//   TF1 *f2 = new TF1("f2", lifetime_plt, -4., 15., 2);
//   f2->SetParameter(0,1.);
//   f2->SetParameter(1,1.5);
//   f2->Draw();
  //h1->Draw("same");
}
Exemplo n.º 23
0
void h2fast(const char *url , Bool_t draw=kFALSE, Long64_t cachesize=10000000, Int_t learn=1) {
// gEnv->SetValue("TFile.DavixLog", 10);
//  gDebug= 0x02;
   TStopwatch sw;
   TTree* T = NULL;
   sw.Start();
   Long64_t oldb = TFile::GetFileBytesRead();
   TFile *f = TFile::Open(url);
  
   if (!f || f->IsZombie()) {
      printf("File h1big.root does not exist\n");
      exit (-1);
   }
   

//   TTreeCacheUnzip::SetParallelUnzip(TTreeCacheUnzip::kEnable);

   T= (TTree*)f->Get("h42");
   Long64_t nentries = T->GetEntries();
   T->SetCacheSize(cachesize);
   TTreeCache::SetLearnEntries(learn);
   TFileCacheRead *tpf = f->GetCacheRead();
   //tpf->SetEntryRange(0,nentries);
   
   if (draw) T->Draw("rawtr","E33>20");
   else {
      TBranch *brawtr = T->GetBranch("rawtr");
      TBranch *bE33   = T->GetBranch("E33");
      Float_t E33; 
      bE33->SetAddress(&E33);
      for (Long64_t i=0;i<nentries;i++) {
         T->LoadTree(i);
         bE33->GetEntry(i);
         if (E33 > 0) brawtr->GetEntry(i);
      } 
   } 
   if (tpf) tpf->Print();
   printf("Bytes read = %lld\n",TFile::GetFileBytesRead()-oldb);
   printf("Real Time = %7.3f s, CPUtime = %7.3f s\n",sw.RealTime(),sw.CpuTime());
   delete T;
   delete f;
}
void billr(Int_t compress) {
   //read N histograms from keys
   timer.Start();
   TFile f("bill.root");
   TIter next(f.GetListOfKeys());
   TH1F *h;
   TH1::AddDirectory(kFALSE);
   TKey *key;
   Int_t i=0;
   TH1F *hmean = new TH1F("hmean","hist mean from keys",100,0,1);
   
   while ((key=(TKey*)next())) {
      h = (TH1F*)key->ReadObj();
      hmean->Fill(h->GetMean());
      delete h;
      i++;
   }
   timer.Stop();
   printf("billr%d  : RT=%7.3f s, Cpu=%7.3f s\n",compress,timer.RealTime(),timer.CpuTime());
}
Exemplo n.º 25
0
void makePlots() {

  gSystem->AddIncludePath("-I$ROOFITSYS/include"); 
  gROOT->LoadMacro("analyze.C+");

  TStopwatch ts;
  ts.Start();

  TString input_ele = "ELE_FILE_TO_RUN";
  TString input_muon = "MUON_FILE_TO_RUN";
  bool addMC = true;
  int intLumi = 19712; // quote to 19.7

  double metCut = -1.;

  bool displayKStest = false;
  bool blinded = false;
  int nPhotons_req = NUM_PHOTONS_REQUIRED;

  const int nChannels = 4;
  TString channels[nChannels] = {"ele_jjj", "ele_bjj",
				 "muon_jjj", "muon_bjj"};
  int nBtagReq[nChannels] = {0, 1,
			     0, 1};

  for(int i = 0; i < nChannels; i++) {
    if(i != 1 && i != 3) continue;

    if(i < 2) analyze(input_ele, addMC, i, intLumi, metCut, nPhotons_req, nBtagReq[i], displayKStest, blinded, 0);
    else analyze(input_muon, addMC, i, intLumi, metCut, nPhotons_req, nBtagReq[i], displayKStest, blinded, 0);

  }  

  ts.Stop();

  std::cout << "RealTime : " << ts.RealTime()/60.0 << " minutes" << std::endl;
  std::cout << "CPUTime  : " << ts.CpuTime()/60.0 << " minutes" << std::endl;

}
Exemplo n.º 26
0
void findHits(TString inputFile="", TString outputFile="", Int_t nEvents = 0)
{
  // -----   Timer   --------------------------------------------------------
  TStopwatch timer;
  timer.Start();
  // ------------------------------------------------------------------------
  
  // -----   Create analysis run   ----------------------------------------
  FairRunAna* fRun = new FairRunAna();
  fRun->SetInputFile(inputFile);
  fRun->SetOutputFile(outputFile);
 
  // Hit finder
  R3BCalifaCrystalCal2Hit *hitFinder = new R3BCalifaCrystalCal2Hit();
  // Select s438b Demonstrator Geometry
  hitFinder->SelectGeometryVersion(0x438b);
  hitFinder->SetAngularWindow(6.0*TMath::Pi()/180.0, 6.0*TMath::Pi()/180.0, 0);
  fRun->AddTask(hitFinder);
  

  fRun->Init();       
  FairLogger::GetLogger()->SetLogScreenLevel("INFO");
//  FairLogger::GetLogger()->SetLogVerbosityLevel("HIGH");
             
  fRun->Run(0,nEvents);
  
  delete fRun;

  // -----   Finish   -------------------------------------------------------
  timer.Stop();
  Double_t rtime = timer.RealTime();
  Double_t ctime = timer.CpuTime();
  cout << endl << endl;
  cout << "Macro finished succesfully." << endl;
  cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
  cout << endl;
  // ------------------------------------------------------------------------

}
void bill() {
   
   TStopwatch totaltimer;
   totaltimer.Start();
   for (Int_t compress=0;compress<2;compress++) {
      billw(compress);
      billr(compress);
      billtw(compress);
      billtr(compress);
   }
   gSystem->Unlink("bill.root");
   gSystem->Unlink("billt.root");
   totaltimer.Stop();
   Double_t rtime = totaltimer.RealTime();
   Double_t ctime = totaltimer.CpuTime();
   printf("billtot : RT=%7.3f s, Cpu=%7.3f s\n",rtime,ctime);
   //reference is a P IV 2.4 GHz
   Float_t rootmarks = 600*(16.98 + 14.40)/(rtime + ctime);
   printf("******************************************************************\n");
   printf("*  ROOTMARKS =%6.1f   *  Root%-8s  %d/%d\n",rootmarks,gROOT->GetVersion(),gROOT->GetVersionDate(),gROOT->GetVersionTime());
   printf("******************************************************************\n");
}
Exemplo n.º 28
0
int execSaxParserSimple()
{
   const Int_t nIterations = 1000;
   TSAXParser *saxParser = new TSAXParser();
   SAXHandler *saxHandler = new SAXHandler();
   TStopwatch timer;
   saxParser->ConnectToHandler("SAXHandler", saxHandler);
   timer.Start();
   for (Int_t i = 0; i < nIterations; i++) {
      saxParser->ParseFile("./saxSimpleExample.xml");
      saxHandler->Quiet();
   }

   auto realTime = timer.RealTime();
   float threshold = 15;
#ifdef __aarch64__
   threshold = 30;
#endif
   if (realTime > threshold)
      std::cout << "WARNING: The parsing took " << realTime << " seconds. This may be too much\n";

   return 0;
}
    void run_PPToGammaGammaFiles() {

    gROOT->LoadMacro("FlatTreeMaker_Delphes_PPToGammaGammaFiles_C.so");
  
    TChain* fChain = new TChain("Delphes");
    ifstream sourceFiles("PPToGammaGammaFiles.txt");
    char line[128];
    int  count = 0;
    cout<< "Adding files from PPToGammaGammaFiles to chain..."<< endl;
     while (sourceFiles >> line) {
        fChain->Add(line);
        ++count;
     }
    cout << count<<" files added!"<<endl;
    sourceFiles.close();
    TStopwatch timer;
    timer.Start();    
    fChain->Process("FlatTreeMaker_Delphes");

    cout << "\n\nDone!" << endl;
    cout << "CPU Time : " << timer.CpuTime() <<endl;
    cout << "RealTime : " << timer.RealTime() <<endl;                             
    cout <<"\n";
}
Exemplo n.º 30
0
void RAA_dataDrivenUnfoldingErrorCheck(int radius = 4, int radiusPP = 4, char* algo = (char*) "Pu", char *jet_type = (char*) "PF", int unfoldingCut = 30, char* etaWidth = (char*) "n20_eta_p20", double deltaEta = 4.0){

  TStopwatch timer; 
  timer.Start();
  
  TH1::SetDefaultSumw2();
  TH2::SetDefaultSumw2();
  
  bool printDebug = true;

  // get the data and mc histograms from the output of the read macro. 
  
  TDatime date;//this is just here to get them to run optimized. 

  // Raghav's files: 
  //TFile * fPbPb_in = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/CMSSW_5_3_18/src/Output/PbPb_CutEfficiency_YetkinCuts_matched_slantedlinecalopfpt_addingunmatched_exclusionhighertriggers_eMaxSumcand_A_R0p%d.root",radius));
  //  //TFile * fPP_in = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/CMSSW_5_3_18/src/Output/Pp_CutEfficiency_YetkinCuts_matched_slantedlinecalopfpt_addingunmatched_exclusionhighertriggers_eMaxSumcand_A_R0p%d.root",radius));
  //TFile * fPP_in = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/CMSSW_5_3_18/src/Output/Pp_CutEfficiency_noJetID_exclusionhighertriggers_A_R0p%d.root",radius));

  // Pawan's files:
  TFile * fPbPb_in = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/CMSSW_5_3_18/src/Output/Pawan_ntuplehistograms/PbPb_CutEfficiency_YetkinCuts_matched_slantedlinecalopfpt_addingunmatched_exclusionhighertriggers_eMaxSumcand_A_R0p%d.root",radius));
  //TFile * fPP_in = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/CMSSW_5_3_18/src/Output/Pp_CutEfficiency_YetkinCuts_matched_slantedlinecalopfpt_addingunmatched_exclusionhighertriggers_eMaxSumcand_A_R0p%d.root",radius));
  TFile * fPP_in = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/CMSSW_5_3_18/src/Output/Pawan_ntuplehistograms/Pp_CutEfficiency_YetkinCuts_matched_slantedlinecalopfpt_addingunmatched_exclusionhighertriggers_eMaxSumcand_A_R0p%d.root",radius));

  TFile * fPbPb_MB_in = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/CMSSW_5_3_18/src/Output/PbPb_MinBiasUPC_CutEfficiency_YetkinCuts_matched_slantedlinecalopfpt_addingunmatched_exclusionhighertriggers_eMaxSumcand_A_R0p%d.root",radius));


  
  //TH1F * htest = new TH1F("htest","",nbins_pt, boundaries_pt);
  //Int_t unfoldingCutBin = htest->FindBin(unfoldingCut);
  
  cout<<"after input file declaration"<<endl;
  // need to make sure that the file names are in prefect order so that i can run them one after another. 
  // for the above condition, i might have to play with the date stamp. 
  
  const int nbins_cent = 6;
  double boundaries_cent[nbins_cent+1] = {0,2,4,12,20,28,36};
  double ncoll[nbins_cent+1] = {1660,1310,745,251,62.8,10.8,362.24};
  
  // histogram declarations with the following initial appendage: d - Data, m - MC, u- Unfolded
  // for the MC closure test, ive kept separate 

  // setup the radius and the eta bin loop here later. not for the time being. Aug 20th. only run the -2 < eta < 2 with the differenent centrality bins 

  TH1F *dPbPb_TrgComb[nbins_cent+1], *dPbPb_Comb[nbins_cent+1], *dPbPb_Trg80[nbins_cent+1], *dPbPb_Trg65[nbins_cent+1], *dPbPb_Trg55[nbins_cent+1], *dPbPb_1[nbins_cent+1], *dPbPb_2[nbins_cent+1], *dPbPb_3[nbins_cent+1], *dPbPb_80[nbins_cent+1], *dPbPb_65[nbins_cent+1], *dPbPb_55[nbins_cent+1];
  
  TH1F *mPbPb_Gen[nbins_cent+1], *mPbPb_Reco[nbins_cent+1];
  TH2F *mPbPb_Matrix[nbins_cent+1], *mPbPb_Response[nbins_cent+1], *mPbPb_ResponseNorm[nbins_cent+1];
  TH1F *mPbPb_mcclosure_data[nbins_cent+1];
  TH2F *mPbPb_mcclosure_Matrix[nbins_cent+1],*mPbPb_mcclosure_Response[nbins_cent+1], *mPbPb_mcclosure_ResponseNorm[nbins_cent+1];
  TH1F *mPbPb_mcclosure_gen[nbins_cent+1];
  const int Iterations = 20; //for unfolding systematics. 
  const int BayesIter = 4;
  TH1F *uPbPb_Bayes[nbins_cent+1], *uPbPb_BinByBin[nbins_cent+1], *uPbPb_SVD[nbins_cent+1]; 
  TH1F *uPbPb_BayesianIter[nbins_cent+1][Iterations];
  TH1F *dPbPb_MinBias[nbins_cent];
  
  TH1F *dPP_1, *dPP_2, *dPP_3, *dPP_Comb;
  TH1F *mPP_Gen, *mPP_Reco;
  TH2F *mPP_Matrix, *mPP_Response,*mPP_ResponseNorm;
  TH1F *mPP_mcclosure_data;
  TH2F *mPP_mcclosure_Matrix, *mPP_mcclosure_Response,*mPP_mcclosure_ResponseNorm;
  TH1F *mPP_mcclosure_Gen;
  TH1F *uPP_Bayes, *uPP_BinByBin, *uPP_SVD;
  TH1F *uPP_BayesianIter[Iterations];

  // would be better to read in the histograms and rebin them. come to think of it, it would be better to have them already rebinned (and properly scaled - to the level of differential cross section in what ever barns (inverse micro barns) but keep it consistent) from the read macro. 

  // get PbPb data
  for(int i = 0;i<nbins_cent;i++){
    if(printDebug) cout<<"cent_"<<i<<endl;
    dPbPb_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLTComb_R%d_n20_eta_p20_cent%d",radius,i));
    //dPbPb_TrgComb[i]->Scale(4*145.156*1e6);
    dPbPb_TrgComb[i]->Print("base");
    dPbPb_Trg80[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT80_R%d_n20_eta_p20_cent%d",radius,i));
    //dPbPb_Trg80[i]->Scale(4*145.156*1e6);
    dPbPb_Trg80[i]->Print("base");
    dPbPb_Trg65[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT65_R%d_n20_eta_p20_cent%d",radius,i));
    //dPbPb_Trg65[i]->Scale(4*145.156*1e6);
    dPbPb_Trg65[i]->Print("base");
    dPbPb_Trg55[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT55_R%d_n20_eta_p20_cent%d",radius,i));
    //dPbPb_Trg55[i]->Scale(4*145.156*1e6);
    dPbPb_Trg55[i]->Print("base");
    //dPbPb_TrgComb[i] = (TH1F*)dPbPb_Trg80[i]->Clone(Form("Jet_80_triggered_spectra_data_PbPb_cent%d",i));
    
    //dPbPb_MinBias[i] = (TH1F*)fPbPb_MB_in->Get(Form("hpbpb_HLTComb_R%d_n20_eta_p20_cent%d",radius,i));
    //dPbPb_MinBias[i]->Print("base");
    dPbPb_TrgComb[i]->Scale(1./(145.156 * 1e9));
    //dPbPb_MinBias[i]->Scale(1./(161.939 * 1e9));
    
    //dPbPb_TrgComb[i]->Add(dPbPb_MinBias[i]);
    
    for(int k = 1;k<=unfoldingCut;k++) {
      dPbPb_TrgComb[i]->SetBinContent(k,0);
      dPbPb_Trg80[i]->SetBinContent(k,0);
      dPbPb_Trg65[i]->SetBinContent(k,0);
      dPbPb_Trg55[i]->SetBinContent(k,0);
    }
    
  }
  
  //Int_t nSVDIter = 4;
  
  if(printDebug)cout<<"loaded the data histograms PbPb"<<endl;
  // get PbPb MC
  for(int i = 0;i<nbins_cent;i++){
    
    mPbPb_Gen[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_JetComb_gen_R%d_n20_eta_p20_cent%d",radius,i));
    //mPbPb_Gen[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_gen_R%d_n20_eta_p20_cent%d",radius,i));
    mPbPb_Gen[i]->Print("base");
    mPbPb_Reco[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_JetComb_reco_R%d_n20_eta_p20_cent%d",radius,i));
    //mPbPb_Reco[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_reco_R%d_n20_eta_p20_cent%d",radius,i));
    mPbPb_Reco[i]->Print("base");
    mPbPb_Matrix[i] = (TH2F*)fPbPb_in->Get(Form("hpbpb_matrix_HLT_R%d_n20_eta_p20_cent%d",radius,i));
    //mPbPb_Matrix[i] = (TH2F*)fPbPb_in->Get(Form("hpbpb_matrix_R%d_n20_eta_p20_cent%d",radius,i));
    mPbPb_Matrix[i]->Print("base");
    mPbPb_mcclosure_data[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_mcclosure_JetComb_data_R%d_n20_eta_p20_cent%d",radius,i));
    mPbPb_mcclosure_data[i]->Print("base");
    mPbPb_mcclosure_gen[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_mcclosure_gen_JetComb_R%d_n20_eta_p20_cent%d",radius,i));
    mPbPb_mcclosure_gen[i]->Print("base");
    mPbPb_mcclosure_Matrix[i] = (TH2F*)fPbPb_in->Get(Form("hpbpb_mcclosure_matrix_HLT_R%d_n20_eta_p20_cent%d",radius,i));
    mPbPb_mcclosure_Matrix[i]->Print("base");
    
    //since SVD is very straight forward, lets do it rignt here:
    //get the SVD response matrix:
    //RooUnfoldResponse ruResponse(mPbPb_Matrix[i]->ProjectionY(),mPbPb_Matrix[i]->ProjectionX(), mPbPb_Matrix[i],"","");
    //regularization parameter definition: 
    //RooUnfoldSvd unfoldSvd(&ruResponse, dPbPb_TrgComb[i], nSVDIter);
    //uPbPb_SVD[i] = (TH1F*)unfoldSvd.Hreco();
  
    
    // for(int k = 1;k<=unfoldingCut;k++){

    //   mPbPb_Gen[i]->SetBinContent(k,0);
    //   mPbPb_Reco[i]->SetBinContent(k,0);
    //   mPbPb_mcclosure_data[i]->SetBinContent(k,0);
    //   mPbPb_mcclosure_gen[i]->SetBinContent(k,0);
    //   for(int l = 1;l<=1000;l++){
    // 	mPbPb_Matrix[i]->SetBinContent(k,l,0);
    // 	mPbPb_mcclosure_Matrix[i]->SetBinContent(k,l,0);
    // 	mPbPb_Matrix[i]->SetBinContent(l,k,0);
    // 	mPbPb_mcclosure_Matrix[i]->SetBinContent(l,k,0);	
    //   }
    // }
    
    //mPbPb_Response[i] = new TH2F(Form("mPbPb_Response_cent%d",i),"Response Matrix",nbins_pt,boundaries_pt,nbins_pt,boundaries_pt);
    //mPbPb_ResponseNorm[i] = new TH2F(Form("mPbPb_ResponseNorm_cent%d",i),"Normalized Response Matrix",nbins_pt,boundaries_pt,nbins_pt,boundaries_pt);
  }
  
  if(printDebug) cout<<"loaded the data and mc PbPb histograms from the files"<<endl;

  // get PP data
  if(printDebug) cout<<"Getting PP data and MC"<<endl;
  dPP_1 = (TH1F*)fPP_in->Get(Form("hpp_HLT80_R%d_%s",radiusPP,etaWidth)); 
  dPP_1->Print("base");
  dPP_2 = (TH1F*)fPP_in->Get(Form("hpp_HLT60_R%d_%s",radiusPP,etaWidth));
  dPP_2->Print("base");
  dPP_3 = (TH1F*)fPP_in->Get(Form("hpp_HLT40_R%d_%s",radiusPP,etaWidth));
  dPP_3->Print("base");
  dPP_Comb = (TH1F*)fPP_in->Get(Form("hpp_HLTComb_R%d_%s",radiusPP,etaWidth));   
  //dPP_Comb = (TH1F*)dPP_1->Clone(Form("hpp_TrgComb_R%d_n20_eta_p20",radiusPP,etaWidth));   
  dPP_Comb->Print("base");

  dPP_Comb->Scale(1./(5.3 * 1e9));
  
  for(int k = 1;k<=unfoldingCut;k++) {
    dPP_Comb->SetBinContent(k,0);
    dPP_1->SetBinContent(k,0);
    dPP_2->SetBinContent(k,0);
    dPP_3->SetBinContent(k,0);
  }
  
  // get PP MC
  mPP_Gen = (TH1F*)fPP_in->Get(Form("hpp_JetComb_gen_R%d_%s",radiusPP,etaWidth));
  mPP_Gen->Print("base");
  mPP_Reco = (TH1F*)fPP_in->Get(Form("hpp_JetComb_reco_R%d_%s",radiusPP,etaWidth));
  mPP_Reco->Print("base");
  mPP_Matrix = (TH2F*)fPP_in->Get(Form("hpp_matrix_HLT_R%d_%s",radiusPP,etaWidth));
  mPP_Matrix->Print("base");
  mPP_mcclosure_data = (TH1F*)fPP_in->Get(Form("hpp_mcclosure_JetComb_data_R%d_%s",radiusPP,etaWidth));
  mPP_mcclosure_data->Print("base");
  mPP_mcclosure_Matrix = (TH2F*)fPP_in->Get(Form("hpp_mcclosure_matrix_HLT_R%d_%s",radiusPP,etaWidth));
  mPP_mcclosure_Matrix->Print("base");

  //RooUnfoldResponse ruResponsePP(mPP_Matrix->ProjectionY(),mPP_Matrix->ProjectionX(), mPP_Matrix,"","");
  //regularization parameter definition: 
  //RooUnfoldSvd unfoldSvdPP(&ruResponsePP, dPP_Comb, nSVDIter);
  //uPP_SVD = (TH1F*)unfoldSvdPP.Hreco();

  
  // for(int k = 1;k<=unfoldingCut;k++){
  //   mPP_Gen->SetBinContent(k,0);
  //   mPP_Reco->SetBinContent(k,0);
  //   mPP_mcclosure_data->SetBinContent(k,0);
  //   for(int l = 1;l<=1000;l++){
  //     mPP_Matrix->SetBinContent(k,l,0);
  //     mPP_mcclosure_Matrix->SetBinContent(k,l,0);
  //     mPP_Matrix->SetBinContent(l,k,0);
  //     mPP_mcclosure_Matrix->SetBinContent(l,k,0);
  //   }
  // }

  
  if(printDebug) cout<<"Filling the PbPb response Matrix"<<endl;

  // response matrix and unfolding for PbPb 
  // going to try it the way kurt has it. 

  for(int i = 0;i<nbins_cent;i++){
    if(printDebug) cout<<"centrality bin iteration = "<<i<<endl;
    TF1 *f = new TF1("f","[0]*pow(x+[2],[1])");
    f->SetParameters(1e10,-8.8,40);
    // TH1F *hGenSpectraCorr = (TH1F*)mPbPb_Matrix[i]->ProjectionX()->Clone(Form("hGenSpectraCorr_cent%d",i));
    // hGenSpectraCorr->Fit("f"," ");
    // hGenSpectraCorr->Fit("f","","");
    // hGenSpectraCorr->Fit("f","LL");
    // TH1F *fHist = functionHist(f,hGenSpectraCorr,Form("fHist_cent%d",i));// function that you get from the fitting 
    // hGenSpectraCorr->Divide(fHist);
    for (int y=1;y<=mPbPb_Matrix[i]->GetNbinsY();y++) {
      double sum=0;
      for (int x=1;x<=mPbPb_Matrix[i]->GetNbinsX();x++) {
	if (mPbPb_Matrix[i]->GetBinContent(x,y)<=1*mPbPb_Matrix[i]->GetBinError(x,y)) {
	  //in the above line mine had 0*getbinerror while Kurt's had 1*. 
	  mPbPb_Matrix[i]->SetBinContent(x,y,0);
	  mPbPb_Matrix[i]->SetBinError(x,y,0);
	}
	sum+=mPbPb_Matrix[i]->GetBinContent(x,y);
      }
      
      for (int x=1;x<=mPbPb_Matrix[i]->GetNbinsX();x++) {	   
	double ratio = 1;
	// if (hGenSpectraCorr->GetBinContent(x)!=0) ratio = 1e5/hGenSpectraCorr->GetBinContent(x);
	mPbPb_Matrix[i]->SetBinContent(x,y,mPbPb_Matrix[i]->GetBinContent(x,y)*ratio);
	mPbPb_Matrix[i]->SetBinError(x,y,mPbPb_Matrix[i]->GetBinError(x,y)*ratio);
      }
    }
    //mPbPb_Matrix[i]->Smooth(0);
    // Ok major differences here between my code and Kurt in b-jet Tools under Unfold - lines 469 and above.  
    
    mPbPb_Response[i] = (TH2F*)mPbPb_Matrix[i]->Clone(Form("mPbPb_Response_cent%d",i));
    TH1F *hProj = (TH1F*)mPbPb_Response[i]->ProjectionY()->Clone(Form("hProj_cent%d",i));

    for (int y=1;y<=mPbPb_Response[i]->GetNbinsY();y++) {
      double sum=0;
      for (int x=1;x<=mPbPb_Response[i]->GetNbinsX();x++) {
	if (mPbPb_Response[i]->GetBinContent(x,y)<=1*mPbPb_Response[i]->GetBinError(x,y)) {
	  // in the above if loop, kurt has 1*error and my old had 0*error
	  mPbPb_Response[i]->SetBinContent(x,y,0);
	  mPbPb_Response[i]->SetBinError(x,y,0);
	}
	sum+=mPbPb_Response[i]->GetBinContent(x,y);
      }
      
      for (int x=1;x<=mPbPb_Response[i]->GetNbinsX();x++) {  	
	if (sum==0) continue;
	double ratio = 1;
	//if(dPbPb_TrgComb[i]->GetBinContent(y)==0) ratio = 1e-100/sum;
	// else ratio = dPbPb_TrgComb[i]->GetBinContent(y)/sum
	ratio = 1./sum;
	if (hProj->GetBinContent(y)==0) ratio = 1e-100/sum;
	else ratio = hProj->GetBinContent(y)/sum;
	mPbPb_Response[i]->SetBinContent(x,y,mPbPb_Response[i]->GetBinContent(x,y)*ratio);
	mPbPb_Response[i]->SetBinError(x,y,mPbPb_Response[i]->GetBinError(x,y)*ratio);
      }
    }
    
    mPbPb_ResponseNorm[i] = (TH2F*)mPbPb_Matrix[i]->Clone(Form("mPbPb_ResponseNorm_cent%d",i));
    for (int x=1;x<=mPbPb_ResponseNorm[i]->GetNbinsX();x++) {
      double sum=0;
      for (int y=1;y<=mPbPb_ResponseNorm[i]->GetNbinsY();y++) {
	if (mPbPb_ResponseNorm[i]->GetBinContent(x,y)<=1*mPbPb_ResponseNorm[i]->GetBinError(x,y)) {
	  mPbPb_ResponseNorm[i]->SetBinContent(x,y,0);
	  mPbPb_ResponseNorm[i]->SetBinError(x,y,0);
	}
	sum+=mPbPb_ResponseNorm[i]->GetBinContent(x,y);
      }
      
      for (int y=1;y<=mPbPb_ResponseNorm[i]->GetNbinsY();y++) {  	
	if (sum==0) continue;
	double ratio = 1./sum;
	mPbPb_ResponseNorm[i]->SetBinContent(x,y,mPbPb_ResponseNorm[i]->GetBinContent(x,y)*ratio);
	mPbPb_ResponseNorm[i]->SetBinError(x,y,mPbPb_ResponseNorm[i]->GetBinError(x,y)*ratio);
      }
      
    }
    
    
  }

  
  if(printDebug) cout<<"Filling PP response Matrix"<<endl;

  // response matrix for pp.  
  // Kurt doesnt have this whole hGenSpectraCorr thing in his macro. need to check why the difference exists between out codes
  
  TF1 *fpp = new TF1("fpp","[0]*pow(x+[2],[1])");
  fpp->SetParameters(1e10,-8.8,40);
  // if(printDebug) cout<<"before getting the gen spectra corr matrix"<<endl;
  // TH1F *hGenSpectraCorrPP = (TH1F*)mPP_Matrix->ProjectionX()->Clone("hGenSpectraCorrPP");
  // if(printDebug) cout<<"after gettign the gen spectra corr matrix"<<endl;
  // hGenSpectraCorrPP->Fit("f"," ");
  // hGenSpectraCorrPP->Fit("f","","");
  // hGenSpectraCorrPP->Fit("f","LL");
  // TH1F *fHistPP = functionHist(fpp,hGenSpectraCorrPP,"fHistPP");// that the function that you get from the fitting 
  // hGenSpectraCorrPP->Divide(fHistPP);
  
  for (int y=1;y<=mPP_Matrix->GetNbinsY();y++) {
    double sum=0;
    for (int x=1;x<=mPP_Matrix->GetNbinsX();x++) {
      if (mPP_Matrix->GetBinContent(x,y)<=1*mPP_Matrix->GetBinError(x,y)) {
	mPP_Matrix->SetBinContent(x,y,0);
	mPP_Matrix->SetBinError(x,y,0);
      }
      sum+=mPP_Matrix->GetBinContent(x,y);
    }
    
    for (int x=1;x<=mPP_Matrix->GetNbinsX();x++) {	   
      double ratio = 1;
      // if (hGenSpectraCorrPP->GetBinContent(x)!=0) ratio = 1e5/hGenSpectraCorrPP->GetBinContent(x);
      mPP_Matrix->SetBinContent(x,y,mPP_Matrix->GetBinContent(x,y)*ratio);
      mPP_Matrix->SetBinError(x,y,mPP_Matrix->GetBinError(x,y)*ratio);
    }
  }
  // mPbPb_Matrix[i]->Smooth(0);
  
  // Ok major differences here between my code and Kurt in b-jet Tools under Unfold - lines 469 and above.  

  if(printDebug) cout<<"getting the response matrix"<<endl;

  mPP_Response = (TH2F*)mPP_Matrix->Clone("mPP_Response");
  TH1F *hProjPP = (TH1F*)mPP_Response->ProjectionY()->Clone("hProjPP");
  
  
  for (int y=1;y<=mPP_Response->GetNbinsY();y++) {
    double sum=0;
    for (int x=1;x<=mPP_Response->GetNbinsX();x++) {
      if (mPP_Response->GetBinContent(x,y)<=1*mPP_Response->GetBinError(x,y)) {
	// in the above if statement, kurt has 1*error and my old has 0*error
	mPP_Response->SetBinContent(x,y,0);
	mPP_Response->SetBinError(x,y,0);
      }
      sum+=mPP_Response->GetBinContent(x,y);
    }
    
    for (int x=1;x<=mPP_Response->GetNbinsX();x++) {  	
      if (sum==0) continue;
      double ratio = 1;
      //if(dPbPb_TrgComb[i]->GetBinContent(y)==0) ratio = 1e-100/sum;
      // else ratio = dPbPb_TrgComb[i]->GetBinContent(y)/sum
      ratio = 1./sum;
      if (hProjPP->GetBinContent(y)==0) ratio = 1e-100/sum;
      else ratio = hProjPP->GetBinContent(y)/sum;
      mPP_Response->SetBinContent(x,y,mPP_Response->GetBinContent(x,y)*ratio);
      mPP_Response->SetBinError(x,y,mPP_Response->GetBinError(x,y)*ratio);
    }
  }
  if(printDebug) cout<<"getting the normalized response matrix"<<endl;
  mPP_ResponseNorm = (TH2F*)mPP_Matrix->Clone("mPP_ResponseNorm");
  for (int x=1;x<=mPP_ResponseNorm->GetNbinsX();x++) {
    double sum=0;
    for (int y=1;y<=mPP_ResponseNorm->GetNbinsY();y++) {
      if (mPP_ResponseNorm->GetBinContent(x,y)<=1*mPP_ResponseNorm->GetBinError(x,y)) {
	mPP_ResponseNorm->SetBinContent(x,y,0);
	mPP_ResponseNorm->SetBinError(x,y,0);
      }
      sum+=mPP_ResponseNorm->GetBinContent(x,y);
    }
    
    for (int y=1;y<=mPP_ResponseNorm->GetNbinsY();y++) {  	
      if (sum==0) continue;
      double ratio = 1./sum;
      mPP_ResponseNorm->SetBinContent(x,y,mPP_ResponseNorm->GetBinContent(x,y)*ratio);
      mPP_ResponseNorm->SetBinError(x,y,mPP_ResponseNorm->GetBinError(x,y)*ratio);
    }
    
    
  }
  
  // scale the spectra to the respective units

  // for(int i = 0;i<nbins_cent;++i){
  //   dPbPb_TrgComb[i] = (TH1F*)dPbPb_TrgComb[i]->Rebin(nbins_pt,Form("PbPb_measured_spectra_combined_cent%d",i),boundaries_pt);
  //   divideBinWidth(dPbPb_TrgComb[i]);
  // }

  // dPP_Comb = (TH1F*)dPP_Comb->Rebin(nbins_pt,"pp_measured_spectra_combined",boundaries_pt);
  // divideBinWidth(dPP_Comb);
  // dPP_Comb->Scale(1./ dPP_Comb->GetBinContent(nbins_pt));
  
  // Now that we have all the response matrix for the 6 centralities in PbPb and one pp spectra lets start doing the steps:
  // we have 39 pt bins, so we need 1000 gaussian functions for each pt bin.
  
  Int_t unfoldingTrials = 200;
  Double_t meanMeasPbPb[nbins_pt][nbins_cent], sigmaMeasPbPb[nbins_pt][nbins_cent];
  Double_t meanMeasPP[nbins_pt], sigmaMeasPP[nbins_pt];
  Double_t meanUnfoldPbPb[nbins_pt][nbins_cent][unfoldingTrials], sigmaUnfoldPbPb[nbins_pt][nbins_cent][unfoldingTrials];
  Double_t meanUnfoldPP[nbins_pt][unfoldingTrials], sigmaUnfoldPP[nbins_pt][unfoldingTrials]; 
  
  TRandom3 *random = new TRandom3(0);

  for(int u = 0;u<unfoldingTrials;++u){
    cout<<"unfolding trial no = "<<u+1<<endl;
  
    for(int j = 0;j<nbins_pt;++j){
      for(int i = 0;i<nbins_cent;++i){
      
	meanMeasPbPb[j][i] = dPbPb_TrgComb[i]->GetBinContent(j+1);
	sigmaMeasPbPb[j][i] = dPbPb_TrgComb[i]->GetBinError(j+1);

      }// centrality loop

      meanMeasPP[j] = dPP_Comb->GetBinContent(j+1);
      sigmaMeasPP[j] = dPP_Comb->GetBinContent(j+1);
      
    }// nbins_pt loop

    // now proceed to unfolding for each trial.

    for(int i = 0;i<nbins_cent;++i){
      //cout<<"centrality = "<<i<<endl;

      TH1F * hPreUnfoldingSpectra = new TH1F("hPreUnfoldingSpectra","",nbins_pt,0,nbins_pt);
      TH1F * hAfterUnfoldingSpectra;

      for(int j = 0;j<nbins_pt;++j){
	
	hPreUnfoldingSpectra->SetBinContent(j+1, random->Gaus(meanMeasPbPb[j][i], sigmaMeasPbPb[j][i]));
	hPreUnfoldingSpectra->SetBinError(j+1, sigmaMeasPbPb[j][i]/sqrt(unfoldingTrials));
        //if(j==100)cout << " before unfolding bin " << j << " value = " << hPreUnfoldingSpectra->GetBinContent(j+1)<<endl;
        //if(j==100)cout << " before unfolding bin " << j << " error = " << hPreUnfoldingSpectra->GetBinError(j+1)<<endl;
	
      }// nbins_pt loop

      TH1F* hMCGen          = (TH1F*)mPbPb_Response[i]->ProjectionX();
      removeZero(hMCGen);
      //cout << " MC bin " << 100 << " value = " << hMCGen->GetBinContent(100)<<endl;
      bayesianUnfold myUnfoldingMulti(mPbPb_Matrix[i], hMCGen, 0);
      myUnfoldingMulti.unfold(hPreUnfoldingSpectra, BayesIter);

      hAfterUnfoldingSpectra = (TH1F*) myUnfoldingMulti.hPrior->Clone("hAfterUnfoldingSpectra");

      for(int j = 0;j<nbins_pt;++j){
	
	//if(j==100)cout << " before unfolding bin " << j << " value = " << hPreUnfoldingSpectra->GetBinContent(j+1)<<endl;
	//if(j==100)cout << " after  unfolding bin " << j << " value = " << hAfterUnfoldingSpectra->GetBinContent(j+1)<<endl;
	
	meanUnfoldPbPb[j][i][u] = hAfterUnfoldingSpectra->GetBinContent(j+1);
	sigmaUnfoldPbPb[j][i][u] = hAfterUnfoldingSpectra->GetBinError(j+1);

	// cout << "after unfolding meanUnfoldPbPb[" << j << "][" << i << "][" << u<< "] = " <<meanUnfoldPbPb[j][i][u]<<"    ";
	// cout << "after unfolding meanUnfoldPbPb[" << j << "][" << i << "][" << u<< "] = " <<sigmaUnfoldPbPb[j][i][u]<<endl;
	
      }// nbins_pt loop
      
      //hPreUnfoldingSpectra->Print("base");
      //hAfterUnfoldingSpectra->Print("base");
      
      delete hPreUnfoldingSpectra;
      delete hAfterUnfoldingSpectra;
      delete hMCGen; 
      
    }// centrality loop

    cout<<"pp "<<endl;

    // now do it for the pp:
    TH1F * hPreUnfoldingSpectraPP = new TH1F("hPreUnfoldingSpectraPP","",nbins_pt,0,nbins_pt);
    TH1F * hAfterUnfoldingSpectraPP;
    
    for(int j = 0;j<nbins_pt;++j){
	
      hPreUnfoldingSpectraPP->SetBinContent(j+1, random->Gaus(meanMeasPP[j], sigmaMeasPP[j]));
      hPreUnfoldingSpectraPP->SetBinError(j+1, sigmaMeasPP[j]/sqrt(unfoldingTrials));
        
    }// nbins_pt loop
    TH1F* hMCGenPP          = (TH1F*)mPP_Response->ProjectionX();
    removeZero(hMCGenPP);
    bayesianUnfold myUnfoldingMultiPP(mPP_Matrix, hMCGenPP, 0);
    myUnfoldingMultiPP.unfold(hPreUnfoldingSpectraPP, BayesIter);

    hAfterUnfoldingSpectraPP = (TH1F*) myUnfoldingMultiPP.hPrior->Clone("hAfterUnfoldingSpectraPP");

    for(int j = 0;j<nbins_pt;++j){

      meanUnfoldPP[j][u] = hAfterUnfoldingSpectraPP->GetBinContent(j+1);
      sigmaUnfoldPP[j][u] = hAfterUnfoldingSpectraPP->GetBinError(j+1);

    }// nbins_pt loop

    delete hPreUnfoldingSpectraPP;
    delete hAfterUnfoldingSpectraPP;
    delete hMCGenPP; 
    
  }// unfolding trials loop


  // Now that we have all the necesary values we need, lets proceed to fill a histogram with the mean values for each ptbin and get the corrected values.
  TH1F * hAfterUnfoldingptBinDistribution[nbins_pt];
  TH1F * hCorrUnfoldingPbPb[nbins_cent];
  
  for(int i = 0;i<nbins_cent;++i){

    hCorrUnfoldingPbPb[i] = new TH1F(Form("PbPb_BayesianUnfolded_cent%d",i),"Spectra after correction", nbins_pt, 0, nbins_pt);

    for(int j = 0;j<nbins_pt;++j){
      
      //hAfterUnfoldingptBinDistribution[j] = new TH1F(Form("hAfterUnfoldingptBinDistribution_ptBin%d",j),"",100,	(meanMeasPbPb[j][i]-10) * sigmaMeasPbPb[j][i], (meanMeasPbPb[j][i]+10) * sigmaMeasPbPb[j][i]);
      hAfterUnfoldingptBinDistribution[j] = new TH1F(Form("hAfterUnfoldingptBinDistribution_ptBin%d",j),"",100,	0, 1);
      for(int u = 0;u<unfoldingTrials;++u){

	hAfterUnfoldingptBinDistribution[j]->Fill(meanUnfoldPbPb[j][i][u]);

	//if(j==100) cout<< "unfolding_trial = " << u+1 << " mean unfold value = "<< meanUnfoldPbPb[j][i][u] <<endl;

      }// unfolding trials loop

      //if(j==100) cout<<"Mean of that value for pt=100 = "<< (Float_t)hAfterUnfoldingptBinDistribution[j]->GetMean() <<endl;      
      hCorrUnfoldingPbPb[i]->SetBinContent(j+1, hAfterUnfoldingptBinDistribution[j]->GetMean());
      //cout<<"centrality bin "<<i<<", pT bin "<<j<<" bin Content = "<<hCorrUnfoldingPbPb[i]->GetBinContent(j+1)<<endl;
      hCorrUnfoldingPbPb[i]->SetBinError(j+1, hAfterUnfoldingptBinDistribution[j]->GetRMS());
      //cout<<"centrality bin "<<i<<", pT bin "<<j<<" bin Error   = "<<hCorrUnfoldingPbPb[i]->GetBinError(j+1)<<endl;

      delete hAfterUnfoldingptBinDistribution[j];
      
    }// nbins_pt loop

  }// centrality loop

  // similar for the pp:
  TH1F * hAfterUnfoldingptBinDistributionPP[nbins_pt];
  TH1F * hCorrUnfoldingPP;
  
  hCorrUnfoldingPP = new TH1F("PP_BayesianUnfolded","Spectra after unfolding error correction",nbins_pt, 0, nbins_pt);
  
  for(int j = 0;j<nbins_pt;++j){
    
    //hAfterUnfoldingptBinDistributionPP[j] = new TH1F(Form("hAfterUnfoldingptBinDistributionPP_ptBin%d",j),"",1000,(meanMeasPP[j]-10) * sigmaMeasPP[j], (meanMeasPP[j]+10) * sigmaMeasPP[j]);
    hAfterUnfoldingptBinDistributionPP[j] = new TH1F(Form("hAfterUnfoldingptBinDistributionPP_ptBin%d",j),"",100, 0, 1);
    for(int u = 0;u<unfoldingTrials;++u){
      
      hAfterUnfoldingptBinDistributionPP[j]->Fill(meanUnfoldPP[j][u]);
      
    }// unfolding trials loop
    
    hCorrUnfoldingPP->SetBinContent(j+1, hAfterUnfoldingptBinDistributionPP[j]->GetMean());
    //cout<<"PP pT bin "<<j<<" bin Content = "<<hCorrUnfoldingPP->GetBinContent(j+1)<<endl;
    hCorrUnfoldingPP->SetBinError(j+1, hAfterUnfoldingptBinDistributionPP[j]->GetRMS());
    //cout<<"PP pT bin "<<j<<" bin Error   = "<<hCorrUnfoldingPP->GetBinError(j+1)<<endl;
    
    delete hAfterUnfoldingptBinDistributionPP[j];
    
  }// nbins_pt loop
    
  TFile f(Form("../../Output/Pawan_ntuple_PbPb_R%d_pp_R%d_%s_unfoldingCut_%d_data_driven_correction_ak%s%s_%d.root",radius, radiusPP, etaWidth ,unfoldingCut,algo,jet_type,date.GetDate()),"RECREATE");
  f.cd();

  for(int i = 0;i<nbins_cent;i++) {

    hCorrUnfoldingPbPb[i]->Scale(145.156 * 1e9);
    //hCorrUnfoldingPbPb[i] = (TH1F*)hCorrUnfoldingPbPb[i]->Rebin(nbins_pt_coarse, Form("PbPb_BayesianUnfolded_cent%d",i), boundaries_pt_coarse);
    hCorrUnfoldingPbPb[i]->Write();
    hCorrUnfoldingPbPb[i]->Print("base");

    dPbPb_TrgComb[i]->Scale(145.156 * 1e9);
    //dPbPb_TrgComb[i] = (TH1F*)dPbPb_TrgComb[i]->Rebin(nbins_pt_coarse, Form("PbPb_measured_cent%d",i), boundaries_pt_coarse);
    dPbPb_TrgComb[i]->Write();
    dPbPb_TrgComb[i]->Print("base");
    
  }

  hCorrUnfoldingPP->Scale(5.3 * 1e9);
  //hCorrUnfoldingPP = (TH1F*)hCorrUnfoldingPP->Rebin(nbins_pt_coarse, "PP_BayesianUnfolded", boundaries_pt_coarse);
  hCorrUnfoldingPP->Write();
  hCorrUnfoldingPP->Print("base");
  dPP_Comb->Scale(5.3 * 1e9);
  //dPP_Comb = (TH1F*)dPP_Comb->Rebin(nbins_pt_coarse, "PP_measured", boundaries_pt_coarse);  
  dPP_Comb->Write();
  dPP_Comb->Print("base");
  
  f.Write();
  f.Close();

  timer.Stop();
  if(printDebug) cout<<"CPU time (mins) = "<<(Float_t)timer.CpuTime()/60<<endl;
  if(printDebug) cout<<"Real tile (mins) = "<<(Float_t)timer.RealTime()/60<<endl;
  

}