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