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