Index: trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 1195)
+++ trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 1223)
@@ -21,7 +21,7 @@
 //
 // $RCSfile: camera.cxx,v $
-// $Revision: 1.31 $
+// $Revision: 1.32 $
 // $Author: blanch $ 
-// $Date: 2002-01-18 17:41:02 $
+// $Date: 2002-02-28 15:04:52 $
 //
 ////////////////////////////////////////////////////////////////////////
@@ -253,6 +253,7 @@
 
 //@: Upper and lower edges of the trigger loop
-static int Trigger_loop_lthres = 0;
-static int Trigger_loop_uthres = 10;
+static float Trigger_loop_lthres = 2.0;
+static float Trigger_loop_uthres = 10.0;
+static float Trigger_loop_sthres = 1.0;
 static int Trigger_loop_lmult = 2;
 static int Trigger_loop_umult = 10;
@@ -472,6 +473,8 @@
   int btrigger = 0;           //@< trigger flag
   int ithrescount;            //@< counter for loop over threshold trigger
+  float fthrescount;          //@< value for loop over threshold trigger
   int imulticount;            //@< counter for loop over multiplicity trigger
   int itopocount;             //@< counter for loop over topology trigger
+  int isorttopo[3];           //@< sorting the topologies
   int icontrigger;            //@< number of trigger conditions to be analised
   UShort_t numPix;            //@< number of sets of fadc written counts
@@ -599,10 +602,11 @@
   get_Trigger_properties( &Trigger_gate_length, &Trigger_overlaping_time, &Trigger_response_ampl, &Trigger_response_fwhm);
 
-  Trigger_Loop = get_Trigger_Loop(&Trigger_loop_lthres, &Trigger_loop_uthres, &Trigger_loop_lmult, &Trigger_loop_umult, &Trigger_loop_ltop, &Trigger_loop_utop);
-
-  icontrigger =(Trigger_loop_uthres-Trigger_loop_lthres+1)*
+  Trigger_Loop = get_Trigger_Loop(&Trigger_loop_lthres, &Trigger_loop_uthres, &Trigger_loop_sthres, &Trigger_loop_lmult, &Trigger_loop_umult, &Trigger_loop_ltop, &Trigger_loop_utop);
+
+  icontrigger =((int)((Trigger_loop_uthres-Trigger_loop_lthres)
+		/Trigger_loop_sthres)+1)*
     (Trigger_loop_umult-Trigger_loop_lmult+1)*
     (Trigger_loop_utop-Trigger_loop_ltop+1);
