Index: /trunk/Delphes.cpp
===================================================================
--- /trunk/Delphes.cpp	(revision 73)
+++ /trunk/Delphes.cpp	(revision 74)
@@ -179,4 +179,6 @@
   vector<ParticleUtil> electron;
   vector<ParticleUtil> muon;
+  vector<ParticleUtil> gamma;
+  
   TSimpleArray<TRootGenParticle> NFCentralQ;
   
@@ -195,7 +197,7 @@
       electron.clear();
       muon.clear();
+      gamma.clear();
       NFCentralQ.Clear();
       
-      itGen.Reset();
       TrackCentral.clear();
       towers.clear();
@@ -203,4 +205,5 @@
       
       // Loop over all particles in event
+      itGen.Reset();
       while( (particle = (TRootGenParticle*) itGen.Next()) )
 	{
@@ -232,15 +235,20 @@
 	    case pE: // all electrons with eta < DET->MAX_CALO_FWD
               DET->SmearElectron(genMomentum);
+              if(genMomentum.E()!=0 && eta < DET->MAX_TRACKER && genMomentum.Pt() > DET->ELEC_pt){
+	      electron.push_back(ParticleUtil(genMomentum,particle->PID));
+              }
 	      electron.push_back(ParticleUtil(genMomentum,particle->PID));
 	      break; // case pE
 	    case pGAMMA: // all photons with eta < DET->MAX_CALO_FWD
 	      DET->SmearElectron(genMomentum);
-	      if(genMomentum.E()!=0 && eta < DET->MAX_TRACKER) {
-		elementPhoton = (TRootPhoton*) branchPhoton->NewEntry();
-		elementPhoton->Set(genMomentum);
+	      if(genMomentum.E()!=0 && eta < DET->MAX_TRACKER && genMomentum.Pt() > DET->GAMMA_pt) {
+                gamma.push_back(ParticleUtil(genMomentum,particle->PID));
 	      }
 	      break; // case pGAMMA
 	    case pMU: // all muons with eta < DET->MAX_MU
 	      DET->SmearMu(genMomentum);
+              if(genMomentum.E()!=0 && eta < DET->MAX_MU &&  genMomentum.Pt() > DET->MUON_pt){
+	      muon.push_back(ParticleUtil(genMomentum,particle->PID));
+              }
 	      muon.push_back(ParticleUtil(genMomentum,particle->PID));
 	      break; // case pMU
@@ -253,10 +261,10 @@
 	      break;
 	    } // switch (pid)
-
+	    
 	    // all final particles but muons and neutrinos	
 	    // for calorimetric towers and mission PT
-	    
-	    if(genMomentum.E() !=0) {
-	      if(pid !=pMU) {
+	    int charge=Charge(pid); 
+	    if(genMomentum.E() !=0 && pid != pMU) {
+	      if(charge == 0 || (charge !=0 && genMomentum.Pt() >= DET->PT_TRACKS_MIN)){
                 PhysicsTower CaloTower = PhysicsTower(LorentzVector(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()));
     		towers.push_back(CaloTower);
@@ -266,4 +274,5 @@
                 
                 genMomentumCalo.SetPxPyPzE(CaloTower.fourVector.px,CaloTower.fourVector.py,CaloTower.fourVector.pz,CaloTower.fourVector.E);
+		
 		elementCalo = (TRootCalo*) branchCalo->NewEntry();
 		elementCalo->Set(genMomentumCalo);
@@ -274,15 +283,9 @@
 	    // all final charged particles
 	    if(
-	       ((rand()%100) < DET->TRACKING_EFF)  &&
 	       (genMomentum.E()!=0) &&
 	       (fabs(genMomentum.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
+               (genMomentum.Pt() > DET->PT_TRACKS_MIN ) &&     // pt too small to be taken into account
+               ((rand()%100) < DET->TRACKING_EFF)  &&
+               (charge!=0)
 	       )
 	      {
@@ -291,6 +294,6 @@
 		TrackCentral.push_back(genMomentum);
 	      }
-
-	  } // switch
+	    
+	    } // switch
 	  
           VFD->ZDC(treeWriter,branchZDC,particle);
@@ -299,21 +302,22 @@
 	} // while
       
-        for(unsigned int i=0; i < electron.size(); i++) {
-	if(electron[i].E()!=0 && fabs(electron[i].Eta()) < DET->MAX_TRACKER && electron[i].Pt() > DET->ELEC_pt)
-	  {
-	    elementElec = (TRootElectron*) branchElectron->NewEntry();
-	    elementElec->Set(electron[i].Px(),electron[i].Py(),electron[i].Pz(),electron[i].E());
-	    elementElec->Charge = sign(electron[i].PID());
-	    elementElec->IsolFlag = DET->Isolation(electron[i].Phi(),electron[i].Eta(),TrackCentral,2.0);
-	  }
+      DET->SortedVector(electron); 
+      for(unsigned int i=0; i < electron.size(); i++) {
+        elementElec = (TRootElectron*) branchElectron->NewEntry();
+        elementElec->Set(electron[i].Px(),electron[i].Py(),electron[i].Pz(),electron[i].E());
+        elementElec->Charge = sign(electron[i].PID());
+        elementElec->IsolFlag = DET->Isolation(electron[i].Phi(),electron[i].Eta(),TrackCentral,2.0);
       }
+      DET->SortedVector(muon);
       for(unsigned int i=0; i < muon.size(); i++) {
-	if(muon[i].E()!=0 && fabs(muon[i].Eta()) < DET->MAX_MU && muon[i].Pt() > DET->MUON_pt) 
-	  {
-	    elementMu = (TRootMuon*) branchMuon->NewEntry();
-	    elementMu->Charge = sign(muon[i].PID());
-	    elementMu->Set(muon[i].Px(),muon[i].Py(),muon[i].Pz(),muon[i].E());
-	    elementMu->IsolFlag = DET->Isolation(muon[i].Phi(),muon[i].Eta(),TrackCentral,2.0);
-	  }
+        elementMu = (TRootMuon*) branchMuon->NewEntry();
+        elementMu->Charge = sign(muon[i].PID());
+        elementMu->Set(muon[i].Px(),muon[i].Py(),muon[i].Pz(),muon[i].E());
+        elementMu->IsolFlag = DET->Isolation(muon[i].Phi(),muon[i].Eta(),TrackCentral,2.0);
+      }
+      DET->SortedVector(gamma);
+      for(unsigned int i=0; i < gamma.size(); i++) {
+	elementPhoton = (TRootPhoton*) branchPhoton->NewEntry();
+	elementPhoton->Set(gamma[i].Px(),gamma[i].Py(),gamma[i].Pz(),gamma[i].E());
       }
       
@@ -330,5 +334,5 @@
       elementEtmis->Px = (-PTmis).Px();
       elementEtmis->Py = (-PTmis).Py();
-
+      
       //*****************************
       
@@ -336,14 +340,15 @@
       JETRUN->RunJetBtagging(treeWriter, branchJet,sorted_jets,NFCentralQ);
       JETRUN->RunTauJets(treeWriter,branchTauJet,sorted_jets,towers, TrackCentral);
-
+      
       // Add here the trigger
       // Should test all the trigger table on the event, based on reconstructed objects
       treeWriter->Fill();
-    
+      
     } // Loop over all events
-
+  
   treeWriter->Write();
-  delete treeWriter;
-
+ 
+  //running the trigger in case the FLAG trigger is put to 1 in the datacard
+ 
   if(DET->DOTRIGGER == 1)
     {
@@ -351,5 +356,5 @@
       chainT.Add(outputfilename.c_str());
       ExRootTreeReader *treeReaderT = new ExRootTreeReader(&chainT);
-
+      
       TClonesArray *branchElecTrig = treeReaderT->UseBranch("Electron");
       TClonesArray *branchMuonTrig = treeReaderT->UseBranch("Muon");
@@ -358,8 +363,8 @@
       TClonesArray *branchPhotonTrig = treeReaderT->UseBranch("Photon");
       TClonesArray *branchETmisTrig = treeReaderT->UseBranch("ETmis");
-
+      
       ExRootTreeWriter *treeWriterT = new ExRootTreeWriter(outputfilename, "Trigger");
       ExRootTreeBranch *branchTrigger = treeWriterT->NewBranch("TrigResult", TRootTrigger::Class());
-
+      
       Long64_t entryT, allEntriesT = treeReaderT->GetEntries();
       cout << "** Chain contains " << allEntriesT << " events" << endl;
@@ -379,5 +384,11 @@
   
   delete treeReader;
+  delete treeWriter;
   delete DET;
+  delete TRIGT;
+  delete TRACP;
+  delete JETRUN;
+  delete VFD;
+ 
   if(converter) delete converter;
 
Index: /trunk/interface/SmearUtil.h
===================================================================
--- /trunk/interface/SmearUtil.h	(revision 73)
+++ /trunk/interface/SmearUtil.h	(revision 74)
@@ -108,4 +108,5 @@
   float MUON_pt;
   float JET_pt;
+  float GAMMA_pt;
   float TAUJET_pt;
  
@@ -156,4 +157,6 @@
   float * TOWER_DPHI; 
 
+  // to sort a vector
+  void SortedVector(vector<ParticleUtil> &vect);
 
   /// Reads the data card for the initialisation of the parameters 
Index: /trunk/src/SmearUtil.cc
===================================================================
--- /trunk/src/SmearUtil.cc	(revision 73)
+++ /trunk/src/SmearUtil.cc	(revision 74)
@@ -68,4 +68,5 @@
 MUON_pt =         10.0;
 JET_pt =          20.0;
+GAMMA_pt =        10.0;
 TAUJET_pt =       10.0;
 
@@ -178,4 +179,5 @@
     else if(strstr(temp_string.c_str(),"MUON_pt")){curstring >> varname >> value; MUON_pt = value;}
     else if(strstr(temp_string.c_str(),"JET_pt")){curstring >> varname >> value; JET_pt = value;}
+    else if(strstr(temp_string.c_str(),"GAMMA_pt")){curstring >> varname >> value; GAMMA_pt = value;}
     else if(strstr(temp_string.c_str(),"TAUJET_pt")){curstring >> varname >> value; TAUJET_pt = value;}
     else if(strstr(temp_string.c_str(),"NTOWERS")){curstring >> varname >> ivalue; NTOWERS = ivalue;}
@@ -392,4 +394,6 @@
   f_out << left << setw(40) <<"* Minimum pT for Tau-jets: "<<""
 	<< left << setw(20) <<TAUJET_pt         <<""<< right << setw(10)<<"*"<<"\n";
+  f_out << left << setw(40) <<"* Minimum pT for photons: "<<""
+        << left << setw(20) <<GAMMA_pt         <<""<< right << setw(10)<<"*"<<"\n";
   f_out<<"*                                                                    *"<<"\n";
   f_out<<"#***************************                                         *"<<"\n";
@@ -595,4 +599,28 @@
     
 }*/
+
+//******************************************************************************************
+
+void RESOLution::SortedVector(vector<ParticleUtil> &vect)
+{
+  int i,j = 0;
+  TLorentzVector tmp;
+  bool en_desordre = true;
+  int entries=vect.size();
+  for(i = 0 ; (i < entries) && en_desordre; i++)
+    {
+      en_desordre = false;
+      for(j = 1 ; j < entries - i ; j++)
+        {
+          if ( vect[j].Pt() > vect[j-1].Pt() )
+             {
+               ParticleUtil tmp = vect[j-1];
+               vect[j-1] = vect[j];
+               vect[j] = tmp;
+               en_desordre = true;
+              }
+        }
+    }
+}
 
 // **********Provides the energy in the cone of radius TAU_CONE_ENERGY for the tau identification********
@@ -706,23 +734,4 @@
    if (phi > PI-dphi) iPhi = PI-dphi;
 }
-/*
-ParticleUtil::ParticleUtil(const TLorentzVector genMomentum,int pid){
-  E=genMomentum.E();
-  Px=genMomentum.Px();
-  Py=genMomentum.Py();
-  Pz=genMomentum.Pz();
-  PT=genMomentum.Pt();
-  Phi=genMomentum.Phi();
-  Eta=genMomentum.Eta();
-  PID=pid;
-
-}
-*/
-/*
-void ParticleUtil::GetInfo()
-{
-
-}
-*/
 
 //**************************** Returns the delta Phi ****************************
Index: /trunk/src/TriggerUtil.cc
===================================================================
--- /trunk/src/TriggerUtil.cc	(revision 73)
+++ /trunk/src/TriggerUtil.cc	(revision 74)
@@ -63,4 +63,7 @@
   list_of_trigger_bits[i].PrintTrigCondition(LogName,i+1);
  }
+  f_out<<"*                                                                    *"<<"\n";
+  f_out<<"#*********************************************************************"<<"\n";
+
 }
 
