2 //THIS Also includes summing ALL cells in the jetcone towards the jet energy NOT just those above threshold!!!!!
5 /**************************************************************************
6 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
8 * Author: The ALICE Off-line Project. *
9 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
23 Revision 1.2 2006/06/02 23:03:03 pavlinov
24 ALICE numbering scheme
26 Revision 1.1 2006/02/28 21:56:34 jklay
27 moving jetfinder code to subdirectory
29 Revision 1.16 2006/02/15 15:11:05 pavlinov
30 update of Jenn and Marco
32 Revision 1.15 2004/11/22 19:52:05 mhorner
33 Make sure pi0 get through
35 Revision 1.14 2004/04/02 17:11:33 mhorner
36 Marco's bug - fixes implemented
38 Revision 1.13 2004/03/26 01:00:38 mhorner
39 Implementing Marco's optimisations
41 Revision 1.12 2004/03/15 19:59:37 mhorner
42 Pyhtia comparison extended
44 Revision 1.11 2004/03/09 17:06:38 mhorner
47 Revision 1.10 2004/03/06 01:56:09 mhorner
50 Revision 1.9 2004/02/23 20:37:32 mhorner
53 Revision 1.8 2004/01/29 23:28:44 mhorner
54 Jet Finder - hard coded geom parameters removed
56 Revision 1.7 2004/01/21 22:27:47 mhorner
57 Cleaning up coding conventions
59 Revision 1.6 2003/10/28 13:54:30 schutz
60 Compilation warnings fixed
62 Revision 1.5 2003/09/23 13:31:41 mhorner
63 Changed coordinate system
65 Revision 1.4 2003/09/19 13:16:20 mhorner
66 Added additional jet energy info
69 Revision 1.3 2003/09/04 12:49:56 mhorner
70 Changed hadron correction and added saving EMCAL and track contributions
75 //*--Author: Sarah Blyth (LBL)
76 //*--Based on UA1 jet algorithm from LUND JETSET called from EMC-erj
80 #include "TParticle.h"
82 #include "AliRunLoader.h"
83 #include "AliEMCALJetFinderInput.h"
84 #include "AliEMCALJetFinderOutput.h"
85 #include "AliEMCALJetFinderAlgo.h"
86 #include "AliEMCALJetFinderAlgoOmni.h"
87 #include "AliEMCALJetFinderAlgoUA1Unit.h"
88 #include "AliEMCALGeometry.h"
89 #include "AliEMCALLoader.h"
91 #include "AliEMCALDigit.h"
92 #include "AliEMCALJet.h"
95 ClassImp(AliEMCALJetFinderAlgoOmni)
97 AliEMCALJetFinderAlgoOmni::AliEMCALJetFinderAlgoOmni() :
98 fUnit(0),fUnitNoCuts(0),fHadCorr(0),fBGType(kRatio),fNumIter(0),
99 fNumUnits(0),fESeed(0.),fConeRad(0.),fJetEMin(0.),fEtMin(0.),
100 fMinMove(0.),fMaxMove(0.),fBGMaxMove(0.),fPtCut(0.),fBGPar(0.),
101 fEBGTotal(0.),fEBGTotalOld(0.),fEBGAve(0.),fEnergy(0.),fJetEta(0.),
102 fJetPhi(0.),fEtaInit(0.),fPhiInit(0.),fEtaB(0.),fPhiB(0.),fJetESum(0.),
103 fJetEtaSum(0.),fJetPhiSum(0.),fDEta(0.),fDPhi(0.),fDistP(0.),fDistI(0.),
104 fTempE(0.),fRad(0.),fNumInCone(0),fNumJets(0),fArrayInitialised(0)
106 //Default constructor
107 if (fDebug>0) Info("AliEMCALJetFinderAlgoOmni","Beginning Default Constructor");
108 AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance("EMCAL_55_25","EMCAL");
110 fNumUnits = geom->GetNTowers(); //Number of towers in EMCAL
111 fESeed = 5.0; //Default value
112 fConeRad = 0.3; //Default value
113 fJetEMin = 10.0; //Default value
114 fEtMin = 0.0; //Default value
115 fMinMove = 0.05; //From original UA1 JetFinder
116 fMaxMove = 0.15; //From original UA1 JetFinder
117 fBGMaxMove = 0.035; //From original UA1 JetFinder
120 fEBGTotal = 1.0; //Set to 1 so that no div by zero in first FindJets() loop
138 fRad = 2.0; //Set to 2 to start
141 fArrayInitialised = 0; //Set to FALSE to start
142 fBGType = kRatio; //Set Ratio method as default BG subtraction method
143 fBGPar = -1.0; //Set to 1 to start
147 AliEMCALJetFinderAlgoOmni::AliEMCALJetFinderAlgoOmni(const AliEMCALJetFinderAlgoOmni& jfao)
148 : AliEMCALJetFinderAlgo(jfao),
149 fUnit(jfao.fUnit),fUnitNoCuts(jfao.fUnitNoCuts),fHadCorr(jfao.fHadCorr),
150 fBGType(jfao.fBGType),fNumIter(jfao.fNumIter),fNumUnits(jfao.fNumUnits),
151 fESeed(jfao.fESeed),fConeRad(jfao.fConeRad),fJetEMin(jfao.fJetEMin),
152 fEtMin(jfao.fEtMin), fMinMove(jfao.fMinMove),fMaxMove(jfao.fMaxMove),
153 fBGMaxMove(jfao.fBGMaxMove),fPtCut(jfao.fPtCut),fBGPar(jfao.fBGPar),
154 fEBGTotal(jfao.fEBGTotal),fEBGTotalOld(jfao.fEBGTotalOld),fEBGAve(jfao.fEBGAve),
155 fEnergy(jfao.fEnergy),fJetEta(jfao.fJetEta), fJetPhi(jfao.fJetPhi),fEtaInit(jfao.fEtaInit),
156 fPhiInit(jfao.fPhiInit),fEtaB(jfao.fEtaB),fPhiB(jfao.fPhiB),fJetESum(jfao.fJetESum),
157 fJetEtaSum(jfao.fJetEtaSum),fJetPhiSum(jfao.fJetPhiSum),fDEta(jfao.fDEta),fDPhi(jfao.fDPhi),
158 fDistP(jfao.fDistP),fDistI(jfao.fDistI),fTempE(jfao.fTempE),fRad(jfao.fRad),
159 fNumInCone(jfao.fNumInCone),fNumJets(jfao.fNumJets),fArrayInitialised(jfao.fArrayInitialised)
164 AliEMCALJetFinderAlgoOmni::~AliEMCALJetFinderAlgoOmni()
167 if (fDebug>0) Info("AliEMCALJetFinderAlgoOmni","Beginning Destructor");
169 delete[] fUnitNoCuts;
172 void AliEMCALJetFinderAlgoOmni::SetJetFindingParameters
173 (Int_t numUnits, Float_t eSeed, Float_t coneRad, Float_t jetEMin, Float_t etMin,
174 Float_t minMove, Float_t maxMove, Float_t bgMaxMove)
176 //Sets parameters for the JetFinding algorithm
177 if (fDebug>1) Info("SetJetFindingParameters","Setting parameters for JetFinding");
179 SetNumUnits(numUnits);
186 SetBGMaxMove(bgMaxMove);
189 void AliEMCALJetFinderAlgoOmni::SetJetFindingParameters
190 (Int_t numUnits, Float_t eSeed, Float_t coneRad, Float_t jetEMin, Float_t etMin)
192 //Sets fewer parameters for the JetFinding algorithm
193 if (fDebug>1) Info("SetJetFindingParameters","Setting parameters for JetFinding");
195 SetNumUnits(numUnits);
200 SetMinMove(fMinMove);
201 SetMaxMove(fMaxMove);
202 SetBGMaxMove(fBGMaxMove);
205 void AliEMCALJetFinderAlgoOmni::InitUnitArray()
207 //Initialises unit arrays
208 if(fArrayInitialised) delete [] fUnit;
209 if(fArrayInitialised) delete [] fUnitNoCuts;
210 fUnit = new AliEMCALJetFinderAlgoUA1Unit[fNumUnits];
211 fUnitNoCuts = new AliEMCALJetFinderAlgoUA1Unit[fNumUnits];
212 fArrayInitialised = 1;
215 void AliEMCALJetFinderAlgoOmni::FillUnitArray(AliEMCALJetFinderAlgoUA1FillUnitFlagType_t flag)
217 // Fill the unit array
218 if (fDebug>1) Info("FillUnitArray","Beginning FillUnitArray");
219 // AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
221 // AliEMCALGeometry* geom = AliEMCALGeometry::GetInstance(pEMCAL->GetTitle(), "");
225 AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
227 geom = AliEMCALGeometry::GetInstance("EMCAL_55_25","EMCAL");
231 AliEMCALJetFinderAlgoUA1FillUnitFlagType_t option = flag;
232 Int_t numTracks, numDigits;
234 //Loops over all elements in the AliEMCALJetFinderAlgoUA1Unit array and
235 //fills the objects with relevant values from the Data Input object
236 if (fDebug>10) Info("FillUnitArray","Filling array with Unit objects");
237 if (fDebug>15) Info("FillUnitArray","NTracks %i NDigits %i",fInputPointer->GetNTracks(),fInputPointer->GetNDigits());
238 numTracks = fInputPointer->GetNTracks();
239 numDigits = fInputPointer->GetNDigits();
241 AliEMCALDigit *myDigit;
242 if (!fPythiaComparison)
244 //Fill units with Track info if appropriate
245 if(option==kFillTracksOnly || option ==kFillAll)
247 for(Int_t j=0; j<numTracks; j++)
249 myPart = fInputPointer->GetTrack(j);
250 Float_t eta = myPart->Eta();
251 // have to be tune for TRD1; May 31,06
252 // Float_t phi = myPart->Phi();
253 // Int_t towerID = geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi);
256 Float_t pT = myPart->Pt();
257 Float_t unitEnergy = fUnit[towerID-1].GetUnitEnergy();
258 Float_t unitEnergyNoCuts = fUnitNoCuts[towerID-1].GetUnitEnergy();
261 //OLD WAY: //Do Hadron Correction
264 Double_t fullP = myPart->P();
265 Double_t hCEnergy = fHadCorr->GetEnergy(fullP, (Double_t)eta);
266 unitEnergy -= hCEnergy*TMath::Sin(myPart->Theta());
267 unitEnergyNoCuts -= hCEnergy*TMath::Sin(myPart->Theta());
268 fUnit[towerID-1].SetUnitEnergy(unitEnergy);
269 fUnitNoCuts[towerID-1].SetUnitEnergy(unitEnergyNoCuts);
270 } //end Hadron Correction loop
274 //Do Hadron Correction with propagate phi for the track
279 TParticlePDG *pdg = myPart->GetPDG();
280 if(pdg->Charge() < 0)
282 deltaPhi = PropagatePhi(myPart->Pt(), -1.0, curl);
285 deltaPhi = PropagatePhi(myPart->Pt(), 1.0, curl);
288 //Get new tower id for cell that track would curve into
290 if(phi>(TMath::Pi()/180.0)*geom->GetArm1PhiMax() || phi<(TMath::Pi()/180.0)*geom->GetArm1PhiMin())
295 towerID2 = geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi);
300 //Find unit energy of new tower
301 Float_t unitEnergy2 = fUnit[towerID2-1].GetUnitEnergy();
302 Float_t unitEnergy2NoCuts = fUnitNoCuts[towerID2-1].GetUnitEnergy();
303 Double_t fullP = myPart->P();
304 Double_t hCEnergy = fHadCorr->GetEnergy(fullP, (Double_t)eta);
305 unitEnergy2 -= hCEnergy*TMath::Sin(myPart->Theta());
306 unitEnergy2NoCuts -= hCEnergy*TMath::Sin(myPart->Theta());
307 fUnit[towerID2-1].SetUnitEnergy(unitEnergy2);
308 fUnitNoCuts[towerID2-1].SetUnitEnergy(unitEnergy2NoCuts);
309 }//end if for towerID2
310 }//end Hadron Correction loop
313 fUnitNoCuts[towerID-1].SetUnitEnergy(unitEnergyNoCuts + pT);
314 //Do Pt cut on tracks
315 if(fPtCut != 0 && pT < fPtCut) continue;
317 fUnit[towerID-1].SetUnitEnergy(unitEnergy+pT);
320 }//end Tracks condition
323 //Fill units with Digit info if appropriate
324 if(option ==kFillDigitsOnly || option ==kFillAll)
326 for(Int_t k=0; k<numDigits; k++)
328 myDigit = fInputPointer->GetDigit(k);
329 if (fDebug>10) Info("FillUnitArray","getting digits %i %i numdigits",k,numDigits );
330 Int_t towerID = myDigit->GetId();
331 Int_t amplitude = myDigit->GetAmp(); //Gets the integer valued amplitude of the digit
332 Float_t amp = (Float_t)amplitude; //Need to typecast to Float_t before doing real energy conversion
333 Float_t digitEnergy = amp/10000000.0; //Factor of 10 million needed to convert!
334 Float_t unitEnergy = fUnit[towerID-1].GetUnitEnergy() + digitEnergy;
335 Float_t unitEnergyNoCuts = fUnitNoCuts[towerID-1].GetUnitEnergy() + digitEnergy;
336 fUnit[towerID-1].SetUnitEnergy(unitEnergy);
337 fUnitNoCuts[towerID-1].SetUnitEnergy(unitEnergyNoCuts);
339 }//end digits condition
341 //Set all unit flags, Eta, Phi
342 for(Int_t i=0; i<fNumUnits; i++)
344 if (fDebug>10) Info("FillUnitArray","Setting all units outside jets");
345 //Set all units to be outside a jet initially
346 fUnit[i].SetUnitFlag(kOutJet);
347 fUnit[i].SetUnitID(i+1);
350 geom->EtaPhiFromIndex(fUnit[i].GetUnitID(), eta, phi);
351 fUnit[i].SetUnitEta(eta);
352 fUnit[i].SetUnitPhi(phi*TMath::Pi()/180.0);
353 //Set all units to be outside a jet initially
354 fUnitNoCuts[i].SetUnitFlag(kOutJet);
355 fUnitNoCuts[i].SetUnitID(i+1);
358 geom->EtaPhiFromIndex(fUnitNoCuts[i].GetUnitID(), eta, phi);
359 fUnitNoCuts[i].SetUnitEta(eta);
360 fUnitNoCuts[i].SetUnitPhi(phi*TMath::Pi()/180.0);
361 // if(i>13000) cout<<"!!!!!!!!!!!!!!!!!For unit0, eta="<<eta<<" and phi="<<phi*TMath::Pi()/180.0<<" and ID="<<fUnit[i].GetUnitID()<<endl;
362 // 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;
363 }//end loop over all units in array (same as all towers in EMCAL)
366 if (fPythiaComparison)
368 for(Int_t j=0; j<numTracks; j++)
370 myPart = fInputPointer->GetTrack(j);
371 fUnit[j].SetUnitID(j);
372 fUnit[j].SetUnitFlag(kOutJet);
373 fUnit[j].SetUnitEta(myPart->Eta());
374 fUnit[j].SetUnitPhi(myPart->Phi());
375 if (myPart->Energy()*TMath::Sin(myPart->Theta()) > fPtCut || myPart->GetPDG()->Charge() == 0.0 )
377 fUnit[j].SetUnitEnergy(myPart->Energy()*TMath::Sin(myPart->Theta()));
380 fUnit[j].SetUnitEnergy(0.00);
382 fUnitNoCuts[j].SetUnitID(j);
383 fUnitNoCuts[j].SetUnitFlag(kOutJet);
384 fUnitNoCuts[j].SetUnitEta(myPart->Eta());
385 fUnitNoCuts[j].SetUnitPhi(myPart->Phi());
386 fUnitNoCuts[j].SetUnitEnergy(myPart->Energy()*TMath::Sin(myPart->Theta()));
388 for(Int_t k=numTracks; k < fNumUnits; k++)
390 fUnit[k].SetUnitID(k);
391 fUnit[k].SetUnitFlag(kBelowMinEt);
392 fUnit[k].SetUnitEta(0.0);
393 fUnit[k].SetUnitPhi(0.0);
394 fUnit[k].SetUnitEnergy(0.0);
395 fUnitNoCuts[k].SetUnitID(k);
396 fUnitNoCuts[k].SetUnitFlag(kBelowMinEt);
397 fUnitNoCuts[k].SetUnitEta(0.0);
398 fUnitNoCuts[k].SetUnitPhi(0.0);
399 fUnitNoCuts[k].SetUnitEnergy(0.0);
408 void AliEMCALJetFinderAlgoOmni::Sort(AliEMCALJetFinderAlgoUA1Unit *unit, Int_t length)
410 //Calls the recursive quicksort method to sort unit objects in decending order of Energy
411 if (fDebug>1) Info("Sort","Sorting Unit objects");
412 QS(unit, 0, length-1);
416 void AliEMCALJetFinderAlgoOmni::QS(AliEMCALJetFinderAlgoUA1Unit *unit, Int_t left, Int_t right)
418 //Sorts the AliEMCALJetFinderAlgoUA1Unit objects in decending order of Energy
419 if (fDebug>111) Info("QS","QuickSorting Unit objects");
423 AliEMCALJetFinderAlgoUA1Unit unitFirst;
424 AliEMCALJetFinderAlgoUA1Unit unitSecond;
428 unitFirst = unit[(left+right)/2];
432 while( (unit[i].GetUnitEnergy() > unitFirst.GetUnitEnergy()) && (i < right)) i++;
433 while( (unitFirst.GetUnitEnergy() > unit[j].GetUnitEnergy()) && (j > left)) j--;
437 unitSecond = unit[i];
439 unit[j] = unitSecond;
445 if(left < j) QS(unit, left, j);
446 if(i < right) QS(unit, i, right);
450 void AliEMCALJetFinderAlgoOmni::FindBG()
452 if(fBGType == kRatio) RatioBG();
453 else if(fBGType == kCone) ConeBG();
454 else if(fBGType == kConstant) ConstantBG();
457 void AliEMCALJetFinderAlgoOmni::RatioBG()
459 //Finds the background energy for the iteration
460 //using the Ratio method
461 if (fDebug>1) Info("FindBG","Finding Average Background");
462 //Store BGEperCell from previous iteration!
463 fEBGTotalOld = fEBGTotal;
467 //If user has not set fBGPar, set it to the default
468 //for TPC = 90% efficiency, PtCut = 2GeV/c, timecut = 30ns
469 if(fBGPar == -1) fBGPar = 0.4685;
471 //Loop over all unit objects in the Unit array and link to same
472 //unit ID in NoCuts Unit array
473 for(Int_t i=0; i<fNumUnits; i++)
475 if(fUnit[i].GetUnitFlag() != kInJet)
477 Int_t id = fUnit[i].GetUnitID();
478 fEBGTotal += fUnitNoCuts[id-1].GetUnitEnergy();
484 fEBGAve = fEBGTotal / (fNumUnits - numCone);
485 if (fDebug>5) Info("FindBG","Average BG is %f: ",fEBGAve);
487 for(Int_t count=0; count<fNumUnits;count++)
489 fUnit[count].SetUnitFlag(kOutJet);
493 void AliEMCALJetFinderAlgoOmni::ConeBG()
495 //Finds the background energy for the iteration
496 //using all energy not contained inside a jet
497 if (fDebug>1) Info("FindBG","Finding Average Background");
498 //Store old value of BGEperCell!
499 fEBGTotalOld = fEBGTotal;
503 //Loop over all unit objects in the array and sum the energy of those not in a jet
504 for(Int_t i=0; i<fNumUnits; i++)
506 if(fUnit[i].GetUnitFlag() != kInJet)
507 fEBGTotal += fUnit[i].GetUnitEnergy();
511 fEBGAve = fEBGTotal / (fNumUnits - numCone);
512 if (fDebug>5) Info("FindBG","Average BG is %f: ",fEBGAve);
514 for(Int_t count=0; count<fNumUnits;count++)
516 fUnit[count].SetUnitFlag(kOutJet);
520 void AliEMCALJetFinderAlgoOmni::ConstantBG()
522 //Finds the background energy for the iteration
523 //using all energy not contained inside a jet
524 if (fDebug>1) Info("FindBG","Finding Average Background");
526 //If user has not set fBGPar, set it to the default
527 //for TPC = 90% efficiency, PtCut = 2GeV/c, timecut = 30ns
528 if(fBGPar == -1) fBGPar = 0.03378;
531 if (fDebug>5) Info("FindBG","Average BG is %f: ",fEBGAve);
535 for(Int_t count=0; count<fNumUnits;count++)
537 if(fUnit[count].GetUnitFlag() == kInJet)
541 fUnit[count].SetUnitFlag(kOutJet);
543 fEBGTotal = fEBGAve * (fNumUnits-numCone);
544 fEBGTotalOld = fEBGTotal;
547 void AliEMCALJetFinderAlgoOmni::FindJetEtaPhi(Int_t counter)
549 //Finds the eta and phi of the jet axis
550 if (fDebug>10) Info("FindJetEtaPhi","Finding Jet Eta and Phi");
552 fDEta = fUnit[counter].GetUnitEta() - fEtaInit;
553 fDPhi = fUnit[counter].GetUnitPhi() - fPhiInit;
555 fEnergy = fUnit[counter].GetUnitEnergy() - fEBGAve;
556 fJetEtaSum += fEnergy * fDEta;
557 fJetPhiSum += fEnergy * fDPhi;
559 if (fJetESum >1.0e-7)
561 fJetEta = fEtaInit + (fJetEtaSum / fJetESum);
562 fJetPhi = fPhiInit + (fJetPhiSum / fJetESum);
567 void AliEMCALJetFinderAlgoOmni::FindJetEnergy()
569 //Finds the energy of the jet after the final axis has been found
570 if (fDebug>1) Info("FindJetEnergy","Finding Jet Energy");
572 for(Int_t i=0; i<fNumUnits; i++)
574 //Loop over all unit objects in the array and find if within cone radius
575 Float_t dEta = fUnit[i].GetUnitEta() - fJetEta;
576 Float_t dPhi = fUnit[i].GetUnitPhi() - fJetPhi;
578 if ((dEta*dEta) + (dPhi*dPhi)>1.e-7)
580 rad = TMath::Sqrt( (dEta*dEta) + (dPhi*dPhi) );
586 if(fUnit[i].GetUnitFlag()==kOutJet && rad<= fConeRad)
588 fUnit[i].SetUnitFlag(kInCurrentJet);
589 Float_t energy = fUnit[i].GetUnitEnergy() - fEBGAve;
591 fJetEtaSum += energy * dEta;
592 fJetPhiSum += energy * dPhi;
593 fNumInCone++; //Increment the number of cells in the jet cone
599 void AliEMCALJetFinderAlgoOmni::StoreJetInfo()
601 //Stores the resulting jet information in appropriate storage structure (TO BE DECIDED!!!!)
602 if (fDebug>1) Info("StoreJetInfo","Storing Jet Information");
603 AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
605 geom = AliEMCALGeometry::GetInstance("EMCAL_55_25","EMCAL");
607 //fJetESum is the final jet energy (background has been subtracted)
608 //fJetEta is the final jet Eta
609 //fJetPhi is the final jet Phi
610 //fNumInCone is the final number of cells included in the jet cone
611 //fEtaInit is the eta of the initiator cell
612 //fPhiInit is the phi of the initiator cell
614 AliEMCALJet jet(fJetESum,fJetPhi,fJetEta);
616 cout<<"For iteration "<<fNumIter <<" and Jet number " <<fNumJets <<endl;
617 cout<<"The jet energy is: " <<fJetESum <<endl;
618 cout<<"The jet eta is ---->" <<fJetEta <<endl;
619 cout<<"The jet phi is ---->" <<fJetPhi <<endl;
621 Int_t numberTracks = fInputPointer->GetNTracks();
622 Int_t numberDigits = fInputPointer->GetNDigits();
625 Int_t numTracksInCone = 0;
626 Float_t trackEnergy = 0.0;
627 Float_t trackEnergyPtCut =0.0;
628 Float_t emcalEnergy = 0.0;
629 Float_t emcalEnergyBGSub = 0.0;
631 for(Int_t counter=0; counter<numberTracks; counter++)
633 myP = fInputPointer->GetTrack(counter);
634 Float_t eta = myP->Eta();
635 Float_t phi = myP->Phi();
636 Float_t deta = fJetEta-eta;
637 Float_t dphi = fJetPhi -phi;
638 Float_t rad = TMath::Sqrt( (deta*deta) + (dphi*dphi));
639 if(rad<=fConeRad) numTracksInCone++;
642 Float_t *pTArray = new Float_t[numTracksInCone];
643 Float_t *etaArray = new Float_t[numTracksInCone];
644 Float_t *phiArray = new Float_t[numTracksInCone];
645 Int_t *pdgArray = new Int_t[numTracksInCone];
648 for(Int_t counter2=0; counter2<numberTracks; counter2++)
650 myP = fInputPointer->GetTrack(counter2);
651 Float_t eta = myP->Eta();
652 Float_t phi = myP->Phi();
653 Float_t deta = fJetEta-eta;
654 Float_t dphi = fJetPhi -phi;
656 if ((deta*deta) + (dphi*dphi)>1.e-7)
658 rad = TMath::Sqrt( (deta*deta) + (dphi*dphi) );
666 pTArray[index] = myP->Pt();
667 //Calculate track contribution within jetcone
668 trackEnergy += myP->Pt();
669 if(myP->Pt() >= fPtCut) trackEnergyPtCut += myP->Pt();
670 etaArray[index] = eta;
671 phiArray[index] = phi;
672 pdgArray[index] = myP->GetPdgCode();
676 Double_t fullP = myP->P();
677 Double_t hCEnergy = fHadCorr->GetEnergy(fullP, (Double_t)eta);
678 emcalEnergy -= hCEnergy*TMath::Sin(myP->Theta());
679 emcalEnergyBGSub -= hCEnergy*TMath::Sin(myP->Theta());
680 } //end Hadron Correction loop
685 //Loop over digits to find EMCal contribution within jetcone
686 for(Int_t counter3=0; counter3<numberDigits; counter3++)
688 myD = fInputPointer->GetDigit(counter3);
689 //GET DIGIT ETA, PHI so that can check if inside R!
692 Int_t iID = myD->GetId();
693 geom->EtaPhiFromIndex(iID, eta, phi);
694 Float_t deta = fJetEta-eta;
695 Float_t dphi = fJetPhi -(TMath::Pi()/180.0)*phi;
696 //Float_t rad = TMath::Sqrt( (deta*deta) + (dphi*dphi));
698 if ((deta*deta) + (dphi*dphi)>1.e-7)
700 rad = TMath::Sqrt( (deta*deta) + (dphi*dphi) );
708 Int_t amplitude = myD->GetAmp(); //Gets the integer valued amplitude of the digit
709 Float_t amp = (Float_t)amplitude; //Need to typecast to Float_t before doing real energy conversion
710 Float_t digitEnergy = amp/10000000.0; //Factor of 10 million needed to convert!
711 emcalEnergy += digitEnergy;
712 emcalEnergyBGSub += (digitEnergy - fEBGAve);
717 jet.SetTrackList(numTracksInCone,pTArray, etaArray, phiArray, pdgArray);
718 jet.SetEMCALEnergy(emcalEnergy);
719 jet.SetEMCALEnergyBGSub(emcalEnergyBGSub);
720 jet.SetTrackEnergy(trackEnergy);
721 jet.SetTrackEnergyPtCut(trackEnergyPtCut);
722 fOutputPointer->AddJet(&jet);
730 void AliEMCALJetFinderAlgoOmni::FindJets()
732 //Runs the complete UA1 JetFinding algorithm to find jets!
733 if (fDebug>1) Info("FindJets","Starting Jet Finding!!!");
735 //If the array of JetFinderUnit objects has not been initialised then initialise with default settings
736 if(!fArrayInitialised)
739 FillUnitArray(kFillAll);
741 if (fDebug>1) Info("FindJets","Unit array filled");
743 //Step 1. Sort the array in descending order of Energy
744 Sort(fUnit,fNumUnits);
746 //Step 2. Set the number of iterations and Number of jets found to zero to start
750 //Step 3. Begin the iteration loop to find jets
751 //Need to iterate the algorithm while number of iterations<2 OR number of iterations<10 AND
752 //the value of the average background has changed more than specified amount
753 //Min iterations = 2, Max iterations = 10
754 //while(fNumIter<2 || (fNumIter <10 && ( (fEBGTotal-fEBGTotalOld)/fEBGTotal) > fBGMaxMove) )
756 while(fNumIter<2 || (fNumIter <10 && ( fEBGTotal-fEBGTotalOld) > fEBGTotal*fBGMaxMove) )
758 if (fDebug>1) Info("FindJets","Starting BIG iteration ---> %i",fNumIter);
760 //Step 4. Find the value of the average background energy
762 fOutputPointer->Reset(kResetJets); //Reset output object to store info for new iteration
765 //Loop over the array of unit objects and flag those with energy below MinCellEt
767 for(Int_t j=0; j<fNumUnits; j++)
769 if( (fUnit[j].GetUnitEnergy()-fEBGAve) < fEtMin)
771 // fUnit[j].SetUnitFlag(kBelowMinEt); TAKING OUT kBelow flag
775 //cout<<"THERE WERE "<<numbelow<<" units with E <EtMin!!!!!!!!!!!!!!!"<<endl;
777 //Do quick check if there are no jets upfront
778 // if(fUnit[0].GetUnitFlag() == kBelowMinEt)
779 if( (fUnit[0].GetUnitEnergy()-fEBGAve) < fEtMin)
781 cout <<"There are no jets for this event!" <<endl;
785 //Step 5. Begin with the first jet candidate cell (JET SEED LOOP)
786 if (fDebug>5) Info("FindJets","Beginning JET SEED LOOP");
787 for(Int_t count=0; count<fNumUnits; count++)
790 //CHECK CONDITION HERE _ NOT SURE IF SHOULD MAYBE BE: GetUnitEnergy()-fEBGAve >fESeed?????????????????????????????
791 if(fUnit[count].GetUnitEnergy()>=fESeed && fUnit[count].GetUnitFlag()==kOutJet)
793 fEnergy = fUnit[count].GetUnitEnergy() - fEBGAve;
794 fJetEta = fUnit[count].GetUnitEta();
795 fJetPhi = fUnit[count].GetUnitPhi();
796 Int_t seedID = fUnit[count].GetUnitID();
797 if (fDebug>5) Info("FindJets","Inside first candidate jet seed loop for time : %i", count);
798 if (fDebug>5) Info("FindJets","Found candidate energy %f ",fEnergy);
799 if (fDebug>5) Info("FindJets","Found candidate eta %f ", fJetEta);
800 if (fDebug>5) Info("FindJets","Found candidate phi %f ", fJetPhi);
801 if (fDebug>5) Info("FindJets","Found candidate ID %i", seedID);
814 //Step 6. Find Jet Eta and Phi
815 //Loop over all units in the array to find the ones in the jet cone and determine contrib to Jet eta, phi
816 for(Int_t count1=0; count1<fNumUnits; count1++)
818 if(fUnit[count1].GetUnitID() == seedID && testflag)
821 continue; //skip unit if the jetseed to avoid doublecounting
823 if(fUnit[count1].GetUnitFlag() == kOutJet)
825 fDEta = fUnit[count1].GetUnitEta() - fJetEta;
826 fDPhi = fUnit[count1].GetUnitPhi() - fJetPhi;
827 if ( (fDEta*fDEta) + (fDPhi*fDPhi) >1.e-7)
829 fRad = TMath::Sqrt( (fDEta*fDEta) + (fDPhi*fDPhi) );
836 FindJetEtaPhi(count1);
839 }//end for (Jet Eta, Phi LOOP)
841 //Find the distance cone centre moved from previous cone centre
842 if (fDebug>10) Info("FindJets","Checking if cone move small enough");
843 if (((fJetEta-fEtaB)*(fJetEta-fEtaB)) + ((fJetPhi-fPhiB)*(fJetPhi-fPhiB)) >1.e-7)
845 fDistP = TMath::Sqrt( ((fJetEta-fEtaB)*(fJetEta-fEtaB)) + ((fJetPhi-fPhiB)*(fJetPhi-fPhiB)) );
850 // if(fDistP <= fMinMove) break;
853 //Find the distance cone centre is from initiator cell
854 if (fDebug>10) Info("FindJets","Checking if cone move too large");
855 if ( ((fJetEtaSum)*(fJetEtaSum))+((fJetPhiSum)*(fJetPhiSum)) >1.e-7)
857 fDistI = TMath::Sqrt( ((fJetEtaSum/fJetESum)*(fJetEtaSum/fJetESum)) + ((fJetPhiSum/fJetESum)*
858 (fJetPhiSum/fJetESum)));
864 if(fDistP>fMinMove && fDistI<fMaxMove)
870 }while(fDistP>fMinMove && fDistI<fMaxMove);
876 //Step 7. Find the Jet Energy
877 if (fDebug>1) Info("FindJets","Looking for Jet energy");
884 //cout<<"Number of cells in jet cone is: "<<fNumInCone<<endl;
886 //Step 8. Check if the jet is a valid jet
887 //Check if cluster energy is above Min allowed to be a jet
888 //DID NOT DO THE COSH COMPARISON HERE -> NEED TO CHECK WHICH COMPARISON IS BEST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
889 if (fDebug>5) Info("FindJets","Checking cluster is valid jet");
890 if(fJetESum < fJetEMin)
892 for(Int_t count2=0; count2<fNumUnits; count2++)
894 if(fUnit[count2].GetUnitFlag()==kInCurrentJet || fUnit[count2].GetUnitFlag()==kOutJet)
895 fUnit[count2].SetUnitFlag(kOutJet);
897 if (fDebug>10) Info("FindJets","NOT a valid jet cell");
900 for(Int_t count2=0; count2<fNumUnits; count2++)
902 if(fUnit[count2].GetUnitFlag()==kInCurrentJet)
904 // cout<<"Setting unit #"<<count2 <<" to be officially in a jet!"<<endl;
905 fUnit[count2].SetUnitFlag(kInJet);
909 //NEED TO CHECK FINAL WEIRD ITERATION OF ETA AND PHI CHANGES!!!!!!!!!
910 // fJetPhi += fJetPhiSum/fJetESum; //CHECK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
911 // fJetEta += fJetEtaSum/fJetESum; //CHECK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
913 fNumJets++; //Incrementing number of jets found
914 StoreJetInfo(); //Storing jet info
916 }//end if (check cluster above Min Jet Energy)
917 }//end if (Jet Seed condition)
918 }//end (JET SEED LOOP)
920 if (fDebug>5) Info("FindJets","End of BIG iteration number %i",fNumIter);
923 }//end 10 iteration WHILE LOOP