Index: trunk/MagicSoft/Simulation/Detector/include-MTrigger/MTrigger.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-MTrigger/MTrigger.cxx	(revision 391)
+++ trunk/MagicSoft/Simulation/Detector/include-MTrigger/MTrigger.cxx	(revision 392)
@@ -28,7 +28,10 @@
   FILE *unit_mtrig ; 
   Int_t endflag = 1  ; 
+  Int_t bthresholdpixel = FALSE;
   char   datac[256] ; 
   char   dummy[50] ; 
-  
+  char   input_thres[50];
+  Int_t  i, ii ; 
+
   Float_t threshold ; 
  
@@ -93,4 +96,8 @@
 	sscanf (datac, "%s %i", dummy, &trigger_geometry ) ;
       }
+      else if ( strncmp (datac, "threshold_file", 14 ) == 0 ) {
+	sscanf (datac, "%s %s", dummy, input_thres ) ;
+	bthresholdpixel=TRUE;
+      }
 
       if ( feof(unit_mtrig) != 0 ) {
@@ -108,8 +115,14 @@
   cout << endl
        << "[MTrigger]  Setting up the MTrigger with this values "<< endl ; 
-  cout << endl 
-       << "[MTrigger]    ChannelThreshold:   " << threshold << " mV" 
-       << endl ; 
-
+  if(bthresholdpixel){
+    cout<<endl
+	<< "[MTrigger]    ChannelThreshold from file:   "<<input_thres
+	<<endl;
+  }
+  else{
+    cout << endl 
+	 << "[MTrigger]    ChannelThreshold:   " << threshold << " mV" 
+	 << endl ; 
+  }
   cout << "[MTrigger]    Gate Length:        " << gate_leng  << " ns"
        << endl ; 
@@ -129,12 +142,31 @@
   //   we have introduced individual thresholds for all pixels
   //
-  for (Int_t k=0; k<TRIGGER_PIXELS; k++ ) {
-    chan_thres[k] = threshold ; 
-  }
+  FILE *unit_thres;
+
+  if (bthresholdpixel == TRUE) {
+    if ((unit_thres=fopen(input_thres, "r"))==0){
+      cout<<"WARNING: not able to read ..."<<input_thres<<endl;
+      cout<<"Threshold will be set to "<<threshold<<" for all pixels"<<endl;
+      for (Int_t k=0; k<TRIGGER_PIXELS; k++ ) {
+	chan_thres[k] = threshold ; 
+      }
+    }
+    else {
+      for (i=0;i<TRIGGER_PIXELS;i++){
+      	fscanf(unit_thres, "%f",&chan_thres[i]);
+      }
+      fclose (unit_thres);
+    }
+  }
+  else {
+    for (Int_t k=0; k<TRIGGER_PIXELS; k++ ) {
+      chan_thres[k] = threshold ; 
+    }
+  }
+
 
   //
   //    set up the response shape
   // 
-  Int_t  i, ii ; 
      
   Float_t   sigma ; 
@@ -151,10 +183,4 @@
     sing_resp[i] = 
       ampl_resp * expf(-0.5 * (x-x0)*(x-x0) / (sigma*sigma) ) ; 
-
-    //      cout << i << "  "
-    //  	 << x << "  "
-    //  	 << sing_resp[i] 
-    //  	 << endl ; 
-
   
   }
@@ -267,6 +293,8 @@
   
   for ( i = 0 ; i < 5 ; i++) {
-    SlicesFirst[i]  = 0 ; 
-    SlicesSecond[i] = 0 ; 
+    SlicesFirst[i]  = -50.0 ; 
+    SlicesSecond[i] = -50.0 ;
+    PixelsFirst[i]  = -1;
+    PixelsSecond[i] = -1;
   }
   cout << " end of MTrigger::MTrigger()" << endl ; 
@@ -305,18 +333,35 @@
   for ( ii=0 ; ii<TRIGGER_TIME_SLICES; ii++ ) { 
     sum_d_sig[ii] = 0. ;  
-  }
-
-  //
-  //   set the information about the Different Level Triggers to zero
-  //
-
-  nZero = nFirst = nSecond = 0 ; 
+  }    
+}
+
+void MTrigger::ClearZero() {
+  //
+  //   set the information about the Zero Level Trigger to zero
+  //
+
+  Int_t i;
+
+  nZero = 0 ; 
+
+  for (i=0 ; i<TRIGGER_TIME_SLICES; i++ ) { 
+    SlicesZero[i] = FALSE;
+  }
+  
+}
+
+void MTrigger::ClearFirst() {
+  //
+  //   set the information about the First Level Trigger to zero
+  //
+
+  Int_t i;
+
+  nFirst =  0 ; 
   
   for ( i = 0 ; i < 5 ; i++) {
-    SlicesZero[i]   = 0 ; 
-    SlicesFirst[i]  = 0 ; 
-    SlicesSecond[i] = 0 ; 
-  }
-    
+    SlicesFirst[i]  = -50.0 ; 
+    PixelsFirst[i]  = -1;
+  }
 }
 
