// on definit les histos que l'on veut
//TH1F *h_Histo_Ursula;

TH1F *h_numEMcand;
TH1F *h_numEMgood;
TH1F *h_numEl;
TH1F *h_numTEl;

TH1F *h_EMcandpT;
TH1F *h_EMgoodpT;
TH1F *h_ElpT;

TH1F *h_EMcandiso;
TH1F *h_EMgoodiso;
TH1F *h_Eliso;

TH1F *h_EMcandEMfrac;
TH1F *h_EMgoodEMfrac;
TH1F *h_ElEMfrac;

TH1F *h_EMcandHMx8;
TH1F *h_EMgoodHMx8;
TH1F *h_ElHMx8;

TH1F *h_ElMass;

//MOOR HISTO after Emid meeting

TH2F *h_pTvsHma;


//Z histos
int ZHisPar[3]={100,0,180};
TH1F *h_invElMass;
TH1F *h_invDump;
TH1F *h_invEMgoodMass;
TH1F *h_iHiElMass;
TH1F *h_iHiDump;
TH1F *h_iHiEMgoodMass;
TH1F *h_Z_cut[4];

//quality HISTOS
TH1F *h_dphi;
TH1F *h_dz;
TH1F *h_chi2;
TH1F *h_EoverP;

//cuts histos
char *cutname[4]={"pT_","EMF","iso","Hmx"};
int chbin[4]={100,50,100,100};
float chsta[4]={0,0.5,-0.2,0};
float chend[4]={50,1.5,0.5,100};
TH1F *h_CutHistoSerie[4][4];
TH1F *h_CutHistoParal[4][4];


//histos des triggers
char *lnames[128];
bool triglist[128];
TH1F *h_trigger[4];

//jets histos
TH1F*  h_numJet;

//MET RELATED HISTOS
TH1F* h_MET;
TH1F* h_MEx;
TH1F* h_MEy
;
TH1F* h_SET;

//W histos
int WHisPar[3]={100,0,140};
TH1F* h_MT;
TH1F* h_pTW;


//step histos
TH1F *h_W_step[4];
TH1F *h_Z_step[5];

///----------------------------------------------------------------------
void HistoDecl()
//----------------------------------------------------------------------
{    
  // h_Histo_Ursula=new TH1F("h_Histo_Ursula","",100,0,30);

  //TESTJR();

    //EM histos
    h_numEMcand=new TH1F("numEMcand","Number of EM candidates",11,-0.5,10.5);
    h_numEMgood=new TH1F("numEMgood","Number of EM after cuts",11,-0.5,10.5);
    h_numEl=new TH1F("numEl","number of electrons",7,-0.5,6.5);
    h_numTEl=new TH1F("numTEl","number of electrons with a track",7,-0.5,6.5);

    h_EMcandpT=new TH1F("EMcandpT","transverse momentum of EMcandidate",chbin[0],chsta[0],chend[0]);
    h_EMgoodpT=new TH1F("EMgoodpT","transverse momentum of good EMs",chbin[0],chsta[0],chend[0]);
    h_ElpT=new TH1F("ElpT","transverse momentum of electrons",chbin[0],chsta[0],chend[0]);

    h_EMcandiso=new TH1F("EMcandiso","isolation of EMcandidates",chbin[2],chsta[2],chend[2]);
    h_EMgoodiso=new TH1F("EMgoodiso","isolation of good EMs",chbin[2],chsta[2],chend[2]);
    h_Eliso=new TH1F("Eliso","isolation of electrons",chbin[2],chsta[2],chend[2]);

    h_EMcandEMfrac=new TH1F("EMcandEMfrac","EM fraction of EMcandidates",chbin[1],chsta[1],chend[1]);
    h_EMgoodEMfrac=new TH1F("EMgoodEMfrac","EM fraction of goods EMs",chbin[1],chsta[1],chend[1]);
    h_ElEMfrac=new TH1F("ElEMfrac","EM fraction of elctrons",chbin[1],chsta[1],chend[1]);
 
    h_EMcandHMx8=new TH1F("EMcandHMx8","HMatrice",chbin[3],chsta[3],chend[3]);
    h_EMgoodHMx8=new TH1F("EMgoodHMx8","HMatrice",chbin[3],chsta[3],chend[3]);
    h_ElHMx8=new TH1F("ElHMx8","HMatrice",chbin[3],chsta[3],chend[3]);
      
    h_ElMass=new TH1F("ElMass","Mass of electrons",100,-0.02,0.02);
    h_invElMass=new TH1F("invElMass","Invariant mass of all electrons",ZHisPar[0],ZHisPar[1],ZHisPar[2]);
    h_invDump=new TH1F("invDump",",Invariant mass under 0.5 GeV",100,0,1);
    h_invEMgoodMass= new TH1F("invEMgoodMass","Invariant mass of all good EMs",ZHisPar[0],ZHisPar[1],ZHisPar[2]);
    h_iHiElMass=new TH1F("iHiElMass","invariant mass of 2 highest electrons",ZHisPar[0],ZHisPar[1],ZHisPar[2]);
    h_iHiDump=new TH1F("iHiDump","2highest mass under 0.1 GeV",100,0,0.1);
    h_iHiEMgoodMass= new TH1F("iHiEMgoodMass","invariant mass of 2highest good EMcand",ZHisPar[0],ZHisPar[1],ZHisPar[2]);

    char tex[25];
    h_pTvsHma= new TH2F ("pTvsHma","Pt versus Hmatrix8 for candidates",chbin[0],chsta[0],chend[0],chbin[3],chsta[3],chend[3]);


    //histos de test des cuts
    char stex[15]="";
    
    //cout << "fait les histo"<<endl;
    for (int i=0;i<4;++i)
      {
	sprintf(stex,"%s%s",stex,cutname[i]);
	//cout <<stex<<endl;
	for (int j=0;j<4;++j)
	  {	    
	    sprintf(tex,"%sAfterCuts%s",cutname[j],stex);
	    //cout <<tex<<endl;
	    h_CutHistoSerie[i][j] = new TH1F(tex,tex,chbin[j],chsta[j],chend[j]);
	    sprintf(tex,"%sAfterCut%sOnly",cutname[j],cutname[i]);
	    //cout <<tex<<endl;
	    h_CutHistoParal[i][j] = new TH1F(tex,tex,chbin[j],chsta[j],chend[j]);
	    
	    //cout <<"endloop j"<<endl;
	  }
	//trigger histo
	sprintf(tex,"triggerAfter%s",stex);
	h_trigger[i] = new TH1F(tex,tex,128,-0.5,127.5);
	sprintf(tex,"InvMassAfter%s",stex);
	h_Z_cut[i] = new TH1F(tex,tex,100,0,140);
      }
    
    
    //Jets histos
    h_numJet=new TH1F("numJet","number of jets",20,-0.5,20.5);
 
    //MET histos
    h_MET=new TH1F("MET","missing transverse energy",100,0,100);
    h_MEx=new TH1F("MEx","Missing t. energy in x",200,-200,200);
    h_MEy=new TH1F("MEy","Missing t. energy in y",200,-200,200);

    h_SET=new TH1F("SET","scalar Et",300,0,600);

    //W histos
    h_MT=new TH1F("MT","Transverse Mass",150,0,300);
    h_pTW=new TH1F("pTW","Transvers momentum of W boson",60,0,60);
   
    //step histos
    char Ztex[30]="Z_";
    char Wtex[30]="W_";
    char tex_step[5][15]={"Cand","pT","EMisoHmcut","1trk","2trk"};
    for (int i=0;i<5;++i)
      {
	sprintf(Ztex,"%s%s",Ztex,tex_step[i]);
	h_Z_step[i] = new TH1F(Ztex,Ztex,ZHisPar[0],ZHisPar[1],ZHisPar[2]);
	
      }
    for (int i=0;i<4;++i)
      {
	sprintf(Wtex,"%s%s",Wtex,tex_step[i]);
	h_W_step[i] = new TH1F(Wtex,Wtex,WHisPar[0],WHisPar[1],WHisPar[2]);
      }

    //quality HISTOS
    h_dphi= new TH1F("dphi","delta phi",100,-0.05,0.05);
    h_dz= new TH1F("dz","delta z",100,-10,10);
    h_chi2= new TH1F("chi2","chi2 probability",100,0,1);
    h_EoverP=new TH1F("EoverP","E/P ",100,0,3);
    

}
//----------------------------------------------------------------------
void plot()
//----------------------------------------------------------------------
{
  cout << "no plot implemented"<<endl;
}

