1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 //_________________________________________________________________________
17 // C++ version of UA2 and/or Lund jet finding algorithm
18 // UA1 jet algorithm from LUND JETSET (LUCELL)
19 // Find jets at the level of no detector and Digits.
20 // Needs modifications.
21 //*-- Author : D.Peressounko after UA1 coll. etc
22 //////////////////////////////////////////////////////////////////////////////
24 // --- ROOT system ---
25 #include "TClonesArray.h"
27 #include "TParticle.h"
29 // --- Standard library ---
31 // --- AliRoot header files ---
32 #include "AliPHOSJet.h"
33 #include "AliPHOSDigit.h"
34 #include "AliPHOSGetter.h"
35 #include "AliPHOSJetFinder.h"
36 #include "AliPHOSDigitizer.h"
38 ClassImp(AliPHOSJetFinder)
41 //____________________________________________________________________________
42 AliPHOSJetFinder::AliPHOSJetFinder():TNamed("AliPHOSJetFinder","")
44 //Initialize jet parameters
46 fMode = 0 ; //No iterations
47 fStatusCode = -999 ; //no selection
49 fConeRad = 1.; //Radius of jet value?????????
50 fMaxConeMove = 0.15 ; //value???????
51 fMinConeMove = 0.05 ; //value???????
52 fEtSeed = 4. ; //Energy of seed particle value??????????
53 fEtMin = 5.; //minimal energy of jet value??????????
54 fPrecBg = 0.00035 ; //value????????
63 //____________________________________________________________________________
64 AliPHOSJetFinder::~AliPHOSJetFinder()
77 //____________________________________________________________________________
78 void AliPHOSJetFinder::FindJetsFromParticles(const TClonesArray * plist,TObjArray * jetslist)
80 //Find jets in the case without detector.
83 TIter nextJet(jetslist) ;
88 //In this cicle we find number of jets and define approx. their directions
89 //note, that we do not really add particles to jet (index =-1)
90 while((p=static_cast<TParticle*>(next()))){
91 if(fStatusCode==-999 || p->GetStatusCode()==fStatusCode){
92 if(p->Energy() >= fEtSeed){ //Energetic enough
93 //cout << "p " << p->Energy() << endl ;
94 //cout << "Status "<<fStatusCode<<" "<<p->GetName()<<" " << p->Energy() << " "<<p->Eta()<< " "<<p->Phi()<<endl ;
95 Bool_t startnew = kTRUE ;
96 //Do not start new jet if part of older jet
98 while((jet=static_cast<AliPHOSJet*>(nextJet()))){
100 if(jet->AcceptConeDeviation(p)){
102 //cout << "false" << endl ;
107 //cout << "new " << endl ;
108 jet = new AliPHOSJet() ;
110 // jet = static_cast<AliPHOSJet*>(jetslist->Last()) ;
111 jet->SetConeRadius(fConeRad) ;
112 jet->SetMaxConeMove(fMaxConeMove) ;
113 // jet->SetMinConeMove(fMinConeMove) ;
114 jet->AddParticle(p,-1) ;
118 while((jet=static_cast<AliPHOSJet*>(nextJet()))){
119 if(jet->AcceptConeDeviation(p))
120 jet->AddParticle(p,-1) ; //Just recalculate direction of jet
125 //now calculate directions of jets using collected information
127 while((jet=static_cast<AliPHOSJet*>(nextJet()))){
128 jet->CalculateAll() ;
129 if(jet->Energy() < fEtMin){
130 jetslist->Remove(jet) ;
135 jetslist->Compress() ;
136 //And finally, really add particles to jets
137 for(Int_t iPart=0; iPart<plist->GetEntries();iPart++){
138 p=static_cast<TParticle*>(plist->At(iPart)) ;
139 if(fStatusCode == -999 || p->GetStatusCode()==fStatusCode){
140 Double_t dist = 999999. ; //big distance
142 for(Int_t i=0; i<jetslist->GetEntriesFast();i++){
143 jet=static_cast<AliPHOSJet*>(jetslist->At(i)) ;
144 if(jet->IsInCone(p)){
145 Double_t cdist = jet->DistanceToJet(p);
153 (static_cast<AliPHOSJet*>(jetslist->At(iJet)))->AddParticle(p,iPart); //assign particle to closest jet
157 //Calculate jet parameters
159 while((jet=static_cast<AliPHOSJet*>(nextJet()))){
160 jet->CalculateAll() ;
164 //____________________________________________________________________________
165 void AliPHOSJetFinder::FindJetsFromDigits(const TClonesArray * digits, TObjArray * jets){
166 //Find jets in the case witht detector at the level of digits.
167 if(digits->GetEntries()==0){
168 Error("JetsFromDigits","No entries in digits list \n") ;
173 TClonesArray * copyDigits = new TClonesArray(*digits) ;
175 //Remove CPV digits if any
176 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance("GPS2","") ;
178 AliPHOSDigit * digit ;
179 for(iDigit=copyDigits->GetEntries()-1;iDigit>=0;iDigit--){
180 digit=static_cast<AliPHOSDigit *>(copyDigits->At(iDigit)) ;
181 if(!geom->IsInEMC(digit->GetId()))
182 copyDigits->RemoveAt(iDigit) ;
186 copyDigits->Compress() ;
188 Double_t totalEnergy = 0 ;
189 Float_t * energy = new Float_t[copyDigits->GetEntries()] ;
190 //calculate average energy of digits
191 //fill array of energies
192 for(iDigit=0;iDigit<copyDigits->GetEntries();iDigit++){
193 digit=static_cast<AliPHOSDigit *>(copyDigits->At(iDigit)) ;
194 energy[iDigit] = Calibrate(digit) ;
195 totalEnergy+=energy[iDigit] ;
198 //Sort digits in decreasing energy.
199 Int_t * index = new Int_t[copyDigits->GetEntries()] ;
200 TMath::Sort(copyDigits->GetEntries(),energy,index) ;
202 Double_t eAverage = totalEnergy/copyDigits->GetEntries() ;
203 //remove digits below average energy
204 for(iDigit=copyDigits->GetEntries()-1;iDigit>=0;iDigit--){
205 digit=static_cast<AliPHOSDigit *>(copyDigits->At(index[iDigit])) ;
206 if(energy[index[iDigit]] < eAverage)
207 copyDigits->RemoveAt(iDigit) ;
215 while(iIter < 10){//less than 10 iterations
217 //while digits above seed
218 for(Int_t ind=0;ind<copyDigits->GetEntriesFast();ind++){
219 digit=static_cast<AliPHOSDigit*>(copyDigits->At(index[ind])) ;
220 if(energy[index[ind]] > fEtSeed && digit){ //start new jet
221 jet = new AliPHOSJet() ;
223 CalculateEEtaPhi(digit,e,eta,phi) ;
224 jet->AddDigit(e,eta,phi,-1) ;
225 //loop over left digits
226 for(Int_t iDigit = 0 ; iDigit < copyDigits->GetEntries() ; iDigit++){
227 if(iDigit!= ind){ //first digit already in jet
228 digit = static_cast<AliPHOSDigit *>(copyDigits->At(iDigit));
229 CalculateEEtaPhi(digit,e,eta,phi) ;
230 if(jet->IsInCone(eta,phi) && //is cell in cone
231 jet->AcceptConeDeviation(e,eta,phi)){//if cone does not move too much
232 jet->AddDigit(e,eta,phi,-1) ; //accept new direction
235 }//end of loop over cells
237 //accept all anused cells incide cone
238 //note, that digits might be returned as anused later
239 for(Int_t icell = 0 ; icell < copyDigits->GetEntries() ; icell++){
240 digit = static_cast<AliPHOSDigit *>(copyDigits->At(icell));
241 if(jet->IsInCone(eta,phi)){ //is cell in cone
242 CalculateEEtaPhi(digit,e,eta,phi) ;
243 jet->AddDigit(e,eta,phi,digit->GetIndexInList()) ;
247 //Accept Jet with Et > Et_min and remove all belonging digits
248 if(jet->Energy()/TMath::CosH(jet->Eta()) > fEtMin){
250 const Int_t * indxs = jet->Indexs(nIndxs) ;
251 for(Int_t i=0;i<nIndxs;i++){
252 copyDigits->RemoveAt(indxs[i]) ;
254 jet->CalculateAll() ;
255 jets->AddAt(jet,fNJets++);
257 else{ //remove jet and do not touch digits
262 if(energy[index[ind]] < fEtSeed){ // no more digits above threshold left, return from loop
268 //calculate new energy of backrgound
269 Double_t oldTotalEnergy = totalEnergy ;
271 for(Int_t i=0 ; i<copyDigits->GetEntriesFast() ; i++){
272 digit=static_cast<AliPHOSDigit*>(copyDigits->At(index[ind])) ;
274 totalEnergy+=energy[i] ;
276 if(!fMode || (oldTotalEnergy != 0) &&
277 (TMath::Abs(oldTotalEnergy - totalEnergy)/oldTotalEnergy < fPrecBg))
283 copyDigits->Delete() ;
286 //____________________________________________________________________________
287 Double_t AliPHOSJetFinder::Calibrate(const AliPHOSDigit * digit){
288 // if(fPedestals || fGains ){ //use calibration data
289 // if(!fPedestals || !fGains ){
290 // Error("Calibrate","Either Pedestals of Gains not set!") ;
293 // Float_t en=(digit->GetAmp() - fPedestals->Data(digit->GetId)()))*fGains->Data(digit->GetId()) ;
299 // else{ //simulation
300 if(fSimGain==0){ //read simulation parameters
301 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
303 Error("Calibrate","Can not read Calibration parameters") ;
306 const TTask * task = gime->Digitizer() ;
307 if(strcmp(task->IsA()->GetName(),"AliPHOSDigitizer")==0){
308 const AliPHOSDigitizer * dig = static_cast<const AliPHOSDigitizer *>(task) ;
309 fSimGain = dig->GetEMCchannel() ;
310 fSimPedestal = dig->GetEMCpedestal();
314 return fSimPedestal + digit->GetAmp()*fSimGain ;
318 //____________________________________________________________________________
319 void AliPHOSJetFinder::CalculateEEtaPhi(const AliPHOSDigit * d,Double_t &e, Double_t &eta, Double_t &phi){
320 //Calculate direction of the jet
322 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance("GPS2","") ;
324 geom->RelPosInAlice(d->GetId(), pos) ;
328 //____________________________________________________________________________
329 void AliPHOSJetFinder::Print(){
330 //Print parameters of the found jet
331 printf("\n --------------- AliPHOSJetFinder --------------- \n") ;
332 printf(" Jets found .........%d \n",fNJets) ;
333 printf(" Seed energy cut ....%f \n",fEtSeed) ;
334 printf(" Cone radius ........%f \n",fConeRad) ;
335 printf(" Minimal cone move ..%f \n",fMinConeMove) ;
336 printf(" Maximal cone move ..%f \n",fMaxConeMove) ;
337 printf("------------------------------------------------- \n") ;