@@ -496,5 +541,4 @@
   for ( Int_t i=0 ; i < TRIGGER_PIXELS; i++  ) {
     if ( used [i] == TRUE ) {
-      //cout << "Pixel " << i << " used"  ; 
        
       for ( Int_t ii=1 ; ii<TRIGGER_TIME_SLICES; ii++ ) { 
@@ -505,4 +549,52 @@
     }
   }
+}
+
+void MTrigger::SetMultiplicity(Int_t multi){
+  //=============================================================
+  //
+  //    It sets the private member trigger_multi
+
+  trigger_multi=multi;
+}
+
+void MTrigger::SetTopology(Int_t topo){
+  //=============================================================
+  //
+  //    It sets the private member trigger_geometry
+
+  trigger_geometry=topo;
+}
+
+void MTrigger::SetThreshold(Float_t thres[]){
+  //=============================================================
+  //
+  //    It sets the private member chan_thres[TRIGGER_PIXELS]
+
+  Int_t i;
+
+  for(i=0;i<TRIGGER_PIXELS;i++){
+    chan_thres[i]=thres[i];
+  }
+}
+
+void MTrigger::ReadThreshold(char name[]){
+  //=============================================================
+  //
+  //   It reads values for threshold of each pixel from file name
+
+  FILE *unit;
+  Int_t i=0;
+
+  if ((unit=fopen(name, "r"))==0){
+    cout<<"WARNING: not able to read ..."<<name<<endl;
+  }
+  else {
+    while (i<TRIGGER_PIXELS){
+      fscanf(unit, "%f",&chan_thres[i++]);
+    }
+    fclose (unit);
+  }
+	
 }
 
@@ -538,6 +630,4 @@
 
       baseline[i] = baseline[i] / ( (Float_t ) TRIGGER_TIME_SLICES)  ;
-
-      //   cout << "Pixel " << i << " baseline " << baseline[i] <<endl ; 
 
       //
@@ -763,9 +853,5 @@
 
   Int_t iReturn = 0 ;  // Return value for this function 
-  
-  if ( nZero > 1 ) { 
-    cout << " INFORMATION:  more than one Zero Level TRIGGER " << endl ; 
-  }
-  
+    
   //   Definition of needed variables  
   Bool_t Muster[TRIGGER_PIXELS] ; 
@@ -777,5 +863,5 @@
 
   if (trigger_geometry==0 &&  trigger_multi>7) {
-    cout <<"You are lookiny for a topology that needs more than six neighbours of the same pixel"<<endl;
+    cout <<"You are looking for a topology that needs more than six neighbours of the same pixel"<<endl;
     cout <<" Topology   "<<trigger_geometry<<"   Multiplicity   "<<trigger_multi<<endl;;
     return (kFALSE);
@@ -822,5 +908,4 @@
 	    //
 	    if ( d_sig [iPix][iSli] > 0. ) {
-	      
 	      Muster[iPix] = kTRUE ; 
 	    } 
@@ -871,4 +956,5 @@
 		//   A NN-Trigger is detected at time Slice 
 		//
+		PixelsFirst[nFirst] = j;  //  We save pixel that triggers
 		SlicesFirst[nFirst++] = iSli ; // We save time when it triggers
 		iReturn++ ;
@@ -899,4 +985,5 @@
 		//   A NN-Trigger is detected at time Slice 
 		//
+		PixelsFirst[nFirst] = j;  //  We save pixel that triggers
 		SlicesFirst[nFirst++] = iSli ; //  We save when it triggers
 		iReturn++ ;
@@ -976,4 +1063,5 @@
 		}
 		if (closed_pack){
+		  PixelsFirst[nFirst] = j;  //  We save pixel that triggers
 		  SlicesFirst[nFirst++] = iSli ; //  We save time when it triggers
 		  iReturn++ ;
@@ -1063,2 +1151,19 @@
   return(return_val);
 }
+
+Float_t MTrigger::GetFirstLevelTime( Int_t il ){
+
+  //=============================================================
+  //
+  //  It gives the time for the il trigger at first level
+
+  return((Float_t) ((Float_t) SlicesFirst[il]/((Float_t) SLICES_PER_NSEC)));
+}
+
+Int_t MTrigger::GetFirstLevelPixel( Int_t il ){
+
+  //=============================================================
+  //
+  //  It gives the pixel that triggers for the il trigger at first level
+  return(PixelsFirst[il]);
+}
