1 //SARAH'S REVISED PERSONAL COPY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5 /**************************************************************************
6 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
8 * Author: The ALICE Off-line Project. *
9 * Contributors are mentioned in the code where appropriate. *
11 * Permission to use, copy, modify and distribute this software and its *
12 * documentation strictly for non-commercial purposes is hereby granted *
13 * without fee, provided that the above copyright notice appears in all *
14 * copies and that both the copyright notice and this permission notice *
15 * appear in the supporting documentation. The authors make no claims *
16 * about the suitability of this software for any purpose. It is *
17 * provided "as is" without express or implied warranty. *
18 **************************************************************************/
22 //*--Author: Sarah Blyth (LBL)
23 //*--Based on UA1 jet algorithm from LUND JETSET called from EMC-erj
26 #include "AliEMCALJetFinderInput.h"
27 #include "AliEMCALJetFinderOutput.h"
28 #include "AliEMCALJetFinderAlgo.h"
29 #include "AliEMCALJetFinderAlgoUA1Revised2.h"
30 #include "AliEMCALJetFinderAlgoUA1Unit.h"
31 #include "AliEMCALGeometry.h"
33 #include "AliEMCALDigit.h"
34 #include "TParticle.h"
36 #include "AliEMCALJet.h"
40 ClassImp(AliEMCALJetFinderAlgoUA1Revised2)
42 AliEMCALJetFinderAlgoUA1Revised2::AliEMCALJetFinderAlgoUA1Revised2()
45 if (fDebug>0) Info("AliEMCALJetFinderAlgoUA1Revised","Beginning Default Constructor");
48 fNumUnits = 13824; //Number of towers in EMCAL
49 fESeed = 5.0; //Default value
50 fConeRad = 0.5; //Default value
51 fJetEMin = 10.0; //Default value
52 fEtMin = 0.28; //Default value
53 fMinMove = 0.05; //From original UA1 JetFinder
54 fMaxMove = 0.15; //From original UA1 JetFinder
55 fBGMaxMove = 0.035; //From original UA1 JetFinder
58 fEBGTotal = 1.0; //Set to 1 so that no div by zero in first FindJets() loop
76 fRad = 2.0; //Set to 2 to start
79 fArrayInitialised = 0; //Set to FALSE to start
82 AliEMCALJetFinderAlgoUA1Revised2::~AliEMCALJetFinderAlgoUA1Revised2()
85 if (fDebug>0) Info("AliEMCALJetFinderAlgoUA1Revised","Beginning Destructor");
89 void AliEMCALJetFinderAlgoUA1Revised2::SetJetFindingParameters
90 (Int_t numUnits, Float_t eSeed, Float_t coneRad, Float_t jetEMin, Float_t etMin,
91 Float_t minMove, Float_t maxMove, Float_t bgMaxMove)
93 //Sets parameters for the JetFinding algorithm
94 if (fDebug>1) Info("SetJetFindingParameters","Setting parameters for JetFinding");
96 SetNumUnits(numUnits);
103 SetBGMaxMove(bgMaxMove);
106 void AliEMCALJetFinderAlgoUA1Revised2::SetJetFindingParameters
107 (Int_t numUnits, Float_t eSeed, Float_t coneRad, Float_t jetEMin, Float_t etMin)
109 //Sets fewer parameters for the JetFinding algorithm
110 if (fDebug>1) Info("SetJetFindingParameters","Setting parameters for JetFinding");
112 SetNumUnits(numUnits);
117 SetMinMove(fMinMove);
118 SetMaxMove(fMaxMove);
119 SetBGMaxMove(fBGMaxMove);
122 void AliEMCALJetFinderAlgoUA1Revised2::InitUnitArray()
124 //Initialises unit array
125 if(fArrayInitialised) delete[] fUnit;
126 fUnit = new AliEMCALJetFinderAlgoUA1Unit[fNumUnits];
127 fArrayInitialised = 1;
130 void AliEMCALJetFinderAlgoUA1Revised2::FillUnitArray(AliEMCALJetFinderAlgoUA1FillUnitFlagType_t flag)
132 if (fDebug>1) Info("FillUnitArray","Beginning FillUnitArray");
133 AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
136 // AliEMCALGeometry* geom = AliEMCALGeometry::GetInstance(pEMCAL->GetTitle(), "");
139 AliEMCALGeometry* geom = AliEMCALGeometry::GetInstance("EMCAL_5655_21", "");
142 AliEMCALJetFinderAlgoUA1FillUnitFlagType_t option = flag;
143 Int_t numTracks, numDigits;
145 //Loops over all elements in the AliEMCALJetFinderAlgoUA1Unit array and
146 //fills the objects with relevant values from the Data Input object
147 if (fDebug>1) Info("FillUnitArray","Filling array with Unit objects");
148 if (fDebug>1) Info("FillUnitArray","NTracks %i NDigits %i",fInputPointer->GetNTracks(),fInputPointer->GetNDigits());
149 numTracks = fInputPointer->GetNTracks();
150 numDigits = fInputPointer->GetNDigits();
152 AliEMCALDigit *myDigit;
154 //Fill units with Track info if appropriate
155 if(option==kFillTracksOnly || option ==kFillAll)
157 for(Int_t j=0; j<numTracks; j++)
159 myPart = fInputPointer->GetTrack(j);
160 Float_t eta = myPart->Eta();
161 Float_t phi = myPart->Phi();
162 Int_t towerID = geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi);
163 Float_t pT = myPart->Pt();
164 Float_t unitEnergy = fUnit[towerID-1].GetUnitEnergy();
166 //Do Hadron Correction
169 Double_t fullP = myPart->P();
170 Double_t hCEnergy = fHadCorr->GetEnergy(fullP, (Double_t)eta);
171 unitEnergy -= hCEnergy*TMath::Sin(myPart->Theta());
172 fUnit[towerID-1].SetUnitEnergy(unitEnergy);
173 } //end Hadron Correction loop
175 //Do Pt cut on tracks
176 if(fPtCut != 0 && pT < fPtCut) continue;
178 fUnit[towerID-1].SetUnitEnergy(unitEnergy+pT);
181 }//end Tracks condition
184 //Fill units with Digit info if appropriate
185 if(option ==kFillDigitsOnly || option ==kFillAll)
187 for(Int_t k=0; k<numDigits; k++)
189 myDigit = fInputPointer->GetDigit(k);
190 if (fDebug>1) Info("FillUnitArray","getting digits %i %i numdigits",k,numDigits );
191 Int_t towerID = myDigit->GetId();
192 Int_t amplitude = myDigit->GetAmp(); //Gets the integer valued amplitude of the digit
193 Float_t amp = (Float_t)amplitude; //Need to typecast to Float_t before doing real energy conversion
194 Float_t digitEnergy = amp/10000000.0; //Factor of 10 million needed to convert!
195 Float_t unitEnergy = fUnit[towerID-1].GetUnitEnergy() + digitEnergy;
196 fUnit[towerID-1].SetUnitEnergy(unitEnergy);
199 }//end digits condition
201 //Set all unit flags, Eta, Phi
202 for(Int_t i=0; i<fNumUnits; i++)
204 if (fDebug>1) Info("FillUnitArray","Setting all units outside jets");
205 fUnit[i].SetUnitFlag(kOutJet); //Set all units to be outside a jet initially
206 fUnit[i].SetUnitID(i+1);
209 geom->EtaPhiFromIndex(fUnit[i].GetUnitID(), eta, phi);
210 fUnit[i].SetUnitEta(eta);
211 fUnit[i].SetUnitPhi(phi*TMath::Pi()/180.0);
212 // if(i>13000) cout<<"!!!!!!!!!!!!!!!!!For unit0, eta="<<eta<<" and phi="<<phi*TMath::Pi()/180.0<<" and ID="<<fUnit[i].GetUnitID()<<endl;
213 // 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;
214 }//end loop over all units in array (same as all towers in EMCAL)
218 void AliEMCALJetFinderAlgoUA1Revised2::Sort(AliEMCALJetFinderAlgoUA1Unit *unit, Int_t length)
220 //Calls the recursive quicksort method to sort unit objects in decending order of Energy
221 if (fDebug>1) Info("Sort","Sorting Unit objects");
222 QS(unit, 0, length-1);
226 void AliEMCALJetFinderAlgoUA1Revised2::QS(AliEMCALJetFinderAlgoUA1Unit *unit, Int_t left, Int_t right)
228 //Sorts the AliEMCALJetFinderAlgoUA1Unit objects in decending order of Energy
229 if (fDebug>111) Info("QS","QuickSorting Unit objects");
233 AliEMCALJetFinderAlgoUA1Unit unitFirst;
234 AliEMCALJetFinderAlgoUA1Unit unitSecond;
238 unitFirst = unit[(left+right)/2];
242 while( (unit[i].GetUnitEnergy() > unitFirst.GetUnitEnergy()) && (i < right)) i++;
243 while( (unitFirst.GetUnitEnergy() > unit[j].GetUnitEnergy()) && (j > left)) j--;
247 unitSecond = unit[i];
249 unit[j] = unitSecond;
255 if(left < j) QS(unit, left, j);
256 if(i < right) QS(unit, i, right);
260 void AliEMCALJetFinderAlgoUA1Revised2::FindBG()
262 //Finds the background energy for the iteration
263 if (fDebug>1) Info("FindBG","Finding Average Background");
267 Int_t numOutWithE = 0;
269 //Loop over all unit objects in the array and sum the energy of those not in a jet
270 //WITH NOMINAL ENERGY!!!
271 for(Int_t i=0; i<fNumUnits; i++)
273 if(fUnit[i].GetUnitFlag() != kInJet && fUnit[i].GetUnitEnergy()>0.00001)
275 fEBGTotal += fUnit[i].GetUnitEnergy();
281 fEBGTotalOld = fEBGTotal;
282 fEBGAve = fEBGTotal / numOutWithE; // /(fNumUnits - numCone);
283 if (fDebug>5) Info("FindBG","Average BG is %f: ",fEBGAve);
285 for(Int_t count=0; count<fNumUnits;count++)
287 fUnit[count].SetUnitFlag(kOutJet);
292 void AliEMCALJetFinderAlgoUA1Revised2::FindJetEtaPhi(Int_t counter)
294 //Finds the eta and phi of the jet axis
295 if (fDebug>1) Info("FindJetEtaPhi","Finding Jet Eta and Phi");
297 fDEta = fUnit[counter].GetUnitEta() - fEtaInit;
298 fDPhi = fUnit[counter].GetUnitPhi() - fPhiInit;
300 fEnergy = fUnit[counter].GetUnitEnergy() - fEBGAve;
301 fJetEtaSum += fEnergy * fDEta;
302 fJetPhiSum += fEnergy * fDPhi;
304 fJetEta = fEtaInit + (fJetEtaSum / fJetESum);
305 fJetPhi = fPhiInit + (fJetPhiSum / fJetESum);
309 void AliEMCALJetFinderAlgoUA1Revised2::FindJetEnergy()
311 //Finds the energy of the jet after the final axis has been found
312 if (fDebug>1) Info("FindJetEnergy","Finding Jet Energy");
314 for(Int_t i=0; i<fNumUnits; i++)
316 //Loop over all unit objects in the array and find if within cone radius
317 Float_t dEta = fUnit[i].GetUnitEta() - fJetEta;
318 Float_t dPhi = fUnit[i].GetUnitPhi() - fJetPhi;
319 Float_t rad = TMath::Sqrt( (dEta*dEta) + (dPhi*dPhi) );
321 if(fUnit[i].GetUnitFlag()==kOutJet && rad<= fConeRad)
323 fUnit[i].SetUnitFlag(kInCurrentJet);
324 Float_t energy = fUnit[i].GetUnitEnergy() - fEBGAve;
326 fJetEtaSum += energy * dEta;
327 fJetPhiSum += energy * dPhi;
328 fNumInCone++; //Increment the number of cells in the jet cone
334 void AliEMCALJetFinderAlgoUA1Revised2::StoreJetInfo()
336 //Stores the resulting jet information in appropriate storage structure (TO BE DECIDED!!!!)
337 if (fDebug>1) Info("StoreJetInfo","Storing Jet Information");
340 //fJetESum is the final jet energy (background has been subtracted)
341 //fJetEta is the final jet Eta
342 //fJetPhi is the final jet Phi
343 //fNumInCone is the final number of cells included in the jet cone
344 //fEtaInit is the eta of the initiator cell
345 //fPhiInit is the phi of the initiator cell
346 fJet.SetEnergy(fJetESum);
347 fJet.SetEta(fJetEta);
348 fJet.SetPhi(fJetPhi);
350 cout<<"For iteration "<<fNumIter <<" and Jet number " <<fNumJets <<endl;
351 cout<<"The jet energy is: " <<fJetESum <<endl;
352 cout<<"The jet eta is ---->" <<fJetEta <<endl;
353 cout<<"The jet phi is ---->" <<fJetPhi <<endl;
355 Int_t numberTracks = fInputPointer->GetNTracks();
357 Int_t numTracksInCone = 0;
359 for(Int_t counter=0; counter<numberTracks; counter++)
361 myP = fInputPointer->GetTrack(counter);
362 Float_t eta = myP->Eta();
363 Float_t phi = myP->Phi();
364 Float_t deta = fJetEta-eta;
365 Float_t dphi = fJetPhi -phi;
366 Float_t rad = TMath::Sqrt( (deta*deta) + (dphi*dphi));
367 if(rad<=fConeRad) numTracksInCone++;
370 Float_t *pTArray = new Float_t[numTracksInCone];
371 Float_t *etaArray = new Float_t[numTracksInCone];
372 Float_t *phiArray = new Float_t[numTracksInCone];
373 Int_t *pdgArray = new Int_t[numTracksInCone];
376 for(Int_t counter2=0; counter2<numberTracks; counter2++)
378 myP = fInputPointer->GetTrack(counter2);
379 Float_t eta = myP->Eta();
380 Float_t phi = myP->Phi();
381 Float_t deta = fJetEta-eta;
382 Float_t dphi = fJetPhi -phi;
383 Float_t rad = TMath::Sqrt( (deta*deta) + (dphi*dphi));
386 pTArray[index] = myP->Pt();
387 etaArray[index] = eta;
388 phiArray[index] = phi;
389 pdgArray[index] = myP->GetPdgCode();
394 fJet.SetTrackList(numTracksInCone,pTArray, etaArray, phiArray, pdgArray);
395 fOutputObject.AddJet(&fJet);
403 void AliEMCALJetFinderAlgoUA1Revised2::FindJets()
405 //Runs the complete UA1 JetFinding algorithm to find jets!
406 if (fDebug>1) Info("FindJets","Starting Jet Finding!!!");
408 //If the array of JetFinderUnit objects has not been initialised then initialise with default settings
409 if(!fArrayInitialised)
412 FillUnitArray(kFillAll);
414 if (fDebug>1) Info("FindJets","Unit array filled");
416 //Step 1. Sort the array in descending order of Energy
417 Sort(fUnit,fNumUnits);
419 //Step 2. Set the number of iterations and Number of jets found to zero to start
423 //Step 3. Begin the iteration loop to find jets
424 //Need to iterate the algorithm while number of iterations<2 OR number of iterations<10 AND
425 //the value of the average background has changed more than specified amount
426 //Min iterations = 2, Max iterations = 10
427 //while(fNumIter<2 || (fNumIter <10 && ( (fEBGTotal-fEBGTotalOld)/fEBGTotal) > fBGMaxMove) )
429 while(fNumIter<2 || (fNumIter <10 && ( fEBGTotal-fEBGTotalOld) > fEBGTotal*fBGMaxMove) )
431 if (fDebug>1) Info("FindJets","Starting BIG iteration ---> %i",fNumIter);
433 //Step 4. Find the value of the average background energy
435 fOutputObject.Reset(kResetJets); //Reset output object to store info for new iteration
438 //Loop over the array of unit objects and flag those with energy below MinCellEt
440 for(Int_t j=0; j<fNumUnits; j++)
442 if( (fUnit[j].GetUnitEnergy()-fEBGAve) < fEtMin)
444 fUnit[j].SetUnitFlag(kBelowMinEt);
446 // if (fDebug>1) Info("FindJets","Below Min Et: %i",j);
450 //Do quick check if there are no jets upfront
451 if(fUnit[0].GetUnitFlag() == kBelowMinEt)
453 cout <<"There are no jets for this event!" <<endl;
457 //Step 5. Begin with the first jet candidate cell (JET SEED LOOP)
458 if (fDebug>5) Info("FindJets","Beginning JET SEED LOOP");
459 for(Int_t count=0; count<fNumUnits; count++)
462 //CHECK CONDITION HERE _ NOT SURE IF SHOULD MAYBE BE: GetUnitEnergy()-fEBGAve >fESeed?????????????????????????????
463 if(fUnit[count].GetUnitEnergy()>=fESeed && fUnit[count].GetUnitFlag()==kOutJet)
465 fEnergy = fUnit[count].GetUnitEnergy() - fEBGAve;
466 fJetEta = fUnit[count].GetUnitEta();
467 fJetPhi = fUnit[count].GetUnitPhi();
468 Int_t seedID = fUnit[count].GetUnitID();
469 if (fDebug>5) Info("FindJets","Inside first candidate jet seed loop for time : %i", count);
470 if (fDebug>5) Info("FindJets","Found candidate energy %f ",fEnergy);
471 if (fDebug>5) Info("FindJets","Found candidate eta %f ", fJetEta);
472 if (fDebug>5) Info("FindJets","Found candidate phi %f ", fJetPhi);
473 if (fDebug>5) Info("FindJets","Found candidate ID %i", seedID);
483 //Step 6. Find Jet Eta and Phi
484 //Loop over all units in the array to find the ones in the jet cone and determine contrib to Jet eta, phi
487 for(Int_t count1=0; count1<fNumUnits; count1++)
489 if(fUnit[count1].GetUnitID() == seedID) continue; //skip unit if the jetseed to avoid doublecounting
490 if(fUnit[count1].GetUnitFlag() == kOutJet)
492 fDEta = fUnit[count1].GetUnitEta() - fJetEta;
493 fDPhi = fUnit[count1].GetUnitPhi() - fJetPhi;
494 fRad = TMath::Sqrt( (fDEta*fDEta) + (fDPhi*fDPhi) );
497 FindJetEtaPhi(count1);
500 }//end for (Jet Eta, Phi LOOP)
502 //Find the distance cone centre moved from previous cone centre
503 if (fDebug>10) Info("FindJets","Checking if cone move small enough");
504 fDistP = TMath::Sqrt( ((fJetEta-fEtaB)*(fJetEta-fEtaB)) + ((fJetPhi-fPhiB)*(fJetPhi-fPhiB)) );
505 // if(fDistP <= fMinMove) break;
508 //Find the distance cone centre is from initiator cell
509 if (fDebug>10) Info("FindJets","Checking if cone move too large");
510 fDistI = TMath::Sqrt( ((fJetEtaSum/fJetESum)*(fJetEtaSum/fJetESum)) + ((fJetPhiSum/fJetESum)*
511 (fJetPhiSum/fJetESum)));
513 if(fDistP>fMinMove && fDistI<fMaxMove)
519 }while(fDistP>fMinMove && fDistI<fMaxMove);
525 //Step 7. Find the Jet Energy
526 if (fDebug>1) Info("FindJets","Looking for Jet energy");
533 //Step 8. Check if the jet is a valid jet
534 //Check if cluster energy is above Min allowed to be a jet
535 //DID NOT DO THE COSH COMPARISON HERE -> NEED TO CHECK WHICH COMPARISON IS BEST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
536 if (fDebug>5) Info("FindJets","Checking cluster is valid jet");
537 if(fJetESum < fJetEMin)
539 for(Int_t count2=0; count2<fNumUnits; count2++)
541 if(fUnit[count2].GetUnitFlag()==kInCurrentJet || fUnit[count2].GetUnitFlag()==kOutJet)
542 fUnit[count2].SetUnitFlag(kOutJet);
544 if (fDebug>10) Info("FindJets","NOT a valid jet cell");
547 for(Int_t count2=0; count2<fNumUnits; count2++)
549 if(fUnit[count2].GetUnitFlag()==kInCurrentJet)
551 // cout<<"Setting unit #"<<count2 <<" to be officially in a jet!"<<endl;
552 fUnit[count2].SetUnitFlag(kInJet);
556 //NEED TO CHECK FINAL WEIRD ITERATION OF ETA AND PHI CHANGES!!!!!!!!!
557 // fJetPhi += fJetPhiSum/fJetESum; //CHECK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
558 // fJetEta += fJetEtaSum/fJetESum; //CHECK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
560 fNumJets++; //Incrementing number of jets found
561 StoreJetInfo(); //Storing jet info
563 }//end if (check cluster above Min Jet Energy)
564 }//end if (Jet Seed condition)
565 }//end (JET SEED LOOP)
567 if (fDebug>5) Info("FindJets","End of BIG iteration number %i",fNumIter);
570 }//end 10 iteration WHILE LOOP