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.1 2006/02/28 21:56:34 jklay
24 moving jetfinder code to subdirectory
26 Revision 1.16 2006/02/15 15:11:05 pavlinov
27 update of Jenn and Marco
29 Revision 1.15 2004/11/22 19:52:05 mhorner
30 Make sure pi0 get through
32 Revision 1.14 2004/04/02 17:11:33 mhorner
33 Marco's bug - fixes implemented
35 Revision 1.13 2004/03/26 01:00:38 mhorner
36 Implementing Marco's optimisations
38 Revision 1.12 2004/03/15 19:59:37 mhorner
39 Pyhtia comparison extended
41 Revision 1.11 2004/03/09 17:06:38 mhorner
44 Revision 1.10 2004/03/06 01:56:09 mhorner
47 Revision 1.9 2004/02/23 20:37:32 mhorner
50 Revision 1.8 2004/01/29 23:28:44 mhorner
51 Jet Finder - hard coded geom parameters removed
53 Revision 1.7 2004/01/21 22:27:47 mhorner
54 Cleaning up coding conventions
56 Revision 1.6 2003/10/28 13:54:30 schutz
57 Compilation warnings fixed
59 Revision 1.5 2003/09/23 13:31:41 mhorner
60 Changed coordinate system
62 Revision 1.4 2003/09/19 13:16:20 mhorner
63 Added additional jet energy info
66 Revision 1.3 2003/09/04 12:49:56 mhorner
67 Changed hadron correction and added saving EMCAL and track contributions
72 //*--Author: Sarah Blyth (LBL)
73 //*--Based on UA1 jet algorithm from LUND JETSET called from EMC-erj
77 #include "TParticle.h"
79 #include "AliRunLoader.h"
80 #include "AliEMCALJetFinderInput.h"
81 #include "AliEMCALJetFinderOutput.h"
82 #include "AliEMCALJetFinderAlgo.h"
83 #include "AliEMCALJetFinderAlgoOmni.h"
84 #include "AliEMCALJetFinderAlgoUA1Unit.h"
85 #include "AliEMCALGeometry.h"
86 #include "AliEMCALLoader.h"
88 #include "AliEMCALDigit.h"
89 #include "AliEMCALJet.h"
92 ClassImp(AliEMCALJetFinderAlgoOmni)
94 AliEMCALJetFinderAlgoOmni::AliEMCALJetFinderAlgoOmni()
97 if (fDebug>0) Info("AliEMCALJetFinderAlgoOmni","Beginning Default Constructor");
98 AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance("EMCAL_55_25","EMCAL");
100 fNumUnits = geom->GetNTowers(); //Number of towers in EMCAL
101 fESeed = 5.0; //Default value
102 fConeRad = 0.3; //Default value
103 fJetEMin = 10.0; //Default value
104 fEtMin = 0.0; //Default value
105 fMinMove = 0.05; //From original UA1 JetFinder
106 fMaxMove = 0.15; //From original UA1 JetFinder
107 fBGMaxMove = 0.035; //From original UA1 JetFinder
110 fEBGTotal = 1.0; //Set to 1 so that no div by zero in first FindJets() loop
128 fRad = 2.0; //Set to 2 to start
131 fArrayInitialised = 0; //Set to FALSE to start
132 fBGType = kRatio; //Set Ratio method as default BG subtraction method
133 fBGPar = -1.0; //Set to 1 to start
136 AliEMCALJetFinderAlgoOmni::~AliEMCALJetFinderAlgoOmni()
139 if (fDebug>0) Info("AliEMCALJetFinderAlgoOmni","Beginning Destructor");
141 delete[] fUnitNoCuts;
144 void AliEMCALJetFinderAlgoOmni::SetJetFindingParameters
145 (Int_t numUnits, Float_t eSeed, Float_t coneRad, Float_t jetEMin, Float_t etMin,
146 Float_t minMove, Float_t maxMove, Float_t bgMaxMove)
148 //Sets parameters for the JetFinding algorithm
149 if (fDebug>1) Info("SetJetFindingParameters","Setting parameters for JetFinding");
151 SetNumUnits(numUnits);
158 SetBGMaxMove(bgMaxMove);
161 void AliEMCALJetFinderAlgoOmni::SetJetFindingParameters
162 (Int_t numUnits, Float_t eSeed, Float_t coneRad, Float_t jetEMin, Float_t etMin)
164 //Sets fewer parameters for the JetFinding algorithm
165 if (fDebug>1) Info("SetJetFindingParameters","Setting parameters for JetFinding");
167 SetNumUnits(numUnits);
172 SetMinMove(fMinMove);
173 SetMaxMove(fMaxMove);
174 SetBGMaxMove(fBGMaxMove);
177 void AliEMCALJetFinderAlgoOmni::InitUnitArray()
179 //Initialises unit arrays
180 if(fArrayInitialised) delete [] fUnit;
181 if(fArrayInitialised) delete [] fUnitNoCuts;
182 fUnit = new AliEMCALJetFinderAlgoUA1Unit[fNumUnits];
183 fUnitNoCuts = new AliEMCALJetFinderAlgoUA1Unit[fNumUnits];
184 fArrayInitialised = 1;
187 void AliEMCALJetFinderAlgoOmni::FillUnitArray(AliEMCALJetFinderAlgoUA1FillUnitFlagType_t flag)
189 // Fill the unit array
190 if (fDebug>1) Info("FillUnitArray","Beginning FillUnitArray");
191 // AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
193 // AliEMCALGeometry* geom = AliEMCALGeometry::GetInstance(pEMCAL->GetTitle(), "");
197 AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
199 geom = AliEMCALGeometry::GetInstance("EMCAL_55_25","EMCAL");
203 AliEMCALJetFinderAlgoUA1FillUnitFlagType_t option = flag;
204 Int_t numTracks, numDigits;
206 //Loops over all elements in the AliEMCALJetFinderAlgoUA1Unit array and
207 //fills the objects with relevant values from the Data Input object
208 if (fDebug>10) Info("FillUnitArray","Filling array with Unit objects");
209 if (fDebug>15) Info("FillUnitArray","NTracks %i NDigits %i",fInputPointer->GetNTracks(),fInputPointer->GetNDigits());
210 numTracks = fInputPointer->GetNTracks();
211 numDigits = fInputPointer->GetNDigits();
213 AliEMCALDigit *myDigit;
214 if (!fPythiaComparison)
216 //Fill units with Track info if appropriate
217 if(option==kFillTracksOnly || option ==kFillAll)
219 for(Int_t j=0; j<numTracks; j++)
221 myPart = fInputPointer->GetTrack(j);
222 Float_t eta = myPart->Eta();
223 // have to be tune for TRD1; May 31,06
224 // Float_t phi = myPart->Phi();
225 // Int_t towerID = geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi);
228 Float_t pT = myPart->Pt();
229 Float_t unitEnergy = fUnit[towerID-1].GetUnitEnergy();
230 Float_t unitEnergyNoCuts = fUnitNoCuts[towerID-1].GetUnitEnergy();
233 //OLD WAY: //Do Hadron Correction
236 Double_t fullP = myPart->P();
237 Double_t hCEnergy = fHadCorr->GetEnergy(fullP, (Double_t)eta);
238 unitEnergy -= hCEnergy*TMath::Sin(myPart->Theta());
239 unitEnergyNoCuts -= hCEnergy*TMath::Sin(myPart->Theta());
240 fUnit[towerID-1].SetUnitEnergy(unitEnergy);
241 fUnitNoCuts[towerID-1].SetUnitEnergy(unitEnergyNoCuts);
242 } //end Hadron Correction loop
246 //Do Hadron Correction with propagate phi for the track
251 TParticlePDG *pdg = myPart->GetPDG();
252 if(pdg->Charge() < 0)
254 deltaPhi = PropagatePhi(myPart->Pt(), -1.0, curl);
257 deltaPhi = PropagatePhi(myPart->Pt(), 1.0, curl);
260 //Get new tower id for cell that track would curve into
262 if(phi>(TMath::Pi()/180.0)*geom->GetArm1PhiMax() || phi<(TMath::Pi()/180.0)*geom->GetArm1PhiMin())
267 towerID2 = geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi);
272 //Find unit energy of new tower
273 Float_t unitEnergy2 = fUnit[towerID2-1].GetUnitEnergy();
274 Float_t unitEnergy2NoCuts = fUnitNoCuts[towerID2-1].GetUnitEnergy();
275 Double_t fullP = myPart->P();
276 Double_t hCEnergy = fHadCorr->GetEnergy(fullP, (Double_t)eta);
277 unitEnergy2 -= hCEnergy*TMath::Sin(myPart->Theta());
278 unitEnergy2NoCuts -= hCEnergy*TMath::Sin(myPart->Theta());
279 fUnit[towerID2-1].SetUnitEnergy(unitEnergy2);
280 fUnitNoCuts[towerID2-1].SetUnitEnergy(unitEnergy2NoCuts);
281 }//end if for towerID2
282 }//end Hadron Correction loop
285 fUnitNoCuts[towerID-1].SetUnitEnergy(unitEnergyNoCuts + pT);
286 //Do Pt cut on tracks
287 if(fPtCut != 0 && pT < fPtCut) continue;
289 fUnit[towerID-1].SetUnitEnergy(unitEnergy+pT);
292 }//end Tracks condition
295 //Fill units with Digit info if appropriate
296 if(option ==kFillDigitsOnly || option ==kFillAll)
298 for(Int_t k=0; k<numDigits; k++)
300 myDigit = fInputPointer->GetDigit(k);
301 if (fDebug>10) Info("FillUnitArray","getting digits %i %i numdigits",k,numDigits );
302 Int_t towerID = myDigit->GetId();
303 Int_t amplitude = myDigit->GetAmp(); //Gets the integer valued amplitude of the digit
304 Float_t amp = (Float_t)amplitude; //Need to typecast to Float_t before doing real energy conversion
305 Float_t digitEnergy = amp/10000000.0; //Factor of 10 million needed to convert!
306 Float_t unitEnergy = fUnit[towerID-1].GetUnitEnergy() + digitEnergy;
307 Float_t unitEnergyNoCuts = fUnitNoCuts[towerID-1].GetUnitEnergy() + digitEnergy;
308 fUnit[towerID-1].SetUnitEnergy(unitEnergy);
309 fUnitNoCuts[towerID-1].SetUnitEnergy(unitEnergyNoCuts);
311 }//end digits condition
313 //Set all unit flags, Eta, Phi
314 for(Int_t i=0; i<fNumUnits; i++)
316 if (fDebug>10) Info("FillUnitArray","Setting all units outside jets");
317 //Set all units to be outside a jet initially
318 fUnit[i].SetUnitFlag(kOutJet);
319 fUnit[i].SetUnitID(i+1);
322 geom->EtaPhiFromIndex(fUnit[i].GetUnitID(), eta, phi);
323 fUnit[i].SetUnitEta(eta);
324 fUnit[i].SetUnitPhi(phi*TMath::Pi()/180.0);
325 //Set all units to be outside a jet initially
326 fUnitNoCuts[i].SetUnitFlag(kOutJet);
327 fUnitNoCuts[i].SetUnitID(i+1);
330 geom->EtaPhiFromIndex(fUnitNoCuts[i].GetUnitID(), eta, phi);
331 fUnitNoCuts[i].SetUnitEta(eta);
332 fUnitNoCuts[i].SetUnitPhi(phi*TMath::Pi()/180.0);
333 // if(i>13000) cout<<"!!!!!!!!!!!!!!!!!For unit0, eta="<<eta<<" and phi="<<phi*TMath::Pi()/180.0<<" and ID="<<fUnit[i].GetUnitID()<<endl;
334 // 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;
335 }//end loop over all units in array (same as all towers in EMCAL)
338 if (fPythiaComparison)
340 for(Int_t j=0; j<numTracks; j++)
342 myPart = fInputPointer->GetTrack(j);
343 fUnit[j].SetUnitID(j);
344 fUnit[j].SetUnitFlag(kOutJet);
345 fUnit[j].SetUnitEta(myPart->Eta());
346 fUnit[j].SetUnitPhi(myPart->Phi());
347 if (myPart->Energy()*TMath::Sin(myPart->Theta()) > fPtCut || myPart->GetPDG()->Charge() == 0.0 )
349 fUnit[j].SetUnitEnergy(myPart->Energy()*TMath::Sin(myPart->Theta()));
352 fUnit[j].SetUnitEnergy(0.00);
354 fUnitNoCuts[j].SetUnitID(j);
355 fUnitNoCuts[j].SetUnitFlag(kOutJet);
356 fUnitNoCuts[j].SetUnitEta(myPart->Eta());
357 fUnitNoCuts[j].SetUnitPhi(myPart->Phi());
358 fUnitNoCuts[j].SetUnitEnergy(myPart->Energy()*TMath::Sin(myPart->Theta()));
360 for(Int_t k=numTracks; k < fNumUnits; k++)
362 fUnit[k].SetUnitID(k);
363 fUnit[k].SetUnitFlag(kBelowMinEt);
364 fUnit[k].SetUnitEta(0.0);
365 fUnit[k].SetUnitPhi(0.0);
366 fUnit[k].SetUnitEnergy(0.0);
367 fUnitNoCuts[k].SetUnitID(k);
368 fUnitNoCuts[k].SetUnitFlag(kBelowMinEt);
369 fUnitNoCuts[k].SetUnitEta(0.0);
370 fUnitNoCuts[k].SetUnitPhi(0.0);
371 fUnitNoCuts[k].SetUnitEnergy(0.0);
380 void AliEMCALJetFinderAlgoOmni::Sort(AliEMCALJetFinderAlgoUA1Unit *unit, Int_t length)
382 //Calls the recursive quicksort method to sort unit objects in decending order of Energy
383 if (fDebug>1) Info("Sort","Sorting Unit objects");
384 QS(unit, 0, length-1);
388 void AliEMCALJetFinderAlgoOmni::QS(AliEMCALJetFinderAlgoUA1Unit *unit, Int_t left, Int_t right)
390 //Sorts the AliEMCALJetFinderAlgoUA1Unit objects in decending order of Energy
391 if (fDebug>111) Info("QS","QuickSorting Unit objects");
395 AliEMCALJetFinderAlgoUA1Unit unitFirst;
396 AliEMCALJetFinderAlgoUA1Unit unitSecond;
400 unitFirst = unit[(left+right)/2];
404 while( (unit[i].GetUnitEnergy() > unitFirst.GetUnitEnergy()) && (i < right)) i++;
405 while( (unitFirst.GetUnitEnergy() > unit[j].GetUnitEnergy()) && (j > left)) j--;
409 unitSecond = unit[i];
411 unit[j] = unitSecond;
417 if(left < j) QS(unit, left, j);
418 if(i < right) QS(unit, i, right);
422 void AliEMCALJetFinderAlgoOmni::FindBG()
424 if(fBGType == kRatio) RatioBG();
425 else if(fBGType == kCone) ConeBG();
426 else if(fBGType == kConstant) ConstantBG();
429 void AliEMCALJetFinderAlgoOmni::RatioBG()
431 //Finds the background energy for the iteration
432 //using the Ratio method
433 if (fDebug>1) Info("FindBG","Finding Average Background");
434 //Store BGEperCell from previous iteration!
435 fEBGTotalOld = fEBGTotal;
439 //If user has not set fBGPar, set it to the default
440 //for TPC = 90% efficiency, PtCut = 2GeV/c, timecut = 30ns
441 if(fBGPar == -1) fBGPar = 0.4685;
443 //Loop over all unit objects in the Unit array and link to same
444 //unit ID in NoCuts Unit array
445 for(Int_t i=0; i<fNumUnits; i++)
447 if(fUnit[i].GetUnitFlag() != kInJet)
449 Int_t id = fUnit[i].GetUnitID();
450 fEBGTotal += fUnitNoCuts[id-1].GetUnitEnergy();
456 fEBGAve = fEBGTotal / (fNumUnits - numCone);
457 if (fDebug>5) Info("FindBG","Average BG is %f: ",fEBGAve);
459 for(Int_t count=0; count<fNumUnits;count++)
461 fUnit[count].SetUnitFlag(kOutJet);
465 void AliEMCALJetFinderAlgoOmni::ConeBG()
467 //Finds the background energy for the iteration
468 //using all energy not contained inside a jet
469 if (fDebug>1) Info("FindBG","Finding Average Background");
470 //Store old value of BGEperCell!
471 fEBGTotalOld = fEBGTotal;
475 //Loop over all unit objects in the array and sum the energy of those not in a jet
476 for(Int_t i=0; i<fNumUnits; i++)
478 if(fUnit[i].GetUnitFlag() != kInJet)
479 fEBGTotal += fUnit[i].GetUnitEnergy();
483 fEBGAve = fEBGTotal / (fNumUnits - numCone);
484 if (fDebug>5) Info("FindBG","Average BG is %f: ",fEBGAve);
486 for(Int_t count=0; count<fNumUnits;count++)
488 fUnit[count].SetUnitFlag(kOutJet);
492 void AliEMCALJetFinderAlgoOmni::ConstantBG()
494 //Finds the background energy for the iteration
495 //using all energy not contained inside a jet
496 if (fDebug>1) Info("FindBG","Finding Average Background");
498 //If user has not set fBGPar, set it to the default
499 //for TPC = 90% efficiency, PtCut = 2GeV/c, timecut = 30ns
500 if(fBGPar == -1) fBGPar = 0.03378;
503 if (fDebug>5) Info("FindBG","Average BG is %f: ",fEBGAve);
507 for(Int_t count=0; count<fNumUnits;count++)
509 if(fUnit[count].GetUnitFlag() == kInJet)
513 fUnit[count].SetUnitFlag(kOutJet);
515 fEBGTotal = fEBGAve * (fNumUnits-numCone);
516 fEBGTotalOld = fEBGTotal;
519 void AliEMCALJetFinderAlgoOmni::FindJetEtaPhi(Int_t counter)
521 //Finds the eta and phi of the jet axis
522 if (fDebug>10) Info("FindJetEtaPhi","Finding Jet Eta and Phi");
524 fDEta = fUnit[counter].GetUnitEta() - fEtaInit;
525 fDPhi = fUnit[counter].GetUnitPhi() - fPhiInit;
527 fEnergy = fUnit[counter].GetUnitEnergy() - fEBGAve;
528 fJetEtaSum += fEnergy * fDEta;
529 fJetPhiSum += fEnergy * fDPhi;
531 if (fJetESum >1.0e-7)
533 fJetEta = fEtaInit + (fJetEtaSum / fJetESum);
534 fJetPhi = fPhiInit + (fJetPhiSum / fJetESum);
539 void AliEMCALJetFinderAlgoOmni::FindJetEnergy()
541 //Finds the energy of the jet after the final axis has been found
542 if (fDebug>1) Info("FindJetEnergy","Finding Jet Energy");
544 for(Int_t i=0; i<fNumUnits; i++)
546 //Loop over all unit objects in the array and find if within cone radius
547 Float_t dEta = fUnit[i].GetUnitEta() - fJetEta;
548 Float_t dPhi = fUnit[i].GetUnitPhi() - fJetPhi;
550 if ((dEta*dEta) + (dPhi*dPhi)>1.e-7)
552 rad = TMath::Sqrt( (dEta*dEta) + (dPhi*dPhi) );
558 if(fUnit[i].GetUnitFlag()==kOutJet && rad<= fConeRad)
560 fUnit[i].SetUnitFlag(kInCurrentJet);
561 Float_t energy = fUnit[i].GetUnitEnergy() - fEBGAve;
563 fJetEtaSum += energy * dEta;
564 fJetPhiSum += energy * dPhi;
565 fNumInCone++; //Increment the number of cells in the jet cone
571 void AliEMCALJetFinderAlgoOmni::StoreJetInfo()
573 //Stores the resulting jet information in appropriate storage structure (TO BE DECIDED!!!!)
574 if (fDebug>1) Info("StoreJetInfo","Storing Jet Information");
575 AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
577 geom = AliEMCALGeometry::GetInstance("EMCAL_55_25","EMCAL");
579 //fJetESum is the final jet energy (background has been subtracted)
580 //fJetEta is the final jet Eta
581 //fJetPhi is the final jet Phi
582 //fNumInCone is the final number of cells included in the jet cone
583 //fEtaInit is the eta of the initiator cell
584 //fPhiInit is the phi of the initiator cell
586 AliEMCALJet jet(fJetESum,fJetPhi,fJetEta);
588 cout<<"For iteration "<<fNumIter <<" and Jet number " <<fNumJets <<endl;
589 cout<<"The jet energy is: " <<fJetESum <<endl;
590 cout<<"The jet eta is ---->" <<fJetEta <<endl;
591 cout<<"The jet phi is ---->" <<fJetPhi <<endl;
593 Int_t numberTracks = fInputPointer->GetNTracks();
594 Int_t numberDigits = fInputPointer->GetNDigits();
597 Int_t numTracksInCone = 0;
598 Float_t trackEnergy = 0.0;
599 Float_t trackEnergyPtCut =0.0;
600 Float_t emcalEnergy = 0.0;
601 Float_t emcalEnergyBGSub = 0.0;
603 for(Int_t counter=0; counter<numberTracks; counter++)
605 myP = fInputPointer->GetTrack(counter);
606 Float_t eta = myP->Eta();
607 Float_t phi = myP->Phi();
608 Float_t deta = fJetEta-eta;
609 Float_t dphi = fJetPhi -phi;
610 Float_t rad = TMath::Sqrt( (deta*deta) + (dphi*dphi));
611 if(rad<=fConeRad) numTracksInCone++;
614 Float_t *pTArray = new Float_t[numTracksInCone];
615 Float_t *etaArray = new Float_t[numTracksInCone];
616 Float_t *phiArray = new Float_t[numTracksInCone];
617 Int_t *pdgArray = new Int_t[numTracksInCone];
620 for(Int_t counter2=0; counter2<numberTracks; counter2++)
622 myP = fInputPointer->GetTrack(counter2);
623 Float_t eta = myP->Eta();
624 Float_t phi = myP->Phi();
625 Float_t deta = fJetEta-eta;
626 Float_t dphi = fJetPhi -phi;
628 if ((deta*deta) + (dphi*dphi)>1.e-7)
630 rad = TMath::Sqrt( (deta*deta) + (dphi*dphi) );
638 pTArray[index] = myP->Pt();
639 //Calculate track contribution within jetcone
640 trackEnergy += myP->Pt();
641 if(myP->Pt() >= fPtCut) trackEnergyPtCut += myP->Pt();
642 etaArray[index] = eta;
643 phiArray[index] = phi;
644 pdgArray[index] = myP->GetPdgCode();
648 Double_t fullP = myP->P();
649 Double_t hCEnergy = fHadCorr->GetEnergy(fullP, (Double_t)eta);
650 emcalEnergy -= hCEnergy*TMath::Sin(myP->Theta());
651 emcalEnergyBGSub -= hCEnergy*TMath::Sin(myP->Theta());
652 } //end Hadron Correction loop
657 //Loop over digits to find EMCal contribution within jetcone
658 for(Int_t counter3=0; counter3<numberDigits; counter3++)
660 myD = fInputPointer->GetDigit(counter3);
661 //GET DIGIT ETA, PHI so that can check if inside R!
664 Int_t iID = myD->GetId();
665 geom->EtaPhiFromIndex(iID, eta, phi);
666 Float_t deta = fJetEta-eta;
667 Float_t dphi = fJetPhi -(TMath::Pi()/180.0)*phi;
668 //Float_t rad = TMath::Sqrt( (deta*deta) + (dphi*dphi));
670 if ((deta*deta) + (dphi*dphi)>1.e-7)
672 rad = TMath::Sqrt( (deta*deta) + (dphi*dphi) );
680 Int_t amplitude = myD->GetAmp(); //Gets the integer valued amplitude of the digit
681 Float_t amp = (Float_t)amplitude; //Need to typecast to Float_t before doing real energy conversion
682 Float_t digitEnergy = amp/10000000.0; //Factor of 10 million needed to convert!
683 emcalEnergy += digitEnergy;
684 emcalEnergyBGSub += (digitEnergy - fEBGAve);
689 jet.SetTrackList(numTracksInCone,pTArray, etaArray, phiArray, pdgArray);
690 jet.SetEMCALEnergy(emcalEnergy);
691 jet.SetEMCALEnergyBGSub(emcalEnergyBGSub);
692 jet.SetTrackEnergy(trackEnergy);
693 jet.SetTrackEnergyPtCut(trackEnergyPtCut);
694 fOutputPointer->AddJet(&jet);
702 void AliEMCALJetFinderAlgoOmni::FindJets()
704 //Runs the complete UA1 JetFinding algorithm to find jets!
705 if (fDebug>1) Info("FindJets","Starting Jet Finding!!!");
707 //If the array of JetFinderUnit objects has not been initialised then initialise with default settings
708 if(!fArrayInitialised)
711 FillUnitArray(kFillAll);
713 if (fDebug>1) Info("FindJets","Unit array filled");
715 //Step 1. Sort the array in descending order of Energy
716 Sort(fUnit,fNumUnits);
718 //Step 2. Set the number of iterations and Number of jets found to zero to start
722 //Step 3. Begin the iteration loop to find jets
723 //Need to iterate the algorithm while number of iterations<2 OR number of iterations<10 AND
724 //the value of the average background has changed more than specified amount
725 //Min iterations = 2, Max iterations = 10
726 //while(fNumIter<2 || (fNumIter <10 && ( (fEBGTotal-fEBGTotalOld)/fEBGTotal) > fBGMaxMove) )
728 while(fNumIter<2 || (fNumIter <10 && ( fEBGTotal-fEBGTotalOld) > fEBGTotal*fBGMaxMove) )
730 if (fDebug>1) Info("FindJets","Starting BIG iteration ---> %i",fNumIter);
732 //Step 4. Find the value of the average background energy
734 fOutputPointer->Reset(kResetJets); //Reset output object to store info for new iteration
737 //Loop over the array of unit objects and flag those with energy below MinCellEt
739 for(Int_t j=0; j<fNumUnits; j++)
741 if( (fUnit[j].GetUnitEnergy()-fEBGAve) < fEtMin)
743 // fUnit[j].SetUnitFlag(kBelowMinEt); TAKING OUT kBelow flag
747 //cout<<"THERE WERE "<<numbelow<<" units with E <EtMin!!!!!!!!!!!!!!!"<<endl;
749 //Do quick check if there are no jets upfront
750 // if(fUnit[0].GetUnitFlag() == kBelowMinEt)
751 if( (fUnit[0].GetUnitEnergy()-fEBGAve) < fEtMin)
753 cout <<"There are no jets for this event!" <<endl;
757 //Step 5. Begin with the first jet candidate cell (JET SEED LOOP)
758 if (fDebug>5) Info("FindJets","Beginning JET SEED LOOP");
759 for(Int_t count=0; count<fNumUnits; count++)
762 //CHECK CONDITION HERE _ NOT SURE IF SHOULD MAYBE BE: GetUnitEnergy()-fEBGAve >fESeed?????????????????????????????
763 if(fUnit[count].GetUnitEnergy()>=fESeed && fUnit[count].GetUnitFlag()==kOutJet)
765 fEnergy = fUnit[count].GetUnitEnergy() - fEBGAve;
766 fJetEta = fUnit[count].GetUnitEta();
767 fJetPhi = fUnit[count].GetUnitPhi();
768 Int_t seedID = fUnit[count].GetUnitID();
769 if (fDebug>5) Info("FindJets","Inside first candidate jet seed loop for time : %i", count);
770 if (fDebug>5) Info("FindJets","Found candidate energy %f ",fEnergy);
771 if (fDebug>5) Info("FindJets","Found candidate eta %f ", fJetEta);
772 if (fDebug>5) Info("FindJets","Found candidate phi %f ", fJetPhi);
773 if (fDebug>5) Info("FindJets","Found candidate ID %i", seedID);
786 //Step 6. Find Jet Eta and Phi
787 //Loop over all units in the array to find the ones in the jet cone and determine contrib to Jet eta, phi
788 for(Int_t count1=0; count1<fNumUnits; count1++)
790 if(fUnit[count1].GetUnitID() == seedID && testflag)
793 continue; //skip unit if the jetseed to avoid doublecounting
795 if(fUnit[count1].GetUnitFlag() == kOutJet)
797 fDEta = fUnit[count1].GetUnitEta() - fJetEta;
798 fDPhi = fUnit[count1].GetUnitPhi() - fJetPhi;
799 if ( (fDEta*fDEta) + (fDPhi*fDPhi) >1.e-7)
801 fRad = TMath::Sqrt( (fDEta*fDEta) + (fDPhi*fDPhi) );
808 FindJetEtaPhi(count1);
811 }//end for (Jet Eta, Phi LOOP)
813 //Find the distance cone centre moved from previous cone centre
814 if (fDebug>10) Info("FindJets","Checking if cone move small enough");
815 if (((fJetEta-fEtaB)*(fJetEta-fEtaB)) + ((fJetPhi-fPhiB)*(fJetPhi-fPhiB)) >1.e-7)
817 fDistP = TMath::Sqrt( ((fJetEta-fEtaB)*(fJetEta-fEtaB)) + ((fJetPhi-fPhiB)*(fJetPhi-fPhiB)) );
822 // if(fDistP <= fMinMove) break;
825 //Find the distance cone centre is from initiator cell
826 if (fDebug>10) Info("FindJets","Checking if cone move too large");
827 if ( ((fJetEtaSum)*(fJetEtaSum))+((fJetPhiSum)*(fJetPhiSum)) >1.e-7)
829 fDistI = TMath::Sqrt( ((fJetEtaSum/fJetESum)*(fJetEtaSum/fJetESum)) + ((fJetPhiSum/fJetESum)*
830 (fJetPhiSum/fJetESum)));
836 if(fDistP>fMinMove && fDistI<fMaxMove)
842 }while(fDistP>fMinMove && fDistI<fMaxMove);
848 //Step 7. Find the Jet Energy
849 if (fDebug>1) Info("FindJets","Looking for Jet energy");
856 //cout<<"Number of cells in jet cone is: "<<fNumInCone<<endl;
858 //Step 8. Check if the jet is a valid jet
859 //Check if cluster energy is above Min allowed to be a jet
860 //DID NOT DO THE COSH COMPARISON HERE -> NEED TO CHECK WHICH COMPARISON IS BEST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
861 if (fDebug>5) Info("FindJets","Checking cluster is valid jet");
862 if(fJetESum < fJetEMin)
864 for(Int_t count2=0; count2<fNumUnits; count2++)
866 if(fUnit[count2].GetUnitFlag()==kInCurrentJet || fUnit[count2].GetUnitFlag()==kOutJet)
867 fUnit[count2].SetUnitFlag(kOutJet);
869 if (fDebug>10) Info("FindJets","NOT a valid jet cell");
872 for(Int_t count2=0; count2<fNumUnits; count2++)
874 if(fUnit[count2].GetUnitFlag()==kInCurrentJet)
876 // cout<<"Setting unit #"<<count2 <<" to be officially in a jet!"<<endl;
877 fUnit[count2].SetUnitFlag(kInJet);
881 //NEED TO CHECK FINAL WEIRD ITERATION OF ETA AND PHI CHANGES!!!!!!!!!
882 // fJetPhi += fJetPhiSum/fJetESum; //CHECK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
883 // fJetEta += fJetEtaSum/fJetESum; //CHECK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
885 fNumJets++; //Incrementing number of jets found
886 StoreJetInfo(); //Storing jet info
888 }//end if (check cluster above Min Jet Energy)
889 }//end if (Jet Seed condition)
890 }//end (JET SEED LOOP)
892 if (fDebug>5) Info("FindJets","End of BIG iteration number %i",fNumIter);
895 }//end 10 iteration WHILE LOOP