]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALJetFinderAlgoUA1Hybrid.cxx
coding convention
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALJetFinderAlgoUA1Hybrid.cxx
1 //SARAH'S HYBRID PERSONAL COPY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2
3 //THIS IS SARAH'S REVISED UA1 CODE WITH CHANGES FOR ETA/PHI ITERATION INCLUDED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4 //THIS Also includes summing ALL cells in the jetcone towards the jet energy NOT just those above threshold!!!!!
5
6
7 /**************************************************************************
8  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
9  *                                                                        *
10  * Author: The ALICE Off-line Project.                                    *
11  * Contributors are mentioned in the code where appropriate.              *
12  *                                                                        *
13  * Permission to use, copy, modify and distribute this software and its   *
14  * documentation strictly for non-commercial purposes is hereby granted   *
15  * without fee, provided that the above copyright notice appears in all   *
16  * copies and that both the copyright notice and this permission notice   *
17  * appear in the supporting documentation. The authors make no claims     *
18  * about the suitability of this software for any purpose. It is          *
19  * provided "as is" without express or implied warranty.                  *
20  **************************************************************************/
21
22 /* $Id$ */
23
24 //*--Author: Sarah Blyth (LBL)
25 //*--Based on UA1 jet algorithm from LUND JETSET called from EMC-erj
26
27 #include "TTask.h"
28 #include "AliEMCALJetFinderInput.h"
29 #include "AliEMCALJetFinderOutput.h"
30 #include "AliEMCALJetFinderAlgo.h"
31 #include "AliEMCALJetFinderAlgoUA1Hybrid.h"
32 #include "AliEMCALJetFinderAlgoUA1Unit.h"
33 #include "AliEMCALGeometry.h"
34 #include "AliEMCAL.h"
35 #include "AliEMCALGetter.h"
36 #include "AliEMCALDigit.h"
37 #include "TParticle.h"
38 #include "AliRun.h"
39 #include "AliEMCALJet.h"
40 #include "TMath.h"
41
42
43 ClassImp(AliEMCALJetFinderAlgoUA1Hybrid)
44
45   AliEMCALJetFinderAlgoUA1Hybrid::AliEMCALJetFinderAlgoUA1Hybrid()
46 {
47   //Default constructor
48 if (fDebug>0) Info("AliEMCALJetFinderAlgoUA1Hybrid","Beginning Default Constructor");
49
50   fNumIter           = 0;
51   fNumUnits          = 13824;     //Number of towers in EMCAL
52   fESeed             = 5.0;       //Default value
53   fConeRad           = 0.5;       //Default value
54   fJetEMin           = 10.0;      //Default value
55   fEtMin             = 0.28;      //Default value
56   fMinMove           = 0.05;      //From original UA1 JetFinder
57   fMaxMove           = 0.15;      //From original UA1 JetFinder
58   fBGMaxMove         = 0.035;     //From original UA1 JetFinder
59   fPtCut             = 0;         
60   fHadCorr           = 0;       
61   fEBGTotal          = 1.0;       //Set to 1 so that no div by zero in first FindJets() loop
62   fEBGTotalOld       = 0.0;
63   fEBGAve            = 0.0;
64   fEnergy            = 0.0;
65   fJetEta            = 0.0;
66   fJetPhi            = 0.0;
67   fEtaInit           = 0.0;
68   fPhiInit           = 0.0;
69   fEtaB              = 0.0;
70   fPhiB              = 0.0;
71   fJetESum           = 0.0;
72   fJetEtaSum         = 0.0;
73   fJetPhiSum         = 0.0;
74   fDEta              = 0.0;
75   fDPhi              = 0.0;
76   fDistP             = 0.0;
77   fDistI             = 0.0;
78   fTempE             = 0.0;
79   fRad               = 2.0;      //Set to 2 to start 
80   fNumInCone         = 0;
81   fNumJets           = 0;
82   fArrayInitialised  = 0;        //Set to FALSE to start
83 }
84
85  AliEMCALJetFinderAlgoUA1Hybrid::~AliEMCALJetFinderAlgoUA1Hybrid()
86    {
87      //Destructor
88      if (fDebug>0) Info("AliEMCALJetFinderAlgoUA1Revised","Beginning Destructor");
89      delete[] fUnit;
90    }
91
92  void AliEMCALJetFinderAlgoUA1Hybrid::SetJetFindingParameters
93                                (Int_t numUnits, Float_t eSeed, Float_t coneRad, Float_t jetEMin, Float_t etMin, 
94                                Float_t minMove, Float_t maxMove, Float_t bgMaxMove)
95    {
96      //Sets parameters for the JetFinding algorithm
97      if (fDebug>1) Info("SetJetFindingParameters","Setting parameters for JetFinding");
98
99      SetNumUnits(numUnits);
100      SetJetESeed(eSeed);
101      SetConeRad(coneRad);
102      SetJetEMin(jetEMin);
103      SetEtMin(etMin);
104      SetMinMove(minMove);
105      SetMaxMove(maxMove);
106      SetBGMaxMove(bgMaxMove);
107    }
108
109  void AliEMCALJetFinderAlgoUA1Hybrid::SetJetFindingParameters
110                                (Int_t numUnits, Float_t eSeed, Float_t coneRad, Float_t jetEMin, Float_t etMin)
111    {
112      //Sets fewer parameters for the JetFinding algorithm
113      if (fDebug>1) Info("SetJetFindingParameters","Setting parameters for JetFinding");
114
115      SetNumUnits(numUnits);
116      SetJetESeed(eSeed);
117      SetConeRad(coneRad);
118      SetJetEMin(jetEMin);
119      SetEtMin(etMin);
120      SetMinMove(fMinMove);
121      SetMaxMove(fMaxMove);
122      SetBGMaxMove(fBGMaxMove);
123    }
124
125  void AliEMCALJetFinderAlgoUA1Hybrid::InitUnitArray()
126    {
127      //Initialises unit array
128      if(fArrayInitialised) delete[] fUnit;
129      fUnit = new AliEMCALJetFinderAlgoUA1Unit[fNumUnits];
130      fArrayInitialised = 1;
131    }
132
133  void AliEMCALJetFinderAlgoUA1Hybrid::FillUnitArray(AliEMCALJetFinderAlgoUA1FillUnitFlagType_t flag)
134    {
135      if (fDebug>1) Info("FillUnitArray","Beginning FillUnitArray");
136      //AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
137
138          //   if (pEMCAL){ 
139          //          AliEMCALGeometry* geom =  AliEMCALGeometry::GetInstance(pEMCAL->GetTitle(), "");
140          //     }else
141          //    {
142      //AliEMCALGeometry* geom =  AliEMCALGeometry::GetInstance("EMCAL_5655_21", "");
143      AliEMCALGeometry* geom = AliEMCALGetter::Instance()->EMCALGeometry() ; 
144           
145      //    }
146          
147      AliEMCALJetFinderAlgoUA1FillUnitFlagType_t option = flag;
148      Int_t         numTracks, numDigits;
149     
150      //Loops over all elements in the AliEMCALJetFinderAlgoUA1Unit array and 
151      //fills the objects with relevant values from the Data Input object
152      if (fDebug>1) Info("FillUnitArray","Filling array with Unit objects");
153      if (fDebug>1) Info("FillUnitArray","NTracks %i NDigits %i",fInputPointer->GetNTracks(),fInputPointer->GetNDigits());
154          numTracks = fInputPointer->GetNTracks();
155          numDigits = fInputPointer->GetNDigits();
156          TParticle         *myPart;
157          AliEMCALDigit     *myDigit;
158
159          //Fill units with Track info if appropriate
160          if(option==kFillTracksOnly || option ==kFillAll) 
161            {          
162             for(Int_t j=0; j<numTracks; j++)
163             {
164              myPart = fInputPointer->GetTrack(j);
165              Float_t eta = myPart->Eta();
166              Float_t  phi = myPart->Phi();
167              Int_t towerID = geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi);
168              Float_t  pT = myPart->Pt();
169              Float_t unitEnergy = fUnit[towerID-1].GetUnitEnergy(); 
170
171              //Do Hadron Correction
172               if(fHadCorr != 0)
173                {
174                  Double_t   fullP = myPart->P();
175                  Double_t   hCEnergy = fHadCorr->GetEnergy(fullP, (Double_t)eta);
176                  unitEnergy -= hCEnergy*TMath::Sin(myPart->Theta());
177                  fUnit[towerID-1].SetUnitEnergy(unitEnergy);
178                } //end Hadron Correction loop 
179              
180              //Do Pt cut on tracks
181              if(fPtCut != 0 && pT < fPtCut) continue;
182
183              fUnit[towerID-1].SetUnitEnergy(unitEnergy+pT);
184
185              }//end tracks loop
186            }//end Tracks condition
187
188
189          //Fill units with Digit info if appropriate
190          if(option ==kFillDigitsOnly || option ==kFillAll)
191            {
192             for(Int_t k=0; k<numDigits; k++)
193             {
194              myDigit = fInputPointer->GetDigit(k);
195              if (fDebug>1) Info("FillUnitArray","getting digits %i %i numdigits",k,numDigits );
196              Int_t towerID = myDigit->GetId();
197              Int_t amplitude = myDigit->GetAmp();     //Gets the integer valued amplitude of the digit
198              Float_t amp = (Float_t)amplitude;        //Need to typecast to Float_t before doing real energy conversion
199              Float_t digitEnergy = amp/10000000.0;    //Factor of 10 million needed to convert!
200              Float_t unitEnergy = fUnit[towerID-1].GetUnitEnergy() + digitEnergy;
201              fUnit[towerID-1].SetUnitEnergy(unitEnergy);
202
203             }//end digits loop
204            }//end digits condition
205
206          //Set all unit flags, Eta, Phi
207          for(Int_t i=0; i<fNumUnits; i++)
208            {
209              if (fDebug>1) Info("FillUnitArray","Setting all units outside jets");
210              fUnit[i].SetUnitFlag(kOutJet);           //Set all units to be outside a jet initially
211              fUnit[i].SetUnitID(i+1);
212              Float_t eta;
213              Float_t phi;
214              geom->EtaPhiFromIndex(fUnit[i].GetUnitID(), eta, phi);
215              fUnit[i].SetUnitEta(eta);
216              fUnit[i].SetUnitPhi(phi*TMath::Pi()/180.0);
217              //      if(i>13000) cout<<"!!!!!!!!!!!!!!!!!For unit0, eta="<<eta<<" and phi="<<phi*TMath::Pi()/180.0<<" and ID="<<fUnit[i].GetUnitID()<<endl;
218              //  if(fUnit[i].GetUnitEnergy()>0) cout<<"Unit ID "<<fUnit[i].GetUnitID() <<"with eta="<<eta<<" and phi="<<phi*TMath::Pi()/180.0<<" has energy="<<fUnit[i].GetUnitEnergy()<<endl;
219            }//end loop over all units in array (same as all towers in EMCAL)
220    }
221
222
223  void AliEMCALJetFinderAlgoUA1Hybrid::Sort(AliEMCALJetFinderAlgoUA1Unit *unit, Int_t length)
224  {
225    //Calls the recursive quicksort method to sort unit objects in decending order of Energy
226    if (fDebug>1) Info("Sort","Sorting Unit objects");
227    QS(unit, 0, length-1);
228  }
229   
230
231  void AliEMCALJetFinderAlgoUA1Hybrid::QS(AliEMCALJetFinderAlgoUA1Unit *unit, Int_t left, Int_t right)
232  {
233   //Sorts the AliEMCALJetFinderAlgoUA1Unit objects in decending order of Energy
234    if (fDebug>111) Info("QS","QuickSorting Unit objects");   
235
236    Int_t    i;
237    Int_t    j;
238    AliEMCALJetFinderAlgoUA1Unit  unitFirst;
239    AliEMCALJetFinderAlgoUA1Unit  unitSecond;
240
241    i = left;
242    j = right;
243    unitFirst = unit[(left+right)/2];
244
245  do
246   {
247     while( (unit[i].GetUnitEnergy() > unitFirst.GetUnitEnergy()) && (i < right)) i++;
248     while( (unitFirst.GetUnitEnergy() > unit[j].GetUnitEnergy()) && (j > left)) j--;
249
250     if(i <= j)
251       {
252         unitSecond = unit[i];
253         unit[i] = unit[j];
254         unit[j] = unitSecond;
255         i++;
256         j--;
257       }//end if
258   }while(i <= j);
259
260  if(left < j) QS(unit, left, j);
261  if(i < right) QS(unit, i, right);
262  }
263
264
265  void AliEMCALJetFinderAlgoUA1Hybrid::FindBG()
266    {
267      //Finds the background energy for the iteration
268      if (fDebug>1) Info("FindBG","Finding Average Background"); 
269
270      fEBGTotal          = 0.0;
271      Int_t numCone      = 0;
272
273      //Loop over all unit objects in the array and sum the energy of those not in a jet
274      for(Int_t i=0; i<fNumUnits; i++)
275        {
276          if(fUnit[i].GetUnitFlag() != kInJet)
277            fEBGTotal += fUnit[i].GetUnitEnergy();
278          else numCone++;
279        }//end for
280
281      fEBGTotalOld = fEBGTotal;
282      fEBGAve = fEBGTotal / (fNumUnits - numCone);
283      if (fDebug>5) Info("FindBG","Average BG is %f: ",fEBGAve);      
284
285      for(Int_t count=0; count<fNumUnits;count++)
286        {
287          fUnit[count].SetUnitFlag(kOutJet);
288        }//end for
289    }
290
291
292  void AliEMCALJetFinderAlgoUA1Hybrid::FindJetEtaPhi(Int_t counter)
293    {
294      //Finds the eta and phi of the jet axis
295      if (fDebug>1) Info("FindJetEtaPhi","Finding Jet Eta and Phi");
296
297      fDEta = fUnit[counter].GetUnitEta() - fEtaInit;
298      fDPhi = fUnit[counter].GetUnitPhi() - fPhiInit;
299
300      fEnergy = fUnit[counter].GetUnitEnergy() - fEBGAve;
301      fJetEtaSum += fEnergy * fDEta;
302      fJetPhiSum += fEnergy * fDPhi;
303      fJetESum += fEnergy;
304      fJetEta = fEtaInit + (fJetEtaSum / fJetESum);
305      fJetPhi = fPhiInit + (fJetPhiSum / fJetESum);
306    }
307
308
309  void AliEMCALJetFinderAlgoUA1Hybrid::FindJetEnergy()
310    {
311      //Finds the energy of the jet after the final axis has been found
312      if (fDebug>1) Info("FindJetEnergy","Finding Jet Energy");
313
314      for(Int_t i=0; i<fNumUnits; i++)
315        {
316          //Loop over all unit objects in the array and find if within cone radius
317          Float_t dEta = fUnit[i].GetUnitEta() - fJetEta;
318          Float_t dPhi = fUnit[i].GetUnitPhi() - fJetPhi;
319          Float_t rad = TMath::Sqrt( (dEta*dEta) + (dPhi*dPhi) );
320
321          if(fUnit[i].GetUnitFlag()==kOutJet && rad<= fConeRad)
322            {
323              fUnit[i].SetUnitFlag(kInCurrentJet);
324              Float_t energy = fUnit[i].GetUnitEnergy() - fEBGAve;
325              fJetESum += energy;                             
326              fJetEtaSum += energy * dEta;
327              fJetPhiSum += energy * dPhi;
328              fNumInCone++;                     //Increment the number of cells in the jet cone
329            }//end if
330        }//end for
331    }
332
333
334  void AliEMCALJetFinderAlgoUA1Hybrid::StoreJetInfo()
335    {
336      //Stores the resulting jet information in appropriate storage structure (TO BE DECIDED!!!!)
337      if (fDebug>1) Info("StoreJetInfo","Storing Jet Information");
338     
339      //Store:
340      //fJetESum is the final jet energy (background has been subtracted)
341      //fJetEta is the final jet Eta
342      //fJetPhi is the final jet Phi
343      //fNumInCone is the final number of cells included in the jet cone
344      //fEtaInit is the eta of the initiator cell
345      //fPhiInit is the phi of the initiator cell
346      fJet.SetEnergy(fJetESum);
347      fJet.SetEta(fJetEta);
348      fJet.SetPhi(fJetPhi);
349
350       cout<<"For iteration "<<fNumIter <<" and Jet number " <<fNumJets <<endl;
351       cout<<"The jet energy is: " <<fJetESum <<endl;
352       cout<<"The jet eta is ---->" <<fJetEta <<endl;
353       cout<<"The jet phi is ---->" <<fJetPhi <<endl;
354
355      Int_t             numberTracks = fInputPointer->GetNTracks();
356      TParticle         *myP;
357      Int_t             numTracksInCone = 0;
358
359      for(Int_t counter=0; counter<numberTracks; counter++)
360        {
361         myP = fInputPointer->GetTrack(counter);
362         Float_t eta = myP->Eta();
363         Float_t phi = myP->Phi(); 
364         Float_t deta = fJetEta-eta;
365         Float_t dphi = fJetPhi -phi;
366         Float_t rad = TMath::Sqrt( (deta*deta) + (dphi*dphi));
367         if(rad<=fConeRad) numTracksInCone++;
368        }//end for
369
370      Float_t    *pTArray = new Float_t[numTracksInCone];
371      Float_t    *etaArray = new Float_t[numTracksInCone];
372      Float_t    *phiArray = new Float_t[numTracksInCone];
373      Int_t      *pdgArray = new Int_t[numTracksInCone];
374      Int_t             index = 0;
375
376      for(Int_t counter2=0; counter2<numberTracks; counter2++)
377        {
378          myP = fInputPointer->GetTrack(counter2);
379          Float_t eta = myP->Eta();
380          Float_t phi = myP->Phi(); 
381          Float_t deta = fJetEta-eta;
382          Float_t dphi = fJetPhi -phi;
383          Float_t rad = TMath::Sqrt( (deta*deta) + (dphi*dphi));
384          if(rad<=fConeRad)
385            {
386              pTArray[index] = myP->Pt();
387              etaArray[index] = eta;
388              phiArray[index] = phi;
389              pdgArray[index] = myP->GetPdgCode();
390              index++;
391            }//end if
392        }//end for
393
394      fJet.SetTrackList(numTracksInCone,pTArray, etaArray, phiArray, pdgArray);
395      fOutputObject.AddJet(&fJet);
396      delete[] pTArray;
397      delete[] etaArray;
398      delete[] phiArray;
399      delete[] pdgArray;
400    }
401
402
403  void AliEMCALJetFinderAlgoUA1Hybrid::FindJets()
404    {
405      //Runs the complete UA1 JetFinding algorithm to find jets!
406      if (fDebug>1) Info("FindJets","Starting Jet Finding!!!");
407
408      //If the array of JetFinderUnit objects has not been initialised then initialise with default settings
409      if(!fArrayInitialised) 
410       {
411        InitUnitArray();
412        FillUnitArray(kFillAll);
413       }//end if
414      if (fDebug>1) Info("FindJets","Unit array filled");
415
416      //Step 1. Sort the array in descending order of Energy
417      Sort(fUnit,fNumUnits);
418
419      //Step 2. Set the number of iterations and Number of jets found to zero to start
420      fNumIter = 0;
421      fNumJets = 0;
422
423      //Step 3. Begin the iteration loop to find jets
424      //Need to iterate the algorithm while number of iterations<2 OR number of iterations<10 AND 
425      //the value of the average background has changed more than specified amount
426      //Min iterations = 2, Max iterations = 10
427      //while(fNumIter<2 || (fNumIter <10 && ( (fEBGTotal-fEBGTotalOld)/fEBGTotal) > fBGMaxMove) )
428
429      while(fNumIter<2 || (fNumIter <10 && ( fEBGTotal-fEBGTotalOld) > fEBGTotal*fBGMaxMove) )
430        {
431         if (fDebug>1) Info("FindJets","Starting BIG iteration ---> %i",fNumIter);
432
433          //Step 4. Find the value of the average background energy
434          FindBG();
435          fOutputObject.Reset(kResetJets); //Reset output object to store info for new iteration
436          fNumJets=0;
437
438          //Loop over the array of unit objects and flag those with energy below MinCellEt
439          Int_t numbelow = 0;
440          for(Int_t j=0; j<fNumUnits; j++)
441            {
442              if( (fUnit[j].GetUnitEnergy()-fEBGAve) < fEtMin)
443                 {       
444                   //          fUnit[j].SetUnitFlag(kBelowMinEt);    TAKING OUT kBelow flag
445                   numbelow++;
446                 }//end if
447            }//end for
448          //cout<<"THERE WERE "<<numbelow<<" units with E <EtMin!!!!!!!!!!!!!!!"<<endl;
449
450          //Do quick check if there are no jets upfront
451          // if(fUnit[0].GetUnitFlag() == kBelowMinEt)
452          if( (fUnit[0].GetUnitEnergy()-fEBGAve) < fEtMin)
453            {
454             cout <<"There are no jets for this event!" <<endl;
455             break;
456            }//end if
457
458          //Step 5. Begin with the first jet candidate cell (JET SEED LOOP)
459          if (fDebug>5) Info("FindJets","Beginning JET SEED LOOP");
460          for(Int_t count=0; count<fNumUnits; count++)
461            {
462
463 //CHECK CONDITION HERE _ NOT SURE IF SHOULD MAYBE BE: GetUnitEnergy()-fEBGAve >fESeed?????????????????????????????
464              if(fUnit[count].GetUnitEnergy()>=fESeed && fUnit[count].GetUnitFlag()==kOutJet)
465                {
466                  fEnergy = fUnit[count].GetUnitEnergy() - fEBGAve;
467                  fJetEta = fUnit[count].GetUnitEta();
468                  fJetPhi = fUnit[count].GetUnitPhi();
469                  Int_t seedID = fUnit[count].GetUnitID();
470                  if (fDebug>5) Info("FindJets","Inside first candidate jet seed loop for time : %i", count);
471                  if (fDebug>5) Info("FindJets","Found candidate energy %f ",fEnergy);
472                  if (fDebug>5) Info("FindJets","Found candidate eta %f ", fJetEta);
473                  if (fDebug>5) Info("FindJets","Found candidate phi %f ", fJetPhi);
474                  if (fDebug>5) Info("FindJets","Found candidate ID %i", seedID);
475
476                  fEtaInit = fJetEta;
477                  fPhiInit = fJetPhi;
478                  fEtaB = fJetEta;
479                  fPhiB = fJetPhi;
480                  fJetESum = 0.0;
481                  fJetEtaSum = 0.0;
482                  fJetPhiSum = 0.0;
483        
484          //Step 6. Find Jet Eta and Phi
485                  //Loop over all units in the array to find the ones in the jet cone and determine contrib to Jet eta, phi
486                  do
487                    {
488                      for(Int_t count1=0; count1<fNumUnits; count1++)               
489                        {
490                          if(fUnit[count1].GetUnitID() == seedID) continue;   //skip unit if the jetseed to avoid doublecounting
491                          if(fUnit[count1].GetUnitFlag() == kOutJet)
492                            {
493                              fDEta = fUnit[count1].GetUnitEta() - fJetEta;
494                              fDPhi = fUnit[count1].GetUnitPhi() - fJetPhi;
495                              fRad = TMath::Sqrt( (fDEta*fDEta) + (fDPhi*fDPhi) );
496                              if(fRad <= fConeRad)
497                                {
498                                  FindJetEtaPhi(count1); 
499                                }//end if
500                            }//end if
501                        }//end for (Jet Eta, Phi LOOP)
502                              
503                       //Find the distance cone centre moved from previous cone centre
504                       if (fDebug>10) Info("FindJets","Checking if cone move small enough");
505                       fDistP = TMath::Sqrt( ((fJetEta-fEtaB)*(fJetEta-fEtaB)) + ((fJetPhi-fPhiB)*(fJetPhi-fPhiB)) );
506                       //     if(fDistP <= fMinMove) break;
507                              
508
509                       //Find the distance cone centre is from initiator cell
510                       if (fDebug>10) Info("FindJets","Checking if cone move too large");
511                       fDistI = TMath::Sqrt( ((fJetEtaSum/fJetESum)*(fJetEtaSum/fJetESum)) + ((fJetPhiSum/fJetESum)*
512                                                                                                     (fJetPhiSum/fJetESum)));
513
514                       if(fDistP>fMinMove && fDistI<fMaxMove)
515                         {
516                           fEtaB = fJetEta;
517                           fPhiB = fJetPhi;
518                         }//end if
519                  
520                    }while(fDistP>fMinMove && fDistI<fMaxMove);
521                           
522                  fJetEta = fEtaB;
523                  fJetPhi = fPhiB;
524
525
526        //Step 7. Find the Jet Energy
527                  if (fDebug>1) Info("FindJets","Looking for Jet energy");
528                  fJetESum = 0.0;
529                  fJetEtaSum = 0.0;
530                  fJetPhiSum = 0.0;
531                  fNumInCone = 0;
532                  FindJetEnergy();
533
534                  //cout<<"Number of cells in jet cone is: "<<fNumInCone<<endl;
535
536        //Step 8. Check if the jet is a valid jet
537                  //Check if cluster energy is above Min allowed to be a jet
538 //DID NOT DO THE COSH COMPARISON HERE -> NEED TO CHECK WHICH COMPARISON IS BEST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
539                  if (fDebug>5) Info("FindJets","Checking cluster is valid jet");
540                  if(fJetESum < fJetEMin)
541                    {
542                      for(Int_t count2=0; count2<fNumUnits; count2++)
543                        {
544                          if(fUnit[count2].GetUnitFlag()==kInCurrentJet || fUnit[count2].GetUnitFlag()==kOutJet)
545                            fUnit[count2].SetUnitFlag(kOutJet);
546                        }//end for
547                    if (fDebug>10) Info("FindJets","NOT a valid jet cell");
548                   }else
549                     {
550                      for(Int_t count2=0; count2<fNumUnits; count2++)
551                        {
552                          if(fUnit[count2].GetUnitFlag()==kInCurrentJet)
553                            {
554                              //      cout<<"Setting unit #"<<count2 <<" to be officially in a jet!"<<endl;
555                            fUnit[count2].SetUnitFlag(kInJet);
556                            }
557                        }//end for                       
558
559  //NEED TO CHECK FINAL WEIRD ITERATION OF ETA AND PHI CHANGES!!!!!!!!!
560                      //  fJetPhi += fJetPhiSum/fJetESum;        //CHECK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
561                      //  fJetEta += fJetEtaSum/fJetESum;        //CHECK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
562
563                      fNumJets++;              //Incrementing number of jets found
564                      StoreJetInfo();          //Storing jet info
565
566                  }//end if (check cluster above Min Jet Energy)
567                }//end if (Jet Seed condition)
568            }//end (JET SEED LOOP)
569
570 if (fDebug>5) Info("FindJets","End of BIG iteration number %i",fNumIter);
571 // this->Dump();
572          fNumIter++;
573        }//end 10 iteration WHILE LOOP
574  }
575
576
577
578
579
580
581
582
583
584
585