Beispiel #1
0
void change_prompt()
{
    TRint* rint = dynamic_cast<TRint*>(gApplication);
    if (!rint) return;

    rint->SetPrompt("genie [%d] ");
}
Beispiel #2
0
int main(int argc, char** argv)
{
   KVBase::InitEnvironment();
   TRint* myapp = new TRint("kaliveda", &argc, argv, NULL, 0);
   myapp->SetPrompt("kaliveda [%d] ");
   myapp->Run();
   return 0;
}
Beispiel #3
0
void load_libs(bool MustClean = true) {
  // All the CINT exception handler does is obfuscate the stack. With this,
  // uncaught exceptions immediately show a useful backtrace under gdb.
  //  G__SetCatchException(0);

  gSystem->SetAclicMode(TSystem::kOpt);

  // This magic incantation prevents ROOT doing slow cleanup work in
  // TList::RecursiveRemove() under ~TH1(). It also tends to lead to shutdown
  // crashes. HistCache now avoids almost all of that histogram destruction, so
  // now we can leave this at the default setting and get both speed and
  // stability.
  std::cout << "gROOT->SetMustClean(" << (MustClean ? "true" : "false") << ");"
            << std::endl;
  gROOT->SetMustClean(MustClean);

  // Colorize error messages. Would be better if we could just pick up the
  // flags novasoft uses, but they don't seem to be in any env var.
  gSystem->SetFlagsDebug(
      TString(gSystem->GetFlagsDebug()) +
      " -fdiagnostics-color=auto -DDONT_USE_FQ_HARDCODED_SYST_PATHS=1");
  gSystem->SetFlagsOpt(
      TString(gSystem->GetFlagsOpt()) +
      " -fdiagnostics-color=auto -UNDEBUG "
      "-DDONT_USE_FQ_HARDCODED_SYST_PATHS=1"); // match gcc's maxopt behaviour
                                               // of retaining assert()

  // Include path
  TString includes = "-I$ROOTSYS/include -I$CAFANA/include";

  const std::vector<std::string> libs = {
      "Minuit2",          "Net",           "StandardRecord", "OscLibFunc",
      "UtilitiesFunc",    "CAFAnaCore",    "CAFAnaVars",     "CAFAnaCuts",
      "CAFAnaExperiment", "CAFAnaSysts",   "CAFAnaDecomp",   "CAFAnaExtrap",
      "CAFAnaPrediction", "CAFAnaAnalysis"};

  // Actually load the libraries
  std::cout << "Loading libraries:" << std::endl;
  for (const std::string &lib : libs)
    load(lib);
  std::cout << std::endl;

  // Magic incantation to get Reflex-based dictionaries converted into the
  // CINT-based information that ROOT needs
  //  Cintex::Enable();

  gSystem->SetIncludePath(includes);

  // Pick up standard NOvA style
  gROOT->Macro("$CAFANA/include/Utilities/rootlogon.C");
  gROOT->ForceStyle();

  TRint *rint = dynamic_cast<TRint *>(gApplication);
  if (rint) {
    rint->SetPrompt("cafe [%d] ");
  }
}
Beispiel #4
0
int main(int argc, char* argv[])
{
  // argc = 1;  // if you need to use command line arguments for your needs
  TRint* theApp = new TRint("Rint", &argc, argv, 0, 0, 1);  // do not show splash screen and print ROOT version
  
  classtree();
  
  // work in command line mode
  theApp->Run();
  delete theApp;
}
int main(int argc, char* argv[]){

	TRint* r = new TRint("theApp",0,0); // Opens up an interactive session of ROOT
	gErrorIgnoreLevel = 1001; // Ignore ROOT info messages	
	
	gStyle->SetOptTitle(0);
	gStyle->SetOptStat(0);
	
 	TCanvas *c1 = new TCanvas ("c1","c1",1100,800);
  	c1->Divide(2,1);
  	c1->cd(1);
  	
	vector<eventsTracker> eventsInfo(argc-1);
	
	for (int j = 0; j < argc-1; j++){	// Loop over each file entered into the command line
    	analyzeDataFile(argv[j+1], eventsInfo[j]);
    	eventsInfo[j].printJetMassHist();
	}

	c1->cd(2);	
	for (int j = 0; j < argc-1; j++){	// Loop over each file entered into the command line
    	eventsInfo[j].printNTracksHist();
	}
	
	/*TLegend* jetMassLegend = new TLegend(0.65,0.75,0.89,0.88);
	jetMassLegend->AddEntry(jetMassHistQCD,"QCD Jet","l");
	jetMassLegend->AddEntry(jetMassHistZp,"Z' Jet","l");
	jetMassLegend->Draw();

	TLegend* nTracksLegend = new TLegend(0.65,0.75,0.89,0.88);
	nTracksLegend->AddEntry(jetMassHistQCD,"QCD Jet","l");
	nTracksLegend->AddEntry(jetMassHistZp,"Z' Jet","l");
	nTracksLegend->Draw();*/
	
	r->Run(); 
	
	return 0;
}
//__________________________________________________________  
int main(int argc, char **argv) {

  if(argc!=6) {
    std::cout << "Invalid arguments..." << endl;
    return 1;
  }

  double timeCutLow = atof(argv[1]);
  double timeCutHigh = atof(argv[2]);

  //Create the add back table
  CreateAddBackTable(atof(argv[3]));
  
  double betaDiffLow = atof(argv[4]);
  double betaDiffHigh = atof(argv[5]);

  // Create interactive interface
  TRint *theApp = new TRint("ROOT example", &argc, argv, NULL, 0);

  //PID cuts:
  TFile *BRcut[3];
  TFile *ZDcut[3];

  //--------------------------------------------------------------------
  //Cuts
  char name[100];  

  for(int i=0;i<3;i++) {
    sprintf(name,"../cut/brcut%i.root",i);
    BRcut[i] = new TFile(name,"READ");
  }
  
  for(int i=0;i<3;i++) {
    sprintf(name,"../cut/zdcut%i.root",i);
    ZDcut[i] = new TFile(name,"READ");
  }
  
  TCutG *brcut[3];
  TCutG *zdcut[3];
  
  for(int i=0;i<3;i++) {
    //sprintf(name,"brcut%i",i);
    BRcut[i]->GetObject("CUTG",brcut[i]);
  }
  
  for(int i=0;i<3;i++) {
    //sprintf(name,"zdcut%i",i);
    ZDcut[i]->GetObject("CUTG",zdcut[i]); 
  }
  
  // Parameters for the MINOS ANALYSIS && Reading of ConfigFileSetup.txt for beta values
  double Test;
  double DALIOffset;
  double TargetLength; // in mm
  int BeamA, BeamZ;
  string ConfigBeam;
  double BeamEnergy;
  double betaLISE_before, betaLISE_middle, betaLISE_after, beta_vertex;
  double z_vertex;

  ifstream ConfigFile;
  ConfigFile.open("./../ConfigFileSetup.txt");
  string Header;
  ConfigFile >> ConfigBeam;
  ConfigFile >> Header >> Test;
  ConfigFile >> Header >> Test;
  ConfigFile >> Header >> Test;
  ConfigFile >> Header >> Test;
  ConfigFile >> Header >> Test;
  ConfigFile >> Header >> DALIOffset;
  ConfigFile >> Header >> TargetLength;
  ConfigFile >> Header >> BeamA;
  ConfigFile >> Header >> BeamZ;
  ConfigFile >> Header >> BeamEnergy;
  ConfigFile >> Header >> betaLISE_before;
  ConfigFile >> Header >> betaLISE_middle;
  ConfigFile >> Header >> betaLISE_after;
  ConfigFile.close();

  cout<<"The beta values are: Before target="<<betaLISE_before<<", Middle of target="<<betaLISE_middle<<", End of target="<<betaLISE_after<<endl;


  Event *Tree = new Event();
  
  Long64_t nentries = Tree->fChain->GetEntriesFast();

  TFile *rootfile = new TFile("outputfile.root","RECREATE");
  rootfile->cd();

  //Define spectra:
  int minBin = 0;
  int maxBin = 6000;
  int binning = 25;
  int numBin = (maxBin-minBin)/binning;

  //Specific variables;
  int daliMult;
  int daliTimeTrueMult;
  int daliFold;
  int daliTimeTrueFold;

  Double_t DopplerAngle;

  int countingFilling = 0;
  //________________________________________________________________________
  //Spectra:

  TH1F *h_beta_diff[3];

  TH2F *h_doppler[40];
  TH2F *h_aoq_z[4];

  for(int i=0;i<3;i++) {
    sprintf(name,"h_beta_diff[%i]",i);
    h_beta_diff[i] = new TH1F(name,name,1000,-0.1,0.1);
  }

  for(int i=0;i<40;i++) {
    sprintf(name,"h_doppler[%i]",i);
    h_doppler[i] = new TH2F(name,name,186,0,186,numBin,minBin,maxBin);
  }

  for(int i=0;i<4;i++) {
    sprintf(name,"h_aoq_z[%i]",i);
    h_aoq_z[i] = new TH2F(name,name,500,-100,100,250,0,120);
    //h_aoq_z[i] = new TH2F(name,name,500,2.0,3.0,250,40,60);
  }  

  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  //Start looping through data;
  
  Long64_t i=0;
  for (Long64_t jentry=0; jentry<nentries;jentry++) {
    //for (Long64_t jentry=0; jentry<1000;jentry++) {
    //Long64_t ientry = Tree->LoadTree(jentry);
    //if (ientry < 0) break;
    Tree->fChain->GetEvent(jentry);   
    // if (Cut(ientry) < 0) continue;
    
    if(jentry%10000 ==0) cout << jentry <<"/"<<nentries<<" Events DONE!"<<endl;
        
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    //Sorting the MINOS data
    // Calculate beta from the z_vertex found with MINOS offline software 
    //            (estimated beam track parallel to the z axis)
    z_vertex = Tree->z_vertex;
    if(z_vertex>=-10 && z_vertex<0) beta_vertex = betaLISE_before;
    else if(z_vertex>=0 && z_vertex<=100) {
	beta_vertex = betaLISE_before - z_vertex*(betaLISE_before-betaLISE_after)/TargetLength;
    }
    else if(z_vertex>100 && z_vertex<=110) beta_vertex = betaLISE_after;
    else beta_vertex = betaLISE_middle;

    z_vertex = (z_vertex - DALIOffset)/10.; //Convert z in the DALI2 referential (in cm)


    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    //Sorting the DALI2 data
    fDaliFold   = 0;//Fold
    fDaliFoldTa = 0;//Fold
    fDaliMultTa = 0;//multiplicity
    for(int j=0;j<NUMBEROFDALICRYSTALS;j++) {
      crystalUsedForAddback[j] = false;
    }
  
    //cout<<"DALINaI: "<<Tree->DALINaI_<<endl;
    
    for(int j=0;j<Tree->DALINaI_;j++){
      fDali[j].id         = Tree->DALINaI_id[j]-1; 
      fDali[j].layer      = Tree->DALINaI_layer[j];
      fDali[j].theta      = fTheta[fDali[j].id];
      fDali[j].x          = fPosX[fDali[j].id];
      fDali[j].y          = fPosY[fDali[j].id];
      fDali[j].z          = fPosZ[fDali[j].id];
      fDali[j].e          = Tree->DALINaI_fEnergy[j];
      fDali[j].t          = Tree->DALINaI_fTimeOffseted[j];
      if(fDali[j].e>0){
        DopplerAngle = CalculateTheta(fDali[j].x,fDali[j].y,fDali[j].z,z_vertex);

        fDali[j].dopp[0] = DopplerCorrect(beta_vertex,DopplerAngle,fDali[j].e);
        fDali[j].dopp[1] = DopplerCorrect(beta_vertex,DopplerAngle,fDali[j].e);
        fDali[j].dopp[2] = DopplerCorrect(beta_vertex,DopplerAngle,fDali[j].e);
        

        if(fDali[j].t>timeCutLow-500&&fDali[j].t<timeCutHigh+500)fDaliFold++;
        
        //   cout<<"DALIFold: "<<fDaliFold<<endl;
        if(fDali[j].t>timeCutLow && fDali[j].t<timeCutHigh){
          fDali[j].ttrue = true;
          fDaliFoldTa++;
        }
        else fDali[j].ttrue = false;
      }
      else {
        fDali[j].dopp[0] = -999.;
        fDali[j].dopp[1] = -999.;
        fDali[j].dopp[2] = -999.;
        fDali[j].dopp[3] = -999.;
        fDali[j].ttrue   = false;
      }

    }
      
    for(int j=Tree->DALINaI_;j<NUMBEROFDALICRYSTALS;j++){
      fDali[j].id         = -1;
      fDali[j].layer      = -1;
      fDali[j].theta      = -1;
      fDali[j].x          = -999;
      fDali[j].y          = -999;
      fDali[j].z          = -999;
      fDali[j].e          = -999;
      fDali[j].t          = -999;
      fDali[j].ttrue      = false;
      fDali[j].dopp[0]    = -999;
      fDali[j].dopp[1]    = -999;
      fDali[j].dopp[2]    = -999;
      fDali[j].dopp[3]    = -999;      
    }

    if(fDali[0].e>0) SortData(fDaliFold,fDali);

    //Going to the add-back:
    float dummyEnergy[NUMBEROFDALICRYSTALS][6] = {{0.}};
    //Making add-back and true multiplicity:
    //The Energy must be sorted already according to the highest detected one.
    //cout<<"Starting addback"<<endl;
    for(int i=0;i<fDaliFold;i++){

      if(crystalUsedForAddback[fDali[i].id] == true || fDali[i].ttrue == false) continue;

      DopplerAngle = CalculateTheta(fDali[i].x,fDali[i].y,fDali[i].z,z_vertex); 

      dummyEnergy[fDaliMultTa][0] = DopplerCorrect(beta_vertex,DopplerAngle,fDali[i].e);
      dummyEnergy[fDaliMultTa][1] = DopplerCorrect(beta_vertex,DopplerAngle,fDali[i].e);
      dummyEnergy[fDaliMultTa][2] = DopplerCorrect(beta_vertex,DopplerAngle,fDali[i].e);
        
      crystalUsedForAddback[fDali[i].id]=true;
      fDali[fDaliMultTa].idwa = fDali[i].id;
        
      for(int j = i+1;j<fDaliFold;j++)  {
        if(crystalUsedForAddback[fDali[j].id]==false && fDali[j].ttrue==true)  {
          for(int k = 0;k<fNumberOfAddbackPartners[fDali[i].id] ;k++) {
            if(fDali[j].id == fAddbackTable[fDali[i].id][k+1])  {
                
              crystalUsedForAddback[fDali[j].id]=true;
                
              DopplerAngle = CalculateTheta(fDali[i].x,fDali[i].y,fDali[i].z,z_vertex);

                dummyEnergy[fDaliMultTa][0] += DopplerCorrect(beta_vertex,DopplerAngle,fDali[j].e);
                dummyEnergy[fDaliMultTa][1] += DopplerCorrect(beta_vertex,DopplerAngle,fDali[j].e);
                dummyEnergy[fDaliMultTa][2] += DopplerCorrect(beta_vertex,DopplerAngle,fDali[j].e);
              
              
            }
          }
        }
      } 
      fDaliMultTa++;
    }
    for(int i = 0;i<fDaliMultTa;i++) {
      fDali[i].doppwa[0] = dummyEnergy[i][0];
      fDali[i].doppwa[1] = dummyEnergy[i][1];
      fDali[i].doppwa[2] = dummyEnergy[i][2];
    }
    for(int i = fDaliMultTa;i<NUMBEROFDALICRYSTALS;i++) {
      fDali[i].doppwa[0] = -999;
      fDali[i].doppwa[1] = -999;
      fDali[i].doppwa[2] = -999;
      fDali[i].idwa      = -999;
    }
          
     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    //Starting with the analysis conditions
    // FIRST setting for Cr66
    bool br67mn = false; // (p,2p) channel
    bool br68fe = false; // (p,3p) channel
    bool br68mn = false; // (p,2pn) channel
    // SECOND setting for Fe72
    //bool br73co = false; // (p,2p) channel
    //bool br74ni = false; // (p,3p) channel
    //bool br74co = false; // (p,2pn) channel
    // THIRD setting for Ni78
    //bool br79cu = false; // (p,2p) channel
    //bool br80zn = false; // (p,3p) channel
    //bool br80cu = false; // (p,2pn) channel

    bool zd2p66cr = false;
    bool zd3p66cr = false;
    bool zd2pn66cr = false;
    //bool zd2p72fe = false;
    //bool zd3p72fe = false;
    //bool zd2pn72fe = false;
    //bool zd2p78ni = false;
    //bool zd3p78ni = false;
    //bool zd2pn78ni = false;

    //BRS
    if(brcut[0]->IsInside(Tree->BigRIPSBeam_aoq[0],Tree->BigRIPSBeam_zet[0])) br67mn = true;
    if(brcut[1]->IsInside(Tree->BigRIPSBeam_aoq[0],Tree->BigRIPSBeam_zet[0])) br68fe = true; 
    if(brcut[2]->IsInside(Tree->BigRIPSBeam_aoq[0],Tree->BigRIPSBeam_zet[0])) br68mn = true; 
 
    //ZDS
    if(zdcut[0]->IsInside(Tree->BigRIPSBeam_aoq[3],Tree->BigRIPSBeam_zet[3])) zd2p66cr = true;
    if(zdcut[1]->IsInside(Tree->BigRIPSBeam_aoq[3],Tree->BigRIPSBeam_zet[3])) zd3p66cr = true; 
    if(zdcut[2]->IsInside(Tree->BigRIPSBeam_aoq[3],Tree->BigRIPSBeam_zet[3])) zd2pn66cr = true; 

    //Beta diff
    float beta_diff = Tree->BigRIPSBeam_beta[0]-Tree->BigRIPSBeam_beta[3];
    if(br67mn&&zd2p66cr) h_beta_diff[0]->Fill(beta_diff);
    if(br68fe&&zd3p66cr) h_beta_diff[1]->Fill(beta_diff);
    if(br68mn&&zd2pn66cr) h_beta_diff[2]->Fill(beta_diff);

    //Trigger register information
    bool DSB = false;
    bool F11 = false;
    bool DaliTrigger = false;

    //Need to check the settings for PSP !!!!!!!!!!!!!!!!!!!!!!!!
    if(Tree->EventInfo_fBit[0]==13||Tree->EventInfo_fBit[0]==15) DaliTrigger = true;
    if(Tree->EventInfo_fBit[0]==10||Tree->EventInfo_fBit[0]==11||Tree->EventInfo_fBit[0]==15) DSB = true;
    if(Tree->EventInfo_fBit[0]==12||Tree->EventInfo_fBit[0]==14) F11 = true;
    
    //Introducing counter value here:
    //br67mn && zd2p66cr:0
    //br68fe && zd3p66cr:1
    //br68mn && zd2pn66cr:2
    
    //Getting the statistics for the cross-section:
    //Beam
    h_aoq_z[0]->Fill(Tree->BigRIPSBeam_aoq[0],Tree->BigRIPSBeam_zet[0]);
    if(DSB)
      h_aoq_z[1]->Fill(Tree->BigRIPSBeam_aoq[0],Tree->BigRIPSBeam_zet[0]);
    
    int counter = -1;

    //Asking for good condition of ppac and beta diff
    /*
    if(br67mn && zd2p66cr && Tree->fgoodppacfocusor[9]==1 && Tree->fgoodppacfocusor[11]==1 && 
       beta_diff>betaDiffLow && beta_diff < betaDiffHigh)
      counter = 0;
    else if(br68fe && zd3p66cr && Tree->fgoodppacfocusor[9]==1 && Tree->fgoodppacfocusor[11]==1 
            && beta_diff>betaDiffLow && beta_diff < betaDiffHigh)
      counter = 1;
    else if(br68mn && zd2pn66cr && Tree->fgoodppacfocusor[9]==1 && Tree->fgoodppacfocusor[11]==1 
            && beta_diff>betaDiffLow && beta_diff < betaDiffHigh)
      counter = 2;
    else continue;
    */

    if(br67mn && zd2p66cr)
      counter = 0;
    else if(br68fe && zd3p66cr)
      counter = 1;
    else if(br68mn && zd2pn66cr)
      counter = 2;
    else continue;

    for(int j=0;j<fDaliFold;j++){
      if(fDali[j].ttrue) {
        h_doppler[0+counter*10]->Fill(fDali[j].id,fDali[j].dopp[counter]);
        if(fDaliFold<3)  h_doppler[1+counter*10]->Fill(fDali[j].id,fDali[j].dopp[counter]);
        if(fDaliFold==1) h_doppler[2+counter*10]->Fill(fDali[j].id,fDali[j].dopp[counter]);
      }
    } 
    for(int j=0;j<fDaliMultTa;j++){
      h_doppler[3+counter*10]->Fill(fDali[j].idwa,fDali[j].doppwa[counter]);
      if(fDaliMultTa==1) h_doppler[4+counter*10]->Fill(fDali[0].idwa,fDali[0].doppwa[counter]);
      if(fDaliMultTa==2) h_doppler[5+counter*10]->Fill(fDali[j].idwa,fDali[j].doppwa[counter]);
      if(fDaliMultTa==3) h_doppler[6+counter*10]->Fill(fDali[j].idwa,fDali[j].doppwa[counter]);
      if(fDaliMultTa>3)  h_doppler[7+counter*10]->Fill(fDali[j].idwa,fDali[j].doppwa[counter]);
      if(fDaliMultTa<=2) {
        h_doppler[8+counter*10]->Fill(fDali[j].idwa,fDali[j].doppwa[counter]);
      }
      if(fDaliMultTa<=3) {
        h_doppler[9+counter*10]->Fill(fDali[j].idwa,fDali[j].doppwa[counter]);
      }
    }
    
    //ZDS
    h_aoq_z[2]->Fill(Tree->BigRIPSBeam_aoq[3],Tree->BigRIPSBeam_zet[3]);
    if(F11 && Tree->fgoodppacfocusor[9]==1 && Tree->fgoodppacfocusor[11]==1)
      h_aoq_z[3]->Fill(Tree->BigRIPSBeam_aoq[3],Tree->BigRIPSBeam_zet[3]);
  }
  
  for(int i=0;i<30;i++)
    h_doppler[i]->Write();
  
  for(int i=0;i<3;i++)
    h_beta_diff[i]->Write();
  
  for(int i=0;i<4;i++) {
    h_aoq_z[i]->Write();
  }  

  theApp->Run();
  return 0;
}
Beispiel #7
0
int main(int argc, char **argv)
{
	printf("Bazinga!\n");
	try {
		/* get data */
		std::cout << "argc = " << argc << endl;
		if (argc == 1) {
			//_mychain->Add("/home/ephelps/analysis/root_37808_pass1.a20.root/h10");
			/* open cint session */
			int argc_root = 0;
			Fid *fid = Fid::Instance();
			fid->Print();
			TRint *app = new TRint("Rint",&argc_root,argv,NULL,0);
			app->Run();
		} else {
			TChain *_mychain = new TChain();
			int dtype = _DATA_H10SIM;
			for (int i = 1; i < argc; i++) {
				_mychain->Add(argv[i]);
				std::cout << i << ": " << argv[i] << std::endl;
			}
			if (_mychain->GetBranch("rf_time2")) dtype = _DATA_H10EXP;
			else if(_mychain->GetBranch("w4")) dtype = _DATA_3PI;
			else dtype = _DATA_H10SIM;
			TFile fout("out.root","recreate");
			h10looper *_mylooper = 0;
			Data *data = 0;
			if (dtype == _DATA_H10EXP) {
				data = new h10exp();
				//TFile fin_el("/data/e1f/exp-el.root");
				TEntryList *elist = 0; //(TEntryList*)fin_el.Get("q2_18_27_pippim");
				h10looper *_mylooper = new h10looper(data, _mychain);
				_mylooper->Add(new DhCalcLuminosity("accuq",&fout));
				_mylooper->Add(new DhSkimCharge<h10exp>("skimq",&fout));
				_mylooper->Add(new DhEid<h10exp>("skime",&fout,"/home/ephelps/analysis/omega/input/eid.exp.out"));
				_mylooper->Add(new DhPcor("pcor",&fout));
				_mylooper->Add(new DhSkimChargedParts<h10exp>("skim1or2pi",&fout));
				_mylooper->Add(new DhTmH10clone<h10exp>(_mylooper,"h10clone",&fout));
				_mylooper->Add(new DhTm3pi<h10exp>("3pi-tree",&fout));
				//_mylooper->Add(new DhFid<h10exp>("fid",&fout,"/home/ephelps/analysis/omega/input/fid.parms"));
				/* process data */
				_mylooper->Loop(-1,kFALSE,elist);
			} else if (dtype == _DATA_H10SIM) {
				data = new h10sim();
				_mylooper = new h10looper(data, _mychain);
				_mylooper->Add(new DhTm3pi<h10sim,true>("3pi-tree-thrown-all",&fout));
				_mylooper->Add(new DhSkimCharge<h10sim>("skimq",&fout));
				_mylooper->Add(new DhEid<h10sim>("skime",&fout,"/home/ephelps/analysis/omega/input/eid.mc.out"));
				_mylooper->Add(new DhSkimChargedParts<h10sim>("skim1or2pi",&fout));
				_mylooper->Add(new DhTmH10clone<h10sim>(_mylooper,"h10clone",&fout));
				_mylooper->Add(new DhTm3pi<h10sim,true>("3pi-tree-thrown",&fout));
				_mylooper->Add(new DhTm3pi<h10sim,false>("3pi-tree-recon",&fout));
				//_mylooper->Add(new DhFid<h10exp>("fid",&fout,"/home/ephelps/analysis/omega/input/fid.parms"));
				/* process data */
				_mylooper->Loop(-1,kFALSE);
			} else if (dtype == _DATA_3PI) {
				data = new Evt();
				_mylooper = new h10looper(data, _mychain);
				//_mylooper->Add(new Dh3piToPhysFrm(_mylooper,"3pi-cm",&fout));
				//_mylooper->Add(new Dh3piHists("3pi-hists",&fout));
				_mylooper->Add(new DhTop1("top1",&fout));
				_mylooper->Loop(-1,kFALSE);
			}
			if (_mychain) delete _mychain;
			if (_mylooper) delete _mylooper;
			if (data) delete data;
			/* clean up */
		}
	} catch(exception *e) {
		std::cout << e->what() << std::endl;
		delete e;
		return 88;
	}
	printf("!agnizaB\n");
	return 0;
}
int main(int argc, char** argv){

  // Set it to "true" if you do not want to see the histograms interactively
  gROOT->SetBatch(IS_BATCH);
  gStyle->SetOptStat(1111111);
  gStyle->SetOptFit(1111);

  // Open the input root file and set branches
  // On pcciet3a, pcciet3b, pccmscie6
  //TString sampleFile = "/data4/Fall11_WplusC_Trees_July2012/TTbar.root";
  // Just for some checks (there are selection cuts applied on the following file)
  //TString sampleFile = "/data4/Fall11_WplusC_Trees_July2012/TTbar_SSVHPNOMTNOISOreduced.root";
  // Stop file
//  TString sampleFile = "/data4/Fall11_WplusC_Trees_July2012/Stop.root";
  TString sampleFile = "dcap://gaeds015.ciemat.es:22125/pnfs/ciemat.es/data/cms/store/user/delacruz/STop2012/NTuplesFeb2013/v1/merge_stops_signalmc_T2tt_Mstop-225to1200_mLSP-0to1000_Pythia_new.root";

  Event ev;
  Event* pointerToEvent = &ev;
  printf("Processing sample '%s'...\n", sampleFile.Data());
  TFile input_sample(sampleFile,"READONLY");
  TTree* tree = 0;
  input_sample.GetObject("MUTREE/MUTREE",tree);
  if (!tree) input_sample.GetObject("MUTREE",tree);
  tree->SetBranchAddress("event", &pointerToEvent);

  int nentriesInTree = tree->GetEntriesFast();
  if (maxEventsUsed<0) maxEventsUsed = nentriesInTree;
  printf("\tThere are %d events in the file; running on %d events\n", nentriesInTree, maxEventsUsed);

  TH1D* hCosb = new TH1D("hCosb", "cos(#theta_{tb})", 50, -1.0, 1.0);

  printf("Input thetaEff for topPol %.3f is: %.3f\n", 1., GetThetaMixing(1., 950., 175., 425.));
  printf("Input thetaEff for topPol %.3f is: %.3f\n", 0.5, GetThetaMixing(0.5, 950., 175., 425.));
  printf("Input thetaEff for topPol %.3f is: %.3f\n", 0., GetThetaMixing(0., 950., 175., 425.));
  printf("Input thetaEff for topPol %.3f is: %.3f\n", -0.5, GetThetaMixing(-0.5, 950., 175., 425.));
  printf("Input thetaEff for topPol %.3f is: %.3f\n", -1., GetThetaMixing(-1., 950., 175., 425.));

  // Event loop
  for (int iEvent=0; iEvent<maxEventsUsed; iEvent++) {
    if (tree->LoadTree(iEvent)<0) break;
    tree->GetEntry(iEvent);

    if (ev.genInfos.size()<=0) {
      printf("This is not a MC file, EXIT!!!\n");
      return -1;
    }

    if (iEvent%1000000==0) printf("... event index %d\n", iEvent);
    
    unsigned int ngen = ev.genParticles.size();

    //double m_stop = 0.;
    //double m_chi0 = 0.;
    //double m_top = 0.;
    std::vector<SUSYGenParticle> genParticles;
    for (unsigned int ig=0; ig<ngen; ++ig) {
      GenParticle gen = ev.genParticles[ig];
      if (gen.status!=3) break;
      SUSYGenParticle part;
      part.pdgId = gen.pdgId;
      part.energy = gen.energy;
      part.pt = gen.pt;
      part.eta = gen.eta;
      part.phi = gen.phi;
      part.firstMother = -1; if (gen.mothers.size()>0) part.firstMother = gen.mothers[0];
      //if (abs(gen.pdgId)==1000006) m_stop = sqrt(pow(gen.energy,2)-pow(gen.pt*cosh(gen.eta),2));
      //if (abs(gen.pdgId)==1000022) m_chi0 = sqrt(pow(gen.energy,2)-pow(gen.pt*cosh(gen.eta),2));
      //if (abs(gen.pdgId)==6) m_top = sqrt(pow(gen.energy,2)-pow(gen.pt*cosh(gen.eta),2));

      genParticles.push_back(part);
    }
    //printf("m_stop: %.3f, m_top: %.3f, m_chi0: %.3f\n", m_stop, m_top, m_chi0);

    //double pol_new = POL;
    //double pol_new = AverageTopPolarization_Stop_to_TopChi0(-1.1, genParticles);
    //double weight = Reweight_Stop_to_TopChi0_TopOnshell (genParticles, 0., pol_new);

    // m_stop=950 GeV, m_chi0=425 GeV, m_top=175 GeV
    double thetaMixingTarget = -1.134; // Pol=-1
    //double thetaMixingTarget = -0.437; // Pol=+1
    double weight = Reweight_Stop_to_TopChi0_with_SUSYmodel (genParticles, thetaMixingTarget);

    for (unsigned int ig=0; ig<ngen; ++ig) {
      GenParticle gen = ev.genParticles[ig];
      if (gen.status!=3) break;
      if (abs(gen.pdgId)!=5) continue;
      if (gen.mothers.size()!=1) continue;
      GenParticle genTop = ev.genParticles[gen.mothers[0]];
      if (abs(genTop.pdgId)!=6) continue;

      if (genTop.pdgId*gen.pdgId<0) continue;

      double etop = genTop.energy;
      double pxtop = genTop.pt*cos(genTop.phi);
      double pytop = genTop.pt*sin(genTop.phi);
      double pztop = genTop.pt*sinh(genTop.eta);
      double ptop  = sqrt(pxtop*pxtop+pytop*pytop+pztop*pztop);
      double mtop  = sqrt(etop*etop-ptop*ptop);
      double pxb   = gen.pt*cos(gen.phi);
      double pyb   = gen.pt*sin(gen.phi);
      double pzb   = gen.pt*sinh(gen.eta);
      double pb    = sqrt(pxb*pxb+pyb*pyb+pzb*pzb);

      // We also need a stop
      if (genTop.mothers.size()==0) continue;
      GenParticle genStop = ev.genParticles[genTop.mothers[0]];
      if (abs(genStop.pdgId)!=1000006) continue;

      // Move top and fermion to the stop center-of-mass frame
      TLorentzVector stop4;
      stop4.SetPtEtaPhiE(genStop.pt, genStop.eta, genStop.phi, genStop.energy);
      TVector3 betaS(-stop4.Px()/stop4.Energy(),-stop4.Py()/stop4.Energy(),-stop4.Pz()/stop4.Energy());
      TLorentzVector topRef(pxtop,pytop,pztop,etop);
      topRef.Boost(betaS); // keept this vector to calculate costh
      TLorentzVector top4(pxtop,pytop,pztop,etop);
      top4.Boost(betaS);
      TLorentzVector b4(pxb,pyb,pzb,pb);
      b4.Boost(betaS);

      TVector3 betaV(-top4.Px()/top4.Energy(),-top4.Py()/top4.Energy(),-top4.Pz()/top4.Energy());
      top4.Boost(betaV);
      b4.Boost(betaV);

      double costh = (topRef.Px()*b4.Px()+topRef.Py()*b4.Py()+topRef.Pz()*b4.Pz())/topRef.P()/b4.P();

      hCosb->Fill(costh,weight);

    }

  }

  // To see things interactively (if IS_BATCH == false);
  TRint* app = new TRint("Wprime Analysis", &argc, argv);

  hCosb->SetMinimum(0.);
  hCosb->Draw();

  // Fitting slope
  TF1* f1 = new TF1("f1","[0]*(1+[1]*x)");
  f1->SetParName(0,"ValueAt0");
  f1->SetParName(1,"Slope");
  hCosb->Fit(f1,"","same");

  gROOT->GetListOfCanvases()->At(0)->SaveAs("costhb.jpg");

  app->Run();

  return 0;
}
int main(int argc, char* argv[]){
  using namespace muon_pog;


  if (argc < 3) 
    {
      std::cout << "Usage : "
		<< argv[0] << " PATH_TO_INPUT_FILE PAT_TO_CONFIG_FILE(s)\n";
      exit(100);
    }

  // Input root file
  TString fileName = argv[1];

  std::cout << "[" << argv[0] << "] Processing file " << fileName.Data() << std::endl;
  
  std::vector<Plotter> plotters;
  for (int iConfig = 2; iConfig < argc; ++iConfig)
    {
        std::cout << "[" << argv[0] << "] Using config file " << argv[iConfig] << std::endl;
	plotters.push_back(std::string(argv[iConfig]));
    }
  
  // Set it to kTRUE if you do not run interactively
  gROOT->SetBatch(kTRUE); 

  // Initialize Root application
  TRint* app = new TRint("CMS Root Application", &argc, argv);

  //setTDRStyle(); what to do here?
   
  // Initialize pointers to summary and full event structure
 
  muon_pog::Event* ev = new muon_pog::Event();
  TTree* tree;
  TBranch* evBranch;

  // Open file, get tree, set branches

  TFile* inputFile = TFile::Open(fileName,"READONLY");
  tree = (TTree*)inputFile->Get("MUONPOGTREE");
  if (!tree) inputFile->GetObject("MuonPogTree/MUONPOGTREE",tree);

  evBranch = tree->GetBranch("event");
  evBranch->SetAddress(&ev);

  system("mkdir -p results");
  
  TFile* outputFile = TFile::Open("results/results.root","RECREATE"); // CB find a better name for output file  

  for (auto & plotter : plotters)
    plotter.book(outputFile);
      
  // Watch number of entries
  int nEntries = tree->GetEntriesFast();
  std::cout << "[" << argv[0] << "] Number of entries = " << nEntries << std::endl;

  int nFilteredEvents = 0;
  
  for (Long64_t iEvent=0; iEvent<nEntries; ++iEvent) 
    {
      if (tree->LoadTree(iEvent)<0) break;

      evBranch->GetEntry(iEvent);

      for (auto & plotter : plotters)
	plotter.fill(ev->muons, ev->hlt);

    }

  outputFile->Write();
  
  if (!gROOT->IsBatch()) app->Run();

  return 0;
}
int main(int argc, char** argv){

  // Set it to kTRUE if you do not run interactively
  gROOT->SetBatch(kFALSE); 

  // Initialize Root application
  TRint* app = new TRint("CMS Root Application", &argc, argv);

  // Canvas
  TCanvas* c1 = new TCanvas("c1","Top2012 analysis");
  gStyle->SetOptStat(1111111);
  gStyle->SetMarkerStyle(20);
  gStyle->SetMarkerSize(1.0);

  // Input root file
  TString sample = "Data.root";
  
  // Declare histograms
  TH1D* hbtag = new TH1D("hbtag", "CSV discriminant, most significant jet", 25, 0., 1.);
  hbtag->Sumw2();
  
  // Initialize pointers to summary and full event structure
  Summary summary;
  Summary* pointerToSummary = &summary;
  Event ev;
  Event* pointerToEvent = &ev;
  TTree* tree;
  TBranch* bSummary;
  TBranch* bEvent;

  // Open file, get tree, set branches
  printf("Processing sample '%s' ...\n", sample.Data());
  TFile* pinput_sample = TFile::Open(sample,"READONLY");
  TFile& input_sample = *pinput_sample;
  tree = (TTree*)input_sample.Get("MUTREE");
  if (!tree) input_sample.GetObject("MuTree/MUTREE",tree);
  bSummary = tree->GetBranch("summary");
  bEvent = tree->GetBranch("event");
  bSummary->SetAddress(&pointerToSummary);
  bEvent->SetAddress(&pointerToEvent);

  // Watch number of entries
  int nentries = tree->GetEntriesFast();
  printf("Number of entries = %d\n", nentries);

  // Typical way to normalize the MC to data
  double lumi = 20000.; // 1/pb
  double xsection = 200.; // pb
  double skimFilterEfficiency = 1.; // different from 1 if MC was already skimmed
  double weight = lumi*xsection*skimFilterEfficiency / nentries;

  for (Long64_t iEvent=0; iEvent<nentries; iEvent++) {
      if (tree->LoadTree(iEvent)<0) break;

      // First, access the summary
      bSummary->GetEntry(iEvent);

      // Cut on summary information to save processing time
      if (summary.nMuons==0) continue; // look for events with at least 1 muon
      if (summary.maxMT<30.) continue; // look for events with maxMT>30
      if (summary.nJets<2) continue; // look for events with at least 2 jets

      // Now get the full event, once we know that summary conditions are satisfied
      bEvent->GetEntry(iEvent);

      // Get the most significant b jet
      unsigned int njets = ev.jets.size();
      double btag = 0.;
      for (unsigned int ij=0; ij<njets; ++ij) {
            Jet jet = ev.jets[ij];
            if (jet.btagCSV>btag) {
                  btag = jet.btagCSV;
            }
      }
      
      // Fill histogram
      hbtag->Fill(btag, weight);
  }

  hbtag->Draw("e");

  c1->SaveAs("btag.jpg");

  if (!gROOT->IsBatch()) app->Run();

  return 0;
}
int main(int argc, char* argv[]){

  float xSec      = 1;
  float filterEff = 1;

  if (argc < 2) 
    {
      std::cout << "Usage : " << argv[0] << " PATH_TO_FILE <X_SEC> <FILTER_EFF>\n";
      exit(100);
    }

  if (argc >= 3) 
    {
      xSec = std::atof(argv[2]);
      if (fabs(xSec) < 1E-20)
	{
	  std::cout << "atof(<X_SEC>) : " << xSec << " is too small\n";
	  exit(100);
	}
    }

  if (argc >= 4) 
    {
      filterEff = std::atof(argv[3]);
      if (fabs(filterEff) < 1E-20)
	{
	  std::cout << "atof(<FILTER_EFF>) : " << filterEff << " is too small\n";
	  exit(100);
	}
    }
  
  // Input root file
  TString fileName = argv[1];

  int tagBegin = fileName.Index("MuonHltTree")+12;
  int tagEnd   = fileName.Index(".root");
  TString fileTag  = fileName(tagBegin,std::max(0,tagEnd-tagBegin));

  // Set it to kTRUE if you do not run interactively
  gROOT->SetBatch(kTRUE); 

  // Initialize Root application
  TRint* app = new TRint("CMS Root Application", &argc, argv);

  setTDRStyle();
  
  std::vector<RatePlotter> plotters;

  plotters.push_back(RatePlotter(0.,5.,"genReferencePt0",true));
  plotters.push_back(RatePlotter(1.,3.,"genReferencePt11",false));

  plotters.push_back(RatePlotter(16,2.4,"hltL1sMu16",false));
  plotters.push_back(RatePlotter(16,2.4,"hltL2fL1sMu16L1f0L2Filtered16Q",false));
  plotters.push_back(RatePlotter(24,2.4,"hltL3fL1sMu16L1f0L2f16QL3Filtered24Q",false));
  plotters.push_back(RatePlotter(40,2.4,"hltL3fL1sMu16L1f0L2f16QL3Filtered40Q",false));
  plotters.push_back(RatePlotter(24,2.4,"hltL3crIsoL1sMu16L1f0L2f16QL3f24QL3crIsoRhoFiltered0p15",false));
	   
  plotters.push_back(RatePlotter(16,2.1,"hltL1sMu16",false));
  plotters.push_back(RatePlotter(16,2.1,"hltL2fL1sMu16L1f0L2Filtered16Q",false));
  plotters.push_back(RatePlotter(24,2.1,"hltL3fL1sMu16L1f0L2f16QL3Filtered24Q",false));
  plotters.push_back(RatePlotter(40,2.1,"hltL3fL1sMu16L1f0L2f16QL3Filtered40Q",false));
  plotters.push_back(RatePlotter(24,2.1,"hltL3crIsoL1sMu16L1f0L2f16QL3f24QL3crIsoRhoFiltered0p15",false));

  // Initialize pointers to summary and full event structure
 
  ciemat::Event* ev = new ciemat::Event();
  TTree* tree;
  TBranch* evBranch;

  // Open file, get tree, set branches

  std::cout << "[" << argv[0] << "] Processing file " << fileName.Data() << std::endl;

  TFile* inputFile = TFile::Open(fileName,"READONLY");
  tree = (TTree*)inputFile->Get("MUHLTTREE");
  if (!tree) inputFile->GetObject("MuonHltTree/MUHLTTREE",tree);

  evBranch = tree->GetBranch("event");
  evBranch->SetAddress(&ev);

  system("mkdir -p results");
  
  TString outputFileName("results/rateResults_"+fileTag+".root");  
  TFile* outputFile = TFile::Open(outputFileName,"RECREATE");  

  std::vector<RatePlotter>::iterator plotterIt  = plotters.begin();
  std::vector<RatePlotter>::iterator plotterEnd = plotters.end();
  
  for(; plotterIt!=plotterEnd; ++ plotterIt)
    {
      plotterIt->book(outputFile);
    }

  // Watch number of entries
  int nEntries = tree->GetEntriesFast();
  std::cout << "[" << argv[0] << "] Number of entries = " << nEntries << std::endl;

  for (Long64_t iEvent=0; iEvent<nEntries; ++iEvent) 
    {
      if (tree->LoadTree(iEvent)<0) break;

      evBranch->GetEntry(iEvent);

      plotterIt  = plotters.begin();
      plotterEnd = plotters.end();

      for(; plotterIt!=plotterEnd; ++ plotterIt)
      	{
      	  plotterIt->fill(ev);
      	}
      
    }

  float scaleFactor = 1./nEntries * xSec * filterEff;

  plotterIt  = plotters.begin();
  plotterEnd = plotters.end();
  
  for(; plotterIt!=plotterEnd; ++ plotterIt)
    {
      plotterIt->plotAndSave(scaleFactor);
    }
  
  outputFile->Write();

  if (!gROOT->IsBatch()) app->Run();

  return 0;
}
int main(int argc, char** argv){

  TString chfile;
  TString chfileref;
  TString DirectoryLast;
  TString labelData;
  TString labelRef;


  int ntrueargs = 0;
  bool logyFlag = true;
  bool normalize = false;

  for (int i=1; i<argc; ++i) {
      if (argv[i][0] == '-') {
            if (argv[i][1]=='l') logyFlag = false;
            else if (argv[i][1]=='b') gROOT->SetBatch();
            else if (argv[i][1]=='h') return printUsage();
            else if (argv[i][1]=='n') normalize=true;
            else if (argv[i][1]=='D') labelData = argv[i+1];
            else if (argv[i][1]=='R') labelRef= argv[i+1];

      } else {
            ntrueargs += 1;
            if (ntrueargs==1) chfile = argv[i];
            else if (ntrueargs==2) chfileref = argv[i];
            else if (ntrueargs==3) DirectoryLast = argv[i];
      }
  }

  if (ntrueargs<3) return printUsage();

  TRint* app = new TRint("CMS Root Application", 0, 0);

  TString cmssw_version = gSystem->Getenv("CMSSW_VERSION");
  TString chsample = "EWKMu";
  TString chtitle = chsample + " validation for " + cmssw_version;




  //TCanvas* c1 = new TCanvas("c1",chtitle.Data());
  TCanvas* c1 = new TCanvas("c1",chtitle.Data(),0,0,1024,768);
  c1->SetFillColor(0);
  TPaveLabel* paveTitle = new TPaveLabel(0.1,0.93,0.9,0.99, chtitle.Data());
  paveTitle->Draw();
  paveTitle->SetFillColor(0);
  gStyle->SetOptLogy(logyFlag);
  gStyle->SetPadGridX(true);
  gStyle->SetPadGridY(true);
  gStyle->SetOptStat(0);
//  gStyle->SetFillColor(0);

  TPad* pad[4];
  pad[0] = new TPad("pad_tl","The top-left pad",0.01,0.48,0.49,0.92);
  pad[0]->SetFillColor(0); 
  pad[1] = new TPad("pad_tr","The top-right pad",0.51,0.48,0.99,0.92); 
  pad[1]->SetFillColor(0);
  pad[2] = new TPad("pad_bl","The bottom-left pad",0.01,0.01,0.49,0.46); 
  pad[2]->SetFillColor(0);
  pad[3] = new TPad("pad_br","The bottom-right pad",0.51,0.01,0.99,0.46); 
  pad[3]->SetFillColor(0);

  for (unsigned int i=0; i<4; ++i) pad[i]->Draw();
                                                                                
  TLegend* leg = new TLegend(0.6041667,0.7487715,0.9861111,0.9576167);
  leg->SetFillColor(0);
  TFile* input_file = new TFile(chfile.Data(),"READONLY");
  TFile* input_fileref = new TFile(chfileref.Data(),"READONLY");
  bool first_plots_done = false;

  TString directory = DirectoryLast + "/BeforeCuts";

  TDirectory* dir_before = input_file->GetDirectory(directory);
  TDirectory* dirref_before = input_fileref->GetDirectory(directory);
  TList* list_before = dir_before->GetListOfKeys();
  list_before->Print();

  unsigned int list_before_size = list_before->GetSize();
  TString auxTitle = chtitle + ": BEFORE CUTS";
  for (unsigned int i=0; i<list_before_size; i+=4) {
      if (first_plots_done==true) c1->DrawClone();
      paveTitle->SetLabel(auxTitle.Data());
      for (unsigned int j=0; j<4; ++j) {
            pad[j]->cd(); 
            pad[j]->Clear(); 
            if ((i+j)>=list_before_size) continue;

            TH1D* h1 = (TH1D*)dir_before->Get(list_before->At(i+j)->GetName()); 
//            h1->SetLineColor(kBlue);
//            h1->SetMarkerColor(kBlue);
            h1->SetMarkerStyle(21);
            h1->SetLineStyle(1);
            h1->SetLineWidth(3);
            h1->SetTitleSize(0.05,"X");
            h1->SetTitleSize(0.05,"Y");
            TString title=(TString)dir_before->Get(list_before->At(i+j)->GetName())->GetTitle();
            TString name=(TString)dir_before->Get(list_before->At(i+j)->GetName())->GetName(); 
            TString nameD =name+"_MC";
            h1->SetXTitle(title);
            h1->SetName(nameD);

            h1->SetYTitle("");
            h1->SetTitle(""); 
            h1->SetTitleOffset(0.85,"X");

            TH1D* hr = (TH1D*)dirref_before->Get(list_before->At(i+j)->GetName()); 
            hr->SetLineColor(kPink-4);
//            hr->SetLineStyle(2);
            hr->SetLineWidth(3);
            hr->SetTitleSize(0.05,"X");
            hr->SetTitleSize(0.05,"Y");
            hr->SetFillColor(kPink-4);
            hr->SetFillStyle(3001);
            hr->SetXTitle(title);
            TString nameMC =name+"_Data";
            h1->SetName(nameMC);

            hr->SetYTitle("");
            hr->SetTitle("");
            hr->SetTitleOffset(0.85,"X");



            if(normalize) {hr->DrawNormalized("hist",h1->Integral());}
            else{hr->Draw("hist");}
            h1->Draw("sames,p,E");
            
            int max1=h1->GetMaximum();
            int maxr=hr->GetMaximum();
            if(!normalize){
            if(max1 >= maxr) { hr->SetMaximum(max1*1.2); h1->SetMaximum(max1*1.2);}
            else {hr->SetMaximum(maxr*1.2); h1->SetMaximum(maxr*1.2);}
            }
            else if (normalize){
            hr->GetYaxis()->SetRangeUser(h1->GetMinimum()*0.1,max1*1.2);
            }


            leg->Clear();
            leg->AddEntry(h1,labelData.Data(),"Lp");
            leg->AddEntry(hr,labelRef.Data() ,"f");

            leg->Draw();




      }
      first_plots_done = true;
      c1->Modified();
      c1->Update();
      char chplot[80];
      sprintf(chplot,"%sValidation_%s_BEFORECUTS_%d.root",chsample.Data(),cmssw_version.Data(),i/4);
      c1->SaveAs(chplot);
      sprintf(chplot,"%sValidation_%s_BEFORECUTS_%d.gif",chsample.Data(),cmssw_version.Data(),i/4);
      c1->SaveAs(chplot);
  }

  TString directory2 = DirectoryLast + "/LastCut";

  TDirectory* dir_lastcut = input_file->GetDirectory(directory2);
  TDirectory* dirref_lastcut = input_fileref->GetDirectory(directory2);
  TList* list_lastcut = dir_lastcut->GetListOfKeys();
  list_lastcut->Print();

  unsigned int list_lastcut_size = list_lastcut->GetSize();
  auxTitle = chtitle + ": AFTER N-1 CUTS";
  for (unsigned int i=0; i<list_lastcut_size; i+=4) {
      if (first_plots_done==true) c1->DrawClone();
      paveTitle->SetLabel(auxTitle.Data());
      for (unsigned int j=0; j<4; ++j) {
            pad[j]->cd(); 
            pad[j]->Clear(); 
            if ((i+j)>=list_lastcut_size) continue;

            TH1D* h1 = (TH1D*)dir_lastcut->Get(list_lastcut->At(i+j)->GetName()); 
//            h1->SetLineColor(kBlue);
//            h1->SetMarkerColor(kBlue);
            h1->SetMarkerStyle(21);
            h1->SetLineWidth(3);
            h1->SetTitleSize(0.05,"X");
            h1->SetTitleSize(0.05,"Y");
            TString name=(TString)dir_lastcut->Get(list_lastcut->At(i+j)->GetName())->GetName();
            TString title=(TString)dir_lastcut->Get(list_lastcut->At(i+j)->GetName())->GetTitle();
            TString nameD=name+"_Data";
            h1->SetXTitle(title); 
            h1->SetName(nameD);
            h1->SetYTitle("");
            h1->SetTitle(""); 
            h1->SetTitleOffset(0.85,"X");

            TH1D* hr = (TH1D*)dirref_lastcut->Get(list_lastcut->At(i+j)->GetName()); 
            hr->SetLineColor(kAzure+5);
//            hr->SetLineStyle(2);
            hr->SetLineWidth(3);
            hr->SetTitleSize(0.05,"X");
            hr->SetTitleSize(0.05,"Y");
            hr->SetFillColor(kAzure+5);
            hr->SetFillStyle(3001);
            hr->SetXTitle(title);
            TString nameMC=name+"_Data";
            h1->SetName(nameMC);
            hr->SetYTitle("");
            hr->SetTitle("");
            hr->SetTitleOffset(0.85,"X");


            if(normalize) {hr->DrawNormalized("hist",h1->Integral());}
            else{hr->Draw("hist");}
            h1->Draw("sames,p,E");

            int max1=h1->GetMaximum();
            int maxr=hr->GetMaximum();
            if(!normalize){
            if(max1 >= maxr) { hr->SetMaximum(max1*1.2); h1->SetMaximum(max1*1.2);}
            else {hr->SetMaximum(maxr*1.2); h1->SetMaximum(maxr*1.2);}
            }
            else if (normalize){
            hr->GetYaxis()->SetRangeUser(h1->GetMinimum()*0.1,max1*1.2);
            }
            

            leg->Clear();
            leg->AddEntry(h1,labelData.Data(),"lp");
            leg->AddEntry(hr,labelRef.Data(),"f");
            leg->Draw();
      }
      first_plots_done = true;
      c1->Modified();
      c1->Update();
      char chplot[80];
      sprintf(chplot,"%sValidation_%s_LASTCUT_%d.root",chsample.Data(),cmssw_version.Data(),i/4);
      c1->SaveAs(chplot);
      sprintf(chplot,"%sValidation_%s_LASTCUT_%d.gif",chsample.Data(),cmssw_version.Data(),i/4);
      c1->SaveAs(chplot);
  }

  if (!gROOT->IsBatch()) app->Run();

  return 0;
}