]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALJetFinderAlgoOmni.cxx
get tables from the aliroot directory if they are not in the current one
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALJetFinderAlgoOmni.cxx
1
2 //THIS Also includes summing ALL cells in the jetcone towards the jet energy NOT just those above threshold!!!!!
3
4
5 /**************************************************************************
6  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
7  *                                                                        *
8  * Author: The ALICE Off-line Project.                                    *
9  * Contributors are mentioned in the code where appropriate.              *
10  *                                                                        *
11  * Permission to use, copy, modify and distribute this software and its   *
12  * documentation strictly for non-commercial purposes is hereby granted   *
13  * without fee, provided that the above copyright notice appears in all   *
14  * copies and that both the copyright notice and this permission notice   *
15  * appear in the supporting documentation. The authors make no claims     *
16  * about the suitability of this software for any purpose. It is          *
17  * provided "as is" without express or implied warranty.                  *
18  **************************************************************************/
19
20 /*
21  
22 $Log$
23 Revision 1.11  2004/03/09 17:06:38  mhorner
24 Made more robust
25
26 Revision 1.10  2004/03/06 01:56:09  mhorner
27 Pythai comp code
28
29 Revision 1.9  2004/02/23 20:37:32  mhorner
30 changed geometry call
31
32 Revision 1.8  2004/01/29 23:28:44  mhorner
33 Jet Finder - hard coded geom parameters removed
34
35 Revision 1.7  2004/01/21 22:27:47  mhorner
36 Cleaning up coding conventions
37
38 Revision 1.6  2003/10/28 13:54:30  schutz
39 Compilation warnings fixed
40
41 Revision 1.5  2003/09/23 13:31:41  mhorner
42 Changed coordinate system
43
44 Revision 1.4  2003/09/19 13:16:20  mhorner
45 Added additional jet energy info
46
47
48 Revision 1.3  2003/09/04 12:49:56  mhorner
49 Changed hadron correction and added saving EMCAL and track contributions
50
51 */
52
53
54 //*--Author: Sarah Blyth (LBL)
55 //*--Based on UA1 jet algorithm from LUND JETSET called from EMC-erj
56
57 #include "TTask.h"
58 #include "AliEMCALJetFinderInput.h"
59 #include "AliEMCALJetFinderOutput.h"
60 #include "AliEMCALJetFinderAlgo.h"
61 #include "AliEMCALJetFinderAlgoOmni.h"
62 #include "AliEMCALJetFinderAlgoUA1Unit.h"
63 #include "AliEMCALGetter.h"
64 #include "AliEMCALGeometry.h"
65 #include "AliEMCAL.h"
66 #include "AliEMCALDigit.h"
67 #include "TParticle.h"
68 #include "AliRun.h"
69 #include "AliEMCALJet.h"
70 #include "TMath.h"
71
72
73 ClassImp(AliEMCALJetFinderAlgoOmni)
74
75   AliEMCALJetFinderAlgoOmni::AliEMCALJetFinderAlgoOmni()
76 {
77   //Default constructor
78 if (fDebug>0) Info("AliEMCALJetFinderAlgoOmni","Beginning Default Constructor");
79
80 // AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
81 //  AliEMCALGeometry * geom = gime->EMCALGeometry();
82   AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance("EMCAL_55_25","EMCAL");
83   fNumIter           = 0;
84   fNumUnits          = geom->GetNTowers();     //Number of towers in EMCAL
85   fESeed             = 5.0;       //Default value
86   fConeRad           = 0.3;       //Default value
87   fJetEMin           = 10.0;      //Default value
88   fEtMin             = 0.0;      //Default value
89   fMinMove           = 0.05;      //From original UA1 JetFinder
90   fMaxMove           = 0.15;      //From original UA1 JetFinder
91   fBGMaxMove         = 0.035;     //From original UA1 JetFinder
92   fPtCut             = 0;         
93   fHadCorr           = 0;       
94   fEBGTotal          = 1.0;       //Set to 1 so that no div by zero in first FindJets() loop
95   fEBGTotalOld       = 0.0;
96   fEBGAve            = 0.0;
97   fEnergy            = 0.0;
98   fJetEta            = 0.0;
99   fJetPhi            = 0.0;
100   fEtaInit           = 0.0;
101   fPhiInit           = 0.0;
102   fEtaB              = 0.0;
103   fPhiB              = 0.0;
104   fJetESum           = 0.0;
105   fJetEtaSum         = 0.0;
106   fJetPhiSum         = 0.0;
107   fDEta              = 0.0;
108   fDPhi              = 0.0;
109   fDistP             = 0.0;
110   fDistI             = 0.0;
111   fTempE             = 0.0;
112   fRad               = 2.0;      //Set to 2 to start 
113   fNumInCone         = 0;
114   fNumJets           = 0;
115   fArrayInitialised  = 0;        //Set to FALSE to start
116   fBGType            = kRatio;   //Set Ratio method as default BG subtraction method 
117   fBGPar             = -1.0;      //Set to 1 to start
118 }
119
120  AliEMCALJetFinderAlgoOmni::~AliEMCALJetFinderAlgoOmni()
121    {
122      //Destructor
123      if (fDebug>0) Info("AliEMCALJetFinderAlgoOmni","Beginning Destructor");
124      delete[] fUnit;
125      delete[] fUnitNoCuts;
126    }
127
128  void AliEMCALJetFinderAlgoOmni::SetJetFindingParameters
129                                (Int_t numUnits, Float_t eSeed, Float_t coneRad, Float_t jetEMin, Float_t etMin, 
130                                Float_t minMove, Float_t maxMove, Float_t bgMaxMove)
131    {
132      //Sets parameters for the JetFinding algorithm
133      if (fDebug>1) Info("SetJetFindingParameters","Setting parameters for JetFinding");
134
135      SetNumUnits(numUnits);
136      SetJetESeed(eSeed);
137      SetConeRad(coneRad);
138      SetJetEMin(jetEMin);
139      SetEtMin(etMin);
140      SetMinMove(minMove);
141      SetMaxMove(maxMove);
142      SetBGMaxMove(bgMaxMove);
143    }
144
145  void AliEMCALJetFinderAlgoOmni::SetJetFindingParameters
146                                (Int_t numUnits, Float_t eSeed, Float_t coneRad, Float_t jetEMin, Float_t etMin)
147    {
148      //Sets fewer parameters for the JetFinding algorithm
149      if (fDebug>1) Info("SetJetFindingParameters","Setting parameters for JetFinding");
150
151      SetNumUnits(numUnits);
152      SetJetESeed(eSeed);
153      SetConeRad(coneRad);
154      SetJetEMin(jetEMin);
155      SetEtMin(etMin);
156      SetMinMove(fMinMove);
157      SetMaxMove(fMaxMove);
158      SetBGMaxMove(fBGMaxMove);
159    }
160
161  void AliEMCALJetFinderAlgoOmni::InitUnitArray()
162    {
163      //Initialises unit arrays
164      if(fArrayInitialised) delete[] fUnit;
165      fUnit = new AliEMCALJetFinderAlgoUA1Unit[fNumUnits];
166      fUnitNoCuts = new AliEMCALJetFinderAlgoUA1Unit[fNumUnits];
167      fArrayInitialised = 1;
168    }
169
170  void AliEMCALJetFinderAlgoOmni::FillUnitArray(AliEMCALJetFinderAlgoUA1FillUnitFlagType_t flag)
171    {
172            // Fill the unit array 
173      if (fDebug>1) Info("FillUnitArray","Beginning FillUnitArray");
174          //    AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
175          //   if (pEMCAL){ 
176          //          AliEMCALGeometry* geom =  AliEMCALGeometry::GetInstance(pEMCAL->GetTitle(), "");
177          //     }else
178          //    {
179
180      AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
181      AliEMCALGeometry * geom = gime->EMCALGeometry();
182
183         //    }
184          
185      AliEMCALJetFinderAlgoUA1FillUnitFlagType_t option = flag;
186      Int_t         numTracks, numDigits;
187     
188      //Loops over all elements in the AliEMCALJetFinderAlgoUA1Unit array and 
189      //fills the objects with relevant values from the Data Input object
190      if (fDebug>10) Info("FillUnitArray","Filling array with Unit objects");
191      if (fDebug>15) Info("FillUnitArray","NTracks %i NDigits %i",fInputPointer->GetNTracks(),fInputPointer->GetNDigits());
192          numTracks = fInputPointer->GetNTracks();
193          numDigits = fInputPointer->GetNDigits();
194          TParticle         *myPart;
195          AliEMCALDigit     *myDigit;
196      if (!fPythiaComparison)
197      {
198          //Fill units with Track info if appropriate
199          if(option==kFillTracksOnly || option ==kFillAll) 
200            {          
201             for(Int_t j=0; j<numTracks; j++)
202             {
203              myPart = fInputPointer->GetTrack(j);
204              Float_t eta = myPart->Eta();
205              Float_t  phi = myPart->Phi();
206              Int_t towerID = geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi);
207              Float_t  pT = myPart->Pt();
208              Float_t unitEnergy = fUnit[towerID-1].GetUnitEnergy(); 
209              Float_t unitEnergyNoCuts = fUnitNoCuts[towerID-1].GetUnitEnergy();
210
211              
212              //OLD WAY:   //Do Hadron Correction
213               if(fHadCorr != 0)
214                {
215                  Double_t   fullP = myPart->P();
216                  Double_t   hCEnergy = fHadCorr->GetEnergy(fullP, (Double_t)eta);
217                  unitEnergy -= hCEnergy*TMath::Sin(myPart->Theta());
218                  unitEnergyNoCuts -= hCEnergy*TMath::Sin(myPart->Theta());
219                  fUnit[towerID-1].SetUnitEnergy(unitEnergy);
220                  fUnitNoCuts[towerID-1].SetUnitEnergy(unitEnergyNoCuts);
221                } //end Hadron Correction loop 
222               
223     
224              /*
225               //Do Hadron Correction with propagate phi for the track
226               if(fHadCorr != 0)
227                 {
228                   Bool_t curl = 1;
229                   Float_t deltaPhi;
230                   TParticlePDG *pdg = myPart->GetPDG();
231                   if(pdg->Charge() < 0)
232                     {
233                       deltaPhi = PropagatePhi(myPart->Pt(), -1.0, curl);
234                     }
235                   else{
236                     deltaPhi = PropagatePhi(myPart->Pt(), 1.0, curl);
237                   }
238                   phi += deltaPhi;
239                   //Get new tower id for cell that track would curve into
240                   Int_t towerID2;
241                   if(phi>(TMath::Pi()/180.0)*geom->GetArm1PhiMax() || phi<(TMath::Pi()/180.0)*geom->GetArm1PhiMin())
242                     {
243                       towerID2 = -1;
244                     }
245                   else{
246                       towerID2 = geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi);
247                     }
248                   
249                   if(towerID2 != -1)
250                     {
251                       //Find unit energy of new tower
252                       Float_t unitEnergy2 = fUnit[towerID2-1].GetUnitEnergy();
253                       Float_t unitEnergy2NoCuts = fUnitNoCuts[towerID2-1].GetUnitEnergy();
254                       Double_t   fullP = myPart->P();
255                       Double_t   hCEnergy = fHadCorr->GetEnergy(fullP, (Double_t)eta);
256                       unitEnergy2 -= hCEnergy*TMath::Sin(myPart->Theta());
257                       unitEnergy2NoCuts -= hCEnergy*TMath::Sin(myPart->Theta());
258                       fUnit[towerID2-1].SetUnitEnergy(unitEnergy2);
259                       fUnitNoCuts[towerID2-1].SetUnitEnergy(unitEnergy2NoCuts);
260                     }//end if for towerID2
261                 }//end Hadron Correction loop
262              */
263
264               fUnitNoCuts[towerID-1].SetUnitEnergy(unitEnergyNoCuts + pT);
265              //Do Pt cut on tracks
266              if(fPtCut != 0 && pT < fPtCut) continue;
267
268              fUnit[towerID-1].SetUnitEnergy(unitEnergy+pT);
269
270              }//end tracks loop
271            }//end Tracks condition
272
273
274          //Fill units with Digit info if appropriate
275          if(option ==kFillDigitsOnly || option ==kFillAll)
276            {
277             for(Int_t k=0; k<numDigits; k++)
278             {
279              myDigit = fInputPointer->GetDigit(k);
280              if (fDebug>10) Info("FillUnitArray","getting digits %i %i numdigits",k,numDigits );
281              Int_t towerID = myDigit->GetId();
282              Int_t amplitude = myDigit->GetAmp();     //Gets the integer valued amplitude of the digit
283              Float_t amp = (Float_t)amplitude;        //Need to typecast to Float_t before doing real energy conversion
284              Float_t digitEnergy = amp/10000000.0;    //Factor of 10 million needed to convert!
285              Float_t unitEnergy = fUnit[towerID-1].GetUnitEnergy() + digitEnergy;
286              Float_t unitEnergyNoCuts = fUnitNoCuts[towerID-1].GetUnitEnergy() + digitEnergy;
287              fUnit[towerID-1].SetUnitEnergy(unitEnergy);
288              fUnitNoCuts[towerID-1].SetUnitEnergy(unitEnergyNoCuts);
289             }//end digits loop
290            }//end digits condition
291
292          //Set all unit flags, Eta, Phi
293          for(Int_t i=0; i<fNumUnits; i++)
294            {
295              if (fDebug>10) Info("FillUnitArray","Setting all units outside jets");
296              //Set all units to be outside a jet initially
297              fUnit[i].SetUnitFlag(kOutJet);           
298              fUnit[i].SetUnitID(i+1);
299              Float_t eta;
300              Float_t phi;
301              geom->EtaPhiFromIndex(fUnit[i].GetUnitID(), eta, phi);
302              fUnit[i].SetUnitEta(eta);
303              fUnit[i].SetUnitPhi(phi*TMath::Pi()/180.0);
304              //Set all units to be outside a jet initially
305              fUnitNoCuts[i].SetUnitFlag(kOutJet);          
306              fUnitNoCuts[i].SetUnitID(i+1);
307              eta = 0.0;
308              phi = 0.0;
309              geom->EtaPhiFromIndex(fUnitNoCuts[i].GetUnitID(), eta, phi);
310              fUnitNoCuts[i].SetUnitEta(eta);
311              fUnitNoCuts[i].SetUnitPhi(phi*TMath::Pi()/180.0);
312              //      if(i>13000) cout<<"!!!!!!!!!!!!!!!!!For unit0, eta="<<eta<<" and phi="<<phi*TMath::Pi()/180.0<<" and ID="<<fUnit[i].GetUnitID()<<endl;
313              //  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;
314            }//end loop over all units in array (same as all towers in EMCAL)
315
316      }
317      if (fPythiaComparison)
318      {
319              for(Int_t j=0; j<numTracks; j++)                            
320              {
321                      myPart = fInputPointer->GetTrack(j);
322                      fUnit[j].SetUnitID(j);
323                      fUnit[j].SetUnitFlag(kOutJet);
324                      fUnit[j].SetUnitEta(myPart->Eta());
325                      fUnit[j].SetUnitPhi(myPart->Phi());
326                      if (myPart->Energy()*TMath::Sin(myPart->Theta()) > fPtCut)
327                      {
328                              fUnit[j].SetUnitEnergy(myPart->Energy()*TMath::Sin(myPart->Theta()));
329                      }else
330                      {
331                              fUnit[j].SetUnitEnergy(0.00);
332                      }
333                      fUnitNoCuts[j].SetUnitID(j);
334                      fUnitNoCuts[j].SetUnitFlag(kOutJet);
335                      fUnitNoCuts[j].SetUnitEta(myPart->Eta());
336                      fUnitNoCuts[j].SetUnitPhi(myPart->Phi());
337                      fUnitNoCuts[j].SetUnitEnergy(myPart->Energy()*TMath::Sin(myPart->Theta()));
338              }
339              for(Int_t k=numTracks; k < fNumUnits; k++)
340              {
341                      fUnit[k].SetUnitID(k);
342                      fUnit[k].SetUnitFlag(kBelowMinEt);
343                      fUnit[k].SetUnitEta(0.0);
344                      fUnit[k].SetUnitPhi(0.0);
345                      fUnit[k].SetUnitEnergy(0.0);                    
346                      fUnitNoCuts[k].SetUnitID(k);
347                      fUnitNoCuts[k].SetUnitFlag(kBelowMinEt);
348                      fUnitNoCuts[k].SetUnitEta(0.0);
349                      fUnitNoCuts[k].SetUnitPhi(0.0);
350                      fUnitNoCuts[k].SetUnitEnergy(0.0);                   
351              }
352      }
353
354
355
356    }
357
358
359  void AliEMCALJetFinderAlgoOmni::Sort(AliEMCALJetFinderAlgoUA1Unit *unit, Int_t length)
360  {
361    //Calls the recursive quicksort method to sort unit objects in decending order of Energy
362    if (fDebug>1) Info("Sort","Sorting Unit objects");
363    QS(unit, 0, length-1);
364  }
365   
366
367  void AliEMCALJetFinderAlgoOmni::QS(AliEMCALJetFinderAlgoUA1Unit *unit, Int_t left, Int_t right)
368  {
369   //Sorts the AliEMCALJetFinderAlgoUA1Unit objects in decending order of Energy
370    if (fDebug>111) Info("QS","QuickSorting Unit objects");   
371
372    Int_t    i;
373    Int_t    j;
374    AliEMCALJetFinderAlgoUA1Unit  unitFirst;
375    AliEMCALJetFinderAlgoUA1Unit  unitSecond;
376
377    i = left;
378    j = right;
379    unitFirst = unit[(left+right)/2];
380
381  do
382   {
383     while( (unit[i].GetUnitEnergy() > unitFirst.GetUnitEnergy()) && (i < right)) i++;
384     while( (unitFirst.GetUnitEnergy() > unit[j].GetUnitEnergy()) && (j > left)) j--;
385
386     if(i <= j)
387       {
388         unitSecond = unit[i];
389         unit[i] = unit[j];
390         unit[j] = unitSecond;
391         i++;
392         j--;
393       }//end if
394   }while(i <= j);
395
396  if(left < j) QS(unit, left, j);
397  if(i < right) QS(unit, i, right);
398  }
399
400
401  void AliEMCALJetFinderAlgoOmni::FindBG()
402  {
403    if(fBGType == kRatio) RatioBG();
404    else if(fBGType == kCone) ConeBG();
405    else if(fBGType == kConstant) ConstantBG();
406  }
407
408  void AliEMCALJetFinderAlgoOmni::RatioBG()
409    {
410      //Finds the background energy for the iteration
411      //using the Ratio method
412      if (fDebug>1) Info("FindBG","Finding Average Background"); 
413      //Store BGEperCell from previous iteration!
414      fEBGTotalOld = fEBGTotal;
415      fEBGTotal          = 0.0;
416      Int_t numCone      = 0;
417
418      //If user has not set fBGPar, set it to the default
419      //for TPC = 90% efficiency, PtCut = 2GeV/c, timecut = 30ns
420      if(fBGPar == -1) fBGPar = 0.4685;
421
422      //Loop over all unit objects in the Unit array and link to same
423      //unit ID in NoCuts Unit array
424      for(Int_t i=0; i<fNumUnits; i++)
425        {
426          if(fUnit[i].GetUnitFlag() != kInJet)
427            {
428              Int_t id = fUnit[i].GetUnitID();
429              fEBGTotal += fUnitNoCuts[id-1].GetUnitEnergy();  
430            }
431          else numCone++;
432        }//end for
433
434      fEBGTotal *= fBGPar;
435      fEBGAve = fEBGTotal / (fNumUnits - numCone);
436      if (fDebug>5) Info("FindBG","Average BG is %f: ",fEBGAve); 
437
438      for(Int_t count=0; count<fNumUnits;count++)
439        {
440          fUnit[count].SetUnitFlag(kOutJet);
441        }//end for
442    }
443
444  void AliEMCALJetFinderAlgoOmni::ConeBG()
445    {
446      //Finds the background energy for the iteration
447      //using all energy not contained inside a jet
448      if (fDebug>1) Info("FindBG","Finding Average Background"); 
449      //Store old value of BGEperCell!
450      fEBGTotalOld = fEBGTotal;
451      fEBGTotal          = 0.0;
452      Int_t numCone      = 0;
453
454      //Loop over all unit objects in the array and sum the energy of those not in a jet
455      for(Int_t i=0; i<fNumUnits; i++)
456        {
457          if(fUnit[i].GetUnitFlag() != kInJet)
458            fEBGTotal += fUnit[i].GetUnitEnergy();
459          else numCone++;
460        }//end for
461
462      fEBGAve = fEBGTotal / (fNumUnits - numCone);
463      if (fDebug>5) Info("FindBG","Average BG is %f: ",fEBGAve);      
464
465      for(Int_t count=0; count<fNumUnits;count++)
466        {
467          fUnit[count].SetUnitFlag(kOutJet);
468        }//end for
469    }
470
471  void AliEMCALJetFinderAlgoOmni::ConstantBG()
472    {     
473      //Finds the background energy for the iteration
474      //using all energy not contained inside a jet
475      if (fDebug>1) Info("FindBG","Finding Average Background"); 
476
477      //If user has not set fBGPar, set it to the default
478      //for TPC = 90% efficiency, PtCut = 2GeV/c, timecut = 30ns
479      if(fBGPar == -1) fBGPar = 0.03378;
480
481      fEBGAve = fBGPar;
482      if (fDebug>5) Info("FindBG","Average BG is %f: ",fEBGAve);      
483
484      fEBGTotal          = 0.0;
485      Int_t numCone      = 0;
486      for(Int_t count=0; count<fNumUnits;count++)
487        {
488          if(fUnit[count].GetUnitFlag() == kInJet)
489            {
490              numCone++;
491            }
492          fUnit[count].SetUnitFlag(kOutJet);
493        }//end for
494      fEBGTotal = fEBGAve * (fNumUnits-numCone);
495      fEBGTotalOld = fEBGTotal;
496    }
497
498  void AliEMCALJetFinderAlgoOmni::FindJetEtaPhi(Int_t counter)
499    {
500      //Finds the eta and phi of the jet axis
501      if (fDebug>10) Info("FindJetEtaPhi","Finding Jet Eta and Phi");
502
503      fDEta = fUnit[counter].GetUnitEta() - fEtaInit;
504      fDPhi = fUnit[counter].GetUnitPhi() - fPhiInit;
505
506      fEnergy = fUnit[counter].GetUnitEnergy() - fEBGAve;
507      fJetEtaSum += fEnergy * fDEta;
508      fJetPhiSum += fEnergy * fDPhi;
509      fJetESum += fEnergy;
510      if (fJetESum >1.0e-7)
511      {
512              fJetEta = fEtaInit + (fJetEtaSum / fJetESum);
513              fJetPhi = fPhiInit + (fJetPhiSum / fJetESum);
514      }
515    }
516
517
518  void AliEMCALJetFinderAlgoOmni::FindJetEnergy()
519    {
520      //Finds the energy of the jet after the final axis has been found
521      if (fDebug>1) Info("FindJetEnergy","Finding Jet Energy");
522
523      for(Int_t i=0; i<fNumUnits; i++)
524        {
525          //Loop over all unit objects in the array and find if within cone radius
526          Float_t dEta = fUnit[i].GetUnitEta() - fJetEta;
527          Float_t dPhi = fUnit[i].GetUnitPhi() - fJetPhi;
528          Float_t rad;
529          if ((dEta*dEta) + (dPhi*dPhi)>1.e-7)
530          {
531                  rad = TMath::Sqrt( (dEta*dEta) + (dPhi*dPhi) );
532          }else
533          {
534                  rad=0.0;
535          }
536
537          if(fUnit[i].GetUnitFlag()==kOutJet && rad<= fConeRad)
538            {
539              fUnit[i].SetUnitFlag(kInCurrentJet);
540              Float_t energy = fUnit[i].GetUnitEnergy() - fEBGAve;
541              fJetESum += energy;                             
542              fJetEtaSum += energy * dEta;
543              fJetPhiSum += energy * dPhi;
544              fNumInCone++;                     //Increment the number of cells in the jet cone
545            }//end if
546        }//end for
547    }
548
549
550  void AliEMCALJetFinderAlgoOmni::StoreJetInfo()
551    {
552      //Stores the resulting jet information in appropriate storage structure (TO BE DECIDED!!!!)
553      if (fDebug>1) Info("StoreJetInfo","Storing Jet Information");
554      AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
555      AliEMCALGeometry * geom = gime->EMCALGeometry();
556      //Store:
557      //fJetESum is the final jet energy (background has been subtracted)
558      //fJetEta is the final jet Eta
559      //fJetPhi is the final jet Phi
560      //fNumInCone is the final number of cells included in the jet cone
561      //fEtaInit is the eta of the initiator cell
562      //fPhiInit is the phi of the initiator cell
563      fJet.SetEnergy(fJetESum);
564      fJet.SetEta(fJetEta);
565      fJet.SetPhi(fJetPhi);
566
567       cout<<"For iteration "<<fNumIter <<" and Jet number " <<fNumJets <<endl;
568       cout<<"The jet energy is: " <<fJetESum <<endl;
569       cout<<"The jet eta is ---->" <<fJetEta <<endl;
570       cout<<"The jet phi is ---->" <<fJetPhi <<endl;
571
572      Int_t             numberTracks = fInputPointer->GetNTracks();
573      Int_t             numberDigits = fInputPointer->GetNDigits();
574      AliEMCALDigit     *myD;
575      TParticle         *myP;
576      Int_t             numTracksInCone = 0;
577      Float_t           trackEnergy = 0.0;
578      Float_t           trackEnergyPtCut =0.0; 
579      Float_t           emcalEnergy = 0.0;
580      Float_t           emcalEnergyBGSub = 0.0;
581
582      for(Int_t counter=0; counter<numberTracks; counter++)
583        {
584         myP = fInputPointer->GetTrack(counter);
585         Float_t eta = myP->Eta();
586         Float_t phi = myP->Phi(); 
587         Float_t deta = fJetEta-eta;
588         Float_t dphi = fJetPhi -phi;
589         Float_t rad = TMath::Sqrt( (deta*deta) + (dphi*dphi));
590         if(rad<=fConeRad) numTracksInCone++;
591        }//end for
592
593      Float_t    *pTArray = new Float_t[numTracksInCone];
594      Float_t    *etaArray = new Float_t[numTracksInCone];
595      Float_t    *phiArray = new Float_t[numTracksInCone];
596      Int_t      *pdgArray = new Int_t[numTracksInCone];
597      Int_t             index = 0;
598
599      for(Int_t counter2=0; counter2<numberTracks; counter2++)
600        {
601          myP = fInputPointer->GetTrack(counter2);
602          Float_t eta = myP->Eta();
603          Float_t phi = myP->Phi(); 
604          Float_t deta = fJetEta-eta;
605          Float_t dphi = fJetPhi -phi;
606          Float_t rad ;
607          if ((deta*deta) + (dphi*dphi)>1.e-7)
608          {
609                  rad = TMath::Sqrt( (deta*deta) + (dphi*dphi) );
610          }else
611          {
612                  rad=0.0;
613          }
614
615          if(rad<=fConeRad)
616            {
617              pTArray[index] = myP->Pt();
618              //Calculate track contribution within jetcone
619              trackEnergy += myP->Pt();
620              if(myP->Pt() >= fPtCut) trackEnergyPtCut += myP->Pt();
621              etaArray[index] = eta;
622              phiArray[index] = phi;
623              pdgArray[index] = myP->GetPdgCode();
624              index++;
625              if(fHadCorr != 0)
626              {
627                      Double_t   fullP = myP->P();
628                      Double_t   hCEnergy = fHadCorr->GetEnergy(fullP, (Double_t)eta);
629                      emcalEnergy -= hCEnergy*TMath::Sin(myP->Theta());
630                      emcalEnergyBGSub -= hCEnergy*TMath::Sin(myP->Theta());
631              } //end Hadron Correction loop 
632                            
633            }//end if
634        }//end for
635
636      //Loop over digits to find EMCal contribution within jetcone
637      for(Int_t counter3=0; counter3<numberDigits; counter3++)
638        {
639          myD = fInputPointer->GetDigit(counter3);
640          //GET DIGIT ETA, PHI so that can check if inside R!
641          Float_t eta = 0.0;
642          Float_t phi = 0.0;
643          Int_t iID = myD->GetId();
644          geom->EtaPhiFromIndex(iID, eta, phi);
645          Float_t deta = fJetEta-eta;
646          Float_t dphi = fJetPhi -(TMath::Pi()/180.0)*phi;
647          //Float_t rad = TMath::Sqrt( (deta*deta) + (dphi*dphi));
648          Float_t rad ;
649          if ((deta*deta) + (dphi*dphi)>1.e-7)
650          {
651                  rad = TMath::Sqrt( (deta*deta) + (dphi*dphi) );
652          }else
653          {
654                  rad=0.0;
655          }
656
657          if(rad<=fConeRad)
658            {
659          Int_t amplitude = myD->GetAmp();     //Gets the integer valued amplitude of the digit
660          Float_t amp = (Float_t)amplitude;        //Need to typecast to Float_t before doing real energy conversion
661          Float_t digitEnergy = amp/10000000.0;    //Factor of 10 million needed to convert!
662          emcalEnergy += digitEnergy;
663          emcalEnergyBGSub += (digitEnergy - fEBGAve);
664            }//end if
665        }//end count3 for
666
667      //Save in JET object
668      fJet.SetTrackList(numTracksInCone,pTArray, etaArray, phiArray, pdgArray);
669      fJet.SetEMCALEnergy(emcalEnergy);
670      fJet.SetEMCALEnergyBGSub(emcalEnergyBGSub);
671      fJet.SetTrackEnergy(trackEnergy);
672      fJet.SetTrackEnergyPtCut(trackEnergyPtCut);
673      fOutputObject.AddJet(&fJet);
674      delete[] pTArray;
675      delete[] etaArray;
676      delete[] phiArray;
677      delete[] pdgArray;
678    }
679
680
681  void AliEMCALJetFinderAlgoOmni::FindJets()
682    {
683      //Runs the complete UA1 JetFinding algorithm to find jets!
684      if (fDebug>1) Info("FindJets","Starting Jet Finding!!!");
685
686      //If the array of JetFinderUnit objects has not been initialised then initialise with default settings
687      if(!fArrayInitialised) 
688       {
689        InitUnitArray();
690        FillUnitArray(kFillAll);
691       }//end if
692      if (fDebug>1) Info("FindJets","Unit array filled");
693
694      //Step 1. Sort the array in descending order of Energy
695      Sort(fUnit,fNumUnits);
696
697      //Step 2. Set the number of iterations and Number of jets found to zero to start
698      fNumIter = 0;
699      fNumJets = 0;
700
701      //Step 3. Begin the iteration loop to find jets
702      //Need to iterate the algorithm while number of iterations<2 OR number of iterations<10 AND 
703      //the value of the average background has changed more than specified amount
704      //Min iterations = 2, Max iterations = 10
705      //while(fNumIter<2 || (fNumIter <10 && ( (fEBGTotal-fEBGTotalOld)/fEBGTotal) > fBGMaxMove) )
706
707      while(fNumIter<2 || (fNumIter <10 && ( fEBGTotal-fEBGTotalOld) > fEBGTotal*fBGMaxMove) )
708        {
709         if (fDebug>1) Info("FindJets","Starting BIG iteration ---> %i",fNumIter);
710
711          //Step 4. Find the value of the average background energy
712          FindBG();
713          fOutputObject.Reset(kResetJets); //Reset output object to store info for new iteration
714          fNumJets=0;
715
716          //Loop over the array of unit objects and flag those with energy below MinCellEt
717          Int_t numbelow = 0;
718          for(Int_t j=0; j<fNumUnits; j++)
719            {
720              if( (fUnit[j].GetUnitEnergy()-fEBGAve) < fEtMin)
721                 {       
722                   //          fUnit[j].SetUnitFlag(kBelowMinEt);    TAKING OUT kBelow flag
723                   numbelow++;
724                 }//end if
725            }//end for
726          //cout<<"THERE WERE "<<numbelow<<" units with E <EtMin!!!!!!!!!!!!!!!"<<endl;
727
728          //Do quick check if there are no jets upfront
729          // if(fUnit[0].GetUnitFlag() == kBelowMinEt)
730          if( (fUnit[0].GetUnitEnergy()-fEBGAve) < fEtMin)
731            {
732             cout <<"There are no jets for this event!" <<endl;
733             break;
734            }//end if
735
736          //Step 5. Begin with the first jet candidate cell (JET SEED LOOP)
737          if (fDebug>5) Info("FindJets","Beginning JET SEED LOOP");
738          for(Int_t count=0; count<fNumUnits; count++)
739            {
740
741 //CHECK CONDITION HERE _ NOT SURE IF SHOULD MAYBE BE: GetUnitEnergy()-fEBGAve >fESeed?????????????????????????????
742              if(fUnit[count].GetUnitEnergy()>=fESeed && fUnit[count].GetUnitFlag()==kOutJet)
743                {
744                  fEnergy = fUnit[count].GetUnitEnergy() - fEBGAve;
745                  fJetEta = fUnit[count].GetUnitEta();
746                  fJetPhi = fUnit[count].GetUnitPhi();
747                  Int_t seedID = fUnit[count].GetUnitID();
748                  if (fDebug>5) Info("FindJets","Inside first candidate jet seed loop for time : %i", count);
749                  if (fDebug>5) Info("FindJets","Found candidate energy %f ",fEnergy);
750                  if (fDebug>5) Info("FindJets","Found candidate eta %f ", fJetEta);
751                  if (fDebug>5) Info("FindJets","Found candidate phi %f ", fJetPhi);
752                  if (fDebug>5) Info("FindJets","Found candidate ID %i", seedID);
753
754                  fEtaInit = fJetEta;
755                  fPhiInit = fJetPhi;
756                  fEtaB = fJetEta;
757                  fPhiB = fJetPhi;
758                  fJetESum = 0.0;
759                  fJetEtaSum = 0.0;
760                  fJetPhiSum = 0.0;
761        
762          //Step 6. Find Jet Eta and Phi
763                  //Loop over all units in the array to find the ones in the jet cone and determine contrib to Jet eta, phi
764                  do
765                    {
766                      for(Int_t count1=0; count1<fNumUnits; count1++)               
767                        {
768                          if(fUnit[count1].GetUnitID() == seedID) continue;   //skip unit if the jetseed to avoid doublecounting
769                          if(fUnit[count1].GetUnitFlag() == kOutJet)
770                            {
771                              fDEta = fUnit[count1].GetUnitEta() - fJetEta;
772                              fDPhi = fUnit[count1].GetUnitPhi() - fJetPhi;
773                              if ( (fDEta*fDEta) + (fDPhi*fDPhi) >1.e-7)
774                              {
775                                      fRad = TMath::Sqrt( (fDEta*fDEta) + (fDPhi*fDPhi) );
776                              }else
777                              {
778                                      fRad=0.000;
779                              }
780                              if(fRad <= fConeRad)
781                                {
782                                  FindJetEtaPhi(count1); 
783                                }//end if
784                            }//end if
785                        }//end for (Jet Eta, Phi LOOP)
786                              
787                       //Find the distance cone centre moved from previous cone centre
788                       if (fDebug>10) Info("FindJets","Checking if cone move small enough");
789                       if (((fJetEta-fEtaB)*(fJetEta-fEtaB)) + ((fJetPhi-fPhiB)*(fJetPhi-fPhiB))  >1.e-7)
790                       {
791                               fDistP = TMath::Sqrt( ((fJetEta-fEtaB)*(fJetEta-fEtaB)) + ((fJetPhi-fPhiB)*(fJetPhi-fPhiB)) );
792                       }else
793                       {
794                               fDistP = 0.00;
795                       }
796                       //     if(fDistP <= fMinMove) break;
797                              
798
799                       //Find the distance cone centre is from initiator cell
800                       if (fDebug>10) Info("FindJets","Checking if cone move too large");
801                       if ( ((fJetEtaSum)*(fJetEtaSum))+((fJetPhiSum)*(fJetPhiSum)) >1.e-7)
802                       {
803                               fDistI = TMath::Sqrt( ((fJetEtaSum/fJetESum)*(fJetEtaSum/fJetESum)) + ((fJetPhiSum/fJetESum)*
804                                                                                                     (fJetPhiSum/fJetESum)));
805                       }else
806                       {
807                               fDistI = 0.00;
808                       }
809
810                       if(fDistP>fMinMove && fDistI<fMaxMove)
811                         {
812                           fEtaB = fJetEta;
813                           fPhiB = fJetPhi;
814                         }//end if
815                  
816                    }while(fDistP>fMinMove && fDistI<fMaxMove);
817                           
818                  fJetEta = fEtaB;
819                  fJetPhi = fPhiB;
820
821
822        //Step 7. Find the Jet Energy
823                  if (fDebug>1) Info("FindJets","Looking for Jet energy");
824                  fJetESum = 0.0;
825                  fJetEtaSum = 0.0;
826                  fJetPhiSum = 0.0;
827                  fNumInCone = 0;
828                  FindJetEnergy();
829
830                  //cout<<"Number of cells in jet cone is: "<<fNumInCone<<endl;
831
832        //Step 8. Check if the jet is a valid jet
833                  //Check if cluster energy is above Min allowed to be a jet
834 //DID NOT DO THE COSH COMPARISON HERE -> NEED TO CHECK WHICH COMPARISON IS BEST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
835                  if (fDebug>5) Info("FindJets","Checking cluster is valid jet");
836                  if(fJetESum < fJetEMin)
837                    {
838                      for(Int_t count2=0; count2<fNumUnits; count2++)
839                        {
840                          if(fUnit[count2].GetUnitFlag()==kInCurrentJet || fUnit[count2].GetUnitFlag()==kOutJet)
841                            fUnit[count2].SetUnitFlag(kOutJet);
842                        }//end for
843                    if (fDebug>10) Info("FindJets","NOT a valid jet cell");
844                   }else
845                     {
846                      for(Int_t count2=0; count2<fNumUnits; count2++)
847                        {
848                          if(fUnit[count2].GetUnitFlag()==kInCurrentJet)
849                            {
850                              //      cout<<"Setting unit #"<<count2 <<" to be officially in a jet!"<<endl;
851                            fUnit[count2].SetUnitFlag(kInJet);
852                            }
853                        }//end for                       
854
855  //NEED TO CHECK FINAL WEIRD ITERATION OF ETA AND PHI CHANGES!!!!!!!!!
856                      //  fJetPhi += fJetPhiSum/fJetESum;        //CHECK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
857                      //  fJetEta += fJetEtaSum/fJetESum;        //CHECK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
858
859                      fNumJets++;              //Incrementing number of jets found
860                      StoreJetInfo();          //Storing jet info
861
862                  }//end if (check cluster above Min Jet Energy)
863                }//end if (Jet Seed condition)
864            }//end (JET SEED LOOP)
865
866 if (fDebug>5) Info("FindJets","End of BIG iteration number %i",fNumIter);
867 // this->Dump();
868          fNumIter++;
869        }//end 10 iteration WHILE LOOP
870  }
871
872
873
874
875
876
877
878
879
880
881