]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/jetfinder/AliEMCALJetFinderAlgoOmni.cxx
Coding convention corrections
[u/mrichter/AliRoot.git] / EMCAL / jetfinder / AliEMCALJetFinderAlgoOmni.cxx
CommitLineData
45a58699 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$
dc7da436 23Revision 1.1 2006/02/28 21:56:34 jklay
24moving jetfinder code to subdirectory
25
45a58699 26Revision 1.16 2006/02/15 15:11:05 pavlinov
27update of Jenn and Marco
28
29Revision 1.15 2004/11/22 19:52:05 mhorner
30Make sure pi0 get through
31
32Revision 1.14 2004/04/02 17:11:33 mhorner
33Marco's bug - fixes implemented
34
35Revision 1.13 2004/03/26 01:00:38 mhorner
36Implementing Marco's optimisations
37
38Revision 1.12 2004/03/15 19:59:37 mhorner
39Pyhtia comparison extended
40
41Revision 1.11 2004/03/09 17:06:38 mhorner
42Made more robust
43
44Revision 1.10 2004/03/06 01:56:09 mhorner
45Pythai comp code
46
47Revision 1.9 2004/02/23 20:37:32 mhorner
48changed geometry call
49
50Revision 1.8 2004/01/29 23:28:44 mhorner
51Jet Finder - hard coded geom parameters removed
52
53Revision 1.7 2004/01/21 22:27:47 mhorner
54Cleaning up coding conventions
55
56Revision 1.6 2003/10/28 13:54:30 schutz
57Compilation warnings fixed
58
59Revision 1.5 2003/09/23 13:31:41 mhorner
60Changed coordinate system
61
62Revision 1.4 2003/09/19 13:16:20 mhorner
63Added additional jet energy info
64
65
66Revision 1.3 2003/09/04 12:49:56 mhorner
67Changed hadron correction and added saving EMCAL and track contributions
68
69*/
70
71
72//*--Author: Sarah Blyth (LBL)
73//*--Based on UA1 jet algorithm from LUND JETSET called from EMC-erj
74
75#include "TTask.h"
76#include "TMath.h"
77#include "TParticle.h"
78#include "AliRun.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"
87#include "AliEMCAL.h"
88#include "AliEMCALDigit.h"
89#include "AliEMCALJet.h"
90
91
92ClassImp(AliEMCALJetFinderAlgoOmni)
93
94 AliEMCALJetFinderAlgoOmni::AliEMCALJetFinderAlgoOmni()
95{
96 //Default constructor
97if (fDebug>0) Info("AliEMCALJetFinderAlgoOmni","Beginning Default Constructor");
98 AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance("EMCAL_55_25","EMCAL");
99 fNumIter = 0;
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
108 fPtCut = 0;
109 fHadCorr = 0;
110 fEBGTotal = 1.0; //Set to 1 so that no div by zero in first FindJets() loop
111 fEBGTotalOld = 0.0;
112 fEBGAve = 0.0;
113 fEnergy = 0.0;
114 fJetEta = 0.0;
115 fJetPhi = 0.0;
116 fEtaInit = 0.0;
117 fPhiInit = 0.0;
118 fEtaB = 0.0;
119 fPhiB = 0.0;
120 fJetESum = 0.0;
121 fJetEtaSum = 0.0;
122 fJetPhiSum = 0.0;
123 fDEta = 0.0;
124 fDPhi = 0.0;
125 fDistP = 0.0;
126 fDistI = 0.0;
127 fTempE = 0.0;
128 fRad = 2.0; //Set to 2 to start
129 fNumInCone = 0;
130 fNumJets = 0;
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
134}
135
136 AliEMCALJetFinderAlgoOmni::~AliEMCALJetFinderAlgoOmni()
137 {
138 //Destructor
139 if (fDebug>0) Info("AliEMCALJetFinderAlgoOmni","Beginning Destructor");
140 delete[] fUnit;
141 delete[] fUnitNoCuts;
142 }
143
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)
147 {
148 //Sets parameters for the JetFinding algorithm
149 if (fDebug>1) Info("SetJetFindingParameters","Setting parameters for JetFinding");
150
151 SetNumUnits(numUnits);
152 SetJetESeed(eSeed);
153 SetConeRad(coneRad);
154 SetJetEMin(jetEMin);
155 SetEtMin(etMin);
156 SetMinMove(minMove);
157 SetMaxMove(maxMove);
158 SetBGMaxMove(bgMaxMove);
159 }
160
161 void AliEMCALJetFinderAlgoOmni::SetJetFindingParameters
162 (Int_t numUnits, Float_t eSeed, Float_t coneRad, Float_t jetEMin, Float_t etMin)
163 {
164 //Sets fewer parameters for the JetFinding algorithm
165 if (fDebug>1) Info("SetJetFindingParameters","Setting parameters for JetFinding");
166
167 SetNumUnits(numUnits);
168 SetJetESeed(eSeed);
169 SetConeRad(coneRad);
170 SetJetEMin(jetEMin);
171 SetEtMin(etMin);
172 SetMinMove(fMinMove);
173 SetMaxMove(fMaxMove);
174 SetBGMaxMove(fBGMaxMove);
175 }
176
177 void AliEMCALJetFinderAlgoOmni::InitUnitArray()
178 {
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;
185 }
186
187 void AliEMCALJetFinderAlgoOmni::FillUnitArray(AliEMCALJetFinderAlgoUA1FillUnitFlagType_t flag)
188 {
189 // Fill the unit array
190 if (fDebug>1) Info("FillUnitArray","Beginning FillUnitArray");
191 // AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
192 // if (pEMCAL){
193 // AliEMCALGeometry* geom = AliEMCALGeometry::GetInstance(pEMCAL->GetTitle(), "");
194 // }else
195 // {
196
197 AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
198 if (geom == 0)
199 geom = AliEMCALGeometry::GetInstance("EMCAL_55_25","EMCAL");
200
201 // }
202
203 AliEMCALJetFinderAlgoUA1FillUnitFlagType_t option = flag;
204 Int_t numTracks, numDigits;
205
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();
212 TParticle *myPart;
213 AliEMCALDigit *myDigit;
214 if (!fPythiaComparison)
215 {
216 //Fill units with Track info if appropriate
217 if(option==kFillTracksOnly || option ==kFillAll)
218 {
219 for(Int_t j=0; j<numTracks; j++)
220 {
221 myPart = fInputPointer->GetTrack(j);
222 Float_t eta = myPart->Eta();
dc7da436 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);
226 Int_t towerID = 0;
227
45a58699 228 Float_t pT = myPart->Pt();
229 Float_t unitEnergy = fUnit[towerID-1].GetUnitEnergy();
230 Float_t unitEnergyNoCuts = fUnitNoCuts[towerID-1].GetUnitEnergy();
231
232
233 //OLD WAY: //Do Hadron Correction
234 if(fHadCorr != 0)
235 {
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
243
244
245 /*
246 //Do Hadron Correction with propagate phi for the track
247 if(fHadCorr != 0)
248 {
249 Bool_t curl = 1;
250 Float_t deltaPhi;
251 TParticlePDG *pdg = myPart->GetPDG();
252 if(pdg->Charge() < 0)
253 {
254 deltaPhi = PropagatePhi(myPart->Pt(), -1.0, curl);
255 }
256 else{
257 deltaPhi = PropagatePhi(myPart->Pt(), 1.0, curl);
258 }
259 phi += deltaPhi;
260 //Get new tower id for cell that track would curve into
261 Int_t towerID2;
262 if(phi>(TMath::Pi()/180.0)*geom->GetArm1PhiMax() || phi<(TMath::Pi()/180.0)*geom->GetArm1PhiMin())
263 {
264 towerID2 = -1;
265 }
266 else{
267 towerID2 = geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi);
268 }
269
270 if(towerID2 != -1)
271 {
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
283 */
284
285 fUnitNoCuts[towerID-1].SetUnitEnergy(unitEnergyNoCuts + pT);
286 //Do Pt cut on tracks
287 if(fPtCut != 0 && pT < fPtCut) continue;
288
289 fUnit[towerID-1].SetUnitEnergy(unitEnergy+pT);
290
291 }//end tracks loop
292 }//end Tracks condition
293
294
295 //Fill units with Digit info if appropriate
296 if(option ==kFillDigitsOnly || option ==kFillAll)
297 {
298 for(Int_t k=0; k<numDigits; k++)
299 {
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);
310 }//end digits loop
311 }//end digits condition
312
313 //Set all unit flags, Eta, Phi
314 for(Int_t i=0; i<fNumUnits; i++)
315 {
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);
320 Float_t eta;
321 Float_t phi;
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);
328 eta = 0.0;
329 phi = 0.0;
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)
336
337 }
338 if (fPythiaComparison)
339 {
340 for(Int_t j=0; j<numTracks; j++)
341 {
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 )
348 {
349 fUnit[j].SetUnitEnergy(myPart->Energy()*TMath::Sin(myPart->Theta()));
350 }else
351 {
352 fUnit[j].SetUnitEnergy(0.00);
353 }
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()));
359 }
360 for(Int_t k=numTracks; k < fNumUnits; k++)
361 {
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);
372 }
373 }
374
375
376
377 }
378
379
380 void AliEMCALJetFinderAlgoOmni::Sort(AliEMCALJetFinderAlgoUA1Unit *unit, Int_t length)
381 {
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);
385 }
386
387
388 void AliEMCALJetFinderAlgoOmni::QS(AliEMCALJetFinderAlgoUA1Unit *unit, Int_t left, Int_t right)
389 {
390 //Sorts the AliEMCALJetFinderAlgoUA1Unit objects in decending order of Energy
391 if (fDebug>111) Info("QS","QuickSorting Unit objects");
392
393 Int_t i;
394 Int_t j;
395 AliEMCALJetFinderAlgoUA1Unit unitFirst;
396 AliEMCALJetFinderAlgoUA1Unit unitSecond;
397
398 i = left;
399 j = right;
400 unitFirst = unit[(left+right)/2];
401
402 do
403 {
404 while( (unit[i].GetUnitEnergy() > unitFirst.GetUnitEnergy()) && (i < right)) i++;
405 while( (unitFirst.GetUnitEnergy() > unit[j].GetUnitEnergy()) && (j > left)) j--;
406
407 if(i <= j)
408 {
409 unitSecond = unit[i];
410 unit[i] = unit[j];
411 unit[j] = unitSecond;
412 i++;
413 j--;
414 }//end if
415 }while(i <= j);
416
417 if(left < j) QS(unit, left, j);
418 if(i < right) QS(unit, i, right);
419 }
420
421
422 void AliEMCALJetFinderAlgoOmni::FindBG()
423 {
424 if(fBGType == kRatio) RatioBG();
425 else if(fBGType == kCone) ConeBG();
426 else if(fBGType == kConstant) ConstantBG();
427 }
428
429 void AliEMCALJetFinderAlgoOmni::RatioBG()
430 {
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;
436 fEBGTotal = 0.0;
437 Int_t numCone = 0;
438
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;
442
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++)
446 {
447 if(fUnit[i].GetUnitFlag() != kInJet)
448 {
449 Int_t id = fUnit[i].GetUnitID();
450 fEBGTotal += fUnitNoCuts[id-1].GetUnitEnergy();
451 }
452 else numCone++;
453 }//end for
454
455 fEBGTotal *= fBGPar;
456 fEBGAve = fEBGTotal / (fNumUnits - numCone);
457 if (fDebug>5) Info("FindBG","Average BG is %f: ",fEBGAve);
458
459 for(Int_t count=0; count<fNumUnits;count++)
460 {
461 fUnit[count].SetUnitFlag(kOutJet);
462 }//end for
463 }
464
465 void AliEMCALJetFinderAlgoOmni::ConeBG()
466 {
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;
472 fEBGTotal = 0.0;
473 Int_t numCone = 0;
474
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++)
477 {
478 if(fUnit[i].GetUnitFlag() != kInJet)
479 fEBGTotal += fUnit[i].GetUnitEnergy();
480 else numCone++;
481 }//end for
482
483 fEBGAve = fEBGTotal / (fNumUnits - numCone);
484 if (fDebug>5) Info("FindBG","Average BG is %f: ",fEBGAve);
485
486 for(Int_t count=0; count<fNumUnits;count++)
487 {
488 fUnit[count].SetUnitFlag(kOutJet);
489 }//end for
490 }
491
492 void AliEMCALJetFinderAlgoOmni::ConstantBG()
493 {
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");
497
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;
501
502 fEBGAve = fBGPar;
503 if (fDebug>5) Info("FindBG","Average BG is %f: ",fEBGAve);
504
505 fEBGTotal = 0.0;
506 Int_t numCone = 0;
507 for(Int_t count=0; count<fNumUnits;count++)
508 {
509 if(fUnit[count].GetUnitFlag() == kInJet)
510 {
511 numCone++;
512 }
513 fUnit[count].SetUnitFlag(kOutJet);
514 }//end for
515 fEBGTotal = fEBGAve * (fNumUnits-numCone);
516 fEBGTotalOld = fEBGTotal;
517 }
518
519 void AliEMCALJetFinderAlgoOmni::FindJetEtaPhi(Int_t counter)
520 {
521 //Finds the eta and phi of the jet axis
522 if (fDebug>10) Info("FindJetEtaPhi","Finding Jet Eta and Phi");
523
524 fDEta = fUnit[counter].GetUnitEta() - fEtaInit;
525 fDPhi = fUnit[counter].GetUnitPhi() - fPhiInit;
526
527 fEnergy = fUnit[counter].GetUnitEnergy() - fEBGAve;
528 fJetEtaSum += fEnergy * fDEta;
529 fJetPhiSum += fEnergy * fDPhi;
530 fJetESum += fEnergy;
531 if (fJetESum >1.0e-7)
532 {
533 fJetEta = fEtaInit + (fJetEtaSum / fJetESum);
534 fJetPhi = fPhiInit + (fJetPhiSum / fJetESum);
535 }
536 }
537
538
539 void AliEMCALJetFinderAlgoOmni::FindJetEnergy()
540 {
541 //Finds the energy of the jet after the final axis has been found
542 if (fDebug>1) Info("FindJetEnergy","Finding Jet Energy");
543
544 for(Int_t i=0; i<fNumUnits; i++)
545 {
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;
549 Float_t rad;
550 if ((dEta*dEta) + (dPhi*dPhi)>1.e-7)
551 {
552 rad = TMath::Sqrt( (dEta*dEta) + (dPhi*dPhi) );
553 }else
554 {
555 rad=0.0;
556 }
557
558 if(fUnit[i].GetUnitFlag()==kOutJet && rad<= fConeRad)
559 {
560 fUnit[i].SetUnitFlag(kInCurrentJet);
561 Float_t energy = fUnit[i].GetUnitEnergy() - fEBGAve;
562 fJetESum += energy;
563 fJetEtaSum += energy * dEta;
564 fJetPhiSum += energy * dPhi;
565 fNumInCone++; //Increment the number of cells in the jet cone
566 }//end if
567 }//end for
568 }
569
570
571 void AliEMCALJetFinderAlgoOmni::StoreJetInfo()
572 {
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();
576 if (geom == 0)
577 geom = AliEMCALGeometry::GetInstance("EMCAL_55_25","EMCAL");
578 //Store:
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
585
586 AliEMCALJet jet(fJetESum,fJetPhi,fJetEta);
587
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;
592
593 Int_t numberTracks = fInputPointer->GetNTracks();
594 Int_t numberDigits = fInputPointer->GetNDigits();
595 AliEMCALDigit *myD;
596 TParticle *myP;
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;
602
603 for(Int_t counter=0; counter<numberTracks; counter++)
604 {
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++;
612 }//end for
613
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];
618 Int_t index = 0;
619
620 for(Int_t counter2=0; counter2<numberTracks; counter2++)
621 {
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;
627 Float_t rad ;
628 if ((deta*deta) + (dphi*dphi)>1.e-7)
629 {
630 rad = TMath::Sqrt( (deta*deta) + (dphi*dphi) );
631 }else
632 {
633 rad=0.0;
634 }
635
636 if(rad<=fConeRad)
637 {
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();
645 index++;
646 if(fHadCorr != 0)
647 {
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
653
654 }//end if
655 }//end for
656
657 //Loop over digits to find EMCal contribution within jetcone
658 for(Int_t counter3=0; counter3<numberDigits; counter3++)
659 {
660 myD = fInputPointer->GetDigit(counter3);
661 //GET DIGIT ETA, PHI so that can check if inside R!
662 Float_t eta = 0.0;
663 Float_t phi = 0.0;
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));
669 Float_t rad ;
670 if ((deta*deta) + (dphi*dphi)>1.e-7)
671 {
672 rad = TMath::Sqrt( (deta*deta) + (dphi*dphi) );
673 }else
674 {
675 rad=0.0;
676 }
677
678 if(rad<=fConeRad)
679 {
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);
685 }//end if
686 }//end count3 for
687
688 //Save in JET object
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);
695 delete[] pTArray;
696 delete[] etaArray;
697 delete[] phiArray;
698 delete[] pdgArray;
699 }
700
701
702 void AliEMCALJetFinderAlgoOmni::FindJets()
703 {
704 //Runs the complete UA1 JetFinding algorithm to find jets!
705 if (fDebug>1) Info("FindJets","Starting Jet Finding!!!");
706
707 //If the array of JetFinderUnit objects has not been initialised then initialise with default settings
708 if(!fArrayInitialised)
709 {
710 InitUnitArray();
711 FillUnitArray(kFillAll);
712 }//end if
713 if (fDebug>1) Info("FindJets","Unit array filled");
714
715 //Step 1. Sort the array in descending order of Energy
716 Sort(fUnit,fNumUnits);
717
718 //Step 2. Set the number of iterations and Number of jets found to zero to start
719 fNumIter = 0;
720 fNumJets = 0;
721
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) )
727
728 while(fNumIter<2 || (fNumIter <10 && ( fEBGTotal-fEBGTotalOld) > fEBGTotal*fBGMaxMove) )
729 {
730 if (fDebug>1) Info("FindJets","Starting BIG iteration ---> %i",fNumIter);
731
732 //Step 4. Find the value of the average background energy
733 FindBG();
734 fOutputPointer->Reset(kResetJets); //Reset output object to store info for new iteration
735 fNumJets=0;
736
737 //Loop over the array of unit objects and flag those with energy below MinCellEt
738 Int_t numbelow = 0;
739 for(Int_t j=0; j<fNumUnits; j++)
740 {
741 if( (fUnit[j].GetUnitEnergy()-fEBGAve) < fEtMin)
742 {
743 // fUnit[j].SetUnitFlag(kBelowMinEt); TAKING OUT kBelow flag
744 numbelow++;
745 }//end if
746 }//end for
747 //cout<<"THERE WERE "<<numbelow<<" units with E <EtMin!!!!!!!!!!!!!!!"<<endl;
748
749 //Do quick check if there are no jets upfront
750 // if(fUnit[0].GetUnitFlag() == kBelowMinEt)
751 if( (fUnit[0].GetUnitEnergy()-fEBGAve) < fEtMin)
752 {
753 cout <<"There are no jets for this event!" <<endl;
754 break;
755 }//end if
756
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++)
760 {
761
762//CHECK CONDITION HERE _ NOT SURE IF SHOULD MAYBE BE: GetUnitEnergy()-fEBGAve >fESeed?????????????????????????????
763 if(fUnit[count].GetUnitEnergy()>=fESeed && fUnit[count].GetUnitFlag()==kOutJet)
764 {
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);
774
775 fEtaInit = fJetEta;
776 fPhiInit = fJetPhi;
777 fEtaB = fJetEta;
778 fPhiB = fJetPhi;
779 Int_t testflag = 1;
780 do
781 {
782 fJetESum = 0.0;
783 fJetEtaSum = 0.0;
784 fJetPhiSum = 0.0;
785
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++)
789 {
790 if(fUnit[count1].GetUnitID() == seedID && testflag)
791 {
792 testflag=0;
793 continue; //skip unit if the jetseed to avoid doublecounting
794 }
795 if(fUnit[count1].GetUnitFlag() == kOutJet)
796 {
797 fDEta = fUnit[count1].GetUnitEta() - fJetEta;
798 fDPhi = fUnit[count1].GetUnitPhi() - fJetPhi;
799 if ( (fDEta*fDEta) + (fDPhi*fDPhi) >1.e-7)
800 {
801 fRad = TMath::Sqrt( (fDEta*fDEta) + (fDPhi*fDPhi) );
802 }else
803 {
804 fRad=0.000;
805 }
806 if(fRad <= fConeRad)
807 {
808 FindJetEtaPhi(count1);
809 }//end if
810 }//end if
811 }//end for (Jet Eta, Phi LOOP)
812
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)
816 {
817 fDistP = TMath::Sqrt( ((fJetEta-fEtaB)*(fJetEta-fEtaB)) + ((fJetPhi-fPhiB)*(fJetPhi-fPhiB)) );
818 }else
819 {
820 fDistP = 0.00;
821 }
822 // if(fDistP <= fMinMove) break;
823
824
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)
828 {
829 fDistI = TMath::Sqrt( ((fJetEtaSum/fJetESum)*(fJetEtaSum/fJetESum)) + ((fJetPhiSum/fJetESum)*
830 (fJetPhiSum/fJetESum)));
831 }else
832 {
833 fDistI = 0.00;
834 }
835
836 if(fDistP>fMinMove && fDistI<fMaxMove)
837 {
838 fEtaB = fJetEta;
839 fPhiB = fJetPhi;
840 }//end if
841
842 }while(fDistP>fMinMove && fDistI<fMaxMove);
843
844 fJetEta = fEtaB;
845 fJetPhi = fPhiB;
846
847
848 //Step 7. Find the Jet Energy
849 if (fDebug>1) Info("FindJets","Looking for Jet energy");
850 fJetESum = 0.0;
851 fJetEtaSum = 0.0;
852 fJetPhiSum = 0.0;
853 fNumInCone = 0;
854 FindJetEnergy();
855
856 //cout<<"Number of cells in jet cone is: "<<fNumInCone<<endl;
857
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)
863 {
864 for(Int_t count2=0; count2<fNumUnits; count2++)
865 {
866 if(fUnit[count2].GetUnitFlag()==kInCurrentJet || fUnit[count2].GetUnitFlag()==kOutJet)
867 fUnit[count2].SetUnitFlag(kOutJet);
868 }//end for
869 if (fDebug>10) Info("FindJets","NOT a valid jet cell");
870 }else
871 {
872 for(Int_t count2=0; count2<fNumUnits; count2++)
873 {
874 if(fUnit[count2].GetUnitFlag()==kInCurrentJet)
875 {
876 // cout<<"Setting unit #"<<count2 <<" to be officially in a jet!"<<endl;
877 fUnit[count2].SetUnitFlag(kInJet);
878 }
879 }//end for
880
881 //NEED TO CHECK FINAL WEIRD ITERATION OF ETA AND PHI CHANGES!!!!!!!!!
882 // fJetPhi += fJetPhiSum/fJetESum; //CHECK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
883 // fJetEta += fJetEtaSum/fJetESum; //CHECK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
884
885 fNumJets++; //Incrementing number of jets found
886 StoreJetInfo(); //Storing jet info
887
888 }//end if (check cluster above Min Jet Energy)
889 }//end if (Jet Seed condition)
890 }//end (JET SEED LOOP)
891
892if (fDebug>5) Info("FindJets","End of BIG iteration number %i",fNumIter);
893// this->Dump();
894 fNumIter++;
895 }//end 10 iteration WHILE LOOP
896 }
897
898
899
900
901
902
903
904
905
906
907