Index: trunk/MagicSoft/Mars/mtemp/MFindStars.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/MFindStars.cc	(revision 3999)
+++ trunk/MagicSoft/Mars/mtemp/MFindStars.cc	(revision 4002)
@@ -58,9 +58,10 @@
 {
   fName  = name  ? name  : "MFindStars";
-  fTitle = title ? title : "Tool to find stars from Base Currents";
+  fTitle = title ? title : "Tool to find stars from DC Currents";
 
   fMaxNumIntegratedEvents = 10;
-  fRingInterest = 100; //[mm] ~ 0.3 deg
-
+  fRingInterest = 100.; //[mm] ~ 0.3 deg
+  fMinDCForStars = 3.; //[uA]
+  
   fPixelsUsed.Set(577);
   fPixelsUsed.Reset((Char_t)kTRUE);
@@ -94,5 +95,5 @@
     }
 
-   fDrive = (MReportDrive*)pList->FindObject(AddSerialNumber("MReportDrive"));
+    fDrive = (MReportDrive*)pList->FindObject(AddSerialNumber("MReportDrive"));
 
     if (!fDrive)
@@ -101,4 +102,54 @@
       return kFALSE;
     }
+    else
+      {
+        //Initialitation MAstroCamera
+        // Name of a MC file having MGeomCam and MMcConfigRunHeader
+        TString fname = "../data/Gamma_zbin9_90_7_1480to1489_w0.root";
+
+        // Time for which to get the picture
+        //    MTime time;
+        //    time.Set(2004, 2, 28, 01, 32, 15);
+        
+        // Current observatory
+        MObservatory magic1;
+        
+        // Right Ascension [h] and declination [deg] of source
+        // Currently 'perfect' pointing is assumed
+        //    const Double_t ra  = MAstro::Hms2Rad(5, 34, 31.9);
+        //    const Double_t dec = MAstro::Dms2Rad(22, 0, 52.0);
+
+        // --------------------------------------------------------------------------
+        // Create camera display from geometry
+        MMcConfigRunHeader *config=0;
+        MGeomCam           *geom=0;
+        
+        TFile file(fname);
+        TTree *tree = (TTree*)file.Get("RunHeaders");
+        tree->SetBranchAddress("MMcConfigRunHeader", &config);
+        if (tree->GetBranch("MGeomCam"))
+          tree->SetBranchAddress("MGeomCam", &geom);
+        tree->GetEntry(0);
+        
+        fAstro.SetMirrors(*config->GetMirrors());
+        fAstro.SetGeom(*geom);
+        
+        
+        fAstro.SetLimMag(6);
+        fAstro.SetRadiusFOV(3);
+        fAstro.ReadBSC("../data/bsc5.dat");
+        
+        fAstro.SetObservatory(magic1);
+        // Time for which to get the picture
+        //    MTime time;
+        //    time.Set(2004, 2, 28, 01, 32, 15);
+        //   fAstro.SetTime(time);
+        fAstro.SetTime(*fTimeCurr);
+        fAstro.SetGuiActive();
+        
+        fAstro.SetStarList(fStars->GetList());
+        
+      }
+    
 
     fStars = (MStarLocalCam*)pList->FindCreateObj(AddSerialNumber("MStarLocalCam"));
@@ -109,50 +160,4 @@
     }
 
