int spikes_getContamFromMerged(int nEntries=-1,
			       TString dirOut="/home/llr/cms/ndaci/SKWork/macro/skEfficiency/Spikes/HighPuContamination/try2/",
			       TString dirIn="/data_CMS/cms/ndaci/ndaci_2011A/Commissioning/CommissioningEmulReco/NewKill/highPU/MergedToData/",
			       TString file="all_spikes.root",
			       TString usr_hlt="noHLT",
			       TString nameChain="Spikes", 
			       float spikeCut=8.,
			       bool debug=false)
{

  ofstream outlog(dirOut+"/log_getContam.txt",ios::out);

  // INPUT TREE //                                                                                                                   
  if(debug) cout << "--- add data trees to myChain" << endl;
  TChain * myChain = new TChain(nameChain);
  myChain->Add(dirIn+file);

  // VARIABLES //                                                                                      
  int nEvent, nRun, nLumi ; // data                                                      
  //int nEvent_To, nRun_To, nLumi_To; // trigOnly
  // Vertices //
  int vtx_N;
  double _vtx_x[200], _vtx_y[200], _vtx_z[200];
  double _vtx_normalizedChi2[200], _vtx_ndof[200], _vtx_nTracks[200], _vtx_d0[200];

  // Trigger Paths //                                                                           
  int trig_hltInfo[250];
  //int _trig_isEleHLTpath;                                                                                    
  int trig_HLT_path[4]; // unbias, EG5, EG8, EG12
  char trig_fired_names[5000];
  vector<string> m_HLT_pathsV;
  vector<string> m_HLT_triggered;
  vector<int> m_HLT_pathsV_check;

  // Spikes
  int spike_N,spike_TTieta[5000], spike_TTiphi[5000], spike_Rieta[5000], spike_Riphi[5000], spike_severityLevel[5000], 
    spike_outOfTime[5000];
  double  spike_Et[5000], spike_eta[5000], spike_phi[5000], spike_theta[5000];
  int spike_RCTL1iso[5000], spike_RCTL1noniso[5000], spike_RCTL1iso_To[5000], spike_RCTL1noniso_To[5000], 
    spike_RCTL1iso_M_To[5000], spike_RCTL1noniso_M_To[5000],
    spike_maxEGtrig[5000], spike_maxEGtrig_To[5000], spike_maxEGtrig_M_To[5000];
  
  // TP info
  const int nTow = 4032;
  int trig_tower_N,trig_tower_ieta[nTow],trig_tower_iphi[nTow],trig_tower_adc[nTow],trig_tower_sFGVB[nTow],trig_tower_FG[nTow];
  int trig_tower_N_M,trig_tower_ieta_M[nTow],trig_tower_iphi_M[nTow],trig_tower_adc_M[nTow],trig_tower_sFGVB_M[nTow],
    trig_tower_FG_M[nTow];
  int trig_tower_N_E,trig_tower_ieta_E[nTow],trig_tower_iphi_E[nTow],trig_tower_adc_E[nTow][5],trig_tower_sFGVB_E[nTow][5],
    trig_tower_FG_E[nTow][5];

  // HCAL TP //
  int trig_tower_hcal_N, trig_tower_hcal_ieta[4032], trig_tower_hcal_iphi[4032], trig_tower_hcal_FG[4032],trig_tower_hcal_et[4032];

  // L1 Candidates //                                                                                                             
  int trig_L1emIso_N, trig_L1emNonIso_N; 
  int trig_L1emIso_N_To, trig_L1emNonIso_N_To, trig_L1emIso_N_M_To, trig_L1emNonIso_N_M_To;

  // L1 candidates info //
  int trig_L1emIso_ieta[4], trig_L1emIso_iphi[4], trig_L1emIso_rank[4];
  int trig_L1emNonIso_ieta[4], trig_L1emNonIso_iphi[4], trig_L1emNonIso_rank[4];

  int trig_L1emIso_ieta_To[4], trig_L1emIso_iphi_To[4], trig_L1emIso_rank_To[4];
  int trig_L1emNonIso_ieta_To[4], trig_L1emNonIso_iphi_To[4], trig_L1emNonIso_rank_To[4];
  int trig_L1emIso_ieta_M_To[4], trig_L1emIso_iphi_M_To[4], trig_L1emIso_rank_M_To[4];
  int trig_L1emNonIso_ieta_M_To[4], trig_L1emNonIso_iphi_M_To[4], trig_L1emNonIso_rank_M_To[4];

  // INITIALIZATION //                                                                                                               
  //                                                                                                                                 
  // Global                                                                                                                        
  nEvent = 0;
  nRun = 0;
  nLumi = 0;
  //                                                                                                                          
  // Vertices                                                                                                                   
  vtx_N = 0;
  for(int iv=0;iv<200;iv++) {
    _vtx_normalizedChi2[iv] = 0.;
    _vtx_ndof[iv] = 0.;
    _vtx_nTracks[iv] = 0.;
    _vtx_d0[iv] = 0.;
    _vtx_x[iv] = 0.;
    _vtx_y[iv] = 0.;
    _vtx_z[iv] = 0.;
  }
  //                                                                                                                        
  // L1 candidates                                                                                              
  trig_L1emIso_N    = 0;
  trig_L1emNonIso_N = 0;
  trig_L1emIso_N_M_To  = 0;
  trig_L1emNonIso_N_M_To = 0;

  for(int il1=0 ; il1<4 ; il1++) {
    trig_L1emIso_ieta[il1] = 0;
    trig_L1emIso_iphi[il1] = 0;
    trig_L1emIso_rank[il1] = 0;
    trig_L1emNonIso_ieta[il1] = 0;
    trig_L1emNonIso_iphi[il1] = 0;
    trig_L1emNonIso_rank[il1] = 0;

    trig_L1emIso_ieta_To[il1] = 0;
    trig_L1emIso_iphi_To[il1] = 0;
    trig_L1emIso_rank_To[il1] = 0;
    trig_L1emNonIso_ieta_To[il1] = 0;
    trig_L1emNonIso_iphi_To[il1] = 0;
    trig_L1emNonIso_rank_To[il1] = 0;

    trig_L1emIso_ieta_M_To[il1] = 0;
    trig_L1emIso_iphi_M_To[il1] = 0;
    trig_L1emIso_rank_M_To[il1] = 0;
    trig_L1emNonIso_ieta_M_To[il1] = 0;
    trig_L1emNonIso_iphi_M_To[il1] = 0;
    trig_L1emNonIso_rank_M_To[il1] = 0;
  }

  // Trigger towers              
  trig_tower_N = 0;
  for(int iTow=0 ; iTow<nTow ; iTow++) {
    trig_tower_ieta[iTow] = trig_tower_iphi[iTow]  = -999;
    trig_tower_adc[iTow]  = trig_tower_sFGVB[iTow] = trig_tower_FG[iTow] = -999;
  }
  trig_tower_N_M = 0;
  for(int iTow=0 ; iTow<nTow ; iTow++) {
    trig_tower_ieta_M[iTow] = trig_tower_iphi_M[iTow]  = -999;
    trig_tower_adc_M[iTow]  = trig_tower_sFGVB_M[iTow] = trig_tower_FG_M[iTow] = -999;
  }
  trig_tower_N_E = 0;
  for(int iTow=0 ; iTow<nTow ; iTow++) {
    trig_tower_ieta_E[iTow] = trig_tower_iphi_E[iTow] = -999;
    for(int i=0 ; i<5 ; i++)
      trig_tower_adc_E[iTow][i] = trig_tower_sFGVB_E[iTow][i] = trig_tower_FG_E[iTow][i] = -999;
  }
  trig_tower_hcal_N = 0;
  for(int iTow=0 ; iTow<nTow ; iTow++) {
    trig_tower_hcal_ieta[iTow] = trig_tower_hcal_iphi[iTow]  = -999;
    trig_tower_hcal_FG[iTow]  = trig_tower_hcal_et[iTow] = -999;
  }

  // SPIKES //
  spike_N = 0;  
  for(int isp=0 ; isp<5000 ; isp++) {
    spike_outOfTime[isp] = -999;
    spike_severityLevel[isp] = -999 ;
    //spike_SwissCross[isp] = -999 ;
    spike_Et[isp] = -999 ;
    spike_phi[isp] = -999 ;
    spike_eta[isp] = -999 ;
    spike_theta[isp] = -999 ;
    spike_TTiphi[isp] = -999 ;
    spike_TTieta[isp] = -999 ;
    spike_Riphi[isp] = -999 ;
    spike_Rieta[isp] = -999 ;
    //
    spike_RCTL1iso[isp] = -999 ;
    spike_RCTL1noniso[isp] = -999 ;
    spike_RCTL1iso_To[isp] = -999 ;
    spike_RCTL1noniso_To[isp] = -999 ;
    spike_RCTL1iso_M_To[isp] = -999 ;
    spike_RCTL1noniso_M_To[isp] = -999 ;
    //spike_time[isp] = -999 ;
  }


  myChain->SetBranchAddress("nEvent",&nEvent);
  myChain->SetBranchAddress("nRun",&nRun);
  myChain->SetBranchAddress("nLumi",&nLumi);

  myChain->SetBranchAddress("vtx_N",&vtx_N);

  myChain->SetBranchAddress("trig_HLT_path",&trig_HLT_path);
  myChain->SetBranchAddress("trig_fired_names",&trig_fired_names);
  myChain->SetBranchAddress("trig_hltInfo",&trig_hltInfo);

  // L1 candidates                             
  myChain->SetBranchAddress("trig_L1emIso_N", &trig_L1emIso_N);
  myChain->SetBranchAddress("trig_L1emIso_ieta", &trig_L1emIso_ieta);
  myChain->SetBranchAddress("trig_L1emIso_iphi", &trig_L1emIso_iphi);
  myChain->SetBranchAddress("trig_L1emIso_rank", &trig_L1emIso_rank);

  myChain->SetBranchAddress("trig_L1emNonIso_N", &trig_L1emNonIso_N);
  myChain->SetBranchAddress("trig_L1emNonIso_ieta", &trig_L1emNonIso_ieta);
  myChain->SetBranchAddress("trig_L1emNonIso_iphi", &trig_L1emNonIso_iphi);
  myChain->SetBranchAddress("trig_L1emNonIso_rank", &trig_L1emNonIso_rank);

  // Spikes
  myChain->SetBranchAddress("spike_N",&spike_N);
  myChain->SetBranchAddress("spike_TTieta",&spike_TTieta);
  myChain->SetBranchAddress("spike_TTiphi",&spike_TTiphi);
  myChain->SetBranchAddress("spike_Rieta",&spike_Rieta);
  myChain->SetBranchAddress("spike_Riphi",&spike_Riphi);
  myChain->SetBranchAddress("spike_severityLevel",&spike_severityLevel);
  myChain->SetBranchAddress("spike_outOfTime",&spike_outOfTime);
  myChain->SetBranchAddress("spike_Et",&spike_Et);
  myChain->SetBranchAddress("spike_eta",&spike_eta);
  myChain->SetBranchAddress("spike_phi",&spike_phi);
  myChain->SetBranchAddress("spike_theta",&spike_theta);
//
  myChain->SetBranchAddress("spike_maxEGtrig",&spike_maxEGtrig);
  myChain->SetBranchAddress("spike_maxEGtrig_To",&spike_maxEGtrig_To);
  myChain->SetBranchAddress("spike_maxEGtrig_M_To",&spike_maxEGtrig_M_To);

  myChain->SetBranchAddress("trig_tower_N", &trig_tower_N);
  myChain->SetBranchAddress("trig_tower_ieta",  &trig_tower_ieta);
  myChain->SetBranchAddress("trig_tower_iphi",  &trig_tower_iphi);
  myChain->SetBranchAddress("trig_tower_adc",  &trig_tower_adc);
  myChain->SetBranchAddress("trig_tower_sFGVB",  &trig_tower_sFGVB);
  myChain->SetBranchAddress("trig_tower_FG",  &trig_tower_FG);

  myChain->SetBranchAddress("trig_tower_N_E",     &trig_tower_N_E);
  myChain->SetBranchAddress("trig_tower_ieta_E",  &trig_tower_ieta_E);
  myChain->SetBranchAddress("trig_tower_iphi_E",  &trig_tower_iphi_E);
  myChain->SetBranchAddress("trig_tower_adc_E",   &trig_tower_adc_E);
  myChain->SetBranchAddress("trig_tower_sFGVB_E", &trig_tower_sFGVB_E);
  myChain->SetBranchAddress("trig_tower_FG_E", &trig_tower_FG_E);

  // HCAL TP                                                        
  myChain->SetBranchAddress("trig_tower_hcal_N", &trig_tower_hcal_N);
  myChain->SetBranchAddress("trig_tower_hcal_ieta",  &trig_tower_hcal_ieta);
  myChain->SetBranchAddress("trig_tower_hcal_iphi",  &trig_tower_hcal_iphi);
  myChain->SetBranchAddress("trig_tower_hcal_et",  &trig_tower_hcal_et);
  myChain->SetBranchAddress("trig_tower_hcal_FG",  &trig_tower_hcal_FG);

  myChain->SetBranchStatus("trig_tower*",0);
  
  // L1 candidates collections                        
  myChain->SetBranchAddress("trig_L1emIso_N", &trig_L1emIso_N);
  myChain->SetBranchAddress("trig_L1emIso_ieta", &trig_L1emIso_ieta);
  myChain->SetBranchAddress("trig_L1emIso_iphi", &trig_L1emIso_iphi);
  myChain->SetBranchAddress("trig_L1emIso_rank", &trig_L1emIso_rank);

  myChain->SetBranchAddress("trig_L1emNonIso_N", &trig_L1emNonIso_N);
  myChain->SetBranchAddress("trig_L1emNonIso_ieta", &trig_L1emNonIso_ieta);
  myChain->SetBranchAddress("trig_L1emNonIso_iphi", &trig_L1emNonIso_iphi);
  myChain->SetBranchAddress("trig_L1emNonIso_rank", &trig_L1emNonIso_rank);

  myChain->SetBranchAddress("trig_L1emIso_N_To", &trig_L1emIso_N_To);
  myChain->SetBranchAddress("trig_L1emIso_ieta_To", &trig_L1emIso_ieta_To);
  myChain->SetBranchAddress("trig_L1emIso_iphi_To", &trig_L1emIso_iphi_To);
  myChain->SetBranchAddress("trig_L1emIso_rank_To", &trig_L1emIso_rank_To);

  myChain->SetBranchAddress("trig_L1emNonIso_N_To", &trig_L1emNonIso_N_To);
  myChain->SetBranchAddress("trig_L1emNonIso_ieta_To", &trig_L1emNonIso_ieta_To);
  myChain->SetBranchAddress("trig_L1emNonIso_iphi_To", &trig_L1emNonIso_iphi_To);
  myChain->SetBranchAddress("trig_L1emNonIso_rank_To", &trig_L1emNonIso_rank_To);

  myChain->SetBranchAddress("trig_L1emIso_N_M_To", &trig_L1emIso_N_M_To);
  myChain->SetBranchAddress("trig_L1emIso_ieta_M_To", &trig_L1emIso_ieta_M_To);
  myChain->SetBranchAddress("trig_L1emIso_iphi_M_To", &trig_L1emIso_iphi_M_To);
  myChain->SetBranchAddress("trig_L1emIso_rank_M_To", &trig_L1emIso_rank_M_To);

  myChain->SetBranchAddress("trig_L1emNonIso_N_M_To", &trig_L1emNonIso_N_M_To);
  myChain->SetBranchAddress("trig_L1emNonIso_ieta_M_To", &trig_L1emNonIso_ieta_M_To);
  myChain->SetBranchAddress("trig_L1emNonIso_iphi_M_To", &trig_L1emNonIso_iphi_M_To);
  myChain->SetBranchAddress("trig_L1emNonIso_rank_M_To", &trig_L1emNonIso_rank_M_To);

  int numEntries = myChain->GetEntries () ;
  int nProcess = numEntries;
  if(nEntries>=0 && nEntries<numEntries)
    nProcess = nEntries;

  TString filename;
  bool evt_trig_EG12, evt_trig, evt_trig_M;
  int spike_trig, spike_trig_M;

  // Numbers //
  const int nM=2;
  const int nEG=8;
  int thresh[nEG] = {2,5,8,10,12,15,20,30} ;
  TString trigname[nEG] = {"2","5","8","10","12","15","20","30"};
  TString collname[nM]={"N","M"};

  // HISTOGRAMS //
  TH1F * h_spikes;
  TH1F * h_triggering_spikes[nEG][nM];
  TH1F * h_evts_trigBy_any[nEG][nM];
  TH1F * h_evts_trigBy_spikes[nEG][nM];

  const int nVtx = 40;
  TString name_histo;

  h_spikes = new TH1F("h_spikes","h_spikes",nVtx,0,nVtx); // abscisse = vtx_N

  for(int iEG=0 ; iEG<nEG ; iEG++ ) {
    for(int iM=0 ; iM<nM ; iM++ ) {
      
      name_histo = "h_triggering_spikes_EG"+trigname[iEG]+"_"+collname[iM];
      h_triggering_spikes[iEG][iM]=new TH1F(name_histo,name_histo,nVtx,0,nVtx);
      
      name_histo = "h_evts_trigBy_any_EG"+trigname[iEG]+"_"+collname[iM];
      h_evts_trigBy_any[iEG][iM]=new TH1F(name_histo,name_histo,nVtx,0,nVtx);
      
      name_histo = "h_evts_trigBy_spikes_EG"+trigname[iEG]+"_"+collname[iM];
      h_evts_trigBy_spikes[iEG][iM]=new TH1F(name_histo,name_histo,nVtx,0,nVtx);     

    }
  }
  
  // Loop over entries //
  int nCurrentRun = -999;
  outlog << "will process " << nProcess << "/" << numEntries << "entries" << endl;
  //
  for (int iEvent = 0 ; iEvent < nProcess ; iEvent++ ) {
    
    // TP Initialization                                                                                                           
    trig_tower_N = 0;
    for(int iTow=0 ; iTow<nTow ; iTow++) {
      trig_tower_ieta[iTow] = trig_tower_iphi[iTow]  = -999;
      trig_tower_adc[iTow]  = trig_tower_sFGVB[iTow] = -999;
    }
    trig_tower_N_M = 0;
    for(int iTow=0 ; iTow<nTow ; iTow++) {
      trig_tower_ieta_M[iTow] = trig_tower_iphi_M[iTow]  = -999;
      trig_tower_adc_M[iTow]  = trig_tower_sFGVB_M[iTow] = -999;
    }
    trig_tower_N_E = 0;
    for(int iTow=0 ; iTow<nTow ; iTow++) {
      trig_tower_ieta_E[iTow] = trig_tower_iphi_E[iTow] = -999;
      for(int i=0 ; i<5 ; i++)
	trig_tower_adc_E[iTow][i] = trig_tower_sFGVB_E[iTow][i] = -999;
    }

    // L1 candidates                                                                                                               
    trig_L1emIso_N    = 0;
    trig_L1emNonIso_N = 0;
    trig_L1emIso_N_M_To  = 0;
    trig_L1emNonIso_N_M_To = 0;
    trig_L1emIso_N_To  = 0;
    trig_L1emNonIso_N_To = 0;

    for(int il1=0 ; il1<4 ; il1++) {
      trig_L1emIso_ieta[il1] = 0;
      trig_L1emIso_iphi[il1] = 0;
      trig_L1emIso_rank[il1] = 0;
      trig_L1emNonIso_ieta[il1] = 0;
      trig_L1emNonIso_iphi[il1] = 0;
      trig_L1emNonIso_rank[il1] = 0;

      trig_L1emIso_ieta_To[il1] = 0;
      trig_L1emIso_iphi_To[il1] = 0;
      trig_L1emIso_rank_To[il1] = 0;
      trig_L1emNonIso_ieta_To[il1] = 0;
      trig_L1emNonIso_iphi_To[il1] = 0;
      trig_L1emNonIso_rank_To[il1] = 0;

      trig_L1emNonIso_ieta_M_To[il1] = 0;
      trig_L1emNonIso_iphi_M_To[il1] = 0;
      trig_L1emNonIso_rank_M_To[il1] = 0;
      trig_L1emIso_ieta_M_To[il1] = 0;
      trig_L1emIso_iphi_M_To[il1] = 0;
      trig_L1emIso_rank_M_To[il1] = 0;
    }
    
    myChain->GetEntry (iEvent) ;

    // show processed file                                                                                                         
    if(iEvent==0) {
      filename = myChain->GetFile()->GetName() ;
      outlog << "File : " << filename << endl << endl;
    }
    else if( filename != myChain->GetFile()->GetName() ) {
      filename = myChain->GetFile()->GetName() ;
      outlog << "File : " << myChain->GetFile()->GetName() << endl << endl;
    }

    // show current run/iCat processed                                                                                             
    if(iEvent==0) {
      nCurrentRun = nRun ;
      outlog << "nRun=" << nRun << endl;
    }
    else if(nRun!=nCurrentRun) {
      nCurrentRun=nRun ;
      outlog << "nRun=" << nRun << endl;
    }

    // HLT selection //
    if(usr_hlt=="unbias")
      if(trig_HLT_path[0]==0) continue;
    
    // CHECK EG12 FIRED //
    evt_trig_EG12=false;
    for(int i=0 ; i<4 ; i++) {
      if(trig_L1emIso_rank[i] >= 12) evt_trig_EG12=true;
      if(trig_L1emNonIso_rank[i] >= 12) evt_trig_EG12=true;
    }
    if(!evt_trig_EG12) continue;

    // EXTRACT CONTAMINATION //
    //
    spike_trig=spike_trig_M=0;
    // Loop over Spikes
    for(int iS=0 ; iS<spike_N ; iS++) {

      h_spikes->Fill(vtx_N);

      if( spike_Et[iS] < spikeCut ) continue;
      
      if( spike_maxEGtrig[iS] != spike_maxEGtrig_To[iS] )
	if(debug) cout << "Spike #" << iS << " discripancy between OnlineFromData and OnlineFromEmul !" << endl;
    
      if( spike_maxEGtrig[iS]>spike_trig ) spike_trig = spike_maxEGtrig[iS];
      if( spike_maxEGtrig_M_To[iS]>spike_trig_M ) spike_trig_M = spike_maxEGtrig_M_To[iS];

      for(int iEG=0 ; iEG<nEG ; iEG++) {
	if( spike_maxEGtrig[iS]>thresh[iEG] ) h_triggering_spikes[iEG][0]->Fill(vtx_N);
	if( spike_maxEGtrig_M_To[iS]>thresh[iEG] ) h_triggering_spikes[iEG][1]->Fill(vtx_N);
      }
    }
    // 
    // Object triggering event
    for(int iEG=0 ; iEG<nEG ; iEG++) {
      
      // EG trig by any object
      evt_trig=evt_trig_M=false;
      for(int i=0 ; i<4 ; i++) {
	if(trig_L1emIso_rank_To[i] >= thresh[iEG]) evt_trig=true;
	if(trig_L1emNonIso_rank_To[i] >= thresh[iEG]) evt_trig=true;
	//
	if(trig_L1emIso_rank_M_To[i] >= thresh[iEG]) evt_trig_M=true;
	if(trig_L1emNonIso_rank_M_To[i] >= thresh[iEG]) evt_trig_M=true;	
      }
      
      if(evt_trig)
	h_evts_trigBy_any[iEG][0]->Fill(vtx_N);
      
      if(evt_trig_M)
	h_evts_trigBy_any[iEG][1]->Fill(vtx_N);
      
      // EG trig by spike
      if(spike_trig>=thresh[iEG])
	h_evts_trigBy_spikes[iEG][0]->Fill(vtx_N);

      if(spike_trig_M>=thresh[iEG])
	h_evts_trigBy_spikes[iEG][1]->Fill(vtx_N);
    }
     
  }
    
  TFile *outplot = new TFile(dirOut+"/spike_plots.root","RECREATE");
  h_spikes->Write();

  for(int iEG=0 ; iEG<nEG ; iEG++) {
    for(int iM=0; iM<nM ; iM++) {
      h_triggering_spikes[iEG][iM]->Write();
      h_evts_trigBy_any[iEG][iM]->Write();
      h_evts_trigBy_spikes[iEG][iM]->Write();
    }
  }
  outplot->Close();

  cout << "DONE, BABY" << endl;

  return 0;
}
Ejemplo n.º 2
0
int main(int argc,char *argv[]) {   // code starts // main
  
  TApplication myApp("myApp", 0, 0 ,0,-1);   
  
  vector<string> inFileList;   // process the file input file list (in case it is desired to run multiple root files as input
  int returnCode = processCommandLineArgs( argc, argv, inFileList);
  if(returnCode!=0){
    cerr << "Error\n";
    return returnCode;
  }
  
  TChain *dataTree = new TChain("dataTree"); // open a TChain and add the opened root files to it
  for (unsigned int i = 0; i < inFileList.size(); ++i)
    dataTree->Add(inFileList[i].c_str());
  cout << "number of events: " << dataTree->GetEntries() << endl;  // check the number of entries in the TChain
  
  int sizeTDC_0,sizeTDC_1,sizeTDC_2;   // cuántos hits hubieron en un evento
  double TDC_LE_0[kHitsTDCmax];   // todos los flancos iniciales de los pulsos de un evento, canal 0 (leading edge)
  double TDC_LE_1[kHitsTDCmax];   // todos los flancos iniciales de los pulsos de un evento, canal 1
  double TDC_LE_2[kHitsTDCmax];
  
  double TDC_TE_0[kHitsTDCmax];   // todos los flancos finales de los pulsos de un evento, canal 0 (trailing edge)
  double TDC_TE_1[kHitsTDCmax];
  double TDC_TE_2[kHitsTDCmax];
  
  // determina el estado de las ramas del árbol de root //
  dataTree->SetBranchStatus("*",0);          // apaga todas las ramas
  dataTree->SetBranchStatus("sizeTDC_0",1);  // enciente la rama sizeTDC_0 
  dataTree->SetBranchStatus("sizeTDC_1",1);  // ...
  dataTree->SetBranchStatus("sizeTDC_2",1);
  dataTree->SetBranchStatus("TDC_LE_0",1);
  dataTree->SetBranchStatus("TDC_LE_1",1);
  dataTree->SetBranchStatus("TDC_LE_2",1);
  dataTree->SetBranchStatus("TDC_TE_0",1);
  dataTree->SetBranchStatus("TDC_TE_1",1);
  dataTree->SetBranchStatus("TDC_TE_2",1);
  
  // vincula las ramas del árbol de root con las variables declaradas más arriba
  dataTree->SetBranchAddress("sizeTDC_0",&sizeTDC_0);   // vincula la rama entre comillas llamada sizeTDC_0 con la direccón de memoria donde vive la variable previamente declarada (que hemos llamado igual por simplicidad)
  dataTree->SetBranchAddress("sizeTDC_1",&sizeTDC_1);
  dataTree->SetBranchAddress("sizeTDC_2",&sizeTDC_2);
  dataTree->SetBranchAddress("TDC_LE_0",&TDC_LE_0);
  dataTree->SetBranchAddress("TDC_LE_1",&TDC_LE_1);
  dataTree->SetBranchAddress("TDC_LE_2",&TDC_LE_2);
  dataTree->SetBranchAddress("TDC_TE_0",&TDC_TE_0);
  dataTree->SetBranchAddress("TDC_TE_1",&TDC_TE_1);
  dataTree->SetBranchAddress("TDC_TE_2",&TDC_TE_2);  
  
  { // Open the Ttree and index it event-by-event
    
	int n_events = (int) dataTree->GetEntries();

	/// 
	/// Inicio
	/// 
	// Placas en Arreglo A-ch0  B-ch1 C-ch2

	int ventana = 50; //Nanosegundos
	int contadorFiltro = 0; 
	int veto = 500; //Nanosegundos
	ofstream salida;
	salida.open("filtro.dat"); //archivo de salida

     
	for(int i=0; i<n_events; i++){  // loop over the number of events start
      
		dataTree->GetEntry(i);   // pido que la entrada del árbol llene las variables previamente declaradas
     
		///////////////////////////////////////////////////

		if (sizeTDC_0==1 && sizeTDC_1==1 && sizeTDC_2==1) //Exactamente un conteo en cada placa
		{
			if ( (TDC_LE_2[0]- TDC_LE_0[0]) <= ventana ) // A y C en coincidencia
			{
				if ( (TDC_LE_1[0]- TDC_LE_2[0]) >= veto ) // Sólo se toman en cuenta pulsos con mayor duración al veto
				{
					salida << TDC_LE_1[0] - TDC_LE_2[0] << endl ; //Salida al archivo
					contadorFiltro++;
				}
			}
		}

  } // End of indexing the TTree

	//Razón decaimientos muón / eventos totales

		double razon = static_cast <double> (contadorFiltro) / n_events ;

		cout << razon << endl;

		salida.close();
  }

  
  return 0;  // main end
}
int process(TString nameChain, TString file, int iFile, int nEntries, TString dirOut, 
	    TString dirIn, ofstream& outlog, int iJson, TString RunPhase, bool debug)  {
  
  // OUTPUT FILE //
  ostringstream ossi("");
  ossi << iFile ;
  TString name = dirIn;
  name +="elepairs_";
  name +=ossi.str();
  name +=".root";
  //TString name=(TString)(dirIn+"elepairs_"+ossi.str()+".root");

  TFile *outfile = new TFile(name,"RECREATE");
  ossi.str("");

  // INPUT TREE //
  TChain * myChain = new TChain(nameChain);
  myChain->Add(file);
  cout<<"test1"<<endl;
  int nEvent, nRun, nLumi ;

  // Vertices //
  int _vtx_N;
  double _vtx_x[200], _vtx_y[200], _vtx_z[200];
  double _vtx_normalizedChi2[200], _vtx_ndof[200], _vtx_nTracks[200], _vtx_d0[200];

  // Trigger Paths //
  int trig_hltInfo[250];
  int _trig_isEleHLTpath;
  int trig_HLT_path[4]; // unbias, EG5, EG8, EG12
  char trig_fired_names[5000];
  //
  vector<string> m_HLT_pathsV;
  vector<string> m_HLT_triggered;
  vector<int> m_HLT_pathsV_check;

//   m_HLT_pathsV.clear();
//   m_HLT_pathsV_check.clear();
//   for(int iP=0 ; iP<(int)HLT_paths_.size() ; iP++) {
//     m_HLT_pathsV.push_back( HLT_paths_[iP]);
//     m_HLT_pathsV_check.push_back(0);
//   }

  // Electrons
  TClonesArray * electrons = new TClonesArray ("TLorentzVector");
  int ele_N, sc_hybrid_N; 
  int ele_outOfTimeSeed[10],ele_severityLevelSeed[10];
  double ele_he[10], ele_sigmaietaieta[10];
  double ele_hcalDepth1TowerSumEt_dr03[10], ele_hcalDepth2TowerSumEt_dr03[10];
  double ele_ecalRecHitSumEt_dr03[10], ele_tkSumPt_dr03[10];
  double ele_sclEta[10], ele_sclEt[10];
  //double ecalIsoRel03,hcalIsoRel03,trackIsoRel03;
  double ele_deltaphiin[10], ele_deltaetain[10];
  double ele_conv_dist[10], ele_conv_dcot[10];
  double ele_fbrem[10];
  int ele_expected_inner_hits[10];
  //int ele_ambiguousGsfTracks[10];
  int ele_isConversion[10];
  int ele_echarge[10];
  //
  int ele_RCTeta[10], ele_RCTphi[10], ele_RCTL1iso[10], ele_RCTL1noniso[10], ele_RCTL1iso_M[10], ele_RCTL1noniso_M[10];
  int ele_TTetaVect[10][50], ele_TTphiVect[10][50];
  double ele_TTetVect[10][50];
  int ele_RCTetaVect[10][10], ele_RCTphiVect[10][10], ele_RCTL1isoVect[10][10], 
    ele_RCTL1nonisoVect[10][10],ele_RCTL1isoVect_M[10][10], ele_RCTL1nonisoVect_M[10][10];
  double ele_RCTetVect[10][10];

  // TP info
  const int nTow = 4032;
  int trig_tower_N,trig_tower_ieta[nTow],trig_tower_iphi[nTow],trig_tower_adc[nTow],trig_tower_sFGVB[nTow]; 
  int trig_tower_N_M,trig_tower_ieta_M[nTow],trig_tower_iphi_M[nTow],trig_tower_adc_M[nTow],trig_tower_sFGVB_M[nTow]; 
  int trig_tower_N_E,trig_tower_ieta_E[nTow],trig_tower_iphi_E[nTow],trig_tower_adc_E[nTow][5],trig_tower_sFGVB_E[nTow][5];

  // HCAL TP
  int trig_tower_hcal_N, trig_tower_hcal_ieta[4032], trig_tower_hcal_iphi[4032], trig_tower_hcal_FG[4032],trig_tower_hcal_et[4032];
  int trig_L1emIso_N, trig_L1emNonIso_N, trig_L1emIso_N_M, trig_L1emNonIso_N_M;

  // L1 candidates info
  int trig_L1emIso_ieta[4], trig_L1emIso_iphi[4], trig_L1emIso_rank[4];
  int trig_L1emNonIso_ieta[4], trig_L1emNonIso_iphi[4], trig_L1emNonIso_rank[4];
  int trig_L1emIso_ieta_M[4], trig_L1emIso_iphi_M[4], trig_L1emIso_rank_M[4];
  int trig_L1emNonIso_ieta_M[4], trig_L1emNonIso_iphi_M[4], trig_L1emNonIso_rank_M[4];

  // L1 prefiring
  int trig_preL1emIso_N; 
  int trig_preL1emNonIso_N;
  int trig_preL1emIso_ieta[4], trig_preL1emIso_iphi[4], trig_preL1emIso_rank[4]; 
  int trig_preL1emNonIso_ieta[4], trig_preL1emNonIso_iphi[4],trig_preL1emNonIso_rank[4];
  // L1 postfiring
  int trig_postL1emIso_N; 
  int trig_postL1emNonIso_N;
  int trig_postL1emIso_ieta[4], trig_postL1emIso_iphi[4], trig_postL1emIso_rank[4]; 
  int trig_postL1emNonIso_ieta[4], trig_postL1emNonIso_iphi[4],trig_postL1emNonIso_rank[4];
  
  // Masking
  int trig_nMaskedRCT, trig_nMaskedCh;
  int trig_iMaskedRCTeta[100], trig_iMaskedRCTphi[100], trig_iMaskedRCTcrate[100], trig_iMaskedTTeta[100], trig_iMaskedTTphi[100];

  int trig_strip_mask_N;
  int trig_strip_mask_TTieta[1000], trig_strip_mask_TTiphi[1000], trig_strip_mask_status[1000],
    trig_strip_mask_StripID[1000], trig_strip_mask_PseudoStripID[1000], trig_strip_mask_TccID[1000], trig_strip_mask_CCU[1000],
    trig_strip_mask_xtal_ix[1000][5], trig_strip_mask_xtal_iy[1000][5], trig_strip_mask_xtal_iz[1000][5];

  int trig_xtal_mask_N; // [EB+EE]
  int trig_xtal_mask_ieta[1000],trig_xtal_mask_iphi[1000], // for EE : xtal ieta->ix ; iphi -> iy
    trig_xtal_mask_TTieta[1000],trig_xtal_mask_TTiphi[1000], // but for EE towers, still ieta, iphi...
    trig_xtal_mask_Rieta[1000],trig_xtal_mask_Riphi[1000],
    trig_xtal_mask_status[1000], trig_xtal_mask_EBEE[1000]; // EBEE = {0,1} => 0=EB ; 1=EE
  //double trig_xtal_mask_eT[1000];  

  cout<<"test2"<<endl;
  // INITIALIZATION //
  //
  // Global
  nEvent = 0;
  nRun = 0;
  nLumi = 0;
  //
  // Vertices
  _vtx_N = 0; 
  for(int iv=0;iv<200;iv++) {
    _vtx_normalizedChi2[iv] = 0.;
    _vtx_ndof[iv] = 0.;
    _vtx_nTracks[iv] = 0.;
    _vtx_d0[iv] = 0.;
    _vtx_x[iv] = 0.;
    _vtx_y[iv] = 0.;
    _vtx_z[iv] = 0.;
  }
  //
  // L1 candidates
  trig_L1emIso_N    = 0; 
  trig_L1emNonIso_N = 0;
  trig_preL1emIso_N   = 0; 
  trig_preL1emNonIso_N  = 0;
  trig_postL1emIso_N    = 0; 
  trig_postL1emNonIso_N = 0;
  //
  for(int il1=0 ; il1<4 ; il1++) {
    trig_L1emIso_ieta[il1] = 0; 
    trig_L1emIso_iphi[il1] = 0; 
    trig_L1emIso_rank[il1] = 0; 
    trig_L1emNonIso_ieta[il1] = 0; 
    trig_L1emNonIso_iphi[il1] = 0; 
    trig_L1emNonIso_rank[il1] = 0; 
		
    trig_preL1emIso_ieta[il1] = 0; 
    trig_preL1emIso_iphi[il1] = 0; 
    trig_preL1emIso_rank[il1] = 0;
    trig_preL1emNonIso_ieta[il1] = 0; 
    trig_preL1emNonIso_iphi[il1] = 0; 
    trig_preL1emNonIso_rank[il1] = 0; 
		
    trig_postL1emIso_ieta[il1] = 0; 
    trig_postL1emIso_iphi[il1] = 0; 
    trig_postL1emIso_rank[il1] = 0;
    trig_postL1emNonIso_ieta[il1] = 0; 
    trig_postL1emNonIso_iphi[il1] = 0; 
    trig_postL1emNonIso_rank[il1] = 0;  
  }
  // 
  // Trigger towers
  trig_tower_N = 0;
  for(int iTow=0 ; iTow<nTow ; iTow++) {
    trig_tower_ieta[iTow] = trig_tower_iphi[iTow]  = -999;
    trig_tower_adc[iTow]  = trig_tower_sFGVB[iTow] = -999;
  }
  trig_tower_N_M = 0;
  for(int iTow=0 ; iTow<nTow ; iTow++) {
    trig_tower_ieta_M[iTow] = trig_tower_iphi_M[iTow]  = -999;
    trig_tower_adc_M[iTow]  = trig_tower_sFGVB_M[iTow] = -999;
  }
  trig_tower_N_E = 0;
  for(int iTow=0 ; iTow<nTow ; iTow++) {
    trig_tower_ieta_E[iTow] = trig_tower_iphi_E[iTow] = -999;
    for(int i=0 ; i<5 ; i++)
      trig_tower_adc_E[iTow][i] = trig_tower_sFGVB_E[iTow][i] = -999;
  }
  trig_tower_hcal_N = 0;
  for(int iTow=0 ; iTow<nTow ; iTow++) {
    trig_tower_hcal_ieta[iTow] = trig_tower_hcal_iphi[iTow]  = -999;
    trig_tower_hcal_FG[iTow]  = trig_tower_hcal_et[iTow] = -999;
  }
  //
  // Masked Towers
  trig_nMaskedRCT=0;
  trig_nMaskedCh=0;
  //
  for (int ii=0;ii<100;ii++) {
    trig_iMaskedRCTeta[ii]   = -999;
    trig_iMaskedRCTphi[ii]   = -999;
    trig_iMaskedRCTcrate[ii] = -999;
    trig_iMaskedTTeta[ii]    = -999;
    trig_iMaskedTTphi[ii]    = -999;
  }
  //
  // Masked strip/xtals
  trig_strip_mask_N = 0;
  trig_xtal_mask_N = 0;
  //
  for(int i=0 ; i<1000 ; i++) {
    trig_strip_mask_TTieta[i] = -999;
    trig_strip_mask_TTiphi[i] = -999;
    trig_strip_mask_status[i] = -999;
    trig_strip_mask_StripID[i] = -999;
    trig_strip_mask_PseudoStripID[i] = -999;
    trig_strip_mask_TccID[i] = -999;
    trig_strip_mask_CCU[i] = -999;
    //
    for(int j=0 ; j<5 ; j++) {
      trig_strip_mask_xtal_ix[i][j] = -999;
      trig_strip_mask_xtal_iy[i][j] = -999;
      trig_strip_mask_xtal_iz[i][j] = -999;
    }
    trig_xtal_mask_ieta[i] = -999;
    trig_xtal_mask_iphi[i] = -999;
    trig_xtal_mask_TTieta[i] = -999;
    trig_xtal_mask_TTiphi[i] = -999;
    trig_xtal_mask_Rieta[i] = -999;
    trig_xtal_mask_Riphi[i] = -999;
    trig_xtal_mask_status[i] = -999;
    trig_xtal_mask_EBEE[i] = -999;
  }

  cout<<"test3"<<endl;
  // Disable useless branches
  //myChain->SetBranchStatus("spike_*",0);
  //myChain->SetBranchStatus("vtx_*",0);
  //myChain->SetBranchStatus("skim_*",0);
  //myChain->SetBranchStatus("trig_pre*",0);
  //myChain->SetBranchStatus("trig_post*",0);
  //myChain->SetBranchStatus("trig_HLT*",0);
  //myChain->SetBranchStatus("BS*",0);
  //myChain->SetBranchStatus("MC_*",0);
  //myChain->SetBranchStatus("ele_MC*",0);
  ////myChain->SetBranchStatus("ele_eid*",0);
  ////myChain->SetBranchStatus("ele_Seed*",0);
  //myChain->SetBranchStatus("ele_charge*",0);
  //myChain->SetBranchStatus("met_*",0);
  //myChain->SetBranchStatus("muons*",0);
  //myChain->SetBranchStatus("jets*",0);
  myChain->SetBranchStatus("sc*",0);
  //myChain->SetBranchStatus("sc_hybrid_N",1);
  //myChain->SetBranchStatus("",0);

  // Global
  myChain->SetBranchAddress("nEvent",&nEvent);
  myChain->SetBranchAddress("nRun",&nRun);
  myChain->SetBranchAddress("nLumi",&nLumi);

  // Trigger
//   myChain->SetBranchAddress ("trig_HLT_triggered", &m_HLT_triggered);
//   myChain->SetBranchAddress ("trig_HLT_pathsV", &m_HLT_pathsV);
//   myChain->SetBranchAddress ("trig_HLT_pathsV_check", &m_HLT_pathsV_check);
  //
  myChain->SetBranchAddress("trig_HLT_path",&trig_HLT_path);
  // unbias, EG5, EG8, EG12
  //
  myChain->SetBranchAddress("trig_fired_names",&trig_fired_names);
  myChain->SetBranchAddress("trig_hltInfo",&trig_hltInfo);

  // SC
  //myChain->SetBranchAddress("sc_hybrid_N",   &sc_hybrid_N);
  
  // Electrons
  myChain->SetBranchAddress("ele_N",   &ele_N);
  myChain->SetBranchAddress("electrons",&electrons);
  myChain->SetBranchAddress("ele_severityLevelSeed", &ele_severityLevelSeed);
  myChain->SetBranchAddress("ele_he",&ele_he);
  myChain->SetBranchAddress("ele_sigmaietaieta",&ele_sigmaietaieta);
  myChain->SetBranchAddress("ele_hcalDepth1TowerSumEt_dr03", &ele_hcalDepth1TowerSumEt_dr03);
  myChain->SetBranchAddress("ele_hcalDepth2TowerSumEt_dr03", &ele_hcalDepth2TowerSumEt_dr03);
  myChain->SetBranchAddress("ele_ecalRecHitSumEt_dr03", &ele_ecalRecHitSumEt_dr03);
  myChain->SetBranchAddress("ele_tkSumPt_dr03",&ele_tkSumPt_dr03);
  myChain->SetBranchAddress("ele_sclEta",&ele_sclEta);
  myChain->SetBranchAddress("ele_sclEt",&ele_sclEt);
  myChain->SetBranchAddress("ele_expected_inner_hits",&ele_expected_inner_hits);
  myChain->SetBranchAddress("ele_deltaphiin",&ele_deltaphiin);
  myChain->SetBranchAddress("ele_deltaetain",&ele_deltaetain);
  myChain->SetBranchAddress("ele_conv_dist",&ele_conv_dist);
  myChain->SetBranchAddress("ele_conv_dcot",&ele_conv_dcot);
  myChain->SetBranchAddress("ele_fbrem",&ele_fbrem);
  //myChain->SetBranchAddress("ele_ambiguousGsfTracks", &ele_ambiguousGsfTracks);
  myChain->SetBranchAddress("ele_isConversion",&ele_isConversion);
  myChain->SetBranchAddress("ele_echarge",&ele_echarge);

  // L1 electron informations
  myChain->SetBranchAddress("ele_TTetaVect", &ele_TTetaVect);
  myChain->SetBranchAddress("ele_TTphiVect", &ele_TTphiVect);
  myChain->SetBranchAddress("ele_TTetVect", &ele_TTetVect);
  //
  myChain->SetBranchAddress("ele_RCTeta", &ele_RCTeta);
  myChain->SetBranchAddress("ele_RCTphi", &ele_RCTphi);
  myChain->SetBranchAddress("ele_RCTL1iso", &ele_RCTL1iso);
  myChain->SetBranchAddress("ele_RCTL1noniso", &ele_RCTL1noniso);
  myChain->SetBranchAddress("ele_RCTL1iso_M", &ele_RCTL1iso_M);
  myChain->SetBranchAddress("ele_RCTL1noniso_M", &ele_RCTL1noniso_M);

  myChain->SetBranchAddress("ele_RCTetaVect", &ele_RCTetaVect);
  myChain->SetBranchAddress("ele_RCTphiVect", &ele_RCTphiVect);
  myChain->SetBranchAddress("ele_RCTetVect", &ele_RCTetVect);
  myChain->SetBranchAddress("ele_RCTL1isoVect", &ele_RCTL1isoVect);
  myChain->SetBranchAddress("ele_RCTL1nonisoVect", &ele_RCTL1nonisoVect);
  myChain->SetBranchAddress("ele_RCTL1isoVect_M", &ele_RCTL1isoVect_M);
  myChain->SetBranchAddress("ele_RCTL1nonisoVect_M", &ele_RCTL1nonisoVect_M);

  // L1 candidates
  myChain->SetBranchAddress("trig_L1emIso_N", &trig_L1emIso_N);
  myChain->SetBranchAddress("trig_L1emIso_ieta", &trig_L1emIso_ieta);
  myChain->SetBranchAddress("trig_L1emIso_iphi", &trig_L1emIso_iphi);
  myChain->SetBranchAddress("trig_L1emIso_rank", &trig_L1emIso_rank);

  myChain->SetBranchAddress("trig_L1emNonIso_N", &trig_L1emNonIso_N);
  myChain->SetBranchAddress("trig_L1emNonIso_ieta", &trig_L1emNonIso_ieta);
  myChain->SetBranchAddress("trig_L1emNonIso_iphi", &trig_L1emNonIso_iphi); 
  myChain->SetBranchAddress("trig_L1emNonIso_rank", &trig_L1emNonIso_rank);

  myChain->SetBranchAddress("trig_L1emIso_N_M", &trig_L1emIso_N_M);
  myChain->SetBranchAddress("trig_L1emIso_ieta_M", &trig_L1emIso_ieta_M);
  myChain->SetBranchAddress("trig_L1emIso_iphi_M", &trig_L1emIso_iphi_M);
  myChain->SetBranchAddress("trig_L1emIso_rank_M", &trig_L1emIso_rank_M);
  
  myChain->SetBranchAddress("trig_L1emNonIso_N_M", &trig_L1emNonIso_N_M);
  myChain->SetBranchAddress("trig_L1emNonIso_ieta_M", &trig_L1emNonIso_ieta_M);
  myChain->SetBranchAddress("trig_L1emNonIso_iphi_M", &trig_L1emNonIso_iphi_M);
  myChain->SetBranchAddress("trig_L1emNonIso_rank_M", &trig_L1emNonIso_rank_M);

  // Pre/post - firing L1 candidates
  myChain->SetBranchAddress("trig_preL1emIso_N",     &trig_preL1emIso_N);
  myChain->SetBranchAddress("trig_preL1emIso_ieta",  &trig_preL1emIso_ieta);
  myChain->SetBranchAddress("trig_preL1emIso_iphi",  &trig_preL1emIso_iphi);
  myChain->SetBranchAddress("trig_preL1emIso_rank",  &trig_preL1emIso_rank);
  //
  myChain->SetBranchAddress("trig_preL1emNonIso_N",     &trig_preL1emNonIso_N);
  myChain->SetBranchAddress("trig_preL1emNonIso_ieta",  &trig_preL1emNonIso_ieta);
  myChain->SetBranchAddress("trig_preL1emNonIso_iphi",  &trig_preL1emNonIso_iphi);
  myChain->SetBranchAddress("trig_preL1emNonIso_rank",  &trig_preL1emNonIso_rank);
  //
  myChain->SetBranchAddress("trig_postL1emIso_N",     &trig_postL1emIso_N);
  myChain->SetBranchAddress("trig_postL1emIso_ieta",  &trig_postL1emIso_ieta);
  myChain->SetBranchAddress("trig_postL1emIso_iphi",  &trig_postL1emIso_iphi);
  myChain->SetBranchAddress("trig_postL1emIso_rank",  &trig_postL1emIso_rank);
  //
  myChain->SetBranchAddress("trig_postL1emNonIso_N",     &trig_postL1emNonIso_N);
  myChain->SetBranchAddress("trig_postL1emNonIso_ieta",  &trig_postL1emNonIso_ieta);
  myChain->SetBranchAddress("trig_postL1emNonIso_iphi",  &trig_postL1emNonIso_iphi);
  myChain->SetBranchAddress("trig_postL1emNonIso_rank",  &trig_postL1emNonIso_rank);

  // Trigger Towers
  // normal collection
  myChain->SetBranchAddress("trig_tower_N", &trig_tower_N);
  myChain->SetBranchAddress("trig_tower_ieta",  &trig_tower_ieta);
  myChain->SetBranchAddress("trig_tower_iphi",  &trig_tower_iphi);
  myChain->SetBranchAddress("trig_tower_adc",  &trig_tower_adc);
  myChain->SetBranchAddress("trig_tower_sFGVB",  &trig_tower_sFGVB);
 
  // modified collection
  myChain->SetBranchAddress("trig_tower_N_M", &trig_tower_N_M);
  myChain->SetBranchAddress("trig_tower_ieta_M",  &trig_tower_ieta_M);
  myChain->SetBranchAddress("trig_tower_iphi_M",  &trig_tower_iphi_M);
  myChain->SetBranchAddress("trig_tower_adc_M",  &trig_tower_adc_M);
  myChain->SetBranchAddress("trig_tower_sFGVB_M",  &trig_tower_sFGVB_M);

  myChain->SetBranchAddress("trig_tower_N_E",     &trig_tower_N_E);
  myChain->SetBranchAddress("trig_tower_ieta_E",  &trig_tower_ieta_E);
  myChain->SetBranchAddress("trig_tower_iphi_E",  &trig_tower_iphi_E);
  myChain->SetBranchAddress("trig_tower_adc_E",   &trig_tower_adc_E);
  myChain->SetBranchAddress("trig_tower_sFGVB_E", &trig_tower_sFGVB_E);
  
  // HCAL TP
  myChain->SetBranchAddress("trig_tower_hcal_N", &trig_tower_hcal_N);
  myChain->SetBranchAddress("trig_tower_hcal_ieta",  &trig_tower_hcal_ieta);
  myChain->SetBranchAddress("trig_tower_hcal_iphi",  &trig_tower_hcal_iphi);
  myChain->SetBranchAddress("trig_tower_hcal_et",  &trig_tower_hcal_et);
  myChain->SetBranchAddress("trig_tower_hcal_FG",  &trig_tower_hcal_FG);

  // Strip masking
  myChain->SetBranchAddress("trig_strip_mask_N", &trig_strip_mask_N);
  myChain->SetBranchAddress("trig_strip_mask_TTieta", &trig_strip_mask_TTieta);
  myChain->SetBranchAddress("trig_strip_mask_TTiphi", &trig_strip_mask_TTiphi);
  myChain->SetBranchAddress("trig_strip_mask_StripID", &trig_strip_mask_StripID);
  myChain->SetBranchAddress("trig_strip_mask_PseudoStripID", &trig_strip_mask_PseudoStripID);
  myChain->SetBranchAddress("trig_strip_mask_TccID", &trig_strip_mask_TccID);
  myChain->SetBranchAddress("trig_strip_mask_CCU", &trig_strip_mask_CCU);
  myChain->SetBranchAddress("trig_strip_mask_xtal_ix", &trig_strip_mask_xtal_ix);
  myChain->SetBranchAddress("trig_strip_mask_xtal_iy", &trig_strip_mask_xtal_iy);
  myChain->SetBranchAddress("trig_strip_mask_xtal_iz", &trig_strip_mask_xtal_iz);
  //
  // Crystal masking
  myChain->SetBranchAddress("trig_xtal_mask_N", &trig_xtal_mask_N);
  myChain->SetBranchAddress("trig_xtal_mask_ieta", &trig_xtal_mask_ieta);
  myChain->SetBranchAddress("trig_xtal_mask_iphi", &trig_xtal_mask_iphi);
  myChain->SetBranchAddress("trig_xtal_mask_TTieta", &trig_xtal_mask_TTieta);
  myChain->SetBranchAddress("trig_xtal_mask_TTiphi", &trig_xtal_mask_TTiphi);
  myChain->SetBranchAddress("trig_xtal_mask_Rieta", &trig_xtal_mask_Rieta);
  myChain->SetBranchAddress("trig_xtal_mask_Riphi", &trig_xtal_mask_Riphi);
  myChain->SetBranchAddress("trig_xtal_mask_status", &trig_xtal_mask_status);
  myChain->SetBranchAddress("trig_xtal_mask_EBEE", &trig_xtal_mask_EBEE);

  // Masking
  myChain->SetBranchAddress("trig_nMaskedRCT",      &trig_nMaskedRCT);      
  myChain->SetBranchAddress("trig_iMaskedRCTeta",   &trig_iMaskedRCTeta);                                          
  myChain->SetBranchAddress("trig_iMaskedRCTcrate", &trig_iMaskedRCTcrate);
  myChain->SetBranchAddress("trig_iMaskedRCTphi",   &trig_iMaskedRCTphi);
  myChain->SetBranchAddress("trig_nMaskedCh",       &trig_nMaskedCh);    
  myChain->SetBranchAddress("trig_iMaskedTTeta",    &trig_iMaskedTTeta);   
  myChain->SetBranchAddress("trig_iMaskedTTphi",    &trig_iMaskedTTphi);      	


  if(debug) cout << "got the input tree, start to define output tree" << endl;
  
  // OUTPUT TREE //
  TTree * outtree = new TTree("ElePairs","ElePairs");

  // General informations
  outtree->Branch("nRun",&nRun,"nRun/I");
  outtree->Branch("nLumi",&nLumi,"nLumi/I");
  outtree->Branch("nEvent",&nEvent,"nEvent/I");

  // Vertices
  outtree->Branch("vtx_N",&_vtx_N,"vtx_N/I");
  outtree->Branch("vtx_normalizedChi2",&_vtx_normalizedChi2,"vtx_normalizedChi2[200]/D");
  outtree->Branch("vtx_ndof",&_vtx_ndof,"vtx_ndof[200]/D");
  outtree->Branch("vtx_nTracks",&_vtx_nTracks,"vtx_nTracks[200]/D");
  outtree->Branch("vtx_d0",&_vtx_d0,"vtx_d0[200]/D");
  outtree->Branch("vtx_x",&_vtx_x,"vtx_x[200]/D");
  outtree->Branch("vtx_y",&_vtx_y,"vtx_y[200]/D");
  outtree->Branch("vtx_z",&_vtx_z,"vtx_z[200]/D");

  // HLT informations
//   outtree->Branch ("trig_HLT_triggered", &m_HLT_triggered, 256000,0);
//   outtree->Branch ("trig_HLT_pathsV", &m_HLT_pathsV, 256000,0);
//   outtree->Branch ("trig_HLT_pathsV_check", &m_HLT_pathsV_check, 256000,0);
  //
  outtree->Branch("trig_HLT_path",&trig_HLT_path,"trig_HLT_path[4]/I");
  // unbias, EG5, EG8, EG12
  //
  outtree->Branch("trig_fired_names",&trig_fired_names,"trig_fired_names[5000]/C");
  outtree->Branch("trig_hltInfo",&trig_hltInfo,"trig_hltInfo[250]/I");  

  // Trigger towers
  outtree->Branch("trig_tower_N",&trig_tower_N,"trig_tower_N/I");
  outtree->Branch("trig_tower_ieta",&trig_tower_ieta,"trig_tower_ieta[4032]/I");
  outtree->Branch("trig_tower_iphi",&trig_tower_iphi,"trig_tower_iphi[4032]/I");
  outtree->Branch("trig_tower_adc",&trig_tower_adc,"trig_tower_adc[4032]/I");
  outtree->Branch("trig_tower_sFGVB",&trig_tower_sFGVB,"trig_tower_sFGVB[4032]/I");
  //
  outtree->Branch("trig_tower_N_M",&trig_tower_N_M,"trig_tower_N_M/I");
  outtree->Branch("trig_tower_ieta_M",&trig_tower_ieta_M,"trig_tower_ieta_M[4032]/I");
  outtree->Branch("trig_tower_iphi_M",&trig_tower_iphi_M,"trig_tower_iphi_M[4032]/I");
  outtree->Branch("trig_tower_adc_M",&trig_tower_adc_M,"trig_tower_adc_M[4032]/I");
  outtree->Branch("trig_tower_sFGVB_M",&trig_tower_sFGVB_M,"trig_tower_sFGVB_M[4032]/I");
  //
  outtree->Branch("trig_tower_N_E",&trig_tower_N_E,"trig_tower_N_E/I");
  outtree->Branch("trig_tower_ieta_E",&trig_tower_ieta_E,"trig_tower_ieta_E[4032]/I");
  outtree->Branch("trig_tower_iphi_E",&trig_tower_iphi_E,"trig_tower_iphi_E[4032]/I");
  outtree->Branch("trig_tower_adc_E",&trig_tower_adc_E,"trig_tower_adc_E[4032][5]/I");
  outtree->Branch("trig_tower_sFGVB_E",&trig_tower_sFGVB_E,"trig_tower_sFGVB_E[4032][5]/I");

  // HCAL TP
  outtree->Branch("trig_tower_hcal_N", &trig_tower_hcal_N, "trig_tower_hcal_N/I");
  outtree->Branch("trig_tower_hcal_ieta",  &trig_tower_hcal_ieta,  "trig_tower_hcal_ieta[trig_tower_N]/I");
  outtree->Branch("trig_tower_hcal_iphi",  &trig_tower_hcal_iphi,  "trig_tower_hcal_iphi[trig_tower_N]/I");
  outtree->Branch("trig_tower_hcal_et",  &trig_tower_hcal_et,  "trig_tower_hcal_et[trig_tower_N]/I");
  outtree->Branch("trig_tower_hcal_FG",  &trig_tower_hcal_FG,  "trig_tower_hcal_FG[trig_tower_N]/I");

  // Strip masking
  outtree->Branch("trig_strip_mask_N", &trig_strip_mask_N, "trig_strip_mask_N/I");
  outtree->Branch("trig_strip_mask_TTieta", &trig_strip_mask_TTieta, "trig_strip_mask_TTieta[trig_strip_mask_N]/I");
  outtree->Branch("trig_strip_mask_TTiphi", &trig_strip_mask_TTiphi, "trig_strip_mask_TTiphi[trig_strip_mask_N]/I");
  outtree->Branch("trig_strip_mask_StripID", &trig_strip_mask_StripID, "trig_strip_mask_StripID[trig_strip_mask_N]/I");
  outtree->Branch("trig_strip_mask_PseudoStripID", &trig_strip_mask_PseudoStripID, "trig_strip_mask_PseudoStripID[trig_strip_mask_N]/I");
  outtree->Branch("trig_strip_mask_TccID", &trig_strip_mask_TccID, "trig_strip_mask_TccID[trig_strip_mask_N]/I");
  outtree->Branch("trig_strip_mask_CCU", &trig_strip_mask_CCU, "trig_strip_mask_CCU[trig_strip_mask_N]/I");
  outtree->Branch("trig_strip_mask_xtal_ix", &trig_strip_mask_xtal_ix, "trig_strip_mask_xtal_ix[trig_strip_mask_N][5]/I");
  outtree->Branch("trig_strip_mask_xtal_iy", &trig_strip_mask_xtal_iy, "trig_strip_mask_xtal_iy[trig_strip_mask_N][5]/I");
  outtree->Branch("trig_strip_mask_xtal_iz", &trig_strip_mask_xtal_iz, "trig_strip_mask_xtal_iz[trig_strip_mask_N][5]/I");
  //
  // Crystal masking
  outtree->Branch("trig_xtal_mask_N", &trig_xtal_mask_N, "trig_xtal_mask_N/I");
  outtree->Branch("trig_xtal_mask_ieta", &trig_xtal_mask_ieta, "trig_xtal_mask_ieta[trig_xtal_mask_N]/I");
  outtree->Branch("trig_xtal_mask_iphi", &trig_xtal_mask_iphi, "trig_xtal_mask_iphi[trig_xtal_mask_N]/I");
  outtree->Branch("trig_xtal_mask_TTieta", &trig_xtal_mask_TTieta, "trig_xtal_mask_TTieta[trig_xtal_mask_N]/I");
  outtree->Branch("trig_xtal_mask_TTiphi", &trig_xtal_mask_TTiphi, "trig_xtal_mask_TTiphi[trig_xtal_mask_N]/I");
  outtree->Branch("trig_xtal_mask_Rieta", &trig_xtal_mask_Rieta, "trig_xtal_mask_Rieta[trig_xtal_mask_N]/I");
  outtree->Branch("trig_xtal_mask_Riphi", &trig_xtal_mask_Riphi, "trig_xtal_mask_Riphi[trig_xtal_mask_N]/I");
  outtree->Branch("trig_xtal_mask_status", &trig_xtal_mask_status, "trig_xtal_mask_status[trig_xtal_mask_N]/I");
  outtree->Branch("trig_xtal_mask_EBEE", &trig_xtal_mask_EBEE, "trig_xtal_mask_EBEE[trig_xtal_mask_N]/I");
  // L1 candidates
  outtree->Branch("trig_L1emIso_N",     &trig_L1emIso_N,     "trig_L1emIso_N/I");
  outtree->Branch("trig_L1emIso_ieta",  &trig_L1emIso_ieta,  "trig_L1emIso_ieta[4]/I");
  outtree->Branch("trig_L1emIso_iphi",  &trig_L1emIso_iphi,  "trig_L1emIso_iphi[4]/I");
  outtree->Branch("trig_L1emIso_rank",  &trig_L1emIso_rank,  "trig_L1emIso_rank[4]/I");
  //outtree->Branch("trig_L1emIso_eta",   &trig_L1emIso_eta,   "trig_L1emIso_eta[4]/D");
  //outtree->Branch("trig_L1emIso_phi",   &trig_L1emIso_phi,   "trig_L1emIso_phi[4]/D");
//   outtree->Branch("trig_L1emIso_energy",&trig_L1emIso_energy,"trig_L1emIso_energy[4]/D");
//   outtree->Branch("trig_L1emIso_et",    &trig_L1emIso_et,    "trig_L1emIso_et[4]/D");
  //
  outtree->Branch("trig_L1emNonIso_N",     &trig_L1emNonIso_N,     "trig_L1emNonIso_N/I");
  outtree->Branch("trig_L1emNonIso_ieta",  &trig_L1emNonIso_ieta,  "trig_L1emNonIso_ieta[4]/I");
  outtree->Branch("trig_L1emNonIso_iphi",  &trig_L1emNonIso_iphi,  "trig_L1emNonIso_iphi[4]/I");
  outtree->Branch("trig_L1emNonIso_rank",  &trig_L1emNonIso_rank,  "trig_L1emNonIso_rank[4]/I");
//   outtree->Branch("trig_L1emNonIso_eta",   &trig_L1emNonIso_eta,   "trig_L1emNonIso_eta[4]/D");
//   outtree->Branch("trig_L1emNonIso_phi",   &trig_L1emNonIso_phi,   "trig_L1emNonIso_phi[4]/D");
//   outtree->Branch("trig_L1emNonIso_energy",&trig_L1emNonIso_energy,"trig_L1emNonIso_energy[4]/D");
//   outtree->Branch("trig_L1emNonIso_et",    &trig_L1emNonIso_et,    "trig_L1emNonIso_et[4]/D");
  //
  outtree->Branch("trig_L1emIso_N_M",     &trig_L1emIso_N_M,     "trig_L1emIso_N_M/I");
  outtree->Branch("trig_L1emIso_ieta_M",  &trig_L1emIso_ieta_M,  "trig_L1emIso_ieta_M[4]/I");
  outtree->Branch("trig_L1emIso_iphi_M",  &trig_L1emIso_iphi_M,  "trig_L1emIso_iphi_M[4]/I");
  outtree->Branch("trig_L1emIso_rank_M",  &trig_L1emIso_rank_M,  "trig_L1emIso_rank_M[4]/I");
//   outtree->Branch("trig_L1emIso_eta_M",   &trig_L1emIso_eta_M,   "trig_L1emIso_eta_M[4]/D");
//   outtree->Branch("trig_L1emIso_phi_M",   &trig_L1emIso_phi_M,   "trig_L1emIso_phi_M[4]/D");
//   outtree->Branch("trig_L1emIso_energy_M",&trig_L1emIso_energy_M,"trig_L1emIso_energy_M[4]/D");
//   outtree->Branch("trig_L1emIso_et_M",    &trig_L1emIso_et_M,    "trig_L1emIso_et_M[4]/D");
  //
  outtree->Branch("trig_L1emNonIso_N_M", &trig_L1emNonIso_N_M, "trig_L1emNonIso_N_M/I");
  outtree->Branch("trig_L1emNonIso_ieta_M", &trig_L1emNonIso_ieta_M, "trig_L1emNonIso_ieta_M[4]/I");
  outtree->Branch("trig_L1emNonIso_iphi_M", &trig_L1emNonIso_iphi_M, "trig_L1emNonIso_iphi_M[4]/I");
  outtree->Branch("trig_L1emNonIso_rank_M", &trig_L1emNonIso_rank_M, "trig_L1emNonIso_rank_M[4]/I");
//   outtree->Branch("trig_L1emNonIso_eta_M", &trig_L1emNonIso_eta_M, "trig_L1emNonIso_eta_M[4]/D");
//   outtree->Branch("trig_L1emNonIso_phi_M", &trig_L1emNonIso_phi_M, "trig_L1emNonIso_phi_M[4]/D");
//   outtree->Branch("trig_L1emNonIso_energy_M",&trig_L1emNonIso_energy_M,"trig_L1emNonIso_energy_M[4]/D");
//   outtree->Branch("trig_L1emNonIso_et_M", &trig_L1emNonIso_et_M, "trig_L1emNonIso_et_M[4]/D");

  // pre-post firing L1 candidates
  outtree->Branch("trig_preL1emIso_N",     &trig_preL1emIso_N,     "trig_preL1emIso_N/I");
  outtree->Branch("trig_preL1emIso_ieta",  &trig_preL1emIso_ieta,  "trig_preL1emIso_ieta[4]/I");
  outtree->Branch("trig_preL1emIso_iphi",  &trig_preL1emIso_iphi,  "trig_preL1emIso_iphi[4]/I");
  outtree->Branch("trig_preL1emIso_rank",  &trig_preL1emIso_rank,  "trig_preL1emIso_rank[4]/I");
  //
  outtree->Branch("trig_preL1emNonIso_N",     &trig_preL1emNonIso_N,     "trig_preL1emNonIso_N/I");
  outtree->Branch("trig_preL1emNonIso_ieta",  &trig_preL1emNonIso_ieta,  "trig_preL1emNonIso_ieta[4]/I");
  outtree->Branch("trig_preL1emNonIso_iphi",  &trig_preL1emNonIso_iphi,  "trig_preL1emNonIso_iphi[4]/I");
  outtree->Branch("trig_preL1emNonIso_rank",  &trig_preL1emNonIso_rank,  "trig_preL1emNonIso_rank[4]/I");
  //
  outtree->Branch("trig_postL1emIso_N",     &trig_postL1emIso_N,     "trig_postL1emIso_N/I");
  outtree->Branch("trig_postL1emIso_ieta",  &trig_postL1emIso_ieta,  "trig_postL1emIso_ieta[4]/I");
  outtree->Branch("trig_postL1emIso_iphi",  &trig_postL1emIso_iphi,  "trig_postL1emIso_iphi[4]/I");
  outtree->Branch("trig_postL1emIso_rank",  &trig_postL1emIso_rank,  "trig_postL1emIso_rank[4]/I");
  //
  outtree->Branch("trig_postL1emNonIso_N",     &trig_postL1emNonIso_N,     "trig_postL1emNonIso_N/I");
  outtree->Branch("trig_postL1emNonIso_ieta",  &trig_postL1emNonIso_ieta,  "trig_postL1emNonIso_ieta[4]/I");
  outtree->Branch("trig_postL1emNonIso_iphi",  &trig_postL1emNonIso_iphi,  "trig_postL1emNonIso_iphi[4]/I");
  outtree->Branch("trig_postL1emNonIso_rank",  &trig_postL1emNonIso_rank,  "trig_postL1emNonIso_rank[4]/I");
  //
  outtree->Branch("trig_nMaskedRCT",      &trig_nMaskedRCT,     "trig_nMaskedRCT/I");      
  outtree->Branch("trig_iMaskedRCTeta",   &trig_iMaskedRCTeta,  "trig_iMaskedRCTeta[trig_nMaskedRCT]/I");                                          
  outtree->Branch("trig_iMaskedRCTcrate", &trig_iMaskedRCTcrate,"trig_iMaskedRCTcrate[trig_nMaskedRCT]/I");                                                    
  outtree->Branch("trig_iMaskedRCTphi",   &trig_iMaskedRCTphi,  "trig_iMaskedRCTphi[trig_nMaskedRCT]/I");
  outtree->Branch("trig_nMaskedCh",       &trig_nMaskedCh,      "trig_nMaskedCh/I");    
  outtree->Branch("trig_iMaskedTTeta",    &trig_iMaskedTTeta,   "trig_iMaskedTTeta[trig_nMaskedCh]/I");   
  outtree->Branch("trig_iMaskedTTphi",    &trig_iMaskedTTphi,   "trig_iMaskedTTphi[trig_nMaskedCh]/I");      	


  // Pairs informations
  double pair_M;
  double pair_eta[2], pair_sclEta[2], pair_sclEt[2], pair_phi[2], pair_pT[2], pair_eT[2], pair_E[2];
  int pair_cuts[2], pair_HLT_Ele27_cut[2], pair_fidu[2], pair_charge[2], pair_RCTeta[2], pair_RCTphi[2], 
    pair_L1iso[2], pair_L1noniso[2], pair_L1iso_M[2], pair_L1noniso_M[2];
  int pair_RCTetaVect[2][10], pair_RCTphiVect[2][10], 
    pair_L1isoVect[2][10], pair_L1nonisoVect[2][10],pair_L1isoVect_M[2][10], pair_L1nonisoVect_M[2][10];
  double pair_RCTetVect[2][10];
  int pair_TTetaVect[2][50], pair_TTphiVect[2][50];
  double pair_TTetVect[2][50];

  //
  outtree->Branch("pair_M",&pair_M,"pair_M/D");
  //
  outtree->Branch("pair_cuts",&pair_cuts,"pair_cuts[2]/I");
  // 0 : noCut | 1 : VBTF 95 | 2 : VBTF 80 | 3 : VBTF 60
  outtree->Branch("pair_HLT_Ele27_cut",&pair_HLT_Ele27_cut,"pair_HLT_Ele27_cut[2]/I");
  outtree->Branch("pair_fidu",&pair_fidu,"pair_fidu[2]/I");
  //
  outtree->Branch("pair_eta",&pair_eta,"pair_eta[2]/D");
  outtree->Branch("pair_sclEta",&pair_sclEta,"pair_sclEta[2]/D");
  outtree->Branch("pair_phi",&pair_phi,"pair_phi[2]/D");
  outtree->Branch("pair_RCTeta",&pair_RCTeta,"pair_RCTeta[2]/I");
  outtree->Branch("pair_RCTphi",&pair_RCTphi,"pair_RCTphi[2]/I");
  //
  outtree->Branch("pair_charge",&pair_charge,"pair_charge[2]/I");
  outtree->Branch("pair_pT",&pair_pT,"pair_pT[2]/D");
  outtree->Branch("pair_eT",&pair_eT,"pair_eT[2]/D");
  outtree->Branch("pair_sclEt",&pair_sclEt,"pair_sclEt[2]/D");
  outtree->Branch("pair_E",&pair_E,"pair_E[2]/D");

  outtree->Branch("pair_TTetaVect", &pair_TTetaVect,"pair_TTetaVect[2][50]/I");
  outtree->Branch("pair_TTphiVect", &pair_TTphiVect,"pair_TTphiVect[2][50]/I");
  outtree->Branch("pair_TTetVect", &pair_TTetVect,"pair_TTetVect[2][50]/D");

  outtree->Branch("pair_L1iso",&pair_L1iso,"pair_L1iso[2]/I");
  outtree->Branch("pair_L1noniso",&pair_L1noniso,"pair_L1noniso[2]/I");
  outtree->Branch("pair_L1iso_M",&pair_L1iso_M,"pair_L1iso_M[2]/I");
  outtree->Branch("pair_L1noniso_M",&pair_L1noniso_M,"pair_L1noniso_M[2]/I");
  //
  outtree->Branch("pair_RCTetVect",&pair_RCTetVect,"pair_RCTetVect[2][10]/D");
  outtree->Branch("pair_RCTetaVect",&pair_RCTetaVect,"pair_RCTetaVect[2][10]/I");
  outtree->Branch("pair_RCTphiVect",&pair_RCTphiVect,"pair_RCTphiVect[2][10]/I");
  outtree->Branch("pair_L1isoVect",&pair_L1isoVect,"pair_L1isoVect[2][10]/I");
  outtree->Branch("pair_L1nonisoVect",&pair_L1nonisoVect,"pair_L1nonisoVect[2][10]/I");
  outtree->Branch("pair_L1isoVect_M",&pair_L1isoVect_M,"pair_L1isoVect_M[2][10]/I");
  outtree->Branch("pair_L1nonisoVect_M",&pair_L1nonisoVect_M,"pair_L1nonisoVect_M[2][10]/I");

  if(debug) cout << "output tree defined" << endl;
  cout<<"test4"<<endl;
  // USEFUL VARIABLES //
  vector<int> pairIdx;
  int cutEle[2], fidu[2];
  bool cut_HLT_Ele27[2];
  TLorentzVector* cand[2];
  TLorentzVector total;
  bool isGoodRun;
  TString filename;

  // JSON FILE READER //
  
  string jsonDir = "/data_CMS/cms/ndaci/" ;
  const int nJson = 10;
  string jsonFile[nJson]; // 2010B, May10, Aug05, Prompt
  map<int, vector<pair<int, int> > > jsonMap[nJson] ;

  jsonFile[0] = jsonDir + "ndaci_2011A/JSON/goodrunlist_json.txt" ;
  jsonFile[1] = jsonDir + "ndaci_2011A/JSON/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt" ;
  jsonFile[2] = jsonDir + "ndaci_2011A/JSON/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON_v3.txt" ;
  jsonFile[3] = jsonDir + "ndaci_2011A/JSON/Cert_160404-180252_7TeV_PromptReco_Collisions11_JSON.txt" ;
  jsonFile[4] = jsonDir + "ndaci_2011A/JSON/Cert_160404-180252_7TeV_ReRecoNov08_Collisions11_JSON.txt" ;

  // 2012
  jsonFile[5] = jsonDir + "ndaci_2012/JSON/Cert_190456-203002_8TeV_PromptReco_Collisions12_JSON.txt";
  jsonFile[6] = jsonDir + "ndaci_2012/JSON/Cert_190456-196531_8TeV_13Jul2012ReReco_Collisions12_JSON_v2.txt";
  jsonFile[7] = jsonDir + "ndaci_2012/JSON/Cert_190782-190949_8TeV_06Aug2012ReReco_Collisions12_JSON.txt";
  jsonFile[8] = jsonDir + "ndaci_2012/JSON/Cert_198022-198523_8TeV_24Aug2012ReReco_Collisions12_JSON.txt";
  jsonFile[9] = jsonDir + "ndaci_2012/JSON/Cert_190456-208357_8TeV_PromptReco_Collisions12_JSON.txt";
  cout<<"test5"<<endl;
  /**  for(int i=0 ; i<nJson ; i++)
    jsonMap[i] = readJSONFile(jsonFile[i]);
  
    if(debug) cout << "JSON defined" << endl;**/

  // -------------------------------------------------------------------------------
  // LOOP OVER EVENTS
  // -------------------------------------------------------------------------------  
  if(debug) cout << "gonna loop over events" << endl;
  cout<< "begining loop over events"<<endl;
  int numEntries = myChain->GetEntries () ;
  int nProcess = numEntries;
  if(nEntries>=0 && nEntries<numEntries)
    nProcess = nEntries;

  int nCurrentRun = -999;
  outlog << "will process " << nProcess << "/" << numEntries << "entries" << endl;

  for (int iEvent = 0 ; iEvent < nProcess ; iEvent++ )
    { 

      // HLT information
      for(int i=0 ; i<4 ; i++)
	trig_HLT_path[i]=0;
      
      for(int i=0 ; i<250 ; i++)
	trig_hltInfo[i]=0;

      // TP Initialization
      trig_tower_N = 0;
      for(int iTow=0 ; iTow<nTow ; iTow++) {
	trig_tower_ieta[iTow] = trig_tower_iphi[iTow]  = -999;
	trig_tower_adc[iTow]  = trig_tower_sFGVB[iTow] = -999;
      }
      trig_tower_N_M = 0;
      for(int iTow=0 ; iTow<nTow ; iTow++) {
	trig_tower_ieta_M[iTow] = trig_tower_iphi_M[iTow]  = -999;
	trig_tower_adc_M[iTow]  = trig_tower_sFGVB_M[iTow] = -999;
      }
      trig_tower_N_E = 0;
      for(int iTow=0 ; iTow<nTow ; iTow++) {
	trig_tower_ieta_E[iTow] = trig_tower_iphi_E[iTow] = -999;
	for(int i=0 ; i<5 ; i++)
	  trig_tower_adc_E[iTow][i] = trig_tower_sFGVB_E[iTow][i] = -999;
      }

      myChain->GetEntry (iEvent) ;
     
      // show processed file
      if(iEvent==0) {
        filename = myChain->GetFile()->GetName() ;
        outlog << "File : " << filename << endl << endl;
      }
      else if( filename != myChain->GetFile()->GetName() ) {
        filename = myChain->GetFile()->GetName() ;
        outlog << "File : " << myChain->GetFile()->GetName() << endl << endl;
      }
     
      // show current run/iCat processed
      if(iEvent==0) {
	nCurrentRun = nRun ;
	outlog << "nRun=" << nRun << endl;
      }
      else if(nRun!=nCurrentRun) {
	nCurrentRun=nRun ;
	outlog << "nRun=" << nRun << endl;
      }

      // run selection (using both json files)
      //int iJson = detJson(nRun);
      //int iJson = 4;
      if(debug) cout << "iJson = " << iJson << endl;
      outlog << "iJson = " << iJson << endl;
      if( iJson>-1 && iJson<9) {
	isGoodRun = AcceptEventByRunAndLumiSection(nRun, nLumi, jsonMap[iJson]);
	if(!isGoodRun) {
	  outlog << "failed JSON" << endl;
	  continue;
	}
      }
      else {
	outlog << "no proper JSON file" << endl;
	//continue;
      }

      // at least 2 electrons
      if(ele_N<2) continue;
      else outlog << "ele_N=" << ele_N << endl;

      // LOOP OVER ELECTRONS //
      if(debug) cout << "<-- ele_N=" << ele_N << endl
		     << "--- electrons.size=" << electrons->GetSize() << endl;
      for( int iEle1=0 ; iEle1<ele_N ; iEle1++ ) {
	if(debug) cout << "--- get ele #" << iEle1 << endl;
	cand[0] = (TLorentzVector*) (electrons->At (iEle1)) ;
	if(debug) cout << "--- got it" << endl;

	// severity selection
	if( ele_severityLevelSeed[iEle1] >= 3 ) continue;
	
	// check whether electrons of the pair pass HLT_Ele27 Id/Iso cuts
	if(debug) cout << "--- checks VBTF cuts" << endl;
	cut_HLT_Ele27[0] = VBTFcuts( "HLT_Ele27", RunPhase,
				     cand[0]->Pt(), cand[0]->Et(), ele_sclEta[iEle1], cand[0]->Eta(), ele_tkSumPt_dr03[iEle1], ele_ecalRecHitSumEt_dr03[iEle1], 
				     ele_hcalDepth1TowerSumEt_dr03[iEle1], ele_hcalDepth2TowerSumEt_dr03[iEle1], ele_expected_inner_hits[iEle1],
				     ele_deltaphiin[iEle1], ele_deltaetain[iEle1], ele_he[iEle1], ele_sigmaietaieta[iEle1],
				     ele_conv_dist[iEle1], ele_conv_dcot[iEle1], ele_fbrem[iEle1], ele_isConversion[iEle1] ) ;

	// check if ele is a good tag candidate : pass VBTF 95 and has pT>5 GeV
	cutEle[0] = 0;
	cutEle[0] = whichCuts( RunPhase, cand[0]->Pt(), cand[0]->Et(), ele_sclEta[iEle1], cand[0]->Eta(), ele_tkSumPt_dr03[iEle1], ele_ecalRecHitSumEt_dr03[iEle1], 
			       ele_hcalDepth1TowerSumEt_dr03[iEle1], ele_hcalDepth2TowerSumEt_dr03[iEle1], ele_expected_inner_hits[iEle1],
			       ele_deltaphiin[iEle1], ele_deltaetain[iEle1], ele_he[iEle1], ele_sigmaietaieta[iEle1],
			       ele_conv_dist[iEle1], ele_conv_dcot[iEle1], ele_fbrem[iEle1], ele_isConversion[iEle1] ) ;
	fidu[0] = 0;
	if ( fabs(ele_sclEta[iEle1]) < 2.5 && ( fabs(ele_sclEta[iEle1]) > 1.566 || fabs(ele_sclEta[iEle1])<1.4442 ) ) 
	  fidu[0] = 1 ;

	if( cutEle[0]>0 && cand[0]->Et()>=5. ) {
	  if(debug) cout << "--- ele #" << iEle1 << " is a good tag candidate" << endl;
	  
	  // loop to find probe candidates
	  for( int iEle2=0 ; iEle2<ele_N ; iEle2++ ) {
	    if(debug) cout << "----- looks Ele #" << iEle2 << endl;

	    cand[1] = (TLorentzVector*) (electrons->At (iEle2)) ;

	    // severity
	    if( ele_severityLevelSeed[iEle2] >= 3 ) continue;

	    // check HLT_Ele27 cuts
	    cut_HLT_Ele27[1] = VBTFcuts( "HLT_Ele27", RunPhase,
					 cand[1]->Pt(), cand[1]->Et(), ele_sclEta[iEle1], cand[1]->Eta(), ele_tkSumPt_dr03[iEle1], ele_ecalRecHitSumEt_dr03[iEle1], 
					 ele_hcalDepth1TowerSumEt_dr03[iEle1], ele_hcalDepth2TowerSumEt_dr03[iEle1], ele_expected_inner_hits[iEle1],
					 ele_deltaphiin[iEle1], ele_deltaetain[iEle1], ele_he[iEle1], ele_sigmaietaieta[iEle1],
					 ele_conv_dist[iEle1], ele_conv_dcot[iEle1], ele_fbrem[iEle1], ele_isConversion[iEle1] ) ;
	    

	    // check cuts passed by probe candidate
	    cutEle[1] = whichCuts( RunPhase, cand[1]->Pt(), cand[0]->Et(), ele_sclEta[iEle2], cand[1]->Eta(), ele_tkSumPt_dr03[iEle2], ele_ecalRecHitSumEt_dr03[iEle2], 
				   ele_hcalDepth1TowerSumEt_dr03[iEle2], ele_hcalDepth2TowerSumEt_dr03[iEle2], ele_expected_inner_hits[iEle2],
				   ele_deltaphiin[iEle2], ele_deltaetain[iEle2], ele_he[iEle2], ele_sigmaietaieta[iEle2],
				   ele_conv_dist[iEle2], ele_conv_dcot[iEle2], ele_fbrem[iEle2], ele_isConversion[iEle2] ) ;
	    fidu[1] = 0;
	    if ( fabs(ele_sclEta[iEle2]) < 2.5 && ( fabs(ele_sclEta[iEle2]) > 1.566 || fabs(ele_sclEta[iEle2])<1.4442 ) ) 
	      fidu[1] = 1 ;

	    if( cutEle[1]>0 && iEle2<=iEle1 ) continue; // prevents to create several times the same pair

	    if(debug) cout << "---> OK to form a pre-selected pair <--" << endl;

	    // get the pair informations
	    total = (*cand[0]) + (*cand[1]) ;

	    // keep only pairs with Mee > 30 GeV
	    if( total.M() < 30. ) continue; 

	    pair_M = total.M() ;

	    pairIdx.clear();
	    pairIdx.push_back(iEle1);
	    pairIdx.push_back(iEle2);

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

	      pair_cuts[iP] = cutEle[iP];
	      pair_fidu[iP] = fidu[iP];
	      pair_HLT_Ele27_cut[iP] = cut_HLT_Ele27[iP];
	      //
	      pair_eta[iP] = cand[iP]->Eta();
	      pair_sclEta[iP] = ele_sclEta[pairIdx[iP]];
	      pair_phi[iP] = cand[iP]->Phi();
	      pair_RCTeta[iP] = ele_RCTeta[pairIdx[iP]];
	      pair_RCTphi[iP] = ele_RCTphi[pairIdx[iP]];
	      //
	      pair_charge[iP] = ele_echarge[pairIdx[iP]];
	      pair_pT[iP] = cand[iP]->Pt();
	      pair_eT[iP] = cand[iP]->Et();
	      pair_sclEt[iP] = ele_sclEt[pairIdx[iP]];
	      pair_E[iP] = cand[iP]->E();
	      //
	      pair_L1iso[iP] = ele_RCTL1iso[pairIdx[iP]];
	      pair_L1noniso[iP] = ele_RCTL1noniso[pairIdx[iP]];
	      pair_L1iso_M[iP] = ele_RCTL1iso_M[pairIdx[iP]];
 	      pair_L1noniso_M[iP] = ele_RCTL1noniso_M[pairIdx[iP]];
	      //
	      for(int iV=0 ; iV<10 ; iV++) {
		pair_RCTetVect[iP][iV] = ele_RCTetVect[pairIdx[iP]][iV];
		pair_RCTetaVect[iP][iV] = ele_RCTetaVect[pairIdx[iP]][iV];
		pair_RCTphiVect[iP][iV] = ele_RCTphiVect[pairIdx[iP]][iV]; 
		pair_L1isoVect[iP][iV] = ele_RCTL1isoVect[pairIdx[iP]][iV]; 
		pair_L1nonisoVect[iP][iV] = ele_RCTL1nonisoVect[pairIdx[iP]][iV];
 		pair_L1isoVect_M[iP][iV] = ele_RCTL1isoVect_M[pairIdx[iP]][iV];
 		pair_L1nonisoVect_M[iP][iV] = ele_RCTL1nonisoVect_M[pairIdx[iP]][iV];
	      } 
	      //
	      for(int iV=0 ; iV<50 ; iV++) {
		pair_TTetaVect[iP][iV] = ele_TTetaVect[pairIdx[iP]][iV];
		pair_TTphiVect[iP][iV] = ele_TTphiVect[pairIdx[iP]][iV];
		pair_TTetVect[iP][iV] = ele_TTetVect[pairIdx[iP]][iV];
	      }
	    }
	    if(debug) cout << "outtree->Fill();" << endl;
	    outtree->Fill();

	  } // loop for probe
	} // endif ele1 is good tag candidate
      } // loop over electrons
     
    }//loop over events

  if(debug) cout << "End loop events" << endl;
  outlog << "End loop events" << endl;

  // Record tree
  if(debug) cout << "recording tree..." << endl;
  outlog << "recording tree..." << endl;

  outtree->Write();

  if(debug) cout << "recorded !" << endl;
  outlog << "recorded !" << endl;

  outfile->Close();

  if(debug) cout << "file closed." << endl;
  outlog << "file closed." << endl;

  return 1;

}
//Creates rootFile with a TTree with the ouput of MVA in it.
void MVAOutput(string Cat = "NoEleMatch_woGwoGSF_Barrel"
	       )
{
//   TChain *inputTree = new TChain("TrainTree");
  TChain *inputTree = new TChain("TestTree");
  TString pathToFile = "tmva/tmvaRoot/";
//   inputTree->Add(pathToFile+Form("/TMVA_v14EleVeto_%s.root",Cat.data()));
  inputTree->Add(pathToFile+Form("/V18/TMVA_v18EleVeto_%s.root",Cat.data()));
  if(inputTree->IsZombie()){
    cout<<"ZOOOOMBIEEE"<<endl;
    return;
  }

  int nEntries = inputTree->GetEntries();

//   std::string outputFileName = Form("/data_CMS/cms/ivo/AntiEMVANewTraining/MVAOutput/V14/MvaOutput_Test_%s.root",Cat.data());
  std::string outputFileName = Form("/data_CMS/cms/ivo/AntiEMVANewTraining/MVAOutput/V18/MvaOutput_All-TestTree_%s.root",Cat.data());
  
  TFile* outputFile = new TFile (outputFileName.data(),"RECREATE");
  TTree* mytree = new TTree("tree", "tree");

  float t_NoEleMatch_woGwoGSF_Barrel;
  float t_NoEleMatch_woGwGSF_Barrel;
  float t_NoEleMatch_wGwoGSF_Barrel;
  float t_NoEleMatch_wGwGSF_Barrel;
  float t_woGwoGSF_Barrel;
  float t_woGwGSF_Barrel;
  float t_wGwoGSF_Barrel;
  float t_wGwGSF_Barrel;
  float t_NoEleMatch_woGwoGSF_Endcap;
  float t_NoEleMatch_woGwGSF_Endcap;
  float t_NoEleMatch_wGwoGSF_Endcap;
  float t_NoEleMatch_wGwGSF_Endcap;
  float t_woGwoGSF_Endcap;
  float t_woGwGSF_Endcap;
  float t_wGwoGSF_Endcap;
  float t_wGwGSF_Endcap;

  int t_classID;

  mytree->Branch("NoEleMatch_woGwoGSF_Barrel",&t_NoEleMatch_woGwoGSF_Barrel,"NoEleMatch_woGwoGSF_Barrel/F");
  mytree->Branch("NoEleMatch_woGwGSF_Barrel",&t_NoEleMatch_woGwGSF_Barrel,"NoEleMatch_woGwGSF_Barrel/F");
  mytree->Branch("NoEleMatch_wGwoGSF_Barrel",&t_NoEleMatch_wGwoGSF_Barrel,"NoEleMatch_wGwoGSF_Barrel/F");
  mytree->Branch("NoEleMatch_wGwGSF_Barrel",&t_NoEleMatch_wGwGSF_Barrel,"NoEleMatch_wGwGSF_Barrel/F");
  mytree->Branch("woGwoGSF_Barrel",&t_woGwoGSF_Barrel,"woGwoGSF_Barrel/F");
  mytree->Branch("woGwGSF_Barrel",&t_woGwGSF_Barrel,"woGwGSF_Barrel/F");
  mytree->Branch("wGwoGSF_Barrel",&t_wGwoGSF_Barrel,"wGwoGSF_Barrel/F");
  mytree->Branch("wGwGSF_Barrel",&t_wGwGSF_Barrel,"wGwGSF_Barrel/F");
  mytree->Branch("NoEleMatch_woGwoGSF_Endcap",&t_NoEleMatch_woGwoGSF_Endcap,"NoEleMatch_woGwoGSF_Endcap/F");
  mytree->Branch("NoEleMatch_woGwGSF_Endcap",&t_NoEleMatch_woGwGSF_Endcap,"NoEleMatch_woGwGSF_Endcap/F");
  mytree->Branch("NoEleMatch_wGwoGSF_Endcap",&t_NoEleMatch_wGwoGSF_Endcap,"NoEleMatch_wGwoGSF_Endcap/F");
  mytree->Branch("NoEleMatch_wGwGSF_Endcap",&t_NoEleMatch_wGwGSF_Endcap,"NoEleMatch_wGwGSF_Endcap/F");
  mytree->Branch("woGwoGSF_Endcap",&t_woGwoGSF_Endcap,"woGwoGSF_Endcap/F");
  mytree->Branch("woGwGSF_Endcap",&t_woGwGSF_Endcap,"woGwGSF_Endcap/F");
  mytree->Branch("wGwoGSF_Endcap",&t_wGwoGSF_Endcap,"wGwoGSF_Endcap/F");
  mytree->Branch("wGwGSF_Endcap",&t_wGwGSF_Endcap,"wGwGSF_Endcap/F");

  mytree->Branch("classID",&t_classID,"classID/I");

//   float Tau_EtaAtEcalEntrance;
//   float Tau_Pt;
//   float Tau_EmFraction; 
//   float Tau_HadrHoP; 
//   float Tau_HadrEoP; 
//   float Tau_VisMass; 
  float Tau_dCrackPhi;
  float Tau_dCrackEta;
//   float Tau_DecayMode; 
  float Tau_NumHitsVariable;

//   //PFTaus variables

  inputTree->SetBranchAddress("Tau_dCrackEta", &Tau_dCrackEta); 
  inputTree->SetBranchAddress("Tau_dCrackPhi", &Tau_dCrackPhi); 
  inputTree->SetBranchAddress("_Tau_GSFNumHits_M_Tau_KFNumHits__D__Tau_GSFNumHits_P_Tau_KFNumHits_", &Tau_NumHitsVariable); 


  int Tau_GsfEleMatch;
  int Tau_GenEleMatch;
  int Tau_GenEleFromZMatch;
  int Tau_GenEleFromZTauTauMatch;
  int Tau_GenHadMatch;
  int Tau_GenJetMatch;
//   float Tau_AbsEta;
  float Tau_Eta;
  float Tau_EtaAtEcalEntrance;
  float Tau_PhiAtEcalEntrance;
  float Tau_Pt;
  float Tau_KFNumHits; 
  float Tau_HasGsf; 
  float Tau_GSFChi2; 
  float Tau_GSFNumHits; 
  float Tau_GSFTrackResol; 
  float Tau_GSFTracklnPt; 
  float Tau_GSFTrackEta; 
  float Tau_EmFraction; 
  float Tau_NumChargedCands;
  float Tau_NumGammaCands; 
  float Tau_HadrHoP; 
  float Tau_HadrEoP; 
  float Tau_VisMass; 
  float Tau_GammaEtaMom;
  float Tau_GammaPhiMom;
  float Tau_GammaEnFrac;
  float Tau_HadrMva; 
//   float Tau_IsoMVALoose; 
  float Tau_LooseComb3HitsIso; 
  float Tau_AntiELoose; 
  float Tau_AntiEMedium; 
  float Tau_AntiETight; 
  float Tau_AntiELooseMVA3; 
  float Tau_AntiEMediumMVA3; 
  float Tau_AntiETightMVA3; 
  float Tau_AntiEVTightMVA3; 
  float Tau_MatchElePassVeto; 
  float Tau_DecayMode; 


  float Elec_AbsEta;
  float Elec_Pt;
  float Elec_HasSC;
  float Elec_PFMvaOutput;
  float Elec_EtotOverPin;
  float Elec_EeOverPout;
  float Elec_EgammaOverPdif;
  int Elec_EarlyBrem;//
  int Elec_LateBrem;//
  float Elec_Logsihih;
  float Elec_DeltaEta;
  float Elec_HoHplusE;
  float Elec_Fbrem;
  float Elec_HasGSF;
  float Elec_Chi2GSF;
  float Elec_GSFNumHits;
  float Elec_GSFTrackResol;
  float Elec_GSFTracklnPt;
  float Elec_GSFTrackEta;

  float ElecVeto_Pt;

  int classID;


  //GsfElectron variables

  inputTree->SetBranchAddress("Elec_AbsEta", &Elec_AbsEta);
  inputTree->SetBranchAddress("Elec_Pt", &Elec_Pt);
  inputTree->SetBranchAddress("Elec_HasSC", &Elec_HasSC);
  inputTree->SetBranchAddress("Elec_PFMvaOutput", &Elec_PFMvaOutput);
  inputTree->SetBranchAddress("Elec_EtotOverPin", &Elec_EtotOverPin);
  inputTree->SetBranchAddress("Elec_EeOverPout", &Elec_EeOverPout);
  inputTree->SetBranchAddress("Elec_EgammaOverPdif", &Elec_EgammaOverPdif);
  inputTree->SetBranchAddress("Elec_EarlyBrem", &Elec_EarlyBrem);
  inputTree->SetBranchAddress("Elec_LateBrem", &Elec_LateBrem);
  inputTree->SetBranchAddress("Elec_Logsihih", &Elec_Logsihih);
  inputTree->SetBranchAddress("Elec_DeltaEta", &Elec_DeltaEta);
  inputTree->SetBranchAddress("Elec_HoHplusE", &Elec_HoHplusE);
  inputTree->SetBranchAddress("Elec_Fbrem", &Elec_Fbrem);
  inputTree->SetBranchAddress("Elec_HasGSF", &Elec_HasGSF);
  inputTree->SetBranchAddress("Elec_Chi2GSF", &Elec_Chi2GSF);
  inputTree->SetBranchAddress("Elec_GSFNumHits", &Elec_GSFNumHits);
  inputTree->SetBranchAddress("Elec_GSFTrackResol", &Elec_GSFTrackResol);
  inputTree->SetBranchAddress("Elec_GSFTracklnPt", &Elec_GSFTracklnPt);
  inputTree->SetBranchAddress("Elec_GSFTrackEta", &Elec_GSFTrackEta);


  //PFTaus variables

  inputTree->SetBranchAddress("Tau_GsfEleMatch", &Tau_GsfEleMatch);
  inputTree->SetBranchAddress("Tau_GenEleMatch", &Tau_GenEleMatch);
  inputTree->SetBranchAddress("Tau_GenEleFromZMatch", &Tau_GenEleFromZMatch);
  inputTree->SetBranchAddress("Tau_GenEleFromZTauTauMatch", &Tau_GenEleFromZTauTauMatch);
  inputTree->SetBranchAddress("Tau_GenHadMatch", &Tau_GenHadMatch);
  inputTree->SetBranchAddress("Tau_GenJetMatch", &Tau_GenJetMatch);
  inputTree->SetBranchAddress("Tau_EtaAtEcalEntrance", &Tau_EtaAtEcalEntrance);
  inputTree->SetBranchAddress("Tau_PhiAtEcalEntrance", &Tau_PhiAtEcalEntrance);
  inputTree->SetBranchAddress("Tau_Pt", &Tau_Pt);
  inputTree->SetBranchAddress("Tau_Eta", &Tau_Eta);
  inputTree->SetBranchAddress("Tau_HasGsf", &Tau_HasGsf); 
  inputTree->SetBranchAddress("Tau_GSFChi2", &Tau_GSFChi2);
  inputTree->SetBranchAddress("Tau_GSFNumHits", &Tau_GSFNumHits);
  inputTree->SetBranchAddress("Tau_GSFTrackResol", &Tau_GSFTrackResol);
  inputTree->SetBranchAddress("Tau_GSFTracklnPt", &Tau_GSFTracklnPt);
  inputTree->SetBranchAddress("Tau_GSFTrackEta", &Tau_GSFTrackEta);
  inputTree->SetBranchAddress("Tau_KFNumHits", &Tau_KFNumHits);
  inputTree->SetBranchAddress("Tau_EmFraction", &Tau_EmFraction); 
  inputTree->SetBranchAddress("Tau_NumChargedCands", &Tau_NumChargedCands);
  inputTree->SetBranchAddress("Tau_NumGammaCands", &Tau_NumGammaCands); 
  inputTree->SetBranchAddress("Tau_HadrHoP", &Tau_HadrHoP); 
  inputTree->SetBranchAddress("Tau_HadrEoP", &Tau_HadrEoP); 
  inputTree->SetBranchAddress("Tau_VisMass", &Tau_VisMass); 
  inputTree->SetBranchAddress("Tau_GammaEtaMom", &Tau_GammaEtaMom);
  inputTree->SetBranchAddress("Tau_GammaPhiMom", &Tau_GammaPhiMom);
  inputTree->SetBranchAddress("Tau_GammaEnFrac", &Tau_GammaEnFrac);
  inputTree->SetBranchAddress("Tau_HadrMva", &Tau_HadrMva);  
//   inputTree->SetBranchAddress("Tau_IsoMVALoose", &Tau_IsoMVALoose); 
  inputTree->SetBranchAddress("Tau_LooseComb3HitsIso", &Tau_LooseComb3HitsIso); 
  inputTree->SetBranchAddress("Tau_AntiELoose", &Tau_AntiELoose); 
  inputTree->SetBranchAddress("Tau_AntiEMedium", &Tau_AntiEMedium); 
  inputTree->SetBranchAddress("Tau_AntiETight", &Tau_AntiETight); 
  inputTree->SetBranchAddress("Tau_AntiELooseMVA3", &Tau_AntiELooseMVA3); 
  inputTree->SetBranchAddress("Tau_AntiEMediumMVA3", &Tau_AntiEMediumMVA3); 
  inputTree->SetBranchAddress("Tau_AntiETightMVA3", &Tau_AntiETightMVA3); 
  inputTree->SetBranchAddress("Tau_AntiEVTightMVA3", &Tau_AntiEVTightMVA3); 

  inputTree->SetBranchAddress("ElecVeto_Pt",&ElecVeto_Pt);

  inputTree->SetBranchAddress("Tau_DecayMode", &Tau_DecayMode); 
  inputTree->SetBranchAddress("Tau_MatchElePassVeto", &Tau_MatchElePassVeto); 

  inputTree->SetBranchAddress("classID", &classID); 

  inputTree->SetBranchStatus("*", 1);

//   string Weight_NoEleMatch_woGwoGSF_BL = "tmva/weights/V14/TMVAClassification_v14EleVeto_NoEleMatch_woGwoGSF_Barrel_BDTG.weights.xml";
//   string Weight_NoEleMatch_woGwGSF_BL = "tmva/weights/V14/TMVAClassification_v14EleVeto_NoEleMatch_woGwGSF_Barrel_BDTG.weights.xml";
//   string Weight_NoEleMatch_wGwoGSF_BL = "tmva/weights/V14/TMVAClassification_v14EleVeto_NoEleMatch_wGwoGSF_Barrel_BDTG.weights.xml";
//   string Weight_NoEleMatch_wGwGSF_BL = "tmva/weights/V14/TMVAClassification_v14EleVeto_NoEleMatch_wGwGSF_Barrel_BDTG.weights.xml";
//   string Weight_woGwoGSF_BL = "tmva/weights/V14/TMVAClassification_v14EleVeto_woGwoGSF_Barrel_BDTG.weights.xml";
//   string Weight_woGwGSF_BL = "tmva/weights/V14/TMVAClassification_v14EleVeto_woGwGSF_Barrel_BDTG.weights.xml";
//   string Weight_wGwoGSF_BL = "tmva/weights/V14/TMVAClassification_v14EleVeto_wGwoGSF_Barrel_BDTG.weights.xml";
//   string Weight_wGwGSF_BL = "tmva/weights/V14/TMVAClassification_v14EleVeto_wGwGSF_Barrel_BDTG.weights.xml";
//   string Weight_NoEleMatch_woGwoGSF_EC = "tmva/weights/V14/TMVAClassification_v14EleVeto_NoEleMatch_woGwoGSF_Endcap_BDTG.weights.xml";
//   string Weight_NoEleMatch_woGwGSF_EC = "tmva/weights/V14/TMVAClassification_v14EleVeto_NoEleMatch_woGwGSF_Endcap_BDTG.weights.xml";
//   string Weight_NoEleMatch_wGwoGSF_EC = "tmva/weights/V14/TMVAClassification_v14EleVeto_NoEleMatch_wGwoGSF_Endcap_BDTG.weights.xml";
//   string Weight_NoEleMatch_wGwGSF_EC = "tmva/weights/V14/TMVAClassification_v14EleVeto_NoEleMatch_wGwGSF_Endcap_BDTG.weights.xml";
//   string Weight_woGwoGSF_EC = "tmva/weights/V14/TMVAClassification_v14EleVeto_woGwoGSF_Endcap_BDTG.weights.xml";
//   string Weight_woGwGSF_EC = "tmva/weights/V14/TMVAClassification_v14EleVeto_woGwGSF_Endcap_BDTG.weights.xml";
//   string Weight_wGwoGSF_EC = "tmva/weights/V14/TMVAClassification_v14EleVeto_wGwoGSF_Endcap_BDTG.weights.xml";
//   string Weight_wGwGSF_EC = "tmva/weights/V14/TMVAClassification_v14EleVeto_wGwGSF_Endcap_BDTG.weights.xml";

  string Weight_NoEleMatch_woGwoGSF_BL = "tmva/weights/V18/TMVAClassification_v18EleVeto_NoEleMatch_woGwoGSF_Barrel_BDTG.weights.xml";
  string Weight_NoEleMatch_woGwGSF_BL = "tmva/weights/V18/TMVAClassification_v18EleVeto_NoEleMatch_woGwGSF_Barrel_BDTG.weights.xml";
  string Weight_NoEleMatch_wGwoGSF_BL = "tmva/weights/V18/TMVAClassification_v18EleVeto_NoEleMatch_wGwoGSF_Barrel_BDTG.weights.xml";
  string Weight_NoEleMatch_wGwGSF_BL = "tmva/weights/V18/TMVAClassification_v18EleVeto_NoEleMatch_wGwGSF_Barrel_BDTG.weights.xml";
  string Weight_woGwoGSF_BL = "tmva/weights/V18/TMVAClassification_v18EleVeto_woGwoGSF_Barrel_BDTG.weights.xml";
  string Weight_woGwGSF_BL = "tmva/weights/V18/TMVAClassification_v18EleVeto_woGwGSF_Barrel_BDTG.weights.xml";
  string Weight_wGwoGSF_BL = "tmva/weights/V18/TMVAClassification_v18EleVeto_wGwoGSF_Barrel_BDTG.weights.xml";
  string Weight_wGwGSF_BL = "tmva/weights/V18/TMVAClassification_v18EleVeto_wGwGSF_Barrel_BDTG.weights.xml";
  string Weight_NoEleMatch_woGwoGSF_EC = "tmva/weights/V18/TMVAClassification_v18EleVeto_NoEleMatch_woGwoGSF_Endcap_BDTG.weights.xml";
  string Weight_NoEleMatch_woGwGSF_EC = "tmva/weights/V18/TMVAClassification_v18EleVeto_NoEleMatch_woGwGSF_Endcap_BDTG.weights.xml";
  string Weight_NoEleMatch_wGwoGSF_EC = "tmva/weights/V18/TMVAClassification_v18EleVeto_NoEleMatch_wGwoGSF_Endcap_BDTG.weights.xml";
  string Weight_NoEleMatch_wGwGSF_EC = "tmva/weights/V18/TMVAClassification_v18EleVeto_NoEleMatch_wGwGSF_Endcap_BDTG.weights.xml";
  string Weight_woGwoGSF_EC = "tmva/weights/V18/TMVAClassification_v18EleVeto_woGwoGSF_Endcap_BDTG.weights.xml";
  string Weight_woGwGSF_EC = "tmva/weights/V18/TMVAClassification_v18EleVeto_woGwGSF_Endcap_BDTG.weights.xml";
  string Weight_wGwoGSF_EC = "tmva/weights/V18/TMVAClassification_v18EleVeto_wGwoGSF_Endcap_BDTG.weights.xml";
  string Weight_wGwGSF_EC = "tmva/weights/V18/TMVAClassification_v18EleVeto_wGwGSF_Endcap_BDTG.weights.xml";

  TMVA::Reader *reader_NoEleMatch_woGwoGSF_BL = new TMVA::Reader( "!Color:!Silent:Error" );  
  reader_NoEleMatch_woGwoGSF_BL->AddVariable("Tau_EtaAtEcalEntrance",&Tau_EtaAtEcalEntrance);
  reader_NoEleMatch_woGwoGSF_BL->AddVariable("Tau_Pt",&Tau_Pt);
  reader_NoEleMatch_woGwoGSF_BL->AddVariable("Tau_EmFraction",&Tau_EmFraction);
  reader_NoEleMatch_woGwoGSF_BL->AddVariable("Tau_HadrHoP",&Tau_HadrHoP);
  reader_NoEleMatch_woGwoGSF_BL->AddVariable("Tau_HadrEoP",&Tau_HadrEoP);
  reader_NoEleMatch_woGwoGSF_BL->AddVariable("Tau_VisMass",&Tau_VisMass);
  reader_NoEleMatch_woGwoGSF_BL->AddVariable("Tau_dCrackEta",&Tau_dCrackEta);
  reader_NoEleMatch_woGwoGSF_BL->AddVariable("Tau_dCrackPhi",&Tau_dCrackPhi);
//   reader_NoEleMatch_woGwoGSF_BL->AddVariable("Tau_DecayMode",&Tau_DecayMode);
  reader_NoEleMatch_woGwoGSF_BL->SetVerbose(kTRUE);
  reader_NoEleMatch_woGwoGSF_BL->BookMVA("BDTG",Weight_NoEleMatch_woGwoGSF_BL);


  TMVA::Reader *reader_NoEleMatch_woGwGSF_BL = new TMVA::Reader( "!Color:!Silent:Error" );  
  reader_NoEleMatch_woGwGSF_BL->AddVariable("Tau_EtaAtEcalEntrance",&Tau_EtaAtEcalEntrance);
  reader_NoEleMatch_woGwGSF_BL->AddVariable("Tau_Pt",&Tau_Pt);
  reader_NoEleMatch_woGwGSF_BL->AddVariable("Tau_EmFraction",&Tau_EmFraction);
  reader_NoEleMatch_woGwGSF_BL->AddVariable("Tau_HadrHoP",&Tau_HadrHoP);
  reader_NoEleMatch_woGwGSF_BL->AddVariable("Tau_HadrEoP",&Tau_HadrEoP);
  reader_NoEleMatch_woGwGSF_BL->AddVariable("Tau_VisMass",&Tau_VisMass);
  reader_NoEleMatch_woGwGSF_BL->AddVariable("Tau_HadrMva",&Tau_HadrMva);
  reader_NoEleMatch_woGwGSF_BL->AddVariable("Tau_GSFChi2",&Tau_GSFChi2);
  reader_NoEleMatch_woGwGSF_BL->AddVariable("(Tau_GSFNumHits - Tau_KFNumHits)/(Tau_GSFNumHits + Tau_KFNumHits)",&Tau_NumHitsVariable);
  reader_NoEleMatch_woGwGSF_BL->AddVariable("Tau_GSFTrackResol",&Tau_GSFTrackResol);
  reader_NoEleMatch_woGwGSF_BL->AddVariable("Tau_GSFTracklnPt",&Tau_GSFTracklnPt);
  reader_NoEleMatch_woGwGSF_BL->AddVariable("Tau_GSFTrackEta",&Tau_GSFTrackEta);
  reader_NoEleMatch_woGwGSF_BL->AddVariable("Tau_dCrackEta",&Tau_dCrackEta);
  reader_NoEleMatch_woGwGSF_BL->AddVariable("Tau_dCrackPhi",&Tau_dCrackPhi);
//   reader_NoEleMatch_woGwGSF_BL->AddVariable("Tau_DecayMode",&Tau_DecayMode);
  reader_NoEleMatch_woGwGSF_BL->SetVerbose(kTRUE);
  reader_NoEleMatch_woGwGSF_BL->BookMVA("BDTG",Weight_NoEleMatch_woGwGSF_BL);

  TMVA::Reader *reader_NoEleMatch_wGwoGSF_BL = new TMVA::Reader( "!Color:!Silent:Error" );  
  reader_NoEleMatch_wGwoGSF_BL->AddVariable("Tau_EtaAtEcalEntrance",&Tau_EtaAtEcalEntrance);
  reader_NoEleMatch_wGwoGSF_BL->AddVariable("Tau_Pt",&Tau_Pt);
  reader_NoEleMatch_wGwoGSF_BL->AddVariable("Tau_EmFraction",&Tau_EmFraction);
  reader_NoEleMatch_wGwoGSF_BL->AddVariable("Tau_NumGammaCands",&Tau_NumGammaCands);
  reader_NoEleMatch_wGwoGSF_BL->AddVariable("Tau_HadrHoP",&Tau_HadrHoP);
  reader_NoEleMatch_wGwoGSF_BL->AddVariable("Tau_HadrEoP",&Tau_HadrEoP);
  reader_NoEleMatch_wGwoGSF_BL->AddVariable("Tau_VisMass",&Tau_VisMass);
  reader_NoEleMatch_wGwoGSF_BL->AddVariable("Tau_GammaEtaMom",&Tau_GammaEtaMom);
  reader_NoEleMatch_wGwoGSF_BL->AddVariable("Tau_GammaPhiMom",&Tau_GammaPhiMom);
  reader_NoEleMatch_wGwoGSF_BL->AddVariable("Tau_GammaEnFrac",&Tau_GammaEnFrac);
  reader_NoEleMatch_wGwoGSF_BL->AddVariable("Tau_dCrackEta",&Tau_dCrackEta);
  reader_NoEleMatch_wGwoGSF_BL->AddVariable("Tau_dCrackPhi",&Tau_dCrackPhi);
//   reader_NoEleMatch_wGwoGSF_BL->AddVariable("Tau_DecayMode",&Tau_DecayMode);
  reader_NoEleMatch_wGwoGSF_BL->SetVerbose(kTRUE);
  reader_NoEleMatch_wGwoGSF_BL->BookMVA("BDTG",Weight_NoEleMatch_wGwoGSF_BL);

  TMVA::Reader *reader_NoEleMatch_wGwGSF_BL = new TMVA::Reader( "!Color:!Silent:Error" );  
  reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_EtaAtEcalEntrance",&Tau_EtaAtEcalEntrance);
  reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_Pt",&Tau_Pt);
  reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_EmFraction",&Tau_EmFraction);
  reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_NumGammaCands",&Tau_NumGammaCands);
  reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_HadrHoP",&Tau_HadrHoP);
  reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_HadrEoP",&Tau_HadrEoP);
  reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_VisMass",&Tau_VisMass);
  reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_HadrMva",&Tau_HadrMva);
  reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_GammaEtaMom",&Tau_GammaEtaMom);
  reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_GammaPhiMom",&Tau_GammaPhiMom);
  reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_GammaEnFrac",&Tau_GammaEnFrac);
  reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_GSFChi2",&Tau_GSFChi2);
  reader_NoEleMatch_wGwGSF_BL->AddVariable("(Tau_GSFNumHits - Tau_KFNumHits)/(Tau_GSFNumHits + Tau_KFNumHits)",&Tau_NumHitsVariable);
  reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_GSFTrackResol",&Tau_GSFTrackResol);
  reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_GSFTracklnPt",&Tau_GSFTracklnPt);
  reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_GSFTrackEta",&Tau_GSFTrackEta);
  reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_dCrackEta",&Tau_dCrackEta);
  reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_dCrackPhi",&Tau_dCrackPhi);
//   reader_NoEleMatch_wGwGSF_BL->AddVariable("Tau_DecayMode",&Tau_DecayMode);
  reader_NoEleMatch_wGwGSF_BL->SetVerbose(kTRUE);
  reader_NoEleMatch_wGwGSF_BL->BookMVA("BDTG",Weight_NoEleMatch_wGwGSF_BL);

  TMVA::Reader *reader_woGwoGSF_BL = new TMVA::Reader( "!Color:!Silent:Error" );
  reader_woGwoGSF_BL->AddVariable("Elec_EtotOverPin",&Elec_EtotOverPin);
  reader_woGwoGSF_BL->AddVariable("Elec_EgammaOverPdif",&Elec_EgammaOverPdif);
  reader_woGwoGSF_BL->AddVariable("Elec_Fbrem",&Elec_Fbrem);
  reader_woGwoGSF_BL->AddVariable("Elec_Chi2GSF",&Elec_Chi2GSF);
  reader_woGwoGSF_BL->AddVariable("Elec_GSFNumHits",&Elec_GSFNumHits);
  reader_woGwoGSF_BL->AddVariable("Elec_GSFTrackResol",&Elec_GSFTrackResol);
  reader_woGwoGSF_BL->AddVariable("Elec_GSFTracklnPt",&Elec_GSFTracklnPt);
  reader_woGwoGSF_BL->AddVariable("Elec_GSFTrackEta",&Elec_GSFTrackEta);
  reader_woGwoGSF_BL->AddVariable("Tau_EtaAtEcalEntrance",&Tau_EtaAtEcalEntrance);
  reader_woGwoGSF_BL->AddVariable("Tau_Pt",&Tau_Pt);
  reader_woGwoGSF_BL->AddVariable("Tau_EmFraction",&Tau_EmFraction);
  reader_woGwoGSF_BL->AddVariable("Tau_HadrHoP",&Tau_HadrHoP);
  reader_woGwoGSF_BL->AddVariable("Tau_HadrEoP",&Tau_HadrEoP);
  reader_woGwoGSF_BL->AddVariable("Tau_VisMass",&Tau_VisMass);
  reader_woGwoGSF_BL->AddVariable("Tau_dCrackEta",&Tau_dCrackEta);
  reader_woGwoGSF_BL->AddVariable("Tau_dCrackPhi",&Tau_dCrackPhi);
//   reader_woGwoGSF_BL->AddVariable("Tau_DecayMode",&Tau_DecayMode);
  reader_woGwoGSF_BL->SetVerbose(kTRUE);
  reader_woGwoGSF_BL->BookMVA("BDTG",Weight_woGwoGSF_BL);

  TMVA::Reader *reader_woGwGSF_BL = new TMVA::Reader( "!Color:!Silent:Error" );  
  reader_woGwGSF_BL->AddVariable("Elec_EtotOverPin",&Elec_EtotOverPin);
  reader_woGwGSF_BL->AddVariable("Elec_EgammaOverPdif",&Elec_EgammaOverPdif);
  reader_woGwGSF_BL->AddVariable("Elec_Fbrem",&Elec_Fbrem);
  reader_woGwGSF_BL->AddVariable("Elec_Chi2GSF",&Elec_Chi2GSF);
  reader_woGwGSF_BL->AddVariable("Elec_GSFNumHits",&Elec_GSFNumHits);
  reader_woGwGSF_BL->AddVariable("Elec_GSFTrackResol",&Elec_GSFTrackResol);
  reader_woGwGSF_BL->AddVariable("Elec_GSFTracklnPt",&Elec_GSFTracklnPt);
  reader_woGwGSF_BL->AddVariable("Elec_GSFTrackEta",&Elec_GSFTrackEta);
  reader_woGwGSF_BL->AddVariable("Tau_EtaAtEcalEntrance",&Tau_EtaAtEcalEntrance);
  reader_woGwGSF_BL->AddVariable("Tau_Pt",&Tau_Pt);
  reader_woGwGSF_BL->AddVariable("Tau_EmFraction",&Tau_EmFraction);
  reader_woGwGSF_BL->AddVariable("Tau_HadrHoP",&Tau_HadrHoP);
  reader_woGwGSF_BL->AddVariable("Tau_HadrEoP",&Tau_HadrEoP);
  reader_woGwGSF_BL->AddVariable("Tau_VisMass",&Tau_VisMass);
  reader_woGwGSF_BL->AddVariable("Tau_HadrMva",&Tau_HadrMva);
  reader_woGwGSF_BL->AddVariable("Tau_GSFChi2",&Tau_GSFChi2);
  reader_woGwGSF_BL->AddVariable("(Tau_GSFNumHits - Tau_KFNumHits)/(Tau_GSFNumHits + Tau_KFNumHits)",&Tau_NumHitsVariable);
  reader_woGwGSF_BL->AddVariable("Tau_GSFTrackResol",&Tau_GSFTrackResol);
  reader_woGwGSF_BL->AddVariable("Tau_GSFTracklnPt",&Tau_GSFTracklnPt);
  reader_woGwGSF_BL->AddVariable("Tau_GSFTrackEta",&Tau_GSFTrackEta);
  reader_woGwGSF_BL->AddVariable("Tau_dCrackEta",&Tau_dCrackEta);
  reader_woGwGSF_BL->AddVariable("Tau_dCrackPhi",&Tau_dCrackPhi);
//   reader_woGwGSF_BL->AddVariable("Tau_DecayMode",&Tau_DecayMode);
  reader_woGwGSF_BL->SetVerbose(kTRUE);
  reader_woGwGSF_BL->BookMVA("BDTG",Weight_woGwGSF_BL);

  TMVA::Reader *reader_wGwoGSF_BL = new TMVA::Reader( "!Color:!Silent:Error" );  
  reader_wGwoGSF_BL->AddVariable("Elec_EtotOverPin",&Elec_EtotOverPin);
  reader_wGwoGSF_BL->AddVariable("Elec_EgammaOverPdif",&Elec_EgammaOverPdif);
  reader_wGwoGSF_BL->AddVariable("Elec_Fbrem",&Elec_Fbrem);
  reader_wGwoGSF_BL->AddVariable("Elec_Chi2GSF",&Elec_Chi2GSF);
  reader_wGwoGSF_BL->AddVariable("Elec_GSFNumHits",&Elec_GSFNumHits);
  reader_wGwoGSF_BL->AddVariable("Elec_GSFTrackResol",&Elec_GSFTrackResol);
  reader_wGwoGSF_BL->AddVariable("Elec_GSFTracklnPt",&Elec_GSFTracklnPt);
  reader_wGwoGSF_BL->AddVariable("Elec_GSFTrackEta",&Elec_GSFTrackEta);
  reader_wGwoGSF_BL->AddVariable("Tau_EtaAtEcalEntrance",&Tau_EtaAtEcalEntrance);
  reader_wGwoGSF_BL->AddVariable("Tau_Pt",&Tau_Pt);
  reader_wGwoGSF_BL->AddVariable("Tau_EmFraction",&Tau_EmFraction);
  reader_wGwoGSF_BL->AddVariable("Tau_NumGammaCands",&Tau_NumGammaCands);
  reader_wGwoGSF_BL->AddVariable("Tau_HadrHoP",&Tau_HadrHoP);
  reader_wGwoGSF_BL->AddVariable("Tau_HadrEoP",&Tau_HadrEoP);
  reader_wGwoGSF_BL->AddVariable("Tau_VisMass",&Tau_VisMass);
  reader_wGwoGSF_BL->AddVariable("Tau_GammaEtaMom",&Tau_GammaEtaMom);
  reader_wGwoGSF_BL->AddVariable("Tau_GammaPhiMom",&Tau_GammaPhiMom);
  reader_wGwoGSF_BL->AddVariable("Tau_GammaEnFrac",&Tau_GammaEnFrac);
  reader_wGwoGSF_BL->AddVariable("Tau_dCrackEta",&Tau_dCrackEta);
  reader_wGwoGSF_BL->AddVariable("Tau_dCrackPhi",&Tau_dCrackPhi);
//   reader_wGwoGSF_BL->AddVariable("Tau_DecayMode",&Tau_DecayMode);
  reader_wGwoGSF_BL->SetVerbose(kTRUE);
  reader_wGwoGSF_BL->BookMVA("BDTG",Weight_wGwoGSF_BL);

  TMVA::Reader *reader_wGwGSF_BL = new TMVA::Reader( "!Color:!Silent:Error" );  
  reader_wGwGSF_BL->AddVariable("Elec_EtotOverPin",&Elec_EtotOverPin);
  reader_wGwGSF_BL->AddVariable("Elec_EgammaOverPdif",&Elec_EgammaOverPdif);
  reader_wGwGSF_BL->AddVariable("Elec_Fbrem",&Elec_Fbrem);
  reader_wGwGSF_BL->AddVariable("Elec_Chi2GSF",&Elec_Chi2GSF);
  reader_wGwGSF_BL->AddVariable("Elec_GSFNumHits",&Elec_GSFNumHits);
  reader_wGwGSF_BL->AddVariable("Elec_GSFTrackResol",&Elec_GSFTrackResol);
  reader_wGwGSF_BL->AddVariable("Elec_GSFTracklnPt",&Elec_GSFTracklnPt);
  reader_wGwGSF_BL->AddVariable("Elec_GSFTrackEta",&Elec_GSFTrackEta);
  reader_wGwGSF_BL->AddVariable("Tau_EtaAtEcalEntrance",&Tau_EtaAtEcalEntrance);
  reader_wGwGSF_BL->AddVariable("Tau_Pt",&Tau_Pt);
  reader_wGwGSF_BL->AddVariable("Tau_EmFraction",&Tau_EmFraction);
  reader_wGwGSF_BL->AddVariable("Tau_NumGammaCands",&Tau_NumGammaCands);
  reader_wGwGSF_BL->AddVariable("Tau_HadrHoP",&Tau_HadrHoP);
  reader_wGwGSF_BL->AddVariable("Tau_HadrEoP",&Tau_HadrEoP);
  reader_wGwGSF_BL->AddVariable("Tau_VisMass",&Tau_VisMass);
  reader_wGwGSF_BL->AddVariable("Tau_HadrMva",&Tau_HadrMva);
  reader_wGwGSF_BL->AddVariable("Tau_GammaEtaMom",&Tau_GammaEtaMom);
  reader_wGwGSF_BL->AddVariable("Tau_GammaPhiMom",&Tau_GammaPhiMom);
  reader_wGwGSF_BL->AddVariable("Tau_GammaEnFrac",&Tau_GammaEnFrac);
  reader_wGwGSF_BL->AddVariable("Tau_GSFChi2",&Tau_GSFChi2);
  reader_wGwGSF_BL->AddVariable("(Tau_GSFNumHits - Tau_KFNumHits)/(Tau_GSFNumHits + Tau_KFNumHits)",&Tau_NumHitsVariable);
  reader_wGwGSF_BL->AddVariable("Tau_GSFTrackResol",&Tau_GSFTrackResol);
  reader_wGwGSF_BL->AddVariable("Tau_GSFTracklnPt",&Tau_GSFTracklnPt);
  reader_wGwGSF_BL->AddVariable("Tau_GSFTrackEta",&Tau_GSFTrackEta);
  reader_wGwGSF_BL->AddVariable("Tau_dCrackEta",&Tau_dCrackEta);
  reader_wGwGSF_BL->AddVariable("Tau_dCrackPhi",&Tau_dCrackPhi);
//   reader_wGwGSF_BL->AddVariable("Tau_DecayMode",&Tau_DecayMode);
  reader_wGwGSF_BL->SetVerbose(kTRUE);
  reader_wGwGSF_BL->BookMVA("BDTG",Weight_wGwGSF_BL);

  ////////////////////////

  TMVA::Reader *reader_NoEleMatch_woGwoGSF_EC = new TMVA::Reader( "!Color:!Silent:Error" );  
  reader_NoEleMatch_woGwoGSF_EC->AddVariable("Tau_EtaAtEcalEntrance",&Tau_EtaAtEcalEntrance);
  reader_NoEleMatch_woGwoGSF_EC->AddVariable("Tau_Pt",&Tau_Pt);
  reader_NoEleMatch_woGwoGSF_EC->AddVariable("Tau_EmFraction",&Tau_EmFraction);
  reader_NoEleMatch_woGwoGSF_EC->AddVariable("Tau_HadrHoP",&Tau_HadrHoP);
  reader_NoEleMatch_woGwoGSF_EC->AddVariable("Tau_HadrEoP",&Tau_HadrEoP);
  reader_NoEleMatch_woGwoGSF_EC->AddVariable("Tau_VisMass",&Tau_VisMass);
  reader_NoEleMatch_woGwoGSF_EC->AddVariable("Tau_dCrackEta",&Tau_dCrackEta);
//   reader_NoEleMatch_woGwoGSF_EC->AddVariable("Tau_DecayMode",&Tau_DecayMode);
  reader_NoEleMatch_woGwoGSF_EC->SetVerbose(kTRUE);
  reader_NoEleMatch_woGwoGSF_EC->BookMVA("BDTG",Weight_NoEleMatch_woGwoGSF_EC);

  TMVA::Reader *reader_NoEleMatch_woGwGSF_EC = new TMVA::Reader( "!Color:!Silent:Error" );  
  reader_NoEleMatch_woGwGSF_EC->AddVariable("Tau_EtaAtEcalEntrance",&Tau_EtaAtEcalEntrance);
  reader_NoEleMatch_woGwGSF_EC->AddVariable("Tau_Pt",&Tau_Pt);
  reader_NoEleMatch_woGwGSF_EC->AddVariable("Tau_EmFraction",&Tau_EmFraction);
  reader_NoEleMatch_woGwGSF_EC->AddVariable("Tau_HadrHoP",&Tau_HadrHoP);
  reader_NoEleMatch_woGwGSF_EC->AddVariable("Tau_HadrEoP",&Tau_HadrEoP);
  reader_NoEleMatch_woGwGSF_EC->AddVariable("Tau_VisMass",&Tau_VisMass);
  reader_NoEleMatch_woGwGSF_EC->AddVariable("Tau_HadrMva",&Tau_HadrMva);
  reader_NoEleMatch_woGwGSF_EC->AddVariable("Tau_GSFChi2",&Tau_GSFChi2);
  reader_NoEleMatch_woGwGSF_EC->AddVariable("(Tau_GSFNumHits - Tau_KFNumHits)/(Tau_GSFNumHits + Tau_KFNumHits)",&Tau_NumHitsVariable);
  reader_NoEleMatch_woGwGSF_EC->AddVariable("Tau_GSFTrackResol",&Tau_GSFTrackResol);
  reader_NoEleMatch_woGwGSF_EC->AddVariable("Tau_GSFTracklnPt",&Tau_GSFTracklnPt);
  reader_NoEleMatch_woGwGSF_EC->AddVariable("Tau_GSFTrackEta",&Tau_GSFTrackEta);
  reader_NoEleMatch_woGwGSF_EC->AddVariable("Tau_dCrackEta",&Tau_dCrackEta);
//   reader_NoEleMatch_woGwGSF_EC->AddVariable("Tau_DecayMode",&Tau_DecayMode);
  reader_NoEleMatch_woGwGSF_EC->SetVerbose(kTRUE);
  reader_NoEleMatch_woGwGSF_EC->BookMVA("BDTG",Weight_NoEleMatch_woGwGSF_EC);

  TMVA::Reader *reader_NoEleMatch_wGwoGSF_EC = new TMVA::Reader( "!Color:!Silent:Error" );  
  reader_NoEleMatch_wGwoGSF_EC->AddVariable("Tau_EtaAtEcalEntrance",&Tau_EtaAtEcalEntrance);
  reader_NoEleMatch_wGwoGSF_EC->AddVariable("Tau_Pt",&Tau_Pt);
  reader_NoEleMatch_wGwoGSF_EC->AddVariable("Tau_EmFraction",&Tau_EmFraction);
  reader_NoEleMatch_wGwoGSF_EC->AddVariable("Tau_NumGammaCands",&Tau_NumGammaCands);
  reader_NoEleMatch_wGwoGSF_EC->AddVariable("Tau_HadrHoP",&Tau_HadrHoP);
  reader_NoEleMatch_wGwoGSF_EC->AddVariable("Tau_HadrEoP",&Tau_HadrEoP);
  reader_NoEleMatch_wGwoGSF_EC->AddVariable("Tau_VisMass",&Tau_VisMass);
  reader_NoEleMatch_wGwoGSF_EC->AddVariable("Tau_GammaEtaMom",&Tau_GammaEtaMom);
  reader_NoEleMatch_wGwoGSF_EC->AddVariable("Tau_GammaPhiMom",&Tau_GammaPhiMom);
  reader_NoEleMatch_wGwoGSF_EC->AddVariable("Tau_GammaEnFrac",&Tau_GammaEnFrac);
  reader_NoEleMatch_wGwoGSF_EC->AddVariable("Tau_dCrackEta",&Tau_dCrackEta);
//   reader_NoEleMatch_wGwoGSF_EC->AddVariable("Tau_DecayMode",&Tau_DecayMode);
  reader_NoEleMatch_wGwoGSF_EC->SetVerbose(kTRUE);
  reader_NoEleMatch_wGwoGSF_EC->BookMVA("BDTG",Weight_NoEleMatch_wGwoGSF_EC);

  TMVA::Reader *reader_NoEleMatch_wGwGSF_EC = new TMVA::Reader( "!Color:!Silent:Error" );  
  reader_NoEleMatch_wGwGSF_EC->AddVariable("Tau_EtaAtEcalEntrance",&Tau_EtaAtEcalEntrance);
  reader_NoEleMatch_wGwGSF_EC->AddVariable("Tau_Pt",&Tau_Pt);
  reader_NoEleMatch_wGwGSF_EC->AddVariable("Tau_EmFraction",&Tau_EmFraction);
  reader_NoEleMatch_wGwGSF_EC->AddVariable("Tau_NumGammaCands",&Tau_NumGammaCands);
  reader_NoEleMatch_wGwGSF_EC->AddVariable("Tau_HadrHoP",&Tau_HadrHoP);
  reader_NoEleMatch_wGwGSF_EC->AddVariable("Tau_HadrEoP",&Tau_HadrEoP);
  reader_NoEleMatch_wGwGSF_EC->AddVariable("Tau_VisMass",&Tau_VisMass);
  reader_NoEleMatch_wGwGSF_EC->AddVariable("Tau_HadrMva",&Tau_HadrMva);
  reader_NoEleMatch_wGwGSF_EC->AddVariable("Tau_GammaEtaMom",&Tau_GammaEtaMom);
  reader_NoEleMatch_wGwGSF_EC->AddVariable("Tau_GammaPhiMom",&Tau_GammaPhiMom);
  reader_NoEleMatch_wGwGSF_EC->AddVariable("Tau_GammaEnFrac",&Tau_GammaEnFrac);
  reader_NoEleMatch_wGwGSF_EC->AddVariable("Tau_GSFChi2",&Tau_GSFChi2);
  reader_NoEleMatch_wGwGSF_EC->AddVariable("(Tau_GSFNumHits - Tau_KFNumHits)/(Tau_GSFNumHits + Tau_KFNumHits)",&Tau_NumHitsVariable);
  reader_NoEleMatch_wGwGSF_EC->AddVariable("Tau_GSFTrackResol",&Tau_GSFTrackResol);
  reader_NoEleMatch_wGwGSF_EC->AddVariable("Tau_GSFTracklnPt",&Tau_GSFTracklnPt);
  reader_NoEleMatch_wGwGSF_EC->AddVariable("Tau_GSFTrackEta",&Tau_GSFTrackEta);
  reader_NoEleMatch_wGwGSF_EC->AddVariable("Tau_dCrackEta",&Tau_dCrackEta);
//   reader_NoEleMatch_wGwGSF_EC->AddVariable("Tau_DecayMode",&Tau_DecayMode);
  reader_NoEleMatch_wGwGSF_EC->SetVerbose(kTRUE);
  reader_NoEleMatch_wGwGSF_EC->BookMVA("BDTG",Weight_NoEleMatch_wGwGSF_EC);

  TMVA::Reader *reader_woGwoGSF_EC = new TMVA::Reader( "!Color:!Silent:Error" );
  reader_woGwoGSF_EC->AddVariable("Elec_EtotOverPin",&Elec_EtotOverPin);
  reader_woGwoGSF_EC->AddVariable("Elec_EgammaOverPdif",&Elec_EgammaOverPdif);
  reader_woGwoGSF_EC->AddVariable("Elec_Fbrem",&Elec_Fbrem);
  reader_woGwoGSF_EC->AddVariable("Elec_Chi2GSF",&Elec_Chi2GSF);
  reader_woGwoGSF_EC->AddVariable("Elec_GSFNumHits",&Elec_GSFNumHits);
  reader_woGwoGSF_EC->AddVariable("Elec_GSFTrackResol",&Elec_GSFTrackResol);
  reader_woGwoGSF_EC->AddVariable("Elec_GSFTracklnPt",&Elec_GSFTracklnPt);
  reader_woGwoGSF_EC->AddVariable("Elec_GSFTrackEta",&Elec_GSFTrackEta);
  reader_woGwoGSF_EC->AddVariable("Tau_EtaAtEcalEntrance",&Tau_EtaAtEcalEntrance);
  reader_woGwoGSF_EC->AddVariable("Tau_Pt",&Tau_Pt);
  reader_woGwoGSF_EC->AddVariable("Tau_EmFraction",&Tau_EmFraction);
  reader_woGwoGSF_EC->AddVariable("Tau_HadrHoP",&Tau_HadrHoP);
  reader_woGwoGSF_EC->AddVariable("Tau_HadrEoP",&Tau_HadrEoP);
  reader_woGwoGSF_EC->AddVariable("Tau_VisMass",&Tau_VisMass);
  reader_woGwoGSF_EC->AddVariable("Tau_dCrackEta",&Tau_dCrackEta);
//   reader_woGwoGSF_EC->AddVariable("Tau_DecayMode",&Tau_DecayMode);
  reader_woGwoGSF_EC->SetVerbose(kTRUE);
  reader_woGwoGSF_EC->BookMVA("BDTG",Weight_woGwoGSF_EC);

  TMVA::Reader *reader_woGwGSF_EC = new TMVA::Reader( "!Color:!Silent:Error" );  
  reader_woGwGSF_EC->AddVariable("Elec_EtotOverPin",&Elec_EtotOverPin);
  reader_woGwGSF_EC->AddVariable("Elec_EgammaOverPdif",&Elec_EgammaOverPdif);
  reader_woGwGSF_EC->AddVariable("Elec_Fbrem",&Elec_Fbrem);
  reader_woGwGSF_EC->AddVariable("Elec_Chi2GSF",&Elec_Chi2GSF);
  reader_woGwGSF_EC->AddVariable("Elec_GSFNumHits",&Elec_GSFNumHits);
  reader_woGwGSF_EC->AddVariable("Elec_GSFTrackResol",&Elec_GSFTrackResol);
  reader_woGwGSF_EC->AddVariable("Elec_GSFTracklnPt",&Elec_GSFTracklnPt);
  reader_woGwGSF_EC->AddVariable("Elec_GSFTrackEta",&Elec_GSFTrackEta);
  reader_woGwGSF_EC->AddVariable("Tau_EtaAtEcalEntrance",&Tau_EtaAtEcalEntrance);
  reader_woGwGSF_EC->AddVariable("Tau_Pt",&Tau_Pt);
  reader_woGwGSF_EC->AddVariable("Tau_EmFraction",&Tau_EmFraction);
  reader_woGwGSF_EC->AddVariable("Tau_HadrHoP",&Tau_HadrHoP);
  reader_woGwGSF_EC->AddVariable("Tau_HadrEoP",&Tau_HadrEoP);
  reader_woGwGSF_EC->AddVariable("Tau_VisMass",&Tau_VisMass);
  reader_woGwGSF_EC->AddVariable("Tau_HadrMva",&Tau_HadrMva);
  reader_woGwGSF_EC->AddVariable("Tau_GSFChi2",&Tau_GSFChi2);
  reader_woGwGSF_EC->AddVariable("(Tau_GSFNumHits - Tau_KFNumHits)/(Tau_GSFNumHits + Tau_KFNumHits)",&Tau_NumHitsVariable);
  reader_woGwGSF_EC->AddVariable("Tau_GSFTrackResol",&Tau_GSFTrackResol);
  reader_woGwGSF_EC->AddVariable("Tau_GSFTracklnPt",&Tau_GSFTracklnPt);
  reader_woGwGSF_EC->AddVariable("Tau_GSFTrackEta",&Tau_GSFTrackEta);
  reader_woGwGSF_EC->AddVariable("Tau_dCrackEta",&Tau_dCrackEta);
//   reader_woGwGSF_EC->AddVariable("Tau_DecayMode",&Tau_DecayMode);
  reader_woGwGSF_EC->SetVerbose(kTRUE);
  reader_woGwGSF_EC->BookMVA("BDTG",Weight_woGwGSF_EC);

  TMVA::Reader *reader_wGwoGSF_EC = new TMVA::Reader( "!Color:!Silent:Error" );  
  reader_wGwoGSF_EC->AddVariable("Elec_EtotOverPin",&Elec_EtotOverPin);
  reader_wGwoGSF_EC->AddVariable("Elec_EgammaOverPdif",&Elec_EgammaOverPdif);
  reader_wGwoGSF_EC->AddVariable("Elec_Fbrem",&Elec_Fbrem);
  reader_wGwoGSF_EC->AddVariable("Elec_Chi2GSF",&Elec_Chi2GSF);
  reader_wGwoGSF_EC->AddVariable("Elec_GSFNumHits",&Elec_GSFNumHits);
  reader_wGwoGSF_EC->AddVariable("Elec_GSFTrackResol",&Elec_GSFTrackResol);
  reader_wGwoGSF_EC->AddVariable("Elec_GSFTracklnPt",&Elec_GSFTracklnPt);
  reader_wGwoGSF_EC->AddVariable("Elec_GSFTrackEta",&Elec_GSFTrackEta);
  reader_wGwoGSF_EC->AddVariable("Tau_EtaAtEcalEntrance",&Tau_EtaAtEcalEntrance);
  reader_wGwoGSF_EC->AddVariable("Tau_Pt",&Tau_Pt);
  reader_wGwoGSF_EC->AddVariable("Tau_EmFraction",&Tau_EmFraction);
  reader_wGwoGSF_EC->AddVariable("Tau_NumGammaCands",&Tau_NumGammaCands);
  reader_wGwoGSF_EC->AddVariable("Tau_HadrHoP",&Tau_HadrHoP);
  reader_wGwoGSF_EC->AddVariable("Tau_HadrEoP",&Tau_HadrEoP);
  reader_wGwoGSF_EC->AddVariable("Tau_VisMass",&Tau_VisMass);
  reader_wGwoGSF_EC->AddVariable("Tau_GammaEtaMom",&Tau_GammaEtaMom);
  reader_wGwoGSF_EC->AddVariable("Tau_GammaPhiMom",&Tau_GammaPhiMom);
  reader_wGwoGSF_EC->AddVariable("Tau_GammaEnFrac",&Tau_GammaEnFrac);
  reader_wGwoGSF_EC->AddVariable("Tau_dCrackEta",&Tau_dCrackEta);
//   reader_wGwoGSF_EC->AddVariable("Tau_DecayMode",&Tau_DecayMode);
  reader_wGwoGSF_EC->SetVerbose(kTRUE);
  reader_wGwoGSF_EC->BookMVA("BDTG",Weight_wGwoGSF_EC);

  TMVA::Reader *reader_wGwGSF_EC = new TMVA::Reader( "!Color:!Silent:Error" );  
  reader_wGwGSF_EC->AddVariable("Elec_EtotOverPin",&Elec_EtotOverPin);
  reader_wGwGSF_EC->AddVariable("Elec_EgammaOverPdif",&Elec_EgammaOverPdif);
  reader_wGwGSF_EC->AddVariable("Elec_Fbrem",&Elec_Fbrem);
  reader_wGwGSF_EC->AddVariable("Elec_Chi2GSF",&Elec_Chi2GSF);
  reader_wGwGSF_EC->AddVariable("Elec_GSFNumHits",&Elec_GSFNumHits);
  reader_wGwGSF_EC->AddVariable("Elec_GSFTrackResol",&Elec_GSFTrackResol);
  reader_wGwGSF_EC->AddVariable("Elec_GSFTracklnPt",&Elec_GSFTracklnPt);
  reader_wGwGSF_EC->AddVariable("Elec_GSFTrackEta",&Elec_GSFTrackEta);
  reader_wGwGSF_EC->AddVariable("Tau_EtaAtEcalEntrance",&Tau_EtaAtEcalEntrance);
  reader_wGwGSF_EC->AddVariable("Tau_Pt",&Tau_Pt);
  reader_wGwGSF_EC->AddVariable("Tau_EmFraction",&Tau_EmFraction);
  reader_wGwGSF_EC->AddVariable("Tau_NumGammaCands",&Tau_NumGammaCands);
  reader_wGwGSF_EC->AddVariable("Tau_HadrHoP",&Tau_HadrHoP);
  reader_wGwGSF_EC->AddVariable("Tau_HadrEoP",&Tau_HadrEoP);
  reader_wGwGSF_EC->AddVariable("Tau_VisMass",&Tau_VisMass);
  reader_wGwGSF_EC->AddVariable("Tau_HadrMva",&Tau_HadrMva);
  reader_wGwGSF_EC->AddVariable("Tau_GammaEtaMom",&Tau_GammaEtaMom);
  reader_wGwGSF_EC->AddVariable("Tau_GammaPhiMom",&Tau_GammaPhiMom);
  reader_wGwGSF_EC->AddVariable("Tau_GammaEnFrac",&Tau_GammaEnFrac);
  reader_wGwGSF_EC->AddVariable("Tau_GSFChi2",&Tau_GSFChi2);
  reader_wGwGSF_EC->AddVariable("(Tau_GSFNumHits - Tau_KFNumHits)/(Tau_GSFNumHits + Tau_KFNumHits)",&Tau_NumHitsVariable);
  reader_wGwGSF_EC->AddVariable("Tau_GSFTrackResol",&Tau_GSFTrackResol);
  reader_wGwGSF_EC->AddVariable("Tau_GSFTracklnPt",&Tau_GSFTracklnPt);
  reader_wGwGSF_EC->AddVariable("Tau_GSFTrackEta",&Tau_GSFTrackEta);
  reader_wGwGSF_EC->AddVariable("Tau_dCrackEta",&Tau_dCrackEta);
//   reader_wGwGSF_EC->AddVariable("Tau_DecayMode",&Tau_DecayMode);
  reader_wGwGSF_EC->SetVerbose(kTRUE);
  reader_wGwGSF_EC->BookMVA("BDTG",Weight_wGwGSF_EC);

  cout<< "Number of entries : "<<nEntries<<endl;

  for (int iEntry = 0; iEntry<nEntries ; iEntry++){
    if(iEntry%100000==0) cout << iEntry  <<"/"<<nEntries << endl;
    inputTree->GetEntry(iEntry);

    t_NoEleMatch_woGwoGSF_Barrel = -99;
    t_NoEleMatch_woGwGSF_Barrel = -99;
    t_NoEleMatch_wGwoGSF_Barrel = -99;
    t_NoEleMatch_wGwGSF_Barrel = -99;
    t_woGwoGSF_Barrel = -99;
    t_woGwGSF_Barrel = -99;
    t_wGwoGSF_Barrel = -99;
    t_wGwGSF_Barrel = -99;
    t_NoEleMatch_woGwoGSF_Endcap = -99;
    t_NoEleMatch_woGwGSF_Endcap = -99;
    t_NoEleMatch_wGwoGSF_Endcap = -99;
    t_NoEleMatch_wGwGSF_Endcap = -99;
    t_woGwoGSF_Endcap = -99;
    t_woGwGSF_Endcap = -99;
    t_wGwoGSF_Endcap = -99;
    t_wGwGSF_Endcap = -99;

//     cout<<"classID :"<<classID<<endl;
    t_classID = classID;

    if (Cat.find("NoEleMatch_woGwoGSF_Barrel")!=std::string::npos) t_NoEleMatch_woGwoGSF_Barrel = reader_NoEleMatch_woGwoGSF_BL->EvaluateMVA("BDTG");
    if (Cat.find("NoEleMatch_woGwGSF_Barrel")!=std::string::npos) t_NoEleMatch_woGwGSF_Barrel = reader_NoEleMatch_woGwGSF_BL->EvaluateMVA("BDTG");
    if (Cat.find("NoEleMatch_wGwoGSF_Barrel")!=std::string::npos) t_NoEleMatch_wGwoGSF_Barrel = reader_NoEleMatch_wGwoGSF_BL->EvaluateMVA("BDTG");
    if (Cat.find("NoEleMatch_wGwGSF_Barrel")!=std::string::npos) t_NoEleMatch_wGwGSF_Barrel = reader_NoEleMatch_wGwGSF_BL->EvaluateMVA("BDTG");
    if (Cat.find("woGwoGSF_Barrel")!=std::string::npos) t_woGwoGSF_Barrel = reader_woGwoGSF_BL->EvaluateMVA("BDTG");
    if (Cat.find("woGwGSF_Barrel")!=std::string::npos) t_woGwGSF_Barrel = reader_woGwGSF_BL->EvaluateMVA("BDTG");
    if (Cat.find("wGwoGSF_Barrel")!=std::string::npos) t_wGwoGSF_Barrel = reader_wGwoGSF_BL->EvaluateMVA("BDTG");
    if (Cat.find("wGwGSF_Barrel")!=std::string::npos) t_wGwGSF_Barrel = reader_wGwGSF_BL->EvaluateMVA("BDTG");
    if (Cat.find("NoEleMatch_woGwoGSF_Endcap")!=std::string::npos) t_NoEleMatch_woGwoGSF_Endcap = reader_NoEleMatch_woGwoGSF_EC->EvaluateMVA("BDTG");
    if (Cat.find("NoEleMatch_woGwGSF_Endcap")!=std::string::npos) t_NoEleMatch_woGwGSF_Endcap = reader_NoEleMatch_woGwGSF_EC->EvaluateMVA("BDTG");
    if (Cat.find("NoEleMatch_wGwoGSF_Endcap")!=std::string::npos) t_NoEleMatch_wGwoGSF_Endcap = reader_NoEleMatch_wGwoGSF_EC->EvaluateMVA("BDTG");
    if (Cat.find("NoEleMatch_wGwGSF_Endcap")!=std::string::npos) t_NoEleMatch_wGwGSF_Endcap = reader_NoEleMatch_wGwGSF_EC->EvaluateMVA("BDTG");
    if (Cat.find("woGwoGSF_Endcap")!=std::string::npos) t_woGwoGSF_Endcap = reader_woGwoGSF_EC->EvaluateMVA("BDTG");
    if (Cat.find("woGwGSF_Endcap")!=std::string::npos) t_woGwGSF_Endcap = reader_woGwGSF_EC->EvaluateMVA("BDTG");
    if (Cat.find("wGwoGSF_Endcap")!=std::string::npos) t_wGwoGSF_Endcap = reader_wGwoGSF_EC->EvaluateMVA("BDTG");
    if (Cat.find("wGwGSF_Endcap")!=std::string::npos) t_wGwGSF_Endcap = reader_wGwGSF_EC->EvaluateMVA("BDTG");

    mytree->Fill();

  }

  mytree->Write();
  
  cout<<"Creating file : "<<outputFileName.data()<<endl;
//   inputFile->Close();
  outputFile->Close();
  return;
}
void minBiasJetSkim(const TString configFile, const TString inputFile, const TString outputFile)
{
       std::cout<<"running minBiasJetSkim()"<<std::endl;
       std::cout<<"configFile  = "<< configFile.Data() <<std::endl;
       std::cout<<"inputFile   = "<< inputFile.Data() <<std::endl;
       std::cout<<"outputFile  = "<< outputFile.Data() <<std::endl;

       InputConfiguration configInput = InputConfigurationParser::Parse(configFile.Data());
       CutConfiguration configCuts = CutConfigurationParser::Parse(configFile.Data());

       if (!configInput.isValid) {
           std::cout << "Input configuration is invalid." << std::endl;
           std::cout << "exiting" << std::endl;
           return;
       }
       if (!configCuts.isValid) {
           std::cout << "Cut configuration is invalid." << std::endl;
           std::cout << "exiting" << std::endl;
           return;
       }

       // cut configuration
       float cut_vz = configCuts.proc[CUTS::kSKIM].obj[CUTS::kEVENT].f[CUTS::EVT::k_vz];
       int cut_pcollisionEventSelection = configCuts.proc[CUTS::kSKIM].obj[CUTS::kEVENT].i[CUTS::EVT::k_pcollisionEventSelection];

       std::vector<std::string> jetCollections = ConfigurationParser::ParseList(configCuts.proc[CUTS::kSKIM].obj[CUTS::kJET].s[CUTS::JET::k_jetCollection]);
       int nMaxEvents_minBiasMixing = configCuts.proc[CUTS::kSKIM].obj[CUTS::kGAMMAJET].i[CUTS::GJT::k_nMaxEvents_minBiasMixing];
       int nCentralityBins = configCuts.proc[CUTS::kSKIM].obj[CUTS::kGAMMAJET].i[CUTS::GJT::k_nCentralityBins];
       int nVertexBins = configCuts.proc[CUTS::kSKIM].obj[CUTS::kGAMMAJET].i[CUTS::GJT::k_nVertexBins];
       int nEventPlaneBins = configCuts.proc[CUTS::kSKIM].obj[CUTS::kGAMMAJET].i[CUTS::GJT::k_nEventPlaneBins];

       int nJetCollections = jetCollections.size();

       // verbose about cut configuration
       std::cout<<"Cut Configuration :"<<std::endl;
       std::cout<<"cut_vz = "<< cut_vz <<std::endl;
       std::cout<<"cut_pcollisionEventSelection = "<< cut_pcollisionEventSelection <<std::endl;

       std::cout<<"nJetCollections = "<< nJetCollections <<std::endl;
       for (int i=0; i<nJetCollections; ++i) {
           std::cout << Form("jetCollections[%d] = %s", i, jetCollections.at(i).c_str()) << std::endl;
       }
       std::cout<<"nMaxEvents_minBiasMixing = "<< nMaxEvents_minBiasMixing <<std::endl;
       std::cout<<"nCentralityBins          = "<< nCentralityBins <<std::endl;
       std::cout<<"nVertexBins              = "<< nVertexBins <<std::endl;
       std::cout<<"nEventPlaneBins          = "<< nEventPlaneBins <<std::endl;

       std::vector<std::string> inputFiles = InputConfigurationParser::ParseFiles(inputFile.Data());

       std::cout<<"input ROOT files : num = "<<inputFiles.size()<< std::endl;
       std::cout<<"#####"<< std::endl;
       for (std::vector<std::string>::iterator it = inputFiles.begin() ; it != inputFiles.end(); ++it) {
           std::cout<<(*it).c_str()<< std::endl;
       }
       std::cout<<"##### END #####"<< std::endl;

       TChain* treeHLT   = new TChain("hltanalysis/HltTree");
       TChain* treeEvent = new TChain("ggHiNtuplizer/EventTree");
       TChain* treeJets[nJetCollections];
       for (int i=0; i<nJetCollections; ++i) {
           treeJets[i] = new TChain(Form("%s/t", jetCollections.at(i).c_str()));
       }
       TChain* treeHiEvt = new TChain("hiEvtAnalyzer/HiTree");
       TChain* treeSkim  = new TChain("skimanalysis/HltTree");
       TChain* treeHiForestInfo = new TChain("HiForest/HiForestInfo");

       for (std::vector<std::string>::iterator it = inputFiles.begin() ; it != inputFiles.end(); ++it) {
          treeHLT->Add((*it).c_str());
          treeEvent->Add((*it).c_str());
          for (int i=0; i<nJetCollections; ++i) {
              treeJets[i]->Add((*it).c_str());
          }
          treeHiEvt->Add((*it).c_str());
          treeSkim->Add((*it).c_str());
          if (it == inputFiles.begin())  treeHiForestInfo->Add((*it).c_str());
       }

       HiForestInfoController hfic(treeHiForestInfo);
       std::cout<<"### HiForestInfo Tree ###"<< std::endl;
       hfic.printHiForestInfo();
       std::cout<<"###"<< std::endl;

       treeHLT->SetBranchStatus("*",0);     // disable all branches

       treeEvent->SetBranchStatus("*",0);
       treeEvent->SetBranchStatus("run",1);
       treeEvent->SetBranchStatus("event",1);
       treeEvent->SetBranchStatus("lumis",1);

       for (int i=0; i<nJetCollections; ++i) {
           treeJets[i]->SetBranchStatus("*",0);        // disable all branches
           treeJets[i]->SetBranchStatus("nref",1);     // enable jet branches
           treeJets[i]->SetBranchStatus("rawpt",1);    // enable jet branches
           treeJets[i]->SetBranchStatus("jtpt",1);     // enable jet branches
           treeJets[i]->SetBranchStatus("jteta",1);    // enable jet branches
           treeJets[i]->SetBranchStatus("jtphi",1);    // enable jet branches
           treeJets[i]->SetBranchStatus("jty",1);      // enable jet branches
           treeJets[i]->SetBranchStatus("jtpu",1);     // enable jet branches
           treeJets[i]->SetBranchStatus("jtm",1);      // enable jet branches
           treeJets[i]->SetBranchStatus("track*",1);
           treeJets[i]->SetBranchStatus("charged*",1);
           treeJets[i]->SetBranchStatus("photon*",1);
           treeJets[i]->SetBranchStatus("neutral*",1);
           treeJets[i]->SetBranchStatus("eMax*",1);
           treeJets[i]->SetBranchStatus("eSum*",1);
           treeJets[i]->SetBranchStatus("eN*",1);
           treeJets[i]->SetBranchStatus("muMax*",1);
           treeJets[i]->SetBranchStatus("muSum*",1);
           treeJets[i]->SetBranchStatus("muN*",1);
       }

       // specify explicitly which branches to store, do not use wildcard
       treeHiEvt->SetBranchStatus("*",0);
       treeHiEvt->SetBranchStatus("run",1);
       treeHiEvt->SetBranchStatus("evt",1);
       treeHiEvt->SetBranchStatus("lumi",1);
       treeHiEvt->SetBranchStatus("vz",1);
       treeHiEvt->SetBranchStatus("hiBin",1);
       treeHiEvt->SetBranchStatus("hiHF",1);
       treeHiEvt->SetBranchStatus("hiHFplus",1);
       treeHiEvt->SetBranchStatus("hiHFminus",1);
       treeHiEvt->SetBranchStatus("hiHFplusEta4",1);
       treeHiEvt->SetBranchStatus("hiHFminusEta4",1);
      //  treeHiEvt->SetBranchStatus("hiNevtPlane",1);

       float vz;
       Int_t hiBin;
       Float_t         hiEvtPlanes[29];   //[hiNevtPlane]
       treeHiEvt->SetBranchAddress("hiEvtPlanes",&hiEvtPlanes);

       treeHiEvt->SetBranchAddress("vz",&vz);
       treeHiEvt->SetBranchAddress("hiBin",&hiBin);

       // specify explicitly which branches to store, do not use wildcard
       treeSkim->SetBranchStatus("*",0);
       treeSkim->SetBranchStatus("ana_step",1);
       treeSkim->SetBranchStatus("pcollisionEventSelection",1);
       treeSkim->SetBranchStatus("pHBHENoiseFilterResultProducer",1);
       treeSkim->SetBranchStatus("HBHENoiseFilterResultRun1",1);
       treeSkim->SetBranchStatus("HBHENoiseFilterResultRun2Loose",1);
       treeSkim->SetBranchStatus("HBHENoiseFilterResultRun2Tight",1);
       treeSkim->SetBranchStatus("HBHENoiseFilterResult",1);
       treeSkim->SetBranchStatus("HBHEIsoNoiseFilterResult",1);

       Int_t pcollisionEventSelection;

       if (treeSkim->GetBranch("pcollisionEventSelection")) {
           treeSkim->SetBranchAddress("pcollisionEventSelection",&pcollisionEventSelection);
       }
       else {   // overwrite to default
           pcollisionEventSelection = 1;
           std::cout<<"could not get branch : pcollisionEventSelection"<<std::endl;
           std::cout<<"set to default value : pcollisionEventSelection = "<<pcollisionEventSelection<<std::endl;
       }

       // event information
       UInt_t run, lumis;
       ULong64_t event;
       treeEvent->SetBranchAddress("run", &run);
       treeEvent->SetBranchAddress("event", &event);
       treeEvent->SetBranchAddress("lumis", &lumis);

       TFile* output = new TFile(outputFile,"RECREATE");

       TTree *configTree = setupConfigurationTreeForWriting(configCuts);

       int centBinWidth = 200/nCentralityBins;  // number of "hiBin"s that a centrality bin covers
       int vertexBinWidth = 30/nVertexBins;     // number of "vz"s    that a vertex     bin covers
       float eventPlaneBinWidth = TMath::Pi()/nEventPlaneBins;     // number of "vz"s    that a vertex     bin covers
                                                // accepted vz range is -15 to 15.

       TTree *outputTreesHLT[nCentralityBins][nVertexBins][nEventPlaneBins];
       TTree *outputTreesEvent[nCentralityBins][nVertexBins][nEventPlaneBins];
       TTree *outputTreesJet[nCentralityBins][nVertexBins][nEventPlaneBins][nJetCollections];
       TTree *outputTreesHiEvt[nCentralityBins][nVertexBins][nEventPlaneBins];
       TTree *outputTreesSkim[nCentralityBins][nVertexBins][nEventPlaneBins];

       Long64_t nEntriesFilled[nCentralityBins][nVertexBins][nEventPlaneBins];    // number of events read for a centrality bin
       for(int i=0; i<nCentralityBins; ++i)
       {
           for(int j=0; j<nVertexBins; ++j){
             for(int l=0; l<nEventPlaneBins; ++l) {

               nEntriesFilled[i][j][l] = 0;

               outputTreesHLT[i][j][l] = treeHLT->CloneTree(0);
               outputTreesHLT[i][j][l]->SetName(Form("hltTree_centBin%d_vzBin%d_evPlaneBin%d", i, j, l));
               outputTreesHLT[i][j][l]->SetTitle(Form("subbranches of hltanalysis/HltTree for centrality bin %d vz bin %d evPlane Bin %d", i, j, l));
               outputTreesHLT[i][j][l]->SetMaxTreeSize(MAXTREESIZE);

               outputTreesEvent[i][j][l] = treeEvent->CloneTree(0);
               outputTreesEvent[i][j][l]->SetName(Form("EventTree_centBin%d_vzBin%d_evPlaneBin%d", i, j, l));
               outputTreesEvent[i][j][l]->SetTitle(Form("subbranches of ggHiNtuplizer/EventTree for centrality bin %d vz bin %d evPlane Bin %d", i, j, l));
               outputTreesEvent[i][j][l]->SetMaxTreeSize(MAXTREESIZE);

               for(int k=0; k<nJetCollections; ++k){
                   std::string jetCollectionName = jetCollections.at(k).c_str();
                   outputTreesJet[i][j][l][k] = treeJets[k]->CloneTree(0);
                   outputTreesJet[i][j][l][k]->SetName(Form("%s_centBin%d_vzBin%d_evPlaneBin%d", jetCollectionName.c_str(), i, j, l));
                   outputTreesJet[i][j][l][k]->SetTitle(Form("subbranches of %s/t for centrality bin %d vz bin %d evPlane Bin %d", jetCollectionName.c_str(), i, j, l));
                   outputTreesJet[i][j][l][k]->SetMaxTreeSize(MAXTREESIZE);
               }

               outputTreesHiEvt[i][j][l] = treeHiEvt->CloneTree(0);
               outputTreesHiEvt[i][j][l]->SetName(Form("HiEvt_centBin%d_vzBin%d_evPlaneBin%d", i, j, l));
               outputTreesHiEvt[i][j][l]->SetTitle(Form("subbranches of hiEvtAnalyzer/HiTree for centrality bin %d vz bin %d evPlane Bin %d", i, j, l));
               outputTreesHiEvt[i][j][l]->SetMaxTreeSize(MAXTREESIZE);

               outputTreesSkim[i][j][l] = treeSkim->CloneTree(0);
               outputTreesSkim[i][j][l]->SetName(Form("skim_centBin%d_vzBin%d_evPlaneBin%d", i, j, l));
               outputTreesSkim[i][j][l]->SetTitle(Form("subbranches of skimanalysis/HltTree for centrality bin %d vz bin %d evPlane Bin %d", i, j, l));
               outputTreesSkim[i][j][l]->SetMaxTreeSize(MAXTREESIZE);
             }
           }
       }
//       TTree* outputTreeHiForestInfo = treeHiForestInfo->CloneTree(0);
//       outputTreeHiForestInfo->SetName("HiForestInfo");
//       outputTreeHiForestInfo->SetTitle("first entry of HiForest/HiForestInfo");
//
//       outputTreeHiForestInfo->SetMaxTreeSize(MAXTREESIZE);
//
//       // write HiForestInfo
//       treeHiForestInfo->GetEntry(0);
//       outputTreeHiForestInfo->Fill();

       EventMatcher* em = new EventMatcher();
       Long64_t duplicateEntries = 0;

       Long64_t entries = treeEvent->GetEntries();
       Long64_t entriesAnalyzed = 0;
       std::cout << "entries         = " << entries << std::endl;
       std::cout<< "Loop : ggHiNtuplizer/EventTree" <<std::endl;
       for (Long64_t j_entry=0; j_entry<entries; ++j_entry)
       {
           if (j_entry % 20000 == 0)  {
             std::cout << "current entry = " <<j_entry<<" out of "<<entries<<" : "<<std::setprecision(2)<<(double)j_entry/entries*100<<" %"<<std::endl;
           }

           treeHLT->GetEntry(j_entry);
           treeEvent->GetEntry(j_entry);
           for (int i = 0; i<nJetCollections; ++i) {
               treeJets[i]->GetEntry(j_entry);
           }
           treeHiEvt->GetEntry(j_entry);
           treeSkim->GetEntry(j_entry);

           bool eventAdded = em->addEvent(run,lumis,event,j_entry);
           if(!eventAdded) // this event is duplicate, skip this one.
           {
               duplicateEntries++;
               continue;
           }

           // event selection
           if(!(TMath::Abs(vz) < cut_vz)) continue;
           if(pcollisionEventSelection < cut_pcollisionEventSelection) continue;
           entriesAnalyzed++;

           int centBin = hiBin / centBinWidth;
           int vzBin   = (vz+15) / vertexBinWidth;
           int evplaneBin = (hiEvtPlanes[8]+(TMath::Pi()/2.)) / eventPlaneBinWidth;
          //  std::cout<<evplaneBin<< " bin " << eventPlaneBinWidth << " value " << hiEvtPlanes[8]+(TMath::Pi()/2.) << std::endl;
           if (nEntriesFilled[centBin][vzBin][evplaneBin] > nMaxEvents_minBiasMixing) continue;

           outputTreesHLT[centBin][vzBin][evplaneBin]->Fill();
           outputTreesEvent[centBin][vzBin][evplaneBin]->Fill();
           for (int i = 0; i<nJetCollections; ++i) {
               outputTreesJet[centBin][vzBin][evplaneBin][i]->Fill();
           }
           outputTreesHiEvt[centBin][vzBin][evplaneBin]->Fill();
           outputTreesSkim[centBin][vzBin][evplaneBin]->Fill();

           nEntriesFilled[centBin][vzBin][evplaneBin]++;
       }
       std::cout<<  "Loop ENDED : ggHiNtuplizer/EventTree" <<std::endl;
       std::cout << "entries            = " << entries << std::endl;
       std::cout << "duplicateEntries   = " << duplicateEntries << std::endl;
       std::cout << "entriesAnalyzed    = " << entriesAnalyzed << std::endl;

       for(int i=0; i<nCentralityBins; ++i){
           for(int j=0; j<nVertexBins; ++j){
             for(int l=0; l<nEventPlaneBins; ++l){
                 std::cout<<Form("outputTreesJet[%d][%d][%d]->GetEntries() = %lld", i, j, l, outputTreesEvent[i][j][l]->GetEntries())<<std::endl;
                 if (outputTreesEvent[i][j][l]->GetEntries() < 100) {
                     std::cout<< "Be careful : less than 100 events were put into centBin = "<<i<<" , vertexBin = "<<j<<" , EventPlaneBin = "<<l<<std::endl;
                 }
             }
          }
       }

       configTree->Write("",TObject::kOverwrite);

       output->Write("",TObject::kOverwrite);
       output->Close();

       std::cout<<"minBiasJetSkim() - END"<<std::endl;
}
Ejemplo n.º 6
0
int main(int argc, char *argv[]){
  
  char DFin_location[256];
  DFin_location = argv[1] ;
  char DFout_location[256] argv[2];
  char AnaFile[256] = argv[3] ;
  char SimFile[256] = argv[4] ;
  int TriggerBucket = atoi(argv[5]);
  int RUN = atoi(argv[5]);

  std::cout << argv[1] << std::endl;  
  std::cout << DFin_location << std::endl;

  return;



  //here goes the first file
  TChain * DFinput = new TChain("Telescope");
  DFinput->Add(DFin_location);

  unsigned int Event_in;
  int roc_in;
  int col_in,row_in,vcal_in;
  float flux_in;
  double pulseHeight_in;
  std::cout << roc_in << std::endl;

  DFinput->SetBranchStatus("*",false);

  DFinput->SetBranchStatus("Event",true);
  DFinput->SetBranchStatus("roc",true);
  DFinput->SetBranchStatus("pulseHeight",true);
  DFinput->SetBranchStatus("vcal",true);
  DFinput->SetBranchStatus("col",true);
  DFinput->SetBranchStatus("row",true);
  DFinput->SetBranchStatus("flux",true);

  DFinput->SetBranchAddress("Event",&Event_in);
  DFinput->SetBranchAddress("roc",&roc_in);
  DFinput->SetBranchAddress("row",&row_in);
  DFinput->SetBranchAddress("col",&col_in);
  DFinput->SetBranchAddress("vcal",&vcal_in);
  DFinput->SetBranchAddress("flux",&flux_in);
  DFinput->SetBranchAddress("pulseHeight",&pulseHeight_in);

  std::cout << "Loaded DF input file from: " << DFin_location << std::endl;


  //here goes the second file
  TChain * DFoutput = new TChain("hitTree");
  DFoutput->Add(DFout_location);

  unsigned int event_number;
  int roc_out,col_out,row_out,vcal_out;
  double pulseHeight_out;
  long TS_out;


  DFoutput->SetBranchStatus("*",false);

  DFoutput->SetBranchStatus("event_number",true);
  DFoutput->SetBranchStatus("TS",true);
  DFoutput->SetBranchStatus("roc",true);
  DFoutput->SetBranchStatus("col",true);
  DFoutput->SetBranchStatus("row",true);
  DFoutput->SetBranchStatus("vcal",true);
  DFoutput->SetBranchStatus("pulseHeight",true);


  DFoutput->SetBranchAddress("event_number",&event_number);
  DFoutput->SetBranchAddress("TS",&TS_out);
  DFoutput->SetBranchAddress("roc",&roc_out);
  DFoutput->SetBranchAddress("col",&col_out);
  DFoutput->SetBranchAddress("row",&row_out);
  DFoutput->SetBranchAddress("vcal",&vcal_out);
  DFoutput->SetBranchAddress("pulseHeight",&pulseHeight_out);

  std::cout << "Loaded DF output file from: " << DFout_location << std::endl;

  //here come the analysis files
  //comes later


  //here come the original run data files



  //Now we make some histograms we want to compare


  TCanvas * c1 = new TCanvas("Comparison","Comparison",1200,1200);
  // gStyle->SetOptStat(0);
  c1->Divide(2,2);

  c1->cd(1);



  TH1I * Pixels_per_Event_in = new TH1I("Pixels per Event", "DataFlow input",20,0,20);
  unsigned int temp_evtn=-1;

  int ROC_DUT = 3;
  int nhits = 0;
  std::cout << "Total Entries input : " <<  DFinput->GetEntries() << std::endl;
  std::cout << "Total Entries output: " <<  DFoutput->GetEntries() << std::endl;
  long int maxEntries = DFinput->GetEntries();
  for(int i = 0; i < maxEntries; ++i)
    //for(int i = 0; i < 5000000; ++i)
    {
      DFinput->GetEntry(i);
      if(i%100000 == 0) std::cout << setprecision(2) << "Entry: " << i << "    " << (double)(i*100)/maxEntries << "%" << std::endl;
      //std::cout << "Entry: " << i << "Event " << Event_in << "ROC " << roc_in << " " << row_in << "|" << col_in << std::endl;
      temp_evtn = Event_in;
      if(Event_in%588 == TriggerBucket)
	{
	  if(roc_in == -1)
	    {
	      Pixels_per_Event_in->Fill(0);
	      continue;
	    }
	  else
	    {
	      while(Event_in == temp_evtn)
		{
		  // std::cout << "I'm in the loop. ROC " << roc_in << std::endl;
		  if(roc_in == ROC_DUT)
		    {
		      ++nhits;
		    }
		  ++i;
		  if(i == maxEntries) break;
		  DFinput->GetEntry(i);
		  //	      std::cout << "Entry: " << i << "Event " << Event_in << "ROC " << roc_in <<   std::endl;
		}
	    }
	  --i;
	  Pixels_per_Event_in->Fill(nhits);
	  //	  std::cout << "Found event with " << nhits << "Hits on ROC " << ROC_DUT << std::endl;
	  nhits = 0;
	}
    }

    
  Pixels_per_Event_in->Draw();
  c1->Update();
  //second histogram
  std::cout << "Second histogramm" << std::endl;

  TH1I * Pixels_per_Event_out = new TH1I("Pixels per Event","DataFlow output",20,0,20);
  for(int i = 0; i < DFoutput->GetEntries();++i)
    {
      DFoutput->GetEntry(i);
      //if(i%100 == 0) std::cout << "Entry: " << i << "Event " << event_number << "ROC " << roc_out <<   std::endl;
      //      std::cout << "Entry: " << i << "Event " << event_number << "ROC " << roc_out <<   std::endl;
      temp_evtn = event_number;
      if(roc_out == -1)
	{
	  nhits = 0;
	 Pixels_per_Event_out->Fill(nhits);
	  continue;
	}
      else
	{
	  while(event_number == temp_evtn)
	    {
	      // std::cout << "I'm in the loop. ROC " << roc_in << std::endl;
	      if(roc_out == ROC_DUT)
		{
		  ++nhits;
		}
	      ++i;
	      if(i == DFoutput->GetEntries()) break;
	      DFoutput->GetEntry(i);
	      // std::cout << "Entry: " << i << "Event " << event_number << "ROC " << roc_out <<   std::endl;

	    }

	  --i;
	  Pixels_per_Event_out->Fill(nhits);
	  //	  std::cout << "Found event with " << nhits << "Hits on ROC " << ROC_DUT << std::endl;
	  nhits = 0;

	}

    }

  c1->cd(2);
  Pixels_per_Event_out->Draw();
  c1->Update();

  //picking up the 3rd histogram
  TFile * simAnaFile = new TFile(SimFile,"READ");
  if ( simAnaFile->IsOpen()) printf("File opened successfully\n");				    
  
				    
  char histname[256];
  sprintf(histname,"MyCMSPixelClusteringProcessor/detector_3/pixelPerEvent_d%i",ROC_DUT);

  std::cout << histname << std::endl;

  TH1I * Hits_per_Event_sim;

  Hits_per_Event_sim=(TH1I*)simAnaFile->Get("MyCMSPixelClusteringProcessor/detector_3/pixelPerEvent_d3");
  
  c1->cd(3);
 
  Hits_per_Event_sim->GetXaxis()->SetRangeUser(0,20);
 
  Hits_per_Event_sim->SetTitle("Analysis of simulated data");
 
  Hits_per_Event_sim->Draw();

  c1->Update();


  //pick up the last "original" histogram

  TFile * realAnaFile = new TFile(AnaFile,"READ");
  if ( realAnaFile->IsOpen()) printf("File opened successfully\n");				    
  
				    
  sprintf(histname,"MyCMSPixelClusteringProcessor/detector_3/pixelPerEvent_d%i",ROC_DUT);

  TH1I * Hits_per_Event_ana;


  Hits_per_Event_ana=(TH1I*)realAnaFile->Get("MyCMSPixelClusteringProcessor/detector_3/pixelPerEvent_d3");
  
  c1->cd(4);
  Hits_per_Event_ana->GetXaxis()->SetRangeUser(0,20);
  Hits_per_Event_ana->SetTitle("Analysis of measured data");
  Hits_per_Event_ana->Draw();

  c1->Update();

  char txt[256];
  sprintf(txt,"RUN%i_PixelsPerEvent.pdf",RUN);
  c1->SaveAs(txt);

  ///now for future references I'll try everything in one plot

  TCanvas * c2 = new TCanvas("c2","c2",600,600);
  c2->cd();
  //  gStyle->SetOptStat(0);

  double norm = 100.;
  std::cout << Pixels_per_Event_in->Integral() << std::endl;
  //Pixels_per_Event_out->GetXaxis()->SetLimits(0, norm);
  Pixels_per_Event_out->Scale(norm/Pixels_per_Event_out->Integral());
  Pixels_per_Event_out->SetMaximum(100);
  Pixels_per_Event_out->SetLineColor(2);
  Pixels_per_Event_out->SetLineWidth(3);
  Pixels_per_Event_out->Draw("SAME");

  Hits_per_Event_sim->Scale(norm/Hits_per_Event_sim->Integral());
  Hits_per_Event_sim->SetMaximum(100);
  Hits_per_Event_sim->SetLineColor(3);
  Hits_per_Event_sim->SetLineWidth(3);
  Hits_per_Event_sim->Draw("SAME");

  Hits_per_Event_ana->Scale(norm/Hits_per_Event_ana->Integral());
  Hits_per_Event_ana->SetMaximum(100);
  Hits_per_Event_ana->SetLineColor(4);
  Hits_per_Event_ana->SetLineWidth(3);
  Hits_per_Event_ana->Draw("SAME");

  Pixels_per_Event_in->Scale(norm/Pixels_per_Event_in->Integral());
  Pixels_per_Event_in->SetMaximum(100);
  Pixels_per_Event_in->SetLineColor(1);
  Pixels_per_Event_in->SetLineWidth(3);
  Pixels_per_Event_in->Draw("SAME");

  TLegend * leg1 = new TLegend(0.75,0.9,0.35,0.75);
  leg1->AddEntry(Pixels_per_Event_in,"DataFlow input","L");
  leg1->AddEntry(Pixels_per_Event_out,"DataFlow output","L");
  leg1->AddEntry(Hits_per_Event_sim,"Analysis of simulated data","L");
  leg1->AddEntry(Hits_per_Event_ana,"Analysis of measured data","L");


  leg1->Draw();


  c2->Update();


  sprintf(txt,"RUN%i_PixelsPerEventNorm.pdf",RUN);
  c2->SaveAs(txt);

  /*
   *  Now some more plots
   */

  //hit map
  //simulated data
  TCanvas * c3 = new TCanvas("c3","c3",1200,600);
  c3->Divide(2,1);
  c3->cd(1);
  
  sprintf(histname,"MyCMSPixelClusteringProcessor/detector_3/pixelPerEvent_d%i",ROC_DUT);

  std::cout << histname << std::endl;

  TH2D * Hit_Map_sim;


  Hit_Map_sim=(TH2D*)simAnaFile->Get("MyCMSPixelClusteringProcessor/detector_3/hitMap_d3");
  

  Hit_Map_sim->SetTitle("Analysis of simulated data");
  Hit_Map_sim->Draw("COLZ");
  Hit_Map_sim->SetStats(0);
  c3->Update();

  //measured data

  c3->cd(2);

  TH2D * Hit_Map_ana;
  

  Hit_Map_ana=(TH2D*)realAnaFile->Get("MyCMSPixelClusteringProcessor/detector_3/hitMap_d3");
  
 
  Hit_Map_ana->GetXaxis()->SetRangeUser(1,50);
  Hit_Map_ana->GetYaxis()->SetRangeUser(1,78);
  Hit_Map_ana->SetTitle("Analysis of measured data");
  Hit_Map_ana->Draw("COLZ");
  Hit_Map_ana->SetStats(0);

  char txt[256];
  sprintf(txt,"RUN%i_HitMap.pdf",RUN);
  c3->SaveAs(txt);


  /*
   *cluster size
   */

  //simulated data 
  TCanvas * c4 = new TCanvas("c4","c4",1200,600);
  c4->Divide(2,1);
  c4->cd(1);
  c4->SetLogy(1);

  sprintf(histname,"MyCMSPixelClusteringProcessor/detector_%i/clustersize_d%i",ROC_DUT,ROC_DUT);

  std::cout << histname << std::endl;

  TH1I * Clustersize_sim;


  Clustersize_sim=(TH1I*)simAnaFile->Get(histname);
  
 
  Clustersize_sim->GetXaxis()->SetRangeUser(0,20);
  Clustersize_sim->SetTitle("Analysis of simulated data");
  Clustersize_sim->Draw();
  c4->Update();

  //measured data
  c4->cd(2);
  c4->SetLogy(1);

  TH1I * Clustersize_ana;
  Clustersize_ana=(TH1I*)realAnaFile->Get(histname);
  
  Clustersize_ana->GetXaxis()->SetRangeUser(0,20);
  Clustersize_ana->SetTitle("Analysis of measured data");
  Clustersize_ana->Draw();
  c4->Update();

  sprintf(txt,"RUN%i_ClusterSize.pdf",RUN);
  c4->SaveAs(txt);
  
  /*
   *number of tracks
   */

  string simTrackFileName(SimFile);
  simTrackFileName = simTrackFileName.replace(simTrackFileName.find("clustering"), sizeof("clustering")-1,"tracks");
 
  char * filename = simTrackFileName.c_str();

  std::cout << filename << std::endl;

  TFile * simTrackFile = new TFile(filename,"READ");
  if ( simTrackFile->IsOpen()) printf("Track file opened successfully\n");				    

  TCanvas * c5 = new TCanvas("c5","c5",1200,600);
  c5->Divide(2,1);
  c5->SetLogy(1);
  c5->cd(1);
  sprintf(histname,"MyEUTelTestFitter/nTrack");
 
  std::cout << histname << std::endl;

  TH1D * NTracks_sim;
  NTracks_sim=(TH1D*)simTrackFile->Get(histname);
  NTracks_sim->SetTitle("Analysis of simulated data");
  NTracks_sim->Draw();
  c5->Update();

  string anaTrackFileName(AnaFile);
  anaTrackFileName = anaTrackFileName.replace(anaTrackFileName.find("clustering"), sizeof("clustering")-1,"tracks");
  char * filename2 = anaTrackFileName.c_str();

  TFile * anaTrackFile = new TFile(filename2,"READ");
  if ( anaTrackFile->IsOpen()) printf("Analysis track file opened successfully\n");				    

  c5->cd(2);
  c5->SetLogy(1);

  TH1D * NTracks_ana;
  NTracks_ana=(TH1D*)anaTrackFile->Get(histname);
  NTracks_ana->SetTitle("Analysis of measured data");
  NTracks_ana->Draw();
  c5->Update();

  sprintf(txt,"RUN%i_NumberOfTracks.pdf",RUN);
  c5->SaveAs(txt);



}//comparison()