Index: /trunk/Delphes.cpp
===================================================================
--- /trunk/Delphes.cpp	(revision 177)
+++ /trunk/Delphes.cpp	(revision 178)
@@ -66,4 +66,6 @@
   }
   
+// 1. ********** initialisation ***********
+
   srand (time (NULL));         /* Initialisation du gÃ©nÃ©rateur */
   
@@ -112,7 +114,6 @@
   //VFD information
   VeryForward * VFD = new VeryForward(DetDatacard);
-  
-  //todo(LogName.c_str());
-  
+ 
+  // data converters
   DataConverter *converter=0;
   
@@ -149,5 +150,5 @@
   TIter itGen((TCollection*)branchGen);
   
-  //write the output root file
+  //Output file : contents of the analysis object data
   ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputfilename, "Analysis");
   ExRootTreeBranch *branchJet = treeWriter->NewBranch("Jet", TRootJet::Class());
@@ -163,5 +164,4 @@
   ExRootTreeBranch *branchFP420 = treeWriter->NewBranch("FP420hits", TRootRomanPotHits::Class());
   
-  
   TRootGenParticle *particle; 
   TRootETmis *elementEtmis;
@@ -178,8 +178,6 @@
   vector<fastjet::PseudoJet> input_particles;//for FastJet algorithm
   vector<fastjet::PseudoJet> sorted_jets;
-  
   vector<TLorentzVector> TrackCentral;  
   vector<PhysicsTower> towers;
-  
   vector<ParticleUtil> electron;
   vector<ParticleUtil> muon;
@@ -187,12 +185,14 @@
 
   TSimpleArray<TRootGenParticle> NFCentralQ;
-  
-  
   float iPhi=0,iEta=0;
 
-  // Loop over all events
+
+
+// 2. ********** Loop over all events ***********
   Long64_t entry, allEntries = treeReader->GetEntries();
-  cout << "** Chain contains " << allEntries << " events" << endl;
-  for(entry = 0; entry < 200; ++entry)
+  cout << "** The input list contains " << allEntries << " events" << endl;
+
+  // loop on all events
+  for(entry = 0; entry < allEntries; ++entry)
     {
       TLorentzVector PTmis(0,0,0,0);
@@ -210,9 +210,11 @@
       input_particles.clear();
       
-      // Loop over all particles in event
+      // 2.1 Loop over all particles in event
       itGen.Reset();
-      while( (particle = (TRootGenParticle*) itGen.Next()) )
-	{
+      while( (particle = (TRootGenParticle*) itGen.Next()) ) {
           int pid = abs(particle->PID);
+
+	
+	  // 2.1.1********************* preparation for the b-tagging
 	  //// This subarray is needed for the B-jet algorithm
 	  // optimization for speed : put first PID condition, then ETA condition, then either pt or status
@@ -224,8 +226,7 @@
           }
 	  
+	  // 2.1.2 ********************* central detector: keep only visible particles
 	  // 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 != pNU1) && (pid != pNU2) && (pid != pNU3)) &&
@@ -234,7 +235,13 @@
             { 
 	      genMomentum.SetPxPyPzE(particle->Px, particle->Py, particle->Pz, particle->E);
-	      if(DET->FLAG_bfield==1)TRACP->Propagation(particle,genMomentum);
+
+	      // 2.1.2.1 ********************* central detector: magnetic field
+	      // genMomentum is then changed with respect to the magnetic field
+	      //if(DET->FLAG_bfield==1)  genMomentum = TRACP->Propagation(particle);
+	      if(DET->FLAG_bfield==1)  TRACP->Propagation(particle,genMomentum);
 	      float eta=fabs(genMomentum.Eta());
-	      
+	     
+ 
+	      // 2.1.2.2 ********************* central detector: smearing (calorimeters, muon chambers)
 	      switch(pid) {
 		
@@ -264,31 +271,35 @@
 		DET->SmearHadron(genMomentum, 1.0);
 		break;
-	      } // switch (pid)
-	      
+	      } // 2.1.2.2  switch (pid)
+	     
+ 
+	      // 2.1.2.3 ********************* central detector: calotowers
 	      // all final particles but muons and neutrinos	
 	      // for calorimetric towers and missing PT
 	      int charge=Charge(pid); 
 	      if(genMomentum.E() !=0 && pid != pMU) {
-		if(charge == 0 || (charge !=0 && genMomentum.Pt() >= DET->TRACK_ptmin)){
-		  DET->BinEtaPhi(genMomentum.Phi(), genMomentum.Eta(), iPhi, iEta);
-                  if(iEta != -100 && iPhi != -100) 
-                    {
+		// in case the Bfield is not simulated, checks that charged particles have enough pt to reach the calos
+		if ( !DET->FLAG_bfield && charge!=0 && genMomentum.Pt() <= DET->TRACK_ptmin ) { /* particules do not reach calos */ }
+		else { // particles reach calos	
+	  	  // applies the calo segmentation and returns iEta & iPhi
+		  DET->BinEtaPhi(genMomentum.Phi(), genMomentum.Eta(), iPhi, iEta); 
+                  if(iEta != -100 && iPhi != -100) { 
                       genMomentumCalo.SetPtEtaPhiE(genMomentum.Pt(),iEta,iPhi,genMomentum.E());
                       elementCalo = (TRootCalo*) branchCalo->NewEntry();
                       elementCalo->Set(genMomentumCalo);
-
-//		      CalTower     myCaloTower(genMomentumCalo.Et,genMomentumCalo.Eta,genMomentumCalo.Phi,iEta,iPhi);
-//		      PhysicsTower Tower(LorentzVector(genMomentumCalo.Px(),genMomentumCalo.Py(),genMomentumCalo.Pz(), genMomentumCalo.E()),myCaloTower);
-		      PhysicsTower Tower(LorentzVector(genMomentumCalo.Px(),genMomentumCalo.Py(),genMomentumCalo.Pz(), genMomentumCalo.E()));
+		      PhysicsTower Tower(LorentzVector(genMomentumCalo.Px(),genMomentumCalo.Py(),genMomentumCalo.Pz(),genMomentumCalo.E()));
                       towers.push_back(Tower);
-                    }
-		}
-	      }
+                  } // if iEta != -100
+		} // else : when particles reach the calos
+	      } // 2.1.2.3 calotowers
 	      
+
+	      // 2.1.2.4 ********************* central detector: tracks
 	      // all final charged particles
 	      if(
 		 (genMomentum.E()!=0) &&
 		 (fabs(genMomentum.Eta()) < DET->CEN_max_tracker) && 
-		 (genMomentum.Pt() > DET->TRACK_ptmin ) &&     // pt too small to be taken into account
+		 (DET->FLAG_bfield || ( !DET->FLAG_bfield && genMomentum.Pt() > DET->TRACK_ptmin )) &&     
+			// if bfield not simulated, pt should be high enough to be taken into account
 		 ((rand()%100) < DET->TRACK_eff)  &&
 		 (charge!=0)
@@ -298,16 +309,21 @@
 		  elementTracks->Set(genMomentum);
 		  TrackCentral.push_back(genMomentum);
-		}
+		} // 2.1.2.4 tracks
 	      