-//Initialitation MAstroCamera
-    // Name of a MC file having MGeomCam and MMcConfigRunHeader
-    TString fname = "../data/Gamma_zbin9_90_7_1480to1489_w0.root";
-
-    // Time for which to get the picture
-//    MTime time;
-//    time.Set(2004, 2, 28, 01, 32, 15);
-
-    // Current observatory
-    MObservatory magic1;
-
-    // Right Ascension [h] and declination [deg] of source
-    // Currently 'perfect' pointing is assumed
-//    const Double_t ra  = MAstro::Hms2Rad(5, 34, 31.9);
-//    const Double_t dec = MAstro::Dms2Rad(22, 0, 52.0);
-
-      // --------------------------------------------------------------------------
-    // Create camera display from geometry
-    MMcConfigRunHeader *config=0;
-    MGeomCam           *geom=0;
-
-    TFile file(fname);
-    TTree *tree = (TTree*)file.Get("RunHeaders");
-    tree->SetBranchAddress("MMcConfigRunHeader", &config);
-    if (tree->GetBranch("MGeomCam"))
-        tree->SetBranchAddress("MGeomCam", &geom);
-    tree->GetEntry(0);
-
-    fAstro.SetMirrors(*config->GetMirrors());
-    fAstro.SetGeom(*geom);
-
-
-    fAstro.SetLimMag(6);
-    fAstro.SetRadiusFOV(3);
-    fAstro.ReadBSC("../data/bsc5.dat");
-
-    fAstro.SetObservatory(magic1);
-    // Time for which to get the picture
-//    MTime time;
-//    time.Set(2004, 2, 28, 01, 32, 15);
-//   fAstro.SetTime(time);
-    fAstro.SetTime(*fTimeCurr);
-    fAstro.SetGuiActive();
-
-    fAstro.SetStarList(fStars->GetList());
-
     return kTRUE;
 }
