Index: /trunk/Makefile
===================================================================
--- /trunk/Makefile	(revision 8)
+++ /trunk/Makefile	(revision 9)
@@ -28,4 +28,22 @@
 
 
+Resolutions$(ExeSuf): \
+	tmp/Resolutions.$(ObjSuf)
+
+tmp/Resolutions.$(ObjSuf): \
+	Resolutions.cpp \
+	Utilities/ExRootAnalysis/interface/ExRootTreeReader.h \
+	Utilities/ExRootAnalysis/interface/ExRootTreeWriter.h \
+	Utilities/ExRootAnalysis/interface/ExRootTreeBranch.h \
+	Utilities/CDFCones/interface/JetCluAlgorithm.h \
+	Utilities/CDFCones/interface/MidPointAlgorithm.h \
+	Utilities/CDFCones/interface/PhysicsTower.h \
+	Utilities/CDFCones/interface/Cluster.h \
+	interface/DataConverter.h \
+	interface/HEPEVTConverter.h \
+	interface/LHEFConverter.h \
+	interface/STDHEPConverter.h \
+	interface/SmearUtil.h \
+	interface/TreeClasses.h
 Delphes$(ExeSuf): \
 	tmp/Delphes.$(ObjSuf)
@@ -46,7 +64,9 @@
 	interface/SmearUtil.h
 EXECUTABLE =  \
+	Resolutions$(ExeSuf) \
 	Delphes$(ExeSuf)
 
 EXECUTABLE_OBJ =  \
+	tmp/Resolutions.$(ObjSuf) \
 	tmp/Delphes.$(ObjSuf)
 
@@ -54,9 +74,13 @@
 	Utilities/ExRootAnalysis/src/BlockClassesLinkDef.h \
 	Utilities/ExRootAnalysis/interface/BlockClasses.h
+tmp/src/TreeClassesDict.$(SrcSuf): \
+	src/TreeClassesLinkDef.h
 DICT =  \
-	tmp/Utilities/ExRootAnalysis/src/BlockClassesDict.$(SrcSuf)
+	tmp/Utilities/ExRootAnalysis/src/BlockClassesDict.$(SrcSuf) \
+	tmp/src/TreeClassesDict.$(SrcSuf)
 
 DICT_OBJ =  \
-	tmp/Utilities/ExRootAnalysis/src/BlockClassesDict.$(ObjSuf)
+	tmp/Utilities/ExRootAnalysis/src/BlockClassesDict.$(ObjSuf) \
+	tmp/src/TreeClassesDict.$(ObjSuf)
 
 tmp/src/STDHEPConverter.$(ObjSuf): \
@@ -70,4 +94,7 @@
 	Utilities/stdhep/stdhep_declarations.h \
 	interface/STDHEPConverter.h
+tmp/src/TreeClasses.$(ObjSuf): \
+	src/TreeClasses.$(SrcSuf) \
+	interface/TreeClasses.h
 tmp/src/LHEFConverter.$(ObjSuf): \
 	src/LHEFConverter.$(SrcSuf) \
@@ -169,4 +196,5 @@
 SOURCE_OBJ =  \
 	tmp/src/STDHEPConverter.$(ObjSuf) \
+	tmp/src/TreeClasses.$(ObjSuf) \
 	tmp/src/LHEFConverter.$(ObjSuf) \
 	tmp/src/HEPEVTConverter.$(ObjSuf) \
@@ -228,15 +256,52 @@
 	Utilities/mcfio/mcf_ntubldInit.c
 tmp/Utilities/stdhep/mcf_hepev4_xdr.$(ObjSuf): \
-	Utilities/stdhep/mcf_hepev4_xdr.c
+	Utilities/stdhep/mcf_hepev4_xdr.c \
+	Utilities/mcfio/mcfio_Dict.h \
+	Utilities/mcfio/mcf_xdr.h \
+	Utilities/stdhep/stdhep.h \
+	Utilities/stdhep/hepev4.h \
+	Utilities/stdhep/stdtmp.h \
+	Utilities/stdhep/stdver.h
 tmp/Utilities/stdhep/mcf_stdcm1_xdr.$(ObjSuf): \
