Exemple #1
0
void drawDist(const char* infilename, const char* system, Int_t rWrite, Int_t rPerformance) {

        myOptions(0);

        gROOT->ForceStyle();
        gStyle->SetPalette(1.0);

        TDatime now;
        int iDate = now.GetDate();
        int iYear=iDate/10000;
        int iMonth=(iDate%10000)/100;
        int iDay=iDate%100;
        char* cMonth[12]={"Jan","Feb","Mar","Apr","May","Jun",
                          "Jul","Aug","Sep","Oct","Nov","Dec"};
        char cStamp1[25],cStamp2[25];
        sprintf(cStamp1,"%i %s %i",iDay, cMonth[iMonth-1], iYear);
        sprintf(cStamp2,"%i/%.2d/%i",iDay, iMonth, iYear);

        TFile *f = new TFile(infilename, "read");
        // TList *list = (TList*)f->Get("femtolist");

        // pseudorapidity vs pt
        TH2D* ypt =(TH2D*)f->Get(Form("EtaPtcutPass1%stpcM%i",system,0));

        int minMultBin = 0;
        int maxMultBin = 6;
        double EvMultall = 0;

        for(int i = minMultBin; i < maxMultBin; i++) {
                TH1D* yptN =(TH1D*)f->Get(Form("EtaPtcutPass1%stpcM%i",system,i));
                ypt->Add(yptN);
                //delete hEvMult;
        }

        TCanvas *c2 = new TCanvas("pseudorapidity vs pt", "pseudorapidity vs pt");
        c2->SetGridx();
        c2->SetGridy();
        c2->SetFillColor(10);
        ypt->GetXaxis()->SetTitle("#eta");
        ypt->GetYaxis()->SetTitle("p_{T}");
        ypt->GetXaxis()->SetTitleOffset(1.3);
        ypt->GetYaxis()->SetTitleOffset(1.3);
        ypt->GetXaxis()->SetRangeUser(-0.8,0.8);
        ypt->GetYaxis()->SetRangeUser(0.1,8.);
        ypt->Draw("colz");

        // https://wiki.bnl.gov/eic/index.php/ROOT#Moving_and_resizing_the_palette_axis_of_a_2D_histogram
        gPad->SetRightMargin( 0.12 ); // The default right margin is 0.1 i.e. 10% of the image width
//   TPaletteAxis* palette
//       = dynamic_cast<TPaletteAxis*>( myHistogram.GetListOfFunctions()->FindObject( "palette" ) );
//   if( palette ) {
//     palette->SetX1NDC( 0.86 ); // Start the palette 86 % of the way across the image
//     palette->SetX1NDC( 0.91 ); // End the palette 91% of the way across the image
//     gPad->Modified(); // Update with the new position
//   } // if

        postprocess(c2,Form("ypt%s",system),rWrite,rPerformance);

}
Int_t THaScaler::Init( const TDatime& time ) 
{
  // Initialize scalers for given date/time.
  // Accuracy is 1 day. Only date is used, time is ignored.

  Int_t i = time.GetDate();
  char date[11];
  sprintf( date, "%2.2d-%2.2d-%4.4d",i%100,(i%10000-i%100)/100,i/10000 );
  return Init( date );
};
void xrootdTestVanderbilt(const int iOption=0) {

  TDatime *dateTime = new TDatime;
  int iDate = dateTime->GetDate();
  int iTime = dateTime->GetTime();
  cout << "  Begin Vanderbilt access testing " << iDate << " at " << iTime << endl;

  if(iOption == 0 || iOption == 1) {
    TFile *f = TFile::Open("root://cmsxrootd.fnal.gov//store/test/xrootd/T2_US_Vanderbilt//store/mc/SAM/GenericTTbar/GEN-SIM-RECO/CMSSW_5_3_1_START53_V5-v1/0013/CE4D66EB-5AAE-E111-96D6-003048D37524.root");
    if(f) {
      cout << "\n cmsxrootd.fnal.gov successful access to Vanderbilt" << endl;
      f->ls();
      f->Close();
    }
    else {
      cout << "\n cmsxrootd.fnal.gov unsuccessful access to Vanderbilt" << endl;
    }
    dateTime->Set();     // set to system date/time
    iDate = dateTime->GetDate();
    iTime = dateTime->GetTime();
    cout << "  Completed Vanderbilt access test from FNAL on " << iDate << " at " << iTime << endl;
  } // check on iOption = 0 or iOption = 1
  if(iOption == 0 || iOption == 2) {
    TFile *g = TFile::Open("root://cms-xrd-global.cern.ch//store/test/xrootd/T2_US_Vanderbilt//store/mc/SAM/GenericTTbar/GEN-SIM-RECO/CMSSW_5_3_1_START53_V5-v1/0013/CE4D66EB-5AAE-E111-96D6-003048D37524.root");
    if(g) {
      cout << "\n cms-xrd-global.cern.ch successful access to Vanderbilt" << endl;
      g->ls();
      g->Close();
    }
    else {
      cout << "\n cms-xrd-global.cern.ch unsuccessful access to Vanderbilt" << endl;
    }
    dateTime->Set();     // set to system date/time
    iDate = dateTime->GetDate();
    iTime = dateTime->GetTime();
    cout << "  Completed Vanderbilt access test from CERN on " << iDate << " at " << iTime << endl;
  } // check on iOption = 0 or iOption = 2
  dateTime->Set();     // set to system date/time
  cout << "\n  Completed Vanderbilt access testing " << iDate << " at " << iTime << endl;
return;
}
void ALICEWorkInProgress(TCanvas *c,TString today){
 //date must be in the form: 04/05/2010
 if(today=="today"){
   TDatime startt;                                                                                                                                                        
   int date=startt.GetDate();

   int y=date/10000;
   int m=(date%10000)/100;
   int d=date%100;


   today="";
   today+=d;
   if(m<10)
     today.Append("/0");
   else today.Append("/");
   today+=m;
   today.Append("/");
   today+=y;  

 }
 TPad *myPadLogo = new TPad("myPadLogo", "Pad for ALICE Logo",0.67,0.65,0.82,0.89);
 //  myPadLogo->SetFillColor(2); 
 myPadLogo->SetBorderMode(0);
 myPadLogo->SetBorderSize(2);
 myPadLogo->SetFrameBorderMode(0);
 myPadLogo->SetLeftMargin(0.0);
 myPadLogo->SetTopMargin(0.0);
 myPadLogo->SetBottomMargin(0.0);
 myPadLogo->SetRightMargin(0.0);
 myPadLogo->Draw();
 myPadLogo->cd();
 TASImage *myAliceLogo = new TASImage("/u/mfasel/work/electron/Spectrum/alice_logo.png");
 myAliceLogo->Draw();
 c->cd();
 TPaveText* t1=new TPaveText(0.59,0.59,0.89,0.66,"NDC");
 t1->SetFillStyle(0);
 t1->SetBorderSize(0);
 t1->AddText(0.,0.,"ALICE Performance");
 t1->SetTextColor(kRed);
 t1->SetTextFont(42);
 t1->Draw();
 TPaveText* t2=new TPaveText(0.59,0.54,0.89,0.60,"NDC");
 t2->SetFillStyle(0);
 t2->SetBorderSize(0);
 t2->SetTextColor(kRed);
 t2->SetTextFont(52);
 t2->AddText(0.,0.,today.Data());
 t2->Draw();
}
void prepareAll() {
        myOptions(0);

        gROOT->ForceStyle();
        gStyle->SetPalette(1.0);

        TDatime now;
        int iDate = now.GetDate();
        int iYear=iDate/10000;
        int iMonth=(iDate%10000)/100;
        int iDay=iDate%100;
        char* cMonth[12]={"Jan","Feb","Mar","Apr","May","Jun",
                          "Jul","Aug","Sep","Oct","Nov","Dec"};
        char cStamp1[25],cStamp2[25];
        sprintf(cStamp1,"%i %s %i",iDay, cMonth[iMonth-1], iYear);
        sprintf(cStamp2,"%i/%.2d/%i",iDay, iMonth, iYear);
}
Exemple #6
0
void RAA_fakecheck(int startfile = 0, int endfile = 1, int radius = 3, char *algo = "Vs", char *jet_type = "PF"){

  TH1::SetDefaultSumw2();
  TStopwatch timer;
  timer.Start();

  bool printDebug = true;

  if(printDebug) cout<<"Radius = "<<radius<<" and Algo = "<<algo<<" "<<jet_type<<endl;

  // Change to macro to run on condor since its taking a freaking long time. 
  // 

  std::string infile;
  infile = "jetRAA_PbPb_data_forest.txt";
  
  std::ifstream instr(infile.c_str(),std::ifstream::in);
  std::string filename;
  //int nFiles = 11;

  //just to read the files till the start number
  if(printDebug) cout<<"reading from "<<startfile<<" to "<<endfile<<endl;
  
  for(int ifile = 0;ifile<startfile;ifile++){
    instr>>filename;
  }

  const int N = 5;
  //Create chain
  TChain* ch[N];

  string dir[N] = {
    "hltanalysis",
    "skimanalysis",
    //"hcalNoise",
    Form("ak%s%d%sJetAnalyzer",algo,radius,jet_type),
    //"akPu5PFJetAnalyzer",
    //"multiPhotonAnalyzer",
    //"ppTrack",
    //"pfcandAnalyzer",
    //"anaMET",
    //"muonTree",
    "hiEvtAnalyzer",
    "hltobject"
  };
    
  string trees[N] = {
    "HltTree",
    "HltTree",
    //"hbhenoise",
    "t",
    //"t",
    //"photon",
    //"trackTree",
    //"pfTree",
    //"metTree",
    //"HLTMuTree",
    "HiTree",
    "jetObjTree"
  };

  // data files for PbPb Jet55or66 are a list. So we need to TChain them first and then we should be able to use those chaing to get the events. they will have the same names as we used here. 

  //TChain *jetpbpb1 = new TChain(Form("ak%s%dPFJetAnalyzer/t",algo,radius));
  //TChain *evtpbpb1 = new TChain("hiEvtAnalyzer/HiTree");
  //TChain *hltpbpb1 = new TChain("hltanalysis/HltTree");
  //TChain *skmpbpb1 = new TChain("skimanalysis/HltTree");
  //TChain *hltobjpbpb1 = new TChain("hltobject/jetObjTree");
  
  for(int i = 0;i<N;i++)       ch[i] = new TChain(string(dir[i]+"/"+trees[i]).data());

  for(int ifile = startfile;ifile<endfile;ifile++){
    
    instr>>filename;
    if(printDebug) cout<<"File: "<<ifile<<" = "<<filename<<endl;

    for(int i = 0;i<N;i++){
      //ch[i] = new TChain(string(dir[i]+"/"+trees[i]).data());
      ch[i]->Add(filename.c_str());
      if(printDebug) cout << "Tree loaded  " << string(dir[i]+"/"+trees[i]).data() << endl;
      if(printDebug) cout << "Entries : " << ch[i]->GetEntries() << endl;
    }

    //jetpbpb1->Add(filename.c_str());
    //hltpbpb1->Add(filename.c_str());
    //skmpbpb1->Add(filename.c_str());
    //hltobjpbpb1->Add(filename.c_str());
    //evtpbpb1->Add(filename.c_str());
    //if(printDebug) cout<<"Entries = "<<jetpbpb1->GetEntries()<<endl;

  }


  //these ones were used when i ran the macro standalone in root. 
//   // file list - are all named like this: /mnt/hadoop/cms/store/user/dgulhan/HIMC/Jet55or65/HIRun2011-14Mar2014-v2-6lumi-jet55or65-forest-v9/merged/HiForest_Pythia_Hydjet_Jet80_Track8_Jet19_STARTHI53_LV1_merged_forest_##.root
//   // where ## goes from 0-11

//   for(int i = 0;i<=11;i++){
//     if(i==9)continue;
//     jetpbpb1->Add(Form("/mnt/hadoop/cms/store/user/dgulhan/HIMC/Jet55or65/HIRun2011-14Mar2014-v2-6lumi-jet55or65-forest-v9/merged/HiForest_Pythia_Hydjet_Jet80_Track8_Jet19_STARTHI53_LV1_merged_forest_%d.root",i));
//     hltpbpb1->Add(Form("/mnt/hadoop/cms/store/user/dgulhan/HIMC/Jet55or65/HIRun2011-14Mar2014-v2-6lumi-jet55or65-forest-v9/merged/HiForest_Pythia_Hydjet_Jet80_Track8_Jet19_STARTHI53_LV1_merged_forest_%d.root",i));
//     skmpbpb1->Add(Form("/mnt/hadoop/cms/store/user/dgulhan/HIMC/Jet55or65/HIRun2011-14Mar2014-v2-6lumi-jet55or65-forest-v9/merged/HiForest_Pythia_Hydjet_Jet80_Track8_Jet19_STARTHI53_LV1_merged_forest_%d.root",i));
//     evtpbpb1->Add(Form("/mnt/hadoop/cms/store/user/dgulhan/HIMC/Jet55or65/HIRun2011-14Mar2014-v2-6lumi-jet55or65-forest-v9/merged/HiForest_Pythia_Hydjet_Jet80_Track8_Jet19_STARTHI53_LV1_merged_forest_%d.root",i));
//     hltobjpbpb1->Add(Form("/mnt/hadoop/cms/store/user/dgulhan/HIMC/Jet55or65/HIRun2011-14Mar2014-v2-6lumi-jet55or65-forest-v9/merged/HiForest_Pythia_Hydjet_Jet80_Track8_Jet19_STARTHI53_LV1_merged_forest_%d.root",i));
  
//   }

  //jetpbpb1->AddFriend(evtpbpb1);
  //jetpbpb1->AddFriend(hltpbpb1);
  //jetpbpb1->AddFriend(skmpbpb1);
  //jetpbpb1->AddFriend(hltobjpbpb1);

  ch[2]->AddFriend(ch[0]);
  ch[2]->AddFriend(ch[1]);
  ch[2]->AddFriend(ch[3]);
  ch[2]->AddFriend(ch[4]);

  ch[3]->AddFriend(ch[0]);
  ch[3]->AddFriend(ch[1]);
  ch[3]->AddFriend(ch[2]);
  ch[3]->AddFriend(ch[4]);

  Float_t nEntries = (Float_t)ch[2]->GetEntries();
  if(printDebug) cout<<"Total number of entries = "<<nEntries<<endl;

  //jetpbpb1->Print();
  //jetpbpb1->GetListOfBranches();
  //jetpbpb1->GetListOfFriends();

  //jetpbpb1->AddFriend(hltpbpb1);
  
  //if(printDebug) cout<<"# of events which satisfy the Jet55 criteria = "<<ch[2]->GetEntries("HLT_HIJet55_v1")<<endl;
  //if(printDebug) cout<<"# of events which satisfy the Jet65 criteria = "<<ch[2]->GetEntries("HLT_HIJet65_v1")<<endl;
  //if(printDebug) cout<<"testing if HLT tree knows that branch, no of entries there = "<<hltpbpb1->GetEntries("HLT_HIJet55_v1")<<endl;
  //if(printDebug) cout<<"# of events which satisfy Jet55 but fail Jet65 and Jet80 = "<<ch[2]->GetEntries("HLT_HIJet55_v1&&!HLT_HIJet65_v1&&!HLT_HIJet80_v1")<<endl;
  
  TDatime date;

  // declare the output file here: 
  TFile fout(Form("/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_20/src/Output/pbpb_ak%s%d%s_fakejet_histos_%d_%d.root",algo,radius,jet_type,date.GetDate(),endfile),"RECREATE");
  fout.cd();
  
  
  //histogram from the HLT_HIJet55 trigger alone
  TH1F *hJet55 = new TH1F("hJet55","Jets pt which are selected by HLT_HIJet55 trigger (along with eventsel)",1000,0,1000);
  TH1F *hJet55_QA1 = new TH1F("hJet55_QA1","HLT_HIJet55 jets with chMax/jtpt>0.05 (along with eventsel)",1000,0,1000);
  TH1F *hJet55_QA2_a = new TH1F("hJet55_QA2_a","HLT_HIJet55 jets with chargedMax/chargedSum<0.975",1000,0,1000);
  TH1F *hJet55_QA2_b = new TH1F("hJet55_QA2_b","HLT_HIJet55 jets with Max(neutralMax,chargedMax)/Max(chargedSum,neutralSum)<0.975 (along with eventsel)",1000,0,1000);
  TH1F *hJet55_QA1_2b = new TH1F("hJet55_QA1_2b","HLT_HIJet55 jets with chMax/jtpt>0.01 and Max(neutralMax,chargedMax)/Max(chargedSum,neutralSum)<0.975 (along with eventsel)",1000,0,1000);
  TH1F *hJet55_QA3 = new TH1F("hJet55_QA3","HLT_HIJet55 jets with jtpt/trgobjpt<3 (along with eventsel)",1000,0,1000);
  TH1F *hJet55_QA4 = new TH1F("hJet55_QA4","HLT_HIJet55 jets with (chSum+phSum+neSum+muSum+eSum)/jtpt>1.01 (along with eventsel)",1000,0,1000);

  TH1F *hJet65 = new TH1F("hJet65","Jets pt which are selected by HLT_HIJet65 trigger (along with eventsel)",1000,0,1000);
  TH1F *hJet65_QA1 = new TH1F("hJet65_QA1","HLT_HIJet65 jets with chMax/jtpt>0.01 (along with eventsel)",1000,0,1000);
  TH1F *hJet65_QA2_a = new TH1F("hJet65_QA2_a","HLT_HIJet65 jets with chargedMax/chargedSum<0.975",1000,0,1000);
  TH1F *hJet65_QA2_b = new TH1F("hJet65_QA2_b","HLT_HIJet65 jets with Max(neutralMax,chargedMax)/Max(chargedSum,neutralSum)<0.975 (along with eventsel)",1000,0,1000);
  TH1F *hJet65_QA1_2b = new TH1F("hJet65_QA1_2b","HLT_HIJet65 jets with chMax/jtpt>0.01 and Max(neutralMax,chargedMax)/Max(chargedSum,neutralSum)<0.975 (along with eventsel)",1000,0,1000);
  TH1F *hJet65_QA3 = new TH1F("hJet65_QA3","HLT_HIJet65 jets with jtpt/trgobjpt<3 (along with eventsel)",1000,0,1000);
  TH1F *hJet65_QA4 = new TH1F("hJet65_QA4","HLT_HIJet65 jets with (chSum+phSum+neSum+muSum+eSum)/jtpt>1.01 (along with eventsel)",1000,0,1000);

  TH3F *hJet55_3D = new TH3F("hJet55_3D","3D lego histogram of jets with Jet55 trigger, pt vs eta vs phi",60,-2.5,2.5,60,-3,3,1000,0,1000);
  TH1F *hJet55Fake = new TH1F("hJet55Fake","jets with pt>80 which pass Jet55 and fail higher triggers",1000,0,1000);
  // the above one is just to get a feel for all the jets in the Jet55 trigger. 

  TH1F *hJet55_trg = new TH1F("hJet55_trg","HLT_HIJet55 and trgpt>=55 and <65 along with eventsel",1000,0,1000);
  TH1F *hJet55_trg_QA1 = new TH1F("hJet55_trg_QA1","HLT_HI_Jet55 and trgpt>=55 and <65 eventsel and chMax/jtpt>0.01",1000,0,1000);
  TH1F *hJet55_trg_QA2_a = new TH1F("hJet55_trg_QA2_a","HLT_HIJet55 with trgpt>=55 and <65 jets with chargedMax/chargedSum<0.975",1000,0,1000);
  TH1F *hJet55_trg_QA2_b = new TH1F("hJet55_trg_QA2_b","HLT_HI_Jet55 and trgpt>=55 and <65 eventsel and  Max(neutralMax,chargedMax)/Max(chargedSum,neutralSum)<0.975",1000,0,1000);
  TH1F *hJet55_trg_QA1_2b = new TH1F("hJet55_trg_QA1_2b","HLT_HI_Jet55 and trgpt>=55 and <65 eventsel and  Max(neutralMax,chargedMax)/Max(chargedSum,neutralSum)<0.975 and chMax/jtpt>0.01",1000,0,1000);
  TH1F *hJet55_trg_QA3 = new TH1F("hJet55_trg_QA3","HLT_HI_Jet55 and trgpt>=55 and <65 eventsel and jtpt/trgobjpt<3",1000,0,1000);
  TH1F *hJet55_trg_QA4 = new TH1F("hJet55_trg_QA4","HLT_HIJet55 and trgpt>=55 and <65 jets with (chSum+phSum+neSum+muSum+eSum)/jtpt>1.01 (along with eventsel)",1000,0,1000);

  TH1F *hJet55_only = new TH1F("hJet55_only","HLT_HIJet55 jets with no HLT_HIJet65 and no 80 along with eventsel",1000,0,1000);
 
  TH1F *hJet65_only = new TH1F("hJet65_only","HLT_HIJet65 jets with no HLT_HIJet80 along with eventsel",1000,0,1000);
  TH1F *hJet65_trg = new TH1F("hJet65_trg","HLT_HIJet65 and trgpt>=65 and <80 along with eventsel",1000,0,1000);
  TH1F *hJet65_trg_QA1 = new TH1F("hJet65_trg_QA1","HLT_HIJet65 and trgpt>=65 and <80 with chMax/jtpt>0.01 and with eventsel",1000,0,1000);
  TH1F *hJet65_trg_QA2_a = new TH1F("hJet65_trg_QA2_a","HLT_HIJet55 with trgpt>=65 and <80 jets with chargedMax/chargedSum<0.975",1000,0,1000);
  TH1F *hJet65_trg_QA2_b = new TH1F("hJet65_trg_QA2_b","HLT_HIJet65 and trgpt>=65 and <80 with evetsel and  Max(neutralMax,chargedMax)/Max(chargedSum,neutralSum)<0.975",1000,0,1000);
  TH1F *hJet65_trg_QA1_2b =  new TH1F("hJet65_trg_QA1_2b","HLT_HI_Jet65 and trgpt>=65 and <80 eventsel and  Max(neutralMax,chargedMax)/Max(chargedSum,neutralSum)<0.975 and chMax/jtpt>0.01",1000,0,1000);
  TH1F *hJet65_trg_QA3 = new TH1F("hJet65_trg_QA3","HLT_HIJet 65 and trgpt>=65 and <80 with jtpt/trgobjpt<3 and eventsel",1000,0,1000);
  TH1F *hJet65_trg_QA4 = new TH1F("hJet65_trg_QA4","HLT_HIJet55 with trgpt>=65 and <80 jets with (chSum+phSum+neSum+muSum+eSum)/jtpt>1.01 (along with eventsel)",1000,0,1000);


  // should i make one with QA1 and QA3? since QA2 wont work in R=0.2 
  
  TH1F *hJet55_trg_QA1_3 = new TH1F("hJet55_trg_QA1_3","HLT_HIJet55 jets with trgpt>=55 and <65 with eventsel and QA1 and QA3",1000,0,1000);
  TH1F *hJet65_trg_QA1_3 = new TH1F("hJet65_trg_QA1_3","HLT_HIJet65 jets with trgpt>=65 and <80 with eventsel and QA1 and QA3",1000,0,1000);

  TH1F *hJet55_QA1_3 = new TH1F("hJet55_QA1_3","HLT_HIJet55 jets with eventsel and QA1 and QA3",1000,0,1000);
  TH1F *hJet65_QA1_3 = new TH1F("hJet65_QA1_3","HLT_HIJet65 jets with eventsel and QA1 and QA3",1000,0,1000);
  
  /*
  
  //include the jet80 tree just to find the numbers the fake cut removes. 
  TFile *fin80 = TFile::Open("/mnt/hadoop/cms/store/user/velicanu/HIRun2011-14Mar2014-v2-6lumi-jet80-forest-v4ANDv9-merged/0.root");
  TTree *Jet80 = (TTree*)fin80->Get(Form("ak%s%dPFJetAnalyzer/t",algo,radius));
  //Jet80->Print();
  TTree *evt80 = (TTree*)fin80->Get("hiEvtAnalyzer/HiTree");
  //evt80->Print();
  TTree *hlt80 = (TTree*)fin80->Get("hltanalysis/HltTree");
  //hlt80->Print();
  TTree *skm80 = (TTree*)fin80->Get("skimanalysis/HltTree");
  //skm80->Print();
  TTree *Trg80 = (TTree*)fin80->Get("hltobject/jetObjTree");
  //Trg80->Print();
  
  Jet80->AddFriend(evt80);
  Jet80->AddFriend(hlt80);
  Jet80->AddFriend(skm80);
  Jet80->AddFriend(Trg80);
  */

  TCut jet55 = "HLT_HIJet55_v1";
  TCut jet65 = "HLT_HIJet65_v1";
  TCut jet80 = "HLT_HIJet80_v1";
  TCut evtSel = "abs(vz)<15&&pcollisionEventSelection&&pHBHENoiseFilter&&abs(jteta)<2";
  TCut qalCut1 = "(chargedMax/jtpt)>0.05";
  TCut qalCut2_b = "(TMath::Max(chargedMax,neutralMax)/TMath::Max(chargedSum,neutralSum))<0.975";
  TCut qalCut2_a = "(chargedMax/chargedSum)<0.975";
  TCut qalCut3 = "(jtpt/pt)<3";
  TCut qalCut4 = "((chargedSum+photonSum+neutralSum+muSum+eSum)/jtpt)>1.01";
  TCut jet55only = "HLT_HIJet55_v1&&!HLT_HIJet65_v1&&!HLT_HIJet80_v1";
  TCut jet65only = "HLT_HIJet65_v1&&!HLT_HIJet80_v1";
  TCut largejetpt = "jtpt>80";
  TCut trg55 = "pt>=55&&pt<65";
  TCut trg65 = "pt>=65&&pt<80";
  TCut trg80 = "pt>=80";

  //TH1F total,evtSel,jet55,jet55_evtsel,jet55only_ectsel,jet55_evtSel_QA1,jet55_evtSel_QA2,jet55_evtSel_QA3,jet55_evtSel_QA1_2,jet55_evtSel_QA1_3,jet55_evtSel_QA3_2;
  //TH1F jet55_trg55,jet55_trg_evtSel,jet55only_trg55_evtSel,jet55_trg55_evtSel_QA1,jet55_trg55_evtSel_QA2,jet55_trg55_evtSel_QA3,jet55_trg55_evtSel_qalCut1_qalCut2,jet55_trg55_evtSel_qalCut1_qalCut3,jet55_trg55_evtSel_qalCut3_qalCut2;
  //TH1F jet65,jet65_evtSel,jet65only_evtSel,jet65_evtSel_qalCut1,jet65_evtSel_qalCut3,jet65_evtSel_qalCut3,jet65_evtSel_qalCut1_qalCut3,jet65_evtSel_qalCut1_qalCut2,jet65_evtSel_qalCut3_qalCut2;
  //TH1F jet65_
  
  
  //if(printDebug) cout<<"total # of entries = "<<ch[2]->GetEntries()<<endl;
  /*
  if(printDebug) cout<<"total # of entries = "<<ch[2]->GetEntries()<<endl;
  ch[3]->Draw("hiBin>>total");
  if(printDebug) cout<<"with evtSel added  = "<<ch[2]->GetEntries(evtSel)<<endl;
  //ch[2]->Draw("evtSel","hiBin",);
  if(printDebug) cout<<"with evtSel added  = "<<ch[2]->GetEntries(evtSel)<<endl;
  ch[3]->Draw("hiBin>>evtSel",evtSel);
  if(printDebug) cout<<"with jet55"<<" = "<<ch[2]->GetEntries(jet55)<<endl;
  ch[3]->Draw("hiBin>>jet55",jet55);
  if(printDebug) cout<<"with evtSel and Jet55 added = "<<ch[2]->GetEntries(jet55&&evtSel)<<endl;
  ch[3]->Draw("hiBin>>jet55_evtsel",jet55&&evtSel);
  if(printDebug) cout<<"with Jet55_only and evtSel added = "<<ch[2]->GetEntries(jet55only&&evtSel)<<endl;
  ch[3]->Draw("hiBin>>jet55only_evtsel",jet55only&&evtSel);
  */
  //ch[2]->Project("total","hiBin");
  
  //cout<<"with evtSel added  = "<<ch[2]->GetEntries(evtSel)<<endl;
  //ch[2]->Project("evtSel","hiBin",);
  //if(printDebug) cout<<"with evtSel added  = "<<ch[2]->GetEntries(evtSel)<<endl;
  //ch[2]->Project("evtSel","hiBin",evtSel);
  /*
  if(printDebug) cout<<"with jet55"<<" = "<<ch[2]->GetEntries(jet55)<<endl;
  //ch[2]->Project("jet55","hiBin",jet55);
  if(printDebug) cout<<"with evtSel and Jet55 added = "<<ch[2]->GetEntries(jet55&&evtSel)<<endl;
  //ch[2]->Project("jet55_evtsel","hiBin",jet55&&evtSel);
  if(printDebug) cout<<"with Jet55_only and evtSel added = "<<ch[2]->GetEntries(jet55only&&evtSel)<<endl;
  //ch[2]->Project("jet55only_evtsel","hiBin",jet55only&&evtSel);

  if(printDebug) cout<<"jet55 && evtSel && qalCut1"<<" = "<<ch[2]->GetEntries(jet55&&evtSel&&qalCut1)<<endl;
  //ch[2]->Project("jet55_evtSel_QA1","hiBin",jet55&&evtSel&&qalCut1);
  if(printDebug) cout<<"jet55 && evtSel && qalCut2"<<" = "<<ch[2]->GetEntries(jet55&&evtSel&&qalCut2)<<endl;
  //ch[2]->Project("jet55_evtSel_QA2","hiBin",jet55&&evtSel&&qalCut2);
  if(printDebug) cout<<"jet55 && evtSel && qalCut3"<<" = "<<ch[2]->GetEntries(jet55&&evtSel&&qalCut3)<<endl;
  //ch[2]->Project("jet55_evtSel_QA3","hiBin",jet55&&evtSel&&qalCut3);

  if(printDebug) cout<<"jet55 and evtSel and QA1_2 = "<<ch[2]->GetEntries(jet55&&evtSel&&qalCut1&&qalCut2)<<endl;
  //ch[2]->Project("jet55_evtSel_QA1_QA2","hiBin",jet55&&evtSel&&qalCut1&&qalCut2);
  if(printDebug) cout<<"jet55 and evtSel and QA1_3 = "<<ch[2]->GetEntries(jet55&&evtSel&&qalCut1&&qalCut3)<<endl;
  //ch[2]->Project("jet55_evtSel_QA1_QA3","hiBin",jet55&&evtSel&&qalCut1&&qalCut3);
  if(printDebug) cout<<"jet55 and evtSel and QA2_3 = "<<ch[2]->GetEntries(jet55&&evtSel&&qalCut2&&qalCut3)<<endl;
  //ch[2]->Project("jet55_evtSel_QA3_QA2","hiBin",jet55&&evtSel&&qalCut3&&qalCut2);

  */
  //cout<<"with jet55 and trgObjpt selection"<<" = "<<ch[2]->GetEntries(jet55&&trg55)<<endl;
  //ch[2]->Project("jet55_trg55","hiBin",jet55&&trg55);
  /*
  if(printDebug) cout<<"with evtSel and Jet55 and trgobjpt added = "<<ch[2]->GetEntries(jet55&&trg55&&evtSel)<<endl;
  //ch[2]->Project("jet55_trg55_evtSel","hiBin",jet55&&trg55&&evtSel);
  if(printDebug) cout<<"with Jet55_only and trgObjpt and evtSel added = "<<ch[2]->GetEntries(jet55only&&trg55&&evtSel)<<endl;
  //ch[2]->Project("jet55only_trg55_evtSel","hiBin",jet55only&&trg55&&evtSel);

  if(printDebug) cout<<"jet55 and trgObjpt && evtSel && qalCut1"<<" = "<<ch[2]->GetEntries(jet55&&trg55&&evtSel&&qalCut1)<<endl;
  //ch[2]->Project("jet55_trg55_evtSel_QA1","hiBin",jet55&&trg55&&evtSel&&qalCut1);
  if(printDebug) cout<<"jet55 and trgObjpt && evtSel && qalCut2"<<" = "<<ch[2]->GetEntries(jet55&&trg55&&evtSel&&qalCut2)<<endl;
  //ch[2]->Project("jet55_trg55_evtSel_QA2","hiBin",jet55&&trg55&&evtSel&&qalCut2);
  if(printDebug) cout<<"jet55 and trgObjpt && evtSel && qalCut3"<<" = "<<ch[2]->GetEntries(jet55&&trg55&&evtSel&&qalCut3)<<endl;
  //ch[2]->Project("jet55_trg55_evtSel_QA3","hiBin",jet55&&trg55&&evtSel&&qalCut3);

  if(printDebug) cout<<"jet55 and trgObjpt and evtSel and QA1_2 = "<<ch[2]->GetEntries(jet55&&trg55&&evtSel&&qalCut1&&qalCut2)<<endl;
  //ch[2]->Project("jet55_trg55_evtSel_qalCut1_qalCut2","hiBin",jet55&&trg55&&evtSel&&qalCut1&&qalCut2);
  if(printDebug) cout<<"jet55 and trgObjpt and evtSel and QA1_3 = "<<ch[2]->GetEntries(jet55&&trg55&&evtSel&&qalCut1&&qalCut3)<<endl;
  //ch[2]->Project("jet55_trg55_evtSel_qalCut1_qalCut3","hiBin",jet55&&trg55&&evtSel&&qalCut1&&qalCut3);
  if(printDebug) cout<<"jet55 and trgObjpt and evtSel and QA2_3 = "<<ch[2]->GetEntries(jet55&&trg55&&evtSel&&qalCut2&&qalCut3)<<endl;
  //ch[2]->Project("jet55_trg55_evtSel_qalCut1_qa3Cut2","hiBin",jet55&&trg55&&evtSel&&qalCut3&&qalCut2);


  if(printDebug) cout<<"with jet65"<<" = "<<ch[2]->GetEntries(jet65)<<endl;
  //ch[2]->Project("jet65","hiBin",jet65);
  if(printDebug) cout<<"with evtSel and Jet65 added = "<<ch[2]->GetEntries(jet65&&evtSel)<<endl;
  //ch[2]->Project("jet65_evtSel","hiBin",jet65&&evtSel);
  if(printDebug) cout<<"with Jet65_only and evtSel added = "<<ch[2]->GetEntries(jet65only&&evtSel)<<endl;
  //ch[2]->Project("jet65only_evtSel","hiBin",jet65only&&evtSel);

  if(printDebug) cout<<"jet65 && evtSel && qalCut1"<<" = "<<ch[2]->GetEntries(jet65&&evtSel&&qalCut1)<<endl;
  //ch[2]->Project("jet65_evtSel_qalCut1","hiBin",jet65&&evtSel&&qalCut1);
  if(printDebug) cout<<"jet65 && evtSel && qalCut2"<<" = "<<ch[2]->GetEntries(jet65&&evtSel&&qalCut2)<<endl;
  //ch[2]->Project("jet65_evtSel_qalCut2","hiBin",jet65&&evtSel&&qalCut2);
  if(printDebug) cout<<"jet65 && evtSel && qalCut3"<<" = "<<ch[2]->GetEntries(jet65&&evtSel&&qalCut3)<<endl;
  //ch[2]->Project("jet65_evtSel_qalCut3","hiBin",jet65&&evtSel&&qalCut3);

  if(printDebug) cout<<"jet65 and evtSel and QA1_2 = "<<ch[2]->GetEntries(jet65&&evtSel&&qalCut1&&qalCut2)<<endl;
  //ch[2]->Project("jet65_evtSel_qalCut1_qalCut2","hiBin",jet65&&evtSel&&qalCut1&&qalCut2);
  if(printDebug) cout<<"jet65 and evtSel and QA1_3 = "<<ch[2]->GetEntries(jet65&&evtSel&&qalCut1&&qalCut3)<<endl;
  //ch[2]->Project("jet65_evtSel_qalCut1_qalCut3","hiBin",jet65&&evtSel&&qalCut1&&qalCut3);
  if(printDebug) cout<<"jet65 and evtSel and QA2_3 = "<<ch[2]->GetEntries(jet65&&evtSel&&qalCut2&&qalCut3)<<endl;
  //ch[2]->Project("jet65_evtSel_qalCut3_qalCut2","hiBin",jet65&&evtSel&&qalCut3&&qalCut2);

  if(printDebug) cout<<"with jet65 and trgObjpt selection"<<" = "<<ch[2]->GetEntries(jet65&&trg65)<<endl;
  //ch[2]->Project("jet65_trg65","hiBin",jet65&&trg65);
  if(printDebug) cout<<"with evtSel and Jet65 and trgobjpt added = "<<ch[2]->GetEntries(jet65&&trg65&&evtSel)<<endl;
  //ch[2]->Project("jet65_trg65_evtSel","hiBin",jet65&&trg65&&evtSel);
  if(printDebug) cout<<"with Jet65_only and trgObjpt and evtSel added = "<<ch[2]->GetEntries(jet65only&&trg65&&evtSel)<<endl;
  //ch[2]->Project("jet65only_trg65_evtSel","hiBin",jet65only&&trg65&&evtSel);

  if(printDebug) cout<<"jet65 and trgObjpt && evtSel && qalCut1"<<" = "<<ch[2]->GetEntries(jet65&&trg65&&evtSel&&qalCut1)<<endl;
  //ch[2]->Project("jet65_trg65_evtSel_qalCut1","hiBin",jet65&&trg65&&evtSel&&qalCut1);
  if(printDebug) cout<<"jet65 and trgObjpt && evtSel && qalCut2"<<" = "<<ch[2]->GetEntries(jet65&&trg65&&evtSel&&qalCut2)<<endl;
  //ch[2]->Project("jet65_trg65_evtSel_qalCut2","hiBin",jet65&&trg65&&evtSel&&qalCut2);
  if(printDebug) cout<<"jet65 and trgObjpt && evtSel && qalCut3"<<" = "<<ch[2]->GetEntries(jet65&&trg65&&evtSel&&qalCut3)<<endl;
  //ch[2]->Project("jet65_trg65_evtSel_qalCut3","hiBin",jet65&&trg65&&evtSel&&qalCut3);

  if(printDebug) cout<<"jet65 and trgObjpt and evtSel and QA1_2 = "<<ch[2]->GetEntries(jet65&&trg65&&evtSel&&qalCut1&&qalCut2)<<endl;
  //ch[2]->Project("jet65_trg65_evtSel_qalCut1_qalCut2","hiBin",jet65&&trg65&&evtSel&&qalCut1&&qalCut2);
  if(printDebug) cout<<"jet65 and trgObjpt and evtSel and QA1_3 = "<<ch[2]->GetEntries(jet65&&trg65&&evtSel&&qalCut1&&qalCut3)<<endl;
  //ch[2]->Project("jet65_trg65_evtSel_qalCut1_qalCut3","hiBin",jet65&&trg65&&evtSel&&qalCut1&&qalCut3);
  if(printDebug) cout<<"jet65 and trgObjpt and evtSel and QA2_3 = "<<ch[2]->GetEntries(jet65&&trg65&&evtSel&&qalCut2&&qalCut3)<<endl;
  //ch[2]->Project("jet65_trg65_evtSel_qalCut3_qalCut2","hiBin",jet65&&trg65&&evtSel&&qalCut3&&qalCut2);
  */  

  /*
  if(printDebug) cout<<"with jet80"<<" = "<<Jet80->GetEntries(jet80)<<endl;
  if(printDebug) cout<<"with evtSel and Jet80 added = "<<Jet80->GetEntries(jet80&&evtSel)<<endl;

  if(printDebug) cout<<"jet80 && evtSel && qalCut1"<<" = "<<Jet80->GetEntries(jet80&&evtSel&&qalCut1)<<endl;
  if(printDebug) cout<<"jet80 && evtSel && qalCut2"<<" = "<<Jet80->GetEntries(jet80&&evtSel&&qalCut2)<<endl;
  if(printDebug) cout<<"jet80 && evtSel && qalCut3"<<" = "<<Jet80->GetEntries(jet80&&evtSel&&qalCut3)<<endl;

  if(printDebug) cout<<"jet80 and evtSel and QA1_2 = "<<Jet80->GetEntries(jet80&&evtSel&&qalCut1&&qalCut2)<<endl;
  if(printDebug) cout<<"jet80 and evtSel and QA1_3 = "<<Jet80->GetEntries(jet80&&evtSel&&qalCut1&&qalCut3)<<endl;
  if(printDebug) cout<<"jet80 and evtSel and QA2_3 = "<<Jet80->GetEntries(jet80&&evtSel&&qalCut2&&qalCut3)<<endl;
  if(printDebug) cout<<"with jet80 and trgObjpt selection"<<" = "<<Jet80->GetEntries(jet80&&trg80)<<endl;
  if(printDebug) cout<<"with evtSel and Jet680 and trgobjpt added = "<<Jet80->GetEntries(jet80&&trg80&&evtSel)<<endl;
  //if(printDebug) cout<<"with Jet65_only and trgObjpt and evtSel added = "<<ch[2]->GetEntries(jet65only&&trg65&&evtSel)<<endl;

  if(printDebug) cout<<"jet80 and trgObjpt && evtSel && qalCut1"<<" = "<<Jet80->GetEntries(jet80&&trg80&&evtSel&&qalCut1)<<endl;
  if(printDebug) cout<<"jet80 and trgObjpt && evtSel && qalCut2"<<" = "<<Jet80->GetEntries(jet80&&trg80&&evtSel&&qalCut2)<<endl;
  if(printDebug) cout<<"jet80 and trgObjpt && evtSel && qalCut3"<<" = "<<Jet80->GetEntries(jet80&&trg80&&evtSel&&qalCut3)<<endl;

  if(printDebug) cout<<"jet80 and trgObjpt and evtSel and QA1_2 = "<<Jet80->GetEntries(jet80&&trg80&&evtSel&&qalCut1&&qalCut2)<<endl;
  if(printDebug) cout<<"jet80 and trgObjpt and evtSel and QA1_3 = "<<Jet80->GetEntries(jet80&&trg80&&evtSel&&qalCut1&&qalCut3)<<endl;
  if(printDebug) cout<<"jet80 and trgObjpt and evtSel and QA2_3 = "<<Jet80->GetEntries(jet80&&trg80&&evtSel&&qalCut2&&qalCut3)<<endl;
  */



  if(printDebug) cout<<"jet55 only and trig 55 and eventSel and largejetpt"<<" = "<<ch[2]->GetEntries(evtSel&&jet55only&&trg55&&largejetpt)<<endl;

  

  //ch[2]->Print();
  
  ch[2]->Project("hJet55_trg_QA1_3","jtpt",jet55&&trg55&&evtSel&&qalCut1&&qalCut3);
  hJet55_trg_QA1_3->Print("base");
  ch[2]->Project("hJet65_trg_QA1_3","jtpt",jet65&&trg65&&evtSel&&qalCut1&&qalCut3);
  hJet65_trg_QA1_3->Print("base");
  ch[2]->Project("hJet55_QA1_3","jtpt",jet55&&evtSel&&qalCut1&&qalCut3);
  hJet55_QA1_3->Print("base");
  ch[2]->Project("hJet65_QA1_3","jtpt",jet65&&evtSel&&qalCut1&&qalCut3);
  hJet65_QA1_3->Print("base");

  ch[2]->Project("hJet55","jtpt",jet55&&evtSel);
  hJet55->Print("base");
  ch[2]->Project("hJet55_QA1","jtpt",evtSel&&jet55&&qalCut1);
  hJet55_QA1->Print("base");
  ch[2]->Project("hJet55_QA2_a","jtpt",evtSel&&jet55&&qalCut2_a);
  hJet55_QA2_a->Print("base");
  ch[2]->Project("hJet55_QA2_b","jtpt",evtSel&&jet55&&qalCut2_b);
  hJet55_QA2_b->Print("base");
  ch[2]->Project("hJet55_QA1_2b","jtpt",evtSel&&jet55&&qalCut1&&qalCut2_b);
  hJet55_QA1_2b->Print("base");
  ch[2]->Project("hJet55_QA3","jtpt",evtSel&&jet55&&qalCut3);
  hJet55_QA3->Print("base");
  ch[2]->Project("hJet55_QA4","jtpt",evtSel&&jet55&&qalCut4);
  hJet55_QA4->Print("base");
  ch[2]->Project("hJet55Fake","jtpt",evtSel&&jet55only&&largejetpt);
  hJet55Fake->Print("base");
  ch[2]->Project("hJet55_only","jtpt",jet55only&&evtSel);
  hJet55_only->Print("base");

  ch[2]->Project("hJet55_3D","jteta:jtphi:jtpt",evtSel&&jet55only&&largejetpt);
  hJet55_3D->Print("base");

  ch[2]->Project("hJet55_trg","jtpt",evtSel&&jet55&&trg55);
  hJet55_trg->Print("base");
  ch[2]->Project("hJet55_trg_QA1","jtpt",evtSel&&jet55&&trg55&&qalCut1);
  hJet55_trg_QA1->Print("base");
  ch[2]->Project("hJet55_trg_QA2_a","jtpt",evtSel&&jet55&&trg55&&qalCut2_a);
  hJet55_trg_QA2_a->Print("base");
  ch[2]->Project("hJet55_trg_QA2_b","jtpt",evtSel&&jet55&&trg55&&qalCut2_b);
  hJet55_trg_QA2_b->Print("base");
  ch[2]->Project("hJet55_trg_QA1_2b","jtpt",evtSel&&jet55&&trg55&&qalCut1&&qalCut2_b);
  hJet55_trg_QA1_2b->Print("base");
  ch[2]->Project("hJet55_trg_QA3","jtpt",evtSel&&jet55&&trg55&&qalCut3);
  hJet55_trg_QA3->Print("base");

  ch[2]->Project("hJet65","jtpt",jet65&&evtSel);
  hJet65->Print("base");
  ch[2]->Project("hJet65_QA1","jtpt",evtSel&&jet65&&qalCut1);
  hJet65_QA1->Print("base");
  ch[2]->Project("hJet65_QA2_a","jtpt",evtSel&&jet65&&qalCut2_a);
  hJet65_QA2_a->Print("base");
  ch[2]->Project("hJet65_QA2_b","jtpt",evtSel&&jet65&&qalCut2_b);
  hJet65_QA2_b->Print("base");
  ch[2]->Project("hJet65_QA1_2b","jtpt",evtSel&&jet65&&qalCut1&&qalCut2_b);
  hJet65_QA1_2b->Print("base");
  ch[2]->Project("hJet65_QA3","jtpt",evtSel&&jet65&&qalCut3);
  hJet65_QA3->Print("base");
  ch[2]->Project("hJet65_QA4","jtpt",evtSel&&jet65&&qalCut4);
  hJet65_QA4->Print("base");

  ch[2]->Project("hJet65_only","jtpt",evtSel&&jet65only);
  hJet65_only->Print("base");
  ch[2]->Project("hJet65_trg","jtpt",evtSel&&jet65&&trg65);
  hJet65_trg->Print("base");
  ch[2]->Project("hJet65_trg_QA1","jtpt",evtSel&&jet65&&trg65&&qalCut1);
  hJet65_trg_QA1->Print("base");
  ch[2]->Project("hJet65_trg_QA2_a","jtpt",evtSel&&jet65&&trg65&&qalCut2_a);
  hJet65_trg_QA2_a->Print("base");
  ch[2]->Project("hJet65_trg_QA2_b","jtpt",evtSel&&jet65&&trg65&&qalCut2_b);
  hJet65_trg_QA2_b->Print("base");
  ch[2]->Project("hJet65_trg_QA3","jtpt",evtSel&&jet65&&trg65&&qalCut3);
  hJet65_trg_QA3->Print("base");
  ch[2]->Project("hJet65_trg_QA4","jtpt",evtSel&&jet65&&trg65&&qalCut4);
  hJet65_trg_QA4->Print("base");
  ch[2]->Project("hJet65_trg_QA1_2b","jtpt",evtSel&&jet65&&trg65&&qalCut1&&qalCut2_b);
  hJet65_trg_QA1_2b->Print("base");
  

  hJet55 = (TH1F*)hJet55->Rebin(nbins_pt,"hJet55",boundaries_pt);
  divideBinWidth(hJet55);
  hJet55_QA1 = (TH1F*)hJet55_QA1->Rebin(nbins_pt,"hJet55_QA1",boundaries_pt);
  divideBinWidth(hJet55_QA1);
  hJet55_QA2_a = (TH1F*)hJet55_QA2_a->Rebin(nbins_pt,"hJet55_QA2_a",boundaries_pt);
  divideBinWidth(hJet55_QA2_a);
  hJet55_QA2_b = (TH1F*)hJet55_QA2_b->Rebin(nbins_pt,"hJet55_QA2_b",boundaries_pt);
  divideBinWidth(hJet55_QA2_b);
  hJet55_QA1_2b = (TH1F*)hJet55_QA1_2b->Rebin(nbins_pt,"hJet55_QA1_2b",boundaries_pt);
  divideBinWidth(hJet55_QA1_2b);
  hJet55_QA3 = (TH1F*)hJet55_QA3->Rebin(nbins_pt,"hJet55_QA3",boundaries_pt);
  divideBinWidth(hJet55_QA3);
  hJet55_QA4 = (TH1F*)hJet55_QA4->Rebin(nbins_pt,"hJet55_QA4",boundaries_pt);
  divideBinWidth(hJet55_QA4);
  hJet55_only = (TH1F*)hJet55_only->Rebin(nbins_pt,"hJet55_only",boundaries_pt);
  divideBinWidth(hJet55_only);
  hJet55Fake = (TH1F*)hJet55Fake->Rebin(nbins_pt,"hJet55Fake",boundaries_pt);
  divideBinWidth(hJet55Fake);
  hJet55_trg = (TH1F*)hJet55_trg->Rebin(nbins_pt,"hJet55_trg",boundaries_pt);
  divideBinWidth(hJet55_trg);
  hJet55_trg_QA1 = (TH1F*)hJet55_trg_QA1->Rebin(nbins_pt,"hJet55_trg_QA1",boundaries_pt);
  divideBinWidth(hJet55_trg_QA1);
  hJet55_trg_QA2_a = (TH1F*)hJet55_trg_QA2_a->Rebin(nbins_pt,"hJet55_trg_QA2_a",boundaries_pt);
  divideBinWidth(hJet55_trg_QA2_a);
  hJet55_trg_QA2_b = (TH1F*)hJet55_trg_QA2_b->Rebin(nbins_pt,"hJet55_trg_QA2_b",boundaries_pt);
  divideBinWidth(hJet55_trg_QA2_b);
  hJet55_trg_QA1_2b = (TH1F*)hJet55_trg_QA1_2b->Rebin(nbins_pt,"hJet55_trg_QA1_2b",boundaries_pt);
  divideBinWidth(hJet55_trg_QA1_2b);
  hJet55_trg_QA3 = (TH1F*)hJet55_trg_QA3->Rebin(nbins_pt,"hJet55_trg_QA3",boundaries_pt);
  divideBinWidth(hJet55_trg_QA3);
  hJet55_trg_QA4 = (TH1F*)hJet55_trg_QA4->Rebin(nbins_pt,"hJet55_trg_QA4",boundaries_pt);
  divideBinWidth(hJet55_trg_QA4);

  hJet65 = (TH1F*)hJet65->Rebin(nbins_pt,"hJet65",boundaries_pt);
  divideBinWidth(hJet65);
  hJet65_QA1 = (TH1F*)hJet65_QA1->Rebin(nbins_pt,"hJet65_QA1",boundaries_pt);
  divideBinWidth(hJet65_QA1);
  hJet65_QA2_a = (TH1F*)hJet65_QA2_a->Rebin(nbins_pt,"hJet65_QA2_a",boundaries_pt);
  divideBinWidth(hJet65_QA2_a);
  hJet65_QA2_b = (TH1F*)hJet65_QA2_b->Rebin(nbins_pt,"hJet65_QA2_b",boundaries_pt);
  divideBinWidth(hJet65_QA2_b);
  hJet65_QA1_2b = (TH1F*)hJet65_QA1_2b->Rebin(nbins_pt,"hJet65_QA1_2b",boundaries_pt);
  divideBinWidth(hJet65_QA1_2b);
  hJet65_QA3 = (TH1F*)hJet65_QA3->Rebin(nbins_pt,"hJet65_QA3",boundaries_pt);
  divideBinWidth(hJet65_QA3);
  hJet65_QA4 = (TH1F*)hJet65_QA4->Rebin(nbins_pt,"hJet65_QA4",boundaries_pt);
  divideBinWidth(hJet65_QA4);
  hJet65_only = (TH1F*)hJet65_only->Rebin(nbins_pt,"hJet65_only",boundaries_pt);
  divideBinWidth(hJet65_only);
  //hJet65_fake = (TH1F*)hJet65_fake->Rebin(nbins_pt,"hJet65_fake",boundaries_pt);
  //divideBinWidth(hJet65_fake);
  hJet65_trg = (TH1F*)hJet65_trg->Rebin(nbins_pt,"hJet65_trg",boundaries_pt);
  divideBinWidth(hJet65_trg);
  hJet65_trg_QA1 = (TH1F*)hJet65_trg_QA1->Rebin(nbins_pt,"hJet65_trg_QA1",boundaries_pt);
  divideBinWidth(hJet65_trg_QA1);
  hJet65_trg_QA2_a = (TH1F*)hJet65_trg_QA2_a->Rebin(nbins_pt,"hJet65_trg_QA2_a",boundaries_pt);
  divideBinWidth(hJet65_trg_QA2_a);
  hJet65_trg_QA2_b = (TH1F*)hJet65_trg_QA2_b->Rebin(nbins_pt,"hJet65_trg_QA2_b",boundaries_pt);
  divideBinWidth(hJet65_trg_QA2_b);
  hJet65_trg_QA1_2b = (TH1F*)hJet65_trg_QA1_2b->Rebin(nbins_pt,"hJet65_trg_QA1_2b",boundaries_pt);
  divideBinWidth(hJet65_trg_QA1_2b);
  hJet65_trg_QA3 = (TH1F*)hJet65_trg_QA3->Rebin(nbins_pt,"hJet65_trg_QA3",boundaries_pt);
  divideBinWidth(hJet65_trg_QA3);
  hJet65_trg_QA4 = (TH1F*)hJet65_trg_QA4->Rebin(nbins_pt,"hJet65_trg_QA4",boundaries_pt);
  divideBinWidth(hJet65_trg_QA4);

  hJet55_trg_QA1_3 = (TH1F*)hJet55_trg_QA1_3->Rebin(nbins_pt,"hJet55_trg_QA1_3",boundaries_pt);
  divideBinWidth(hJet55_trg_QA1_3);
  hJet65_trg_QA1_3 = (TH1F*)hJet65_trg_QA1_3->Rebin(nbins_pt,"hJet65_trg_QA1_3",boundaries_pt);
  divideBinWidth(hJet65_trg_QA1_3);
  hJet55_QA1_3 = (TH1F*)hJet55_QA1_3->Rebin(nbins_pt,"hJet55_QA1_3",boundaries_pt);
  divideBinWidth(hJet55_QA1_3);
  hJet65_QA1_3 = (TH1F*)hJet65_QA1_3->Rebin(nbins_pt,"hJet65_QA1_3",boundaries_pt);
  divideBinWidth(hJet65_QA1_3);
  

  fout.Write();
  fout.Close();
  
  timer.Stop();
  cout<<"Real time(min) = "<<(Float_t)timer.RealTime()/60<<endl;
  cout<<"CPU time(min)  = "<<(Float_t)timer.CpuTime()/60<<endl;
  cout<<"All done"<<endl;

}
Exemple #7
0
void RAA_HFVsValidation_MC(char *algo = "Vs", char *jet_type = "PF"){


  TStopwatch timer;
  timer.Start();
  
  TH1::SetDefaultSumw2();
  TH2::SetDefaultSumw2();

  gStyle->SetOptStat(0);

  cout<<"Running for Algorithm "<<algo<<" "<<jet_type<<endl;
 
  bool printDebug = true;
  TDatime date;

  const int nbins_pthat = 9;
  Double_t boundaries_pthat[nbins_pthat+1];
  char *fileName_pthat[nbins_pthat+1];
  Double_t xsection[nbins_pthat+1];
  Double_t entries[nbins_pthat]; 
  //there are two ways in which we can select the no of events we use to scale - it has to be between the pthat range. 
  //first file name - partial 50K statistics, second one is full statistics sample. 
  //similarly the entries number is for the small statistics. 
  
  // refer this twiki for the data and MC files: http://twiki.cern.ch/twiki/bin/viewauth/CMS/HiForestPA2014#PYTHIA_HYDJET_embedded_sample

  boundaries_pthat[0]=15;
  fileName_pthat[0] = "/mnt/hadoop/cms/store/user/dgulhan/PYTHIA_HYDJET_Track9_Jet30_Pyquen_DiJet_TuneZ2_Unquenched_Hydjet1p8_2760GeV_merged/HiForest_PYTHIA_HYDJET_pthat15_Track9_Jet30_matchEqR_merged_forest_0.root";
  //fileName_pthat[0] = "/export/d00/scratch/dav2105/badjets/bad15.root";
  xsection[0]= 2.034e-01;
  //entries[0] = ;//total - 48588
  
  boundaries_pthat[1]=30;
  fileName_pthat[1] = "/mnt/hadoop/cms/store/user/dgulhan/PYTHIA_HYDJET_Track9_Jet30_Pyquen_DiJet_TuneZ2_Unquenched_Hydjet1p8_2760GeV_merged/HiForest_PYTHIA_HYDJET_pthat30_Track9_Jet30_matchEqR_merged_forest_0.root";
  //fileName_pthat[1] = "/export/d00/scratch/dav2105/badjets/bad30.root";
  xsection[1]= 1.075e-02;
  // entries[1] = ;//total - 48428
  
  boundaries_pthat[2]=50;
  fileName_pthat[2] = "/mnt/hadoop/cms/store/user/dgulhan/PYTHIA_HYDJET_Track9_Jet30_Pyquen_DiJet_TuneZ2_Unquenched_Hydjet1p8_2760GeV_merged/HiForest_PYTHIA_HYDJET_pthat50_Track9_Jet30_matchEqR_merged_forest_0.root";
  //fileName_pthat[2] = "/export/d00/scratch/dav2105/badjets/bad50.root";
  xsection[2]= 1.025e-03;
  // entries[2] = ;//total - 50000
  
  boundaries_pthat[3]=80;
  fileName_pthat[3] = "/mnt/hadoop/cms/store/user/dgulhan/PYTHIA_HYDJET_Track9_Jet30_Pyquen_DiJet_TuneZ2_Unquenched_Hydjet1p8_2760GeV_merged/HiForest_PYTHIA_HYDJET_pthat80_Track9_Jet30_matchEqR_merged_forest_0.root";
  //fileName_pthat[3] = "/export/d00/scratch/dav2105/badjets/bad80.root";
  xsection[3]= 9.865e-05;
  // entries[3] = ;//total - 49500
  
  boundaries_pthat[4]=120;
  fileName_pthat[4] = "/mnt/hadoop/cms/store/user/dgulhan/PYTHIA_HYDJET_Track9_Jet30_Pyquen_DiJet_TuneZ2_Unquenched_Hydjet1p8_2760GeV_merged/HiForest_PYTHIA_HYDJET_pthat120_Track9_Jet30_matchEqR_merged_forest_0.root";  
  //fileName_pthat[4] = "/export/d00/scratch/dav2105/badjets/bad120.root";
  xsection[4]= 1.129e-05;
  // entries[4] = ;//total - 49500

  boundaries_pthat[5]=170;
  fileName_pthat[5] = "/mnt/hadoop/cms/store/user/dgulhan/PYTHIA_HYDJET_Track9_Jet30_Pyquen_DiJet_TuneZ2_Unquenched_Hydjet1p8_2760GeV_merged/HiForest_PYTHIA_HYDJET_pthat170_Track9_Jet30_matchEqR_merged_forest_0.root";
  //fileName_pthat[5] = "/export/d00/scratch/dav2105/badjets/bad120.root";
  xsection[5]= 1.465e-06;
  // entries[5] = ;//total - 49444

  boundaries_pthat[6]=220;
  fileName_pthat[6] = "/mnt/hadoop/cms/store/user/dgulhan/PYTHIA_HYDJET_Track9_Jet30_Pyquen_DiJet_TuneZ2_Unquenched_Hydjet1p8_2760GeV_merged/HiForest_PYTHIA_HYDJET_pthat220_Track9_Jet30_matchEqR_merged_forest_0.root";
  //fileName_pthat[6] = "/export/d00/scratch/dav2105/badjets/bad220.root";
  xsection[6]= 2.837e-07;
  // entries[6] = ;//total - 49460

  boundaries_pthat[7]=280;
  fileName_pthat[7] = "/mnt/hadoop/cms/store/user/dgulhan/PYTHIA_HYDJET_Track9_Jet30_Pyquen_DiJet_TuneZ2_Unquenched_Hydjet1p8_2760GeV_merged/HiForest_PYTHIA_HYDJET_pthat280_Track9_Jet30_matchEqR_merged_forest_0.root";
  //fileName_pthat[7] = "/export/d00/scratch/dav2105/badjets/bad280.root";
  xsection[7]= 5.323e-08;
  // entries[7] = ;//total - 49541

  boundaries_pthat[8]=370;
  fileName_pthat[8] = "/mnt/hadoop/cms/store/user/dgulhan/PYTHIA_HYDJET_Track9_Jet30_Pyquen_DiJet_TuneZ2_Unquenched_Hydjet1p8_2760GeV_merged/HiForest_PYTHIA_HYDJET_pthat370_Track9_Jet30_matchEqR_merged_forest_0.root";
  //fileName_pthat[8] = "/export/d00/scratch/dav2105/badjets/bad370.root";
  xsection[8]= 5.934e-09;
  // entries[8] = ;//total - 19031

  boundaries_pthat[9] = 2000;
  xsection[9] = 0.0;

  // Vertex & centrality reweighting for PbPb
  TF1 *fVz;
  fVz = new TF1("fVz","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x");
  fVz->SetParameters(9.86748e-01, -8.91367e-03, 5.35416e-04, 2.67665e-06, -2.01867e-06);

  //get the centrality weight from the root file created in the plotting macro. 
  TFile *fcentin = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_20/src/Output/PbPb_DataMC_cent_ratio_20141117.root");
  TH1F *hCentWeight = (TH1F*)fcentin->Get("hCentRatio");


  TH2F *hSumpTvsHF[15];
  TH2F *hSumpTvsHF_cent[nbins_cent+1];
  TH2F *hSumpTvshiBin[15];
  TH2F *hSumpTvshiBin_cent[nbins_cent+1];
  TH2F *hNJetsvsSumpT[nbins_cent+1];
  TH2F *hNJetsvsSumpT_noHF[nbins_cent+1];
  TH2F *hNJetsvsSumpT_HF[nbins_cent+1];
  TH1F *hSumpT[nbins_cent+1];
  TH1F *hPsi[5][15][nbins_cent+1];
  //TH2F *hPsi_2d[5][15][nbins_cent];

  TH2F *hPsivsHF[5][15];
  TH2F *hPsivsHF_cent[5][nbins_cent+1];
  TH2F *hvnvsHF[5][15];
  TH2F *hvnvscent[5][nbins_cent+1];

  // UseFull histograms: Event Plane from HF for the official versus HF/Vs algorithm calculation of the Event Plane.
  // first [3] array elements - Psi_2, Psi_3, Psi_4  only in the HF for tonight. 
  // [3] - total, p - positive and n - negative in eta; based on what we have from the https://github.com/CmsHI/cmssw/blob/forest_CMSSW_5_3_20/RecoHI/HiEvtPlaneAlgos/interface/HiEvtPlaneList.h#L31 
  TH1F *hEP_HF_Official[3][3][nbins_cent+1];
  TH1F *hEP_HF_Vs[3][3][nbins_cent+1];
  TH2F *hEP_HF[3][3][nbins_cent+1];
  TH1F *hAngle_2_HF_Vs[nbins_cent+1];
  TH1F *hAngle_3_HF_Vs[nbins_cent+1];
  TH1F *hAngle_4_HF_Vs[nbins_cent+1];
  TH1F *hAngle_2_HF_Official[nbins_cent+1];
  TH1F *hAngle_3_HF_Official[nbins_cent+1];
  TH1F *hAngle_4_HF_Official[nbins_cent+1];
  TH1F *hMagnitude_2_HF_Vs[nbins_cent+1];
  TH1F *hMagnitude_3_HF_Vs[nbins_cent+1];
  TH1F *hMagnitude_4_HF_Vs[nbins_cent+1];
  TH2F *hSub_vs_SumpT[nbins_cent+1];
  TH2F *hVsAngle_EP[3][nbins_cent+1];

  for(int i = 0;i<nbins_cent+1;i++){
    
    for(int z = 0;z<3;z++){
      for(int x = 0;x<3;x++){
	hEP_HF_Official[z][x][i] = new TH1F(Form("hEP_HF_Official_Psi%d_%d_cent%d",z,x,i),"",630,-3.15,3.15);
	hEP_HF_Vs[z][x][i] = new TH1F(Form("hEP_HF_Vs_Psi%d_%d_cent%d",z,x,i),"",630,-3.15,3.15);
	hEP_HF[z][x][i] = new TH2F(Form("hEP_HF_Psi%d_%d_cent%d",z,x,i),"",630,-3.15,3.15,630,-3.15,3.15);
      }
    }

    hSumpTvsHF_cent[i] = new TH2F(Form("hSumpT_vsHF_cent%d",i),"",5000,0,100000,5000,0,100000);
    hSumpTvshiBin_cent[i] = new TH2F(Form("hSumpT_vshiBin_cent%d",i),"",5000,0,100000,200,0,200);
    hNJetsvsSumpT[i] = new TH2F(Form("hNJetsvsSumpT_cent%d",i),"",50,0,50,5000,0,100000);
    hNJetsvsSumpT_noHF[i] = new TH2F(Form("hNJetsvsSumpT_noHF_cent%d",i),"",50,0,50,5000,0,100000);
    hNJetsvsSumpT_HF[i] = new TH2F(Form("hNJetsvsSumpT_HF_cent%d",i),"",50,0,50,5000,0,100000);
    hAngle_2_HF_Vs[i] = new TH1F(Form("hAngle_2_HF_Vs_cent%d",i),"",30,-3.15,+3.15);
    hAngle_3_HF_Vs[i] = new TH1F(Form("hAngle_3_HF_Vs_cent%d",i),"",30,-3.15,+3.15);
    hAngle_4_HF_Vs[i] = new TH1F(Form("hAngle_4_HF_Vs_cent%d",i),"",30,-3.15,+3.15);
    hAngle_2_HF_Official[i] = new TH1F(Form("hAngle_2_HF_Official_cent%d",i),"",60,-3.15,+3.15);
    hAngle_3_HF_Official[i] = new TH1F(Form("hAngle_3_HF_Official_cent%d",i),"",60,-3.15,+3.15);
    hAngle_4_HF_Official[i] = new TH1F(Form("hAngle_4_HF_Official_cent%d",i),"",60,-3.15,+3.15);
    hSumpT[i] = new TH1F(Form("hSumpT_cent%d",i),"",5000,0,100000);
    hMagnitude_2_HF_Vs[i] = new TH1F(Form("hMagnitude_2_HF_Vs_cent%d",i),"",1000,0,1);
    hMagnitude_3_HF_Vs[i] = new TH1F(Form("hMagnitude_3_HF_Vs_cent%d",i),"",1000,0,1);
    hMagnitude_4_HF_Vs[i] = new TH1F(Form("hMagnitude_4_HF_Vs_cent%d",i),"",1000,0,1);
    hSub_vs_SumpT[i] = new TH2F(Form("hSub_vs_SumpT_cent%d",i),"",1200,0,12000,1200,0,12000);
    hVsAngle_EP[0][i] = new TH2F(Form("hVsAngle_EP_2_cent%d",i),"",60,-3.15,+3.15,60,-3.15,+3.15);
    hVsAngle_EP[1][i] = new TH2F(Form("hVsAngle_EP_3_cent%d",i),"",60,-3.15,+3.15,60,-3.15,+3.15);
    hVsAngle_EP[2][i] = new TH2F(Form("hVsAngle_EP_4_cent%d",i),"",60,-3.15,+3.15,60,-3.15,+3.15);

    /*
    for(int b = 0;b<5;b++){

      hPsivsHF_cent[b][i] = new TH2F(Form("hPsi%d_cent%d",b,i),"",630,-3.15,+3.15,5000,0,100000);
      hvnvsHF[b][i] = new TH2F(Form("hvn%d_HF_cent%d",b,i),"",100,0,1,5000,0,100000);
      //hvnvscent[b][i] = new TH2F
      for(int a = 0;a<15;a++){

	//hPsi[b][a][i] = new TH1F(Form("hPsi_n%d_eta%d_cent%d",b,a,i),"",630,-3.15,3.15);
	
      }
      
    }
    */
  }
  
  /*  
  // declare the histograms in loops:
  for(int a = 0;a<15;a++){
    
    hSumpTvsHF[a] = new TH2F(Form("hSumpT_eta%d_vsHF",a),"",5000,0,100000,5000,0,100000);
    hSumpTvshiBin[a] = new TH2F(Form("hSumpT_eta%d_vshiBin",a),"",5000,0,100000,200,0,200);
    
    for(int b = 0;b<5;b++){
      
      hPsivsHF[b][a] = new TH2F(Form("hPsi%d_etabin%d_HF",b,a),"",630,-3.15,+3.15,5000,0,100000);
      hvnvsHF[b][a] = new TH2F(Form("hvn%d_etabin%d_HF",b,a),"",100,0,1,5000,0,100000);
      
    }// no of flow components
    
  }// eta bin
  */
  TH1F *hPtHat[no_radius];
  TH1F *hPtHatRaw[no_radius];
  // Setup jet data branches - this will be 2D with [radius][pthat-file], but the histogram here is just 1D with [radius]
  JetData *data[no_radius][nbins_pthat]; 
  for(int k = 0;k<no_radius;k++){
    hPtHatRaw[k] = new TH1F(Form("hPtHatRaw_R%d",list_radius[k]),"",nbins_pthat,boundaries_pthat);
    hPtHat[k] = new TH1F(Form("hPtHat_R%d",list_radius[k]),"",nbins_pthat,boundaries_pthat);
    if(printDebug)cout<<"Radius = "<<list_radius[k]<<endl;
    if(printDebug)cout<<"reading all the pbpb mc files"<<endl;
    for (int h=0;h<nbins_pthat;h++) {
      //cout<<Form("ak%s%dJetAnalyzer/t",algo,list_radius[k])<<endl;
      data[k][h] = new JetData(fileName_pthat[h],Form("ak%s%d%sJetAnalyzer/t",algo,list_radius[k],jet_type),Form("ak%s%d%sJetAnalyzer/t",algo,list_radius[k],jet_type),0,1);
      //cout<<"A"<<endl;
      TH1F *hPtHatTmp = new TH1F("hPtHatTmp","",nbins_pthat,boundaries_pthat);
      //cout<<"B"<<endl;
      data[k][h]->tJet->Project("hPtHatTmp","pthat");
      //cout<<"C"<<endl;
      hPtHatRaw[k]->Add(hPtHatTmp);
      //cout<<"D"<<endl;
      delete hPtHatTmp;
    }// pthat loop
  }
  
  
  for(int k = 0;k<no_radius;k++){
    if(printDebug)cout<<"Filling MC for radius = "<<list_radius[k]<<endl;
    // fill PbPb MC 
    if(printDebug)cout<<"Filling PbPb MC"<<endl;
    
    for (int h=0;h<nbins_pthat;h++) {
      if (xsection[h]==0) continue;
      if(printDebug)cout <<"Loading pthat"<<boundaries_pthat[h]<<" sample, cross section = "<<xsection[h]<< Form(" pthat>%.0f&&pthat<%.0f",boundaries_pthat[h],boundaries_pthat[h+1])<<endl;
      
      //TCut pthatcut = Form("pthat>%d && pthat<%d",boundaries_pthat[h],boundaries_pthat[h+1]);
      //double fentries_test = data[k][h]->tJet->GetEntries(pthatcut);
      //cout<<"fentries_test = "<<fentries_test<<endl;
      
      //from Pawan's code: /net/hisrv0001/home/pawan/Validation/CMSSW_7_1_1/src/combinePtHatBins/pbpbJEC2014/condor/CondorPbPbCalJec.C
      TEventList *el = new TEventList("el","el");
      //double pthat_event = data[k][h]->pthat;
      //double pthat_lower = boundaries_pthat[h];
      double pthat_upper = boundaries_pthat[h+1];
      stringstream selection; selection<<"pthat<"<<pthat_upper;
      
      data[k][h]->tJet->Draw(">>el",selection.str().c_str());
      double fentries = el->GetN();
      if(printDebug)cout<<"tree entries: "<<data[k][h]->tJet->GetEntries()<<" elist: "<<fentries<<endl;
      delete el;
      int test_counter = 0; 
      
      for (Long64_t jentry=0; jentry<data[k][h]->tJet->GetEntries();jentry++) {
	//for (Long64_t jentry=0; jentry<10;jentry++) {
	
        //cout<<"hi"<<endl;
        data[k][h]->tEvt->GetEntry(jentry);
        data[k][h]->tJet->GetEntry(jentry);
        data[k][h]->tSkim->GetEntry(jentry);
        	
        int pthatBin = hPtHat[k]->FindBin(data[k][h]->pthat);
	
	double scale = (double)(xsection[pthatBin-1]-xsection[pthatBin])/fentries;
	
	if(!data[k][h]->pcollisionEventSelection) continue;
        int cBin = findBin(data[k][h]->bin);
        //int cBin = nbins_cent-1;
        double weight_cent=1;
        double weight_pt=1;
        double weight_vz=1;
	Float_t cent = cBin;
	
        weight_cent = hCentWeight->GetBinContent(hCentWeight->FindBin(data[k][h]->bin));
	if(fabs(data[k][h]->vz)>15) continue;
	
        weight_vz = fVz->Eval(data[k][h]->vz);
	
        if(scale*weight_cent*weight_vz <=0 ) {
	  cout<<"RED FLAG RED FLAG RED FLAG"<<endl;
	  continue;
	}
	
	int jetCounter = 0;//counts jets which are going to be used in the supernova cut rejection. 
	
	for(int j = 0;j<nbins_eta;j++){
	  
	  for(int g = 0;g<data[k][h]->njets;g++){
	    
	    if(data[k][h]->jteta[g] >= boundaries_eta[j][0] && data[k][h]->jteta[g] < boundaries_eta[j][1]){
	      //cout<<"jtpt = "<<data[k][h]->jtpt[g]<<endl;
	      if(data[k][h]->jtpt[g]>=50) jetCounter++;
	      
	    }// eta selection loop
	    
	  }//jet loop
	  
	}//eta bins loop

	//constructing the x-,y- and x+,y+ based on the following equation: 
	// x- = sumpt[0]*vn[2][0]*cos(2*vpsi[2][0]) y- = sumpt[0]*vn[2][0]*sin(2*vpsi[2][0])
	Float_t Vs_2_x_minus = data[k][h]->sumpT[0]*data[k][h]->v_n[2][0]*TMath::Cos(2*data[k][h]->psi_n[2][0]);
	Float_t Vs_2_x_plus = data[k][h]->sumpT[14]*data[k][h]->v_n[2][14]*TMath::Cos(2*data[k][h]->psi_n[2][14]);
	Float_t Vs_2_y_minus = data[k][h]->sumpT[0]*data[k][h]->v_n[2][0]*TMath::Sin(2*data[k][h]->psi_n[2][0]);
	Float_t Vs_2_y_plus = data[k][h]->sumpT[14]*data[k][h]->v_n[2][14]*TMath::Sin(2*data[k][h]->psi_n[2][14]);
	Float_t Vs_2_x = Vs_2_x_minus + Vs_2_x_plus;
	Float_t Vs_2_y = Vs_2_y_minus + Vs_2_y_plus;
	Float_t Vs_2_angle = TMath::ATan2(Vs_2_y,Vs_2_x);
	hAngle_2_HF_Vs[cBin]->Fill(Vs_2_angle);
	hAngle_2_HF_Vs[nbins_cent]->Fill(Vs_2_angle);
	//cout<<"Vs_2_angle = "<<Vs_2_angle<<endl;

	Float_t Vs_3_x_minus = data[k][h]->sumpT[0]*data[k][h]->v_n[3][0]*TMath::Cos(3*data[k][h]->psi_n[3][0]);
	Float_t Vs_3_x_plus = data[k][h]->sumpT[14]*data[k][h]->v_n[3][14]*TMath::Cos(3*data[k][h]->psi_n[3][14]);
	Float_t Vs_3_y_minus = data[k][h]->sumpT[0]*data[k][h]->v_n[3][0]*TMath::Sin(3*data[k][h]->psi_n[3][0]);
	Float_t Vs_3_y_plus = data[k][h]->sumpT[14]*data[k][h]->v_n[3][14]*TMath::Sin(3*data[k][h]->psi_n[3][14]);
	Float_t Vs_3_x = Vs_3_x_minus + Vs_3_x_plus;
	Float_t Vs_3_y = Vs_3_y_minus + Vs_3_y_plus;
	Float_t Vs_3_angle = TMath::ATan2(Vs_3_y,Vs_3_x);
	hAngle_3_HF_Vs[cBin]->Fill(Vs_3_angle);
	hAngle_3_HF_Vs[nbins_cent]->Fill(Vs_3_angle);
	//cout<<"Vs_3_angle = "<<Vs_3_angle<<endl;

	Float_t Vs_4_x_minus = data[k][h]->sumpT[0]*data[k][h]->v_n[4][0]*TMath::Cos(4*data[k][h]->psi_n[4][0]);
	Float_t Vs_4_x_plus = data[k][h]->sumpT[14]*data[k][h]->v_n[4][14]*TMath::Cos(4*data[k][h]->psi_n[4][14]);
	Float_t Vs_4_y_minus = data[k][h]->sumpT[0]*data[k][h]->v_n[4][0]*TMath::Sin(4*data[k][h]->psi_n[4][0]);
	Float_t Vs_4_y_plus = data[k][h]->sumpT[14]*data[k][h]->v_n[4][14]*TMath::Sin(4*data[k][h]->psi_n[4][14]);
	Float_t Vs_4_x = Vs_4_x_minus + Vs_4_x_plus;
	Float_t Vs_4_y = Vs_4_y_minus + Vs_4_y_plus;
	Float_t Vs_4_angle = TMath::ATan2(Vs_4_y,Vs_4_x);
	hAngle_4_HF_Vs[cBin]->Fill(Vs_4_angle);
	hAngle_4_HF_Vs[nbins_cent]->Fill(Vs_4_angle);
      	//cout<<"Vs_4_angle = "<<Vs_4_angle<<endl;

	//lets get the maginitude of the x,y here: 
	Float_t Vs_Mag_2 = TMath::Sqrt(Vs_2_x*Vs_2_x + Vs_2_y*Vs_2_y);
	Float_t Vs_Mag_3 = TMath::Sqrt(Vs_3_x*Vs_3_x + Vs_3_y*Vs_3_y);
	Float_t Vs_Mag_4 = TMath::Sqrt(Vs_4_x*Vs_4_x + Vs_4_y*Vs_4_y);
	// need to calculate the Total per event (pfPt - pfVsPt) versus sumpT[0]+sumpT[14];
	Float_t pfPt_Tot = 0;
	Float_t pfVsPt_Tot = 0;
	for(int i = 0;i<data[k][h]->nPFpart;i++){
	  pfPt_Tot += data[k][h]->pfPt[i];
	  pfVsPt_Tot += data[k][h]->pfVsPt[i];
	}
	Float_t sumpT_HF = data[k][h]->sumpT[0] + data[k][h]->sumpT[14];

	hMagnitude_2_HF_Vs[cBin]->Fill(Vs_Mag_2/sumpT_HF);
	hMagnitude_2_HF_Vs[nbins_cent]->Fill(Vs_Mag_2/sumpT_HF);
	hMagnitude_3_HF_Vs[cBin]->Fill(Vs_Mag_3/sumpT_HF);
	hMagnitude_3_HF_Vs[nbins_cent]->Fill(Vs_Mag_3/sumpT_HF);
	hMagnitude_4_HF_Vs[cBin]->Fill(Vs_Mag_4/sumpT_HF);
	hMagnitude_4_HF_Vs[nbins_cent]->Fill(Vs_Mag_4/sumpT_HF);
	//Float_t sub_ratio = (Float_t)(pfPt_Tot-pfVsPt_Tot)/sumpT_HF;
	hSub_vs_SumpT[cBin]->Fill(sumpT_HF,pfPt_Tot-pfVsPt_Tot);
	hSub_vs_SumpT[nbins_cent]->Fill(sumpT_HF,pfPt_Tot-pfVsPt_Tot);

	hVsAngle_EP[0][cBin]->Fill(Vs_2_angle,2*data[k][h]->hiEvtPlanes[21]);
	hVsAngle_EP[1][cBin]->Fill(Vs_3_angle,3*data[k][h]->hiEvtPlanes[24]);
	hVsAngle_EP[2][cBin]->Fill(Vs_4_angle,4*data[k][h]->hiEvtPlanes[27]);

	hVsAngle_EP[0][nbins_cent]->Fill(Vs_2_angle,2*data[k][h]->hiEvtPlanes[21]);
	hVsAngle_EP[1][nbins_cent]->Fill(Vs_3_angle,3*data[k][h]->hiEvtPlanes[24]);
	hVsAngle_EP[2][nbins_cent]->Fill(Vs_4_angle,4*data[k][h]->hiEvtPlanes[27]);

	//getting the event plane information for the Official and Vs calculations. 
	/*
	hEP_HF_Official[0][0][cBin]->Fill(data[k][h]->hiEvtPlanes[21],scale*weight_vz*weight_cent);
	hEP_HF_Official[0][1][cBin]->Fill(data[k][h]->hiEvtPlanes[22],scale*weight_vz*weight_cent);
	hEP_HF_Official[0][2][cBin]->Fill(data[k][h]->hiEvtPlanes[23],scale*weight_vz*weight_cent);

	hEP_HF_Official[1][0][cBin]->Fill(data[k][h]->hiEvtPlanes[24],scale*weight_vz*weight_cent);
	hEP_HF_Official[1][1][cBin]->Fill(data[k][h]->hiEvtPlanes[25],scale*weight_vz*weight_cent);
	hEP_HF_Official[1][2][cBin]->Fill(data[k][h]->hiEvtPlanes[26],scale*weight_vz*weight_cent);

	hEP_HF_Official[2][0][cBin]->Fill(data[k][h]->hiEvtPlanes[27],scale*weight_vz*weight_cent);
	hEP_HF_Official[2][1][cBin]->Fill(data[k][h]->hiEvtPlanes[28],scale*weight_vz*weight_cent);
	hEP_HF_Official[2][2][cBin]->Fill(data[k][h]->hiEvtPlanes[29],scale*weight_vz*weight_cent);

	hEP_HF_Vs[0][0][cBin]->Fill(data[k][h]->psi_n[2][0],scale*weight_vz*weight_cent);
	hEP_HF_Vs[0][0][cBin]->Fill(data[k][h]->psi_n[2][14],scale*weight_vz*weight_cent);
	hEP_HF_Vs[0][1][cBin]->Fill(data[k][h]->psi_n[2][0],scale*weight_vz*weight_cent);
	hEP_HF_Vs[0][2][cBin]->Fill(data[k][h]->psi_n[2][14],scale*weight_vz*weight_cent);

	hEP_HF_Vs[1][0][cBin]->Fill(data[k][h]->psi_n[3][0],scale*weight_vz*weight_cent);
	hEP_HF_Vs[1][0][cBin]->Fill(data[k][h]->psi_n[3][14],scale*weight_vz*weight_cent);
	hEP_HF_Vs[1][1][cBin]->Fill(data[k][h]->psi_n[3][0],scale*weight_vz*weight_cent);
	hEP_HF_Vs[1][2][cBin]->Fill(data[k][h]->psi_n[3][14],scale*weight_vz*weight_cent);

	hEP_HF_Vs[2][0][cBin]->Fill(data[k][h]->psi_n[4][0],scale*weight_vz*weight_cent);
	hEP_HF_Vs[2][0][cBin]->Fill(data[k][h]->psi_n[4][14],scale*weight_vz*weight_cent);
	hEP_HF_Vs[2][1][cBin]->Fill(data[k][h]->psi_n[4][0],scale*weight_vz*weight_cent);
	hEP_HF_Vs[2][2][cBin]->Fill(data[k][h]->psi_n[4][14],scale*weight_vz*weight_cent);
	
	hEP_HF[0][0][cBin]->Fill(data[k][h]->hiEvtPlanes[21],data[k][h]->psi_n[2][0],scale*weight_vz*weight_cent);
	hEP_HF[0][0][cBin]->Fill(data[k][h]->hiEvtPlanes[21],data[k][h]->psi_n[2][14],scale*weight_vz*weight_cent);
	hEP_HF[0][1][cBin]->Fill(data[k][h]->hiEvtPlanes[22],data[k][h]->psi_n[2][0],scale*weight_vz*weight_cent);
	hEP_HF[0][2][cBin]->Fill(data[k][h]->hiEvtPlanes[23],data[k][h]->psi_n[2][14],scale*weight_vz*weight_cent);

	hEP_HF[1][0][cBin]->Fill(data[k][h]->hiEvtPlanes[24],data[k][h]->psi_n[3][0],scale*weight_vz*weight_cent);
	hEP_HF[1][0][cBin]->Fill(data[k][h]->hiEvtPlanes[24],data[k][h]->psi_n[3][14],scale*weight_vz*weight_cent);
	hEP_HF[1][1][cBin]->Fill(data[k][h]->hiEvtPlanes[25],data[k][h]->psi_n[3][0],scale*weight_vz*weight_cent);
	hEP_HF[1][2][cBin]->Fill(data[k][h]->hiEvtPlanes[26],data[k][h]->psi_n[3][14],scale*weight_vz*weight_cent);

	hEP_HF[2][0][cBin]->Fill(data[k][h]->hiEvtPlanes[27],data[k][h]->psi_n[4][0],scale*weight_vz*weight_cent);
	hEP_HF[2][0][cBin]->Fill(data[k][h]->hiEvtPlanes[27],data[k][h]->psi_n[4][14],scale*weight_vz*weight_cent);
	hEP_HF[2][1][cBin]->Fill(data[k][h]->hiEvtPlanes[28],data[k][h]->psi_n[4][0],scale*weight_vz*weight_cent);
	hEP_HF[2][2][cBin]->Fill(data[k][h]->hiEvtPlanes[29],data[k][h]->psi_n[4][14],scale*weight_vz*weight_cent);
	*/
	
	float sumpTtotal = 0;
	for(int a = 0;a<15;a++){
	  
	  //hSumpTvsHF[a]->Fill(data[k][h]->sumpT[a],data[k][h]->hiHF,scale*weight_vz*weight_cent);
	  //hSumpTvshiBin[a]->Fill(data[k][h]->sumpT[a],data[k][h]->bin,scale*weight_vz*weight_cent);
	  sumpTtotal+= data[k][h]->sumpT[a];
	  //for(int b = 0;b<5;b++){
	    
	  //  hPsivsHF[b][a]->Fill(data[k][h]->psi_n[b][a],data[k][h]->hiHF,scale*weight_vz*weight_cent);
	  //  hvnvsHF[b][a]->Fill(data[k][h]->v_n[b][a],data[k][h]->hiHF,scale*weight_vz*weight_cent);
	    //hPsi[cBin]->Fill(data[k][h]->psi_n[b][a]);
	  
	  //}// no of flow components 
	}// eta bin

	//Float_t sumpT_HF = data[k][h]->sumpT[0] + data[k][h]->sumpT[14];
	Float_t sumpT_noHF = 0;

	for(int a = 1;a<14;a++){
	  sumpT_noHF+= data[k][h]->sumpT[a];
	}
	
	hNJetsvsSumpT[cBin]->Fill(jetCounter,sumpTtotal,scale*weight_vz*weight_cent);
	hNJetsvsSumpT[nbins_cent]->Fill(jetCounter,sumpTtotal,scale*weight_vz*weight_cent);
	hNJetsvsSumpT_noHF[cBin]->Fill(jetCounter,sumpT_noHF,scale*weight_vz*weight_cent);
	hNJetsvsSumpT_noHF[nbins_cent]->Fill(jetCounter,sumpT_noHF,scale*weight_vz*weight_cent);
	hNJetsvsSumpT_HF[cBin]->Fill(jetCounter,sumpT_HF,scale*weight_vz*weight_cent);
	hNJetsvsSumpT_HF[nbins_cent]->Fill(jetCounter,sumpT_HF,scale*weight_vz*weight_cent);
	
	hSumpTvsHF_cent[cBin]->Fill(sumpTtotal,data[k][h]->hiHF,scale*weight_vz*weight_cent);
	hSumpTvsHF_cent[nbins_cent]->Fill(sumpTtotal,data[k][h]->hiHF,scale*weight_vz*weight_cent);
	//hSumpTvshiBin_cent[cBin]->Fill(data[k][h]->sumpT[a],data[k][h]->hiHF);
	hSumpT[cBin]->Fill(sumpTtotal,scale*weight_vz*weight_cent);
	hSumpT[nbins_cent]->Fill(sumpTtotal,scale*weight_vz*weight_cent);
       
	
      }// event entry loop

    }// pthat loop

  }// radius loop

  TFile fout(Form("/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_20/src/Output/PbPb_MC_HFVsValidation_total_histograms_ak%s%s_%d.root",algo,jet_type,date.GetDate()),"RECREATE");
  fout.cd();

  for(int i = 0;i<=nbins_cent;i++){
    hNJetsvsSumpT[i]->Write();
    hNJetsvsSumpT_noHF[i]->Write();
    hNJetsvsSumpT_HF[i]->Write();
    hSumpTvsHF_cent[i]->Write();
    hSumpT[i]->Write();
    hAngle_2_HF_Vs[i]->Write();
    hAngle_3_HF_Vs[i]->Write();
    hAngle_4_HF_Vs[i]->Write();
    hMagnitude_2_HF_Vs[i]->Write();
    hMagnitude_3_HF_Vs[i]->Write();
    hMagnitude_4_HF_Vs[i]->Write();
    hSub_vs_SumpT[i]->Write();
    hVsAngle_EP[0][i]->Write();
    hVsAngle_EP[1][i]->Write();
    hVsAngle_EP[2][i]->Write();
  }

}
Exemple #8
0
void RAA_calo_pf_JetCorrelation_pp(int startfile = 10, int endfile = 11, int radius=2, int deltaR=2/*which i will divide by 10 later when using*/, Float_t CALOPTCUT = 30.0, Float_t PFPTCUT = 30.0, char *dataset = "MC", char *etaWidth = "n20_eta_p20"){

  TH1::SetDefaultSumw2();

  TStopwatch timer;
  timer.Start();

  TDatime date;
  
  bool printDebug = false;

  // Since this has to run on the HiForest files, it is best to run them as condor jobs similar to the Pp data read macro, along with the jet trees which get their branch address set. 
  
  std::string infile1;
  if(dataset == "Data")infile1 = "jetRAA_pp_data_forest.txt";
  if(dataset == "MC")infile1 = "jetRAA_pp_mc_forest.txt";

  std::ifstream instr1(infile1.c_str(),std::ifstream::in);
  std::string filename1;

  cout<<"reading from "<<startfile<<" to "<<endfile<<endl;

  if(dataset=="MC"){
    for(int ifile = 0;ifile<4*startfile;ifile++){
      instr1>>filename1;
    }
  }
  if(dataset=="Data"){
    for(int ifile = 0;ifile<startfile;ifile++){
      instr1>>filename1;
    }
  }

  
  const int N = 5;
  
  TChain *jetpp1[N][no_radius];

  string dir[N][no_radius];
  
  for(int k = 0;k<no_radius;k++){
    dir[0][k] = "hltanalysis";
    dir[1][k] = "skimanalysis";
    dir[2][k] = Form("ak%dCaloJetAnalyzer",3);
    dir[3][k] = Form("ak%dPFJetAnalyzer",radius);
    dir[4][k] = "hiEvtAnalyzer";
    //dir[5][k] = "hltobject";
    //dir[6][k] = "pfcandAnalyzer";
  }
  
  
  string trees[N] = {
    "HltTree",
    "HltTree",
    "t",
    "t",
    "HiTree"
    //"jetObjTree",
    //"pfTree"
  };
  
  //this loop is to assign the tree values before we go into the file loop. 
  for(int k = 0;k<no_radius;k++){
    for(int t = 0;t<N;t++){
      jetpp1[t][k] = new TChain(string(dir[t][k]+"/"+trees[t]).data());
    }//tree loop ends
  }// radius loop ends
  
  if(dataset == "Data"){
    for(int ifile = startfile;ifile<endfile;ifile++){
    
      instr1>>filename1;
      if(printDebug)cout<<"File: "<<filename1<<endl;
      for(int k = 0;k<no_radius;k++){

	for(int t = 0;t<N;t++){
	
	  jetpp1[t][k]->Add(filename1.c_str());
	  if(printDebug)cout << "Tree loaded  " << string(dir[t][k]+"/"+trees[t]).data() << endl;
	  if(printDebug)cout << "Entries : " << jetpp1[t][k]->GetEntries() << endl;
		
	}// tree loop ends
      
      }// radius loop ends
    
    }// file loop ends

  }

  // these different file loops for MC is necessary because of eachfile being split into 4 files except the last pthat 540 which has 5 files. 
  if(dataset == "MC" && startfile <10){
    for(int ifile = 4*startfile;ifile<4*endfile;ifile++){
    
      instr1>>filename1;
      if(printDebug)cout<<"File: "<<filename1<<endl;
      for(int k = 0;k<no_radius;k++){

	for(int t = 0;t<N;t++){
	
	  jetpp1[t][k]->Add(filename1.c_str());
	  if(printDebug)cout << "Tree loaded  " << string(dir[t][k]+"/"+trees[t]).data() << endl;
	  if(printDebug)cout << "Entries : " << jetpp1[t][k]->GetEntries() << endl;
		
	}// tree loop ends
      
      }// radius loop ends
    
    }// file loop ends

  }

  if(dataset == "MC" && startfile == 10){
    for(int ifile = 4*startfile;ifile<4*endfile+1;ifile++){
    
      instr1>>filename1;
      if(printDebug)cout<<"File: "<<filename1<<endl;
      for(int k = 0;k<no_radius;k++){

	for(int t = 0;t<N;t++){
	
	  jetpp1[t][k]->Add(filename1.c_str());
	  if(printDebug)cout << "Tree loaded  " << string(dir[t][k]+"/"+trees[t]).data() << endl;
	  if(printDebug)cout << "Entries : " << jetpp1[t][k]->GetEntries() << endl;
		
	}// tree loop ends
      
      }// radius loop ends
    
    }// file loop ends

  }
  
  for(int k = 0;k<no_radius;k++){
    jetpp1[2][k]->AddFriend(jetpp1[0][k]);
    jetpp1[2][k]->AddFriend(jetpp1[1][k]);
    jetpp1[2][k]->AddFriend(jetpp1[4][k]);
    //jetpp1[2][k]->AddFriend(jetpp1[5][k]);
    
    jetpp1[3][k]->AddFriend(jetpp1[0][k]);
    jetpp1[3][k]->AddFriend(jetpp1[1][k]);
    jetpp1[3][k]->AddFriend(jetpp1[4][k]);
    //jetpp1[3][k]->AddFriend(jetpp1[5][k]);
    
  }// radius loop ends
 
  // Ok this should now work. 

  cout<<"total no of entries in the combined forest files = "<<jetpp1[2][0]->GetEntries()<<endl;
  //  if(printDebug)cout<<"total no of entries in the Jet80 Tree     = "<<jetpp2[2][0]->GetEntries()<<endl;

  // get the centrality weight, vz weight and the scale from the cross section, pt weighting. 
  static const Int_t nbins_pthat = 11;
  Double_t xsection[nbins_pthat+1] = {2.034e-01, 1.075e-02, 1.025e-03,  9.865e-05, 1.129e-05, 1.465e-06, 2.837e-07, 5.323e-08, 5.934e-09, 8.125e-10, 1.468e-10, 0};
  Double_t boundaries_pthat[nbins_pthat+1] = {15, 30, 50, 80, 120, 170, 220, 280, 370, 460, 540, 2000};
  TH1F * hpthatBin = new TH1F("hpthatBin","",nbins_pthat, boundaries_pthat);

  // Vertex reweighting for pp
  TF1 *fVzPP = new TF1("fVzPP","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x");
  fVzPP->SetParameters(8.41684e-01,-2.58609e-02,4.86550e-03,-3.10581e-04,2.07918e-05);
  
  
  TFile f(Form("/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_20/src/Output/pp_%s_closure_histogram_noJetID_deltaR_0p%d_ak%d_%d_%d.root",dataset,deltaR,radius,date.GetDate(),endfile),"RECREATE");
  f.cd();


  //set the branch addresses:
  // jet tree 1 - Calo 
  int nrefe_1;
  float pt_1[1000];
  float raw_1[1000];
  float refpt_1[1000];
  float eta_1[1000];
  float phi_1[1000];
  float chMax_1[1000];
  float trkMax_1[1000];
  float chSum_1[1000];
  float phSum_1[1000];
  float neSum_1[1000];
  float trkSum_1[1000];
  float phMax_1[1000];
  float neMax_1[1000];
  float eMax_1[1000];
  float muMax_1[1000];
  float eSum_1[1000];
  float muSum_1[1000];
  float jtpu_1[1000];
  float hcalSum_1[1000];
  float ecalSum_1[1000];
  int subid_1[1000];
  
  // jet tree 2 - PF
  int nrefe_2;
  float pt_2[1000];
  float raw_2[1000];
  float refpt_2[1000];
  float eta_2[1000];
  float eta_2_CM[1000];
  float phi_2[1000];
  float chMax_2[1000];
  float trkMax_2[1000];
  float chSum_2[1000];
  float phSum_2[1000];
  float neSum_2[1000];
  float trkSum_2[1000];
  float phMax_2[1000];
  float neMax_2[1000];
  float eMax_2[1000];
  float muMax_2[1000];
  float eSum_2[1000];
  float muSum_2[1000];
  float jtpu_2[1000];
  float hcalSum_2[1000];
  float ecalSum_2[1000];
  int subid_2[1000];
  
  // event tree
  int evt_1;
  int run_1;
  int lumi_1;
  float pthat_1;
  float vx_1;
  float vy_1;
  float vz_1;
  int hiNpix_1;
  int hiNtracks_1;
  float hiHF_1;
  float hiHFminus_1;
  float hiHFplus_1;
  float hiHFplusEta4_1;
  float hiHFminusEta4_1;
  int pPAcollisionEventSelectionPA_1;
  int pHBHENoiseFilter_1;
  int pprimaryvertexFilter_1;
  int pVertexFilterCutGplus_1;

  // trigger tree
  int jet40_1;
  int jet60_1;
  int jet80_1;
  int jet40_p_1;
  int jet60_p_1;
  int jet80_p_1;

  for(int k = 0;k<no_radius;k++){
    //set the branch addresses:  - one of the most boring parts of the code: 
    jetpp1[2][k]->SetBranchAddress("evt",&evt_1);
    jetpp1[2][k]->SetBranchAddress("run",&run_1);
    jetpp1[2][k]->SetBranchAddress("lumi",&lumi_1);
    if(dataset=="MC") jetpp1[2][k]->SetBranchAddress("pthat",&pthat_1);
    jetpp1[2][k]->SetBranchAddress("vz",&vz_1);
    jetpp1[2][k]->SetBranchAddress("vx",&vx_1);
    jetpp1[2][k]->SetBranchAddress("vy",&vy_1);
    jetpp1[2][k]->SetBranchAddress("hiNpix",&hiNpix_1);
    jetpp1[2][k]->SetBranchAddress("hiNtracks",&hiNtracks_1);
    jetpp1[2][k]->SetBranchAddress("hiHFminus",&hiHFminus_1);
    jetpp1[2][k]->SetBranchAddress("hiHF",&hiHF_1);
    jetpp1[2][k]->SetBranchAddress("hiHFplus",&hiHFplus_1);
    jetpp1[2][k]->SetBranchAddress("hiHFplusEta4",&hiHFplusEta4_1);
    jetpp1[2][k]->SetBranchAddress("hiHFminusEta4",&hiHFminusEta4_1);
    jetpp1[2][k]->SetBranchAddress("pPAcollisionEventSelectionPA",&pPAcollisionEventSelectionPA_1);
    jetpp1[2][k]->SetBranchAddress("pHBHENoiseFilter",&pHBHENoiseFilter_1);
    //jetpp1[2][k]->SetBranchAddress("pprimaryvertexFilter",&pprimaryvertexFilter_1);
    //jetpp1[2][k]->SetBranchAddress("pVertexFilterCutGplus",&pVertexFilterCutGplus_1);
  
    jetpp1[2][k]->SetBranchAddress("nref",&nrefe_1);
    jetpp1[2][k]->SetBranchAddress("jtpt",&pt_1);
    jetpp1[2][k]->SetBranchAddress("jteta",&eta_1);
    jetpp1[2][k]->SetBranchAddress("jtphi",&phi_1);
    jetpp1[2][k]->SetBranchAddress("rawpt",&raw_1);
    jetpp1[2][k]->SetBranchAddress("jtpu",&jtpu_1);
    jetpp1[2][k]->SetBranchAddress("chargedMax",&chMax_1);
    jetpp1[2][k]->SetBranchAddress("chargedSum",&chSum_1);
    jetpp1[2][k]->SetBranchAddress("trackMax",&trkMax_1);
    jetpp1[2][k]->SetBranchAddress("trackSum",&trkSum_1);
    jetpp1[2][k]->SetBranchAddress("photonMax",&phMax_1);
    jetpp1[2][k]->SetBranchAddress("photonSum",&phSum_1);
    jetpp1[2][k]->SetBranchAddress("neutralMax",&neMax_1);
    jetpp1[2][k]->SetBranchAddress("neutralSum",&neSum_1);
    jetpp1[2][k]->SetBranchAddress("eSum",&eSum_1);
    jetpp1[2][k]->SetBranchAddress("eMax",&eMax_1);
    jetpp1[2][k]->SetBranchAddress("muSum",&muSum_1);
    jetpp1[2][k]->SetBranchAddress("muMax",&muMax_1);
    jetpp1[2][k]->SetBranchAddress("ecalSum",&ecalSum_1);
    jetpp1[2][k]->SetBranchAddress("hcalSum",&hcalSum_1);
    
    jetpp1[3][k]->SetBranchAddress("nref",&nrefe_2);
    jetpp1[3][k]->SetBranchAddress("jtpt",&pt_2);
    jetpp1[3][k]->SetBranchAddress("jteta",&eta_2);
    jetpp1[3][k]->SetBranchAddress("jtphi",&phi_2);
    jetpp1[3][k]->SetBranchAddress("rawpt",&raw_2);
    jetpp1[3][k]->SetBranchAddress("jtpu",&jtpu_2);
    jetpp1[3][k]->SetBranchAddress("chargedMax",&chMax_2);
    jetpp1[3][k]->SetBranchAddress("chargedSum",&chSum_2);
    jetpp1[3][k]->SetBranchAddress("trackMax",&trkMax_2);
    jetpp1[3][k]->SetBranchAddress("trackSum",&trkSum_2);
    jetpp1[3][k]->SetBranchAddress("photonMax",&phMax_2);
    jetpp1[3][k]->SetBranchAddress("photonSum",&phSum_2);
    jetpp1[3][k]->SetBranchAddress("neutralMax",&neMax_2);
    jetpp1[3][k]->SetBranchAddress("neutralSum",&neSum_2);
    jetpp1[3][k]->SetBranchAddress("eSum",&eSum_2);
    jetpp1[3][k]->SetBranchAddress("eMax",&eMax_2);
    jetpp1[3][k]->SetBranchAddress("muSum",&muSum_2);
    jetpp1[3][k]->SetBranchAddress("muMax",&muMax_2);
    jetpp1[3][k]->SetBranchAddress("ecalSum",&ecalSum_2);
    jetpp1[3][k]->SetBranchAddress("hcalSum",&hcalSum_2);
    
    if(dataset=="MC"){

      jetpp1[2][k]->SetBranchAddress("subid",&subid_1);
      jetpp1[3][k]->SetBranchAddress("subid",&subid_2);
      jetpp1[2][k]->SetBranchAddress("refpt",&refpt_1);
      jetpp1[3][k]->SetBranchAddress("refpt",&refpt_2);

    }
    

    jetpp1[2][k]->SetBranchAddress("HLT_PAJet40_NoJetID_v1",&jet40_1);
    jetpp1[2][k]->SetBranchAddress("HLT_PAJet40_NoJetID_v1_Prescl",&jet40_p_1);
    jetpp1[2][k]->SetBranchAddress("HLT_PAJet60_NoJetID_v1",&jet60_1);
    jetpp1[2][k]->SetBranchAddress("HLT_PAJet60_NoJetID_v1_Prescl",&jet60_p_1);
    jetpp1[2][k]->SetBranchAddress("HLT_PAJet80_NoJetID_v1",&jet80_1);
    jetpp1[2][k]->SetBranchAddress("HLT_PAJet80_NoJetID_v1_Prescl",&jet80_p_1);

    // jetpp1[2][k]->SetBranchAddress("id",&trgObj_id_1);
    // jetpp1[2][k]->SetBranchAddress("pt",&trgObj_pt_1);
    // jetpp1[2][k]->SetBranchAddress("eta",&trgObj_eta_1);
    // jetpp1[2][k]->SetBranchAddress("phi",&trgObj_phi_1);
    // jetpp1[2][k]->SetBranchAddress("mass",&trgObj_mass_1);
    
    /*
    jetpp1[2][k]->SetBranchAddress("nPFpart", &nPFpart);
    jetpp1[2][k]->SetBranchAddress("pfId", pfId);
    jetpp1[2][k]->SetBranchAddress("pfPt", pfPt);
    jetpp1[2][k]->SetBranchAddress("pfVsPtInitial", pfVsPtInitial);
    jetpp1[2][k]->SetBranchAddress("pfVsPt", pfVsPt);
    jetpp1[2][k]->SetBranchAddress("pfEta", pfEta);
    jetpp1[2][k]->SetBranchAddress("pfPhi", pfPhi);
    jetpp1[2][k]->SetBranchAddress("pfArea", pfArea);
    jetpp1[2][k]->SetBranchAddress("vn",&v_n);
    jetpp1[2][k]->SetBranchAddress("psin",&psi_n);
    jetpp1[2][k]->SetBranchAddress("sumpt",&sumpT);
    */

  }// radius loop
  cout<<"after branch declaration"<<endl;

  cout<<"after histogram declaration"<<endl;

  Float_t calopt, pfpt, deltar, chMax, phMax, neMax, muMax, eMax, chSum, phSum, neSum, muSum, eSum, hcalSum, ecalSum;
  Int_t  jet80, jet80_prescl, jet60, jet60_prescl, jet40, jet40_prescl; 
  Int_t evt_value;
  Int_t run_value;
  Int_t lumi_value;
  Float_t weight;
  Float_t subid, pfrawpt, calorawpt, pfrefpt, calorefpt, pfjtpu, calojtpu, vz, pthat, caloeta, calophi, pfeta, pfphi;
  
  TTree* matchJets = new TTree("matchedJets","Ntuple containing important information about matched jets");
  matchJets->Branch("calopt",&calopt,"calopt/F");   matchJets->Branch("phSum",&phSum,"phSum/F");
  matchJets->Branch("pfpt",&pfpt,"pfpt/F");         matchJets->Branch("neSum",&neSum,"neSum/F");
  matchJets->Branch("deltar",&deltar,"deltar/F");   matchJets->Branch("muSum",&muSum,"muSum/F");
  matchJets->Branch("chMax",&chMax,"chMax/F");      matchJets->Branch("eSum",&eSum,"eSum/F");
  matchJets->Branch("phMax",&phMax,"phMax/F"); 
  matchJets->Branch("neMax",&neMax,"neMax/F");      matchJets->Branch("jet80",&jet80,"jet80/I");
  matchJets->Branch("muMax",&muMax,"muMax/F");      matchJets->Branch("jet80_prescl",&jet80_prescl,"jet80_prescl/I");
  matchJets->Branch("eMax",&eMax,"eMax/F");         matchJets->Branch("jet60",&jet60,"jet60/I");
  matchJets->Branch("chSum",&chSum,"chSum/F");      matchJets->Branch("jet60_prescl",&jet60_prescl,"jet60_prescl/I");
  matchJets->Branch("jet40",&jet40,"jet40/I");      matchJets->Branch("jet40_prescl",&jet40_prescl,"jet40_prescl/I");
  matchJets->Branch("hcalSum",&hcalSum,"hcalSum/F");matchJets->Branch("ecalSum",&ecalSum,"ecalSum/F");
  matchJets->Branch("run_value",&run_value,"run_value/I");
  matchJets->Branch("evt_value",&evt_value,"evt_value/I");
  matchJets->Branch("lumi_value",&lumi_value,"lumi_value/I");
  matchJets->Branch("caloeta", &caloeta, "caloeta/F");
  matchJets->Branch("calophi", &calophi, "calophi/F");
  matchJets->Branch("pfeta", &pfeta, "pfeta/F");
  matchJets->Branch("pfphi", &pfphi, "pfphi/F");
  if(dataset=="MC") matchJets->Branch("subid",&subid,"subid/I"); matchJets->Branch("pfrawpt",&pfrawpt,"pfrawpt/F");
  if(dataset=="MC") matchJets->Branch("pfrefpt",&pfrefpt,"pfrefpt/F"); matchJets->Branch("pfjtpu",&pfjtpu,"pfjtpu/F");
  if(dataset=="MC") matchJets->Branch("calorefpt",&calorefpt,"calorefpt/F");
  if(dataset=="MC") matchJets->Branch("pthat",&pthat,"pthat/F"); if(dataset=="MC") matchJets->Branch("vz",&vz,"vz/F");
  if(dataset=="MC") matchJets->Branch("weight",&weight,"weight/F");
  matchJets->Branch("calorawpt",&calorawpt,"calorawpt/F");
  matchJets->Branch("calojtpu",&calojtpu,"calojtpu/F");
  
  TTree* unmatchPFJets = new TTree("unmatchedPFJets","Ntuple containing important information about unmatched PF jets");
  unmatchPFJets->Branch("phSum",&phSum,"phSum/F");
  unmatchPFJets->Branch("pfpt",&pfpt,"pfpt/F");         unmatchPFJets->Branch("neSum",&neSum,"neSum/F");
  unmatchPFJets->Branch("deltar",&deltar,"deltar/F");   unmatchPFJets->Branch("muSum",&muSum,"muSum/F");
  unmatchPFJets->Branch("chMax",&chMax,"chMax/F");      unmatchPFJets->Branch("eSum",&eSum,"eSum/F");
  unmatchPFJets->Branch("phMax",&phMax,"phMax/F");
  unmatchPFJets->Branch("neMax",&neMax,"neMax/F");      unmatchPFJets->Branch("jet80",&jet80,"jet80/I");
  unmatchPFJets->Branch("muMax",&muMax,"muMax/F");      unmatchPFJets->Branch("jet80_prescl",&jet80_prescl,"jet80_prescl/I");
  unmatchPFJets->Branch("eMax",&eMax,"eMax/F");         unmatchPFJets->Branch("jet60",&jet60,"jet60/I");
  unmatchPFJets->Branch("chSum",&chSum,"chSum/F");      unmatchPFJets->Branch("jet60_prescl",&jet60_prescl,"jet60_prescl/I");
  unmatchPFJets->Branch("jet40",&jet40,"jet40/I");      unmatchPFJets->Branch("jet40_prescl",&jet40_prescl,"jet40_prescl/I");
  unmatchPFJets->Branch("hcalSum",&hcalSum,"hcalSum/F");unmatchPFJets->Branch("ecalSum",&ecalSum,"ecalSum/F");
  unmatchPFJets->Branch("run_value",&run_value,"run_value/I");
  unmatchPFJets->Branch("evt_value",&evt_value,"evt_value/I");
  unmatchPFJets->Branch("lumi_value",&lumi_value,"lumi_value/I");
  unmatchPFJets->Branch("pfeta", &pfeta, "pfeta/F");
  unmatchPFJets->Branch("pfphi", &pfphi, "pfphi/F");
  if(dataset=="MC") unmatchPFJets->Branch("subid",&subid,"subid/I"); unmatchPFJets->Branch("pfrawpt",&pfrawpt,"pfrawpt/F");
  if(dataset=="MC") unmatchPFJets->Branch("pfrefpt",&pfrefpt,"pfrefpt/F"); unmatchPFJets->Branch("pfjtpu",&pfjtpu,"pfjtpu/F");
  if(dataset=="MC") unmatchPFJets->Branch("weight",&weight,"weight/F");
  if(dataset=="MC") unmatchPFJets->Branch("pthat",&pthat,"pthat/F"); if(dataset=="MC") unmatchPFJets->Branch("vz",&vz,"vz/F");
  
  TTree* unmatchCaloJets = new TTree("unmatchedCaloJets","Ntuple containing important information about unmatched Calo jets");
  unmatchCaloJets->Branch("phSum",&phSum,"phSum/F");
  unmatchCaloJets->Branch("calopt",&calopt,"calopt/F");   unmatchCaloJets->Branch("neSum",&neSum,"neSum/F");
  unmatchCaloJets->Branch("deltar",&deltar,"deltar/F");   unmatchCaloJets->Branch("muSum",&muSum,"muSum/F");
  unmatchCaloJets->Branch("chMax",&chMax,"chMax/F");      unmatchCaloJets->Branch("eSum",&eSum,"eSum/F");
  unmatchCaloJets->Branch("phMax",&phMax,"phMax/F");     
  unmatchCaloJets->Branch("neMax",&neMax,"neMax/F");      unmatchCaloJets->Branch("jet80",&jet80,"jet80/I");
  unmatchCaloJets->Branch("muMax",&muMax,"muMax/F");      unmatchCaloJets->Branch("jet80_prescl",&jet80_prescl,"jet80_prescl/I");
  unmatchCaloJets->Branch("eMax",&eMax,"eMax/F");         unmatchCaloJets->Branch("jet60",&jet60,"jet60/I");
  unmatchCaloJets->Branch("chSum",&chSum,"chSum/F");      unmatchCaloJets->Branch("jet60_prescl",&jet60_prescl,"jet60_prescl/I");
  unmatchCaloJets->Branch("jet40",&jet40,"jet40/I");      unmatchCaloJets->Branch("jet40_prescl",&jet40_prescl,"jet40_prescl/I");
  unmatchCaloJets->Branch("hcalSum",&hcalSum,"hcalSum/F");unmatchCaloJets->Branch("ecalSum",&ecalSum,"ecalSum/F");
  unmatchCaloJets->Branch("run_value",&run_value,"run_value/I");
  unmatchCaloJets->Branch("evt_value",&evt_value,"evt_value/I");
  unmatchCaloJets->Branch("lumi_value",&lumi_value,"lumi_value/I");
  unmatchCaloJets->Branch("caloeta", &caloeta, "caloeta/F");
  unmatchCaloJets->Branch("calophi", &calophi, "calophi/F");
  if(dataset=="MC") unmatchCaloJets->Branch("subid",&subid,"subid/I"); 
  if(dataset=="MC") unmatchCaloJets->Branch("calorefpt",&calorefpt,"calorefpt/F");
  if(dataset=="MC") unmatchCaloJets->Branch("pthat",&pthat,"pthat/F"); if(dataset=="MC") unmatchCaloJets->Branch("vz",&vz,"vz/F");
  if(dataset=="MC") unmatchCaloJets->Branch("weight",&weight,"weight/F");
  unmatchCaloJets->Branch("calorawpt",&calorawpt,"calorawpt/F");
  unmatchCaloJets->Branch("calojtpu",&calojtpu,"calojtpu/F");


  TH1F * hEvents = new TH1F("hEvents","",20,0,10);

  // define the histograms 

  // define the histograms necessary for that MC closure test.
  TH2F *hpp_mcclosure_matrix_HLT;
  TH2F *hpp_mcclosure_matrix;
  //TH2F *hpp_response;
  TH1F *hpp_mcclosure_JetComb_data;
  TH1F *hpp_mcclosure_data;
  TH1F *hpp_mcclosure_Jet80_data;
  TH1F *hpp_mcclosure_Jet60_data;
  TH1F *hpp_mcclosure_Jet40_data;
  TH1F *hpp_mcclosure_gen;
  TH1F *hpp_mcclosure_JetComb_gen;
  TH1F *hpp_mcclosure_Jet80_gen;
  TH1F *hpp_mcclosure_Jet60_gen;
  TH1F *hpp_mcclosure_Jet40_gen;
  
  hpp_mcclosure_matrix_HLT = new TH2F(Form("hpp_mcclosure_matrix_HLT_R%d_%s",radius,etaWidth),Form("Matrix for mcclosure refpt jtpt from Jet triggers R%d %s ",radius,etaWidth),nbins_pt,boundaries_pt,nbins_pt,boundaries_pt);
  hpp_mcclosure_matrix = new TH2F(Form("hpp_mcclosure_matrix_R%d_%s",radius,etaWidth),Form("Matrix for mcclosure refpt jtpt from Jet triggers R%d %s ",radius,etaWidth),nbins_pt,boundaries_pt,nbins_pt,boundaries_pt);
  //cout<<"C"<<endl;
  hpp_mcclosure_data = new TH1F(Form("hpp_mcclosure_data_R%d_%s",radius,etaWidth),Form("data for unfolding mc closure test R%d %s ",radius,etaWidth),nbins_pt,boundaries_pt);
  hpp_mcclosure_JetComb_data = new TH1F(Form("hpp_mcclosure_JetComb_data_R%d_%s",radius,etaWidth),Form("data for unfolding mc closure test trigger combined  R%d %s ",radius,etaWidth),nbins_pt,boundaries_pt);
  hpp_mcclosure_Jet80_data = new TH1F(Form("hpp_mcclosure_Jet80_data_R%d_%s",radius,etaWidth),Form("data for unfolding mc closure test trigger 80  R%d %s ",radius,etaWidth),nbins_pt,boundaries_pt);
  hpp_mcclosure_Jet60_data = new TH1F(Form("hpp_mcclosure_Jet60_data_R%d_%s",radius,etaWidth),Form("data for unfolding mc closure test trigger 60  R%d %s ",radius,etaWidth),nbins_pt,boundaries_pt);
  hpp_mcclosure_Jet40_data = new TH1F(Form("hpp_mcclosure_Jet40_data_R%d_%s",radius,etaWidth),Form("data for unfolding mc closure test trigger 40  R%d %s ",radius,etaWidth),nbins_pt,boundaries_pt);

  hpp_mcclosure_gen = new TH1F(Form("hpp_mcclosure_gen_R%d_%s",radius,etaWidth),Form("gen spectra for unfolding mc closure test R%d %s ",radius,etaWidth),nbins_pt,boundaries_pt);
  hpp_mcclosure_JetComb_gen = new TH1F(Form("hpp_mcclosure_gen_JetComb_R%d_%s",radius,etaWidth),Form("gen spectra for unfolding mc closure test trigger combined R%d %s ",radius,etaWidth),nbins_pt,boundaries_pt);
  hpp_mcclosure_Jet80_gen = new TH1F(Form("hpp_mcclosure_gen_Jet80_R%d_%s",radius,etaWidth),Form("gen spectra for unfolding mc closure test trigger 80 R%d %s ",radius,etaWidth),nbins_pt,boundaries_pt);
  hpp_mcclosure_Jet60_gen = new TH1F(Form("hpp_mcclosure_gen_Jet60_R%d_%s",radius,etaWidth),Form("gen spectra for unfolding mc closure test trigger 60 R%d %s ",radius,etaWidth),nbins_pt,boundaries_pt);
  hpp_mcclosure_Jet40_gen = new TH1F(Form("hpp_mcclosure_gen_Jet40_R%d_%s",radius,etaWidth),Form("gen spectra for unfolding mc closure test trigger 40 R%d %s ",radius,etaWidth),nbins_pt,boundaries_pt);

  
  // declare the 2d calo and pf candidate vectors, deltaR_calovsPF is going to be a 3d vector like so:
  // calo jet on x axis, pf jet on y axis, and delta R, calopT, pfpT on z axis.
  // we also need to add in the trigger information here since we need to know what trigger the matching comes from. maybe i can run that later as an added check. for now just to see if the algorithm is working should try to run things. 
  //vector<vector<double> > caloJet;
  //vector<vector<double> > pfJet;

  // start the loop process

  for(int k = 0;k<no_radius;k++){

    Long64_t nentries = jetpp1[2][k]->GetEntries();
    //Long64_t nentries = 100;

    Long64_t fentries= 1;
    if(dataset=="MC"){
      TEventList *el = new TEventList("el","el");
      double pthat_upper = boundaries_pthat[startfile + 1];
      stringstream selection; selection<<"pthat<"<<pthat_upper;
      
      jetpp1[2][k]->Draw(">>el",selection.str().c_str());
      fentries = el->GetN();
      delete el;
    }
    
    for(Long64_t nentry = 0; nentry<nentries;nentry++){
      if(printDebug)cout<<"event no = "<<nentry<<endl;
      for(int t = 0;t<N;t++)  jetpp1[t][k]->GetEntry(nentry);
      
      hEvents->Fill(0);

      //int centBin = findBin(hiBin_1);
      //if(centBin==-1) continue;
      //if(pHBHENoiseFilter_1==0 || pcollisionEventSelection_1==0) continue; 
      if(pPAcollisionEventSelectionPA_1==0) continue; 
      hEvents->Fill(1);
      if(dataset=="Data") if(pHBHENoiseFilter_1==0 ) continue;
      hEvents->Fill(2);

      if(fabs(vz_1)>15) continue;
      //cout<<"passed the selection"<<endl;

      hEvents->Fill(3);

      weight = 1;

      if(dataset=="MC"){
	
	int pthatBin = hpthatBin->FindBin(pthat_1);
	
	double scale = (double)(xsection[pthatBin-1]-xsection[pthatBin])/fentries;

	Float_t weight_vz = fVzPP->Eval(vz_1);
	weight = scale*weight_vz;

      }

      // start doing the search for the match. - best thing to do would be to create a 2D match delta R matrix with each calo jet and pf jet. Once thats done - find the smallest entry in that matrix. the i,j of that smallest entry are matched. now remove the row i and column j and then we have a new distance matrix. where we need to find the smallest element again. keep doing this till we have either no rows or no columns.  

      // declare the necessary variables:
      Float_t deltaRCaloPF = 0;
      Float_t calojet_eta = 0;
      Float_t calojet_phi = 0;
      Float_t calojet_pt = 0;
      Float_t pfjet_eta = 0;
      Float_t pfjet_phi = 0;
      Float_t pfjet_pt = 0;
      
      vector<vector<double> > matchedCaloPFJet;
      vector<vector<vector<double> > > deltaR_calovsPF;
      int calosize = 0;
      Float_t deltapT = 0;
      int calomatchcounter = 0;
      
      for(int g = 0;g<nrefe_1;g++){
	
	calojet_eta = eta_1[g];
	calojet_phi = phi_1[g];
	calojet_pt = pt_1[g];
	
	if(calojet_pt < CALOPTCUT) continue;
	if(TMath::Abs(calojet_eta) > 2.0) continue;
	
	int pfmatchcounter = 0;
	deltaR_calovsPF.push_back(vector<vector<double> > ());
	
	calosize++;
	
	for(int j = 0;j<nrefe_2;j++){

	  pfjet_eta = eta_2[j];
	  pfjet_phi = phi_2[j];
	  pfjet_pt = pt_2[j];

	  if(pfjet_pt < PFPTCUT) continue;
	  if(TMath::Abs(pfjet_eta) > 2.0) continue;

	  deltaRCaloPF = Calc_deltaR(calojet_eta, calojet_phi, pfjet_eta, pfjet_phi);
	  
	  // if(deltaRCaloPF > (Float_t)deltaR/10) continue;
	  deltapT = TMath::Abs(calojet_pt - pfjet_pt);

	  deltaR_calovsPF[calomatchcounter].push_back(vector<double> ());
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(deltaRCaloPF); // 0 - delta R
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(deltapT); // 1 - delta pT	  
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(g); // 2 - calo counter 
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(calojet_pt); // 3 - calo jet pT 
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(j); // 4 - pf counter 
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(pfjet_pt); // 5 - pf jet pT
	  // this will have the candidate variables for the matched jets. 
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(chMax_2[j]); // 6 - chMax 
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(phMax_2[j]); // 7 - phMax
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(neMax_2[j]); // 8 - neMax
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(muMax_2[j]); // 9 - muMax
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(eMax_2[j]); // 10 - eMax
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(chSum_2[j]); // 11 - chSum
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(phSum_2[j]); // 12 - phSum
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(neSum_2[j]); // 13 - neSum
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(muSum_2[j]); // 14 - muSum
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(eSum_2[j]); // 15 - eSum
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(0.0); // 16 - this is the variable which will tell me if a jet is matched.
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(hcalSum_2[j]); // 17 - hcalSum 
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(ecalSum_2[j]); // 18 - hcalSum
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(raw_2[j]); // 19 - raw pt
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(jtpu_2[j]); // 20 - jtpu
	  //all the following candidate information is for the calo jets 
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(chMax_1[g]); // 21 - chMax 
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(phMax_1[g]); // 22 - phMax
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(neMax_1[g]); // 23 - neMax
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(muMax_1[g]); // 24 - muMax
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(eMax_1[g]); // 25 - eMax
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(chSum_1[g]); // 26 - chSum
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(phSum_1[g]); // 27 - phSum
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(neSum_1[g]); // 28 - neSum
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(muSum_1[g]); // 29 - muSum
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(eSum_1[g]); // 30 - eSum
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(hcalSum_1[g]); // 31 - hcalSum 
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(ecalSum_1[g]); // 32 - hcalSum
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(raw_1[g]); // 33 - raw pt
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(jtpu_1[g]); // 34 - jtpu

	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(pfjet_eta); // 35 - pf eta
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(pfjet_phi); // 36 - pf phi
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(calojet_eta); // 37 - calo eta
	  deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(calojet_phi); // 38 - calo phi
	  
	  if(dataset=="MC") {
	    deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(refpt_1[g]); // 39 calo ref pt 
	    deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(refpt_2[j]); // 40 pf ref pt 
	    deltaR_calovsPF[calomatchcounter][pfmatchcounter].push_back(subid_2[j]); // 41 - subid only for MC
	    
	  }
	  
	  
	  ++pfmatchcounter;

	}// pf jet loop
	++calomatchcounter;
	
      }// calo jet loop

      // set the event variables before proceeding to the matching. 
      jet80 = jet80_1;
      jet80_prescl = jet80_p_1;
      jet60 = jet60_1;
      jet60_prescl = jet60_p_1;
      jet40 = jet40_1;
      jet40_prescl = jet40_p_1;
      run_value = run_1;
      evt_value = evt_1;
      lumi_value = lumi_1;
      vz = vz_1;
      if(dataset=="MC")pthat = pthat_1;

      if(printDebug)cout<<deltaR_calovsPF.size()<<endl;
      if(printDebug)for(int a = 0;a<deltaR_calovsPF.size();++a) cout<<deltaR_calovsPF[a].size()<<" ";
      if(printDebug)cout<<endl<<"going to small matching"<<endl;
      
      // now that we have the 2D matrix, lets find the smallest delta R element from that and fill in the value of the 

      Float_t smallDeltaR = 10;
      Int_t small_calo = 0;
      Int_t small_pf = 0;

      for(int c = 0;c<deltaR_calovsPF.size();++c){
	// if(printDebug)cout<<"going through all rows in the  matrix "<<c<<endl;
	for(int a = 0;a<deltaR_calovsPF.size();++a){
	  // if(printDebug)cout<<"calo jet iteration "<<a<<endl;
	  for(int b = 0;b<deltaR_calovsPF[a].size();++b){
	    // if(printDebug)cout<<"pf jet iteration "<<b<<endl;
	    
	    if(deltaR_calovsPF[a][b][16]==1){ 
	      break;
	    }
	    if(smallDeltaR > deltaR_calovsPF[a][b][0]){
	      
	      smallDeltaR = deltaR_calovsPF[a][b][0];
	      small_calo = a;
	      small_pf = b;
	      
	    }
	  }
	}
	
	if(smallDeltaR > (Float_t)deltaR/10 || deltaR_calovsPF[small_calo][small_pf][16] == 1) continue;
	
	calopt = deltaR_calovsPF[small_calo][small_pf][3];
	pfpt = deltaR_calovsPF[small_calo][small_pf][5];
	if(dataset=="MC"){
	  pfrefpt = deltaR_calovsPF[small_calo][small_pf][40];
	  calorefpt = deltaR_calovsPF[small_calo][small_pf][39];
	  subid = deltaR_calovsPF[small_calo][small_pf][41]; 
	}
	pfrawpt = deltaR_calovsPF[small_calo][small_pf][19]; 
	calorawpt = deltaR_calovsPF[small_calo][small_pf][33]; 
	pfjtpu = deltaR_calovsPF[small_calo][small_pf][20]; 
	calojtpu = deltaR_calovsPF[small_calo][small_pf][34];
	deltar = deltaR_calovsPF[small_calo][small_pf][0];
	chMax = deltaR_calovsPF[small_calo][small_pf][6];
	phMax = deltaR_calovsPF[small_calo][small_pf][7];
	neMax = deltaR_calovsPF[small_calo][small_pf][8];
	muMax = deltaR_calovsPF[small_calo][small_pf][9];
	eMax = deltaR_calovsPF[small_calo][small_pf][10];
	chSum = deltaR_calovsPF[small_calo][small_pf][11];
	phSum = deltaR_calovsPF[small_calo][small_pf][12];
	neSum = deltaR_calovsPF[small_calo][small_pf][13];
	muSum = deltaR_calovsPF[small_calo][small_pf][14];
	eSum = deltaR_calovsPF[small_calo][small_pf][15];
	pfeta = deltaR_calovsPF[small_calo][small_pf][35];
	pfphi = deltaR_calovsPF[small_calo][small_pf][36];
	caloeta = deltaR_calovsPF[small_calo][small_pf][37];
	calophi = deltaR_calovsPF[small_calo][small_pf][38];
	hcalSum = deltaR_calovsPF[small_calo][small_pf][17];
	ecalSum = deltaR_calovsPF[small_calo][small_pf][18];
	
	//matchJets->Fill();
	
	if(c==0) hEvents->Fill(4);
	  
	if(dataset=="MC"){
	  // fill in the matched histograms with the Jet ID cuts:
	  if(subid!=0) continue;
	
	  Float_t Sumcand = chSum + phSum + neSum + muSum;

	  //if(calopt/pfpt > 0.5 && calopt/pfpt <= 0.85 && eMax/Sumcand < ((Float_t)18/7 *(Float_t)calopt/pfpt - (Float_t)9/7)){
	    if(nentry%2==1) {
	      hpp_mcclosure_matrix->Fill(pfrefpt, pfpt, weight);
	      hpp_mcclosure_gen->Fill(pfrefpt, weight);
	    }
	    if(nentry%2==1) {
	      hpp_mcclosure_data->Fill(pfpt, weight);
	    }
	    //}
	  
	  if(jet40 == 1 && jet60==0 && jet80 == 0){

	    //if(calopt/pfpt > 0.5 && calopt/pfpt <= 0.85 && eMax/Sumcand < ((Float_t)18/7 *(Float_t)calopt/pfpt - (Float_t)9/7)){
	      if(nentry%2==1) {
		hpp_mcclosure_matrix_HLT->Fill(pfrefpt, pfpt, weight);
		hpp_mcclosure_Jet40_gen->Fill(pfrefpt, weight);
	      }
	      if(nentry%2==1) {
		hpp_mcclosure_Jet40_data->Fill(pfpt, weight);
	      }
	      //}

	    // if(calopt/pfpt > 0.85) {
	    //   if(nentry%2==1) {
	    // 	hpp_mcclosure_matrix_HLT->Fill(pfrefpt, pfpt, weight);
	    // 	hpp_mcclosure_Jet40_gen->Fill(pfrefpt, weight);
	    //   }
	    //   if(nentry%2==1) {
	    // 	hpp_mcclosure_Jet40_data->Fill(pfpt, weight);
	    //   }
	    // }

	    // if(calopt/pfpt <= 0.5 && eMax/Sumcand < 0.05) {
	    //   if(nentry%2==1) {
	    // 	hpp_mcclosure_matrix_HLT->Fill(pfrefpt, pfpt, weight);
	    // 	hpp_mcclosure_Jet40_gen->Fill(pfrefpt, weight);
	    //   }
	    //   if(nentry%2==1) {
	    // 	hpp_mcclosure_Jet40_data->Fill(pfpt, weight);
	    //   }
	    // }
	  
	  }

	  if(jet60 == 1 && jet80 == 0){

	    //if(calopt/pfpt > 0.5 && calopt/pfpt <= 0.85 && eMax/Sumcand < ((Float_t)18/7 *(Float_t)calopt/pfpt - (Float_t)9/7)){
	      if(nentry%2==1) {
		hpp_mcclosure_matrix_HLT->Fill(pfrefpt, pfpt, weight);
		hpp_mcclosure_Jet60_gen->Fill(pfrefpt, weight);
	      }
	      if(nentry%2==1) {
		hpp_mcclosure_Jet60_data->Fill(pfpt, weight);
	      }
	      //}

	    // if(calopt/pfpt > 0.85) {
	    //   if(nentry%2==1) {
	    // 	hpp_mcclosure_matrix_HLT->Fill(pfrefpt, pfpt, weight);
	    // 	hpp_mcclosure_Jet60_gen->Fill(pfrefpt, weight);
	    //   }
	    //   if(nentry%2==1) {
	    // 	hpp_mcclosure_Jet60_data->Fill(pfpt, weight);
	    //   }
	    // }

	    // if(calopt/pfpt <= 0.5 && eMax/Sumcand < 0.05) {
	    //   if(nentry%2==1) {
	    // 	hpp_mcclosure_matrix_HLT->Fill(pfrefpt, pfpt, weight);
	    // 	hpp_mcclosure_Jet60_gen->Fill(pfrefpt, weight);
	    //   }
	    //   if(nentry%2==1) {
	    // 	hpp_mcclosure_Jet60_data->Fill(pfpt, weight);
	    //   }
	    // }
	  
	  
	  }

	  if(jet80==1){

	    //if(calopt/pfpt > 0.5 && calopt/pfpt <= 0.85 && eMax/Sumcand < ((Float_t)18/7 *(Float_t)calopt/pfpt - (Float_t)9/7)){
	      if(nentry%2==1) {
		hpp_mcclosure_matrix_HLT->Fill(pfrefpt, pfpt, weight);
		hpp_mcclosure_Jet80_gen->Fill(pfrefpt, weight);
	      }
	      if(nentry%2==1) {
		hpp_mcclosure_Jet80_data->Fill(pfpt, weight);
	      }
	      //}

	    // if(calopt/pfpt > 0.85) {
	    //   if(nentry%2==1) {
	    // 	hpp_mcclosure_matrix_HLT->Fill(pfrefpt, pfpt, weight);
	    // 	hpp_mcclosure_Jet80_gen->Fill(pfrefpt, weight);
	    //   }
	    //   if(nentry%2==1) {
	    // 	hpp_mcclosure_Jet80_data->Fill(pfpt, weight);
	    //   }
	    // }

	    // if(calopt/pfpt <= 0.5 && eMax/Sumcand < 0.05) {
	    //   if(nentry%2==1) {
	    // 	hpp_mcclosure_matrix_HLT->Fill(pfrefpt, pfpt, weight);
	    // 	hpp_mcclosure_Jet80_gen->Fill(pfrefpt, weight);
	    //   }
	    //   if(nentry%2==1) {
	    // 	hpp_mcclosure_Jet80_data->Fill(pfpt, weight);
	    //   }
	    // }
	  
	  
	  }

	}


	smallDeltaR = 10;
	for(int b = 0;b<deltaR_calovsPF[small_calo].size();++b){
	  deltaR_calovsPF[small_calo][b][16] = 1; // by setting this value you effectively remove that calo and pf jet for further matching // removes the column for getting matched. 
	}
	for(int a = 0;a<deltaR_calovsPF.size();++a){
	  deltaR_calovsPF[a][small_pf][16] = 1; // this removes the whole row from getting matched later. 
	}

      }// running it for the number of calo jets: 

      if(printDebug)cout<<"now going to find unmatched pf jets"<<endl;
      // ok Now lets find the un-matched jets and fill the necessary unmatched ntuple:

      if(deltaR_calovsPF.size() == 0) continue;
      for(int b = 0;b<deltaR_calovsPF[0].size();++b){
	if(printDebug)cout<<"pf jet iteration "<<b<<endl;

	if(deltaR_calovsPF[0][b][16] == 1) continue;

	pfpt = deltaR_calovsPF[0][b][5];
	deltar = deltaR_calovsPF[0][b][0];
	if(dataset=="MC"){
	  pfrefpt = deltaR_calovsPF[0][b][40];
	  subid = deltaR_calovsPF[0][b][41]; 
	}
	pfrawpt = deltaR_calovsPF[0][b][19]; 
	pfjtpu = deltaR_calovsPF[0][b][20]; 
	chMax = deltaR_calovsPF[0][b][6];
	phMax = deltaR_calovsPF[0][b][7];
	neMax = deltaR_calovsPF[0][b][8];
	muMax = deltaR_calovsPF[0][b][9];
	eMax = deltaR_calovsPF[0][b][10];
	chSum = deltaR_calovsPF[0][b][11];
	phSum = deltaR_calovsPF[0][b][12];
	neSum = deltaR_calovsPF[0][b][13];
	muSum = deltaR_calovsPF[0][b][14];
	eSum = deltaR_calovsPF[0][b][15];
	pfeta = deltaR_calovsPF[0][b][35];
	pfphi = deltaR_calovsPF[0][b][36];
	hcalSum = deltaR_calovsPF[0][b][17];
	ecalSum = deltaR_calovsPF[0][b][18];
	
	//unmatchPFJets->Fill();

	if(b==0) hEvents->Fill(5);

	if(dataset=="MC"){
	  // fill in the matched histograms with the Jet ID cuts:
	  if(subid!=0) continue;
	
	  Float_t Sumcand = chSum + phSum + neSum + muSum;

	  //if(eMax/Sumcand < 0.05) {
	    if(nentry%2==1) {
	      hpp_mcclosure_matrix->Fill(pfrefpt, pfpt, weight);
	      hpp_mcclosure_gen->Fill(pfrefpt, weight);
	    }
	    if(nentry%2==1) {
	      hpp_mcclosure_data->Fill(pfpt, weight);
	    }
	    //}
	  
	  
	  if(jet40 == 1 && jet60 == 0 && jet80 == 0){

	    //if(eMax/Sumcand < 0.05) {
	      if(nentry%2==1) {
		hpp_mcclosure_matrix_HLT->Fill(pfrefpt, pfpt, weight);
		hpp_mcclosure_Jet40_gen->Fill(pfrefpt, weight);
	      }
	      if(nentry%2==1) {
		hpp_mcclosure_Jet40_data->Fill(pfpt, weight);
	      }
	      //}
	  
	  }

	  if(jet60 == 1 && jet80 == 0){

	    //if(eMax/Sumcand < 0.05) {
	      if(nentry%2==1) {
		hpp_mcclosure_matrix_HLT->Fill(pfrefpt, pfpt, weight);
		hpp_mcclosure_Jet60_gen->Fill(pfrefpt, weight);
	      }
	      if(nentry%2==1) {
		hpp_mcclosure_Jet60_data->Fill(pfpt, weight);
	      }
	      //}
	  
	  
	  }

	  if(jet80==1){

	    //if(eMax/Sumcand < 0.05) {
	      if(nentry%2==1) {
		hpp_mcclosure_matrix_HLT->Fill(pfrefpt, pfpt, weight);
		hpp_mcclosure_Jet80_gen->Fill(pfrefpt, weight);
	      }
	      if(nentry%2==1) {
		hpp_mcclosure_Jet80_data->Fill(pfpt, weight);
	      }
	      //}
	  
	  
	  }
	}

	
      }// unmatched PF jets
      
      if(printDebug)cout<<"now going to find unmatched calo jets"<<endl;

      if(deltaR_calovsPF[0].size() == 0) continue;
      
      for(int a = 0;a<deltaR_calovsPF.size();++a){
	if(printDebug)cout<<"calo jet iteration "<<a<<endl;

	if(deltaR_calovsPF[a][0][16] == 1) continue;

	calopt = deltaR_calovsPF[a][0][3];
	deltar = deltaR_calovsPF[a][0][0];
	if(dataset=="MC"){
	  calorefpt = deltaR_calovsPF[a][0][39];
	  subid = deltaR_calovsPF[a][0][41]; 
	}
	calorawpt = deltaR_calovsPF[a][0][33]; 
	calojtpu = deltaR_calovsPF[a][0][34]; 
	chMax = deltaR_calovsPF[a][0][21];
	phMax = deltaR_calovsPF[a][0][22];
	neMax = deltaR_calovsPF[a][0][23];
	muMax = deltaR_calovsPF[a][0][24];
	eMax = deltaR_calovsPF[a][0][25];
	chSum = deltaR_calovsPF[a][0][26];
	phSum = deltaR_calovsPF[a][0][27];
	neSum = deltaR_calovsPF[a][0][28];
	muSum = deltaR_calovsPF[a][0][29];
	eSum = deltaR_calovsPF[a][0][30];
	caloeta = deltaR_calovsPF[a][0][37];
	calophi = deltaR_calovsPF[a][0][38];
	hcalSum = deltaR_calovsPF[a][0][31];
	ecalSum = deltaR_calovsPF[a][0][32];
	
	//unmatchCaloJets->Fill();

      }

    }// event loop 

  }// radius loop


  // matchJets->Write();
  // matchJets->Print();
  // unmatchPFJets->Write();
  // unmatchPFJets->Print();
  // unmatchCaloJets->Write();
  // unmatchCaloJets->Print();


  hpp_mcclosure_JetComb_data->Add(hpp_mcclosure_Jet80_data);
  hpp_mcclosure_JetComb_data->Add(hpp_mcclosure_Jet60_data);
  hpp_mcclosure_JetComb_data->Add(hpp_mcclosure_Jet40_data);

  hpp_mcclosure_JetComb_gen->Add(hpp_mcclosure_Jet80_gen);
  hpp_mcclosure_JetComb_gen->Add(hpp_mcclosure_Jet60_gen);
  hpp_mcclosure_JetComb_gen->Add(hpp_mcclosure_Jet40_gen);

  hpp_mcclosure_matrix_HLT->Write();
  hpp_mcclosure_matrix->Write();
  hpp_mcclosure_JetComb_data->Write();
  hpp_mcclosure_data->Write();
  hpp_mcclosure_Jet80_data->Write();
  hpp_mcclosure_Jet60_data->Write();
  hpp_mcclosure_Jet40_data->Write();
  hpp_mcclosure_JetComb_gen->Write();    
  hpp_mcclosure_gen->Write();    
  hpp_mcclosure_Jet80_gen->Write();
  hpp_mcclosure_Jet60_gen->Write();
  hpp_mcclosure_Jet40_gen->Write();
    

  hEvents->Write();

  timer.Stop();
  cout<<"Macro finished: "<<endl;
  cout<<"CPU time (min)  = "<<(Float_t)timer.CpuTime()/60<<endl;
  cout<<"Real time (min) = "<<(Float_t)timer.RealTime()/60<<endl;
  
}
Exemple #9
0
//_____________________________________________________________________
void bfcMixer_Ftpc(const Int_t Nevents=20,
                   const Char_t *daqfile="/star/rcf/test/daq/2008/emb/st_fmsslow_adc_9069059_raw_1520001.daq",
                   const Char_t *tagfile="/star/rcf/test/daq/2008/emb/daqtags/st_fmsslow_adc_9069059_raw_1520001.tags.root",
                   const Double_t pt_low=0.2,
                   const Double_t pt_high=0.5,
                   const Double_t eta_low=2.25,
                   const Double_t eta_high=4.45,
                   const Double_t vzlow = -50.0,
                   const Double_t vzhigh = 50.0,
                   const Int_t pid=8,
                   const Double_t mult=1,
                   const std::vector<Int_t> triggers = 0,
                   const Char_t *prodName = "P08iepp",
                   const Char_t* type = "FlatPt") {
    // production chains for P08ic - p+p, Au+Au 9 GeV and d+Au
    TString prodP08iepp("DbV20081117 B2008a ITTF IAna ppOpt l3onl emcDY2 fpd ftpc trgd ZDCvtx NosvtIT NossdIT Corr4 OSpaceZ2 OGridLeak3D VFMCE -hitfilt");
//  TString prodP08icpp("DbV20080712,pp2008,ITTF,OSpaceZ2,OGridLeak3D,beamLine,VFMCE,TpxClu -VFPPV -hitfilt");
//  TString prodP08icAuAu9("DbV20080709 P2008 ITTF VFMCE -hitfilt");
//  TString prodP08icAuAu200("DbV20070101 P2008 ITTF VFMCE -hitfilt");
//  TString prodP08icdAu("DbV20080712 P2008 ITTF OSpaceZ2 OGridLeak3D beamLine, VFMCE TpxClu -VFMinuit -hitfilt");
    TString prodP08iedAu("DbV20090213 P2008 ITTF OSpaceZ2 OGridLeak3D beamLine VFMCE TpxClu -VFMinuit -hitfilt");
    TString prodP10iapp("DbV20091001 pp2009c TpcRS ITTF OSpaceZ2 OGridLeak3D beamLine, VFMCE TpcRS -VFMinuit -hitfilt");
    TString geomP08ic("ry2008");
    TString chain1Opt("in,magF,tpcDb,NoDefault,TpxRaw,-ittf,NoOutput");
//  TString chain2Opt("NoInput,PrepEmbed,gen_T,geomT,sim_T,TpcRS,-ittf,-tpc_daq,nodefault");
    TString chain2Opt("NoInput,PrepEmbed,gen_T,geomT,sim_T,ftpcT,trs,fss,-ittf,-tpc_daq,nodefault");
    chain2Opt += " ";
    chain2Opt += geomP08ic;

    TString chain3Opt("");
    if (prodName == "P08icpp") {
        chain3Opt = prodP08icpp;
    }
    else if (prodName == "P08iepp") {
        chain3Opt = prodP08iepp;
    }
    else if (prodName == "P08icAuAu9") {
        chain3Opt = prodP08icAuAu9;
    }
    else if (prodName == "P08icdAu") {
        chain3Opt = prodP08icdAu;
    }
    else if (prodName == "P08iedAu") {
        chain3Opt = prodP08iedAu;
    }
    else if (prodName == "P08icAuAu200") {
        chain3Opt = prodP08icAuAu200;
    }
    else if (prodName == "P10iapp") {
        chain3opt = prodP10iapp;
    }
    else {
        cout << "Choice prodName does not correspond to known chain. Processing impossible. " << endl;
        return;
    }
    chain3Opt += ",Embedding,TpcMixer,GeantOut,MiniMcMk,McAna,-in,NoInput,useInTracker";
    chain3Opt += ",";
    chain3Opt += geomP08ic;
    // Dynamically link some shared libs
    gROOT->LoadMacro("bfc.C");
    if (gClassTable->GetID("StBFChain") < 0) Load();
    //______________Create the main chain object______________________________________
    Chain = new StChain("Embedding");
    //________________________________________________________________________________
    bfc(-1,chain1Opt,daqfile);
    chain1 = chain;
    chain1->SetName("One");
    Chain->cd();
    //________________________________________________________________________________
    bfc(-1,chain2Opt);
    chain2 = chain;
    chain2->SetName("Two");
    Chain->cd();
#if 1
    if (chain2->GetOption("TRS")) {
        StTrsMaker *trsMk = (StTrsMaker *) chain2->GetMaker("Trs");
        if (! trsMk) {
            cout << "Cannot find Trs in chain2" << endl;
            return;
        }
        trsMk->setNormalFactor(1.32);
        trsMk->SetMode(0);
    }
#endif
    //________________________________________________________________________________
    gSystem->Load("StFtpcMixerMaker");
    StFtpcMixerMaker  *ftpcmixer = new StFtpcMixerMaker("FtpcMixer","daq","fss");
    ftpcmixer->SetInput("Input1","StDAQReader");
    ftpcmixer->SetInput("Input2","Event");
    //________________________________________________________________________________
    TString OutputFileName(gSystem->BaseName(daqfile));
    OutputFileName.ReplaceAll("*","");
    OutputFileName.ReplaceAll(".daq","");
    //  OutputFileName.Append("_emb.root");
    OutputFileName.Append(".root");
    bfc(-1,chain3Opt,0,OutputFileName);
    chain3 = chain;
    chain3->SetName("Three");
    Chain->cd();
    //________________________________________________________________________________
    StTpcMixerMaker  *mixer = (StTpcMixerMaker *) chain3->Maker("TpcMixer");
    if( prodName == "P08icAuAu200")
    {
        mixer->SetInput("Input1","MixerEvent");
    }
    else
    {
        mixer->SetInput("Input1","TpxRaw/.data/Event");
    }
    mixer->SetInput("Input2","Trs/.const/Event");
    Chain->cd();

#if 0
//............. begin of EMC embedding makers................

    //.............. Add BEmc stuff here ....................
    gSystem->Load("StEmcSimulatorMaker");
    gSystem->Load("StEmcMixerMaker");
    gSystem->Load("StEEmcSimulatorMaker");

    StMcEventMaker* mcEventMaker = new StMcEventMaker();
    StEmcSimulatorMaker *bemcSim   = new StEmcSimulatorMaker();
    StEmcMixerMaker     *bemcMixer = new StEmcMixerMaker();
    chain3->AddAfter("emcRaw",bemcMixer);
    chain3->AddAfter("emcRaw",bemcSim);
    chain3->AddAfter("emcRaw",mcEventMaker);
    bemcMixer->SetDebug(0); // set it to 1 for more printouts
// note, Barrel slow sim is always ON, said Adam

    //........... Add EEmc Stuff ( Simu, and Mixer) here ..............
    StEEmcFastMaker  *eemcFastSim = new StEEmcFastMaker();
    StEEmcMixerMaker *eemcMixer   = new StEEmcMixerMaker();

    /* position B+E EMC makers in the chain
       (order is reverse because 'After' is used - looks funny but is right)
    */
    chain3->AddAfter("emcRaw",eemcMixer);
    chain3->AddAfter("emcRaw",eemcFastSim);

    eemcFastSim->SetEmbeddingMode();
    //  eemcFastSim->SetDebug();
    // eemcMixer->SetDebug();

    bool useEndcapSlowSim = true;
    if(useEndcapSlowSim) { // turn Endcap slow simu On/Off
        StEEmcSlowMaker *slowSim=new StEEmcSlowMaker();
        chain3->AddAfter("EEmcFastSim",slowSim);
        slowSim->setEmbeddingMode();
    }
#endif


    //________________________________________________________________________________
    {
        TDatime t;
        gMessMgr->QAInfo() << Form("Run is started at Date/Time %i/%i",t.GetDate(),t.GetTime()) << endm;
    }
    gMessMgr->QAInfo() << Form("Run on %s in %s",gSystem->HostName(),gSystem->WorkingDirectory()) << endm;
    gMessMgr->QAInfo() << Form("with %s", Chain->GetCVS()) << endm;
    // embedded particle set
    StPrepEmbedMaker *embMk = (StPrepEmbedMaker *) Chain->Maker("PrepEmbed");
    if (! embMk) return;
    cout << "bfcMixer: Setting PID: "<<pid<<endl;
    embMk->SetTagFile(tagfile);
    //            pTlow,ptHigh,etaLow,etaHigh,phiLow,phiHigh
    embMk->SetOpt(  pt_low,    pt_high,  eta_low,    eta_high,    0.,   6.283185, type);
    //                pid, mult
    embMk->SetPartOpt(  pid,mult);

    // Default is no event selections
    embMk->SetSkipMode(kTRUE);

    // Make trigger and z-vertex cuts (only if SkipMode is true)
    // Trigger cut
    //   Can put multiple trigger id's
    if ( !triggers.empty() ) {
        for(std::vector<Int_t>::iterator iter = triggers.begin(); iter != triggers.end(); iter++) {
            embMk->SetTrgOpt((*iter)) ;
        }
    }

    // z-vertex cuts
    embMk->SetZVertexCut(vzlow, vzhigh) ;

    TAttr::SetDebug(0);
    Chain->SetAttr(".Privilege",0,"*"                ); 	//All  makers are NOT priviliged
    Chain->SetAttr(".Privilege",1,"StBFChain::*" ); 	//StBFChain is priviliged
    Chain->SetAttr(".Privilege",1,"StIOInterFace::*" ); 	//All IO makers are priviliged
    Chain->SetAttr(".Privilege",1,"St_geant_Maker::*"); 	//It is also IO maker
    Chain->SetAttr(".Privilege",1,"StPrepEmbedMaker::*"); //It is also IO maker
    //  Chain->SetDEBUG(0);
    if (Nevents < 0) return;
    Int_t iInit = Chain->Init();
    if (iInit >=  kStEOF) {
        Chain->FatalErr(iInit,"on init");
        return;
    }
    StMaker *treeMk = Chain->GetMaker("outputStream");
    Chain->EventLoop(Nevents,treeMk);
    gMessMgr->QAInfo() << "Run completed " << endm;
    gSystem->Exec("date");
}
Exemple #10
0
void RAA_plot_HFVs_effect(){
  
  TStopwatch timer;
  timer.Start();

  TDatime date;

  gStyle->SetOptStat(0);

  TH1::SetDefaultSumw2();
  TH2::SetDefaultSumw2();

  
  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};
  
  TFile *fin = TFile::Open("/Users/raghavke/WORK/RAA/Output/PbPb_HF_divergence_events_spectra_VsPF_20141207.root");
  
  TH1F *hpbpb_Jet80[2][2][nbins_cent+1];
  TH1F *hpbpb_Jet65[2][2][nbins_cent+1];
  TH1F *hpbpb_Jet55[2][2][nbins_cent+1];
  TH1F *hpbpb_JetComb[2][2][nbins_cent+1];  

  TH1F *hpbpb_FullJet80[nbins_cent+1];
  TH1F *hpbpb_FullJet65[nbins_cent+1];
  TH1F *hpbpb_FullJet55[nbins_cent+1];
  TH1F *hpbpb_FullJetComb[nbins_cent+1];

  //Get the ratio histograms w.r.t the full spectra. 
  TH1F *hpbpb_Jet80_Ratio[2][2][nbins_cent+1];
  TH1F *hpbpb_Jet65_Ratio[2][2][nbins_cent+1];
  TH1F *hpbpb_Jet55_Ratio[2][2][nbins_cent+1];

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

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

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

	hpbpb_Jet80[b][a][i] = (TH1F*)fin->Get(Form("hpbpb_Jet80_isDiverge_%d_isTightCut_%d_cent%d",b,a,i));
	hpbpb_Jet80[b][a][i] = (TH1F*)hpbpb_Jet80[b][a][i]->Rebin(nbins_pt,Form("hpbpb_Jet80_isDiverge_%d_isTightCut_%d_cent%d",b,a,i),boundaries_pt);
	divideBinWidth(hpbpb_Jet80[b][a][i]);
	hpbpb_Jet65[b][a][i] = (TH1F*)fin->Get(Form("hpbpb_Jet65_isDiverge_%d_isTightCut_%d_cent%d",b,a,i));
	hpbpb_Jet65[b][a][i] = (TH1F*)hpbpb_Jet65[b][a][i]->Rebin(nbins_pt,Form("hpbpb_Jet65_isDiverge_%d_isTightCut_%d_cent%d",b,a,i),boundaries_pt);
	divideBinWidth(hpbpb_Jet65[b][a][i]);
	hpbpb_Jet55[b][a][i] = (TH1F*)fin->Get(Form("hpbpb_Jet55_isDiverge_%d_isTightCut_%d_cent%d",b,a,i));
	hpbpb_Jet55[b][a][i] = (TH1F*)hpbpb_Jet55[b][a][i]->Rebin(nbins_pt,Form("hpbpb_Jet55_isDiverge_%d_isTightCut_%d_cent%d",b,a,i),boundaries_pt);
	divideBinWidth(hpbpb_Jet55[b][a][i]);

      }

    }

    hpbpb_FullJet80[i] = (TH1F*)fin->Get(Form("hpbpb_Jet80_cent%d",i));
    hpbpb_FullJet80[i] = (TH1F*)hpbpb_FullJet80[i]->Rebin(nbins_pt,Form("hpbpb_Jet80_cent%d",i),boundaries_pt);
    divideBinWidth(hpbpb_FullJet80[i]);
    hpbpb_FullJet65[i] = (TH1F*)fin->Get(Form("hpbpb_Jet65_cent%d",i));
    hpbpb_FullJet65[i] = (TH1F*)hpbpb_FullJet65[i]->Rebin(nbins_pt,Form("hpbpb_Jet65_cent%d",i),boundaries_pt);
    divideBinWidth(hpbpb_FullJet65[i]);
    hpbpb_FullJet55[i] = (TH1F*)fin->Get(Form("hpbpb_Jet55_cent%d",i));
    hpbpb_FullJet55[i] = (TH1F*)hpbpb_FullJet55[i]->Rebin(nbins_pt,Form("hpbpb_Jet55_cent%d",i),boundaries_pt);
    divideBinWidth(hpbpb_FullJet55[i]);

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

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

	hpbpb_Jet80_Ratio[b][a][i] = (TH1F*)hpbpb_Jet80[b][a][i]->Clone(Form("hpbpb_Jet80_isDiverge_%d_isTightCut_%d_cent%d_Ratio_with_fullSpectra_Jet80",b,a,i));
	hpbpb_Jet80_Ratio[b][a][i]->Divide(hpbpb_FullJet80[i]);
	hpbpb_Jet65_Ratio[b][a][i] = (TH1F*)hpbpb_Jet65[b][a][i]->Clone(Form("hpbpb_Jet65_isDiverge_%d_isTightCut_%d_cent%d_Ratio_with_fullSpectra_Jet65",b,a,i));
	hpbpb_Jet65_Ratio[b][a][i]->Divide(hpbpb_FullJet65[i]);
	hpbpb_Jet55_Ratio[b][a][i] = (TH1F*)hpbpb_Jet55[b][a][i]->Clone(Form("hpbpb_Jet80_isDiverge_%d_isTightCut_%d_cent%d_Ratio_with_fullSpectra_Jet55",b,a,i));
	hpbpb_Jet55_Ratio[b][a][i]->Divide(hpbpb_FullJet55[i]);
      }

    }
    
  }// cent bin
  
  // Lets start making the plots. These plots will all be a 3x3 panel plot for the different centrality bins. 
  // plots 1,2 and 3 - show the spectra for isdiverge 1 and with and without tight cut for each Jet80 and Jet65 and Jet55 in each centrality  
  // plots 4,5 and 6 - similarly show the ratio histogram for each Jet80 and Jet65 and Jet55 in each centrailty. 

  // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  // plot 1 - is diverge with and without tight cuts plus the whole events list. 

  TCanvas *cJet80_Spectra = new TCanvas("cJet80_Spectra","",800,600);
  makeMultiPanelCanvas(cJet80_Spectra,3,2,0.0,0.0,0.2,0.15,0.07);

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

    cJet80_Spectra->cd(nbins_cent-i);
    cJet80_Spectra->cd(nbins_cent-i)->SetLogy();
    
    hpbpb_FullJet80[i]->SetMarkerStyle(24);
    hpbpb_FullJet80[i]->SetMarkerColor(kBlack);
    hpbpb_FullJet80[i]->SetTitle(" ");
    hpbpb_FullJet80[i]->SetXTitle("Jet p_{T} (GeV/c)");
    hpbpb_FullJet80[i]->SetYTitle("#frac{dN}{dp_{T}}");
    hpbpb_FullJet80[i]->SetAxisRange(0,500,"X");
    hpbpb_FullJet80[i]->Draw();

    hpbpb_Jet80[1][0][i]->SetMarkerStyle(25);
    hpbpb_Jet80[1][0][i]->SetMarkerColor(kRed);
    hpbpb_Jet80[1][0][i]->Draw("same");

    hpbpb_Jet80[1][1][i]->SetMarkerStyle(33);
    hpbpb_Jet80[1][1][i]->SetMarkerColor(kBlue);
    hpbpb_Jet80[1][1][i]->Draw("same");
    
    drawText(Form("%2.0f-%2.0f%%",2.5*boundaries_cent[i],2.5*boundaries_cent[i+1]),0.7,0.85,20);

  }

  cJet80_Spectra->cd(1);
  putCMSPrel();

  TLegend *Jet80_spectra = myLegend(0.5,0.55,0.9,0.8);
  Jet80_spectra->AddEntry(hpbpb_FullJet80[0],"Full Spectra","pl");
  Jet80_spectra->AddEntry(hpbpb_Jet80[1][0][0],"Diverging with Loose Cut","pl");
  Jet80_spectra->AddEntry(hpbpb_Jet80[1][1][0],"Diverging with Tight Cut","pl");
  Jet80_spectra->SetTextSize(0.04);
  Jet80_spectra->Draw();
  
  drawText("Jet80 Trigger",0.5,0.4,14);
  
  cJet80_Spectra->cd(2);
  drawText("pCES,HBHE,|vz|<15",0.2,0.8,14);
  
  cJet80_Spectra->cd(3);
  drawText("supernova diagonal cut",0.2,0.8,14);
  
  cJet80_Spectra->SaveAs(Form("/Users/raghavke/WORK/RAA/Plots/HFVS_RAA_Effect_Jet80_spectra_%d.pdf",date.GetDate()),"RECREATE");
  
  // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  // plot 2 - is diverge with and without tight cuts plus the whole events list - Jet65

  TCanvas *cJet65_Spectra = new TCanvas("cJet65_Spectra","",800,600);
  makeMultiPanelCanvas(cJet65_Spectra,3,2,0.0,0.0,0.2,0.15,0.07);

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

    cJet65_Spectra->cd(nbins_cent-i);
    cJet65_Spectra->cd(nbins_cent-i)->SetLogy();
    
    hpbpb_FullJet65[i]->SetMarkerStyle(24);
    hpbpb_FullJet65[i]->SetMarkerColor(kBlack);
    hpbpb_FullJet65[i]->SetTitle(" ");
    hpbpb_FullJet65[i]->SetXTitle("Jet p_{T} (GeV/c)");
    hpbpb_FullJet65[i]->SetYTitle("#frac{dN}{dp_{T}}");
    hpbpb_FullJet65[i]->SetAxisRange(0,500,"X");
    hpbpb_FullJet65[i]->Draw();
    
    hpbpb_Jet65[1][0][i]->SetMarkerStyle(25);
    hpbpb_Jet65[1][0][i]->SetMarkerColor(kRed);
    hpbpb_Jet65[1][0][i]->Draw("same");
    
    hpbpb_Jet65[1][1][i]->SetMarkerStyle(33);
    hpbpb_Jet65[1][1][i]->SetMarkerColor(kBlue);
    hpbpb_Jet65[1][1][i]->Draw("same");
    
    drawText(Form("%2.0f-%2.0f%%",2.5*boundaries_cent[i],2.5*boundaries_cent[i+1]),0.7,0.85,20);
    
  }

  cJet65_Spectra->cd(1);
  putCMSPrel();

  TLegend *Jet65_spectra = myLegend(0.5,0.55,0.9,0.8);
  Jet65_spectra->AddEntry(hpbpb_FullJet65[0],"Full Spectra","pl");
  Jet65_spectra->AddEntry(hpbpb_Jet65[1][0][0],"Diverging with Loose Cut","pl");
  Jet65_spectra->AddEntry(hpbpb_Jet65[1][1][0],"Diverging with Tight Cut","pl");
  Jet65_spectra->SetTextSize(0.04);
  Jet65_spectra->Draw();
  
  drawText("Jet65 Trigger",0.5,0.4,14);
  
  cJet65_Spectra->cd(2);
  drawText("pCES,HBHE,|vz|<15",0.2,0.8,14);
  
  cJet65_Spectra->cd(3);
  drawText("supernova diagonal cut",0.2,0.8,14);
  
  cJet65_Spectra->SaveAs(Form("/Users/raghavke/WORK/RAA/Plots/HFVS_RAA_Effect_Jet65_spectra_%d.pdf",date.GetDate()),"RECREATE");
  // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  // plot 3 - is diverge with and without tight cuts plus the whole events list - Jet65

  TCanvas *cJet55_Spectra = new TCanvas("cJet55_Spectra","",800,600);
  makeMultiPanelCanvas(cJet55_Spectra,3,2,0.0,0.0,0.2,0.15,0.07);

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

    cJet55_Spectra->cd(nbins_cent-i);
    cJet55_Spectra->cd(nbins_cent-i)->SetLogy();
    
    hpbpb_FullJet55[i]->SetMarkerStyle(24);
    hpbpb_FullJet55[i]->SetMarkerColor(kBlack);
    hpbpb_FullJet55[i]->SetTitle(" ");
    hpbpb_FullJet55[i]->SetXTitle("Jet p_{T} (GeV/c)");
    hpbpb_FullJet55[i]->SetYTitle("#frac{dN}{dp_{T}}");
    hpbpb_FullJet55[i]->SetAxisRange(0,500,"X");
    hpbpb_FullJet55[i]->Draw();
    
    hpbpb_Jet55[1][0][i]->SetMarkerStyle(25);
    hpbpb_Jet55[1][0][i]->SetMarkerColor(kRed);
    hpbpb_Jet55[1][0][i]->Draw("same");
    
    hpbpb_Jet55[1][1][i]->SetMarkerStyle(33);
    hpbpb_Jet55[1][1][i]->SetMarkerColor(kBlue);
    hpbpb_Jet55[1][1][i]->Draw("same");
    
    drawText(Form("%2.0f-%2.0f%%",2.5*boundaries_cent[i],2.5*boundaries_cent[i+1]),0.7,0.85,20);
    
  }

  cJet55_Spectra->cd(1);
  putCMSPrel();

  TLegend *Jet55_spectra = myLegend(0.5,0.55,0.9,0.8);
  Jet55_spectra->AddEntry(hpbpb_FullJet55[0],"Full Spectra","pl");
  Jet55_spectra->AddEntry(hpbpb_Jet55[1][0][0],"Diverging with Loose Cut","pl");
  Jet55_spectra->AddEntry(hpbpb_Jet55[1][1][0],"Diverging with Tight Cut","pl");
  Jet55_spectra->SetTextSize(0.04);
  Jet55_spectra->Draw();
  
  drawText("Jet55 Trigger",0.5,0.4,14);
  
  cJet55_Spectra->cd(2);
  drawText("pCES,HBHE,|vz|<15",0.2,0.8,14);
  
  cJet55_Spectra->cd(3);
  drawText("supernova diagonal cut",0.2,0.8,14);
  
  cJet55_Spectra->SaveAs(Form("/Users/raghavke/WORK/RAA/Plots/HFVS_RAA_Effect_Jet55_spectra_%d.pdf",date.GetDate()),"RECREATE");

  // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  // plot 4 - Ratio plot: is diverge with and without tight cuts plus the whole events list - Jet65

  TCanvas *cJet80_Ratio = new TCanvas("cJet80_Ratio","",800,600);
  makeMultiPanelCanvas(cJet80_Ratio,3,2,0.0,0.0,0.2,0.15,0.07);

  TLine *line80 = new TLine(0,1,500,1);
  line80->SetLineStyle(2);
  line80->SetLineWidth(2);

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

    cJet80_Ratio->cd(nbins_cent-i);
    //cJet80_Ratio->cd(nbins_cent-i)->SetLogy();
    
    hpbpb_Jet80_Ratio[1][0][i]->SetMarkerStyle(25);
    hpbpb_Jet80_Ratio[1][0][i]->SetMarkerColor(kRed);
    hpbpb_Jet80_Ratio[1][0][i]->SetXTitle("Jet p_{T} (GeV/c)");
    hpbpb_Jet80_Ratio[1][0][i]->SetYTitle("Ratio with full spectra");
    hpbpb_Jet80_Ratio[1][0][i]->SetTitle(" ");
    hpbpb_Jet80_Ratio[1][0][i]->SetAxisRange(0,500,"X");
    hpbpb_Jet80_Ratio[1][0][i]->SetAxisRange(0,1,"Y");
    hpbpb_Jet80_Ratio[1][0][i]->Draw("same");
    
    hpbpb_Jet80_Ratio[1][1][i]->SetMarkerStyle(33);
    hpbpb_Jet80_Ratio[1][1][i]->SetMarkerColor(kBlue);
    hpbpb_Jet80_Ratio[1][1][i]->Draw("same");
 
    drawText(Form("%2.0f-%2.0f%%",2.5*boundaries_cent[i],2.5*boundaries_cent[i+1]),0.7,0.85,20);
    
    line80->Draw();
  }

  cJet80_Ratio->cd(1);
  putCMSPrel();

  TLegend *Jet80_ratio = myLegend(0.5,0.55,0.9,0.8);
  Jet80_ratio->AddEntry(hpbpb_Jet80[1][0][0],"Diverging with Loose Cut","pl");
  Jet80_ratio->AddEntry(hpbpb_Jet80[1][1][0],"Diverging with Tight Cut","pl");
  Jet80_ratio->SetTextSize(0.04);
  Jet80_ratio->Draw();
  
  drawText("Jet80 Trigger",0.5,0.4,14);
  
  cJet80_Ratio->cd(2);
  drawText("pCES,HBHE,|vz|<15",0.2,0.8,14);
  drawText("Ratio plots with full spectra",0.15,0.7,14);
  
  cJet80_Ratio->cd(3);
  drawText("supernova diagonal cut",0.2,0.8,14);
  
  cJet80_Ratio->SaveAs(Form("/Users/raghavke/WORK/RAA/Plots/HFVS_RAA_Effect_Jet80_ratio_%d.pdf",date.GetDate()),"RECREATE");
  
  // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  // plot 5 - Ratio plot: is diverge with and without tight cuts plus the whole events list - Jet65

  TCanvas *cJet65_Ratio = new TCanvas("cJet65_Ratio","",800,600);
  makeMultiPanelCanvas(cJet65_Ratio,3,2,0.0,0.0,0.2,0.15,0.07);

  TLine *line65 = new TLine(0,1,500,1);
  line65->SetLineStyle(2);
  line65->SetLineWidth(2);

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

    cJet65_Ratio->cd(nbins_cent-i);
    //cJet65_Ratio->cd(nbins_cent-i)->SetLogy();
    
    hpbpb_Jet65_Ratio[1][0][i]->SetMarkerStyle(25);
    hpbpb_Jet65_Ratio[1][0][i]->SetMarkerColor(kRed);
    hpbpb_Jet65_Ratio[1][0][i]->SetXTitle("Jet p_{T} (GeV/c)");
    hpbpb_Jet65_Ratio[1][0][i]->SetYTitle("Ratio with full spectra");
    hpbpb_Jet65_Ratio[1][0][i]->SetTitle(" ");
    hpbpb_Jet65_Ratio[1][0][i]->SetAxisRange(0,500,"X");
    hpbpb_Jet65_Ratio[1][0][i]->SetAxisRange(0,1,"Y");
    hpbpb_Jet65_Ratio[1][0][i]->Draw("same");
    
    hpbpb_Jet65_Ratio[1][1][i]->SetMarkerStyle(33);
    hpbpb_Jet65_Ratio[1][1][i]->SetMarkerColor(kBlue);
    hpbpb_Jet65_Ratio[1][1][i]->Draw("same");
 
    drawText(Form("%2.0f-%2.0f%%",2.5*boundaries_cent[i],2.5*boundaries_cent[i+1]),0.7,0.85,20);
    
    line65->Draw();
  }

  cJet65_Ratio->cd(1);
  putCMSPrel();

  TLegend *Jet65_ratio = myLegend(0.5,0.55,0.9,0.8);
  Jet65_ratio->AddEntry(hpbpb_Jet65[1][0][0],"Diverging with Loose Cut","pl");
  Jet65_ratio->AddEntry(hpbpb_Jet65[1][1][0],"Diverging with Tight Cut","pl");
  Jet65_ratio->SetTextSize(0.04);
  Jet65_ratio->Draw();
  
  drawText("Jet65 Trigger",0.5,0.4,14);
  
  cJet65_Ratio->cd(2);
  drawText("pCES,HBHE,|vz|<15",0.2,0.8,14);
  drawText("Ratio plots with full spectra",0.15,0.7,14);
  
  cJet65_Ratio->cd(3);
  drawText("supernova diagonal cut",0.2,0.8,14);
  
  cJet65_Ratio->SaveAs(Form("/Users/raghavke/WORK/RAA/Plots/HFVS_RAA_Effect_Jet65_ratio_%d.pdf",date.GetDate()),"RECREATE");


  // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  // plot 6 - Ratio plot: is diverge with and without tight cuts plus the whole events list - Jet55

  TCanvas *cJet55_Ratio = new TCanvas("cJet55_Ratio","",800,600);
  makeMultiPanelCanvas(cJet55_Ratio,3,2,0.0,0.0,0.2,0.15,0.07);

  TLine *line55 = new TLine(0,1,500,1);
  line55->SetLineStyle(2);
  line55->SetLineWidth(2);

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

    cJet55_Ratio->cd(nbins_cent-i);
    //cJet55_Ratio->cd(nbins_cent-i)->SetLogy();
    
    hpbpb_Jet55_Ratio[1][0][i]->SetMarkerStyle(25);
    hpbpb_Jet55_Ratio[1][0][i]->SetMarkerColor(kRed);
    hpbpb_Jet55_Ratio[1][0][i]->SetXTitle("Jet p_{T} (GeV/c)");
    hpbpb_Jet55_Ratio[1][0][i]->SetYTitle("Ratio with full spectra");
    hpbpb_Jet55_Ratio[1][0][i]->SetTitle(" ");
    hpbpb_Jet55_Ratio[1][0][i]->SetAxisRange(0,500,"X");
    hpbpb_Jet55_Ratio[1][0][i]->SetAxisRange(0,1.1,"Y");
    hpbpb_Jet55_Ratio[1][0][i]->Draw("same");
    
    hpbpb_Jet55_Ratio[1][1][i]->SetMarkerStyle(33);
    hpbpb_Jet55_Ratio[1][1][i]->SetMarkerColor(kBlue);
    hpbpb_Jet55_Ratio[1][1][i]->Draw("same");
 
    drawText(Form("%2.0f-%2.0f%%",2.5*boundaries_cent[i],2.5*boundaries_cent[i+1]),0.7,0.85,20);
    
    line55->Draw();
  }

  cJet55_Ratio->cd(1);
  putCMSPrel();

  TLegend *Jet55_ratio = myLegend(0.5,0.55,0.9,0.8);
  Jet55_ratio->AddEntry(hpbpb_Jet55[1][0][0],"Diverging with Loose Cut","pl");
  Jet55_ratio->AddEntry(hpbpb_Jet55[1][1][0],"Diverging with Tight Cut","pl");
  Jet55_ratio->SetTextSize(0.04);
  Jet55_ratio->Draw();
  
  drawText("Jet55 Trigger",0.5,0.4,14);
  
  cJet55_Ratio->cd(2);
  drawText("pCES,HBHE,|vz|<15",0.2,0.8,14);
  drawText("Ratio plots with full spectra",0.15,0.7,14);
  
  cJet55_Ratio->cd(3);
  drawText("supernova diagonal cut",0.2,0.8,14);
  
  cJet55_Ratio->SaveAs(Form("/Users/raghavke/WORK/RAA/Plots/HFVS_RAA_Effect_Jet55_ratio_%d.pdf",date.GetDate()),"RECREATE");

  // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  

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


}// macro main
Exemple #11
0
void RAA_plot_finalpaper(bool isATLASCut = true){
    
  TStopwatch timer;
  timer.Start();

  TDatime date;

  gStyle->SetOptStat(0);

  TH1::SetDefaultSumw2();
  TH2::SetDefaultSumw2();

  char * etaLable = (char*) "0.0 < |#eta| < 2.0";
  char * trkMaxCut = (char*)"_";
  if(isATLASCut) trkMaxCut = (char*)"_trkMax7OrNeMax8GeVCut_";
  char * outLocation = (char*) "July20/";
  if(isATLASCut) outLocation = "July20/ATLASCut/";
  
  Float_t etaLow = 0;
  Float_t etaHigh = 2.0;
  
  TFile *fin_R2, *fin_R3, *fin_R4; 
  fin_R2 = TFile::Open(Form("July20/HiForest_JetComb_JetRAA_%disATLASCut_R0p2_MCCloSameSide_1trigcorAfterUnfo_SevilFakeMBnoLJSbJCut_RecopTCut50GeV_matrixRecoCut_%d.root", isATLASCut, date.GetDate()));
  fin_R3 = TFile::Open(Form("July20/HiForest_JetComb_JetRAA_%disATLASCut_R0p3_MCCloSameSide_1trigcorAfterUnfo_SevilFakeMBnoLJSbJCut_RecopTCut50GeV_matrixRecoCut_%d.root", isATLASCut, date.GetDate()));
  fin_R4 = TFile::Open(Form("July20/HiForest_JetComb_JetRAA_%disATLASCut_R0p4_MCCloSameSide_1trigcorAfterUnfo_SevilFakeMBnoLJSbJCut_RecopTCut50GeV_matrixRecoCut_%d.root", isATLASCut, date.GetDate()));
  
  // get the histograms.
  TH1F * uPbPb_R2_Bayes[nbins_cent], * uPP_R2_Bayes, * uPbPb_R3_Bayes[nbins_cent], * uPP_R3_Bayes, * uPbPb_R4_Bayes[nbins_cent], * uPP_R4_Bayes;
  TH1F * mPbPb_R2[nbins_cent], * mPP_R2, * mPbPb_R3[nbins_cent], * mPP_R3, * mPbPb_R4[nbins_cent], * mPP_R4;
  
  TH1F * RAA_R2_Bayes[nbins_cent], * RAA_R3_Bayes[nbins_cent], * RAA_R4_Bayes[nbins_cent];
  TH1F * RAA_R2_BinByBin[nbins_cent], * RAA_R3_BinByBin[nbins_cent], * RAA_R4_BinByBin[nbins_cent];
  TH1F * RAA_R2_Meas[nbins_cent], * RAA_R3_Meas[nbins_cent], * RAA_R4_Meas[nbins_cent];

  uPP_R2_Bayes = (TH1F*)fin_R2->Get("PP_bayesian_unfolded_spectra");
  uPP_R2_Bayes->Print("base");
  uPP_R3_Bayes = (TH1F*)fin_R3->Get("PP_bayesian_unfolded_spectra");
  uPP_R3_Bayes->Print("base");
  uPP_R4_Bayes = (TH1F*)fin_R4->Get("PP_bayesian_unfolded_spectra");
  uPP_R4_Bayes->Print("base");

  mPP_R2 = (TH1F*)fin_R2->Get("PP_Gen_spectra_refpt");
  mPP_R2->Print("base");
  mPP_R3 = (TH1F*)fin_R3->Get("PP_Gen_spectra_refpt");
  mPP_R3->Print("base");
  mPP_R4 = (TH1F*)fin_R4->Get("PP_Gen_spectra_refpt");
  mPP_R4->Print("base");
  
  for(int i = 0; i<nbins_cent; ++i){

    uPbPb_R2_Bayes[i] = (TH1F*)fin_R2->Get(Form("PbPb_bayesian_unfolded_spectra_combined_cent%d",i));
    uPbPb_R2_Bayes[i]->Print("base");
    uPbPb_R3_Bayes[i] = (TH1F*)fin_R3->Get(Form("PbPb_bayesian_unfolded_spectra_combined_cent%d",i));
    uPbPb_R3_Bayes[i]->Print("base");
    uPbPb_R4_Bayes[i] = (TH1F*)fin_R4->Get(Form("PbPb_bayesian_unfolded_spectra_combined_cent%d",i));
    uPbPb_R3_Bayes[i]->Print("base");
 
    mPbPb_R2[i] = (TH1F*)fin_R2->Get(Form("PbPb_Gen_spectra_refpt_cent%d",i));
    mPbPb_R2[i]->Print("base");
    mPbPb_R3[i] = (TH1F*)fin_R3->Get(Form("PbPb_Gen_spectra_refpt_cent%d",i));
    mPbPb_R3[i]->Print("base");
    mPbPb_R4[i] = (TH1F*)fin_R4->Get(Form("PbPb_Gen_spectra_refpt_cent%d",i));
    mPbPb_R4[i]->Print("base");
    
    RAA_R2_Bayes[i]   = (TH1F*)fin_R2->Get(Form("RAA_bayesian_cent%d",i));  
    RAA_R2_Bayes[i]->Print("base");
    RAA_R3_Bayes[i]   = (TH1F*)fin_R3->Get(Form("RAA_bayesian_cent%d",i));  
    RAA_R3_Bayes[i]->Print("base");
    RAA_R4_Bayes[i]   = (TH1F*)fin_R4->Get(Form("RAA_bayesian_cent%d",i));  
    RAA_R4_Bayes[i]->Print("base");
    
    RAA_R2_BinByBin[i]   = (TH1F*)fin_R2->Get(Form("RAA_binbybin_cent%d",i));  
    RAA_R3_BinByBin[i]   = (TH1F*)fin_R3->Get(Form("RAA_binbybin_cent%d",i));  
    RAA_R4_BinByBin[i]   = (TH1F*)fin_R4->Get(Form("RAA_binbybin_cent%d",i));  
    
    RAA_R2_Meas[i]   = (TH1F*)fin_R2->Get(Form("RAA_measured_cent%d",i));  
    RAA_R3_Meas[i]   = (TH1F*)fin_R3->Get(Form("RAA_measured_cent%d",i));  
    RAA_R4_Meas[i]   = (TH1F*)fin_R4->Get(Form("RAA_measured_cent%d",i));  
    
  }
  
  // plot 1 - spectra plot showing pp and 6 different centrality classes PbPb spectra
  //        - have a 3 panel plot for the different radii, with each of them scaled by two orders of magnitude 

  // first we need to scale the MC to the level of Data:
  // PbPb Data scaling:
  //   uPbPb_Bayes[i]->Scale(1./deltaEta);// delta eta
  //   //uPbPb_Bayes[i]->Scale(1./145.156/1e6);// Jet 80 luminosity
  //   //uPbPb_Bayes[i]->Scale(1./1.1153/1e6);// equivalent no of minbias events 
  //   uPbPb_Bayes[i]->Scale(1./(0.025*(boundaries_cent[i+1] - boundaries_cent[i])));
  //   //uPbPb_Bayes[i]->Scale(1./145.156);
  //   //uPbPb_Bayes[i]->Scale(1./161.939);
  //   uPbPb_Bayes[i]->Scale(1./(7.65*1e6));
  //   uPbPb_Bayes[i]->Scale(64.*1e9/(ncoll[i]*1e3));
  //   uPbPb_Bayes[i] = (TH1F*)uPbPb_Bayes[i]->Rebin(nbins_pt,Form("PbPb_bayesian_unfolded_spectra_combined_cent%d",i),boundaries_pt);
  //   divideBinWidth(uPbPb_Bayes[i]);
  //   uPbPb_Bayes[i]->Write();
  //   So finally PbPb is in 

  // PbPb MC scaling: is already in sigma (mb) / (dEta dpT)
  //   mPbPb_Reco[i]->Scale(1./deltaEta);// delta eta
  //   mPbPb_Reco[i] = (TH1F*)mPbPb_Reco[i]->Rebin(nbins_pt,Form("PbPb_Reco_spectra_refpt_cent%d",i),boundaries_pt);
  //   divideBinWidth(mPbPb_Reco[i]);
  //   mPbPb_Reco[i]->Write();

  // take MC to nano barns from milli barns 
  //mPP_R2->Scale(1e6);
  //mPP_R3->Scale(1e6);
  //mPP_R4->Scale(1e6);

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

  //   mPbPb_R2[i]->Scale(1./(0.025*(boundaries_cent[i+1] - boundaries_cent[i])));
  //   mPbPb_R2[i]->Scale(64.*1e9/(ncoll[i]*1e3));
  //   mPbPb_R2[i]->Scale(1./(7.65));

  //   mPbPb_R3[i]->Scale(1./(0.025*(boundaries_cent[i+1] - boundaries_cent[i])));
  //   mPbPb_R3[i]->Scale(64.*1e9/(ncoll[i]*1e3));
  //   mPbPb_R3[i]->Scale(1./(7.65));

  //   mPbPb_R4[i]->Scale(1./(0.025*(boundaries_cent[i+1] - boundaries_cent[i])));
  //   mPbPb_R4[i]->Scale(64.*1e9/(ncoll[i]*1e3));
  //   mPbPb_R4[i]->Scale(1./(7.65));
  
  // }
  
  Double_t ScaleFactor[nbins_cent+2] = {1, 1e2, 1e4, 1e6, 1e8, 1e10, 1e12, 1e14};  
  
  TCanvas * cSpectra_R2 = new TCanvas("cSpectra_R2","",1200,1000);
  //makeMultiPanelCanvas(cSpectra_R2,3,1,0.0,0.0,0.2,0.15,0.07);
  cSpectra_R2->SetLogy();
  //cSpectra_R2->SetGridy();
  cSpectra_R2->SetLogx();

  uPP_R2_Bayes->Scale(ScaleFactor[0]);
  uPP_R2_Bayes->SetMarkerStyle(20);
  uPP_R2_Bayes->SetMarkerColor(kBlack);
  makeHistTitle(uPP_R2_Bayes," "," Jet p_{T} (GeV/c)","#frac{d#sigma}{dp_{T} d#eta}(nb)                       #frac{d N}{T_{AA} dp_{T} d#eta} (nb)");
  uPP_R2_Bayes->SetAxisRange(60, 299, "X");
  uPP_R2_Bayes->SetAxisRange(1e-4, 1e14, "Y");
  uPP_R2_Bayes->GetYaxis()->SetMoreLogLabels(kFALSE);
  uPP_R2_Bayes->Draw();

  // draw the MC
  mPP_R2->Scale(ScaleFactor[0]);
  mPP_R2->SetLineColor(kBlack);
  mPP_R2->SetAxisRange(64, 299, "X");
  //mPP_R2->Draw("same Lhist");
  
  for(int i = 0; i<nbins_cent; ++i){
    for(int j = 0; j<uPbPb_R2_Bayes[i]->GetNbinsX(); ++j)
      uPbPb_R2_Bayes[i]->SetBinError(j+1, uPbPb_R2_Bayes[i]->GetBinError(j+1)/ScaleFactor[i+1]);
    
    uPbPb_R2_Bayes[i]->Scale(ScaleFactor[i+1]);
    uPbPb_R2_Bayes[i]->SetMarkerStyle(33);
    uPbPb_R2_Bayes[i]->SetMarkerColor(kRed);
    uPbPb_R2_Bayes[i]->SetAxisRange(60, 299, "X");
    uPbPb_R2_Bayes[i]->Draw("same");

    // mPbPb_R2[i]->Scale(ScaleFactor[i+2]);
    // mPbPb_R2[i]->SetLineColor(kRed);
    // mPbPb_R2[i]->SetAxisRange(unfoldingCut, 299, "X");
    // mPbPb_R2[i]->Draw("same Lhist");
  }

  TLegend * leg1_R2 = myLegend(0.25,0.2,0.35,0.3);
  leg1_R2->AddEntry(uPP_R2_Bayes,"PP Data","pl");
  //leg1_R2->AddEntry(mPP_R2,"PYTHIA","pl");
  leg1_R2->SetTextSize(0.02);
  leg1_R2->Draw();

  TLegend * leg2_R2 = myLegend(0.7,0.8,0.8,0.9);
  leg2_R2->AddEntry(uPbPb_R2_Bayes[0],"PbPb Data","pl");
  //leg2_R2->AddEntry(mPbPb_R2[0],"PYTHIA+HYDJET","pl");
  leg2_R2->SetTextSize(0.02);
  leg2_R2->Draw();
  
  drawText("R=0.2, anti k_{T} PF Jets", 0.25,0.2,16);
  drawText("R=0.2, anti k_{T} Pu PF Jets", 0.67,0.8,16);
  drawText(Form("%s", etaLable),0.4,0.23,16);

  putCMSPrel(0.25,0.94,0.025);
  putPbPbLumi(0.65,0.9,0.02);
  putPPLumi(0.25,0.3,0.02);
  
  //drawText("pp", 0.7,0.15,16);
  drawText("0-5% x 10^{2}", 0.7,0.28,16);
  drawText("5-10% x 10^{4}", 0.7,0.36,16);
  drawText("10-30% x 10^{6}", 0.7,0.46,16);
  drawText("30-50% x 10^{8}", 0.7,0.55,16);
  drawText("50-70% x 10^{10}", 0.7,0.64,16);
  drawText("70-90% x 10^{12}", 0.7,0.72,16);

  cSpectra_R2->SaveAs(Form("%sFinal_paper_plots_%disATLASCut_spectra_%s_akR2_%dGeVCut_%s_%d.pdf",outLocation, isATLASCut, ptbins, 50,  etaWidth,date.GetDate()),"RECREATE");

  
  TCanvas * cSpectra_R3 = new TCanvas("cSpectra_R3","",1200,1000);
  //makeMultiPanelCanvas(cSpectra_R3,3,1,0.0,0.0,0.2,0.15,0.07);
  cSpectra_R3->SetLogy();
  //cSpectra_R3->SetGridy();
  cSpectra_R3->SetLogx();

  uPP_R3_Bayes->Scale(ScaleFactor[0]);
  uPP_R3_Bayes->SetMarkerStyle(20);
  uPP_R3_Bayes->SetMarkerColor(kBlack);
  makeHistTitle(uPP_R3_Bayes," "," Jet p_{T} (GeV/c)","#frac{d#sigma}{dp_{T} d#eta}(nb)                       #frac{d N}{T_{AA} dp_{T} d#eta} (nb)");
  uPP_R3_Bayes->SetAxisRange(60, 299, "X");
  uPP_R3_Bayes->SetAxisRange(1e-4, 1e14, "Y");
  uPP_R3_Bayes->GetYaxis()->SetMoreLogLabels(kFALSE);
  uPP_R3_Bayes->Draw();

  // draw the MC
  mPP_R3->Scale(ScaleFactor[0]);
  mPP_R3->SetLineColor(kBlack);
  mPP_R3->SetAxisRange(64, 299, "X");
  //mPP_R3->Draw("same Lhist");
  
  for(int i = 0; i<nbins_cent; ++i){
    for(int j = 0; j<uPbPb_R3_Bayes[i]->GetNbinsX(); ++j)
      uPbPb_R3_Bayes[i]->SetBinError(j+1, uPbPb_R3_Bayes[i]->GetBinError(j+1)/ScaleFactor[i+1]);
    
    uPbPb_R3_Bayes[i]->Scale(ScaleFactor[i+1]);
    uPbPb_R3_Bayes[i]->SetMarkerStyle(33);
    uPbPb_R3_Bayes[i]->SetMarkerColor(kRed);
    uPbPb_R3_Bayes[i]->SetAxisRange(60, 499, "X");
    uPbPb_R3_Bayes[i]->Draw("same");

    // mPbPb_R3[i]->Scale(ScaleFactor[i+2]);
    // mPbPb_R3[i]->SetLineColor(kRed);
    // mPbPb_R3[i]->SetAxisRange(unfoldingCut, 299, "X");
    // mPbPb_R3[i]->Draw("same Lhist");
  }

  TLegend * leg1_R3 = myLegend(0.25,0.2,0.35,0.3);
  leg1_R3->AddEntry(uPP_R3_Bayes,"PP Data","pl");
  //leg1_R3->AddEntry(mPP_R3,"PYTHIA","pl");
  leg1_R3->SetTextSize(0.02);
  leg1_R3->Draw();

  TLegend * leg2_R3 = myLegend(0.7,0.8,0.8,0.9);
  leg2_R3->AddEntry(uPbPb_R3_Bayes[0],"PbPb Data","pl");
  //leg2_R3->AddEntry(mPbPb_R3[0],"PYTHIA+HYDJET","pl");
  leg2_R3->SetTextSize(0.02);
  leg2_R3->Draw();
  
  drawText("R=0.3, anti k_{T} PF Jets", 0.25,0.2,16);
  drawText("R=0.3, anti k_{T} Pu PF Jets", 0.67,0.8,16);
  drawText(Form("%s", etaLable),0.4,0.23,16);

  putCMSPrel(0.25,0.94,0.025);
  putPbPbLumi(0.65,0.9,0.02);
  putPPLumi(0.25,0.3,0.02);
  
  //drawText("pp", 0.7,0.15,16);
  drawText("0-5% x 10^{2}", 0.7,0.28,16);
  drawText("5-10% x 10^{4}", 0.7,0.36,16);
  drawText("10-30% x 10^{6}", 0.7,0.46,16);
  drawText("30-50% x 10^{8}", 0.7,0.55,16);
  drawText("50-70% x 10^{10}", 0.7,0.64,16);
  drawText("70-90% x 10^{12}", 0.7,0.72,16);

  cSpectra_R3->SaveAs(Form("%sFinal_paper_plots_%disATLASCut_spectra_%s_akR3_%dGeVCut_%s_%d.pdf",outLocation, isATLASCut, ptbins, 50, etaWidth, date.GetDate()),"RECREATE");


  
  TCanvas * cSpectra_R4 = new TCanvas("cSpectra_R4","",1200,1000);
  //makeMultiPanelCanvas(cSpectra_R4,3,1,0.0,0.0,0.2,0.15,0.07);
  cSpectra_R4->SetLogy();
  //cSpectra_R4->SetGridy();
  cSpectra_R4->SetLogx();

  uPP_R4_Bayes->Scale(ScaleFactor[0]);
  uPP_R4_Bayes->SetMarkerStyle(20);
  uPP_R4_Bayes->SetMarkerColor(kBlack);
  makeHistTitle(uPP_R4_Bayes," "," Jet p_{T} (GeV/c)","#frac{d#sigma}{dp_{T} d#eta}(nb)                       #frac{d N}{T_{AA} dp_{T} d#eta} (nb)");
  uPP_R4_Bayes->SetAxisRange(60, 299, "X");
  uPP_R4_Bayes->SetAxisRange(1e-4, 1e14, "Y");
  uPP_R4_Bayes->GetYaxis()->SetMoreLogLabels(kFALSE);
  uPP_R4_Bayes->Draw();

  // draw the MC
  mPP_R4->Scale(ScaleFactor[0]);
  mPP_R4->SetLineColor(kBlack);
  mPP_R4->SetAxisRange(64, 299, "X");
  //mPP_R4->Draw("same Lhist");
  
  for(int i = 0; i<nbins_cent; ++i){
    for(int j = 0; j<uPbPb_R4_Bayes[i]->GetNbinsX(); ++j)
      uPbPb_R4_Bayes[i]->SetBinError(j+1, uPbPb_R4_Bayes[i]->GetBinError(j+1)/ScaleFactor[i+1]);
    
    uPbPb_R4_Bayes[i]->Scale(ScaleFactor[i+1]);
    uPbPb_R4_Bayes[i]->SetMarkerStyle(33);
    uPbPb_R4_Bayes[i]->SetMarkerColor(kRed);
    uPbPb_R4_Bayes[i]->SetAxisRange(60, 299, "X");
    uPbPb_R4_Bayes[i]->Draw("same");

    // mPbPb_R4[i]->Scale(ScaleFactor[i+2]);
    // mPbPb_R4[i]->SetLineColor(kRed);
    // mPbPb_R4[i]->SetAxisRange(unfoldingCut, 299, "X");
    // mPbPb_R4[i]->Draw("same Lhist");
  }

  TLegend * leg1_R4 = myLegend(0.25,0.2,0.35,0.3);
  leg1_R4->AddEntry(uPP_R4_Bayes,"PP Data","pl");
  //leg1_R4->AddEntry(mPP_R4,"PYTHIA","pl");
  leg1_R4->SetTextSize(0.02);
  leg1_R4->Draw();

  TLegend * leg2_R4 = myLegend(0.7,0.8,0.8,0.9);
  leg2_R4->AddEntry(uPbPb_R4_Bayes[0],"PbPb Data","pl");
  //leg2_R4->AddEntry(mPbPb_R4[0],"PYTHIA+HYDJET","pl");
  leg2_R4->SetTextSize(0.02);
  leg2_R4->Draw();
  
  drawText("R=0.4, anti k_{T} PF Jets", 0.25,0.2,16);
  drawText("R=0.4, anti k_{T} Pu PF Jets", 0.67,0.8,16);
  drawText(Form("%s", etaLable),0.4,0.23,16);

  putCMSPrel(0.25,0.94,0.025);
  putPbPbLumi(0.65,0.9,0.02);
  putPPLumi(0.25,0.3,0.02);
  
  //drawText("pp", 0.7,0.15,16);
  drawText("0-5% x 10^{2}", 0.7,0.28,16);
  drawText("5-10% x 10^{4}", 0.7,0.36,16);
  drawText("10-30% x 10^{6}", 0.7,0.46,16);
  drawText("30-50% x 10^{8}", 0.7,0.55,16);
  drawText("50-70% x 10^{10}", 0.7,0.64,16);
  drawText("70-90% x 10^{12}", 0.7,0.72,16);

  cSpectra_R4->SaveAs(Form("%sFinal_paper_plots_%disATLASCut_spectra_%s_akR4_%dGeCut_%s_%d.pdf", outLocation, isATLASCut, ptbins, 50, etaWidth, date.GetDate()),"RECREATE");


}
Exemple #12
0
void SaveCanvas(TCanvas* c, TString dir, TString filename)
{
   TDatime* date = new TDatime();
   c->Print(Form("/net/hisrv0001/home/davidlw/pic/%s/%s_%d.eps",dir.Data(),filename.Data(),date->GetDate()));
   c->Print(Form("/net/hisrv0001/home/davidlw/pic/%s/%s_%d.gif",dir.Data(),filename.Data(),date->GetDate()));
   c->Print(Form("/net/hisrv0001/home/davidlw/pic/%s/%s_%d.pdf",dir.Data(),filename.Data(),date->GetDate()));
   c->Print(Form("/net/hisrv0001/home/davidlw/pic/%s/%s_%d.C",dir.Data(),filename.Data(),date->GetDate()));
}
Exemple #13
0
void RAA_dataDrivenUnfoldingErrorCheck_new(int radius = 3, bool isATLASCut = true)
{

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

  char * scale = (char*)"NeqScale";
  // 944Scale
  // NeqScale
  // NeqScalePerCent
  
  int unfoldingCut = 20;
  char * outLocation = (char*) "July20/";
  if(isATLASCut) outLocation = (char*)"July20/ATLASCut/";
  
  // 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. 

  // Pawan's files:
  //TFile * fPbPb_in = TFile::Open(Form("Pawan_TTree_PbPb_Data_MC_subid0_spectra_JetID_CutA_finebins_%s_R0p%d.root", etaWidth, radius));
  //TFile * fPbPb_in = TFile::Open(Form("Pawan_TTree_PbPb_Data_MC_subid0_spectra_JetID_CutA_muMaxOverSumcandMaxLT0p975_finebins_%s_R0p%d.root", etaWidth, radius));
  //TFile * fPbPb_in = TFile::Open(Form("Pawan_TTree_PbPb_Data_MC_subid0_spectra_JetID_CutA_trkMaxOverpfptGT0p02_finebins_%s_R0p%d.root", etaWidth, radius));
  //TFile * fPbPb_in = TFile::Open(Form("Pawan_TTree_PbPb_Data_noPrescl_MC_subid0_spectra_JetID_CutA_finebins_%s_R0p%d.root", etaWidth, radius));
  //TFile * fPbPb_in = TFile::Open(Form("Pawan_TTree_PbPb_Data_noPrescl_MC_subid0_spectra_JetID_CutA_7GeVTrackCut_finebinscut_%s_R0p%d.root", etaWidth, radius));
  // get the files to perform MC closure from the fixed ntuples
  TFile * fPbPb_in, *fMinBias, *fPbPb_MC_in, * fTrig;
  
  if(isATLASCut) fPbPb_in    = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_Data_histograms_FromForest_trkMax7OrNeMax8GeVCut_akPu%d_20_eta_20.root",radius),"r");
  if(!isATLASCut) fPbPb_in    = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_Data_histograms_FromForest_akPu%d_20_eta_20.root",radius),"r");
  if(isATLASCut) fMinBias    = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_MB_Data_histograms_FromForest_trkMax7OrNeMax8GeVCut_fix_pt15GeVCut_akPu%d_20_eta_20.root",radius));
  if(!isATLASCut) fMinBias    = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_MB_Data_histograms_FromForest_fix_pt15GeVCut_akPu%d_20_eta_20.root",radius));
  //TFile * fPbPb_MC_in = TFile::Open(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_MC_histograms_FromForest_pthat50andabove_akPu%d_20_eta_20.root",radius));
  if(isATLASCut) fPbPb_MC_in = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_MC_histograms_FromForest_trkMax7OrNeMax8GeVCut_akPu%d_20_eta_20.root",radius),"r");
  if(!isATLASCut) fPbPb_MC_in = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_MC_histograms_FromForest_akPu%d_20_eta_20.root",radius),"r");
  TFile * fPP_in      = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/pp_Data_histograms_FromForest_ak%d_20_eta_20.root",radius),"r");
  TFile * fPP_MC_in   = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/pp_MC_histograms_FromForest_ak%d_20_eta_20.root",radius),"r");
  if(isATLASCut) fTrig       = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_Data_nofkSub_trkMax7OrNeMax8GeVCut_new_MC_turnonCurves_R%d_20_eta_20_20150715.root",radius),"r");
  if(!isATLASCut) fTrig       = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/PbPb_Data_nofkSub_new_MC_turnonCurves_R%d_20_eta_20_20150715.root",radius),"r");
  TFile * fTrig_pp = new TFile(Form("/afs/cern.ch/work/r/rkunnawa/WORK/RAA/Jun29/pp_MC_turnonCurves_R%d_20_eta_20_20150702.root", radius),"r");
  // TFile * fPPMCTrig = new TFile(Form("PP_Data_MC_turnonCurves_R%d_20_eta_20_20150618.root",radius),"r");

  TH1F * hMC_turnon[nbins_cent+1], * hData_turnon[nbins_cent+1];
  cout<<"after input file declaration"<<endl;
  
  
  // histogram declarations with the following initial appendage: d - Data, m - MC, u- Unfolded
  // for the MC closure test, ive kept separate 

  TH1F *dPbPb_TrgComb[nbins_cent+1], *dPbPb_TrgCombInput[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_GenInput[nbins_cent+1], *mPbPb_RecoInput[nbins_cent+1];
  TH1F *mPbPb_Gen[nbins_cent+1], *mPbPb_Reco[nbins_cent+1];
  TH2F *mPbPb_Matrix[nbins_cent+1], * mPbPb_MatrixInput[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 *hMinBias[nbins_cent];
  
  TH1F *dPP_1, *dPP_2, *dPP_3, *dPP_Comb, * dPP_CombInput;
  TH1F *mPP_Gen, *mPP_Reco, *mPP_GenInput, *mPP_RecoInput;
  TH2F *mPP_Matrix, *mPP_MatrixInput, *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];

  TH1F * hData_FaketoSub_fullbin[nbins_cent+1];
  
  // 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. 

  if(radius == 2) unfoldingCut = unfoldingCut_R2;
  if(radius == 3) unfoldingCut = unfoldingCut_R3;
  if(radius == 4) unfoldingCut = unfoldingCut_R4;
  
  // TH1F * htest = new TH1F("htest","",nbins, ptbins_long);
  // Int_t unfoldingCutBin = htest->FindBin(unfoldingCut);
  
  //Float_t cutarray[6]={50,50,40,35,35,35};
  float cutarray[nbins_cent] = {0.0,0.0,0.0,0.0,0.0,0.0};
  
  if(radius == 2){
    cutarray[0] = 50;
    cutarray[1] = 40;
    cutarray[2] = 40;
    cutarray[3] = 40;
    cutarray[4] = 30;
    cutarray[5] = 30;
  }
  if(radius == 3){
    cutarray[0] = 55;
    cutarray[1] = 50;
    cutarray[2] = 50;
    cutarray[3] = 40;
    cutarray[4] = 35;
    cutarray[5] = 40;
  }
    
  if(radius == 4){
    cutarray[0] = 70;
    cutarray[1] = 60;
    cutarray[2] = 60;
    cutarray[3] = 45;
    cutarray[4] = 40;
    cutarray[5] = 30;
  }
    
  TH1F * hDataBeforeSub[nbins_cent], * hDataAfterSub[nbins_cent];
  
  // get PbPb data
  for(int i = 0;i<nbins_cent;++i){
    if(printDebug) cout<<"cent_"<<i<<endl;

    hData_turnon[i] = (TH1F*)fTrig->Get(Form("hHist_Data_Turnon_cent%d",i));
    
    hData_turnon[i] = (TH1F*)hData_turnon[i]->Rebin(nbins_short, Form("hData_turnon_cent%d",i), boundaries_short);
    //hData_turnon[i] = (TH1F*)hData_turnon[i]->Rebin(10);

    divideBinWidth(hData_turnon[i]);

     //  hMinBias[i]     = (TH1F*)fMinBias->Get(Form("hpbpb_noTrg_R%d_%s_cent%d",radius,etaWidth,i)); //MinBias Histo
    hMinBias[i]     = (TH1F*)fMinBias->Get(Form("hpbpb_HLTMBwoLJSbJ_R%d_%s_cent%d",radius,etaWidth,i)); //MinBias Histo
    hMinBias[i]->Print("base");

    dPbPb_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLTComb_%s_R%d_%s_cent%d",scale, radius,etaWidth,i));
    //dPbPb_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT80_R%d_%s_cent%d",radius,etaWidth,i));
    //dPbPb_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT65_R%d_%s_cent%d",radius,etaWidth,i));
    //dPbPb_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT55_R%d_%s_cent%d",radius,etaWidth,i));
    // dPbPb_TrgComb[i]->Scale(1./(1+0.898+0.494)/1e16);
    // //dPbPb_TrgComb[i]->Scale(4*145.156*1e6);
    dPbPb_TrgComb[i]->Print("base");

    hDataBeforeSub[i] = (TH1F*)dPbPb_TrgComb[i]->Clone(Form("hData_Before_Sub_cent%d",i));
    
    //dPbPb_TrgComb[i] = (TH1F*)fPbPb_DataCorr_in->Get(Form("Data_TrigEffCorrected_FakeSub_cent%d",i));
    //dPbPb_TrgComb[i]->Print("base");
    
    // dPbPb_JEC_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_JEC_HLTComb_R%d_%s_cent%d",radius,etaWidth,i));
    // // //dPbPb_TrgComb[i]->Scale(4*145.156*1e6);
    // dPbPb_JEC_TrgComb[i]->Print("base");
    // dPbPb_Smear_TrgComb[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_Smear_HLTComb_R%d_%s_cent%d",radius,etaWidth,i));
    // // //dPbPb_TrgComb[i]->Scale(4*145.156*1e6);
    // dPbPb_Smear_TrgComb[i]->Print("base");
    // dPbPb_Trg80[i] = (TH1F*)fPbPb_in->Get(Form("hpbpb_HLT80_R%d_%s_cent%d",radius,etaWidth,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_%s_cent%d",radius,etaWidth,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_%s_cent%d",radius,etaWidth,i));
    // //dPbPb_Trg55[i]->Scale(4*145.156*1e6);
    // dPbPb_Trg55[i]->Print("base");

    // if(dotrigcor){
      
    //   doTrigCorr(dPbPb_TrgComb[i], hData_turnon[i]);
    //   doTrigCorr(dPbPb_JEC_TrgComb[i], hData_turnon[i]);
    //   doTrigCorr(dPbPb_Smear_TrgComb[i], hData_turnon[i]);

    // }
    
    //Lets do the subtraction here _Sevil 

      // Float_t bincon=cutarray[i]; 
      // Int_t bincut= hMinBias[i]->FindBin(bincon); 
      
      // for(int k = bincut;k<=hMinBias[i]->GetNbinsX();k++) { 
      // 	hMinBias[i]->SetBinContent(k,0); 
      // 	hMinBias[i]->SetBinError(k,0);
      // } 

      // for(int k = 1;k<=15;k++) { 
      // 	hMinBias[i]->SetBinContent(k,0); 
      // 	hMinBias[i]->SetBinError(k,0);
      // }
      
      Float_t   bin_no = dPbPb_TrgComb[i]->FindBin(15);
      Float_t bin_end=dPbPb_TrgComb[i]->FindBin(25);
      
      Float_t   bin_nomb = hMinBias[i]->FindBin(15);
      Float_t bin_endmb=hMinBias[i]->FindBin(25);
      
      float scalerangeweight=dPbPb_TrgComb[i]->Integral(bin_no,bin_end)/hMinBias[i]->Integral(bin_nomb,bin_endmb);

      // for(int j = 0; j<hMinBias[i]->GetNbinsX(); ++j)
      // 	hMinBias[i]->SetBinError(j+1, (Float_t)hMinBias[i]->GetBinError(j+1)/scalerangeweight);
      
      hMinBias[i]->Scale(scalerangeweight);
      if(dofakeremove) dPbPb_TrgComb[i]->Add(hMinBias[i], -1);

      hDataAfterSub[i] = (TH1F*)dPbPb_TrgComb[i]->Clone(Form("hData_After_Sub_cent%d",i));
      
      // dPbPb_JEC_TrgComb[i]->Add(hMinBias[i], -1);
      // dPbPb_Smear_TrgComb[i]->Add(hMinBias[i], -1);

      // for(int j = 1; j<dPbPb_TrgComb[i]->GetNbinsX(); ++j){

      // 	if(dPbPb_TrgComb[i]->GetBinContent(j) <= 0 ||dPbPb_JEC_TrgComb[i]->GetBinContent(j) <= 0||dPbPb_Smear_TrgComb[i]->GetBinContent(j) <= 0){
      // 	  dPbPb_TrgComb[i]->SetBinContent(j, 0);
      // 	  dPbPb_JEC_TrgComb[i]->SetBinContent(j, 0);
      // 	  dPbPb_Smear_TrgComb[i]->SetBinContent(j, 0);
      // 	  dPbPb_TrgComb[i]->SetBinError(j, 0);
      // 	  dPbPb_JEC_TrgComb[i]->SetBinError(j, 0);
      // 	  dPbPb_Smear_TrgComb[i]->SetBinError(j, 0);
      // 	}
      // }
      
    

    // // lets truncate the histograms here:
    // cout<<" going to truncate Data histogram here cent "<<i<<endl;
    // dPbPb_TrgCombInput[i]->Print("base");

    // dPbPb_TrgComb[i] = new TH1F(Form("PbPb_data_minbiasSub_cent%d",i),"",365, 30, 395);
    // Truncate1D(dPbPb_TrgCombInput[i], dPbPb_TrgComb[i]);    
    
    // // dPbPb_TrgComb[i] = (TH1F*)Truncate1D(dPbPb_TrgComb[i], 340, unfoldingCutBin, 395);
    // // dPbPb_TrgComb[i]->Print("base");
    
    //dPbPb_TrgComb[i] = (TH1F*)dPbPb_TrgComb[i]->Rebin(nbins, Form("PbPb_data_minbiasSub_cent%d",i), ptbins_long);
    dPbPb_TrgComb[i] = (TH1F*)dPbPb_TrgComb[i]->Rebin(10);
    dPbPb_TrgComb[i]->SetName(Form("PbPb_data_minbiasSub_cent%d",i));
    divideBinWidth(dPbPb_TrgComb[i]);
    
    hMinBias[i] = (TH1F*)hMinBias[i]->Rebin(10);
    hDataAfterSub[i] = (TH1F*)hDataAfterSub[i]->Rebin(10);
    hDataBeforeSub[i] = (TH1F*)hDataBeforeSub[i]->Rebin(10);

    divideBinWidth(hMinBias[i]);
    divideBinWidth(hDataAfterSub[i]);
    divideBinWidth(hDataBeforeSub[i]);
    
    dPbPb_TrgComb[i]->Scale(1./(166 * 1e9));
    
    // dPbPb_TrgComb[i]->Print("base");
    
  }

  if(printDebug)cout<<"loaded the data histograms PbPb"<<endl;
  // get PbPb MC
  for(int i = 0;i<nbins_cent;i++){
    
    // mPbPb_GenInput[i] = (TH1F*)fPbPb_MC_in->Get(Form("hpbpb_anaBin_JetComb_gen_R%d_%s_cent%d",radius,etaWidth,i));
    // mPbPb_GenInput[i]->Print("base");
    // mPbPb_RecoInput[i] = (TH1F*)fPbPb_MC_in->Get(Form("hpbpb_anaBin_JetComb_reco_R%d_%s_cent%d",radius,etaWidth,i));
    // mPbPb_RecoInput[i]->Print("base");
    // mPbPb_MatrixInput[i] = (TH2F*)fPbPb_MC_in->Get(Form("hpbpb_anaBin_matrix_HLT_R%d_%s_cent%d",radius,etaWidth,i));
    // mPbPb_MatrixInput[i]->Print("base");

    mPbPb_Gen[i] = (TH1F*)fPbPb_MC_in->Get(Form("hpbpb_JetComb_gen_R%d_%s_cent%d",radius,etaWidth,i));
    //mPbPb_Gen[i]->Rebin(nbins, Form("mPbPb_Gen_cent%d",i), ptbins_long);
    mPbPb_Gen[i]->Rebin(10);
    divideBinWidth(mPbPb_Gen[i]);
    mPbPb_Gen[i]->Print("base");
    mPbPb_Reco[i] = (TH1F*)fPbPb_MC_in->Get(Form("hpbpb_JetComb_reco_R%d_%s_cent%d",radius,etaWidth,i));
    //mPbPb_Reco[i]->Rebin(nbins, Form("mPbPb_Reco_cent%d",i), ptbins_long);
    mPbPb_Reco[i]->Rebin(10);
    divideBinWidth(mPbPb_Reco[i]);
    mPbPb_Reco[i]->Print("base");
    mPbPb_Matrix[i] = (TH2F*)fPbPb_MC_in->Get(Form("hpbpb_matrix_HLT_R%d_%s_cent%d",radius,etaWidth,i));
    //mPbPb_Matrix[i] = (TH2F*)fPbPb_MC_in->Get(Form("hpbpb_anaBin_matrix_HLT_R%d_%s_cent%d",radius,etaWidth,i));
    mPbPb_Matrix[i]->Rebin2D(10, 10);
    mPbPb_Matrix[i]->Print("base");
    
    // if(etaWidth == "10_eta_10"){
    //   if(i == 0 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 1 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 2 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 3 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 4 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==2) unfoldingCutBin = htest->FindBin(30);

    //   if(i == 0 && radius==3) unfoldingCutBin = htest->FindBin(40);
    //   if(i == 1 && radius==3) unfoldingCutBin = htest->FindBin(40);
    //   if(i == 2 && radius==3) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 3 && radius==3) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 4 && radius==3) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==3) unfoldingCutBin = htest->FindBin(30);

    //   if(i == 0 && radius==4) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 1 && radius==4) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 2 && radius==4) unfoldingCutBin = htest->FindBin(40);
    //   if(i == 3 && radius==4) unfoldingCutBin = htest->FindBin(40);
    //   if(i == 4 && radius==4) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==4) unfoldingCutBin = htest->FindBin(30);
    // }

    // if(etaWidth == "10_eta_18"){
    //   if(i == 0 && radius==2) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 1 && radius==2) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 2 && radius==2) unfoldingCutBin = htest->FindBin(40);
    //   if(i == 3 && radius==2) unfoldingCutBin = htest->FindBin(40);
    //   if(i == 4 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==2) unfoldingCutBin = htest->FindBin(30);

    //   if(i == 0 && radius==3) unfoldingCutBin = htest->FindBin(60);
    //   if(i == 1 && radius==3) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 2 && radius==3) unfoldingCutBin = htest->FindBin(40);
    //   if(i == 3 && radius==3) unfoldingCutBin = htest->FindBin(40);
    //   if(i == 4 && radius==3) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==3) unfoldingCutBin = htest->FindBin(30);

    //   if(i == 0 && radius==4) unfoldingCutBin = htest->FindBin(70);
    //   if(i == 1 && radius==4) unfoldingCutBin = htest->FindBin(60);
    //   if(i == 2 && radius==4) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 3 && radius==4) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 4 && radius==4) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==4) unfoldingCutBin = htest->FindBin(30);
    // }

    // if(etaWidth == "20_eta_20"){
    //   if(i == 0 && radius==2) unfoldingCutBin = htest->FindBin(70);
    //   if(i == 1 && radius==2) unfoldingCutBin = htest->FindBin(60);
    //   if(i == 2 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 3 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 4 && radius==2) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==2) unfoldingCutBin = htest->FindBin(30);

    //   if(i == 0 && radius==3) unfoldingCutBin = htest->FindBin(70);
    //   if(i == 1 && radius==3) unfoldingCutBin = htest->FindBin(60);
    //   if(i == 2 && radius==3) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 3 && radius==3) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 4 && radius==3) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==3) unfoldingCutBin = htest->FindBin(30);

    //   if(i == 0 && radius==4) unfoldingCutBin = htest->FindBin(80);
    //   if(i == 1 && radius==4) unfoldingCutBin = htest->FindBin(60);
    //   if(i == 2 && radius==4) unfoldingCutBin = htest->FindBin(50);
    //   if(i == 3 && radius==4) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 4 && radius==4) unfoldingCutBin = htest->FindBin(30);
    //   if(i == 5 && radius==4) unfoldingCutBin = htest->FindBin(30);
    // }

    int bincut = mPbPb_Gen[i]->FindBin(50);
    for(int k = 1;k<=bincut;k++){

    //   mPbPb_Gen[i]->SetBinContent(k,0);
    //   mPbPb_Reco[i]->SetBinContent(k,0);
    //   mPbPb_Gen[i]->SetBinError(k,0);
    //   mPbPb_Reco[i]->SetBinError(k,0);
    //   // set bin content matrix l,k works 
      for(int l = 1;l<=mPbPb_Gen[i]->GetNbinsX();l++){
	mPbPb_Matrix[i]->SetBinContent(l,k,0);
	mPbPb_Matrix[i]->SetBinError(l,k,0);
      }
      
    }

    SetUnfoldBins1D(dPbPb_TrgComb[i], 50, 350);
    
    // cout<<"going to truncate the MC histograms here."<<endl;
    
    // // mPbPb_Reco[i]->Print("base");
    // // mPbPb_Reco[i] = (TH1F*)Truncate1D_anaBin(mPbPb_Reco[i], nbins, ptbins_long);
    // // mPbPb_Reco[i]->Print("base");

    // mPbPb_GenInput[i]->Print("base");
    // mPbPb_Gen[i] = new TH1F(Form("mPbPb_Gen_spectra_cent%d",i),"",nbins, ptbins_long);
    // Truncate1D(mPbPb_GenInput[i], mPbPb_Gen[i]);
    // mPbPb_Gen[i]->Print("base");
    
    // mPbPb_RecoInput[i]->Print("base");
    // mPbPb_Reco[i] = new TH1F(Form("mPbPb_REco_spectra_cent%d",i),"",nbins, ptbins_long);
    // Truncate1D(mPbPb_RecoInput[i], mPbPb_Reco[i]);
    // mPbPb_Reco[i]->Print("base");
    
    // mPbPb_MatrixInput[i]->Print("base");
    // mPbPb_Matrix[i] = new TH2F(Form("mPbPb_Response_Matrix_cent%d",i),"",nbins_truncated, ptbins_long_truncated, nbins_truncated, ptbins_long_truncated);
    // Truncate2D(mPbPb_MatrixInput[i], mPbPb_Matrix[i]);
    // mPbPb_Matrix[i]->Print("base");
 
  }
  
  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;

  //fPP_in->ls();

  // dPP_1 = (TH1F*)fPP_in->Get(Form("hpp_HLT80_R%d_%s",radius,etaWidth)); 
  // dPP_1->Print("base");
  // dPP_2 = (TH1F*)fPP_in->Get(Form("hpp_HLT60_R%d_%s",radius,etaWidth));
  // dPP_2->Print("base");
  // dPP_3 = (TH1F*)fPP_in->Get(Form("hpp_HLT40_R%d_%s",radius,etaWidth));
  // dPP_3->Print("base");
  dPP_Comb = (TH1F*)fPP_in->Get(Form("hpp_HLTComb_R%d_%s",radius,etaWidth));
  //dPP_Comb = (TH1F*)dPP_1->Clone(Form("hpp_TrgComb_R%d_n20_eta_p20",radius,etaWidth));   
  //dPP_CombInput->Print("base");
  dPP_Comb->Scale(1./(5.3 * 1e9));
  
  // dPP_Comb = new TH1F("PP_MeasuredSpectra","",365, 30, 395);
  // Truncate1D(dPP_CombInput, dPP_Comb);

  //dPP_Comb = (TH1F*)dPP_Comb->Rebin(nbins, "PP_MeasuredSpectra", ptbins_long);
  dPP_Comb = (TH1F*)dPP_Comb->Rebin(10);
  dPP_Comb->SetName("PP_MeasuredSpectra");
  divideBinWidth(dPP_Comb);
  dPP_Comb->Print("base");
  
  // get PP MC
  // mPP_GenInput = (TH1F*)fPP_MC_in->Get(Form("hpp_anaBin_JetComb_gen_R%d_%s",radius,etaWidth));
  // mPP_GenInput->Print("base");
  // mPP_Gen = new TH1F("mPP_Gen_spectra","",nbins, ptbins_long);
  // Truncate1D(mPP_GenInput, mPP_Gen);
  // mPP_Gen->Print("base");
  
  // mPP_RecoInput = (TH1F*)fPP_MC_in->Get(Form("hpp_anaBin_JetComb_reco_R%d_%s",radius,etaWidth));
  // mPP_RecoInput->Print("base");
  // mPP_Reco = new TH1F("mPP_Reco_spectra","",nbins, ptbins_long);
  // Truncate1D(mPP_RecoInput, mPP_Reco);
  // mPP_Reco->Print("base");
  
  // mPP_MatrixInput = (TH2F*)fPP_MC_in->Get(Form("hpp_anaBin_matrix_HLT_R%d_%s",radius,etaWidth));
  // mPP_MatrixInput->Print("base");
  // mPP_Matrix = new TH2F("mPP_response_Matrix","",nbins_truncated, ptbins_long_truncated, nbins_truncated, ptbins_long_truncated);
  // Truncate2D(mPP_MatrixInput, mPP_Matrix);
  // mPP_Matrix->Print("base");

  // get PP MC
  // change from fPP_MC_in to fPP_in to run finebinscut
  //mPP_Gen = (TH1F*)fPP_MC_in->Get(Form("hpp_anaBin_JetComb_gen_R%d_20_eta_20",radius));
  mPP_Gen = (TH1F*)fPP_MC_in->Get(Form("hpp_JetComb_gen_R%d_20_eta_20",radius));
  //mPP_Gen->Rebin(nbins, "mPP_Gen", ptbins_long);
  mPP_Gen->Rebin(10);
  divideBinWidth(mPP_Gen);
  mPP_Gen->Print("base");

  //mPP_Reco = (TH1F*)fPP_MC_in->Get(Form("hpp_anaBin_JetComb_reco_R%d_20_eta_20",radius));
  mPP_Reco = (TH1F*)fPP_MC_in->Get(Form("hpp_JetComb_reco_R%d_20_eta_20",radius));
  //mPP_Gen->Rebin(nbins, "mPP_Gen", ptbins_long);
  mPP_Reco->Rebin(10);
  divideBinWidth(mPP_Reco);
  mPP_Reco->Print("base");

  //mPP_Matrix = (TH2F*)fPP_MC_in->Get(Form("hpp_anaBin_matrix_HLT_R%d_20_eta_20",radius));
  mPP_Matrix = (TH2F*)fPP_MC_in->Get(Form("hpp_matrix_HLT_R%d_20_eta_20",radius));
  mPP_Matrix->Rebin2D(10, 10);
  mPP_Matrix->Print("base");

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

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

  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,Form("PbPb_measured_spectra_combined_cent%d",i),ptbins_long);
  //   divideBinWidth(dPbPb_TrgComb[i]);
  // }

  // dPP_Comb = (TH1F*)dPP_Comb->Rebin(nbins,"pp_measured_spectra_combined",ptbins_long);
  // divideBinWidth(dPP_Comb);
  // dPP_Comb->Scale(1./ dPP_Comb->GetBinContent(nbins));
  
  // 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 = 1000;
  Double_t meanMeasPbPb[nbins][nbins_cent], sigmaMeasPbPb[nbins][nbins_cent];
  Double_t meanMeasPP[nbins], sigmaMeasPP[nbins];
  Double_t meanUnfoldPbPb[nbins][nbins_cent][unfoldingTrials], sigmaUnfoldPbPb[nbins][nbins_cent][unfoldingTrials];
  Double_t meanUnfoldPP[nbins][unfoldingTrials], sigmaUnfoldPP[nbins][unfoldingTrials]; 
  
  TRandom3 *random = new TRandom3(0);

  TH1F * hPbPb_beforeUnfold_Gaussian_pt150[nbins_cent];
  TH1F * hPP_beforeUnfold_Gaussian_pt150; 
  hPP_beforeUnfold_Gaussian_pt150 = new TH1F("hPP_beforeUnfold_Gaussian_pt150","",1000, 0.1 * dPP_Comb->GetBinContent(dPP_Comb->FindBin(150)) , 1.9 * dPP_Comb->GetBinContent(dPP_Comb->FindBin(150)));
  
  for(int i = 0; i<nbins_cent; ++i)
    hPbPb_beforeUnfold_Gaussian_pt150[i] = new TH1F(Form("hPbPb_beforeUnfold_Gaussian_pt150_cent%d",i),"Before Unfolding pt bin at 150 value spectra",1000, 0.1 * dPbPb_TrgComb[i]->GetBinContent(dPbPb_TrgComb[i]->FindBin(150)), 1.9 * dPbPb_TrgComb[i]->GetBinContent(dPbPb_TrgComb[i]->FindBin(150)));
  

  for(int u = 0;u<unfoldingTrials;++u){
    cout<<"unfolding trial no = "<<u+1<<endl;
  
    for(int j = 0;j<nbins;++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->GetBinError(j+1);
      
    }// nbins loop

    // now proceed to unfolding for each trial.

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

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

      for(int j = 0;j<nbins;++j){
	
	hPreUnfoldingSpectra->SetBinContent(j+1, random->Gaus(meanMeasPbPb[j][i], sigmaMeasPbPb[j][i]));
	hPreUnfoldingSpectra->SetBinError(j+1, sigmaMeasPbPb[j][i]/sqrt(unfoldingTrials));
	if(j+1 == dPbPb_TrgComb[i]->FindBin(150)) hPbPb_beforeUnfold_Gaussian_pt150[i]->Fill(random->Gaus(meanMeasPbPb[j][i], sigmaMeasPbPb[j][i]));
	
      }// nbins loop

      TH1F* hMCGen          = (TH1F*)mPbPb_Response[i]->ProjectionX();
      removeZero(hMCGen);
      bayesianUnfold myUnfoldingMulti(mPbPb_Matrix[i], hMCGen, 0);
      myUnfoldingMulti.unfold(hPreUnfoldingSpectra, BayesIter);

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

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

	meanUnfoldPbPb[j][i][u] = hAfterUnfoldingSpectra->GetBinContent(j+1);
	sigmaUnfoldPbPb[j][i][u] = hAfterUnfoldingSpectra->GetBinError(j+1);

      }// nbins loop
      
      delete hPreUnfoldingSpectra;
      delete hAfterUnfoldingSpectra;
      delete hMCGen; 
      
    }// centrality loop

    cout<<"pp "<<endl;

    // now do it for the pp:
    TH1F * hPreUnfoldingSpectraPP = new TH1F("hPreUnfoldingSpectraPP","",nbins,0, 1000);
    TH1F * hAfterUnfoldingSpectraPP;
    
    for(int j = 0;j<nbins;++j){
	
      hPreUnfoldingSpectraPP->SetBinContent(j+1, random->Gaus(meanMeasPP[j], sigmaMeasPP[j]));
      hPreUnfoldingSpectraPP->SetBinError(j+1, sigmaMeasPP[j]/sqrt(unfoldingTrials));
      if(j+1 == dPP_Comb->FindBin(150)) hPP_beforeUnfold_Gaussian_pt150->Fill(random->Gaus(meanMeasPP[j], sigmaMeasPP[j]));
      
    }// nbins 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;++j){

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

    }// nbins 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];
  TH1F * hCorrUnfoldingPbPb[nbins_cent];

  // we need to store one gaussian histogram in the root file which we can plot 
  TH1F * hPbPb_Gaussian_pt150[nbins_cent];
  TH1F * hPP_Gaussian_pt150;


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

    hCorrUnfoldingPbPb[i] = new TH1F(Form("PbPb_BayesianUnfolded_cent%d",i),"Spectra after correction", nbins,0, 1000);
    hPbPb_Gaussian_pt150[i] = new TH1F(Form("PbPb_Gaussian_pt150_cent%d",i),"gaussian distribution of values at pt bin at 150",1000, 0.1 * dPbPb_TrgComb[i]->GetBinContent(dPbPb_TrgComb[i]->FindBin(150)), 1.9 * dPbPb_TrgComb[i]->GetBinContent(dPbPb_TrgComb[i]->FindBin(150)));

    for(int j = 0;j<nbins;++j){
      
      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+1 == dPbPb_TrgComb[i]->FindBin(150)) hPbPb_Gaussian_pt150[i]->Fill(meanUnfoldPbPb[j][i][u]);

      }// unfolding trials loop

      hCorrUnfoldingPbPb[i]->SetBinContent(j+1, hAfterUnfoldingptBinDistribution[j]->GetMean());
      hCorrUnfoldingPbPb[i]->SetBinError(j+1, hAfterUnfoldingptBinDistribution[j]->GetRMS());

      delete hAfterUnfoldingptBinDistribution[j];
      
    }// nbins loop

  }// centrality loop

  // similar for the pp:
  TH1F * hAfterUnfoldingptBinDistributionPP[nbins];
  TH1F * hCorrUnfoldingPP;
  
  hCorrUnfoldingPP = new TH1F("PP_BayesianUnfolded","Spectra after unfolding error correction",nbins,0, 1000);
  hPP_Gaussian_pt150 = new TH1F("PP_Gaussian_pt100","gaussian distribution of values at pt bin at 150",1000, 0.1 * dPP_Comb->GetBinContent(dPP_Comb->FindBin(150)) , 1.9 * dPP_Comb->GetBinContent(dPP_Comb->FindBin(150)));
  
  for(int j = 0;j<nbins;++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]);
      if(j+1 == dPP_Comb->FindBin(150)) hPP_Gaussian_pt150->Fill(meanUnfoldPP[j][u]);
      
    }// unfolding trials loop
    
    hCorrUnfoldingPP->SetBinContent(j+1, hAfterUnfoldingptBinDistributionPP[j]->GetMean());
    hCorrUnfoldingPP->SetBinError(j+1, hAfterUnfoldingptBinDistributionPP[j]->GetRMS());
    
    delete hAfterUnfoldingptBinDistributionPP[j];
    
  }// nbins loop
    
  TFile f(Form("July20/HiForest_%disATLASCut_%ddo10GeVBins_data_driven_correction_ak%d.root" , isATLASCut, do10GeVBins, radius),"RECREATE");
  f.cd();

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

    //hCorrUnfoldingPbPb[i] = (TH1F*)hCorrUnfoldingPbPb[i]->Rebin(nbins_coarse, Form("PbPb_BayesianUnfolded_cent%d",i), ptbins_long_coarse);
    //divideBinWidth(hCorrUnfoldingPbPb[i]);
    //dPbPb_TrgComb[i] = (TH1F*)dPbPb_TrgComb[i]->Rebin(nbins_coarse, Form("PbPb_measured_cent%d",i), ptbins_long_coarse);
    //divideBinWidth(dPbPb_TrgComb[i]);

    hMinBias[i]->Write();
    hDataBeforeSub[i]->Write();
    hDataAfterSub[i]->Write();
    
    hCorrUnfoldingPbPb[i]->Scale(166 * 1e9);
    hCorrUnfoldingPbPb[i]->Write();
    hCorrUnfoldingPbPb[i]->Print("base");

    dPbPb_TrgComb[i]->Scale(166 * 1e9);
    dPbPb_TrgComb[i]->SetName(Form("PbPb_data_minbiasSub_cent%d",i));
    //dPbPb_TrgComb[i]->Scale(145.156 * 1e9);
    dPbPb_TrgComb[i]->Write();
    dPbPb_TrgComb[i]->Print("base");

    hPbPb_beforeUnfold_Gaussian_pt150[i]->Write();
    hPbPb_beforeUnfold_Gaussian_pt150[i]->Print("base");
    
    hPbPb_Gaussian_pt150[i]->Write();
    hPbPb_Gaussian_pt150[i]->Print("base");

    mPbPb_Matrix[i]->Write();
    
  }

  //hCorrUnfoldingPP = (TH1F*)hCorrUnfoldingPP->Rebin(nbins_coarse, "PP_BayesianUnfolded", ptbins_long_coarse);
  //divideBinWidth(hCorrUnfoldingPP);
  //dPP_Comb = (TH1F*)dPP_Comb->Rebin(nbins_coarse, "PP_measured", ptbins_long_coarse);  
  //divideBinWidth(dPP_Comb);
  
  hCorrUnfoldingPP->Scale(5.3 * 1e9);
  hCorrUnfoldingPP->Write();
  hCorrUnfoldingPP->Print("base");

  dPP_Comb->Scale(5.3 * 1e9);
  dPP_Comb->Write();
  dPP_Comb->Print("base");

  hPP_beforeUnfold_Gaussian_pt150->Write();
  hPP_beforeUnfold_Gaussian_pt150->Print("base");
  
  hPP_Gaussian_pt150->Write();
  hPP_Gaussian_pt150->Print("base");
  mPP_Matrix->Write();

  f.Write();
  f.Close();

  // make the data driven Error correction histograms and plots here:
  
  TH1F * hError_Meas[nbins_cent+1], * hError_Fixed[nbins_cent+1];
  for(int i = 0; i<nbins_cent+1; ++i){
    cout<<"centrality "<<i<<endl;
    if(i < nbins_cent){
      hError_Meas[i]  = new TH1F(Form("hError_Meas_cent%d",i),"",nbins, 0, 1000);
      hError_Fixed[i] = new TH1F(Form("hError_Fixed_cent%d",i),"",nbins, 0, 1000);
    }
    if(i == nbins_cent){
      hError_Meas[i]  = new TH1F(Form("hError_PP_Meas_cent%d",i),"",nbins, 0, 1000);
      hError_Fixed[i] = new TH1F(Form("hError_PP_Fixed_cent%d",i),"",nbins, 0, 1000);
    }

    for(int j = 1; j<=nbins; ++j){
      //cout<<"ptbins "<<j<<endl;
      if(i < nbins_cent){
	if(dPbPb_TrgComb[i]->GetBinContent(j)!=0) hError_Meas[i]->SetBinContent(j, (float)dPbPb_TrgComb[i]->GetBinError(j)/dPbPb_TrgComb[i]->GetBinContent(j));
        //hError_Meas[i]->SetBinContent(j, (float)dPbPb_TrgComb[i]->GetBinError(j));
	if(hCorrUnfoldingPbPb[i]->GetBinContent(j)!=0)hError_Fixed[i]->SetBinContent(j, (float)hCorrUnfoldingPbPb[i]->GetBinError(j)/hCorrUnfoldingPbPb[i]->GetBinContent(j));
	cout<<j<<" "<<hError_Fixed[i]->GetBinContent(j)<<endl;
	//hError_Fixed[i]->SetBinContent(j, (float)hCorrUnfoldingPbPb[i]->GetBinError(j));
      }
      if(i == nbins_cent){
	hError_Meas[i]->SetBinContent(j, (float)dPP_Comb->GetBinError(j)/dPP_Comb->GetBinContent(j));
	//hError_Meas[i]->SetBinContent(j, (float)dPP_Comb->GetBinError(j));
	hError_Fixed[i]->SetBinContent(j, (float)hCorrUnfoldingPP->GetBinError(j)/hCorrUnfoldingPP->GetBinContent(j));
	//hError_Fixed[i]->SetBinContent(j, (float)hCorrUnfoldingPP->GetBinError(j));
      }
    }
    
    hError_Meas[i]->SetAxisRange(50, 299, "X");
    //hError_Meas[i]->Print("base");
    //hError_Fixed[i]->Print("base");
    //hError_Meas[i]->SetAxisRange(1e-12, 1, "Y");
  }
  //cout<<" passed the loop"<<endl;

  TCanvas * cSpectra = new TCanvas("cSpectra","",1200,1000);
  makeMultiPanelCanvas(cSpectra,3,2,0.0,0.0,0.2,0.15,0.07);  
  for(int i = 0; i<nbins_cent; ++i){
    //cout<<i<<endl;
    cSpectra->cd(nbins_cent-i);
    cSpectra->cd(nbins_cent-i)->SetLogy();
    dPbPb_TrgComb[i]->SetMarkerStyle(24);
    dPbPb_TrgComb[i]->SetMarkerColor(kBlack);
    makeHistTitle(dPbPb_TrgComb[i]," ","jet pT","dN/dpT");
    dPbPb_TrgComb[i]->SetAxisRange(50, 299, "X");
    dPbPb_TrgComb[i]->Draw("p");

    hCorrUnfoldingPbPb[i]->SetMarkerStyle(33);
    hCorrUnfoldingPbPb[i]->SetMarkerColor(kRed);
    hCorrUnfoldingPbPb[i]->Draw("psame");

  }
  TLegend * Spec = myLegend(0.55,0.55,0.75,0.75);
  cSpectra->cd(1);
  putCMSPrel();
  Spec->AddEntry(dPbPb_TrgComb[0],"Measured","pl");
  Spec->AddEntry(hCorrUnfoldingPbPb[0],"Data Driven Correction","pl");
  Spec->SetTextSize(0.04);
  Spec->Draw();
  
  cSpectra->SaveAs(Form("%sUnfoldingSpectra_fromDataDrivenMacro_PbPb_%s_R%d_%d_hiForest_%dGeVCut.pdf",outLocation,etaWidth,radius,date.GetDate(),unfoldingCut),"RECREATE");

  
  TCanvas * cErrorFix = new TCanvas("cErrorFix","",1200,1000);
  makeMultiPanelCanvas(cErrorFix,3,2,0.0,0.0,0.2,0.15,0.07);  
  for(int i = 0; i<nbins_cent; ++i){
    //cout<<i<<endl;
    cErrorFix->cd(nbins_cent-i);
    cErrorFix->cd(nbins_cent-i)->SetLogy();
    makeHistTitle(hError_Meas[i]," ","jet pT","Error/Content");
    hError_Meas[i]->SetMarkerStyle(24);
    hError_Meas[i]->SetMarkerColor(kBlack);
    hError_Meas[i]->Draw("p");

    hError_Fixed[i]->SetMarkerStyle(33);
    hError_Fixed[i]->SetMarkerColor(kRed);
    hError_Fixed[i]->Draw("psame");

  }
  TLegend * err = myLegend(0.55,0.55,0.75,0.75);
  cErrorFix->cd(1);
  putCMSPrel();
  err->AddEntry(hError_Meas[0],"Measured","pl");
  err->AddEntry(hError_Fixed[0],"Data Driven Correction","pl");
  err->SetTextSize(0.04);
  err->Draw();
  
  cErrorFix->SaveAs(Form("%sUnfoldingErrorFix_fromDataDrivenMacro_PbPb_%s_R%d_%d_hiForest_%dGeVCut.pdf",outLocation,etaWidth,radius,date.GetDate(),unfoldingCut),"RECREATE");

  TCanvas * cErrorFixPP = new TCanvas("cErrorFixPP","",800,600);
  cErrorFixPP->SetLogy();
  hError_Meas[nbins_cent]->SetMarkerStyle(24);
  hError_Meas[nbins_cent]->SetMarkerColor(kBlack);
  hError_Meas[nbins_cent]->Draw("p");
  
  hError_Fixed[nbins_cent]->SetMarkerStyle(33);
  hError_Fixed[nbins_cent]->SetMarkerColor(kRed);
  hError_Fixed[nbins_cent]->Draw("psame");
  TLegend * errPP = myLegend(0.55,0.55,0.75,0.75);
  putCMSPrel();
  errPP->AddEntry(hError_Meas[nbins_cent],"Measured","pl");
  errPP->AddEntry(hError_Fixed[nbins_cent],"Data Driven Correction","pl");
  errPP->SetTextSize(0.04);
  errPP->Draw();
  
  cErrorFixPP->SaveAs(Form("%sUnfoldingErrorFix_fromDataDrivenMacro_PP_%s_R%d_%d_hiForest_%dGeVCut.pdf",outLocation,etaWidth,radius,date.GetDate(),unfoldingCut),"RECREATE");
  
  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;


}
void gammaTrkHistProducer(sampleType collision = kPPDATA, float photonPtThr=20, float photonPtThrUp=9999, int icent =7){
  TH1::SetDefaultSumw2();
  
  TString stringSampleType = getSampleName(collision); "";
  
  TDatime* date = new TDatime();
  TString  outName=  Form("photonTrackCorr_%s_output_photonPtThr%d_to_%d_%d.root",stringSampleType.Data(),(int)photonPtThr, (int)photonPtThrUp,  date->GetDate());
  delete date;
  
 
  int lowerCent(0),  upperCent(0); 
  TCut centCut  = "";
  if ( (collision ==kHIDATA) || (collision ==kHIMC) ) {
     lowerCent = ((icent/100)%100) *2 ;
     upperCent =  (icent%100)*2 -1 ; 
     centCut = Form("cBin >= %d && cBin<= %d",lowerCent,upperCent);
  }
  else if (  (collision ==kPPDATA) || (collision==kPPMC)  ){  // if it's pp 
    centCut = "(1==1)";
    //    icent = 7;   // for pp, centrality is set as the smearing 
  }
  else { // pPb
    centCut = Form( "hf4Sum > %f && hf4Sum <= %f", (float)centBinPa[icent-1], (float)centBinPa[icent]);
  }
  
  cout <<" centrality : " << centCut.GetTitle() << endl;
      
  ///////// Photon cut //////////////////////////////////////////////////////////////////////////////
  
  cout <<" photon pt >" << photonPtThr << " GeV" << endl;
  TCut ptPhoCut  = Form("photonEt>%.1f && photonEt<%.1f", (float)photonPtThr, (float)photonPtThrUp  );
  TCut caloIso;
  
  if ( (collision==kPPMC) || (collision==kPPDATA) ) 
    caloIso = "(ecalIso < 4.2  &&  hcalIso < 2.2  &&  trackIso < 2) && hovere<0.1";
  else if ( (collision==kHIMC) || (collision==kHIDATA) )
    caloIso = "(sumIso<5) && hovere<0.1";
  else {
    caloIso = "ecalIso < 4.2  &&  hcalIso < 2.2  &&  trackIso < 2 && hovere<0.1";
  }
  
  TCut sbIso   = "(sumIso>5) && (sumIso<20) && hovere<0.1";
  //  if ( (collision==kPPMC) || (collision==kPPDATA) || (collision==kPAMC) || (collision==kPADATA)  )
  //  sbIso   = "ecalIso < 4.2  &&  hcalIso < 2.2 && trackIso > 2 && trackIso < 5 && hovere<0.1";

  TCut basicPhoCut = centCut && ptPhoCut && caloIso ;
  TCut sbPhoCut    = centCut && ptPhoCut && sbIso   ;
  TCut evtSeltCut = basicPhoCut;
  TCut sbSeltCut  = sbPhoCut;

  TCut phoCandCut   = "sigmaIetaIeta<0.010";
  TCut phoDecayCut  = "(sigmaIetaIeta>0.011) && (sigmaIetaIeta<0.017)";
  if  ( ( collision == kHIMC ) || (collision == kPPMC) || (collision == kPAMC))  
    phoCandCut = phoCandCut && "genIso<5 && abs(genMomId)<=22";
  
  
  TString fname = "";
  if ( collision == kHIDATA)      fname = fnameHIDATA; //
  else if ( collision == kPADATA) fname = fnamePADATA;
  else if ( collision == kPPDATA) {
    if  ( icent == 7 ) fname = fnamePPDATA;
    else if ( icent == 10010 ) fname = fnamePPDATA0010;
    else if ( icent == 11030 ) fname = fnamePPDATA1030;
    else if ( icent == 13050 ) fname = fnamePPDATA3050;
    else if ( icent == 15099 ) fname = fnamePPDATA5099;
    else if ( icent == 10030 ) fname = fnamePPDATA0030;
    else if ( icent == 13099 ) fname = fnamePPDATA30100;
  }  
  else fname = "";
  
  multiTreeUtil* tgj = new multiTreeUtil();
  tgj->addFile(fname,  "tgj",  evtSeltCut,  1);
  tgj->AddFriend("yTrk");
 
  float purity(0);
  
  TString canvasName = Form("gifs/purity_%s_output_icent%d_photonPtThr%d-%d", stringSampleType.Data(),  (int)icent, (int)photonPtThr, (int)photonPtThrUp);
  
  if ( collision == kPPDATA) {  
    purity = 0.85;
  }
  else {
    fitResult fitr = getPurity(fname, collision, evtSeltCut, sbSeltCut, canvasName, photonPtThr, photonPtThrUp);
    purity = fitr.purity010;
  }
  GjSpectra* gSpec = new GjSpectra();
  gSpec->init(Form("icent%d",(int)icent) );
  tgj->Draw2(gSpec->hPtPhoCand,  "photonEt", phoCandCut, "");
  tgj->Draw2(gSpec->hPtPhoDecay, "photonEt", phoDecayCut, "");
  
  // Obtain background subtracted spectra
  
  float candInt = gSpec->hPtPhoCand->Integral();
  float decayInt = gSpec->hPtPhoDecay->Integral();
  gSpec->hPtPhoSig->Reset();
  gSpec->hPtPhoSig->Add(gSpec->hPtPhoCand);
  gSpec->hPtPhoSig->Add(gSpec->hPtPhoDecay, -(1. - purity) * candInt / decayInt);
  gSpec->hPtPhoSig->Scale(1./purity ) ;
  
  TFile outf = TFile(Form("ffFiles/%s",outName.Data()),"update");
  gSpec->hPtPhoCand->Write();
  gSpec->hPtPhoDecay->Write();
  gSpec->hPtPhoSig->Write();
  outf.Close();
  
  
  // Objects
  multiTreeUtil* tObj[3];
  tObj[kTrkRaw] = new multiTreeUtil();
  tObj[kTrkBkg] = new multiTreeUtil();
  
  tObj[kTrkRaw]->addFile(fname,  "yTrk",  evtSeltCut,  1);
  tObj[kTrkBkg]->addFile(fname,  "mTrk",  evtSeltCut,  1);
  
  tObj[kTrkRaw]->AddFriend("tgj");
  tObj[kTrkBkg]->AddFriend("tgj");
  TCut trkCut     =  Form("abs(eta)<%f && pt>%f", (float)cuttrkEta, (float)cuttrkPt );
  
  TString varTrkDphi         = Form("dphi");

  corrFunctionTrk* cTrkDphi = new corrFunctionTrk();
  TH1D* hTrkDphi = new TH1D(Form("dphi_icent%d",icent),";#Delta#phi_{Jet,#gamma} ;dN/d#Delta#phi",20,0,3.141592);
  gammaTrkSingle( gSpec,  tObj, cTrkDphi,  purity, 
		  collision, varTrkDphi, trkCut, "pt",
		  phoCandCut, phoDecayCut,  hTrkDphi, outName);

  TH1D* hTrkDphi1to2GeV = new TH1D(Form("dphi_icent%d_pt1to2GeV",icent),";#Delta#phi_{Jet,#gamma} ;dN/d#Delta#phi",20,0,3.141592);
  corrFunctionTrk* cTrkDphi1to2GeV = new corrFunctionTrk();
  gammaTrkSingle( gSpec,  tObj, cTrkDphi1to2GeV,  purity, 
		  collision, varTrkDphi, trkCut && "pt > 1 && pt <=2", "pt",
		  phoCandCut, phoDecayCut,  hTrkDphi, outName);

  TH1D* hTrkDphi2to4GeV = new TH1D(Form("dphi_icent%d_pt2to4GeV",icent),";#Delta#phi_{Jet,#gamma} ;dN/d#Delta#phi",20,0,3.141592);
  corrFunctionTrk* cTrkDphi2to4GeV = new corrFunctionTrk();
  gammaTrkSingle( gSpec,  tObj, cTrkDphi2to4GeV,  purity, 
		  collision, varTrkDphi, trkCut && "pt > 2 && pt <=4", "pt",
		  phoCandCut, phoDecayCut,  hTrkDphi, outName);

  TH1D* hTrkDphi4to8GeV = new TH1D(Form("dphi_icent%d_pt4to8GeV",icent),";#Delta#phi_{Jet,#gamma} ;dN/d#Delta#phi",20,0,3.141592);
  corrFunctionTrk* cTrkDphi4to8GeV = new corrFunctionTrk();
  gammaTrkSingle( gSpec,  tObj, cTrkDphi4to8GeV,  purity, 
		  collision, varTrkDphi, trkCut && "pt > 4 && pt <=8", "pt",
		  phoCandCut, phoDecayCut,  hTrkDphi, outName);

  TH1D* hTrkDphi8andHighGeV = new TH1D(Form("dphi_icent%d_pt8andHighGeV",icent),";#Delta#phi_{Jet,#gamma} ;dN/d#Delta#phi",20,0,3.141592);
  corrFunctionTrk* cTrkDphi8andHighGeV = new corrFunctionTrk();
  gammaTrkSingle( gSpec,  tObj, cTrkDphi8andHighGeV,  purity, 
		  collision, varTrkDphi, trkCut && "pt > 8", "pt",
		  phoCandCut, phoDecayCut,  hTrkDphi, outName);


}
Exemple #15
0
void TExpenser::drawExpensesTab() {

    fExpensesTab = fTab->AddTab("Expenses");
    fExpensesTab -> SetLayoutManager(new TGHorizontalLayout(fExpensesTab));

    // Create the table
    createExpensesTableInterface();
    fTable = new TGTable(fExpensesTab, 999, fTableInterface, NROWSTABLE, fTableInterface->GetNColumns());
    fExpensesTab -> AddFrame(fTable, new TGLayoutHints(kLHintsCenterY,2,2,2,2));

    // create a frame holding all widgets on the right of the table
    TGVerticalFrame *hframe = new TGVerticalFrame(fExpensesTab, 500, 40);
    fExpensesTab -> AddFrame(hframe, new TGLayoutHints(kLHintsCenterX,2,2,2,2));

    // --------- New expense group --------- //
    TGGroupFrame *frame_new_expense = new TGGroupFrame(hframe, "New expense");
    frame_new_expense->SetTitlePos(TGGroupFrame::kLeft);
    frame_new_expense->SetTextFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1"); // when font too large, collides with group content....
    // frame_new_expense->SetTextColor(kBlue); // doesn't work unfortunately
    hframe->AddFrame(frame_new_expense, new TGLayoutHints(kLHintsExpandX));

    // expense amount entry field
    fAmountEntry = new TGNumberEntryField(frame_new_expense, 0, 0, TGNumberFormat::kNESRealTwo, TGNumberFormat::kNEAAnyNumber);
    frame_new_expense->AddFrame(fAmountEntry, new TGLayoutHints(kLHintsLeft,5,5,3,4));

    // date entry field
    TDatime time;
    fDateEntry = new TGNumberEntry(frame_new_expense, time.GetDate(), 10, -1, TGNumberFormat::kNESDayMYear, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, 20090101., 20200101);
    frame_new_expense->AddFrame(fDateEntry, new TGLayoutHints(kLHintsLeft,5,5,3,4));

    // withdrawn or not
    fWithdrawn = new TGComboBox(frame_new_expense,30);
    fWithdrawn->AddEntry("Not Withdrawn", 1);
    fWithdrawn->AddEntry("Withdrawn", 2);
    fWithdrawn->Select(1);
    fWithdrawn->Resize(150, 20);
    frame_new_expense->AddFrame(fWithdrawn, new TGLayoutHints(kLHintsLeft,5,10,5,5));

    // category selector
    fCategoryBox = new TGComboBox(frame_new_expense,100);
    for (unsigned i = 0; i < NCATEGORIES; i++) {
        fCategoryBox->AddEntry(CATEGORIES[i], i+1);
    }
    fCategoryBox->Resize(150, 20);
    fCategoryBox->Select(1);
    frame_new_expense->AddFrame(fCategoryBox, new TGLayoutHints(kLHintsLeft,5,10,5,5));

    // description field
    fDescription = new TGTextEntry(frame_new_expense, "");
    fDescription -> SetToolTipText("Description");
    fDescription -> Resize(200, fDescription->GetDefaultHeight());
    frame_new_expense -> AddFrame(fDescription, new TGLayoutHints(kLHintsLeft, 5,5,5,5));

    // add-button
    TGTextButton * add_button = new TGTextButton(frame_new_expense,"&Add Expense");
    add_button -> Connect("Clicked()", "TExpenser", this, "add()");
    add_button  ->  SetFont("-*-times-bold-r-*-*-28-*-*-*-*-*-*-*");
    frame_new_expense -> AddFrame(add_button, new TGLayoutHints(kLHintsLeft,5,5,3,4));

    // --------- Withdrawing group --------- //
    TGGroupFrame *frame_withdrawn = new TGGroupFrame(hframe, "Withdrawing");
    frame_withdrawn->SetTitlePos(TGGroupFrame::kLeft);
    frame_withdrawn->SetTextFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1"); // when font too large, collides with group content....
    hframe->AddFrame(frame_withdrawn, new TGLayoutHints(kLHintsExpandX));

    // withdrawn id entry field and withdrawn button
    TGHorizontalFrame *hframe1 = new TGHorizontalFrame(frame_withdrawn, 500, 40);
    frame_withdrawn -> AddFrame(hframe1,new TGLayoutHints(kLHintsLeft,5,5,3,4));
    fWithdrawnIdEntry = new TGNumberEntryField(hframe1, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber);
    hframe1->AddFrame(fWithdrawnIdEntry, new TGLayoutHints(kLHintsLeft|kLHintsExpandY,5,5,3,4));
    TGTextButton * withdrawn_button = new TGTextButton(hframe1,"&Withdrawn");
    withdrawn_button ->  SetFont("-*-times-bold-r-*-*-28-*-*-*-*-*-*-*");
    hframe1->AddFrame(withdrawn_button, new TGLayoutHints(kLHintsLeft,5,5,3,4));
    withdrawn_button -> Connect("Clicked()", "TExpenser", this, "set_withdrawn()");

    // commit-button
    TGTextButton * commit_button = new TGTextButton(hframe,"&Commit");
    commit_button -> Connect("Clicked()", "TExpenser", this, "commit()");
    commit_button -> SetFont("-*-times-bold-r-*-*-28-*-*-*-*-*-*-*");
    hframe -> AddFrame(commit_button, new TGLayoutHints(kLHintsLeft,5,5,3,4));

    // --------- Filter group --------- //
    TGGroupFrame *frame_filter = new TGGroupFrame(hframe, "Filter");
    frame_filter->SetTitlePos(TGGroupFrame::kLeft);
    frame_filter->SetTextFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1"); // when font too large, collides with group content....
    hframe->AddFrame(frame_filter, new TGLayoutHints(kLHintsExpandX));

    // filter category selector
    fFilterCategoryBox = new TGComboBox(frame_filter, 100);
    fFilterCategoryBox->AddEntry("Select Category", 1);
    for (unsigned i = 1; i < NCATEGORIES+1; i++) {
        fFilterCategoryBox->AddEntry(CATEGORIES[i], i+1);
    }
    fFilterCategoryBox->Resize(150, 20);
    fFilterCategoryBox->Select(1);
    frame_filter->AddFrame(fFilterCategoryBox, new TGLayoutHints(kLHintsLeft,5,10,5,5));

    // month selector
    fFilterMonthBox = new TGComboBox(frame_filter);
    fFilterMonthBox -> AddEntry("Select Month", 1);
    for (unsigned i = 0; i < 12; i++) {
        fFilterMonthBox->AddEntry(MONTHS[i], i+2);
    }
    fFilterMonthBox->Select(1);
    fFilterMonthBox->Resize(150, 20);
    frame_filter->AddFrame(fFilterMonthBox, new TGLayoutHints(kLHintsLeft,5,10,5,5));

    // year selector
    fFilterYearBox = new TGComboBox(frame_filter);
    fFilterYearBox -> AddEntry("Select Year", 1);
    for (unsigned i = FIRST_YEAR; i <= LAST_YEAR; i++) {
        fFilterYearBox->AddEntry(toStr(i), i+2-FIRST_YEAR);
    }
    fFilterYearBox->Resize(100, 20);
    fFilterYearBox->Select(1);
    frame_filter->AddFrame(fFilterYearBox, new TGLayoutHints(kLHintsLeft,5,10,5,5));

    // withdrawn/not withdrawn selector
    fFilterWithdrawnBox = new TGComboBox(frame_filter);
    fFilterWithdrawnBox -> AddEntry("Select Withdrawn", 1);
    fFilterWithdrawnBox->AddEntry("Withdrawn", 2);
    fFilterWithdrawnBox->AddEntry("Not Withdrawn", 3);
    fFilterWithdrawnBox->Resize(100, 20);
    fFilterWithdrawnBox->Select(1);
    frame_filter->AddFrame(fFilterWithdrawnBox, new TGLayoutHints(kLHintsLeft,5,10,5,5));

    // description filtering - text field
    fFilterDescriptionEntry = new TGTextEntry(frame_filter, "");
    fFilterDescriptionEntry -> SetToolTipText("Filter Description");
    fFilterDescriptionEntry -> Resize(200, fFilterDescriptionEntry->GetDefaultHeight());
    frame_filter -> AddFrame(fFilterDescriptionEntry, new TGLayoutHints(kLHintsLeft, 5,5,5,5));

    TGHorizontalFrame *hframe2 = new TGHorizontalFrame(frame_filter, 500, 40);
    frame_filter -> AddFrame(hframe2,new TGLayoutHints(kLHintsLeft,5,5,3,4));

    TGTextButton * filter_button = new TGTextButton(hframe2,"&Filter");
    filter_button -> Connect("Clicked()", "TExpenser", this, "filter_expense_table()");
    filter_button -> SetFont("-*-times-bold-r-*-*-28-*-*-*-*-*-*-*");
    hframe2 -> AddFrame(filter_button, new TGLayoutHints(kLHintsLeft,5,5,3,4));

    TGTextButton * undo_filter_button = new TGTextButton(hframe2,"&Undo Filters");
    undo_filter_button -> Connect("Clicked()", "TExpenser", this, "undo_filters_expense_table()");
    undo_filter_button -> SetFont("-*-times-bold-r-*-*-28-*-*-*-*-*-*-*");
    hframe2 -> AddFrame(undo_filter_button, new TGLayoutHints(kLHintsLeft,15,5,3,4));
}
Exemple #16
0
//
// main function
//
void DoOneProcess(TString InputCfAName, TString ProcessName, float weight) { 
    
    // 
    // Get tree 
    // 
    TChain * chainA = new TChain("/configurableAnalysis/eventA");   
    TChain * chainB = new TChain("/configurableAnalysis/eventB");   
    chainA->Add(InputCfAName);
    chainB->Add(InputCfAName);
  
    InitializeA(chainA);
    InitializeB(chainB);

    // 
    // histograms
    // 
    TH1F *h1_result       = new TH1F("h1_result","h1_result", 1, 0, 1);
    
    //
    // main event loop
    //
    Int_t nentries = (Int_t)chainA->GetEntries();
    cout<<"The number of entries is: "<<nentries<<endl;
    // Progress tracking 
    int i_permille_old = 0; 
    TDatime DTStart;
    int StartDate = DTStart.GetDate(); 
    int StartTime = DTStart.GetTime(); 
    cout << "Start time : " << StartTime << endl; 
    
    for(int i = 0; i<nentries; i++) {

        // Progress tracking begin -------------------------------- 
        int i_permille = (int)floor(1000 * i / float(nentries));
        TDatime DTCurrent;
        int CurrentDate = DTCurrent.GetDate();
        int CurrentTime = DTCurrent.GetTime();
        int TimeLaps = (CurrentDate-StartDate)*1000000+(CurrentTime-StartTime);
        int TimeToRun = (float)nentries/(float)i*TimeLaps;
        if (i_permille != i_permille_old) {
            // xterm magic from L. Vacavant and A. Cerri
            if (isatty(1)) {
                printf("\015\033[32m Processed :: \033[1m\033[31m%4.1f %%" 
                       "\033[0m\033[32m   Expected processing time :: \033[1m\033[31m%i:%i:%i \033[0m\015",
                        i_permille/10., (TimeToRun/10000)%100<60 ? (TimeToRun/10000)%100 : (TimeToRun/10000)%100-40, 
                                        (TimeToRun/100)%100<60 ? (TimeToRun/100)%100 : (TimeToRun/100)%100-40, 
                                        (TimeToRun%100)<60 ? (TimeToRun)%100 : (TimeToRun)%100-40 );
                fflush(stdout);
            }
            i_permille_old = i_permille;
        } 
        // Progress tracking end ----------------------------------
        
        // get an entry of an event 
        chainA->GetEntry(i);
        chainB->GetEntry(i);
        
        //
        // Core analysis 
        //

        // Getting good muons
        vector<int> RA4MuonVeto; RA4MuonVeto.clear();
        vector<int> RA4Muon = GetRA4Muon(RA4MuonVeto);
        // Getting good electrons
        vector<int> RA4ElecVeto; RA4ElecVeto.clear();
        vector<int> RA4Elec = GetRA4Elec(RA4ElecVeto, "", 0, true);
        // Containers for B-tagged jets 
        vector<int> LooseBJet; 
        vector<int> MediumBJet; 
        // HT
        double HT=-999.; 
        // MJ 
        vector<float> Vector_mj;   // mj
        double MJ=-999.; 

        // Getting good skinny jets 
        vector<int> GoodJets_AK5PFclean = GetJets(RA4Muon,RA4Elec,RA4MuonVeto,RA4ElecVeto,
                                                  HT,LooseBJet,MediumBJet, 
                                                  2.4, 30, 0.3); 
        for(int i=0; i<GoodJets_AK5PFclean.size(); i++) cout << event << " :: " << GoodJets_AK5PFclean.at(i) << endl;
       

        h1_result->Fill(0.5);

        /* 
        // variables 
        vector<float> Vector_mj;   // mj
        float MJ=0;
        int Nfastjets=0;
        for(int ifastjet=0; ifastjet<(int)fastjets_AK5PF_px_->size(); ifastjet++) {
            
            // Number of jets 
            float pT = TMath::Sqrt( fastjets_AK5PF_px_->at(ifastjet)*fastjets_AK5PF_px_->at(ifastjet)
                                   +fastjets_AK5PF_py_->at(ifastjet)*fastjets_AK5PF_py_->at(ifastjet));

            float temp_mj = Getmj(fastjets_AK5PF_px_->at(ifastjet), fastjets_AK5PF_py_->at(ifastjet),
                                  fastjets_AK5PF_pz_->at(ifastjet), fastjets_AK5PF_energy_->at(ifastjet));

            Vector_mj.push_back(temp_mj); 
            if(Npv_ > 25) {
                h1_mj_fastjets_Npv26toInf->Fill(temp_mj);
            } else if(Npv_>15) {
                h1_mj_fastjets_Npv16to25->Fill(temp_mj);
            } else {
                h1_mj_fastjets_Npv0to15->Fill(temp_mj);
            }
            Nfastjets++;
        }

        // Get MJ        
        MJ = GetMJ(Vector_mj);

        // fill histogram for MJ and Njets
        if(Npv_ > 25) {
            h1_njets_fastjets_Npv26toInf->Fill( TMath::Min((Float_t)Nfastjets,(Float_t)29.499) );
            h1_MJ_fastjets_Npv26toInf->Fill(MJ);
        } else if(Npv_>15) {
            h1_njets_fastjets_Npv16to25->Fill( TMath::Min((Float_t)Nfastjets,(Float_t)29.499) );
            h1_MJ_fastjets_Npv16to25->Fill(MJ);
        } else {
            h1_njets_fastjets_Npv0to15->Fill( TMath::Min((Float_t)Nfastjets,(Float_t)29.499) );
            h1_MJ_fastjets_Npv0to15->Fill(MJ);
        }
       */
    
    } // event loop
    cout << endl;
    cout << "... Looping events done" << endl;

    //
    // Write the result 
    //
    TString ResultFileName = ProcessName+".root";
    //TString ResultFileName = InputCfAName;
    //ResultFileName.ReplaceAll(".root", "");
    //ResultFileName.ReplaceAll("/", "_");
    //ResultFileName = "Result_"+ResultFileName+".root";
    //ResultFileName.ReplaceAll("__", "_");
    cout << "Writing " << ResultFileName << endl;
    TFile *ResultFile = new TFile(ResultFileName, "RECREATE");
    gROOT->cd();
    ResultFile->cd();
    h1_result->SetDirectory(0);  h1_result->Write();
    ResultFile->Close();
    
    TDatime DTEnd;
    int EndTime = DTEnd.GetTime(); 
    cout << "End time : " << EndTime << endl; 

    // cleanup
    delete chainA;
    delete chainB;
    delete ResultFile;
}
Exemple #17
0
void RAA_plot_SVD_unfolding_check(int radius = 3, char * etaWidth = (char*)"n20_eta_p20"){

  TStopwatch timer;
  timer.Start();

  TDatime date;

  gStyle->SetOptStat(0);

  TH1::SetDefaultSumw2();
  TH2::SetDefaultSumw2();

  // get the input SVD files and histograms
  //Int_t nSVDIter[nSVD] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
  Int_t nSVDIter[nSVD] = {12,13,14,15,16,17,18};
  TFile * fin[nSVD];
  TFile * fPbPb_MCin;
  TFile * fPP_MCin;
  fPbPb_MCin = TFile::Open(Form("../../Output/PbPb_MC_closure_histogram_deltaR_0p2_akPu%d_20150423.root",radius));
  fPP_MCin = TFile::Open(Form("../../Output/pp_MC_closure_histogram_deltaR_0p2_ak%d_20150423.root",radius));
  TH1F * hSVD[nSVD][nbins_cent], * hData[nbins_cent];
  TH1F * hSVD_pp[nSVD], * hData_pp;
  TH1F * hSVD_MC[nSVD][nbins_cent], * hGen[nbins_cent];
  TH1F * hSVD_MC_pp[nSVD], * hGen_pp;
  TH2F * hmatrix[nbins_cent];
  TH1F * hMC_Closure[nSVD][nbins_cent];
  TH1F * hMC_Closure_pp[nSVD];

  TFile * fPbPb_in = TFile::Open(Form("../../Output/Pawan_ntuple_PbPb_data_MC_spectra_JetID_CutA_analysisbins_%s_R0p%d.root",etaWidth,radius));
  TFile * fPP_in = TFile::Open(Form("../../Output/Pawan_ntuple_PP_data_MC_spectra_residualFactor_analysisbins_%s_R0p%d.root",etaWidth,radius));
  
  for(int j = 0; j<nSVD; ++j){
    cout<<"resolution parameter j = "<<nSVDIter[j]<<endl;
    for(int i = 0; i<nbins_cent; ++i){
      cout<<"centrality bin = "<<i<<endl;
      fin[j] = TFile::Open(Form("../../Output/svd_unfolding_matrix_param%d_%s_R%d_20150501.root",nSVDIter[j], etaWidth,radius));
      if(j==0) hmatrix[i] = (TH2F*)fPbPb_in->Get(Form("hpbpb_matrix_R%d_%s_cent%d",radius,etaWidth,i));
      if(j==0) hData[i] = (TH1F*)fin[j]->Get(Form("hpbpb_HLTComb_R%d_%s_cent%d",radius,etaWidth,i));
      if(j==0) hGen[i] = (TH1F*)hmatrix[i]->ProjectionX();
      hSVD[j][i] = (TH1F*)fin[j]->Get(Form("PbPb_SVD_unfolding_cent%d",i));
      //hSVD_MC[j][i] = (TH1F*)fin[j]->Get(Form("PbPb_MC_SVD_unfolding_cent%d",i));
      //hMC_Closure[j][i] = (TH1F*)hSVD_MC[j][i]->Clone(Form("hSVD_Closure_iter%d_cent%d",j,i));
      //hMC_Closure[j][i]->Divide(hGen[i]);

    }

    hSVD_pp[j] = (TH1F*)fin[j]->Get("PP_SVD_unfolding");
    //hSVD_MC_pp[j] = (TH1F*)fin[j]->Get("PP_MC_SVD_unfolding_cent%d");
    if(j==0)hData_pp = (TH1F*)fin[j]->Get(Form("hpp_HLTComb_R%d_%s",radius,etaWidth));
    //if(j==0)hGen_pp = (TH1F*)fPP_MCin->Get(Form("hpp_mcclosure_gen_JetComb_R%d_%s",radius,etaWidth));
    //hMC_Closure_pp[j] = (TH1F*)hSVD_MC_pp[j]->Clone(Form("hSVD_Closure_PP_iter%d",j));
    //hMC_Closure_pp[j]->Divide(hGen_pp);
    
  }

  // Start plotting the curves in 6 different centrality bins.
  TCanvas * cSVD_check = new TCanvas("cSVD_check","",1200,1000);
  makeMultiPanelCanvasWithGap(cSVD_check,3,2,0.01,0.01,0.16,0.2,0.04,0.04);

  TLegend * leg = myLegend(0.5,0.55,0.7,0.95);
  for(int i = 0; i<nbins_cent; ++i){

    cSVD_check->cd(nbins_cent-i);
    cSVD_check->cd(nbins_cent-i)->SetLogy();
    cSVD_check->cd(nbins_cent-i)->SetLogx();

    hData[i]->SetMarkerStyle(20);
    hData[i]->SetMarkerColor(kBlack);
    hData[i]->SetAxisRange(40,300,"X");
    hData[i]->SetAxisRange(1e-2,1e7,"Y");
    makeHistTitle(hData[i]," ", " ak R=0.3 Jet p_{T} (GeV/c) " ,"counts");
    hData[i]->Draw();
    drawText(Form("%2.0f-%2.0f%%",2.5*boundaries_cent[i],2.5*boundaries_cent[i+1]),0.8,0.85,20);
    for(int j = 0; j<nSVD; ++j){

      hSVD[j][i]->SetMarkerStyle(24+j);
      hSVD[j][i]->SetMarkerColor(j+2);
      hSVD[j][i]->Draw("same");

      if(i==0)leg->AddEntry(hSVD[j][i],Form("k = %d",nSVDIter[j]),"pl");

    }

  }

  cSVD_check->cd(1);
  putCMSPrel();
  leg->Draw();

  cSVD_check->cd(2);
  drawText("SVD unfolding",0.2,0.2,14);

  cSVD_check->SaveAs(Form("../../Plots/SVD_unfolding_%d_iteration_check_R%d_%d.pdf",nSVD,radius,date.GetDate()),"RECREATE");
  
#if 0
  // plot the MC closure for PbPb

  TCanvas * cClosure_PbPb = new TCanvas("cClosure_PbPb","",1200,1000);
  makeMultiPanelCanvasWithGap(cClosure_PbPb,3,2,0.01,0.01,0.16,0.2,0.04,0.04);
  TLegend * mcclo = myLegend(0.4,0.1,0.7,0.9);
  for(int i = 0; i<nbins_cent; ++i){

    cClosure_PbPb->cd(nbins_cent-i);
    for(int j = 0; j<nSVD; ++j){

      hMC_Closure[j][i]->SetMarkerStyle(24);
      hMC_Closure[j][i]->SetMarkerColor(j+1);
      hMC_Closure[j][i]->SetAxisRange(0,2,"Y");
      hMC_Closure[j][i]->SetAxisRange(30,300,"X");
      makeHistTitle(hMC_Closure[j][i]," ", " ak R=0.3 Jet p_{T} (GeV/c) " ,"Reco/Truth");

      if(j==0) hMC_Closure[j][i]->Draw();
      if(i==0) mcclo->AddEntry(hMC_Closure[j][i],Form("k = %d",nSVDIter[j]),"pl");
      hMC_Closure[j][i]->Draw("same");
    }
    drawText(Form("%2.0f-%2.0f%%",2.5*boundaries_cent[i],2.5*boundaries_cent[i+1]),0.8,0.85,20);
    
  }
  cClosure_PbPb->cd(1);
  putCMSPrel();
  mcclo->Draw();
  
  cClosure_PbPb->cd(2);
  drawText("SVD Unfolding",0.2,0.2,14);

  cClosure_PbPb->SaveAs(Form("../../Plots/SVD_unfolding_%d_mcclosure_same_check_R%d_%d.pdf",nSVD,radius,date.GetDate()),"RECREATE");
#endif

  // Do the spectra check for pp and PP mc closure.
  // Start plotting the curves in 6 different centrality bins.
  TCanvas * cSVD_check_pp = new TCanvas("cSVD_check_pp","",1200,1000);
  TLegend * leg_pp = myLegend(0.5,0.55,0.7,0.95);
  cSVD_check_pp->SetLogy();
  cSVD_check_pp->SetLogx();
  hData_pp->SetMarkerStyle(20);
  hData_pp->SetMarkerColor(kBlack);
  hData_pp->SetAxisRange(40,400,"X");
  hData_pp->SetAxisRange(1e-2,1e7,"Y");
  makeHistTitle(hData_pp," ", " ak R=0.3 Jet p_{T} (GeV/c) " ,"counts");
  hData_pp->Draw();
  for(int j = 0; j<nSVD; ++j){

    hSVD_pp[j]->SetMarkerStyle(24+j);
    hSVD_pp[j]->SetMarkerColor(j+2);
    hSVD_pp[j]->Draw("same");

    leg->AddEntry(hSVD_pp[j],Form("k = %d",nSVDIter[j]),"pl");

  }
  putCMSPrel();
  leg_pp->Draw();

  drawText("SVD unfolding pp",0.2,0.2,14);

  cSVD_check_pp->SaveAs(Form("../../Plots/SVD_unfolding_%d_iteration_check_pp_R%d_%d.pdf",nSVD,radius,date.GetDate()),"RECREATE");
  
#if 0
  // plot the MC closure for PbPb

  TCanvas * cClosure_pp = new TCanvas("cClosure_pp","",1200,1000);
  TLegend * mcclo_pp = myLegend(0.4,0.1,0.7,0.9);

  for(int j = 0; j<nSVD; ++j){
    
    hMC_Closure_pp[j]->SetMarkerStyle(24);
    hMC_Closure_pp[j]->SetMarkerColor(j+1);
    hMC_Closure_pp[j]->SetAxisRange(0,2,"Y");
    hMC_Closure_pp[j]->SetAxisRange(30,300,"X");
    makeHistTitle(hMC_Closure_pp[j]," ", " ak R=0.3 Jet p_{T} (GeV/c) " ,"Reco/Truth");
    
    if(j==0) hMC_Closure_pp[j]->Draw();
    mcclo_pp->AddEntry(hMC_Closure_pp[j],Form("k = %d",nSVDIter[j]),"pl");
    hMC_Closure_pp[j]->Draw("same");
  }
  
  putCMSPrel();
  mcclo_pp->Draw();
  
  drawText("SVD Unfolding pp",0.2,0.2,14);

  cClosure_pp->SaveAs(Form("../../Plots/SVD_unfolding_%d_mcclosure_same_check_pp_R%d_%d.pdf",nSVD,radius,date.GetDate()),"RECREATE");
#endif
  
  //
  timer.Stop();
  cout<<" Total time taken CPU = "<<timer.CpuTime()<<endl;
  cout<<" Total time taken Real = "<<timer.RealTime()<<endl;

}
void RAA_plot_YenJie_CutfromMinBias(char* etaWidth = (char*)"10_eta_18", char * etaLabel = (char*) "1.0 < |#eta| < 1.8", Int_t radius = 3){

  TStopwatch timer;
  gStyle->SetOptStat(0);
  TH1::SetDefaultSumw2();

  cout<<"etaWidth = "<<etaWidth<<" etaLabel="<<etaLabel<<endl;
  bool isAnalysisBin = false; 

  TDatime date;
  
  TFile * fMinBias, * fJetTrig;

  fMinBias = TFile::Open(Form("Pawan_ntuple_PbPb_MinBiasData_spectra_JetID_CutA_finebins_CentralityWeighted_%s_R0p%d.root",etaWidth,radius));
  fJetTrig = TFile::Open(Form("/export/d00/scratch/rkunnawa/rootfiles/RAA/Pawan_ntuple_PbPb_data_MC_subid0_spectra_JetID_CutA_finebins_%s_R0p%d.root",etaWidth,radius));

  // get the histograms
  TH1F * hJetTrigComb[nbins_cent], * hMinBias[nbins_cent];
  TH1F * hSubtracted[nbins_cent];
  Float_t bin_no = 1;

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

    hJetTrigComb[i] = (TH1F*)fJetTrig->Get(Form("hpbpb_HLTComb_R%d_%s_cent%d",radius,etaWidth,i));
     hMinBias[i]     = (TH1F*)fMinBias->Get(Form("hpbpb_noTrg_R%d_%s_cent%d",radius,etaWidth,i));



    // rebin the histograms (maybe, commented out for now, since we are doing the analysis in fine bins) and normalize them here to the bin width of the first pT bin for the analysis: around 15 GeV

    // the input to the datadrivenunfolding takes in analysis bins input, so for that you need to rebin these histograms. but then for RAA_analyze.C the input is fine bins, so you need to rerun this without the rebinning. 
    if(isAnalysisBin){
      hJetTrigComb[i] = (TH1F*)hJetTrigComb[i]->Rebin(nbins_cent, Form("hpbpb_HLTComb_R%d_%s_cent%d",radius,etaWidth,i), boundaries_cent);
      divideBinWidth(hJetTrigComb[i]);
      hMinBias[i] = (TH1F*)hMinBias[i]->Rebin(nbins_cent, Form("hpbpb_noTrg_R%d_%s_cent%d",radius,etaWidth,i), boundaries_cent);
      divideBinWidth(hMinBias[i]);
    }

    // find the bin number of 15 GeV
    bin_no = hJetTrigComb[i]->FindBin(15);
    
    cout<<"bin no"<<bin_no<<endl;

    // set all the entries before bin no 15 to be zero.
    for(int j = 1; j<bin_no; ++j){
      hJetTrigComb[i]->SetBinContent(j,0);
      hJetTrigComb[i]->SetBinError(j,0);
      hMinBias[i]->SetBinContent(j,0);
      hMinBias[i]->SetBinError(j,0);
    }

    float scaleweight=hJetTrigComb[i]->GetBinContent(bin_no)/hMinBias[i]->GetBinContent(bin_no);

    cout<<" weight  "<<scaleweight<<endl;
    // normalize the histogram by the jet entries in bin of pT = 15.
    //    hJetTrigComb[i]->Scale(1./hJetTrigComb[i]->GetBinContent(bin_no));
    //    hMinBias[i]->Scale(1./hMinBias[i]->GetBinContent(bin_no));
    hMinBias[i]->Scale(scaleweight);


    hSubtracted[i]  = (TH1F*)hJetTrigComb[i]->Clone(Form("hFakeMinBias_SubtractedFrom_Data_R%d_%s_cent%d",radius, etaWidth, i));
    hSubtracted[i]->Add(hMinBias[i], -1);
    //    hSubtracted[i]->Draw();

    cout<<"working here  i value:   "<<i<<endl;  
  }


  // make the plots: just a 3x2 panel plot showing all the above three curves and write to output.
  TH2F * hBlankSpectra = new TH2F("hBlankSpectra","",400,0,350,100,1e-1,5e6);
   TCanvas * cFakeSub = new TCanvas("cFakeSub","",1000,800);
   makeMultiPanelCanvasWithGap(cFakeSub,3,2,0.01,0.01,0.16,0.2,0.04,0.04);
   //cFakeSub->Divide(3,2);
   

  TLegend * lSub = myLegend(0.5,0.5,0.7,0.7);
 makeHistTitle(hBlankSpectra," ","Jet p_{T} (GeV/c)","Counts normalized to ptbin = 15 GeV");
  // hBlankSpectra->GetYaxis()->SetNdivisions(1000); 
  hBlankSpectra->GetYaxis()->SetMoreLogLabels(kFALSE);
  hBlankSpectra->GetYaxis()->SetTitleOffset(2.5);


  // 
for(int i = 0; i<6; ++i){
  cout<< "    i values "<<i<<endl;

    cFakeSub->cd(6-i);
    cFakeSub->cd(6-i)->SetLogy();
    hBlankSpectra->Draw();
    
    hJetTrigComb[i]->SetMarkerStyle(24);    
    hJetTrigComb[i]->SetMarkerColor(kBlack);
    hJetTrigComb[i]->SetAxisRange(13,299,"X");
//    makeHistTitle(hJetTrigComb[i]," ","Jet p_{T} (GeV/c)","Counts normalized to ptbin = 15 GeV");
    hJetTrigComb[i]->Draw("same");

    hMinBias[i]->SetMarkerStyle(24);    
    hMinBias[i]->SetMarkerColor(kRed);
    hMinBias[i]->Draw("same");

    hSubtracted[i]->SetMarkerStyle(27);    
    hSubtracted[i]->SetMarkerColor(kBlue);
    hSubtracted[i]->Draw("same");
    //cout<<"working here   too"<<endl; 
    drawText(Form("%2.0f-%2.0f%%",2.5*boundaries_cent[i],2.5*boundaries_cent[i+1]),0.7,0.9,20);    
    if(i==4){   drawText(Form("|vz|<15, %s",etaLabel),0.3,0.8,20); }
  }


  cFakeSub->cd(1);
  putCMSPrel(0.2,0.92,0.04);
  drawText(Form("Anti-k_{T} PuPF Jets R=0.%d",radius),0.2,0.8,20);

  
  lSub->AddEntry(hJetTrigComb[0],"Jet Triggered Data","pl");
  lSub->AddEntry(hMinBias[0],"MinBias data","pl");
  lSub->AddEntry(hSubtracted[0],"Jet Triggered - MinBias","pl");
  lSub->SetTextSize(0.04);
  lSub->Draw();
 
  cFakeSub->SaveAs(Form("PbPb_FakeMinBias_SubtractedFrom_Data_R%d_%s_%d.pdf",radius, etaWidth, date.GetDate()),"RECREATE");
  
  //  create output root file to write the output histogram. 
  TFile fout(Form("PbPb_FakeMinBias_SubtractedFrom_Data_R%d_%s_%d.root",radius, etaWidth, date.GetDate()),"RECREATE");
  fout.cd();

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

  hSubtracted[i]->Write();
  hJetTrigComb[i]->Write();
  hMinBias[i]->Write();

  }

  fout.Close();

  //macro end. 
  timer.Stop();
  cout<<"Macro finished: "<<endl;
  cout<<"CPU time (min)  = "<<(Float_t)timer.CpuTime()/60<<endl;
  cout<<"Real time (min) = "<<(Float_t)timer.RealTime()/60<<endl;
  
}
Exemple #19
0
void RAA_plot_finalpaper(Int_t unfoldingCut = 40 , char *algo = "Pu", char *jet_type = "PF"){
    
  TStopwatch timer;
  timer.Start();

  TDatime date;

  gStyle->SetOptStat(0);

  TH1::SetDefaultSumw2();
  TH2::SetDefaultSumw2();

  char * etaWidth = (char*) "10_eta_10";
  char * etaLable = (char*) "0.0 < |eta| < 1.0";
  Float_t etaLow = 0;
  Float_t etaHigh = 1.0;
  Float_t deltaEta = 2.0; 

  TFile *fin_R2, *fin_R3, *fin_R4; 
  fin_R2 = TFile::Open(Form("/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_20/src/Output/Pawan_ntuple_PbPb_pp_calopfpt_ppNoJetidcut_R0p%d_noFakeWeight_unfold_mcclosure_oppside_trgMC_%s_%dGeVCut_ak%s_20150506.root",2,etaWidth,unfoldingCut,jet_type));
  fin_R3 = TFile::Open(Form("/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_20/src/Output/Pawan_ntuple_PbPb_pp_calopfpt_ppNoJetidcut_R0p%d_noFakeWeight_unfold_mcclosure_oppside_trgMC_%s_%dGeVCut_ak%s_20150506.root",3,etaWidth,unfoldingCut,jet_type));
  fin_R4 = TFile::Open(Form("/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_20/src/Output/Pawan_ntuple_PbPb_pp_calopfpt_ppNoJetidcut_R0p%d_noFakeWeight_unfold_mcclosure_oppside_trgMC_%s_%dGeVCut_ak%s_20150506.root",4,etaWidth,unfoldingCut,jet_type));

  // get the histograms.
  TH1F * uPbPb_R2_Bayes[nbins_cent], * uPP_R2_Bayes, * uPbPb_R3_Bayes[nbins_cent], * uPP_R3_Bayes, * uPbPb_R4_Bayes[nbins_cent], * uPP_R4_Bayes;
  TH1F * mPbPb_R2[nbins_cent], * mPP_R2, * mPbPb_R3[nbins_cent], * mPP_R3, * mPbPb_R4[nbins_cent], * mPP_R4;
  
  TH1F * RAA_R2_Bayes[nbins_cent], * RAA_R3_Bayes[nbins_cent], * RAA_R4_Bayes[nbins_cent];
  TH1F * RAA_R2_BinByBin[nbins_cent], * RAA_R3_BinByBin[nbins_cent], * RAA_R4_BinByBin[nbins_cent];
  TH1F * RAA_R2_Meas[nbins_cent], * RAA_R3_Meas[nbins_cent], * RAA_R4_Meas[nbins_cent];

  uPP_R2_Bayes = (TH1F*)fin_R2->Get("PP_bayesian_unfolded_spectra");
  uPP_R2_Bayes->Print("base");
  uPP_R3_Bayes = (TH1F*)fin_R3->Get("PP_bayesian_unfolded_spectra");
  uPP_R3_Bayes->Print("base");
  uPP_R4_Bayes = (TH1F*)fin_R4->Get("PP_bayesian_unfolded_spectra");
  uPP_R4_Bayes->Print("base");

  mPP_R2 = (TH1F*)fin_R2->Get("PP_Gen_spectra_refpt");
  mPP_R2->Print("base");
  mPP_R3 = (TH1F*)fin_R3->Get("PP_Gen_spectra_refpt");
  mPP_R3->Print("base");
  mPP_R4 = (TH1F*)fin_R4->Get("PP_Gen_spectra_refpt");
  mPP_R4->Print("base");
  
  for(int i = 0; i<nbins_cent; ++i){

    uPbPb_R2_Bayes[i] = (TH1F*)fin_R2->Get(Form("PbPb_bayesian_unfolded_spectra_combined_cent%d",i));
    uPbPb_R2_Bayes[i]->Print("base");
    uPbPb_R3_Bayes[i] = (TH1F*)fin_R3->Get(Form("PbPb_bayesian_unfolded_spectra_combined_cent%d",i));
    uPbPb_R3_Bayes[i]->Print("base");
    uPbPb_R4_Bayes[i] = (TH1F*)fin_R4->Get(Form("PbPb_bayesian_unfolded_spectra_combined_cent%d",i));
    uPbPb_R3_Bayes[i]->Print("base");
 
    mPbPb_R2[i] = (TH1F*)fin_R2->Get(Form("PbPb_Gen_spectra_refpt_cent%d",i));
    mPbPb_R2[i]->Print("base");
    mPbPb_R3[i] = (TH1F*)fin_R3->Get(Form("PbPb_Gen_spectra_refpt_cent%d",i));
    mPbPb_R3[i]->Print("base");
    mPbPb_R4[i] = (TH1F*)fin_R4->Get(Form("PbPb_Gen_spectra_refpt_cent%d",i));
    mPbPb_R4[i]->Print("base");
    
    RAA_R2_Bayes[i]   = (TH1F*)fin_R2->Get(Form("RAA_bayesian_cent%d",i));  
    RAA_R2_Bayes[i]->Print("base");
    RAA_R3_Bayes[i]   = (TH1F*)fin_R3->Get(Form("RAA_bayesian_cent%d",i));  
    RAA_R3_Bayes[i]->Print("base");
    RAA_R4_Bayes[i]   = (TH1F*)fin_R4->Get(Form("RAA_bayesian_cent%d",i));  
    RAA_R4_Bayes[i]->Print("base");
    
    RAA_R2_BinByBin[i]   = (TH1F*)fin_R2->Get(Form("RAA_binbybin_cent%d",i));  
    RAA_R3_BinByBin[i]   = (TH1F*)fin_R3->Get(Form("RAA_binbybin_cent%d",i));  
    RAA_R4_BinByBin[i]   = (TH1F*)fin_R4->Get(Form("RAA_binbybin_cent%d",i));  
    
    RAA_R2_Meas[i]   = (TH1F*)fin_R2->Get(Form("RAA_measured_cent%d",i));  
    RAA_R3_Meas[i]   = (TH1F*)fin_R3->Get(Form("RAA_measured_cent%d",i));  
    RAA_R4_Meas[i]   = (TH1F*)fin_R4->Get(Form("RAA_measured_cent%d",i));  
    
  }
  
  // plot 1 - spectra plot showing pp and 6 different centrality classes PbPb spectra
  //        - have a 3 panel plot for the different radii, with each of them scaled by two orders of magnitude 

  // first we need to scale the MC to the level of Data:
  // PbPb Data scaling:
  //   uPbPb_Bayes[i]->Scale(1./deltaEta);// delta eta
  //   //uPbPb_Bayes[i]->Scale(1./145.156/1e6);// Jet 80 luminosity
  //   //uPbPb_Bayes[i]->Scale(1./1.1153/1e6);// equivalent no of minbias events 
  //   uPbPb_Bayes[i]->Scale(1./(0.025*(boundaries_cent[i+1] - boundaries_cent[i])));
  //   //uPbPb_Bayes[i]->Scale(1./145.156);
  //   //uPbPb_Bayes[i]->Scale(1./161.939);
  //   uPbPb_Bayes[i]->Scale(1./(7.65*1e6));
  //   uPbPb_Bayes[i]->Scale(64.*1e9/(ncoll[i]*1e3));
  //   uPbPb_Bayes[i] = (TH1F*)uPbPb_Bayes[i]->Rebin(nbins_pt,Form("PbPb_bayesian_unfolded_spectra_combined_cent%d",i),boundaries_pt);
  //   divideBinWidth(uPbPb_Bayes[i]);
  //   uPbPb_Bayes[i]->Write();
  //   So finally PbPb is in 

  // PbPb MC scaling: is already in sigma (mb) / (dEta dpT)
  //   mPbPb_Reco[i]->Scale(1./deltaEta);// delta eta
  //   mPbPb_Reco[i] = (TH1F*)mPbPb_Reco[i]->Rebin(nbins_pt,Form("PbPb_Reco_spectra_refpt_cent%d",i),boundaries_pt);
  //   divideBinWidth(mPbPb_Reco[i]);
  //   mPbPb_Reco[i]->Write();

  // take MC to nano barns from milli barns 
  //mPP_R2->Scale(1e6);
  //mPP_R3->Scale(1e6);
  //mPP_R4->Scale(1e6);

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

    mPbPb_R2[i]->Scale(1./(0.025*(boundaries_cent[i+1] - boundaries_cent[i])));
    mPbPb_R2[i]->Scale(64.*1e9/(ncoll[i]*1e3));
    mPbPb_R2[i]->Scale(1./(7.65));

    mPbPb_R3[i]->Scale(1./(0.025*(boundaries_cent[i+1] - boundaries_cent[i])));
    mPbPb_R3[i]->Scale(64.*1e9/(ncoll[i]*1e3));
    mPbPb_R3[i]->Scale(1./(7.65));

    mPbPb_R4[i]->Scale(1./(0.025*(boundaries_cent[i+1] - boundaries_cent[i])));
    mPbPb_R4[i]->Scale(64.*1e9/(ncoll[i]*1e3));
    mPbPb_R4[i]->Scale(1./(7.65));
    
  }
  
  Double_t ScaleFactor[nbins_cent+2] = {1, 1e2, 1e4, 1e6, 1e8, 1e10, 1e12, 1e14};  
  
  TCanvas * cSpectra_R2 = new TCanvas("cSpectra_R2","",1200,1000);
  //makeMultiPanelCanvas(cSpectra_R2,3,1,0.0,0.0,0.2,0.15,0.07);
  cSpectra_R2->SetLogy();
  cSpectra_R2->SetGridy();
  cSpectra_R2->SetLogx();

  uPP_R2_Bayes->Scale(ScaleFactor[0]);
  uPP_R2_Bayes->SetMarkerStyle(20);
  uPP_R2_Bayes->SetMarkerColor(kBlack);
  makeHistTitle(uPP_R2_Bayes," "," Jet p_{T} (GeV/c)","#frac{d #sigma}{T_{AA} dp_{T} d#eta} nb");
  uPP_R2_Bayes->SetAxisRange(unfoldingCut, 299, "X");
  uPP_R2_Bayes->SetAxisRange(1e-4, 1e14, "Y");
  uPP_R2_Bayes->Draw();

  // draw the MC
  mPP_R2->Scale(ScaleFactor[0]);
  mPP_R2->SetLineColor(kBlack);
  mPP_R2->SetAxisRange(unfoldingCut, 299, "X");
  mPP_R2->Draw("same Lhist");
  
  for(int i = 0; i<nbins_cent; ++i){
    uPbPb_R2_Bayes[i]->Scale(ScaleFactor[i+1]);
    uPbPb_R2_Bayes[i]->SetMarkerStyle(33);
    uPbPb_R2_Bayes[i]->SetMarkerColor(kRed);
    uPbPb_R2_Bayes[i]->SetAxisRange(unfoldingCut, 299, "X");
    uPbPb_R2_Bayes[i]->Draw("same");

    // mPbPb_R2[i]->Scale(ScaleFactor[i+2]);
    // mPbPb_R2[i]->SetLineColor(kRed);
    // mPbPb_R2[i]->SetAxisRange(unfoldingCut, 299, "X");
    // mPbPb_R2[i]->Draw("same Lhist");
  }

  TLegend * leg1_R2 = myLegend(0.15,0.1,0.25,0.2);
  leg1_R2->AddEntry(uPP_R2_Bayes,"PP Data","pl");
  leg1_R2->AddEntry(mPP_R2,"PYTHIA","pl");
  leg1_R2->SetTextSize(0.02);
  leg1_R2->Draw();


  TLegend * leg2_R2 = myLegend(0.75,0.8,0.85,0.9);
  leg2_R2->AddEntry(uPbPb_R2_Bayes[0],"PbPb Data","pl");
  //leg2_R2->AddEntry(mPbPb_R2[0],"PYTHIA+HYDJET","pl");
  leg2_R2->SetTextSize(0.02);
  leg2_R2->Draw();
  
  drawText("R=0.2, anti k_{T} PF Jets", 0.15,0.2,16);
  drawText("R=0.2, anti k_{T} Pu PF Jets", 0.75,0.78,16);
  drawText(Form("%s", etaLable),0.15,0.25,16);

  putCMSPrel();
  putPbPbLumi();
  putPPLumi();
  
  //drawText("pp", 0.7,0.15,16);
  drawText("0-5% x 10^{2}", 0.8,0.20,16);
  drawText("5-10% x 10^{4}", 0.8,0.28,16);
  drawText("10-30% x 10^{6}", 0.8,0.38,16);
  drawText("30-50% x 10^{8}", 0.8,0.47,16);
  drawText("50-70% x 10^{10}", 0.8,0.54,16);
  drawText("70-90% x 10^{12}", 0.8,0.63,16);

  cSpectra_R2->SaveAs(Form("../../Plots/Final_paper_plots_spectra_akR2_%s_%d.pdf",etaWidth,date.GetDate()),"RECREATE");

  
  TCanvas * cSpectra_R3 = new TCanvas("cSpectra_R3","",1200,1000);
  //makeMultiPanelCanvas(cSpectra_R3,3,1,0.0,0.0,0.2,0.15,0.07);
  cSpectra_R3->SetLogy();
  cSpectra_R3->SetGridy();
  cSpectra_R3->SetLogx();

  uPP_R3_Bayes->Scale(ScaleFactor[0]);
  uPP_R3_Bayes->SetMarkerStyle(20);
  uPP_R3_Bayes->SetMarkerColor(kBlack);
  makeHistTitle(uPP_R3_Bayes," "," Jet p_{T} (GeV/c)","#frac{d #sigma}{T_{AA} dp_{T} d#eta} nb");
  uPP_R3_Bayes->SetAxisRange(unfoldingCut, 299, "X");
  uPP_R3_Bayes->SetAxisRange(1e-4, 1e14, "Y");
  uPP_R3_Bayes->Draw();

  // draw the MC
  mPP_R3->Scale(ScaleFactor[0]);
  mPP_R3->SetLineColor(kBlack);
  mPP_R3->SetAxisRange(unfoldingCut, 299, "X");
  mPP_R3->Draw("same Lhist");
  
  for(int i = 0; i<nbins_cent; ++i){
    uPbPb_R3_Bayes[i]->Scale(ScaleFactor[i+1]);
    uPbPb_R3_Bayes[i]->SetMarkerStyle(33);
    uPbPb_R3_Bayes[i]->SetMarkerColor(kRed);
    uPbPb_R3_Bayes[i]->SetAxisRange(unfoldingCut, 299, "X");
    uPbPb_R3_Bayes[i]->Draw("same");

    // mPbPb_R3[i]->Scale(ScaleFactor[i+2]);
    // mPbPb_R3[i]->SetLineColor(kRed);
    // mPbPb_R3[i]->SetAxisRange(unfoldingCut, 299, "X");
    // mPbPb_R3[i]->Draw("same Lhist");
  }

  TLegend * leg1_R3 = myLegend(0.15,0.1,0.25,0.2);
  leg1_R3->AddEntry(uPP_R3_Bayes,"PP Data","pl");
  leg1_R3->AddEntry(mPP_R3,"PYTHIA","pl");
  leg1_R3->SetTextSize(0.02);
  leg1_R3->Draw();


  TLegend * leg2_R3 = myLegend(0.75,0.8,0.85,0.9);
  leg2_R3->AddEntry(uPbPb_R3_Bayes[0],"PbPb Data","pl");
  // leg2_R3->AddEntry(mPbPb_R3[0],"PYTHIA+HYDJET","pl");
  leg2_R3->SetTextSize(0.02);
  leg2_R3->Draw();
  
  drawText("R=0.3, anti k_{T} PF Jets", 0.15,0.2,16);
  drawText("R=0.3, anti k_{T} Pu PF Jets", 0.75,0.78,16);
  drawText(Form("%s", etaLable),0.15,0.25,16);

  putCMSPrel();
  putPbPbLumi();
  putPPLumi();
  
  //drawText("pp", 0.7,0.15,16);
  drawText("0-5% x 10^{2}", 0.8,0.20,16);
  drawText("5-10% x 10^{4}", 0.8,0.28,16);
  drawText("10-30% x 10^{6}", 0.8,0.38,16);
  drawText("30-50% x 10^{8}", 0.8,0.47,16);
  drawText("50-70% x 10^{10}", 0.8,0.54,16);
  drawText("70-90% x 10^{12}", 0.8,0.63,16);

  cSpectra_R3->SaveAs(Form("../../Plots/Final_paper_plots_spectra_akR3_%s_%d.pdf",etaWidth, date.GetDate()),"RECREATE");


  
  TCanvas * cSpectra_R4 = new TCanvas("cSpectra_R4","",1200,1000);
  //makeMultiPanelCanvas(cSpectra_R4,3,1,0.0,0.0,0.2,0.15,0.07);
  cSpectra_R4->SetLogy();
  cSpectra_R4->SetGridy();
  cSpectra_R4->SetLogx();

  uPP_R4_Bayes->Scale(ScaleFactor[0]);
  uPP_R4_Bayes->SetMarkerStyle(20);
  uPP_R4_Bayes->SetMarkerColor(kBlack);
  makeHistTitle(uPP_R4_Bayes," "," Jet p_{T} (GeV/c)","#frac{d #sigma}{T_{AA} dp_{T} d#eta} nb");
  uPP_R4_Bayes->SetAxisRange(unfoldingCut, 299, "X");
  uPP_R4_Bayes->SetAxisRange(1e-4, 1e14, "Y");
  uPP_R4_Bayes->Draw();

  // draw the MC
  mPP_R4->Scale(ScaleFactor[0]);
  mPP_R4->SetLineColor(kBlack);
  mPP_R4->SetAxisRange(unfoldingCut, 299, "X");
  mPP_R4->Draw("same Lhist");
  
  for(int i = 0; i<nbins_cent; ++i){
    uPbPb_R4_Bayes[i]->Scale(ScaleFactor[i+1]);
    uPbPb_R4_Bayes[i]->SetMarkerStyle(33);
    uPbPb_R4_Bayes[i]->SetMarkerColor(kRed);
    uPbPb_R4_Bayes[i]->SetAxisRange(unfoldingCut, 299, "X");
    uPbPb_R4_Bayes[i]->Draw("same");

    // mPbPb_R4[i]->Scale(ScaleFactor[i+2]);
    // mPbPb_R4[i]->SetLineColor(kRed);
    // mPbPb_R4[i]->SetAxisRange(unfoldingCut, 299, "X");
    // mPbPb_R4[i]->Draw("same Lhist");
  }

  TLegend * leg1_R4 = myLegend(0.15,0.1,0.25,0.2);
  leg1_R4->AddEntry(uPP_R4_Bayes,"PP Data","pl");
  leg1_R4->AddEntry(mPP_R4,"PYTHIA","pl");
  leg1_R4->SetTextSize(0.02);
  leg1_R4->Draw();


  TLegend * leg2_R4 = myLegend(0.75,0.8,0.85,0.9);
  leg2_R4->AddEntry(uPbPb_R4_Bayes[0],"PbPb Data","pl");
  // leg2_R4->AddEntry(mPbPb_R4[0],"PYTHIA+HYDJET","pl");
  leg2_R4->SetTextSize(0.02);
  leg2_R4->Draw();
  
  drawText("R=0.4, anti k_{T} PF Jets", 0.15,0.2,16);
  drawText("R=0.4, anti k_{T} Pu PF Jets", 0.75,0.78,16);
  drawText(Form("%s", etaLable),0.15,0.25,16);
  
  putCMSPrel();
  putPbPbLumi();
  putPPLumi();
  
  //drawText("pp", 0.7,0.15,16);
  drawText("0-5% x 10^{2}", 0.8,0.20,16);
  drawText("5-10% x 10^{4}", 0.8,0.28,16);
  drawText("10-30% x 10^{6}", 0.8,0.38,16);
  drawText("30-50% x 10^{8}", 0.8,0.47,16);
  drawText("50-70% x 10^{10}", 0.8,0.54,16);
  drawText("70-90% x 10^{12}", 0.8,0.63,16);

  cSpectra_R4->SaveAs(Form("../../Plots/Final_paper_plots_spectra_akR4_%s_%d.pdf",etaWidth, date.GetDate()),"RECREATE");


}
void TOnePadDisplay::Init() {
//Initialization and default options
  Int_t day,month,year,date;
  TDatime *td;
//Date
  td = new TDatime();
  date  = td->GetDate();
  day   = date % 100;
  date /= 100;
  month = date % 100;
  date /= 100;
  year  = date;
  delete td;
  fCanDate  = "";
  fCanDate += day;
  fCanDate.Append(" / ");
  fCanDate += month;
  fCanDate.Append(" / ");
  fCanDate += year;
//Pointers to 0
  fCanvas          = 0;
  fTex1            = 0;
  fTex2            = 0;
  fTex3            = 0;
  fPad             = 0;
//initialization for main canvas
  fCanTopX         = 2;
  fCanTopY         = 2;
  fCanWidth        = 1000; //old 1178
  fCanHeigth       = 700;  //old 770
  fCanColor        = 20;
  fCanBsz          = 12; //4
  fCanStyle        = 1000;
//initialization for pad
  fPadXlow         = 0.015;
  fPadXup          = 0.985;
  fPadYlow         = 0.05;
  fPadYup          = 0.95;
  fPadColor        = 11;
  fPadBsz          = 6;
  fPadStyle        = 1000;
  fPadLogX         = 0;
  fPadLogY         = 0;
//initialization for frame in pad
  fFrameColor      = 171;
//initialization for Style
  fStyleStat       = 1111;
  fStyleFont       = 22;
  fStyleColor      = 171;
  fStyleH          = 0.1;
  fStyleW          = 0.65;//0.76
  fStyleHistColor  = 42;
  fStyleTXSize     = 0.035;//0.035
  fStyleTYSize     = 0.035;//0.035
  fStyleTitleH     = 0.04;//0.04
  fStyleTitleW     = 0.95;
  fStyleTitleX     = 0.12;
  fStyleTXOffset   = 1.0;
  fStyleTitleY     = 0.975;
  fStyleTYOffset   = 1.0;
  fStyleTBSize     = 4;
  fStyleTitleFont  = 22;
  fStyleTitleColor = 1;
  fStyleTFColor    = 191;
  fStyleTTextColor = 1;
  fStyleLabelSize  = 0.035;
  fStyleLabelAxis  = "XYZ";
//labels
  fTextT1          = "SplineFit : General Purpose Fit System";
  fXTex1           = 0.04;
  fYTex1           = 0.96;
  fTextT2          = "F.X.Gentit DAPNIA/SPP CEA Saclay";
  fXTex2           = 0.04;
  fYTex2           = 0.025;
  fTextT3          = "TOnePadDisplay   ";
  fTextT3.Append(fCanDate);
  fXTex3           = 0.8;
  fYTex3           = 0.025;
  fFontTex         = 72;
  fSizeTex         = 0.022419;
  fWidthTex        = 2;
  gOneDisplay      = this;
}
Exemple #21
0
void RAA_plot_JetID_CutEfficiency(  Int_t radius = 4,
				    char * etaWidth = (char*)"20_eta_p20"){

  TH1::SetDefaultSumw2();
  gStyle->SetOptStat(0);

  char * Coll = "PbPb";
  //char * Coll = "Pp";

  TDatime date;

  Int_t trigger[3]; 

  if(Coll == "PbPb") {trigger[0] = 55; trigger[1] = 65; trigger[2] = 80;}
  if(Coll == "Pp") {trigger[0] = 40; trigger[1] = 60; trigger[2] =  80;}

  char * jetType; 

  if(Coll == "PbPb") jetType = Form("akPu%dPF",radius);
  if(Coll == "Pp") jetType = Form("ak%dPF",radius);

  const int nbins_pt = 38;
  const double boundaries_pt[nbins_pt+1] = {
    3, 4, 5, 7, 9, 12, 
    15, 18, 21, 24, 28,
    32, 37, 43, 49, 56,
    64, 74, 84, 97, 114,
    133, 153, 174, 196,
    220, 245, 300, 
    330, 362, 395, 430,
    468, 507, 548, 592,
    638, 686, 1000 
  };
  
  // Pawan's files:
  TFile * fIn = TFile::Open(Form("/export/d00/scratch/rkunnawa/rootfiles/RAA/Pawan_ntuple_PbPb_data_MC_subid0_spectra_JetID_CutA_finebins_%s_R0p%d.root",etaWidth,radius));
  TFile * fPP_in = TFile::Open(Form("/export/d00/scratch/rkunnawa/rootfiles/RAA/Pawan_ntuple_PP_data_MC_spectra_residualFactor_finebins_%s_R0p%d.root",etaWidth, radius));
  
  // get the histograms, the Cut Efficiency is plotted from the MC histograms 
  TH1F * hMC_noCut[3], * hMC_Cut[3], * hMC_unm_noCut[3], * hMC_unm_Cut[3]; 

  TH1F * hMC_Denominator, *hMC_Numerator;

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

    hMC_noCut[i] = (TH1F*)fIn->Get(Form("hMC_Jet%d_noCut", trigger[i]));
    hMC_Cut[i] = (TH1F*)fIn->Get(Form("hMC_Jet%d_CutA", trigger[i]));
    hMC_unm_noCut[i] = (TH1F*)fIn->Get(Form("hMC_unmatched_Jet%d_noCut", trigger[i]));
    hMC_unm_Cut[i] = (TH1F*)fIn->Get(Form("hMC_unmatched_Jet%d_CutA", trigger[i]));

  }

  hMC_Denominator = (TH1F*)hMC_noCut[0]->Clone("hMC_Denominator");
  hMC_Denominator->Add(hMC_noCut[1]);
  hMC_Denominator->Add(hMC_noCut[2]);
  hMC_Denominator->Add(hMC_unm_noCut[0]);
  hMC_Denominator->Add(hMC_unm_noCut[1]);
  hMC_Denominator->Add(hMC_unm_noCut[2]);
  
  hMC_Numerator = (TH1F*)hMC_Cut[0]->Clone("hMC_Numerator");
  hMC_Numerator->Add(hMC_Cut[1]);
  hMC_Numerator->Add(hMC_Cut[2]);
  hMC_Numerator->Add(hMC_unm_Cut[0]);
  hMC_Numerator->Add(hMC_unm_Cut[1]);
  hMC_Numerator->Add(hMC_unm_Cut[2]);

  TH1F * hCutEff = (TH1F*)hMC_Numerator->Clone("hCutEff");
  hCutEff->Divide(hMC_Denominator);
  hCutEff = (TH1F*)hCutEff->Rebin(nbins_pt, "hCutEff", boundaries_pt);
  divideBinWidth(hCutEff);

  // line at 1

  
  TCanvas * cCutEff = new TCanvas("cCutEff","",800,600);
  hCutEff->SetXTitle(Form("%s Gen p_{T} (GeV/c)",jetType));
  hCutEff->SetYTitle("Jet ID Cut Efficiency");
  hCutEff->SetTitle(" ");
  hCutEff->SetAxisRange(40, 300, "X");
  hCutEff->SetAxisRange(0.9, 1.05, "Y");
  hCutEff->SetMarkerStyle(20);
  hCutEff->SetMarkerColor(kBlack);
  hCutEff->Draw();

  putCMSPrel();
  drawText("|#eta|<2, |vz|<15", 0.6, 0.31, 20);
  drawText(Form("%s",Coll), 0.6, 0.21, 20);

  cCutEff->SaveAs(Form("May20/%s_Combined_CutEfficiency_R0p%d_%s_%d.pdf",Coll,radius,etaWidth,date.GetDate()),"RECREATE");
  


  // plot the curves for the different centrality classes. get the combined spectra and do the ratio 
  
  const int nbins_cent = 6; 

  TH1F * hMC_Denominator[nbins_cent];
  TH1F * hMC_Numerator[nbins_cent]; 

  TH1F * hData_Denominator[nbins_cent];
  TH1F * hData_Numerator[nbins_cent]; 

  TH1F * hCutEff[nbins_cent];
  TH1F * hCutEff_Data[nbins_cent];

  TH1F * hPP_MC_Denominator = (TH1F*)fIn_PP->Get("hpp_MC_Comb_noCut");
  TH1F * hPP_MC_Numerator = (TH1F*)fIn_PP->Get(Form("hpp_JetComb_gen_R%d_%s",radius,etaWidth)); 

  TH1F * hPP_Data_Denominator = (TH1F*)fIn_PP->Get("hpp_Data_Comb_noCut");
  TH1F * hPP_Data_Numerator = (TH1F*)fIn_PP->Get(Form("hpp_HLTComb_R%d_%s",radius,etaWidth)); 

  TH1F * hPP_CutEff = (TH1F*)hPP_MC_Numerator->Clone("hPP_CutEff");
  hPP_CutEff->Divide(hPP_MC_Denominator);
  hPP_CutEff->Rebin(10);
  hPP_CutEff->Scale(1./10);
  TH1F * hPP_CutEff_Data = (TH1F*)hPP_Data_Numerator->Clone("hPP_CutEff_Data");
  hPP_CutEff_Data->Divide(hPP_Data_Denominator);
  hPP_CutEff_Data->Rebin(10);
  hPP_CutEff_Data->Scale(1./10);
  
  TLine *line = new TLine(60,1,299,1);
  line->SetLineStyle(2);
  line->SetLineWidth(2);

  for(int i = 0; i<nbins_cent; ++i){
    
    hMC_Denominator[i] = (TH1F*)fIn->Get(Form("hpbpb_MC_noCut_cent%d",i));
    hMC_Numerator[i] = (TH1F*)fIn->Get(Form("hpbpb_gen_R%d_%s_cent%d",radius,etaWidth, i));
    hData_Denominator[i] = (TH1F*)fIn->Get(Form("hpbpb_Data_Comb_noCut_cent%d",i));
    hData_Numerator[i] = (TH1F*)fIn->Get(Form("hpbpb_HLTComb_R%d_%s_cent%d",radius,etaWidth,i));

    hCutEff[i] = (TH1F*)hMC_Numerator[i]->Clone(Form("CutEff_cent%d",i));
    hCutEff[i]->Divide(hMC_Denominator[i]);
    hCutEff[i]->Rebin(20);
    hCutEff[i]->Scale(1./20);

    hCutEff_Data[i] = (TH1F*)hData_Numerator[i]->Clone(Form("CutEff_Data_cent%d",i));
    hCutEff_Data[i]->Divide(hData_Denominator[i]);
    hCutEff_Data[i]->Rebin(20);
    hCutEff_Data[i]->Scale(1./20);

  }

  TCanvas * cCutEff = new TCanvas("cCutEff","",800,600);
  makeMultiPanelCanvas(cCutEff,3,2,0.0,0.0,0.2,0.15,0.07);

  for(int i = 0; i<nbins_cent; ++i){
    cCutEff->cd(nbins_cent-i);
    hCutEff[i]->SetXTitle(Form("akPu%dPF Gen p_{T} (GeV/c)", radius));
    hCutEff[i]->SetYTitle("Jet ID Cut Efficiency");
    hCutEff[i]->SetTitle(" ");
    hCutEff[i]->SetAxisRange(50, 299, "X");
    hCutEff[i]->SetAxisRange(0.95, 1.05, "Y");
    hCutEff[i]->SetMarkerStyle(20);
    hCutEff[i]->SetMarkerColor(kBlack);
    hCutEff[i]->Draw();
    line->Draw();
  }

  putCMSPrel();
  drawText("|#eta|<2, |vz|<15", 0.6, 0.31, 20);
  drawText(Form("%s",Coll), 0.6, 0.21, 20);

  cCutEff->SaveAs(Form("May20/%s_Combined_CutEfficiency_centralityClass_R0p%d_%s_%d.pdf",Coll,radius,etaWidth,date.GetDate()),"RECREATE");

  TCanvas * cCutEff_Data = new TCanvas("cCutEff_Data","",800,600);
  makeMultiPanelCanvas(cCutEff_Data,3,2,0.0,0.0,0.2,0.15,0.07);

  for(int i = 0; i<nbins_cent; ++i){
    cCutEff_Data->cd(nbins_cent-i);
    hCutEff_Data[i]->SetXTitle(Form("akPu%dPF Data reco p_{T} (GeV/c)", radius));
    hCutEff_Data[i]->SetYTitle("Jet ID Cut Efficiency");
    hCutEff_Data[i]->SetTitle(" ");
    hCutEff_Data[i]->SetAxisRange(60, 299, "X");
    hCutEff_Data[i]->SetAxisRange(0.2, 1.1, "Y");
    hCutEff_Data[i]->SetMarkerStyle(20);
    hCutEff_Data[i]->SetMarkerColor(kBlack);
    hCutEff_Data[i]->Draw();
    line->Draw();
  }

  putCMSPrel();
  drawText("|#eta|<2, |vz|<15", 0.6, 0.31, 20);
  drawText(Form("%s",Coll), 0.6, 0.21, 20);

  cCutEff_Data->SaveAs(Form("May20/%s_Combined_CutEfficiency_Data_centralityClass_R0p%d_%s_%d.pdf",Coll,radius,etaWidth,date.GetDate()),"RECREATE");

  
  TCanvas * cPP_CutEff = new TCanvas("cPP_CutEff","",800,600);
  hPP_CutEff->SetXTitle(Form("ak%dPF Gen p_{T} (GeV/c)", radius));
  hPP_CutEff->SetYTitle("Jet ID Cut Efficiency");
  hPP_CutEff->SetTitle(" ");
  hPP_CutEff->SetAxisRange(60, 299, "X");
  hPP_CutEff->SetAxisRange(0.8,1.1,"Y");
  hPP_CutEff->SetMarkerStyle(20);
  hPP_CutEff->Draw();

  cPP_CutEff->SaveAs(Form("May20/PP_Combined_CutEfficiency_R0p%d_%d.pdf",radius, date.GetDate()));

  TCanvas * cPP_CutEff_Data = new TCanvas("cPP_CutEff_Data","",800,600);
  hPP_CutEff_Data->SetXTitle(Form(" ak%dPF Data reco p_{T} (GeV/c)", radius));
  hPP_CutEff_Data->SetYTitle("Jet ID Cut Efficiency");
  hPP_CutEff_Data->SetTitle(" ");
  hPP_CutEff_Data->SetAxisRange(60, 299, "X");
  hPP_CutEff_Data->SetAxisRange(0.8,1.1,"Y");
  hPP_CutEff_Data->SetMarkerStyle(20);
  hPP_CutEff_Data->Draw();

  cPP_CutEff_Data->SaveAs(Form("May20/PP_Combined_CutEfficiency_Data_R0p%d_%s_%d.pdf",radius,etaWidth, date.GetDate()));
  
}
Exemple #22
0
void Check_PFelecFix(int radius = 3,
		     char * algo = (char*)"PF",
		     char * bkgsub = (char*)"Pu"){

  
  TH1::SetDefaultSumw2();
  //gStyle->SetOptStat(0);
  
  TStopwatch timer;
  timer.Start();
  
  TDatime date;

  char * fileType[4][256] = {"badFile","Fix_1","Fix_2","Fix_3"};
  
  // get the input hiForest files, these are going to be in an array 0 - bad fine, 1 - fix_1, 2 - fix_2, 3 - fix_3; 
  TFile * fIn[4];

  // input the filen names
  fIn[0] = TFile::Open("");
  fIn[1] = TFile::Open("");
  fIn[2] = TFile::Open("");
  fIn[3] = TFile::Open("");
  
  // get the jet trees from the necessary files (these events already passed the event quality cuts so only hav to get the jet Tree).
  TTree * jet[4];
   
  // get the histograms from these files for the different centrality bins and the fixes. 
  TH1F * heMax[4][nbins_cent], * heSum[4][nbins_cent];
  TH2F * heMax_vs_jtpt[4][nbins_cent], * heMaxJtpt_vs_jtpt[4][nbins_cent], * heMaxSumcand_vs_jtpt[4][nbins_cent];


  for(int k = 0; k<4; ++k){

    jet[k] = (TTree*)fIn[k]->Get(Form("ak%s%d%sJetAnalyzer/t",bkgsub,radius,algo));

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

      heMax[k][i] = new TH1F(Form("heMax_%s_cent%d",fileType,i),"",200,0,200);
      heMax_vs_jtpt[k][i] = new TH1F(Form("heMax_vs_jtpt_%s_cent0",fileType,i),"",400,0,400,100,0,200);
      heMaxJtpt_vs_jtpt[k][i] = new TH1F(Form("heMaxJtpt_vs_jtpt_%s_cent0",fileType,i),"",400,0,400,100,0,10);
      heMaxSumcand_vs_jtpt[k][i] = new TH1F(Form("heMaxSumcand_vs_jtpt_%s_cent0",fileType,i),"",400,0,400,100,0,10);

      jet[k]->Draw(Form("eMax>>heMax_%s_cent%d",fileType,i),Form("hiBin>=%d && hiBin<%d",5 * boundaries_cent[i], 5 * boundaries_cent[i+1]),"goff");
      jet[k]->Draw(Form("eMax:jtpt>>heMax_vs_jtpt_%s_cent%d",fileType,i),Form("hiBin>=%d && hiBin<%d",5 * boundaries_cent[i], 5 * boundaries_cent[i+1]),"goff");
      jet[k]->Draw(Form("eMax/jtpt:jtpt>>heMaxJtpt_vs_jtpt_%s_cent%d",fileType,i),Form("hiBin>=%d && hiBin<%d",5 * boundaries_cent[i], 5 * boundaries_cent[i+1]),"goff");
      jet[k]->Draw(Form("eMax/(chSum+neSum+muSum+phSum):jtpt>>heMaxSumcand_vs_jtpt_%s_cent%d",fileType,i),Form("hiBin>=%d && hiBin<%d",5 * boundaries_cent[i], 5 * boundaries_cent[i+1]),"goff");
    
    }

  }

  // now that we have the histograms, lets do the plotting part here.
  // we need one canvas for each plotted variable.
  // at the moment im only going to plot the most central events. 0 <= hiBin < 5

  TCanvas * ceMax, *ceMax_vs_jtpt, *ceMaxJtpt_vs_jtpt, *ceMaxSumcand_vs_jtpt;

  ceMax = new TCanvas("ceMax","",1200,1000);
  ceMax->Divide(4,1);
  ceMax_vs_jtpt = new TCanvas("ceMax_vs_jtpt","",1200,1000);
  ceMax_vs_jtpt->Divide(4,1);
  ceMaxJtpt_vs_jtpt = new TCanvas("ceMaxJtpt_vs_jtpt","",1200,1000);
  ceMaxJtpt_vs_jtpt->Divide(4,1);
  ceMaxSumcand_vs_jtpt = new TCanvas("ceMaxSumcand_vs_jtpt","",1200,1000);
  ceMaxSumcand_vs_jtpt->Divide(4,1);

  int cent = 0; // change this to draw other centrality classes 
  
  for(int k = 0; k<4; ++k){

    ceMax->cd(k+1);
    heMax[k][cent]->Draw();
    drawText(Form("%s %2.0f-%2.0f%",fileType,2.5*boundaries_cent[i],2.5*boundaries_cent[i+1]),0.2,0.2,14);

    ceMax_vs_jtpt->cd(k+1);
    heMax_vs_jtpt[k][cent]->Draw("colz");
    drawText(Form("%s %2.0f-%2.0f%",fileType,2.5*boundaries_cent[i],2.5*boundaries_cent[i+1]),0.2,0.2,14);

    ceMaxJtpt_vs_jtpt->cd(k+1);
    heMaxJtpt_vs_jtpt[k][cent]->Draw("colz");
    drawText(Form("%s %2.0f-%2.0f%",fileType,2.5*boundaries_cent[i],2.5*boundaries_cent[i+1]),0.2,0.2,14);

    ceMaxSumcand_vs_jtpt->cd(k+1);
    heMax_vs_jtpt[k][cent]->Draw("colz");
    drawText(Form("%s %2.0f-%2.0f%",fileType,2.5*boundaries_cent[i],2.5*boundaries_cent[i+1]),0.2,0.2,14);

  }

  ceMax->SaveAs(Form("PbPb_eMaxvariable_cent%d_ak%s%d%s_%d.pdf",cent,bkgsub,radius,algo,date.GetDate()),"RECREATE");
  ceMax_vs_jtpt->SaveAs(Form("PbPb_eMax_vs_jtpt_cent%d_ak%s%d%s_%d.pdf",cent,bkgsub,radius,algo,date.GetDate()),"RECREATE");
  ceMaxJtpt_vs_jtpt->SaveAs(Form("PbPb_eMaxOverJtpt_vs_jtpt_cent%d_ak%s%d%s_%d.pdf",cent,bkgsub,radius,algo,date.GetDate()),"RECREATE");
  ceMaxSumcand_vs_jtpt->SaveAs(Form("PbPb_eMaxOver_SumCandidates_without_eMax_vs_jtpt_cent%d_ak%s%d%s_%d.pdf",cent,bkgsub,radius,algo,date.GetDate()),"RECREATE");
  
  timer.Stop();
  cout<<"Macro finished: "<<endl;
  cout<<"CPU time (min)  = "<<(float)timer.CpuTime()/60<<endl;
  cout<<"Real time (min) = "<<(float)timer.RealTime()/60<<endl;



}
void gammaJetHistProducer_jetEnergyScaledMinus2percent(sampleType collision = kPADATA, float photonPtThr=60, float photonPtThrUp=9999, float jetPtThr=30, int icent =1) {
  TH1::SetDefaultSumw2();
  
  TString stringSampleType = getSampleName(collision); "";
  
  TDatime* date = new TDatime();
  TString  outName=  Form("photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr%d_%d.root",stringSampleType.Data(),(int)photonPtThr, (int)photonPtThrUp, (int)jetPtThr,  date->GetDate());
  delete date;
  
  int lowerCent(0),  upperCent(0); 
  TCut centCut  = "";
  if ( (collision ==kHIDATA) || (collision==kHIMC) )   {
    lowerCent = centBin1[icent-1];
    upperCent = centBin1[icent]-1;
    if ( icent > 9999) {
      lowerCent = ((icent/100)%100)/2.5;
      upperCent =  (icent%100)/2.5 -1;
    }   
    centCut = Form("cBin >= %d && cBin<= %d",lowerCent,upperCent);
  }
  else if (  (collision ==kPPDATA) || (collision==kPPMC)  ){  // if it's pp 
    centCut = "(1==1)";
    //    icent = 7;   // for pp, centrality is set as the smearing 
  }
  else { // pPb
    centCut = Form( "hf4Sum > %f && hf4Sum <= %f", (float)centBinPa[icent-1], (float)centBinPa[icent]);
  }
  
  cout <<" centrality : " << centCut.GetTitle() << endl;
      
  ///////// Photon cut //////////////////////////////////////////////////////////////////////////////
  
  cout <<" photon pt >" << photonPtThr << " GeV" << endl;
  TCut ptPhoCut  = Form("photonEt>%.1f && photonEt<%.1f", (float)photonPtThr, (float)photonPtThrUp  );
  TCut caloIso;
  
  if ( (collision==kPPMC) || (collision==kPPDATA) ) 
    caloIso = "(ecalIso < 4.2  &&  hcalIso < 2.2  &&  trackIso < 2) && hovere<0.1";
  else if ( (collision==kHIMC) || (collision==kHIDATA) )
    caloIso = "(sumIso<1) && hovere<0.1";
  else {
    caloIso = "ecalIso < 4.2  &&  hcalIso < 2.2  &&  trackIso < 2 && hovere<0.1";
  }
  
  TCut sbIso   = "(sumIso>10) && (sumIso<20) && hovere<0.1";
  //  if ( (collision==kPPMC) || (collision==kPPDATA) || (collision==kPAMC) || (collision==kPADATA)  )
  //  sbIso   = "ecalIso < 4.2  &&  hcalIso < 2.2 && trackIso > 2 && trackIso < 5 && hovere<0.1";

  TCut basicPhoCut = centCut && ptPhoCut && caloIso ;
  TCut sbPhoCut    = centCut && ptPhoCut && sbIso   ;
  TCut evtSeltCut = basicPhoCut;
  TCut sbSeltCut  = sbPhoCut;

  TCut phoCandCut   = "sigmaIetaIeta<0.010";
  TCut phoDecayCut  = "(sigmaIetaIeta>0.011) && (sigmaIetaIeta<0.017)";
  if  ( ( collision == kHIMC ) || (collision == kPPMC) || (collision == kPAMC))  
    phoCandCut = phoCandCut && "genIso<5 && abs(genMomId)<=22";
  
  
  TString fname = "";
  if ( collision == kHIDATA)      fname = fnameHIDATA_Minus2percentScaled;
  else if ( collision == kPADATA) fname = fnamePADATA_Minus2percentScaled;
  else if ( collision == kPPDATA) {
    if ( icent == 7 ) fname = fnamePPDATA_Minus2percentScaled;
  }  
  else fname = "";
  
  multiTreeUtil* tgj = new multiTreeUtil();
  multiTreeUtil* tgjMC = new multiTreeUtil();
  if (  ( collision == kHIDATA)   || ( collision==kPADATA) || ( collision == kPPDATA) ) {
    tgj->addFile(fname,  "tgj",  evtSeltCut,  1);
  }
  else if ( collision == kPPMC ) {
    tgj->addFile(fnamePPMC_AllQcdPho30to50,    "tgj", evtSeltCut, wPPMC_AllQcdPho30to50 );
    tgj->addFile(fnamePPMC_AllQcdPho50to80,    "tgj", evtSeltCut, wPPMC_AllQcdPho50to80 );
    tgj->addFile(fnamePPMC_AllQcdPho80to120,   "tgj", evtSeltCut, wPPMC_AllQcdPho80to120 );
    tgj->addFile(fnamePPMC_AllQcdPho120to9999, "tgj", evtSeltCut, wPPMC_AllQcdPho120to9999 );
  }
  else if ( collision == kPAMC ) {
    tgj->addFile(fnamePAMC_AllQcdPho30to50,    "tgj", evtSeltCut, wPAMC_AllQcdPho30to50 );
    tgj->addFile(fnamePAMC_AllQcdPho50to80,    "tgj", evtSeltCut, wPAMC_AllQcdPho50to80 );
    tgj->addFile(fnamePAMC_AllQcdPho80to120,   "tgj", evtSeltCut, wPAMC_AllQcdPho80to120 );
    tgj->addFile(fnamePAMC_AllQcdPho120to9999, "tgj", evtSeltCut, wPAMC_AllQcdPho120to9999 );
  }
  else  {    // kHIMC
    tgj->addFile(fnameHIMC_AllQcdPho30to50,    "tgj", evtSeltCut, wHIMC_AllQcdPho30to50 );
    tgj->addFile(fnameHIMC_AllQcdPho50to80,    "tgj", evtSeltCut, wHIMC_AllQcdPho50to80 );
    tgj->addFile(fnameHIMC_AllQcdPho80to9999,  "tgj", evtSeltCut, wHIMC_AllQcdPho80to9999 );
  }
  tgj->AddFriend("yJet");
 
  // get purity with the current jet cut ! 
  float purity(0);
  
  TString canvasName = Form("gifs/purity_%s_output_icent%d_photonPtThr%d-%d_jetPtThr%d", stringSampleType.Data(),  (int)icent, (int)photonPtThr, (int)photonPtThrUp, (int)jetPtThr);
  
  //  if ( (collision==kPPDATA) && (photonPtThr < 50 ) ) {
  //   purity = 0.86 ;   
  //   cout << " !!!!!!!" << endl << endl << " purity is set as  0.86 for this bin because we don't have pp MC low pt sample " << endl;
  //   cout << endl << endl << endl << " !!!!!!" << endl;
  //  }

  if ( (collision==kHIDATA)||(collision==kPPDATA)||(collision==kPADATA) )  {
    
    fitResult fitr = getPurity(fname, collision, evtSeltCut, sbSeltCut, canvasName, photonPtThr, photonPtThrUp);
    purity = fitr.purity010;

    /*
      float originalP = purity;
      if (collision==kPPDATA)  
      purity = purity - 0.05;
      else if (collision==kHIDATA) {
      if ( icent == 10030)
      purity = purity - 0.08; 
      else if ( icent == 13099) 
      purity = purity - 0.07; 
      }
      cout << "====================================================================================" << endl << endl << endl;
      cout << "====================================================================================" << endl << endl << endl;
      cout << "================================ Purity modified!!! ================================" << endl << endl << endl;
      cout << "=============== "<<originalP<< " --> "<<purity<< "====================================" << endl << endl << endl;
      cout << "====================================================================================" << endl << endl << endl;
    */
  }
  else  {
    purity = 1;  
    cout << " MC purity = 1" << endl;
  }
  

  GjSpectra* gSpec = new GjSpectra();
  gSpec->init(Form("icent%d",(int)icent) );
  tgj->Draw2(gSpec->hPtPhoCand,  "photonEt", phoCandCut, "")  ;
  tgj->Draw2(gSpec->hPtPhoDecay, "photonEt", phoDecayCut, "") ;
  
  // Obtain background subtracted spectra
  
  float candInt = gSpec->hPtPhoCand->Integral();
  float candDecay = gSpec->hPtPhoDecay->Integral();
  gSpec->hPtPhoSig->Reset();
  gSpec->hPtPhoSig->Add(gSpec->hPtPhoCand);
  gSpec->hPtPhoSig->Add(gSpec->hPtPhoDecay, -(1. - purity) * candInt / candDecay);
  gSpec->hPtPhoSig->Scale(1./purity ) ;
  
  TFile outf = TFile(Form("ffFiles/%s",outName.Data()),"update");
  gSpec->hPtPhoCand->Write();
  gSpec->hPtPhoDecay->Write();
  gSpec->hPtPhoSig->Write();
  outf.Close();
  
  
  
  // Objects
  multiTreeUtil* tObj[3];
  tObj[kTrkRaw] = new multiTreeUtil();
  tObj[kTrkBkg] = new multiTreeUtil();
  
  if (  ( collision == kHIDATA)   || ( collision==kPADATA) || ( collision == kPPDATA) ) {
    tObj[kTrkRaw]->addFile(fname,  "yJet",  evtSeltCut,  1);
    tObj[kTrkBkg]->addFile(fname,  "mJet",  evtSeltCut,  1);
  }
  else if ( collision == kHIMC ) {
    tObj[kTrkRaw]->addFile(fnameHIMC_AllQcdPho30to50,   "yJet", evtSeltCut, wHIMC_AllQcdPho30to50 ) ;
    tObj[kTrkRaw]->addFile(fnameHIMC_AllQcdPho50to80,   "yJet", evtSeltCut, wHIMC_AllQcdPho50to80 ) ;
    tObj[kTrkRaw]->addFile(fnameHIMC_AllQcdPho80to9999, "yJet", evtSeltCut, wHIMC_AllQcdPho80to9999 ) ;
 
    tObj[kTrkBkg]->addFile(fnameHIMC_AllQcdPho30to50,   "mJet", evtSeltCut, wHIMC_AllQcdPho30to50 ) ;
    tObj[kTrkBkg]->addFile(fnameHIMC_AllQcdPho50to80,   "mJet", evtSeltCut, wHIMC_AllQcdPho50to80 ) ;
    tObj[kTrkBkg]->addFile(fnameHIMC_AllQcdPho80to9999, "mJet", evtSeltCut, wHIMC_AllQcdPho80to9999 ) ;
  } 
  else if ( collision == kPAMC ) {
    tObj[kTrkRaw]->addFile(fnamePAMC_AllQcdPho30to50,   "yJet", evtSeltCut, wPAMC_AllQcdPho30to50 ) ;
    tObj[kTrkRaw]->addFile(fnamePAMC_AllQcdPho50to80,   "yJet", evtSeltCut, wPAMC_AllQcdPho50to80 ) ;
    tObj[kTrkRaw]->addFile(fnamePAMC_AllQcdPho80to120,  "yJet", evtSeltCut, wPAMC_AllQcdPho80to120 ) ;
    tObj[kTrkRaw]->addFile(fnamePAMC_AllQcdPho120to9999,"yJet", evtSeltCut, wPAMC_AllQcdPho120to9999 ) ;
    
    tObj[kTrkBkg]->addFile(fnamePAMC_AllQcdPho30to50,   "mJet", evtSeltCut, wPAMC_AllQcdPho30to50 ) ;
    tObj[kTrkBkg]->addFile(fnamePAMC_AllQcdPho50to80,   "mJet", evtSeltCut, wPAMC_AllQcdPho50to80 ) ;
    tObj[kTrkBkg]->addFile(fnamePAMC_AllQcdPho80to120,  "mJet", evtSeltCut, wPAMC_AllQcdPho80to120 ) ;
    tObj[kTrkBkg]->addFile(fnamePAMC_AllQcdPho120to9999,"mJet", evtSeltCut, wPAMC_AllQcdPho120to9999 ) ;
  }
  else if ( collision == kPPMC ) {
    tObj[kTrkRaw]->addFile(fnamePPMC_AllQcdPho30to50,   "yJet", evtSeltCut, wPPMC_AllQcdPho30to50 );
    tObj[kTrkRaw]->addFile(fnamePPMC_AllQcdPho50to80,   "yJet", evtSeltCut, wPPMC_AllQcdPho50to80 );
    tObj[kTrkRaw]->addFile(fnamePPMC_AllQcdPho80to120,  "yJet", evtSeltCut, wPPMC_AllQcdPho80to120 );
    tObj[kTrkRaw]->addFile(fnamePPMC_AllQcdPho120to9999,"yJet", evtSeltCut, wPPMC_AllQcdPho120to9999 );

    tObj[kTrkBkg]->addFile(fnamePPMC_AllQcdPho30to50,   "mJet", evtSeltCut, wPPMC_AllQcdPho30to50 );
    tObj[kTrkBkg]->addFile(fnamePPMC_AllQcdPho50to80,   "mJet", evtSeltCut, wPPMC_AllQcdPho50to80 );
    tObj[kTrkBkg]->addFile(fnamePPMC_AllQcdPho80to120,  "mJet", evtSeltCut, wPPMC_AllQcdPho80to120 );
    tObj[kTrkBkg]->addFile(fnamePPMC_AllQcdPho120to9999,"mJet", evtSeltCut, wPPMC_AllQcdPho120to9999 );
  }



  tObj[kTrkRaw]->AddFriend("tgj");
  tObj[kTrkBkg]->AddFriend("tgj");
  TCut jetCut     =  Form("abs(eta)<%f && pt>%f", (float)cutjetEta, (float)jetPtThr );
  TCut jetCutDphi =  jetCut && (TCut)(Form("abs(dphi)>%f",(float)awayRange));
  TCut genJetCut     =  Form("abs(jtEta)<%f && jtPt>%f", (float)cutjetEta, (float)jetPtThr );
  TCut genJetCutDphi =  jetCut && (TCut)(Form("abs(refDphi)>%f",(float)awayRange));
  
  TCut jetCut2   = Form("abs(dphi)>%f && pt>%f", (float)awayRange, (float)jetPtThr ) ;
  
  
  TString jetWeight = "";
  
  TH1D* hJetDphi = new TH1D(Form("jetDphi_icent%d",icent),";#Delta#phi_{Jet,#gamma} ;dN/d#Delta#phi",20,0,3.141592);
  corrFunctionTrk* cJetDphi = new corrFunctionTrk();
  TString varJetDphi         = Form("dphi");

  gammaTrkSingle( gSpec,  tObj, cJetDphi,  purity, 
		  collision, varJetDphi, jetCut, jetWeight,
		  phoCandCut, phoDecayCut,  hJetDphi, outName);
  
  TH1D* hJetPt = new TH1D(Form("jetPt_icent%d",icent),";Jet p_{T} (GeV) ;dN/dp_{T} (GeV^{-1})",280, 20,300);
  corrFunctionTrk* cJetPt = new corrFunctionTrk();
  TString varJetPt         = Form("pt");
  
  gammaTrkSingle( gSpec,  tObj, cJetPt,  purity, 
		  collision, varJetPt, jetCutDphi, jetWeight,
		  phoCandCut, phoDecayCut,  hJetPt, outName);
  
  const int nJetIaaBin = 7;
  double jetIaaBin[nJetIaaBin+1] = {30,40,50,60,80,100,120,200};
  TH1D* hJetPtForIaa = new TH1D(Form("jetPtForIaa_icent%d",icent),";Jet p_{T} (GeV) ;dN/dp_{T} (GeV^{-1})",nJetIaaBin, jetIaaBin);
  corrFunctionTrk* cJetIaaPt = new corrFunctionTrk();
  gammaTrkSingle( gSpec,  tObj, cJetIaaPt,  purity,
                  collision, varJetPt, jetCutDphi, jetWeight,
                  phoCandCut, phoDecayCut,  hJetPtForIaa, outName);
  
  //  TH1D* hDjetPt = new TH1D(Form("dpt_icent%d",icent),";p_{T}^{#gamma} - p_{T}^{Jet} (GeV) ;dN/dp_{T} (GeV^{-1})",30,-150,150);
  //  corrFunctionTrk* cDjetPt = new corrFunctionTrk();
  //  TString varJetDpt         = Form("pt - photonEt");
  // gammaTrkSingle( gSpec,  tObj, cDjetPt,  purity, 
  //		  collision, varJetDpt, jetCutDphi, jetWeight,
  //		  phoCandCut, phoDecayCut,  hDjetPt, outName);
  
  
  TH1D* hJetXjg = new TH1D(Form("xjg_icent%d",icent),";p_{T}^{Jet}/p_{T}^{#gamma}  ; ",400,0,5);
  corrFunctionTrk* cJetXjg = new corrFunctionTrk();
  TString varJetXjg         = Form("pt/photonEt");
  
  gammaTrkSingle( gSpec,  tObj, cJetXjg,  purity, 
		  collision, varJetXjg, jetCutDphi, jetWeight,
		  phoCandCut, phoDecayCut,  hJetXjg, outName);
  

  if ( (collision == kPAMC) || (collision == kPPMC) ||(collision == kHIMC) ) {
    TH1D* hGenJetPt = (TH1D*)hJetPt->Clone(Form("genJetPt_icent%d",icent));
    corrFunctionTrk* cGenJetPt = new corrFunctionTrk();
    TString varGenJetPt         = Form("refPt");
    gammaTrkSingle( gSpec,  tObj, cJetPt,  purity, 
		    collision, varGenJetPt, genJetCutDphi, jetWeight,
		    phoCandCut, phoDecayCut,  hGenJetPt, outName);
    
    TH1D* hGenJetXjg = (TH1D*)hJetXjg->Clone(Form("xjg_genJet_icent%d",icent));
    corrFunctionTrk* cGenJetXjg = new corrFunctionTrk();
    TString varGenJetXjg         = Form("refPt/photonEt");
    gammaTrkSingle( gSpec,  tObj, cGenJetXjg,  purity, 
		    collision, varGenJetXjg, genJetCutDphi , jetWeight,
		    phoCandCut, phoDecayCut,  hGenJetXjg, outName);
    
    TH1D* hGenPhotonXjg = (TH1D*)hJetXjg->Clone(Form("xjg_genPho_icent%d",icent));
    corrFunctionTrk* cGenPhotonXjg = new corrFunctionTrk();
    TString varGenPhotonXjg         = Form("pt/genPhotonEt");
    gammaTrkSingle( gSpec,  tObj, cGenPhotonXjg,  purity, 
		    collision, varGenPhotonXjg, jetCutDphi, jetWeight,
		    phoCandCut, phoDecayCut,  hGenPhotonXjg, outName);
    
    TH1D* hGenPhoGenJetXjg = (TH1D*)hJetXjg->Clone(Form("xjg_genPho_genJet_icent%d",icent));
    corrFunctionTrk* cGenPhoGenJetXjg = new corrFunctionTrk();
    TString varGenPhoGenJetXjg         = Form("refPt/genPhotonEt");
    gammaTrkSingle( gSpec,  tObj, cGenPhoGenJetXjg,  purity, 
		    collision, varGenPhoGenJetXjg, genJetCutDphi, jetWeight,
		    phoCandCut, phoDecayCut,  hGenPhoGenJetXjg, outName);
  }
  
  bool doRapidity= false;
  if ( doRapidity) {
  // Eta distribution
    TH1D* hEtaJg = new TH1D(Form("etaJg_icent%d",icent),";#eta_{J,#gamma} ; ",160,-3,3);
    corrFunctionTrk* cEtaJg = new corrFunctionTrk();
    TString varEtaJg         = Form("(photonEta+eta)/2.");
    
    gammaTrkSingle( gSpec,  tObj, cEtaJg,  purity, 
		    collision, varEtaJg, jetCut2, jetWeight,
		    phoCandCut, phoDecayCut,  hEtaJg, outName);
    
    TH1D* hEtaJet = new TH1D(Form("etaJet_icent%d",icent),";#eta_{Jet} ; ",160,-3,3);
    corrFunctionTrk* cEtaJet = new corrFunctionTrk();
    TString varEtaJet         = Form("eta");
    
    gammaTrkSingle( gSpec,  tObj, cEtaJet,  purity, 
		    collision, varEtaJet, jetCut2, jetWeight,
		    phoCandCut, phoDecayCut,  hEtaJet, outName);
  
    TH1D* hEtaPhoton = new TH1D(Form("etaPhoton_icent%d",icent),";#eta_{#gamma} ; ",160,-3,3);
    corrFunctionTrk* cEtaPhoton = new corrFunctionTrk();
    TString varEtaPhoton         = Form("photonEta");
    
    gammaTrkSingle( gSpec,  tObj, cEtaPhoton,  purity, 
		    collision, varEtaPhoton, jetCut2, jetWeight,
		    phoCandCut, phoDecayCut,  hEtaPhoton, outName);
  }
  
}
//_____________________________________________________________________
void bfcMixer_TpcSvtSsd2005(const Int_t Nevents=100,Int_t isSvtIn=1, Int_t isSsdIn=1,
		    const Char_t *daqfile="/star/rcf/test/daq/2005/051/st_physics_adc_6051006_raw_1050001.daq",
		    const Char_t *tagfile="/star/rcf/test/embedding/cuProductionMinBias/FullField/P07ic/2005/051/st_physics_adc_6051006_raw_1050001.tags.root",
		    const Double_t pt_low=0.1,
		    const Double_t pt_high=5.0,
		    const Double_t eta_low=-1.0,
		    const Double_t eta_high=1.0,
		    const Int_t pid=9,
		    const Double_t mult = 0.1) {
  // production chain for P07ib
  TString prodP07ib("P2005b DbV20070518 MakeEvent ITTF Iana ToF spt SsdIt SvtIt pmdRaw SCEbyE OGridLeak OShortR OSpaceZ2 ssd_daq");// KeepSvtHit hitfilt skip1row");
  TString geomP07ib("ry2005f");
  TString chain1Opt("in magF tpcDb NoDefault -ittf NoOutput");
  TString chain2Opt("NoInput PrepEmbed gen_T geomT sim_T trs -ittf -tpc_daq nodefault");
  chain2Opt += " "; chain2Opt += geomP07ib;
  TString chain3Opt = prodP07ib;
  chain3Opt += " TpcMixer Embedding onlraw GeantOut MiniMcMk McAna IdTruth -in NoInput,useInTracker EmbeddingShortCut"; 
  if (isSvtIn) chain3Opt += " SvtEmbed";
  if (isSsdIn) {
    chain1Opt += ",ssddat";
    chain2Opt += ",ssd,McEvent,-spt";
    chain3Opt += ",SsdEmbed";
  }
  chain3Opt += " "; chain3Opt += geomP07ib;
  // Dynamically link some shared libs
  gROOT->LoadMacro("bfc.C");
  if (gClassTable->GetID("StBFChain") < 0) Load();
  //______________Create the main chain object______________________________________
  Chain = new StChain("Embedding");
  //________________________________________________________________________________
  bfc(-1,chain1Opt,daqfile);
  chain1 = chain;
  chain1->SetName("One"); 
  Chain->cd();
  //________________________________________________________________________________  
  bfc(-1,chain2Opt);
  chain2 = chain;
  chain2->SetName("Two"); 
  Chain->cd();
  if (chain2->GetOption("TRS")){
    StTrsMaker *trsMk = (StTrsMaker *) chain2->GetMaker("Trs");
    if (! trsMk) {
      cout << "Cannot find Trs in chain2" << endl;
      return;
    }
    trsMk->setNormalFactor(2.67);
  }
  //________________________________________________________________________________
  //  gSystem->Load("StFtpcMixerMaker");
  //  StFtpcMixerMaker  *ftpcmixer = new StFtpcMixerMaker("FtpcMixer","daq","trs");
  //________________________________________________________________________________
  TString OutputFileName(gSystem->BaseName(daqfile));
  OutputFileName.ReplaceAll("*","");
  OutputFileName.ReplaceAll(".daq","");
  //  OutputFileName.Append("_emb.root");
  OutputFileName.Append(".root");
  bfc(-1,chain3Opt,0,OutputFileName);
  chain3 = chain;
  chain3->SetName("Three"); 
  Chain->cd();
  Chain->cd();
  //________________________________________________________________________________
  {
    TDatime t;
    gMessMgr->QAInfo() << Form("Run is started at Date/Time %i/%i",t.GetDate(),t.GetTime()) << endm;
  }
  gMessMgr->QAInfo() << Form("Run on %s in %s",gSystem->HostName(),gSystem->WorkingDirectory()) << endm;
  gMessMgr->QAInfo() << Form("with %s", Chain->GetCVS()) << endm;
  // embedded particle set
  StPrepEmbedMaker *embMk = (StPrepEmbedMaker *) Chain->Maker("PrepEmbed");
  if (! embMk) return;
  embMk->SetTagFile(tagfile);
  //            pTlow,ptHigh,etaLow,etaHigh,phiLow,phiHigh
  embMk->SetOpt(  pt_low,    pt_high,  eta_low,    eta_high,    0.,   6.283185); 
  //                pid, mult
  embMk->SetPartOpt(  pid,mult);
  TAttr::SetDebug(0);
  Chain->SetAttr(".Privilege",0,"*"                ); 	//All  makers are NOT priviliged
  Chain->SetAttr(".Privilege",1,"StBFChain::*" ); 	//StBFChain is priviliged
  Chain->SetAttr(".Privilege",1,"StIOInterFace::*" ); 	//All IO makers are priviliged
  Chain->SetAttr(".Privilege",1,"St_geant_Maker::*"); 	//It is also IO maker
  Chain->SetAttr(".Privilege",1,"StPrepEmbedMaker::*"); //It is also IO maker
  StMaker *SsdEmbed = Chain->Maker("SsdEmbed");
  if (SsdEmbed) {
    cout << "SsdEmbed has been found ----------------------------------------" << endl;
    SsdEmbed->SetInput("SsdRealData","One/.make/SpaStrip/.data/spa_strip");
    SsdEmbed->SetInput("SsdSimuData","Two/.make/SpaStrip/.data/spa_strip");
    StMaker *SsdPoint = Chain->Maker("SsdPoint");
    if (SsdPoint) {
      cout << "SsdPoint has been found----------------------------------------" << endl;
      SsdPoint->SetInput("SpaStrip","SsdEmbed");
    }
  }
  //  Chain->SetDEBUG(0);
  if (Nevents < 0) return;
  Int_t iInit = Chain->Init();
  if (iInit >=  kStEOF) {Chain->FatalErr(iInit,"on init"); return;}
  StMaker *treeMk = Chain->GetMaker("outputStream");
  Chain->EventLoop(Nevents,treeMk);
  gMessMgr->QAInfo() << "Run completed " << endm;
  gSystem->Exec("date");
}
void DrawFakeEtaBins_reduced(std::string kSpecies="PbPb"){
  timer.Start();

  bool printDebug=false;
   TDatime date;

  std::string kAlgName="ak";
  std::string kSpeciesLong = "pp (PYTHIA)";
  if( kSpecies == "PbPb" ) { kAlgName="akPu";  kSpeciesLong = "PbPb (PYTHIA+HYDJET)"; }
  std::string kjetType="PF";
  
  LoadStyle();
  TH1::SetDefaultSumw2();
  TH2::SetDefaultSumw2();
  TH2F * hBlankRatio = new TH2F("hBlankRatio","",20,-2.1,2.1,50,0,1.0);
  TH2F * hBlankPhiRatio = new TH2F("hBlankPhiRatio","",20,-pi,pi,50,0,1.0);
  TH2F * hBlankPt= new TH2F("hBlankPt","",50,20,350,50,0,1.0);
  TH2F * hBlankPtEff= new TH2F("hBlankPtEff","",50,20,350,50,0.6,1.1);


    TH1F *hPtAll [2][ncen], *hPtEff [2][ncen];
    TH1F *hPtFakeAll[ncen], *hPtFake[2][ncen];
    TH1F *hPtFakeRatio[2][ncen];
    TH1F *hPtAll_etabin[2][ncen][neta], *hPtEff_etabin[2][ncen][neta];    
    TH1F *hPtFakeAll_etabin[ncen][neta], *hPtFake_etabin[2][ncen][neta];
    TH1F *hPtFakeRatio_etabin[2][ncen][neta];   
    TH1F *hPtEffRatio_etabin[2][ncen][neta];     
    TH1F *hPtEffRatio[2][ncen];     
    TH1F *hEtaFakeAll_20[ncen],*hEtaFakeAll_30[ncen], *hEtaFakeAll_40[ncen],*hEtaFakeAll_45[ncen], *hEtaFakeAll_50[ncen], *hEtaFakeAll_60[ncen];
    TH1F *hPhiFakeAll_20[ncen],*hPhiFakeAll_30[ncen], *hPhiFakeAll_40[ncen],*hPhiFakeAll_45[ncen], *hPhiFakeAll_50[ncen], *hPhiFakeAll_60[ncen];
    TH1F *hEtaFake_20[2][ncen],*hEtaFake_30[2][ncen], *hEtaFake_40[2][ncen],*hEtaFake_45[2][ncen], *hEtaFake_50[2][ncen], *hEtaFake_60[2][ncen];
    TH1F *hPhiFake_20[2][ncen],*hPhiFake_30[2][ncen], *hPhiFake_40[2][ncen],*hPhiFake_45[2][ncen], *hPhiFake_50[2][ncen], *hPhiFake_60[2][ncen];  
    TH1F *hEtaFakeRatio_20[2][ncen],*hEtaFakeRatio_30[2][ncen], *hEtaFakeRatio_40[2][ncen],*hEtaFakeRatio_45[2][ncen], *hEtaFakeRatio_50[2][ncen], *hEtaFakeRatio_60[2][ncen];
    TH1F *hPhiFakeRatio_20[2][ncen],*hPhiFakeRatio_30[2][ncen], *hPhiFakeRatio_40[2][ncen],*hPhiFakeRatio_45[2][ncen], *hPhiFakeRatio_50[2][ncen], *hPhiFakeRatio_60[2][ncen];

    TH1F *hEtaFakeRatio_70[2][ncen], *hEtaFakeRatio_80[2][ncen];
    TH1F *hPhiFakeRatio_70[2][ncen], *hPhiFakeRatio_80[2][ncen];
    TH1F *hEtaFakeAll_70[ncen], *hEtaFakeAll_80[ncen];
    TH1F *hPhiFakeAll_70[ncen], *hPhiFakeAll_80[ncen];
    TH1F *hEtaFake_70[2][ncen], *hEtaFake_80[2][ncen];
    TH1F *hPhiFake_70[2][ncen], *hPhiFake_80[2][ncen];
    
  TFile *fin = new TFile(Form("Histos/OutputHist_ntuples_reduced_eta_lt1pt8_%s.root",kSpecies.c_str()),"r");
// radius loop
    for(int nj=0; nj<knj; nj++){
    // i is the with or without jetID loop, NOT the nj loop! 0 == no JetID, 1== JetID
     for(int i=0; i<2; i++){
 // centrality loop    
      for(int ic=0; ic<ncen; ic++){
    	if(i==0){
     	  hPtFakeAll[ic] = (TH1F*)fin->Get(Form("hPtFakeAll_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic)); 
     	  hPtFakeAll[ic]->Print("base");  	  
    	  hEtaFakeAll_20[ic] = (TH1F*)fin->Get(Form("hEtaFakeAll_20_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic)); 
    	  hEtaFakeAll_20[ic]->Print("base");
    	  hPhiFakeAll_20[ic] = (TH1F*)fin->Get(Form("hPhiFakeAll_20_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic)); 
          hPhiFakeAll_20[ic]->Print("base");
    	  hEtaFakeAll_30[ic] = (TH1F*)fin->Get(Form("hEtaFakeAll_30_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic)); 
    	  hEtaFakeAll_30[ic]->Print("base");
    	  hPhiFakeAll_30[ic] = (TH1F*)fin->Get(Form("hPhiFakeAll_30_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic)); 
          hPhiFakeAll_30[ic]->Print("base");
    	  hEtaFakeAll_40[ic] = (TH1F*)fin->Get(Form("hEtaFakeAll_40_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic)); 
    	  hEtaFakeAll_40[ic]->Print("base");
    	  hPhiFakeAll_40[ic] = (TH1F*)fin->Get(Form("hPhiFakeAll_40_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic)); 
          hPhiFakeAll_40[ic]->Print("base");
    	  hEtaFakeAll_45[ic] = (TH1F*)fin->Get(Form("hEtaFakeAll_45_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic)); 
    	  hEtaFakeAll_45[ic] ->Print("base");
    	  hPhiFakeAll_45[ic] = (TH1F*)fin->Get(Form("hPhiFakeAll_45_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic)); 
          hPhiFakeAll_45[ic]->Print("base");
    	  hEtaFakeAll_50[ic] = (TH1F*)fin->Get(Form("hEtaFakeAll_50_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic));
    	  hEtaFakeAll_50[ic]->Print("base"); 
    	  hPhiFakeAll_50[ic] = (TH1F*)fin->Get(Form("hPhiFakeAll_50_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic)); 
    	  hPhiFakeAll_50[ic]->Print("base"); 
    	  hEtaFakeAll_60[ic] = (TH1F*)fin->Get(Form("hEtaFakeAll_60_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic)); 
    	  hEtaFakeAll_60[ic]->Print("base");
    	  hPhiFakeAll_60[ic] = (TH1F*)fin->Get(Form("hPhiFakeAll_60_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic)); 
          hPhiFakeAll_60[ic]->Print("base");
    	  hEtaFakeAll_70[ic] = (TH1F*)fin->Get(Form("hEtaFakeAll_70_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic)); 
    	  hEtaFakeAll_70[ic]->Print("base");
    	  hPhiFakeAll_70[ic] = (TH1F*)fin->Get(Form("hPhiFakeAll_70_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic)); 
          hPhiFakeAll_70[ic]->Print("base");
    	  hEtaFakeAll_80[ic] = (TH1F*)fin->Get(Form("hEtaFakeAll_80_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic)); 
    	  hEtaFakeAll_80[ic]->Print("base");
    	  hPhiFakeAll_80[ic] = (TH1F*)fin->Get(Form("hPhiFakeAll_80_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic)); 
          hPhiFakeAll_80[ic]->Print("base");
           for(int in=0; in<neta; in++){    
              hPtFakeAll_etabin[ic][in] = (TH1F*)fin->Get(Form("hPtFakeAll_etabin_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic,in)); 
     	      hPtFakeAll_etabin[ic][in]->Print("base");  
      	  }
   	  
    	}
     	  hPtAll[i][ic] = (TH1F*)fin->Get(Form("hPtAll_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
     	  hPtAll[i][ic]->Print("base");    	
    	// end if i=0 (no jetID)
     	hPtEff[i][ic] = (TH1F*)fin->Get(Form("hPtEff_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
     	hPtEff[i][ic]->Print("base");
    	hPtFake[i][ic] = (TH1F*)fin->Get(Form("hPtFake_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
        hPtFake[i][ic]->Print("base");
    	hEtaFake_20[i][ic] = (TH1F*)fin->Get(Form("hEtaFake_20_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
    	hEtaFake_20[i][ic]->Print("base");
    	hPhiFake_20[i][ic] = (TH1F*)fin->Get(Form("hPhiFake_20_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
        hPhiFake_20[i][ic]->Print("base");
    	hEtaFake_30[i][ic] = (TH1F*)fin->Get(Form("hEtaFake_30_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
    	hEtaFake_30[i][ic]->Print("base");
    	hPhiFake_30[i][ic] = (TH1F*)fin->Get(Form("hPhiFake_30_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
        hPhiFake_30[i][ic]->Print("base");
    	hEtaFake_40[i][ic] = (TH1F*)fin->Get(Form("hEtaFake_40_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
    	hEtaFake_40[i][ic]->Print("base");
    	hPhiFake_40[i][ic] = (TH1F*)fin->Get(Form("hPhiFake_40_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
        hPhiFake_40[i][ic]->Print("base");
    	hEtaFake_45[i][ic] = (TH1F*)fin->Get(Form("hEtaFake_45_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
    	hEtaFake_45[i][ic]->Print("base");
    	hPhiFake_45[i][ic] = (TH1F*)fin->Get(Form("hPhiFake_45_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
        hPhiFake_45[i][ic]->Print("base");
    	hEtaFake_50[i][ic] = (TH1F*)fin->Get(Form("hEtaFake_50_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
    	hEtaFake_50[i][ic]->Print("base");
    	hPhiFake_50[i][ic] = (TH1F*)fin->Get(Form("hPhiFake_50_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
   	    hPhiFake_50[i][ic]->Print("base");
    	hEtaFake_60[i][ic] = (TH1F*)fin->Get(Form("hEtaFake_60_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
    	hEtaFake_60[i][ic]->Print("base");
     	hEtaFake_60[i][ic]->Draw();   	
    	hPhiFake_60[i][ic] = (TH1F*)fin->Get(Form("hPhiFake_60_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
    	hPhiFake_60[i][ic]->Print("base");
    	hEtaFake_70[i][ic] = (TH1F*)fin->Get(Form("hEtaFake_70_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
    	hEtaFake_70[i][ic]->Print("base");
     	hEtaFake_70[i][ic]->Draw();   	
    	hPhiFake_70[i][ic] = (TH1F*)fin->Get(Form("hPhiFake_70_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
    	hPhiFake_70[i][ic]->Print("base");
    	hEtaFake_80[i][ic] = (TH1F*)fin->Get(Form("hEtaFake_80_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
    	hEtaFake_80[i][ic]->Print("base");
     	hEtaFake_80[i][ic]->Draw();   	
    	hPhiFake_80[i][ic] = (TH1F*)fin->Get(Form("hPhiFake_80_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic)); 
    	hPhiFake_80[i][ic]->Print("base");
    	hEtaFakeRatio_20[i][ic]=(TH1F*)hEtaFake_20[i][ic]->Clone(Form("hEtaFakeRatio_20_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	hEtaFakeRatio_20[i][ic]->Divide(hEtaFakeAll_20[ic]);
    	hEtaFakeRatio_30[i][ic]=(TH1F*)hEtaFake_30[i][ic]->Clone(Form("hEtaFakeRatio_30_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	hEtaFakeRatio_30[i][ic]->Divide(hEtaFakeAll_30[ic]);
    	hEtaFakeRatio_30[i][ic]->SetMarkerSize(2.5);
    	hEtaFakeRatio_40[i][ic]=(TH1F*)hEtaFake_40[i][ic]->Clone(Form("hEtaFakeRatio_40_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	hEtaFakeRatio_40[i][ic]->Divide(hEtaFakeAll_40[ic]);
    	hEtaFakeRatio_40[i][ic]->SetMarkerSize(2.5);
    	hEtaFakeRatio_45[i][ic]=(TH1F*)hEtaFake_45[i][ic]->Clone(Form("hEtaFakeRatio_45_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	hEtaFakeRatio_45[i][ic]->Divide(hEtaFakeAll_45[ic]);
    	hEtaFakeRatio_50[i][ic]=(TH1F*)hEtaFake_50[i][ic]->Clone(Form("hEtaFakeRatio_50_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	hEtaFakeRatio_50[i][ic]->Divide(hEtaFakeAll_50[ic]);
    	hEtaFakeRatio_50[i][ic]->SetMarkerSize(2.5);
    	hEtaFakeRatio_60[i][ic]=(TH1F*)hEtaFake_60[i][ic]->Clone(Form("hEtaFakeRatio_60_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	hEtaFakeRatio_60[i][ic]->Divide(hEtaFakeAll_60[ic]);
    	hEtaFakeRatio_60[i][ic]->SetMarkerSize(2.5);
     	hPhiFakeRatio_20[i][ic]=(TH1F*)hPhiFake_20[i][ic]->Clone(Form("hPhiFakeRatio_20_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	hPhiFakeRatio_20[i][ic]->Divide(hPhiFakeAll_20[ic]);
    	hPhiFakeRatio_30[i][ic]=(TH1F*)hPhiFake_30[i][ic]->Clone(Form("hPhiFakeRatio_30_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	hPhiFakeRatio_30[i][ic]->Divide(hPhiFakeAll_30[ic]);
    	hPhiFakeRatio_30[i][ic]->SetMarkerSize(2.5);
    	hPhiFakeRatio_40[i][ic]=(TH1F*)hPhiFake_40[i][ic]->Clone(Form("hPhiFakeRatio_40_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	hPhiFakeRatio_40[i][ic]->Divide(hPhiFakeAll_40[ic]);
    	hPhiFakeRatio_40[i][ic]->SetMarkerSize(2.5);
    	hPhiFakeRatio_45[i][ic]=(TH1F*)hPhiFake_45[i][ic]->Clone(Form("hPhiFakeRatio_45_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	hPhiFakeRatio_45[i][ic]->Divide(hPhiFakeAll_45[ic]);
    	hPhiFakeRatio_50[i][ic]=(TH1F*)hPhiFake_50[i][ic]->Clone(Form("hPhiFakeRatio_50_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	hPhiFakeRatio_50[i][ic]->Divide(hPhiFakeAll_50[ic]);
    	hPhiFakeRatio_50[i][ic]->SetMarkerSize(2.5);
    	hPhiFakeRatio_60[i][ic]=(TH1F*)hPhiFake_60[i][ic]->Clone(Form("hPhiFakeRatio_60_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	hPhiFakeRatio_60[i][ic]->Divide(hPhiFakeAll_60[ic]);
    	hPhiFakeRatio_60[i][ic]->SetMarkerSize(2.5);
    	hEtaFakeRatio_70[i][ic]=(TH1F*)hEtaFake_70[i][ic]->Clone(Form("hEtaFakeRatio_70_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	hEtaFakeRatio_70[i][ic]->Divide(hEtaFakeAll_70[ic]);
    	hEtaFakeRatio_70[i][ic]->SetMarkerSize(2.5);
    	hPhiFakeRatio_70[i][ic]=(TH1F*)hPhiFake_70[i][ic]->Clone(Form("hPhiFakeRatio_70_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	hPhiFakeRatio_70[i][ic]->Divide(hPhiFakeAll_70[ic]);
    	hPhiFakeRatio_70[i][ic]->SetMarkerSize(2.5);
    	hEtaFakeRatio_80[i][ic]=(TH1F*)hEtaFake_80[i][ic]->Clone(Form("hEtaFakeRatio_80_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	hEtaFakeRatio_80[i][ic]->Divide(hEtaFakeAll_80[ic]);
    	hEtaFakeRatio_80[i][ic]->SetMarkerSize(2.5);
    	hPhiFakeRatio_80[i][ic]=(TH1F*)hPhiFake_80[i][ic]->Clone(Form("hPhiFakeRatio_80_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	hPhiFakeRatio_80[i][ic]->Divide(hPhiFakeAll_80[ic]);
    	hPhiFakeRatio_80[i][ic]->SetMarkerSize(2.5);
    	    	
    	hPtFakeRatio[i][ic]=(TH1F*)hPtFake[i][ic]->Clone(Form("hPtFakeRatio_%s_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	hPtFakeRatio[i][ic]->Divide(hPtFakeAll[ic]);    
    	hPtFakeRatio[i][ic]->SetMarkerSize(2.5);	
        for(int in=0; in<neta; in++){
            hPtAll_etabin[i][ic][in] = (TH1F*)fin->Get(Form("hPtAll_etabin_%s_%d_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic,in)); 
     	   hPtAll_etabin[i][ic][in]->Print("base");       
     	   hPtEff_etabin[i][ic][in] = (TH1F*)fin->Get(Form("hPtEff_etabin_%s_%d_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic,in)); 
     	   hPtEff_etabin[i][ic][in]->Print("base");
    	   hPtFake_etabin[i][ic][in] = (TH1F*)fin->Get(Form("hPtFake_etabin_%s_%d_%d_%d",(kAlgName+srad[nj]+kjetType).c_str(),i,ic,in)); 
           hPtFake_etabin[i][ic][in]->Print("base");    	
    	   hPtFakeRatio_etabin[i][ic][in]=(TH1F*)hPtFake_etabin[i][ic][in]->Clone(Form("hPtFakeRatio_etabin%d_%s_%d_%d",in,(kAlgName+srad[nj]+kjetType).c_str(),i,ic));
    	   hPtFakeRatio_etabin[i][ic][in]->Divide(hPtFakeAll_etabin[ic][in]);    
    	   hPtFakeRatio_etabin[i][ic][in]->SetMarkerSize(2.5);	
    	   hPtEffRatio_etabin[i][ic][in]=(TH1F*)hPtEff_etabin[i][ic][in]->Clone(Form("hPtEffRatio_etabin%d_%s_%d",in,(kAlgName+srad[nj]+kjetType).c_str(),ic));
    	   hPtEffRatio_etabin[i][ic][in]->Divide(hPtAll_etabin[i][ic][in]);    
    	   hPtEffRatio_etabin[i][ic][in]->SetMarkerSize(2.5);	
    	}
    	   hPtEffRatio[i][ic]=(TH1F*)hPtEff[i][ic]->Clone(Form("hPtEffRatio_%s_%d",(kAlgName+srad[nj]+kjetType).c_str(),ic));
    	   hPtEffRatio[i][ic]->Divide(hPtAll[i][ic]);    
    	   hPtEffRatio[i][ic]->SetMarkerSize(2.5);	
    	
       }
//  end centrality loop
    	
     } // end i loop (JetID)   
//     if(nj==0){   
//         TCanvas *c0 = new TCanvas();
//         c0.cd();
//     } else {
//     if(nj==1){
//         TCanvas *c1 = new TCanvas();
//         c1.cd();
//     } else {
//     if(nj==2){
//         TCanvas *c2 = new TCanvas();
//         c2.cd();
//     }
    TCanvas * c30 = new TCanvas("c30","",1200,1000);
    TLegend *leg30 = getLegend(0.5,0.5,0.7,0.9);
    leg30->SetHeader("");   
    for(int ic=0; ic<ncen-2; ic++){
       hEtaFakeRatio_30[1][ic]->SetMarkerStyle(24+ic);
       if(ic==0){ hEtaFakeRatio_30[1][ic]->SetMarkerColor(kViolet); hEtaFakeRatio_30[1][ic]->SetLineColor(kViolet);}
       if(ic==1){ hEtaFakeRatio_30[1][ic]->SetMarkerColor(kGreen+1); hEtaFakeRatio_30[1][ic]->SetLineColor(kGreen+1);}
       if(ic==2){ hEtaFakeRatio_30[1][ic]->SetMarkerColor(kRed); hEtaFakeRatio_30[1][ic]->SetLineColor(kRed);}
       if(ic==3){ hEtaFakeRatio_30[1][ic]->SetMarkerColor(kBlue); hEtaFakeRatio_30[1][ic]->SetLineColor(kBlue);}
       if(ic==4){ hEtaFakeRatio_30[1][ic]->SetMarkerColor(kPink);  hEtaFakeRatio_30[1][ic]->SetLineColor(kPink);}
       if(ic==5){ hEtaFakeRatio_30[1][ic]->SetMarkerColor(kYellow); hEtaFakeRatio_30[1][ic]->SetLineColor(kYellow);}
       if(ic==0){
         hBlankRatio->SetTitle(Form(" %s, %s, jetID, pT>30 GeV/c",(kAlgName+srad[nj]+kjetType).c_str(),kSpeciesLong.c_str()));
         hBlankRatio->GetXaxis()->SetTitle("Reco jet eta");
         hBlankRatio->GetYaxis()->SetTitle("Fake rate");
         hBlankRatio->Draw();
       }
       leg30->AddEntry(hEtaFakeRatio_30[1][ic],Form("%s",ccent[ic]),"p");
       hEtaFakeRatio_30[1][ic]->Draw("same");
    }
    leg30->Draw();    
     c30->SaveAs(Form("ANPlots/FakeEtaRate_30_%sMC_JetID_%s_%d.pdf",kSpecies.c_str(),(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE");
//          hBlankRatio->SetTitle(Form(" %s, pp (PYTHIA), jetID, pT>30 GeV/c ",(kAlgName+srad[nj]+kjetType).c_str()));
//          hBlankRatio->GetXaxis()->SetTitle("Reco jet eta");
//          hBlankRatio->GetYaxis()->SetTitle("Fake rate");
//          hBlankRatio->Draw(); 
//          leg30->AddEntry(hEtaFakeRatio_30[1][7],Form("%s",ccent[7]),"p"); 
//          hEtaFakeRatio_30[1][7]->Draw("same"); 
//     c30->SaveAs(Form("ANPlots/FakeEtaRate_30_ppMC_JetID_%s_%d.pdf",(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE");
    
    TCanvas * c40 = new TCanvas("c40","",1200,1000);
    TLegend *leg40 = getLegend(0.5,0.5,0.7,0.9);
    leg40->SetHeader("");    
    for(int ic=0; ic<ncen-2; ic++){
       hEtaFakeRatio_40[1][ic]->SetMarkerStyle(24+ic);
       if(ic==0){ hEtaFakeRatio_40[1][ic]->SetMarkerColor(kViolet); hEtaFakeRatio_40[1][ic]->SetLineColor(kViolet);}
       if(ic==1){ hEtaFakeRatio_40[1][ic]->SetMarkerColor(kGreen+1); hEtaFakeRatio_40[1][ic]->SetLineColor(kGreen+1);}
       if(ic==2){ hEtaFakeRatio_40[1][ic]->SetMarkerColor(kRed); hEtaFakeRatio_40[1][ic]->SetLineColor(kRed);}
       if(ic==3){ hEtaFakeRatio_40[1][ic]->SetMarkerColor(kBlue); hEtaFakeRatio_40[1][ic]->SetLineColor(kBlue);}
       if(ic==4){ hEtaFakeRatio_40[1][ic]->SetMarkerColor(kPink);  hEtaFakeRatio_40[1][ic]->SetLineColor(kPink);}
       if(ic==5){ hEtaFakeRatio_40[1][ic]->SetMarkerColor(kYellow); hEtaFakeRatio_40[1][ic]->SetLineColor(kYellow);}
       if(ic==0){
         hBlankRatio->SetTitle(Form(" %s, %s, jetID, pT>40 GeV/c",(kAlgName+srad[nj]+kjetType).c_str(),kSpeciesLong.c_str()));
         hBlankRatio->GetXaxis()->SetTitle("Reco jet eta");
         hBlankRatio->GetYaxis()->SetTitle("Fake rate");
         hBlankRatio->Draw();
       }
       leg40->AddEntry(hEtaFakeRatio_40[1][ic],Form("%s",ccent[ic]),"p");
      hEtaFakeRatio_40[1][ic]->Draw("same");
    }
    leg40->Draw();
    c40->SaveAs(Form("ANPlots/FakeEtaRate_40_%sMC_JetID_%s_%d.pdf",kSpecies.c_str(),(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE");
//          hBlankRatio->SetTitle(Form(" %s, pp (PYTHIA), jetID, pT>40 GeV/c ",(kAlgName+srad[nj]+kjetType).c_str()));
//          hBlankRatio->GetXaxis()->SetTitle("Reco jet eta");
//          hBlankRatio->GetYaxis()->SetTitle("Fake rate");
//          hBlankRatio->Draw(); 
//          leg40->AddEntry(hEtaFakeRatio_40[1][7],Form("%s",ccent[7]),"p"); 
//          hEtaFakeRatio_40[1][7]->Draw("same"); 
//     c40->SaveAs(Form("ANPlots/FakeEtaRate_40_ppMC_JetID_%s_%d.pdf",(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE");
    
    TCanvas * c50 = new TCanvas("c50","",1200,1000);
    TLegend *leg50 = getLegend(0.5,0.5,0.7,0.9);
    leg50->SetHeader("");   
    for(int ic=0; ic<ncen-2; ic++){
       hEtaFakeRatio_50[1][ic]->SetMarkerStyle(24+ic);
       if(ic==0){ hEtaFakeRatio_50[1][ic]->SetMarkerColor(kViolet); hEtaFakeRatio_50[1][ic]->SetLineColor(kViolet);}
       if(ic==1){ hEtaFakeRatio_50[1][ic]->SetMarkerColor(kGreen+1); hEtaFakeRatio_50[1][ic]->SetLineColor(kGreen+1);}
       if(ic==2){ hEtaFakeRatio_50[1][ic]->SetMarkerColor(kRed); hEtaFakeRatio_50[1][ic]->SetLineColor(kRed);}
       if(ic==3){ hEtaFakeRatio_50[1][ic]->SetMarkerColor(kBlue); hEtaFakeRatio_50[1][ic]->SetLineColor(kBlue);}
       if(ic==4){ hEtaFakeRatio_50[1][ic]->SetMarkerColor(kPink);  hEtaFakeRatio_50[1][ic]->SetLineColor(kPink);}
       if(ic==5){ hEtaFakeRatio_50[1][ic]->SetMarkerColor(kYellow); hEtaFakeRatio_50[1][ic]->SetLineColor(kYellow);}
       if(ic==0){
         hBlankRatio->SetTitle(Form(" %s, %s, jetID, pT>50 GeV/c",(kAlgName+srad[nj]+kjetType).c_str(),kSpeciesLong.c_str()));
         hBlankRatio->GetXaxis()->SetTitle("Reco jet eta");
         hBlankRatio->GetYaxis()->SetTitle("Fake rate");
         hBlankRatio->Draw();
       }
       leg50->AddEntry(hEtaFakeRatio_50[1][ic],Form("%s",ccent[ic]),"p");
       hEtaFakeRatio_50[1][ic]->Draw("same");
    }
    leg50->Draw();
    c50->SaveAs(Form("ANPlots/FakeEtaRate_50_%sMC_JetID_%s_%d.pdf",kSpecies.c_str(),(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE");
//          hBlankRatio->SetTitle(Form(" %s, pp (PYTHIA), jetID, pT>50 GeV/c ",(kAlgName+srad[nj]+kjetType).c_str()));
//          hBlankRatio->GetXaxis()->SetTitle("Reco jet eta");
//          hBlankRatio->GetYaxis()->SetTitle("Fake rate");
//          hBlankRatio->Draw(); 
//          leg50->AddEntry(hEtaFakeRatio_50[1][7],Form("%s",ccent[7]),"p"); 
//          hEtaFakeRatio_50[1][7]->Draw("same"); 
//     c50->SaveAs(Form("ANPlots/FakeEtaRate_50_ppMC_JetID_%s_%d.pdf",(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE");

    TCanvas * c60 = new TCanvas("c60","",1200,1000);
    TLegend *leg60 = getLegend(0.5,0.5,0.7,0.9);
    leg60->SetHeader("");      
    for(int ic=0; ic<ncen-2; ic++){
       hEtaFakeRatio_60[1][ic]->SetMarkerStyle(24+ic);
       if(ic==0){ hEtaFakeRatio_60[1][ic]->SetMarkerColor(kViolet); hEtaFakeRatio_60[1][ic]->SetLineColor(kViolet);}
       if(ic==1){ hEtaFakeRatio_60[1][ic]->SetMarkerColor(kGreen+1); hEtaFakeRatio_60[1][ic]->SetLineColor(kGreen+1);}
       if(ic==2){ hEtaFakeRatio_60[1][ic]->SetMarkerColor(kRed); hEtaFakeRatio_60[1][ic]->SetLineColor(kRed);}
       if(ic==3){ hEtaFakeRatio_60[1][ic]->SetMarkerColor(kBlue); hEtaFakeRatio_60[1][ic]->SetLineColor(kBlue);}
       if(ic==4){ hEtaFakeRatio_60[1][ic]->SetMarkerColor(kPink);  hEtaFakeRatio_60[1][ic]->SetLineColor(kPink);}
       if(ic==5){ hEtaFakeRatio_60[1][ic]->SetMarkerColor(kYellow); hEtaFakeRatio_60[1][ic]->SetLineColor(kYellow);}
       if(ic==0){
         hBlankRatio->SetTitle(Form(" %s, %s, jetID, pT>60 GeV/c",(kAlgName+srad[nj]+kjetType).c_str(),kSpeciesLong.c_str()));
         hBlankRatio->GetXaxis()->SetTitle("Reco jet eta");
         hBlankRatio->GetYaxis()->SetTitle("Fake rate");
         hBlankRatio->Draw();
       }
       leg60->AddEntry(hEtaFakeRatio_60[1][ic],Form("%s",ccent[ic]),"p");
       hEtaFakeRatio_60[1][ic]->Draw("same");  
    }
    leg60->Draw();    
    c60->SaveAs(Form("ANPlots/FakeEtaRate_60_%sMC_JetID_%s_%d.pdf",kSpecies.c_str(),(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE");    

    TCanvas * c70 = new TCanvas("c70","",1200,1000);
    TLegend *leg70 = getLegend(0.5,0.5,0.7,0.9);
    leg70->SetHeader("");      
    for(int ic=0; ic<ncen-2; ic++){
       hEtaFakeRatio_70[1][ic]->SetMarkerStyle(24+ic);
       if(ic==0){ hEtaFakeRatio_70[1][ic]->SetMarkerColor(kViolet); hEtaFakeRatio_70[1][ic]->SetLineColor(kViolet);}
       if(ic==1){ hEtaFakeRatio_70[1][ic]->SetMarkerColor(kGreen+1); hEtaFakeRatio_70[1][ic]->SetLineColor(kGreen+1);}
       if(ic==2){ hEtaFakeRatio_70[1][ic]->SetMarkerColor(kRed); hEtaFakeRatio_70[1][ic]->SetLineColor(kRed);}
       if(ic==3){ hEtaFakeRatio_70[1][ic]->SetMarkerColor(kBlue); hEtaFakeRatio_70[1][ic]->SetLineColor(kBlue);}
       if(ic==4){ hEtaFakeRatio_70[1][ic]->SetMarkerColor(kPink);  hEtaFakeRatio_70[1][ic]->SetLineColor(kPink);}
       if(ic==5){ hEtaFakeRatio_70[1][ic]->SetMarkerColor(kYellow); hEtaFakeRatio_70[1][ic]->SetLineColor(kYellow);}
       if(ic==0){
         hBlankRatio->SetTitle(Form(" %s, %s, jetID, pT>70 GeV/c",(kAlgName+srad[nj]+kjetType).c_str(),kSpeciesLong.c_str()));
         hBlankRatio->GetXaxis()->SetTitle("Reco jet eta");
         hBlankRatio->GetYaxis()->SetTitle("Fake rate");
         hBlankRatio->Draw();
       }
       leg70->AddEntry(hEtaFakeRatio_70[1][ic],Form("%s",ccent[ic]),"p");
       hEtaFakeRatio_70[1][ic]->Draw("same");  
    }
    leg70->Draw();    
    c70->SaveAs(Form("ANPlots/FakeEtaRate_70_%sMC_JetID_%s_%d.pdf",kSpecies.c_str(),(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE");    

    TCanvas * c80 = new TCanvas("c80","",1200,1000);
    TLegend *leg80 = getLegend(0.5,0.5,0.7,0.9);
    leg80->SetHeader("");      
    for(int ic=0; ic<ncen-2; ic++){
       hEtaFakeRatio_80[1][ic]->SetMarkerStyle(24+ic);
       if(ic==0){ hEtaFakeRatio_80[1][ic]->SetMarkerColor(kViolet); hEtaFakeRatio_80[1][ic]->SetLineColor(kViolet);}
       if(ic==1){ hEtaFakeRatio_80[1][ic]->SetMarkerColor(kGreen+1); hEtaFakeRatio_80[1][ic]->SetLineColor(kGreen+1);}
       if(ic==2){ hEtaFakeRatio_80[1][ic]->SetMarkerColor(kRed); hEtaFakeRatio_80[1][ic]->SetLineColor(kRed);}
       if(ic==3){ hEtaFakeRatio_80[1][ic]->SetMarkerColor(kBlue); hEtaFakeRatio_80[1][ic]->SetLineColor(kBlue);}
       if(ic==4){ hEtaFakeRatio_80[1][ic]->SetMarkerColor(kPink);  hEtaFakeRatio_80[1][ic]->SetLineColor(kPink);}
       if(ic==5){ hEtaFakeRatio_80[1][ic]->SetMarkerColor(kYellow); hEtaFakeRatio_80[1][ic]->SetLineColor(kYellow);}
       if(ic==0){
         hBlankRatio->SetTitle(Form(" %s, %s, jetID, pT>80 GeV/c",(kAlgName+srad[nj]+kjetType).c_str(),kSpeciesLong.c_str()));
         hBlankRatio->GetXaxis()->SetTitle("Reco jet eta");
         hBlankRatio->GetYaxis()->SetTitle("Fake rate");
         hBlankRatio->Draw();
       }
       leg80->AddEntry(hEtaFakeRatio_80[1][ic],Form("%s",ccent[ic]),"p");
       hEtaFakeRatio_80[1][ic]->Draw("same");  
    }
    leg80->Draw();    
    c80->SaveAs(Form("ANPlots/FakeEtaRate_80_%sMC_JetID_%s_%d.pdf",kSpecies.c_str(),(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE");    

//          hBlankRatio->SetTitle(Form(" %s, pp (PYTHIA), jetID, pT>60 GeV/c ",(kAlgName+srad[nj]+kjetType).c_str()));
//          hBlankRatio->GetXaxis()->SetTitle("Reco jet eta");
//          hBlankRatio->GetYaxis()->SetTitle("Fake rate");
//          hBlankRatio->Draw(); 
//          leg60->AddEntry(hEtaFakeRatio_60[1][7],Form("%s",ccent[7]),"p"); 
//          hEtaFakeRatio_60[1][7]->Draw("same"); 
//     c60->SaveAs(Form("ANPlots/FakeEtaRate_60_ppMC_JetID_%s_%d.pdf",(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE");

// phi plots
    TCanvas * cPhi30 = new TCanvas("cPhi30","",1200,1000);
    TLegend *legPhi30 = getLegend(0.5,0.5,0.7,0.9);
    legPhi30->SetHeader("");   
    for(int ic=0; ic<ncen-2; ic++){
       hPhiFakeRatio_30[1][ic]->SetMarkerStyle(24+ic);
       if(ic==0){ hPhiFakeRatio_30[1][ic]->SetMarkerColor(kViolet); hPhiFakeRatio_30[1][ic]->SetLineColor(kViolet);}
       if(ic==1){ hPhiFakeRatio_30[1][ic]->SetMarkerColor(kGreen+1); hPhiFakeRatio_30[1][ic]->SetLineColor(kGreen+1);}
       if(ic==2){ hPhiFakeRatio_30[1][ic]->SetMarkerColor(kRed); hPhiFakeRatio_30[1][ic]->SetLineColor(kRed);}
       if(ic==3){ hPhiFakeRatio_30[1][ic]->SetMarkerColor(kBlue); hPhiFakeRatio_30[1][ic]->SetLineColor(kBlue);}
       if(ic==4){ hPhiFakeRatio_30[1][ic]->SetMarkerColor(kPink);  hPhiFakeRatio_30[1][ic]->SetLineColor(kPink);}
       if(ic==5){ hPhiFakeRatio_30[1][ic]->SetMarkerColor(kYellow); hPhiFakeRatio_30[1][ic]->SetLineColor(kYellow);}
       if(ic==0){
         hBlankPhiRatio->SetTitle(Form(" %s, %s, jetID, pT>30 GeV/c |eta|<%.2f",(kAlgName+srad[nj]+kjetType).c_str(),kSpeciesLong.c_str(),ketacut));
         hBlankPhiRatio->GetXaxis()->SetTitle("Reco jet Phi");
         hBlankPhiRatio->GetYaxis()->SetTitle("Fake rate");
         hBlankPhiRatio->Draw();
       }
       legPhi30->AddEntry(hPhiFakeRatio_30[1][ic],Form("%s",ccent[ic]),"p");
       hPhiFakeRatio_30[1][ic]->Draw("same");
    }
    legPhi30->Draw();    
    cPhi30->SaveAs(Form("ANPlots/FakePhiRate_30_%sMC_JetID_%s_%d.pdf",kSpecies.c_str(),(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE");
    TCanvas * cPhi40 = new TCanvas("cPhi40","",1200,1000);
    TLegend *legPhi40 = getLegend(0.5,0.5,0.7,0.9);
    legPhi40->SetHeader("");    
    for(int ic=0; ic<ncen-2; ic++){
       hPhiFakeRatio_40[1][ic]->SetMarkerStyle(24+ic);
       if(ic==0){ hPhiFakeRatio_40[1][ic]->SetMarkerColor(kViolet); hPhiFakeRatio_40[1][ic]->SetLineColor(kViolet);}
       if(ic==1){ hPhiFakeRatio_40[1][ic]->SetMarkerColor(kGreen+1); hPhiFakeRatio_40[1][ic]->SetLineColor(kGreen+1);}
       if(ic==2){ hPhiFakeRatio_40[1][ic]->SetMarkerColor(kRed); hPhiFakeRatio_40[1][ic]->SetLineColor(kRed);}
       if(ic==3){ hPhiFakeRatio_40[1][ic]->SetMarkerColor(kBlue); hPhiFakeRatio_40[1][ic]->SetLineColor(kBlue);}
       if(ic==4){ hPhiFakeRatio_40[1][ic]->SetMarkerColor(kPink);  hPhiFakeRatio_40[1][ic]->SetLineColor(kPink);}
       if(ic==5){ hPhiFakeRatio_40[1][ic]->SetMarkerColor(kYellow); hPhiFakeRatio_40[1][ic]->SetLineColor(kYellow);}
       if(ic==0){
         hBlankPhiRatio->SetTitle(Form(" %s, %s, jetID, pT>40 GeV/c |eta|<%.2f",(kAlgName+srad[nj]+kjetType).c_str(),kSpeciesLong.c_str(),ketacut));
         hBlankPhiRatio->GetXaxis()->SetTitle("Reco jet Phi");
         hBlankPhiRatio->GetYaxis()->SetTitle("Fake rate");
         hBlankPhiRatio->Draw();
       }
       legPhi40->AddEntry(hPhiFakeRatio_40[1][ic],Form("%s",ccent[ic]),"p");
      hPhiFakeRatio_40[1][ic]->Draw("same");
    }
    legPhi40->Draw();
    cPhi40->SaveAs(Form("ANPlots/FakePhiRate_40_%sMC_JetID_%s_%d.pdf",kSpecies.c_str(),(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE");
    TCanvas * cPhi50 = new TCanvas("cPhi50","",1200,1000);
    TLegend *legPhi50 = getLegend(0.5,0.5,0.7,0.9);
    legPhi50->SetHeader("");   
    for(int ic=0; ic<ncen-2; ic++){
       hPhiFakeRatio_50[1][ic]->SetMarkerStyle(24+ic);
       if(ic==0){ hPhiFakeRatio_50[1][ic]->SetMarkerColor(kViolet); hPhiFakeRatio_50[1][ic]->SetLineColor(kViolet);}
       if(ic==1){ hPhiFakeRatio_50[1][ic]->SetMarkerColor(kGreen+1); hPhiFakeRatio_50[1][ic]->SetLineColor(kGreen+1);}
       if(ic==2){ hPhiFakeRatio_50[1][ic]->SetMarkerColor(kRed); hPhiFakeRatio_50[1][ic]->SetLineColor(kRed);}
       if(ic==3){ hPhiFakeRatio_50[1][ic]->SetMarkerColor(kBlue); hPhiFakeRatio_50[1][ic]->SetLineColor(kBlue);}
       if(ic==4){ hPhiFakeRatio_50[1][ic]->SetMarkerColor(kPink);  hPhiFakeRatio_50[1][ic]->SetLineColor(kPink);}
       if(ic==5){ hPhiFakeRatio_50[1][ic]->SetMarkerColor(kYellow); hPhiFakeRatio_50[1][ic]->SetLineColor(kYellow);}
       if(ic==0){
         hBlankPhiRatio->SetTitle(Form(" %s, %s, jetID, pT>50 GeV/c |eta|<%.2f",(kAlgName+srad[nj]+kjetType).c_str(),kSpeciesLong.c_str(),ketacut));
         hBlankPhiRatio->GetXaxis()->SetTitle("Reco jet Phi");
         hBlankPhiRatio->GetYaxis()->SetTitle("Fake rate");
         hBlankPhiRatio->Draw();
       }
       legPhi50->AddEntry(hPhiFakeRatio_50[1][ic],Form("%s",ccent[ic]),"p");
       hPhiFakeRatio_50[1][ic]->Draw("same");
    }
    legPhi50->Draw();
    cPhi50->SaveAs(Form("ANPlots/FakePhiRate_50_%sMC_JetID_%s_%d.pdf",kSpecies.c_str(),(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE");
    TCanvas * cPhi60 = new TCanvas("cPhi60","",1200,1000);
    TLegend *legPhi60 = getLegend(0.5,0.5,0.7,0.9);
    legPhi60->SetHeader("");      
    for(int ic=0; ic<ncen-2; ic++){
       hPhiFakeRatio_60[1][ic]->SetMarkerStyle(24+ic);
       if(ic==0){ hPhiFakeRatio_60[1][ic]->SetMarkerColor(kViolet); hPhiFakeRatio_60[1][ic]->SetLineColor(kViolet);}
       if(ic==1){ hPhiFakeRatio_60[1][ic]->SetMarkerColor(kGreen+1); hPhiFakeRatio_60[1][ic]->SetLineColor(kGreen+1);}
       if(ic==2){ hPhiFakeRatio_60[1][ic]->SetMarkerColor(kRed); hPhiFakeRatio_60[1][ic]->SetLineColor(kRed);}
       if(ic==3){ hPhiFakeRatio_60[1][ic]->SetMarkerColor(kBlue); hPhiFakeRatio_60[1][ic]->SetLineColor(kBlue);}
       if(ic==4){ hPhiFakeRatio_60[1][ic]->SetMarkerColor(kPink);  hPhiFakeRatio_60[1][ic]->SetLineColor(kPink);}
       if(ic==5){ hPhiFakeRatio_60[1][ic]->SetMarkerColor(kYellow); hPhiFakeRatio_60[1][ic]->SetLineColor(kYellow);}
       if(ic==0){
         hBlankPhiRatio->SetTitle(Form(" %s, %s, jetID, pT>60 GeV/c |eta|<%.2f",(kAlgName+srad[nj]+kjetType).c_str(),kSpeciesLong.c_str(),ketacut));
         hBlankPhiRatio->GetXaxis()->SetTitle("Reco jet Phi");
         hBlankPhiRatio->GetYaxis()->SetTitle("Fake rate");
         hBlankPhiRatio->Draw();
       }
       legPhi60->AddEntry(hPhiFakeRatio_60[1][ic],Form("%s",ccent[ic]),"p");
       hPhiFakeRatio_60[1][ic]->Draw("same");  
    }
    legPhi60->Draw();    
    cPhi60->SaveAs(Form("ANPlots/FakePhiRate_60_%sMC_JetID_%s_%d.pdf",kSpecies.c_str(),(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE"); 
    TCanvas * cPhi70 = new TCanvas("cPhi70","",1200,1000);
    TLegend *legPhi70 = getLegend(0.5,0.5,0.7,0.9);
    legPhi70->SetHeader("");      
    for(int ic=0; ic<ncen-2; ic++){
       hPhiFakeRatio_70[1][ic]->SetMarkerStyle(24+ic);
       if(ic==0){ hPhiFakeRatio_70[1][ic]->SetMarkerColor(kViolet); hPhiFakeRatio_70[1][ic]->SetLineColor(kViolet);}
       if(ic==1){ hPhiFakeRatio_70[1][ic]->SetMarkerColor(kGreen+1); hPhiFakeRatio_70[1][ic]->SetLineColor(kGreen+1);}
       if(ic==2){ hPhiFakeRatio_70[1][ic]->SetMarkerColor(kRed); hPhiFakeRatio_70[1][ic]->SetLineColor(kRed);}
       if(ic==3){ hPhiFakeRatio_70[1][ic]->SetMarkerColor(kBlue); hPhiFakeRatio_70[1][ic]->SetLineColor(kBlue);}
       if(ic==4){ hPhiFakeRatio_70[1][ic]->SetMarkerColor(kPink);  hPhiFakeRatio_70[1][ic]->SetLineColor(kPink);}
       if(ic==5){ hPhiFakeRatio_70[1][ic]->SetMarkerColor(kYellow); hPhiFakeRatio_70[1][ic]->SetLineColor(kYellow);}
       if(ic==0){
         hBlankPhiRatio->SetTitle(Form(" %s, %s, jetID, pT>70 GeV/c |eta|<%.2f",(kAlgName+srad[nj]+kjetType).c_str(),kSpeciesLong.c_str(),ketacut));
         hBlankPhiRatio->GetXaxis()->SetTitle("Reco jet Phi");
         hBlankPhiRatio->GetYaxis()->SetTitle("Fake rate");
         hBlankPhiRatio->Draw();
       }
       legPhi70->AddEntry(hPhiFakeRatio_70[1][ic],Form("%s",ccent[ic]),"p");
       hPhiFakeRatio_70[1][ic]->Draw("same");  
    }
    legPhi70->Draw();    
    cPhi70->SaveAs(Form("ANPlots/FakePhiRate_70_%sMC_JetID_%s_%d.pdf",kSpecies.c_str(),(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE"); 
     TCanvas * cPhi80 = new TCanvas("cPhi80","",1200,1000);
    TLegend *legPhi80 = getLegend(0.5,0.5,0.7,0.9);
    legPhi80->SetHeader("");      
    for(int ic=0; ic<ncen-2; ic++){
       hPhiFakeRatio_80[1][ic]->SetMarkerStyle(24+ic);
       if(ic==0){ hPhiFakeRatio_80[1][ic]->SetMarkerColor(kViolet); hPhiFakeRatio_80[1][ic]->SetLineColor(kViolet);}
       if(ic==1){ hPhiFakeRatio_80[1][ic]->SetMarkerColor(kGreen+1); hPhiFakeRatio_80[1][ic]->SetLineColor(kGreen+1);}
       if(ic==2){ hPhiFakeRatio_80[1][ic]->SetMarkerColor(kRed); hPhiFakeRatio_80[1][ic]->SetLineColor(kRed);}
       if(ic==3){ hPhiFakeRatio_80[1][ic]->SetMarkerColor(kBlue); hPhiFakeRatio_80[1][ic]->SetLineColor(kBlue);}
       if(ic==4){ hPhiFakeRatio_80[1][ic]->SetMarkerColor(kPink);  hPhiFakeRatio_80[1][ic]->SetLineColor(kPink);}
       if(ic==5){ hPhiFakeRatio_80[1][ic]->SetMarkerColor(kYellow); hPhiFakeRatio_80[1][ic]->SetLineColor(kYellow);}
       if(ic==0){
         hBlankPhiRatio->SetTitle(Form(" %s, %s, jetID, pT>80 GeV/c |eta|<%.2f",(kAlgName+srad[nj]+kjetType).c_str(),kSpeciesLong.c_str(),ketacut));
         hBlankPhiRatio->GetXaxis()->SetTitle("Reco jet Phi");
         hBlankPhiRatio->GetYaxis()->SetTitle("Fake rate");
         hBlankPhiRatio->Draw();
       }
       legPhi80->AddEntry(hPhiFakeRatio_80[1][ic],Form("%s",ccent[ic]),"p");
       hPhiFakeRatio_80[1][ic]->Draw("same");  
    }
    legPhi80->Draw();    
    cPhi80->SaveAs(Form("ANPlots/FakePhiRate_80_%sMC_JetID_%s_%d.pdf",kSpecies.c_str(),(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE"); 
            
    TCanvas * cpT = new TCanvas("cpT","",1200,1000);
    TLegend *legpT = getLegend(0.5,0.5,0.7,0.9);
    legpT->SetHeader("");   
    for(int ic=0; ic<ncen-2; ic++){
       hPtFakeRatio[1][ic]->SetMarkerStyle(24+ic);
       if(ic==0){ hPtFakeRatio[1][ic]->SetMarkerColor(kViolet); hPtFakeRatio[1][ic]->SetLineColor(kViolet);}
       if(ic==1){ hPtFakeRatio[1][ic]->SetMarkerColor(kGreen+1); hPtFakeRatio[1][ic]->SetLineColor(kGreen+1);}
       if(ic==2){ hPtFakeRatio[1][ic]->SetMarkerColor(kRed); hPtFakeRatio[1][ic]->SetLineColor(kRed);}
       if(ic==3){ hPtFakeRatio[1][ic]->SetMarkerColor(kBlue); hPtFakeRatio[1][ic]->SetLineColor(kBlue);}
       if(ic==4){ hPtFakeRatio[1][ic]->SetMarkerColor(kPink);  hPtFakeRatio[1][ic]->SetLineColor(kPink);}
       if(ic==5){ hPtFakeRatio[1][ic]->SetMarkerColor(kYellow); hPtFakeRatio[1][ic]->SetLineColor(kYellow);}
       if(ic==0){
         hBlankPt->SetTitle(Form(" %s, %s, jetID",(kAlgName+srad[nj]+kjetType).c_str(),kSpeciesLong.c_str()));
         hBlankPt->GetXaxis()->SetTitle(Form("Reco jet pT (GeV/c) |eta|<%.2f",ketacut));
         hBlankPt->GetYaxis()->SetTitle("Fake rate");
         hBlankPt->Draw();
       }
       legpT->AddEntry(hPtFakeRatio[1][ic],Form("%s",ccent[ic]),"p");
       hPtFakeRatio[1][ic]->Draw("same");
    }
    legpT->Draw();    
     cpT->SaveAs(Form("ANPlots/FakeRatepT_%sMC_JetID_%s_%d.pdf",kSpecies.c_str(),(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE");
     
    TCanvas * cpT_etabin = new TCanvas("cpT_etabin","",1200,1000);
    TLegend *legpT_etabin = getLegend(0.5,0.5,0.7,0.9);
    legpT_etabin->SetHeader("");   
    for(int ic=0; ic<ncen-2; ic++){
       hPtFakeRatio_etabin[1][ic][0]->SetMarkerStyle(24+ic);
       if(ic==0){ hPtFakeRatio_etabin[1][ic][0]->SetMarkerColor(kViolet); hPtFakeRatio_etabin[1][ic][0]->SetLineColor(kViolet);}
       if(ic==1){ hPtFakeRatio_etabin[1][ic][0]->SetMarkerColor(kGreen+1); hPtFakeRatio_etabin[1][ic][0]->SetLineColor(kGreen+1);}
       if(ic==2){ hPtFakeRatio_etabin[1][ic][0]->SetMarkerColor(kRed); hPtFakeRatio_etabin[1][ic][0]->SetLineColor(kRed);}
       if(ic==3){ hPtFakeRatio_etabin[1][ic][0]->SetMarkerColor(kBlue); hPtFakeRatio_etabin[1][ic][0]->SetLineColor(kBlue);}
       if(ic==4){ hPtFakeRatio_etabin[1][ic][0]->SetMarkerColor(kPink);  hPtFakeRatio_etabin[1][ic][0]->SetLineColor(kPink);}
       if(ic==5){ hPtFakeRatio_etabin[1][ic][0]->SetMarkerColor(kYellow); hPtFakeRatio_etabin[1][ic][0]->SetLineColor(kYellow);}
       if(ic==0){
         hBlankPt->SetTitle(Form(" %s, %s, jetID",(kAlgName+srad[nj]+kjetType).c_str(),kSpeciesLong.c_str()));
         hBlankPt->GetXaxis()->SetTitle(Form("Reco jet pT (GeV/c) %s",seta[0]));
         hBlankPt->GetYaxis()->SetTitle("Fake rate");
         hBlankPt->Draw();
       }
       legpT_etabin->AddEntry(hPtFakeRatio_etabin[1][ic][0],Form("%s",ccent[ic]),"p");
       hPtFakeRatio_etabin[1][ic][0]->Draw("same");
    }
    legpT_etabin->Draw();    
     cpT_etabin->SaveAs(Form("ANPlots/FakeRatepT_etabin%d_%sMC_JetID_%s_%d.pdf",0,kSpecies.c_str(),(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE");
     
    TCanvas * cpT_eff_etabin = new TCanvas("cpT_eff_etabin","",1200,1000);
    TLegend *legpT_eff_etabin = getLegend(0.5,0.5,0.3,0.7);
    legpT_eff_etabin->SetHeader("");   
    for(int ic=0; ic<ncen-2; ic++){
       hPtEffRatio_etabin[0][ic][0]->SetMarkerStyle(24+ic);
       if(ic==0){ hPtEffRatio_etabin[0][ic][0]->SetMarkerColor(kViolet); hPtEffRatio_etabin[0][ic][0]->SetLineColor(kViolet);}
       if(ic==1){ hPtEffRatio_etabin[0][ic][0]->SetMarkerColor(kGreen+1); hPtEffRatio_etabin[0][ic][0]->SetLineColor(kGreen+1);}
       if(ic==2){ hPtEffRatio_etabin[0][ic][0]->SetMarkerColor(kRed); hPtEffRatio_etabin[0][ic][0]->SetLineColor(kRed);}
       if(ic==3){ hPtEffRatio_etabin[0][ic][0]->SetMarkerColor(kBlue); hPtEffRatio_etabin[0][ic][0]->SetLineColor(kBlue);}
       if(ic==4){ hPtEffRatio_etabin[0][ic][0]->SetMarkerColor(kPink);  hPtEffRatio_etabin[0][ic][0]->SetLineColor(kPink);}
       if(ic==5){ hPtEffRatio_etabin[0][ic][0]->SetMarkerColor(kYellow); hPtEffRatio_etabin[0][ic][0]->SetLineColor(kYellow);}
       if(ic==0){
         hBlankPtEff->SetTitle(Form(" %s, %s",(kAlgName+srad[nj]+kjetType).c_str(),kSpeciesLong.c_str()));
         hBlankPtEff->GetXaxis()->SetTitle(Form("Reco jet pT (GeV/c) %s",seta[0]));
         hBlankPtEff->GetYaxis()->SetTitle("Efficiency");
         hBlankPtEff->Draw();
       }
       legpT_eff_etabin->AddEntry(hPtEffRatio_etabin[0][ic][0],Form("%s",ccent[ic]),"p");
       hPtEffRatio_etabin[0][ic][0]->Draw("same");
    }
    legpT_eff_etabin->Draw();    
     cpT_eff_etabin->SaveAs(Form("ANPlots/EfficiencypT_eff_etabin%d_%sMC_noJetID_%s_%d.pdf",0,kSpecies.c_str(),(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE");

    TCanvas * cpT_eff = new TCanvas("cpT_eff","",1200,1000);
    TLegend *legpT_eff = getLegend(0.5,0.5,0.3,0.7);
    legpT_eff->SetHeader("");   
    for(int ic=0; ic<ncen-2; ic++){
       hPtEffRatio[0][ic]->SetMarkerStyle(24+ic);
       if(ic==0){ hPtEffRatio[0][ic]->SetMarkerColor(kViolet); hPtEffRatio[0][ic]->SetLineColor(kViolet);}
       if(ic==1){ hPtEffRatio[0][ic]->SetMarkerColor(kGreen+1); hPtEffRatio[0][ic]->SetLineColor(kGreen+1);}
       if(ic==2){ hPtEffRatio[0][ic]->SetMarkerColor(kRed); hPtEffRatio[0][ic]->SetLineColor(kRed);}
       if(ic==3){ hPtEffRatio[0][ic]->SetMarkerColor(kBlue); hPtEffRatio[0][ic]->SetLineColor(kBlue);}
       if(ic==4){ hPtEffRatio[0][ic]->SetMarkerColor(kPink);  hPtEffRatio[0][ic]->SetLineColor(kPink);}
       if(ic==5){ hPtEffRatio[0][ic]->SetMarkerColor(kYellow); hPtEffRatio[0][ic]->SetLineColor(kYellow);}
       if(ic==0){
         hBlankPtEff->SetTitle(Form(" %s, %s",(kAlgName+srad[nj]+kjetType).c_str(),kSpeciesLong.c_str()));
         hBlankPtEff->GetXaxis()->SetTitle(Form("Reco jet pT (GeV/c) |eta|<%.2f",ketacut));
         hBlankPtEff->GetYaxis()->SetTitle("Efficiency");
         hBlankPtEff->Draw();
       }
       legpT_eff->AddEntry(hPtEffRatio[0][ic],Form("%s",ccent[ic]),"p");
       hPtEffRatio[0][ic]->Draw("same");
    }
    legpT_eff->Draw();    
     cpT_eff->SaveAs(Form("ANPlots/EfficiencypT_etaLt2_%sMC_noJetID_%s_%d.pdf",kSpecies.c_str(),(kAlgName+srad[nj]+kjetType).c_str(),date.GetDate()),"RECREATE");

    } // end nj loop (radius)
    
} // end program
Exemple #26
0
//_____________________________________________________________________
void bfcMixer_TpcSvtSsd(const Int_t Nevents=500,Int_t isSvtIn=1, Int_t isSsdIn=1,
		    const Char_t *daqfile="/star/rcf/test/daq/2007/113/8113044/st_physics_8113044_raw_1040042.daq",
		    const Char_t *tagfile="/star/rcf/test/embedding/2007ProductionMinBias/FullField/P08if/2007/113/8113044/st_physics_8113044_raw_1040042.tags.root",
		    const Double_t pt_low=0.1,
		    const Double_t pt_high=5.0,
		    const Double_t eta_low=-1.1,
		    const Double_t eta_high=1.1,
	            const Double_t vzlow=-175.0,
		    const Double_t vzhigh=175.0,
		    const Int_t pid=8,
		    const Double_t mult = 100.,
                    const std::vector<Int_t> triggers = 0,
                    const Char_t* prodName = "P08icAuAu",
                    const Char_t* mode="flatpt"
) {
  // Separate DB timestamp to add it in both chain1 and chain3
  TString DbVP06idpp("DbV20060729 ");
  TString DbVP07icCuCu("DbV20070518 ");
  TString DbVP08icAuAu("DbV20080418 ");

  // production chains for P06id - p+p 200 GeV (Run6)
  TString prodP06idpp("pp2006b ITTF OSpaceZ2 OGridLeak3D VFMCE -VFPPVnoCTB -hitfilt");

  // production chain for P07ib
//  TString prodP07ib("P2005b DbV20070518 MakeEvent ITTF Iana ToF spt SsdIt SvtIt pmdRaw SCEbyE OGridLeak OShortR OSpaceZ2 ssd_daq");// KeepSvtHit hitfilt skip1row");

  // production chain for P07ic - Cu+Cu 200 GeV (Run5)
  TString prodP07icCuCu("P2005b DbV20070518 MakeEvent ITTF ToF ssddat spt SsdIt SvtIt pmdRaw OGridLeak OShortR OSpaceZ2 KeepSvtHit skip1row VFMCE -VFMinuit -hitfilt");

  // production chain for P08if
//    TString prodP08if("B2007g DbV20080418 adcOnly MakeEvent ITTF Iana ToF spt SsdIt SvtIt pmdRaw SCEbyE  OShortR trgd Corr5 OSpaceZ2 ssd_daq KeepSvtHit -hitfilt VFMCE");// KeepSvtHit hitfilt skip1row");

  // Production chain for P08ic Au+Au 200 GeV (Run7)
  TString prodP08icAuAu("B2007g ITTF adcOnly IAna KeepSvtHit VFMCE -hitfilt l3onl emcDY2 fpd ftpc trgd ZDCvtx svtIT ssdIT Corr5 -dstout");

  TString geomP06id("ry2006");
  TString geomP07ic("ry2005f");
  TString geomP08ic("ry2007g");
//  TString chain1Opt("in magF tpcDb adcOnly NoDefault -ittf NoOutput");
  TString chain1Opt("in magF tpcDb NoDefault -ittf NoOutput");
  TString chain2Opt("NoInput PrepEmbed gen_T geomT sim_T trs -ittf -tpc_daq nodefault");

  TString chain3Opt("");
  if( prodName == "P06idpp") {
    chain1Opt.Prepend(DbVP06idpp);
    chain2Opt += " "; chain2Opt += geomP06id;
    chain3Opt = prodP06idpp ;
  }
  else if( prodName == "P07ic" ){
    chain1Opt.Prepend(DbVP07icCuCu);
    chain2Opt += " "; chain2Opt += geomP07ic;
    chain3Opt = prodP07icCuCu;
  }
  else if ( prodName == "P08icAuAu" ){
    chain1Opt.Prepend(DbVP08icAuAu);
    chain2Opt += " "; chain2Opt += geomP08ic;
    chain3Opt = prodP08icAuAu ;
  }
  else{
    cout << "Choice prodName does not correspond to known chain. Processing impossible. " << endl;
    return;
  }
  //  chain3Opt += " Embedding onlraw GeantOut MiniMcMk McAna IdTruth -in NoInput,useInTracker EmbeddingShortCut"; 
//  chain3Opt += " Embedding onlraw McEvent McEvOut GeantOut MiniMcMk McAna IdTruth -in NoInput,useInTracker -hitfilt EmbeddingShortCut"; 
  chain3Opt += " TpcMixer Embedding onlraw McEvent McEvOut GeantOut MiniMcMk McAna IdTruth -in NoInput,useInTracker -hitfilt -TrsPileUp -TrsToF";
  //  chain3Opt += " Embedding onlraw McEvent McEvOut GeantOut IdTruth -in NoInput -hitfilt EmbeddingShortCut"; 

  if (isSvtIn) chain3Opt += " SvtEmbed";
  if (isSsdIn) {
    chain1Opt += ",ssddat";
    chain2Opt += ",ssd,McEvent,-spt";
    chain3Opt += ",SsdEmbed";
  }

  if( prodName == "P06idpp") {
    chain3Opt.Prepend(DbVP06idpp);
    chain3Opt += " "; chain3Opt += geomP06id;
  }
  else if( prodName == "P07ic" ){
    chain3Opt.Prepend(DbVP07icCuCu);
    chain3Opt += " "; chain3Opt += geomP07ic;
  }
  else if ( prodName == "P08icAuAu" ){
    chain3Opt.Prepend(DbVP08icAuAu);
    chain3Opt += " "; chain3Opt += geomP08ic;
  }
  else{
    cout << "Choice prodName does not correspond to known chain. Processing impossible. " << endl;
    return;
  }

  // Dynamically link some shared libs
  gROOT->LoadMacro("bfc.C");
  if (gClassTable->GetID("StBFChain") < 0) Load();
  //______________Create the main chain object______________________________________
  Chain = new StChain("Embedding");
  //________________________________________________________________________________
  bfc(-1,chain1Opt,daqfile);
  chain1 = chain;
  chain1->SetName("One"); 
  Chain->cd();
  //________________________________________________________________________________  
  bfc(-1,chain2Opt);
  chain2 = chain;
  chain2->SetName("Two"); 
  Chain->cd();
  if (chain2->GetOption("TRS")){
    StTrsMaker *trsMk = (StTrsMaker *) chain2->GetMaker("Trs");
    if (! trsMk) {
      cout << "Cannot find Trs in chain2" << endl;
      return;
    }
    trsMk->setNormalFactor(1.05);
    trsMk->SetMode(0);
  }
  //________________________________________________________________________________
  //  gSystem->Load("StFtpcMixerMaker");
  //  StFtpcMixerMaker  *ftpcmixer = new StFtpcMixerMaker("FtpcMixer","daq","trs");
  //________________________________________________________________________________
  TString OutputFileName(gSystem->BaseName(daqfile));
  OutputFileName.ReplaceAll("*","");
  OutputFileName.ReplaceAll(".daq","");
  //  OutputFileName.Append("_emb.root");
  OutputFileName.Append(".root");
  bfc(-1,chain3Opt,0,OutputFileName);
  chain3 = chain;
  chain3->SetName("Three"); 
  Chain->cd();
  Chain->cd();
  //________________________________________________________________________________
  {
    TDatime t;
    gMessMgr->QAInfo() << Form("Run is started at Date/Time %i/%i",t.GetDate(),t.GetTime()) << endm;
  }
  gMessMgr->QAInfo() << Form("Run on %s in %s",gSystem->HostName(),gSystem->WorkingDirectory()) << endm;
  gMessMgr->QAInfo() << Form("with %s", Chain->GetCVS()) << endm;
  // embedded particle set
  StPrepEmbedMaker *embMk = (StPrepEmbedMaker *) Chain->Maker("PrepEmbed");
  if (! embMk) return;
  embMk->SetTagFile(tagfile);
  //            pTlow,ptHigh,etaLow,etaHigh,phiLow,phiHigh
  embMk->SetOpt(  pt_low,    pt_high,  eta_low,    eta_high,    0.,   6.283185, mode); 
  //                pid, mult
  embMk->SetPartOpt(  pid,mult);

  // Set Skip mode (default is OFF)
  embMk->SetSkipMode(kFALSE) ;

  // Make trigger and z-vertex cuts (only if SkipMode is true)
  // Trigger cut
  //   Can put multiple trigger id's 
  if ( !triggers.empty() ){
    for(std::vector<Int_t>::iterator iter = triggers.begin(); iter != triggers.end(); iter++){
      embMk->SetTrgOpt((*iter)) ;
    }
  }

  // z-vertex cuts
  embMk->SetZVertexCut(vzlow, vzhigh) ;

  TAttr::SetDebug(0);
  Chain->SetAttr(".Privilege",0,"*"                ); 	//All  makers are NOT priviliged
  Chain->SetAttr(".Privilege",1,"StBFChain::*" ); 	//StBFChain is priviliged
  Chain->SetAttr(".Privilege",1,"StIOInterFace::*" ); 	//All IO makers are priviliged
  Chain->SetAttr(".Privilege",1,"St_geant_Maker::*"); 	//It is also IO maker
  Chain->SetAttr(".Privilege",1,"StPrepEmbedMaker::*"); //It is also IO maker
  StMaker *SsdEmbed = Chain->Maker("SsdEmbed");
  if (SsdEmbed) {
    cout << "SsdEmbed has been found ----------------------------------------" << endl;
    SsdEmbed->SetInput("SsdRealData","One/.make/SpaStrip/.data/spa_strip");
    SsdEmbed->SetInput("SsdSimuData","Two/.make/SpaStrip/.data/spa_strip");
    StMaker *SsdPoint = Chain->Maker("SsdPoint");
    if (SsdPoint) {
      cout << "SsdPoint has been found----------------------------------------" << endl;
      SsdPoint->SetInput("SpaStrip","SsdEmbed");
    }
  }
  //  Chain->SetDEBUG(0);
  if (Nevents < 0) return;
  Int_t iInit = Chain->Init();
  if (iInit >=  kStEOF) {Chain->FatalErr(iInit,"on init"); return;}
  StMaker *treeMk = Chain->GetMaker("outputStream");

  Chain->EventLoop(Nevents,treeMk);
  gMessMgr->QAInfo() << "Run completed " << endm;
  gSystem->Exec("date");
}
/**
 * This is an alternative to bfcMixer_pythia() allowing the user to explicitly
 * specify BFC options for all three chains.
 *
 * Sample input values:
 *
 * daqFileList = "@run10148002.list"
 * fzdFile     = "/path/to/my_pythia.fzd"
 * flag        = "W"
 *
 */
void EmbeddingReco(const int nEvents, const std::string daqFileList, const std::string fzdFile,
   const std::string bfcOptionsChain1, const std::string bfcOptionsChain2, const std::string bfcOptionsChain3,
   const std::string flag)
{
   // Dynamically link some shared libs
   gROOT->LoadMacro("bfc.C");

   if (gClassTable->GetID("StBFChain") < 0) Load();

   //______________Create the main chain object______________________________________
   Chain = new StChain("Embedding");
   //________________________________________________________________________________
   bfc(-1, bfcOptionsChain1.c_str(), daqFileList.c_str());
   chain1 = chain;
   chain1->SetName("One");
   chain1->SetAttr(".call", "SetActive(0)", "St_db_Maker::"); // Use DB cache to reduce overhead
   Chain->cd();
   //________________________________________________________________________________
   bfc(-1, bfcOptionsChain2.c_str(), fzdFile.c_str());
   chain2 = chain;
   chain2->SetName("Two");
   Chain->cd();

   if (chain2->GetOption("TRS")) {
      StTrsMaker *trsMk = (StTrsMaker *) chain2->GetMaker("Trs");

      if (!trsMk) {
         cout << "Cannot find Trs in chain2" << endl;
         return;
      }

      trsMk->setNormalFactor(1.32);
      trsMk->SetMode(0);
   }

   //________________________________________________________________________________
   //  gSystem->Load("StFtpcMixerMaker");
   //  StFtpcMixerMaker  *ftpcmixer = new StFtpcMixerMaker("FtpcMixer","daq","trs");
   //________________________________________________________________________________
   TString OutputFileName(gSystem->BaseName(fzdFile.c_str()));
   OutputFileName.ReplaceAll("*", "");
   OutputFileName.ReplaceAll(".fzd", "");
   //  OutputFileName.Append("_emb.root");
   OutputFileName.Append(".root");
   bfc(-1, bfcOptionsChain3.c_str(), 0, OutputFileName);
   chain3 = chain;
   chain3->SetName("Three");
   Chain->cd();
   //________________________________________________________________________________
   StTpcMixerMaker  *mixer = (StTpcMixerMaker *) chain3->Maker("TpcMixer");

   mixer->SetInput("Input1", "TpxRaw/.data/Event");

	if (bfcOptionsChain2.find("TpcRS") != std::string::npos) {
      mixer->SetInput("Input2", "TpcRS/Event");
   }
   else {
      mixer->SetInput("Input2", "Trs/.const/Event");
   }

   Chain->cd();

   if (flag == "W") {
      // blacklist some detectors to save DB load
      St_db_Maker *dbMk = (St_db_Maker *)chain3->GetMaker("db");
      dbMk->SetAttr("blacklist", "svt");
      dbMk->SetAttr("blacklist", "ssd");
      //  dbMk->SetAttr("blacklist", "ftpc"); // S.F.
   }

   //------------------------------------ EMC MIXERS ------------------------------------
   // Add BEMC mixer to chain3
   StEmcRawMaker *emcRaw = (StEmcRawMaker *)chain3->GetMaker("emcRaw");
   emcRaw->getBemcRaw()->saveAllStEvent(true); // use all 4800 BEMC towers
   gSystem->Load("StEmcMixerMaker");
   StEmcMixerMaker *bemcMixer = new StEmcMixerMaker;
   chain3->AddAfter("EmcSimulator", bemcMixer);
   // Set EEMC fast and slow simulator in embedding mode
   StEEmcFastMaker *eefs = (StEEmcFastMaker *)chain3->GetMaker("eefs");
   eefs->SetEmbeddingMode(); // Use local StEmcCollection
   eefs->UseFullTower(true); // Use full ETOW detector
   StEEmcSlowMaker *eess = new StEEmcSlowMaker;
   eess->setEmbeddingMode(true);
   // Add EEMC mixer to chain3
   StEEmcMixerMaker *eemcMixer = new StEEmcMixerMaker;
   //------------------------------------------------------------------------------------

   //----------------------------- TRIGGER FILTER -----------------------------
   // We want to achieve the following ordering for makers:
   // 1. BBC simulator
   // 2. BEMC simulator
   // 3. BEMC mixer
   // 4. EEMC fast simulator
   // 5. EEMC slow simulator
   // 6. EEMC mixer
   // 7. Pythia event maker
   // 8. Trigger simulator
   // 9. Trigger filter
   // 10. TPC maker

   // Place TPC chain after EMC makers
   chain3->AddAfter("eefs", chain3->GetMaker("tpcChain"));
   chain3->AddAfter("eefs", eemcMixer);
   chain3->AddAfter("eefs", eess);

   if (flag == "Jet") {
      // Place Pythia maker after GEANT maker
      // and trigger filter after EMC makers
      gSystem->Load("StJetSkimEvent");
      gSystem->Load("StMCAsymMaker");
      gSystem->Load("StBfcTriggerFilterMaker");

      StPythiaEventMaker *pythia = new StPythiaEventMaker;
      TString pyfile = gSystem->BaseName(fzdFile.c_str());
      pyfile.ReplaceAll(".fzd", ".pythia.root");
      pythia->SetPythiaFile(pyfile);
      chain3->AddAfter("geant", pythia);

      // Place trigger simulator after EMC makers
      gSystem->Load("StTriggerUtilities");
      StTriggerSimuMaker *trgsim = new StTriggerSimuMaker;
      trgsim->setMC(1);
      // BBC was not used in Run 9 jet triggers
      //trgsim->useBbc();
      //trgsim->bbc->setSource("StEvent");
      trgsim->useBemc();
      trgsim->bemc->setConfig(StBemcTriggerSimu::kOnline);
      trgsim->useEemc();
      trgsim->eemc->setSource("StEvent");

      /*
      trgsim->bemc->setBarrelJetPatchTh0(32);
      trgsim->bemc->setBarrelJetPatchTh1(43);
      trgsim->bemc->setBarrelJetPatchTh2(64);
      */
      trgsim->setBarrelJetPatchTh(0, 32); // set for Run-11 based on trigger versioning page 20130728
      trgsim->setBarrelJetPatchTh(1, 43);
      trgsim->setBarrelJetPatchTh(2, 64);

      trgsim->setOverlapJetPatchTh(0, 32);
      trgsim->setOverlapJetPatchTh(1, 43);
      trgsim->setOverlapJetPatchTh(2, 64);

      trgsim->setEndcapJetPatchTh(0, 32);
      trgsim->setEndcapJetPatchTh(1, 43);
      trgsim->setEndcapJetPatchTh(2, 64);

      trgsim->setBarrelHighTowerTh(0, 11);
      trgsim->setBarrelHighTowerTh(1, 18);
      trgsim->setBarrelHighTowerTh(2, 25);
      trgsim->setBarrelHighTowerTh(3, 31);

      trgsim->setEndcapHighTowerTh(0, 25);
      trgsim->setEndcapHighTowerTh(1, 31);

      //  StBfcTriggerFilterMaker* trgfilt = new StBfcTriggerFilterMaker;
      // no trigger filter for Run-11 VPDMB
      //  trgfilt->SetOkAllEvents(1);
      // The BFC trigger filter will select only JP1, AJP and BHT3 events
      //  trgfilt->SetJP1();
      //  trgfilt->SetAJP();
      //  trgfilt->SetBHT3();

      // Lower all jet patch thresholds by one unit from
      // their values obtained from the database using
      // the current timestamp.
      //trgfilt->changeJPThresh(-1);
      chain3->AddBefore("tpcChain", trgsim);
      //  chain3->AddBefore("tpcChain",trgfilt); // no trigger filter for Run-11 VPDMB

      // Move these makers after trigger decision
      // *** VERY IMPORTANT ***
      // The order of TpxRaw and TpcRS *must* be preserved
      // or the embedding will *not* work. [RT# 2299]
      // http://www.star.bnl.gov/rt2/Ticket/Display.html?id=2299
      StTpcRSMaker *TpcRS = (StTpcRSMaker *)chain2->GetMaker("TpcRS");
      StTpcHitMaker *TpxRaw = (StTpcHitMaker *)chain1->GetMaker("TpxRaw");
      chain3->AddBefore("TpcMixer", TpxRaw);
      chain3->AddBefore("TpcMixer", TpcRS);

#if 0
      // Turn on debugging of DB maker
      St_db_Maker *db = (St_db_Maker *)chain1->GetMaker("db");
      db->SetDebug(2);
#endif

      //--------------------------------------------------------------------------
      TString trgfile = gSystem->BaseName(fzdFile.c_str());
      trgfile.ReplaceAll(".fzd", ".trig.root");
      TFile *ofile = TFile::Open(trgfile, "recreate");
      assert(ofile);
      TH2F *hBarrelHighTowerSimu = new TH2F("hBarrelHighTowerSimu", "BEMC high tower simu;trigger patch;high tower", 300, 0, 300, 64, 0, 64);
      TH2F *hBarrelPatchSumSimu = new TH2F("hBarrelPatchSumSimu", "BEMC patch sum simu;trigger patch;patch sum", 300, 0, 300, 64, 0, 64);
      TH2F *hEndcapHighTowerSimu = new TH2F("hEndcapHighTowerSimu", "EEMC high tower simu;trigger patch;high tower", 90, 0, 90, 64, 0, 64);
      TH2F *hEndcapPatchSumSimu = new TH2F("hEndcapPatchSumSimu", "EEMC patch sum simu;trigger patch;patch sum", 90, 0, 90, 64, 0, 64);
      TH2F *hBarrelJetPatchSimu = new TH2F("hBarrelJetPatchSimu", "BEMC jet patch;jet patch;adc", 18, 0, 18, 160, 0, 160);
      TH2F *hEndcapJetPatchSimu = new TH2F("hEndcapJetPatchSimu", "EEMC jet patch;jet patch;adc", 6, 0, 6, 160, 0, 160);
      TH2F *hOverlapJetPatchSimu = new TH2F("hOverlapJetPatchSimu", "BEMC-EEMC-overlap;jet patch;adc", 6, 0, 6, 160, 0, 160);
   }

   //--------------------------------------------------------------------------
   // Initialize chain
   Chain->Init();
   PrintTimer(Chain);
   puts("Order of makers in BFCMIXER:");
   StMaker::lsMakers(Chain);
   // Event loop
   int mNTotal = 0;
   int mNFailed = 0;
   TBenchmark evnt;
   StIOMaker *inputStream = (StIOMaker *)chain1->GetMaker("inputStream");

   for (int iEvent = 1; iEvent <= nEvents; ++iEvent) {
      evnt.Reset();
      evnt.Start("QAInfo:");
      Chain->Clear();
      int iMake = Chain->Make(iEvent);

      if (iMake == kStErr) ++mNFailed;

      if (inputStream->GetMakeReturn() % 10 == kStEOF) {
         inputStream->Rewind();
         --iEvent;
         continue;
      }

      //if (iMake == kStSkip) continue;
      if (iMake % 10 == kStEOF || iMake % 10 == kStFatal) break;

      ++mNTotal;
      PrintTimer(Chain);
      //--------------------------------------------------------------------------

      if (flag == "Jet") {
         // BEMC high towers and trigger patches
         for (int triggerpatch = 0; triggerpatch < 300; ++triggerpatch) {
            hBarrelHighTowerSimu->Fill(triggerpatch, trgsim->bemc->getBEMC_FEE_HT_ADC()[triggerpatch]);
            hBarrelPatchSumSimu->Fill(triggerpatch, trgsim->bemc->getBEMC_FEE_TP_ADC()[triggerpatch]);
         } // for triggerpatch

         // BEMC jet patches
         for (int jetpatch = 0; jetpatch < 18; ++jetpatch) {
            hBarrelJetPatchSimu->Fill(jetpatch, trgsim->bemc->barrelJetPatchAdc(jetpatch));
         } // for jetpatch

         // EEMC high towers and trigger patches
         for (int triggerpatch = 0; triggerpatch < 90; ++triggerpatch) {
            hEndcapHighTowerSimu->Fill(triggerpatch, trgsim->eemc->getEndcapHighTower(triggerpatch));
            hEndcapPatchSumSimu->Fill(triggerpatch, trgsim->eemc->getEndcapPatchSum(triggerpatch));
         } // for triggerpatch

         // EEMC jet patches
         for (int jetpatch = 0; jetpatch < 6; ++jetpatch) {
            hEndcapJetPatchSimu->Fill(jetpatch, trgsim->eemc->endcapJetPatchAdc(jetpatch));
         } // for jetpatch

         // BEMC-EEMC-overlap jet patches
         for (int i = 0; i < 2; ++i) {
            int jetpatch, adc;
            trgsim->emc->getOverlapJetPatchAdc(i, jetpatch, adc);
            hOverlapJetPatchSimu->Fill(jetpatch, adc);
         } // for i
      } //end of if("jet")

      //--------------------------------------------------------------------------
      evnt.Stop("QAInfo:");
      printf("QAInfo: Done with Event [no. %d/run %d/evt. %d/Date.Time %d.%d/sta %d] Real Time = %10.2f seconds Cpu Time = %10.2f seconds\n", iEvent, Chain->GetRunNumber(), Chain->GetEventNumber(), Chain->GetDate(), Chain->GetTime(), chain3->GetMakeReturn(), evnt.GetRealTime("QAInfo:"), evnt.GetCpuTime("QAInfo:"));
   } // End event loop

   printf("QAInfo:EventLoop completed code %d\n", iMake);
   gSystem->Exec("date");
   TDatime t;
   printf("QAInfo:Run is finished at Date/Time %i/%i; Total events processed: %i and not completed: %i\n", t.GetDate(), t.GetTime(), mNTotal, mNFailed);

   //--------------------------------------------------------------------------
   if (flag == "Jet") {
      ofile->Write();
      ofile->Close();
   }
}
Exemple #28
0
//_____________________________________________________________________
void bfcMixer_pp2006( Int_t Nevents=10,
			  Char_t *file1="star/data03/daq/2006/120/7120049/st_physics_adc_7120049_raw_1050001.daq", // probably ppLong 2006 run, NOT for real embedding - just for testing
			  //Char_t *file1="st_zerobias_7118049_raw_1110001.daq",// contains 127 events, good foor real embedding
			  // Char_t *file2="eleB.fzd", // one-particle events from Naresh
			  Char_t *file2="mcpi0_hipt_run140_gid7_1000evts.fzd",
			  Int_t useEndcapSlowSim=1
			  // note, Barrel slow sim is always ON, said Adam 
			  ){
  TString path1="/";
  //TString path2="/star/data04/sim/subbanly/electron2006/oneTrack2Keve/fzd/";
    TString path2="/star/u/wzhang/links/gc2002/EEmc/embedData/fzd/";

  // Dynamically link some shared libs
  if (gClassTable->GetID("StBFChain") < 0) Load();

  // Create the main chain object
  chain = new StBFChain("Embedding");
  
  StMaker *saveMk = 0;
  chain->SetFlags("-ittf,NoDefault");
  // Create chain1 object
  chain1 = new StBFChain("One");
  
  saveMk = chain1->cd();
  chain1->SetFlags("in Physics  NoDefault -ittf -trg"); //Akio said OK for '-trg'.
  chain1->Set_IO_Files(path1+file1);
  chain1->Load();
  chain1->Instantiate();

  saveMk->cd();
  
  // Create chain2 object
  chain2 = new StBFChain("Two");
  saveMk = chain2->cd();
  chain2->SetFlags("fzin gen_T geomT sim_T tpc trs -tcl -tpt -PreVtx -tpc_daq -ittf ");   
  chain2->Set_IO_Files(path2+file2);
  chain2->Load();
  chain2->Instantiate();
  St_geant_Maker *geantMk = chain2->GetMaker("geant");
  if (geantMk) geantMk->SetMode(1);   // Mixer mode - do not modify EvtHddr

  // do not rescale dEdx in TRS, it leads to wrong cluster formation, from Jamie
 
  saveMk->cd();

  // Mixer for TPC
  gSystem->Load("StMixerMaker");
  StMixerMaker  *mixer = new StMixerMaker("Mixer","daq","trs");
  chain1->SetInput("Input1","StDAQReader");
  chain2->SetInput("Input2","Event");
  mixer->writeFile("mixer.trs",Nevents);


  // Create chain3 object
  chain3 = new StBFChain("Three");
  saveMk = chain3->cd();
  
  //  options for 2006pp, production=DbV20060915,pp2006b,ITTF,hitfilt
  chain3->SetFlags("Simu NoDefault NoInput onlraw -onlcl  ry2006,tpc_daq,tpcI,svt_daq,SvtD,Physics,Idst,l0,Tree,evout l3onl  fcf emcDY2 fpd trgd ZDCvtx useCDV ITTF tofDat -SvtIT  MuDST -trg  VFPPVnoCTB beamline GeantOut CMuDst dEdxY2 -EventQA");
  // Note, do not freez the DB time stamp or you will not see the latest gains/peds/stat  

  TString tt1=file1;
  TString tt2=file2;
  tt1.ReplaceAll(".daq","");
  tt2.ReplaceAll(".fzd","");
  TString OutputFileName=tt1+"_"+tt2+".root";
  cout <<"BFC: Setting file output to: " <<OutputFileName.Data()<<endl;
  
  chain3->Set_IO_Files(0,OutputFileName.Data());
  chain3->Load();
  chain3->Instantiate();  

  //............. begin of EMC embedding makers................

  //.............. Add BEmc stuff here ....................
  StMcEventMaker* mcEventMaker = new StMcEventMaker();
  StEmcSimulatorMaker *bemcSim   = new StEmcSimulatorMaker();
  StEmcMixerMaker     *bemcMixer = new StEmcMixerMaker();
  chain3->AddAfter("emcRaw",bemcMixer); 
  chain3->AddAfter("emcRaw",bemcSim); 
  chain3->AddAfter("emcRaw",mcEventMaker);
  bemcMixer->SetDebug(0); // set it to 1 for more printouts
 // note, Barrel slow sim is always ON, said Adam 

  //........... Add EEmc Stuff ( Simu, and Mixer) here ..............
  StEEmcFastMaker  *eemcFastSim = new StEEmcFastMaker();
  StEEmcMixerMaker *eemcMixer   = new StEEmcMixerMaker();

  /* position B+E EMC makers in the chain 
     (order is reverse because 'After' is used - looks funny but is right)
  */
  chain3->AddAfter("emcRaw",eemcMixer); 
  chain3->AddAfter("emcRaw",eemcFastSim); 

  
  eemcFastSim->SetEmbeddingMode();
  //  eemcFastSim->SetDebug();
  // eemcMixer->SetDebug();
  
  if(useEndcapSlowSim) { // turn Endcap slow simu On/Off 
    StEEmcSlowMaker *slowSim=new StEEmcSlowMaker();
    chain3->AddAfter("EEmcFastSim",slowSim); 
    slowSim->setEmbeddingMode();
  }

  //............. end of EMC embedding makers................
  
  St_geant_Maker *geantMk = (St_geant_Maker *) chain->GetMaker("geant");
  geantMk->SetActive(kTRUE);
  StMaker *tpcdaqMk = chain3->GetMaker("tpc_raw");
  if(!tpcdaqMk )    {
    cout <<" Error: no tpc daq maker. End. "<<endl;
    return;
  }
  tpcdaqMk->SetMode(1);   // Trs
  tpcdaqMk->SetInput("Event","MixerEvent");

  saveMk->cd(); {
    TDatime t;
    printf ("QAInfo:Run is started at Date/Time%i/%i\n",t.GetDate(),t.GetTime());
  }
  printf ("QAInfo:Run on %s in %s\n",
	  gSystem->HostName(),
	  gSystem->WorkingDirectory());
  printf ("QAInfo: with %s\n", chain->GetCVS());
  
  // Init the chain and all its makers
  
  if (Nevents >= 0) {
    Int_t iInit = chain->Init();
    chain->ls(5); // list the final chain 
  }


  // chain->SetDEBUG();
  treeMk = chain->GetMaker("tree");
  TBenchmark evnt;
  Int_t iMake = 0, i = 1, iBad = 0;


  StIOMaker *inpMk = (StIOMaker *)chain1->GetMaker("inputStream");
  Int_t ncols, eventnumber, mult, skip=0, oldskip = 0, skiptest=0;
  
  cout <<"BFC - Entering Event Loop"<<endl;
 EventLoop: if (i <= Nevents && iMake != kStEOF && iMake != kStFatal) {
   evnt.Reset();
   evnt.Start("QAInfo:");
   chain->Clear();
   
   iMake = chain->Make(i);
   if (treeMk && iMake == kStErr) {treeMk->Make(i); iBad++;}
   StEvtHddr *fEvtHddr = (StEvtHddr*)chain->GetDataSet("EvtHddr");
   StEvtHddr *fEvtHddrDaq = (StEvtHddr*)chain1->GetDataSet("EvtHddr");
   *fEvtHddr = *fEvtHddrDaq;
   // gSystem->Exec("ps ux");
   evnt.Stop("QAInfo:");
   // evnt->Show("QAInfo:");
   printf ("QAInfo: Done with Event [no. %d/run %d/evt. %d/Date.Time%d.%d/sta %d] Real Time = %10.2f seconds Cpu Time =  %10.2f seconds \n", i,chain->GetRunNumber(),chain->GetEventNumber(),chain->GetDate(), chain->GetTime(),
	  iMake,evnt.GetRealTime("QAInfo:"),evnt.GetCpuTime("QAInfo:"));
   
   i++;
   goto EventLoop;
 }

  fflush(stdout);
  printf ("QAInfo:Run completed ");
  gSystem->Exec("date");

}
Exemple #29
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;
  

}
void claverCanvasSaving(TCanvas* c, TString s,TString format="gif") {
  TDatime* date = new TDatime();
  c->SaveAs(Form("%s_%d.%s",s.Data(),date->GetDate(), format.Data()));

  return;
}