@@ -160,13 +165,4 @@
 Int_t MFindStars::Process()
 {
-
-    Float_t ra  = fDrive->GetRa();
-    Float_t dec = fDrive->GetDec();
-
-    fAstro.SetRaDec(ra, dec);
-    fAstro.SetGuiActive();
-   
-    fAstro.FillStarList();
-
     if (fNumIntegratedEvents < fMaxNumIntegratedEvents)
     {
@@ -176,13 +172,43 @@
     else
     {
-	//loop to extract position of stars on the camera
-	TIter Next(fStars->GetList());
-	MStarLocalPos* star;
-	while ((star=(MStarLocalPos*)Next())) 
-	    FindStar(star);
-
-	//After finding stars reset all vairables
-	fDisplay.Reset();
-	fNumIntegratedEvents=0;
+      if (fDrive)
+        {
+          Float_t ra  = fDrive->GetRa();
+          Float_t dec = fDrive->GetDec();
+          
+          fAstro.SetRaDec(ra, dec);
+          fAstro.SetGuiActive();
+          
+          fAstro.FillStarList();
+        }
+      else
+        {
+          Float_t maxPixelDC;
+          MGeomPix maxPixel;
+          while(1)
+            {
+              FindPixelWithMaxDC(maxPixelDC, maxPixel);
+              if (maxPixelDC<fMinDCForStars)
+                break;
+              
+              MStarLocalPos *starpos = new MStarLocalPos;
+              starpos->SetExpValues(maxPixelDC,maxPixel.GetX(),maxPixel.GetY());
+              fStars->GetList()->Add(starpos);
+            }
+        }
+      
+      //loop to extract position of stars on the camera
+      TIter Next(fStars->GetList());
+      MStarLocalPos* star;
+      while ((star=(MStarLocalPos*)Next()))
+        {
+          FindStar(star);
+          ShadowStar(star);
+        }
+      
+      
+      //After finding stars reset all vairables
+      fDisplay.Reset();
+      fNumIntegratedEvents=0;
     }
 
@@ -206,39 +232,21 @@
 }
 
-Bool_t MFindStars::FindStar(MStarLocalPos* star)
-{    
-
-    Float_t expX = star->GetXExp();
-    Float_t expY = star->GetYExp();
-
+Bool_t MFindStars::FindPixelWithMaxDC(Float_t &maxDC, MGeomPix &maxPix)
+{
     UInt_t numPixels = fGeomCam->GetNumPixels();
 
-// First define a area of interest around the expected position of the star
+// Find the two close pixels with the maximun dc
+    UInt_t maxPixIdx[2];
+
     for (UInt_t pix=1; pix<numPixels; pix++)
     {
-
-	Float_t pixXpos=(*fGeomCam)[pix].GetX();
-	Float_t pixYpos=(*fGeomCam)[pix].GetY();
-	Float_t dist = sqrt((pixXpos-expX)*(pixXpos-expX)+
-			    (pixYpos-expY)*(pixYpos-expY));
-
-      if (dist < fRingInterest)
-	  fPixelsUsed[pix]=(Char_t)kTRUE;
-    }
-
-    fDisplay.SetUsed(fPixelsUsed);
-
-// Find the two close pixels with the maximun dc
-    for (UInt_t pix=1; pix<numPixels; pix++)
-    {
-	Float_t maxDC = 0;
+	maxDC = 0;
 
 	if(fDisplay.IsUsed(pix))
 	{
 	    Float_t dc[2];
-	    Float_t maxPix[2];
 	    dc[0] = fDisplay.GetBinContent(pix+1);
 	    
-	    MGeomPix g = (*fGeomCam)[pix];
+	    MGeomPix &g = (*fGeomCam)[pix];
 	    Int_t numNextNeighbors = g.GetNumNeighbors();
 	    
@@ -256,7 +264,15 @@
 		    if(dcsum > maxDC*2)
 		    {
-			maxPix[0] = pix;
-			maxPix[1] = swneighbor;
-			maxDC = dcsum/2;
+                      if(dc[0]>=dc[1])
+                        {
+			maxPixIdx[0] = pix;
+			maxPixIdx[1] = swneighbor;
+                        }
+                      else
+                        {
+                          maxPixIdx[1] = pix;
+                          maxPixIdx[0] = swneighbor;
+                        }
+                      maxDC = dcsum/2;
 		    }	
 		}
@@ -264,4 +280,34 @@
 	}
     }
+
+    maxPix = (*fGeomCam)[maxPixIdx[0]];
+    return kTRUE;
+}
+
+Bool_t MFindStars::FindStar(MStarLocalPos* star)
+{    
+
+  MHCamera cam = fDisplay;
+  
+    Float_t expX = star->GetXExp();
+    Float_t expY = star->GetYExp();
+
+    UInt_t numPixels = fGeomCam->GetNumPixels();
+
+// First define a area of interest around the expected position of the star
+    for (UInt_t pix=1; pix<numPixels; pix++)
+    {
+
+	Float_t pixXpos=(*fGeomCam)[pix].GetX();
+	Float_t pixYpos=(*fGeomCam)[pix].GetY();
+	Float_t dist = sqrt((pixXpos-expX)*(pixXpos-expX)+
+			    (pixYpos-expY)*(pixYpos-expY));
+
+      if (dist < fRingInterest && cam.IsUsed(pix))
+	  fPixelsUsed[pix]=(Char_t)kTRUE;
+    }
+
+    cam.SetUsed(fPixelsUsed);
+
 
     // determine mean x and mean y of the selected px
@@ -274,9 +320,9 @@
     for(UInt_t pix=0; pix<numPixels; pix++)
     {
-	if(fDisplay.IsUsed(pix))
+	if(cam.IsUsed(pix))
 	{
 	    usedPx++;
 
-	    Float_t charge=fDisplay.GetBinContent(pix+1);
+	    Float_t charge=cam.GetBinContent(pix+1);
 	    Float_t pixXpos=(*fGeomCam)[pix].GetX();
 	    Float_t pixYpos=(*fGeomCam)[pix].GetY();
@@ -287,15 +333,40 @@
 	    meanSqY+=charge*pixYpos*pixYpos;
 	    sumCharge+=charge;
-//	    fDisplay.ResetUsed(i); // this px must not be used again!
+//	    cam.ResetUsed(i); // this px must not be used again!
 	} //for... use	
     }
 
     star->SetCalcValues(sumCharge,meanX,meanY,meanSqX,meanSqY);
-    fStars->GetList()->Add(star);
     
     return kTRUE;
 }
 
-
-
-
+Bool_t MFindStars::ShadowStar(MStarLocalPos* star)
+{
+    UInt_t numPixels = fGeomCam->GetNumPixels();
+
+// Define an area around the star which will be set unused.
+    for (UInt_t pix=1; pix<numPixels; pix++)
+    {
+
+	Float_t pixXpos  = (*fGeomCam)[pix].GetX();
+	Float_t pixYpos  = (*fGeomCam)[pix].GetY();
+        Float_t starXpos = star->GetMeanXCalc();
+        Float_t starYpos = star->GetMeanYCalc();
+        
+	Float_t starSize = 2*star->GetSigmaMajorAxisCalc();
+        
+	Float_t dist = sqrt((pixXpos-starXpos)*(pixXpos-starXpos)+
+			    (pixYpos-starYpos)*(pixYpos-starYpos));
+
+        if (dist > starSize && fDisplay.IsUsed(pix))
+	  fPixelsUsed[pix]=(Char_t)kTRUE;
+    }
+
+    fDisplay.SetUsed(fPixelsUsed);
+
+    return kTRUE;
+}
+
+
+
Index: trunk/MagicSoft/Mars/mtemp/MFindStars.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/MFindStars.h	(revision 3999)
+++ trunk/MagicSoft/Mars/mtemp/MFindStars.h	(revision 4002)
@@ -23,4 +23,5 @@
 
 class MGeomCam;
+class MGeomPix;
 class MCameraDC;
 class MTime;
@@ -48,6 +49,11 @@
 
     Float_t fRingInterest; //[mm]
+    Float_t fMinDCForStars;
 
-public:
+    Bool_t FindPixelWithMaxDC(Float_t &maxDC, MGeomPix &maxPix);
+    Bool_t FindStar(MStarLocalPos* star);
+    Bool_t ShadowStar(MStarLocalPos* star);
+
+  public:
     MFindStars(const char *name=NULL, const char *title=NULL);
     
@@ -60,7 +66,6 @@
     void SetBlindPixels(TArrayS blindpixels);
 
-    Bool_t FindStar(MStarLocalPos* star);
 
-  ClassDef(MFindStars, 0) // Tool to find stars from Base Currents
+  ClassDef(MFindStars, 0) // Tool to find stars from DC Currents
 };
 