-	Utilities/stdhep/mcf_stdcm1_xdr.c
+	Utilities/stdhep/mcf_stdcm1_xdr.c \
+	Utilities/mcfio/mcfio_Dict.h \
+	Utilities/mcfio/mcf_xdr.h \
+	Utilities/stdhep/stdcm1.h \
+	Utilities/stdhep/stdver.h
 tmp/Utilities/stdhep/mcf_hepup_xdr.$(ObjSuf): \
-	Utilities/stdhep/mcf_hepup_xdr.c
+	Utilities/stdhep/mcf_hepup_xdr.c \
+	Utilities/mcfio/mcfio_Dict.h \
+	Utilities/mcfio/mcf_xdr.h \
+	Utilities/stdhep/hepeup.h \
+	Utilities/stdhep/heprup.h \
+	Utilities/stdhep/stdver.h
 tmp/Utilities/stdhep/mcf_Stdhep_xdr.$(ObjSuf): \
-	Utilities/stdhep/mcf_Stdhep_xdr.c
+	Utilities/stdhep/mcf_Stdhep_xdr.c \
+	Utilities/mcfio/mcfio_Dict.h \
+	Utilities/mcfio/mcf_xdr.h \
+	Utilities/stdhep/stdhep.h \
+	Utilities/stdhep/stdtmp.h \
+	Utilities/stdhep/stdver.h
 tmp/Utilities/stdhep/stdhep_internal_utils.$(ObjSuf): \
-	Utilities/stdhep/stdhep_internal_utils.c
+	Utilities/stdhep/stdhep_internal_utils.c \
+	Utilities/stdhep/stdhep.h \
+	Utilities/stdhep/hepev4.h \
+	Utilities/stdhep/stdtmp.h \
+	Utilities/stdhep/hepeup.h
 tmp/Utilities/stdhep/stdhep_mcfio.$(ObjSuf): \
-	Utilities/stdhep/stdhep_mcfio.c
+	Utilities/stdhep/stdhep_mcfio.c \
+	Utilities/mcfio/mcf_xdr.h \
+	Utilities/mcfio/mcfio_Block.h \
+	Utilities/mcfio/mcfio_Dict.h \
+	Utilities/mcfio/mcfio_Direct.h \
+	Utilities/mcfio/mcfio_Util1.h \
+	Utilities/stdhep/stdhep.h \
+	Utilities/stdhep/hepev4.h \
+	Utilities/stdhep/hepeup.h \
+	Utilities/stdhep/heprup.h \
+	Utilities/stdhep/stdtmp.h \
+	Utilities/stdhep/stdhd.h \
+	Utilities/stdhep/stdcnt.h \
+	Utilities/stdhep/stdhep_mcfio.h
 STDHEP_OBJ =  \
 	tmp/Utilities/mcfio/mcf_ntuBldDbinc.$(ObjSuf) \
@@ -274,4 +339,9 @@
 	@touch $@
 
+interface/TreeClasses.h: \
+	Utilities/ExRootAnalysis/interface/BlockCompare.h \
+	Utilities/ExRootAnalysis/interface/BlockClasses.h
+	@touch $@
+
 interface/SmearUtil.h: \
 	Utilities/ExRootAnalysis/interface/BlockClasses.h \
@@ -290,4 +360,16 @@
 	Utilities/CDFCones/interface/LorentzVector.h \
 	Utilities/CDFCones/interface/Centroid.h
+	@touch $@
+
+Utilities/stdhep/stdhep_declarations.h: \
+	Utilities/stdhep/stdhep.h \
+	Utilities/stdhep/hepev4.h \
+	Utilities/stdhep/hepeup.h \
+	Utilities/stdhep/heprup.h \
+	Utilities/stdhep/stdtmp.h \
+	Utilities/stdhep/stdhd.h \
+	Utilities/stdhep/stdcnt.h \
+	Utilities/stdhep/stdcm1.h \
+	Utilities/stdhep/stdver.h
 	@touch $@
 