//----------------------------------------------------------------------
void HistoToFile(char* fname)  
//----------------------------------------------------------------------
{
     // save histos to file
   
    char tex[300]="";
    
    
    sprintf(tex,"pt>%f, EMfrac<%f, iso<%f, HMx8<%f, METchoice=%d, MET>%f, from %s",PT_cut,EMcut,isocut,HMxcut,MET_choice,METcut,infile);
    if (write_events) sprintf(tex,"%s skimmed to %s",tex,skimfile);
    cout << tex <<endl;
    
    TFile *out = new TFile(fname, "recreate",tex); // creage des histos
    out->cd();
    
    h_numEMcand->Write();
    h_numEMgood->Write();
    h_numEl->Write();
    h_numTEl->Write();    
    h_numJet->Write();

    h_EMcandpT->Write();
    h_EMgoodpT->Write();
    h_ElpT->Write();

    h_EMcandiso->Write();
    h_EMgoodiso->Write();
    h_Eliso->Write();

    h_EMcandEMfrac->Write();
    h_EMgoodEMfrac->Write();
    h_ElEMfrac->Write();

    h_EMcandHMx8->Write();
    h_EMgoodHMx8->Write();
    h_ElHMx8->Write();

    h_pTvsHma->Write();

    for (int i=0;i<4;++i)
      {
	for (int j=0;j<4;++j)
	  {
	    h_CutHistoSerie[i][j]->Write();
	    h_CutHistoParal[i][j]->Write()  ;
	  }
	h_Z_cut[i]->Write();
	h_trigger[i]->Write();
      }

 
    h_ElMass->Write();
    h_invElMass->Write();
    h_invDump->Write();
    h_invEMgoodMass->Write();
    h_iHiElMass->Write();
    h_iHiDump->Write();
    h_iHiEMgoodMass->Write();

    h_MET->Write();
    h_MEx->Write();
    h_MEy->Write();
    h_SET->Write();

    h_MT->Write();
    h_pTW->Write();
    for (int i=0;i<4;++i)
      {
	h_Z_step[i]->Write();
	h_W_step[i]->Write();
      }
    h_Z_step[4]->Write();
    h_dphi->Write();
    h_dz->Write();
    h_chi2->Write();
    h_EoverP->Write();

    out->Close();
}