Index: trunk/MagicSoft/Mars/mtemp/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mtemp/Makefile	(revision 3999)
+++ trunk/MagicSoft/Mars/mtemp/Makefile	(revision 4002)
@@ -11,9 +11,34 @@
 #------------------------------------------------------------------------------
 
-INCLUDES = -I.
-
 CINT     = Temp
 
-SRCFILES = 
+#------------------------------------------------------------------------------
+
+INCLUDES = -I. \
+	   -I../mbase \
+	   -I../mjobs \
+	   -I../mpedestal \
+	   -I../mbadpixels \
+	   -I../mfileio \
+           -I../mraw \
+           -I../manalysis \
+	   -I../mgui \
+	   -I../mgeom \
+	   -I../msignal \
+	   -I../mcalib \
+	   -I../mfilter \
+	   -I../mhbase \
+	   -I../mimage \
+	   -I../mpointing \
+	   -I../mcamera \
+	   -I../mhist \
+	   -I../mmc \
+	   -I../mreport \
+	   -I../mastro
+
+SRCFILES = \
+        MStarLocalPos.cc \
+        MStarLocalCam.cc \
+        MFindStars.cc
 
 ############################################################
@@ -23,3 +48,4 @@
 include ../Makefile.rules
 
+clean:	rmcint rmobjs rmcore rmlib
 mrproper:	clean rmbak
Index: trunk/MagicSoft/Mars/mtemp/TempLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/TempLinkDef.h	(revision 3999)
+++ trunk/MagicSoft/Mars/mtemp/TempLinkDef.h	(revision 4002)
@@ -5,2 +5,7 @@
 #pragma link off all functions;
 
+#pragma link C++ class MStarLocalPos+;
+#pragma link C++ class MStarLocalCam+;
+#pragma link C++ class MFindStars+;
+
+#endif