Index: /trunk/README
===================================================================
--- /trunk/README	(revision 8)
+++ /trunk/README	(revision 9)
@@ -42,2 +42,3 @@
 stdhep.ps -> page9 = HEPCHG(ID) : get charge for particle ID
 
+
Index: /trunk/Resolutions.cpp
===================================================================
--- /trunk/Resolutions.cpp	(revision 9)
+++ /trunk/Resolutions.cpp	(revision 9)
@@ -0,0 +1,292 @@
+/*
+  ---- FastSim ----
+  A Fast Simulator for general purpose LHC detector
+  S. Ovyn ~~~~ severine.ovyn@uclouvain.be
+
+  Center for Particle Physics and Phenomenology (CP3)
+  Universite Catholique de Louvain (UCL)
+  Louvain-la-Neuve, Belgium
+*/
+
+/// \file Smearing.cpp
+/// \brief executable for the FastSim
+
+#include "TChain.h"
+#include "TApplication.h"
+
+#include "Utilities/ExRootAnalysis/interface/ExRootTreeReader.h"
+#include "Utilities/ExRootAnalysis/interface/ExRootTreeWriter.h"
+#include "Utilities/ExRootAnalysis/interface/ExRootTreeBranch.h"
+
+#include "Utilities/CDFCones/interface/JetCluAlgorithm.h"
+#include "Utilities/CDFCones/interface/MidPointAlgorithm.h"
+#include "Utilities/CDFCones/interface/PhysicsTower.h"
+#include "Utilities/CDFCones/interface/Cluster.h"
+
+#include "interface/DataConverter.h"
+#include "interface/HEPEVTConverter.h"
+#include "interface/LHEFConverter.h"
+#include "interface/STDHEPConverter.h"
+#include "interface/SmearUtil.h"
+#include "interface/TreeClasses.h"
+
+using namespace std;
+
+//------------------------------------------------------------------------------
+
+
+
+void PairingJet(TLorentzVector &JETSm, TLorentzVector JET, vector<Cluster> jetsS)
+{
+  JETSm.SetPxPyPzE(0,0,0,0);
+  vector<Cluster>::iterator itJetS;
+  float deltaRtest=5000;
+  LorentzVector jetMomentumS;
+  for(itJetS = jetsS.begin(); itJetS != jetsS.end(); ++itJetS) 
+     {
+       jetMomentumS = itJetS->fourVector;
+       TLorentzVector Att;
+       Att.SetPxPyPzE(jetMomentumS.px,jetMomentumS.py,jetMomentumS.pz,jetMomentumS.E);
+       if(DeltaR(JET.Phi(),JET.Eta(),Att.Phi(),Att.Eta()) < deltaRtest)
+            {
+              deltaRtest = DeltaR(JET.Phi(),JET.Eta(),Att.Phi(),Att.Eta());
+              if(deltaRtest < 0.25)
+                {
+                  JETSm = Att;
+                }
+            }
+     }
+}
+
+
+int main(int argc, char *argv[])
+{
+  int appargc = 2;
+  char *appName = "Smearing";
+  char *appargv[] = {appName, "-b"};
+  TApplication app(appName, &appargc, appargv);
+  
+  if(argc != 4 && argc != 3) {
+      cout << " Usage: " << argv[0] << " input_file" << " output_file" << " data_card " << endl;
+      cout << " input_list - list of files in Ntpl, StdHep of LHEF format," << endl;
+      cout << " output_file - output file." << endl;
+      cout << " data_card - Datacard containing resolution variables for the detector simulation (optional) "<<endl;
+      exit(1);
+  }
+
+  srand (time (NULL));         /* Initialisation du gÃ©nÃ©rateur */
+  
+  //read the input TROOT file
+  string inputFileList(argv[1]), outputfilename(argv[2]);
+  if(outputfilename.find(".root") > outputfilename.length() ) {
+    cout << "output_file should be a .root file!\n";
+    return -1;
+  }
+  TFile *outputFile = TFile::Open(outputfilename.c_str(), "RECREATE"); // Creates the file, but should be closed just after
+  outputFile->Close();
+
+  string line;
+  ifstream infile(inputFileList.c_str());
+  infile >> line; // the first line determines the type of input files
+ 
+  DataConverter *converter=0;
+   
+  if(strstr(line.c_str(),".hep"))
+    {                           
+      cout<<"*************************************************************************"<<endl;
+      cout<<"************         StdHEP file format detected           **************"<<endl;
+      cout<<"************     Starting convertion to TRoot format       **************"<<endl;
+      cout<<"*************************************************************************"<<endl;
+      converter = new STDHEPConverter(inputFileList,outputfilename);//case ntpl file in input list
+    }
+  else if(strstr(line.c_str(),".lhe"))
+    {
+      cout<<"*************************************************************************"<<endl;
+      cout<<"************          LHEF file format detected            **************"<<endl;
+      cout<<"************     Starting convertion to TRoot format       **************"<<endl;
+      cout<<"*************************************************************************"<<endl;
+      converter = new LHEFConverter(inputFileList,outputfilename);//case ntpl file in input list
+    }
+  else if(strstr(line.c_str(),".root"))
+    {
+      cout<<"*************************************************************************"<<endl;
+      cout<<"************         h2root file format detected           **************"<<endl;
+      cout<<"************     Starting convertion to TRoot format       **************"<<endl;
+      cout<<"*************************************************************************"<<endl;
+      converter = new HEPEVTConverter(inputFileList,outputfilename);//case ntpl file in input list
+    }
+  else { cout << "***  " << line.c_str() << "\n***  file format not identified\n***  Exiting\n"; return -1;};
+
+  TChain chain("GEN");
+  chain.Add(outputfilename.c_str());
+  ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
+  const TClonesArray *branchGen = treeReader->UseBranch("Particle");
+  TIter itGen((TCollection*)branchGen);
+  
+  //write the output root file
+  ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputfilename, "Analysis");
+  ExRootTreeBranch *branchjet = treeWriter->NewBranch("JetPTResol", RESOLJET::Class());
+  ExRootTreeBranch *branchelec = treeWriter->NewBranch("ElecEResol", RESOLELEC::Class());
+  ExRootTreeBranch *branchmuon = treeWriter->NewBranch("MuonPTResol", RESOLMUON::Class());
+  ExRootTreeBranch *branchtaujet = treeWriter->NewBranch("TauJetPTResol", TAUHAD::Class());
+  ExRootTreeBranch *branchetmis = treeWriter->NewBranch("ETmisResol",ETMIS::Class());
+
+  TRootGenParticle *particle;
+  TRootETmis *etmisc;
+
+  RESOLELEC *elementElec;
+  RESOLMUON *elementMuon;
+  RESOLJET *elementJet;
+  TAUHAD *elementTaujet;
+  ETMIS *elementEtmis;
+
+ 
+  //read the datacard input file
+  string DetDatacard("");
+  if(argc==4)  DetDatacard =argv[3];
+  RESOLution *DET = new RESOLution();   
+  DET->ReadDataCard(DetDatacard);
+  
+  
+  TLorentzVector genMomentum(0,0,0,0);
+  LorentzVector jetMomentum;
+  vector<TLorentzVector> TrackCentral;  
+  vector<PhysicsTower> towersS;
+  vector<Cluster> jetsS; 
+  vector<PhysicsTower> towers;
+  vector<Cluster> jets;
+
+ 
+  // Loop over all events
+  Long64_t entry, allEntries = treeReader->GetEntries();
+  cout << "** Chain contains " << allEntries << " events" << endl;
+  for(entry = 0; entry < allEntries; ++entry)
+    {
+      TLorentzVector PTmis(0,0,0,0);
+      treeReader->ReadEntry(entry);
+      treeWriter->Clear();
+      
+      if((entry % 100) == 0 && entry > 0 )  cout << "** Processing element # " << entry << endl;
+      
+      TSimpleArray<TRootGenParticle> bGen;
+      itGen.Reset();
+      TrackCentral.clear();
+      towers.clear();
+      towersS.clear();
+      TSimpleArray<TRootGenParticle> NFCentralQ;
+
+
+      // Loop over all particles in event
+      while( (particle = (TRootGenParticle*) itGen.Next()) )
+	{
+          genMomentum.SetPxPyPzE(particle->Px, particle->Py, particle->Pz, particle->E);
+
+	  int pid = abs(particle->PID);
+	  float eta = fabs(particle->Eta);
+
+if(particle->Status == 1)towers.push_back(PhysicsTower(LorentzVector(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E())));
+
+	  // keeps only final particles, visible by the central detector, including the fiducial volume
+	  // the ordering of conditions have been optimised for speed : put first the STATUS condition
+          if( (particle->Status == 1)    &&
+	      ( 
+		(pid == pMU  && eta < DET->MAX_MU) ||
+                (pid != pMU  && (pid != pNU1) && (pid != pNU2) && (pid != pNU3) && eta < DET->MAX_CALO_FWD) 
+              )
+            ) {
+		switch(pid) {
+		    
+		    case pE: // all electrons with eta < DET->MAX_CALO_FWD
+		      DET->SmearElectron(genMomentum);
+		      break; // case pE
+
+		    case pGAMMA: // all photons with eta < DET->MAX_CALO_FWD
+		      DET->SmearElectron(genMomentum);
+		      break; // case pGAMMA
+
+		    case pMU: // all muons with eta < DET->MAX_MU
+		      DET->SmearMu(genMomentum);
+		      break; // case pMU
+
+		    case pLAMBDA: // all lambdas with eta < DET->MAX_CALO_FWD
+		    case pK0S:    // all K0s with eta < DET->MAX_CALO_FWD
+		      DET->SmearHadron(genMomentum, 0.7);
+		      break; // case hadron
+		      
+		    default:   // all other final particles with eta < DET->MAX_CALO_FWD
+		      DET->SmearHadron(genMomentum, 1.0);
+		      break;
+		} // switch (pid)
+
+		// all final particles but muons and neutrinos	
+		// for calorimetric towers and mission PT
+                if(genMomentum.E()!=0) PTmis = PTmis + genMomentum;//ptmis
+
+		if(pid != pMU && genMomentum.Pt() > DET->PT_TRACKS_MIN)
+                towersS.push_back
+                 (
+                   PhysicsTower
+                    (
+                      LorentzVector(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E())
+                    )
+                 );
+		// all final charged particles
+		if(
+		     ((rand()%100) < DET->TRACKING_EFF)  &&
+		     (genMomentum.E()!=0) &&
+		     (fabs(particle->Eta) < DET->MAX_TRACKER) && 
+		     (genMomentum.Pt() > DET->PT_TRACKS_MIN ) &&     // pt too small to be taken into account
+		     (pid != pGAMMA)    && 
+		     (pid != pPI0)      &&
+		     (pid != pK0L)      &&
+		     (pid != pN)        &&
+		     (pid != pSIGMA0)   &&
+		     (pid != pDELTA0)   &&
+		     (pid != pK0S)   // not charged particles : invisible by tracker
+                 )
+		      TrackCentral.push_back(genMomentum);
+	    } // switch
+	} // while
+
+
+      //*****************************
+      JetCluAlgorithm jetAlgoS(1,DET->CONERADIUS,DET->C_ADJACENCYCUT,DET->C_MAXITERATIONS,DET->C_IRATCH,DET->C_OVERLAPTHRESHOLD);
+      jetAlgoS.run(towersS, jetsS);
+
+      JetCluAlgorithm jetAlgo(0,DET->CONERADIUS,DET->C_ADJACENCYCUT,DET->C_MAXITERATIONS,DET->C_IRATCH,DET->C_OVERLAPTHRESHOLD);
+      jetAlgo.run(towers, jets);
+
+
+      vector<Cluster>::iterator itJet;
+      TLorentzVector JETSm(0,0,0,0);
+      for(itJet = jets.begin(); itJet != jets.end(); ++itJet) {
+          jetMomentum = itJet->fourVector;
+          TLorentzVector JET(0,0,0,0);
+          JET.SetPxPyPzE(jetMomentum.px,jetMomentum.py,jetMomentum.pz,jetMomentum.E);
+          PairingJet(JETSm,JET,jetsS);
+          if(JETSm.Pt()>3)
+            {
+              elementJet= (RESOLJET*) branchjet->NewEntry();
+              elementJet->NonSmearePT = JET.Pt();
+              elementJet->SmearePT = (JETSm.Pt()/JET.Pt());
+              /*cout<<"valeur obtenue "<<JETSm.Pt()/JET.Pt()<<endl;
+              cout<<" pt non smeare "<<JET.Pt()<<" phi "<<JET.Phi()<<" eta "<<JET.Eta()<<endl;
+              cout<<"pt smeare "<<JETSm.Pt()<<" phi "<<JETSm.Phi()<<" eta "<<JETSm.Eta()<<endl;
+              cout<<"************"<<endl;
+*/
+            }
+
+	} // for itJet : loop on all jets
+
+      treeWriter->Fill();
+    } // Loop over all events
+  treeWriter->Write();
+  
+  cout << "** Exiting..." << endl;
+  
+  delete treeWriter;
+  delete treeReader;
+  delete DET;
+  if(converter) delete converter;
+}
+
Index: /trunk/TODO
===================================================================
--- /trunk/TODO	(revision 8)
+++ /trunk/TODO	(revision 9)
@@ -12,2 +12,3 @@
  - vÃ©rifier les unitÃ©s des toutes les valeurs dans les ttree
  - vÃ©rifier que les valeurs par dÃ©faut sont Ã©gales Ã  celles de la datacard par dÃ©faut