-	    } // switch
+	    } // 2.1.2 central detector
 	  
-	  if(DET->FLAG_vfd==1)
-	    {  
+	  // 2.1.3 ********************* forward detectors: zdc
+	  if(DET->FLAG_vfd==1) {
 	     VFD->ZDC(treeWriter,branchZDC,particle);
 	     VFD->RomanPots(treeWriter,branchRP220,branchFP420,particle);
-	    }
+	  }
 	  
-	} // while
-      
+       } // 2.1 while : loop on all particles of the event.
+     
+
+
+      // 2.2 ********** Output preparation & complex objects  ***********
+ 
+      // 2.2.1 ********************* sorting collections by decreasing pt
       DET->SortedVector(electron); 
       for(unsigned int i=0; i < electron.size(); i++) {
@@ -330,5 +346,5 @@
       }
       
-      // computes the Missing Transverse Momentum
+      // 2.2.2 ************* computes the Missing Transverse Momentum
       TLorentzVector Att(0.,0.,0.,0.);
       for(unsigned int i=0; i < towers.size(); i++)
@@ -349,27 +365,27 @@
       elementEtmis->Py = (-PTmis).Py();
       
-      //*****************************
-      
+      // 2.2.3 ************* B-tag, tau jets
       sorted_jets=JETRUN->RunJets(input_particles);
       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
+    } // 2. Loop over all events ('for' loop)
   
   treeWriter->Write();
   delete treeWriter;
-  
-  //running the trigger in case the FLAG trigger is put to 1 in the datacard
-  
+ 
+
+ 
+// 3. ********** Trigger  & Frog ***********
+  // 3.1 ************ running the trigger in case the FLAG trigger is put to 1 in the datacard
   if(DET->FLAG_trigger == 1)
     {
+      // input
       TChain chainT("Analysis");
       chainT.Add(outputfilename.c_str());
       ExRootTreeReader *treeReaderT = new ExRootTreeReader(&chainT);
       
+      // output
       TClonesArray *branchElecTrig = treeReaderT->UseBranch("Electron");
       TClonesArray *branchMuonTrig = treeReaderT->UseBranch("Muon");
@@ -381,20 +397,22 @@
       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;
-      for(entryT = 0; entryT < allEntriesT; ++entryT)
-        {
+      cout << "** Trigger: the 'Analysis' tree contains " << allEntriesT << " events" << endl;
+      // loop on all entries
+      for(entryT = 0; entryT < allEntriesT; ++entryT) {
           treeWriterT->Clear();
           treeReaderT->ReadEntry(entryT);
           TRIGT->GetGlobalResult(branchElecTrig, branchMuonTrig,branchJetTrig, branchTauJetTrig,branchPhotonTrig, branchETmisTrig,branchTrigger);
           treeWriterT->Fill();
-        }
+      } // loop on all entries
       
       treeWriterT->Write();
       delete treeWriterT;
-    }
-  
-  //FROG display
+    } // trigger
+ 
+ 
+  // 3.2 ************** FROG display
   if(DET->FLAG_frog == 1)
     {
@@ -404,4 +422,8 @@
     }
   
+
+
+
+// 4. ********** End & Exit ***********
   cout << "** Exiting..." << endl;
   
@@ -412,8 +434,6 @@
   delete JETRUN;
   delete VFD;
-  
   if(converter) delete converter;
   
   todo("TODO");
 }
-
