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