+ - ajouter FastJet
Index: /trunk/genMakefile.tcl
===================================================================
--- /trunk/genMakefile.tcl	(revision 8)
+++ /trunk/genMakefile.tcl	(revision 9)
@@ -126,5 +126,5 @@
   global prefix suffix objSuf exeSuf
    
-  set executable [glob -nocomplain {Delphes.cpp} ]
+  set executable [glob -nocomplain {Delphes.cpp} {Resolutions.cpp}]
                                 
   set exeFiles {}
@@ -232,5 +232,5 @@
 executableDeps {*.cpp} 
 
-dictDeps {DICT} {Utilities/ExRootAnalysis/src/*LinkDef.h}
+dictDeps {DICT} {Utilities/ExRootAnalysis/src/*LinkDef.h} {src/*LinkDef.h}
 
 sourceDeps {SOURCE} {src/*.cc} {Utilities/ExRootAnalysis/src/*.cc} {Utilities/Hector/src/*.cc} {Utilities/CDFCones/src/*cc} 
Index: /trunk/routines/resolutions.C
===================================================================
--- /trunk/routines/resolutions.C	(revision 9)
+++ /trunk/routines/resolutions.C	(revision 9)
@@ -0,0 +1,97 @@
+#include "TROOT.h"
+#include "TFile.h"
+#include "TTree.h"
+#include "TCanvas.h"
+#include "TProfile.h"
+#include "TF1.h"
+#include "TGraph.h"
+
+#include "interface/FuncDef.h"
+
+void Plot()
+{
+
+  setTDRStyle();
+  gROOT->Reset();
+
+  TFile *f1 = new TFile("Smearing.root","read");
+  TTree *Analyze = (TTree*)f1->Get("Analysis");
+
+
+//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
+//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
+
+   TCanvas *c1 = new TCanvas("c1","gerrors2",100,100,600,450);
+   c1->cd(); 
+  
+   const Int_t numBin=5;
+//   double bins[numBin]={5,10,25,55,85,115,205,400};
+   double bins[5]={10,30,50,80,120};
+   TProfile *ETSoverET = new TProfile("ETSoverET","Resolution des electrons",(numBin-1),bins,-10,10);
+   Analyze->Draw("JetPTResol.SmearePT:JetPTResol.NonSmearePT>>ETSoverET","JetPTResol.NonSmearePT>1");
+
+   double rms[numBin];
+   double mean[numBin];
+   //TF1 *Gauss = new TF1("Gauss","gaus",0,4);
+
+   TCanvas *c2 = new TCanvas("c2","gerrors2",0,0,1000,650);
+   c2->cd(); int frame=0;
+   c2->Divide(6,2);
+//   c2->Divide(6,2);
+
+   float x[numBin];
+   float y[numBin];
+   float finval=0;//valeur a remplir puis a fitter
+
+   for ( int i=0; i<numBin; i++)  // premiÃšre bin : i ==1 et pas i == 0
+      {
+        TAxis *xaxis = ETSoverET->GetXaxis();
+        float binCenter = xaxis->GetBinCenter(i+1);
+        int binMin = (int)xaxis->GetBinLowEdge(i+1);
+        int binMax = (int)xaxis->GetBinUpEdge(i+1);
+        cout<<"binMin "<<binMin<<" binMax "<<binMax<<" bin center "<<binCenter<<endl;
+        char tempMin[500];
+        sprintf(tempMin,"JetPTResol.NonSmearePT>%d",binMin);
+        string mystringMin(tempMin);
+        char tempMax[500];
+        sprintf(tempMax,"JetPTResol.NonSmearePT<%d",binMax);
+        string mystringMax(tempMax);
+        char tempName[500];
+        sprintf(tempName,"JetPTResol.SmearePT>>hETSoverET%d",i);
+        string mystringName(tempName);
+
+        c2->cd(++frame);
+        GaussValues(Analyze,tempName,rms[i],mean[i],mystringMin,mystringMax);
+        x[i]=binCenter;
+        mean[i]=ETSoverET->GetBinContent(i+1);
+   //     rms[i]=ETSoverET->GetBinError(i+1);
+        finval=rms[i]/mean[i];
+        y[i]=finval;
+        cout<<"finval "<<finval<<" mean val "<<mean[i]<<" rms value "<<rms[i]<<endl;
+
+      }
+
+y[0]=0.2;
+
+   TCanvas *c3 = new TCanvas("c3","gerrors2",100,100,600,450);
+   c3->cd();
+
+   TF1 *fitfun = new TF1("user","sqrt(pow([0],2)+pow([1]/sqrt(x),2)+pow([2]/x,2))",10,500);
+
+   TGraph *gr11 = new TGraph((numBin),x,y);
+   gr11->Draw("AP");
+   gr11->GetXaxis()->SetTitle("E_{T}^{MC} [GeV]");
+   gr11->GetYaxis()->SetTitle("#sigma(E_{T}^{rec}/E_{T}^{MC})/<E_{T}^{rec}/E_{T}^{MC}>");
+
+   //fitfun->FixParameter(0,0.0541930);
+   //fitfun->FixParameter(1,0.634908);
+   gr11->Fit("user","RQ");
+   gr11->Fit("user","RQ");
+   gr11->Fit("user","RQ");
+   gr11->Fit("user","R");
+
+
+
+ delete fitfun;
+// delete Gauss;
+}
Index: /trunk/src/SmearUtil.cc
===================================================================
--- /trunk/src/SmearUtil.cc	(revision 8)
+++ /trunk/src/SmearUtil.cc	(revision 9)
@@ -213,13 +213,16 @@
   
   if(fabs(hadron.Eta()) < MAX_CALO_CEN) {
-    energyS = gRandom->Gaus(energy_hcal, sqrt(
+    float energyS1 = gRandom->Gaus(energy_hcal, sqrt(
 					      pow(HAD_Nhcal,2) +
 					      pow(HAD_Chcal*energy_hcal,2) + 
-					      pow(HAD_Shcal*sqrt(energy_hcal),2) )) 
-      +
-      gRandom->Gaus(energy_ecal, sqrt(
+					      pow(HAD_Shcal*sqrt(energy_hcal),2) )) ;
+      
+    float energyS2 = gRandom->Gaus(energy_ecal, sqrt(
 				      pow(HAD_Necal,2) +
 				      pow(HAD_Cecal*energy_ecal,2) + 
-				      pow(HAD_Secal*sqrt(energy_ecal),2) ) );     
+				      pow(HAD_Secal*sqrt(energy_ecal),2) ) );
+
+	energyS = (energyS1>0)?energyS1:0 + (energyS2>0)?energyS2:0;
+	cout << "avant: " << energyS1 + energyS2 << "\t\t" << energyS << endl;
   } else { 
     energyS = gRandom->Gaus(energy, 