-
+  
   if (!Trigger_Loop){
     get_Trigger_Single (qThreshold, &Trigger_multiplicity, &Trigger_topology);
@@ -650,7 +654,7 @@
   if (Trigger_Loop) {
     log(SIGNATURE,
-	"%s:\n\t%20s: %i - %i\n\t%20s: %i - %i\n\t%20s: %i - %i\n\t%20s\n",
+	"%s:\n\t%20s: from %5.2f to %5.2f by %5.2f step\n\t%20s: %i - %i\n\t%20s: %i - %i\n\t%20s\n",
 	"Trigger Loop mode",
-	"Threshold",Trigger_loop_lthres,Trigger_loop_uthres,
+	"Threshold",Trigger_loop_lthres,Trigger_loop_uthres,Trigger_loop_sthres,
 	"Multiplicity",Trigger_loop_lmult,Trigger_loop_umult,
 	"Topology",Trigger_loop_ltop,Trigger_loop_utop,
@@ -711,6 +715,7 @@
   int ***ntriggerloop;
 
-  ntriggerloop= new int ** [(int) (Trigger_loop_uthres+1-Trigger_loop_lthres)]; 
-  for (ithrescount=0;ithrescount<=Trigger_loop_uthres-Trigger_loop_lthres;ithrescount++){
+  ntriggerloop= new int ** [(int)((Trigger_loop_uthres-Trigger_loop_lthres)
+			   /Trigger_loop_sthres)]; 
+  for (ithrescount=0, fthrescount=Trigger_loop_lthres;fthrescount<=Trigger_loop_uthres;fthrescount+=Trigger_loop_sthres, ithrescount++){
     ntriggerloop[ithrescount]= new int * [Trigger_loop_umult-Trigger_loop_lmult+1];
     for (imulticount=0;imulticount<=Trigger_loop_umult-Trigger_loop_lmult;imulticount++){
@@ -722,4 +727,16 @@
   }
 
+  // We should be careful that topologies are sort from 
+  // the less to the more restrictive one. 
+
+  if (Trigger_loop_utop==Trigger_loop_ltop)
+    for(int is=0; is<3;is++)
+      isorttopo[is]=is;
+  else {
+      isorttopo[0]=1;
+      isorttopo[1]=0;
+      isorttopo[2]=2;
+  }    
+
   // set all random numbers seeds
 
@@ -771,4 +788,5 @@
   MMcTrigHeader **HeaderTrig = NULL; 
   MMcFadcHeader **HeaderFadc = NULL;
+
 
   if (Write_McTrig){
@@ -931,14 +949,15 @@
   if(Trigger_Loop && Write_McTrig){
 
-    for (int iconcount=0,ithrescount=0;ithrescount<=Trigger_loop_uthres-Trigger_loop_lthres;ithrescount++){
+    int iconcount;
+    for (iconcount=0,ithrescount=0,fthrescount=Trigger_loop_lthres;fthrescount<=Trigger_loop_uthres;ithrescount++,fthrescount+=Trigger_loop_sthres){
       for (imulticount=0;imulticount<=Trigger_loop_umult-Trigger_loop_lmult;imulticount++){
 	for(itopocount=0;itopocount<=Trigger_loop_utop-Trigger_loop_ltop;itopocount++){
-	  HeaderTrig[iconcount]->SetTopology((Short_t) itopocount+Trigger_loop_ltop);
+	  HeaderTrig[iconcount]->SetTopology((Short_t) isorttopo[itopocount+Trigger_loop_ltop]);
 	  HeaderTrig[iconcount]->SetMultiplicity((Short_t) imulticount+Trigger_loop_lmult);
 	  for(int i=0;i<TRIGGER_PIXELS;i++){
 	    fpixelthres[i]=
-	      ((Float_t)(ithrescount+Trigger_loop_lthres)>=qThreshold[i])?
-	      (Float_t)(ithrescount+Trigger_loop_lthres):qThreshold[i];
-	  }
+	      ((Float_t)(fthrescount)>=qThreshold[i])?
+	      (Float_t)(fthrescount):qThreshold[i];
+	      }
 	  HeaderTrig[iconcount]->SetThreshold( fpixelthres);
 	  HeaderTrig[iconcount]->SetAmplitud(Trigger_response_ampl);
@@ -969,6 +988,6 @@
   }
   if(Trigger_Loop && Write_McFADC){
-
-    for (int iconcount=0,ithrescount=0;ithrescount<=Trigger_loop_uthres-Trigger_loop_lthres;ithrescount++){
+    int iconcount;
+    for (iconcount=0,ithrescount=0,fthrescount=Trigger_loop_lthres;fthrescount<=Trigger_loop_uthres;ithrescount++, fthrescount+=Trigger_loop_sthres){
       for (imulticount=0;imulticount<=Trigger_loop_umult-Trigger_loop_lmult;imulticount++){
 	for(itopocount=0;itopocount<=Trigger_loop_utop-Trigger_loop_ltop;itopocount++){
@@ -1405,10 +1424,14 @@
 	//   We study several trigger conditons
 	if(Trigger_Loop){
+
+	  // Set to zero the flag to know if some conditon has triggered
+	  btrigger=0;
 	  //  Loop over trigger threshold
-	  for (int iconcount=0,ithrescount=Trigger_loop_lthres;ithrescount<=Trigger_loop_uthres;ithrescount++){
+	  int iconcount;
+	  for (iconcount=0, ithrescount=0, fthrescount=Trigger_loop_lthres;fthrescount<=Trigger_loop_uthres;ithrescount++, fthrescount+=Trigger_loop_sthres){
 	    for (i=0;i<TRIGGER_PIXELS;i++)
 	      fpixelthres[i]=
-		((Float_t)(ithrescount)>=qThreshold[i])?
-		(Float_t)(ithrescount):qThreshold[i];
+		((Float_t)(fthrescount)>=qThreshold[i])?
+		(Float_t)(fthrescount):qThreshold[i];
 	    Trigger.SetThreshold(fpixelthres);
 
@@ -1425,5 +1448,4 @@
 	    //  Set trigger flags to zero
 	    Lev1=Lev2=0;
-	    btrigger=0;
 
 	    //  loop over multiplicity of trigger configuration
@@ -1440,6 +1462,15 @@
 		
 		  if(itopocount==0 && imulticount>7) continue;
-		  if(itopocount==2 && imulticount<3) continue;
-		  Trigger.SetTopology(itopocount);
+		  //COBB if(itopocount==2 && imulticount<3) continue;
+		  // It only makes to look for a different topology
+		  // if there are 3 or more N pixels. 
+		  if(imulticount<3)
+		    Trigger.SetTopology(1);
+		  else
+		    {
+		      // We should be careful that topologies are sort from 
+		      // the less to the more restrictive one. 
+		      Trigger.SetTopology(isorttopo[itopocount]);
+		    }
 		  Trigger.ClearFirst();
 		  
@@ -1451,5 +1482,5 @@
 		  if(Lev1>0) {
 		    btrigger= 1;
-		    ntriggerloop[ithrescount-Trigger_loop_lthres][imulticount-Trigger_loop_lmult][itopocount-Trigger_loop_ltop]++;
+		    ntriggerloop[ithrescount][imulticount-Trigger_loop_lmult][itopocount-Trigger_loop_ltop]++;
 		  }
 		  
@@ -1799,11 +1830,11 @@
     log( SIGNATURE, "Fraction of triggers: \n");
     datafile<<"Fraction of triggers: "<<endl;
-    for (ithrescount=Trigger_loop_lthres;ithrescount<=Trigger_loop_uthres;ithrescount++){
+    for (ithrescount=0, fthrescount=Trigger_loop_lthres;fthrescount<=Trigger_loop_uthres;ithrescount++, fthrescount+=Trigger_loop_sthres){
       for (imulticount=Trigger_loop_lmult;imulticount<=Trigger_loop_umult;imulticount++){
 	for(itopocount=Trigger_loop_ltop;itopocount<=Trigger_loop_utop;itopocount++){
-	  log( SIGNATURE, "Thres %d, Multi %d, Topo %d: %5.1f%% (%d out of %d)\n", 
-	       ithrescount,imulticount,itopocount,((float)ntriggerloop[ithrescount-Trigger_loop_lthres][imulticount-Trigger_loop_lmult][itopocount-Trigger_loop_ltop] / ((float)ntshow) * 100.0), ntriggerloop[ithrescount-Trigger_loop_lthres][imulticount-Trigger_loop_lmult][itopocount-Trigger_loop_ltop], ntshow);
-	  datafile<<"Thres "<<ithrescount<<", Multi "<<imulticount<<", Topo"<<itopocount<<": ";
-	  datafile<<((float)ntriggerloop[ithrescount-Trigger_loop_lthres][imulticount-Trigger_loop_lmult][itopocount-Trigger_loop_ltop] / ((float)ntshow) * 100.0)<<"% ("<<ntriggerloop[ithrescount-Trigger_loop_lthres][imulticount-Trigger_loop_lmult][itopocount-Trigger_loop_ltop]<<" out of "<<ntshow<<")"<<endl;
+	  log( SIGNATURE, "Thres %5.1f, Multi %d, Topo %d: %5.1f%% (%d out of %d)\n", 
+	       fthrescount,imulticount,isorttopo[itopocount],((float)ntriggerloop[ithrescount][imulticount-Trigger_loop_lmult][itopocount-Trigger_loop_ltop] / ((float)ntshow) * 100.0), ntriggerloop[ithrescount][imulticount-Trigger_loop_lmult][itopocount-Trigger_loop_ltop], ntshow);
+	  datafile<<"Thres "<<fthrescount<<", Multi "<<imulticount<<", Topo"<<isorttopo[itopocount]<<": ";
+	  datafile<<((float)ntriggerloop[ithrescount][imulticount-Trigger_loop_lmult][itopocount-Trigger_loop_ltop] / ((float)ntshow) * 100.0)<<"% ("<<ntriggerloop[ithrescount][imulticount-Trigger_loop_lmult][itopocount-Trigger_loop_ltop]<<" out of "<<ntshow<<")"<<endl;
 	}
       }   
@@ -3317,4 +3348,11 @@
 //
 // $Log: not supported by cvs2svn $
+// Revision 1.31  2002/01/18 17:41:02  blanch
+// The option of adding noise to all pixels or to not adding the noise
+// has been added.
+// We removed the pixels larger than 577. When there were more than one
+// trigger in one shower, the pixel number was increasing. Now it is
+// flagged by the variable MMcTrig::fFirstLvlTrig.
+//
 // Revision 1.30  2001/11/27 09:49:54  blanch
 // Fixing bug which was treating wrongly the extension of star photons.
@@ -3400,4 +3438,11 @@
 //
 // $Log: not supported by cvs2svn $
+// Revision 1.31  2002/01/18 17:41:02  blanch
+// The option of adding noise to all pixels or to not adding the noise
+// has been added.
+// We removed the pixels larger than 577. When there were more than one
+// trigger in one shower, the pixel number was increasing. Now it is
+// flagged by the variable MMcTrig::fFirstLvlTrig.
+//
 // Revision 1.30  2001/11/27 09:49:54  blanch
 // Fixing bug which was treating wrongly the extension of star photons.
