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)
20 //*-- Author : D.Peressounko after UA1 coll. etc
21 //////////////////////////////////////////////////////////////////////////////
23 // --- ROOT system ---
24 #include "TClonesArray.h"
26 #include "TParticle.h"
28 // --- Standard library ---
30 // --- AliRoot header files ---
32 #include "AliPHOSDigit.h"
33 #include "AliPHOSGetter.h"
34 #include "AliPHOSJetFinder.h"
35 #include "AliPHOSDigitizer.h"
37 ClassImp(AliPHOSJetFinder)
40 //____________________________________________________________________________
41 AliPHOSJetFinder::AliPHOSJetFinder():TNamed("AliPHOSJetFinder","")
44 fMode = 0 ; //No iterations
45 fStatusCode = -999 ; //no selection
47 fConeRad = 1.; //Radius of jet value?????????
48 fMaxConeMove = 0.15 ; //value???????
49 fMinConeMove = 0.05 ; //value???????
50 fEtSeed = 4. ; //Energy of seed particle value??????????
51 fEtMin = 5.; //minimal energy of jet value??????????
52 fPrecBg = 0.00035 ; //value????????
61 //____________________________________________________________________________
62 AliPHOSJetFinder::~AliPHOSJetFinder()
74 //____________________________________________________________________________
75 void AliPHOSJetFinder::FindJetsFromParticles(const TClonesArray * plist,TObjArray * jetslist)
80 TIter nextJet(jetslist) ;
85 //In this cicle we find number of jets and define approx. their directions
86 //note, that we do not really add particles to jet (index =-1)
87 while((p=static_cast<TParticle*>(next()))){
88 if(fStatusCode==-999 || p->GetStatusCode()==fStatusCode){
89 if(p->Energy() >= fEtSeed){ //Energetic enough
90 //cout << "p " << p->Energy() << endl ;
91 //cout << "Status "<<fStatusCode<<" "<<p->GetName()<<" " << p->Energy() << " "<<p->Eta()<< " "<<p->Phi()<<endl ;
92 Bool_t startnew = kTRUE ;
93 //Do not start new jet if part of older jet
95 while((jet=static_cast<AliJet*>(nextJet()))){
97 if(jet->AcceptConeDeviation(p)){
99 //cout << "false" << endl ;
104 //cout << "new " << endl ;
107 // jet = static_cast<AliJet*>(jetslist->Last()) ;
108 jet->SetConeRadius(fConeRad) ;
109 jet->SetMaxConeMove(fMaxConeMove) ;
110 // jet->SetMinConeMove(fMinConeMove) ;
111 jet->AddParticle(p,-1) ;
115 while((jet=static_cast<AliJet*>(nextJet()))){
116 if(jet->AcceptConeDeviation(p))
117 jet->AddParticle(p,-1) ; //Just recalculate direction of jet
122 //now calculate directions of jets using collected information
124 while((jet=static_cast<AliJet*>(nextJet()))){
125 jet->CalculateAll() ;
126 if(jet->Energy() < fEtMin){
127 jetslist->Remove(jet) ;
132 jetslist->Compress() ;
133 //And finally, really add particles to jets
134 for(Int_t iPart=0; iPart<plist->GetEntries();iPart++){
135 p=static_cast<TParticle*>(plist->At(iPart)) ;
136 if(fStatusCode == -999 || p->GetStatusCode()==fStatusCode){
137 Double_t dist = 999999. ; //big distance
139 for(Int_t i=0; i<jetslist->GetEntriesFast();i++){
140 jet=static_cast<AliJet*>(jetslist->At(i)) ;
141 if(jet->IsInCone(p)){
142 Double_t cdist = jet->DistanceToJet(p);
150 (static_cast<AliJet*>(jetslist->At(iJet)))->AddParticle(p,iPart); //assign particle to closest jet
154 //Calculate jet parameters
156 while((jet=static_cast<AliJet*>(nextJet()))){
157 jet->CalculateAll() ;
161 //____________________________________________________________________________
162 void AliPHOSJetFinder::FindJetsFromDigits(const TClonesArray * digits, TObjArray * jets){
164 if(digits->GetEntries()==0){
165 Error("JetsFromDigits","No entries in digits list \n") ;
170 TClonesArray * copyDigits = new TClonesArray(*digits) ;
172 //Remove CPV digits if any
173 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance("GPS2","") ;
175 AliPHOSDigit * digit ;
176 for(iDigit=copyDigits->GetEntries()-1;iDigit>=0;iDigit--){
177 digit=static_cast<AliPHOSDigit *>(copyDigits->At(iDigit)) ;
178 if(!geom->IsInEMC(digit->GetId()))
179 copyDigits->RemoveAt(iDigit) ;
183 copyDigits->Compress() ;
185 Double_t totalEnergy = 0 ;
186 Float_t energy[copyDigits->GetEntries()] ;
187 //calculate average energy of digits
188 //fill array of energies
189 for(iDigit=0;iDigit<copyDigits->GetEntries();iDigit++){
190 digit=static_cast<AliPHOSDigit *>(copyDigits->At(iDigit)) ;
191 energy[iDigit] = Calibrate(digit) ;
192 totalEnergy+=energy[iDigit] ;
195 //Sort digits in decreasing energy.
196 Int_t index[copyDigits->GetEntries()] ;
197 TMath::Sort(copyDigits->GetEntries(),energy,index) ;
199 Double_t eAverage = totalEnergy/copyDigits->GetEntries() ;
200 //remove digits below average energy
201 for(iDigit=copyDigits->GetEntries()-1;iDigit>=0;iDigit--){
202 digit=static_cast<AliPHOSDigit *>(copyDigits->At(index[iDigit])) ;
203 if(energy[index[iDigit]] < eAverage)
204 copyDigits->RemoveAt(iDigit) ;
212 while(iIter < 10){//less than 10 iterations
214 //while digits above seed
215 for(Int_t ind=0;ind<copyDigits->GetEntriesFast();ind++){
216 digit=static_cast<AliPHOSDigit*>(copyDigits->At(index[ind])) ;
217 if(energy[index[ind]] > fEtSeed && digit){ //start new jet
220 CalculateEEtaPhi(digit,e,eta,phi) ;
221 jet->AddDigit(e,eta,phi,-1) ;
222 //loop over left digits
223 for(Int_t iDigit = 0 ; iDigit < copyDigits->GetEntries() ; iDigit++){
224 if(iDigit!= ind){ //first digit already in jet
225 digit = static_cast<AliPHOSDigit *>(copyDigits->At(iDigit));
226 CalculateEEtaPhi(digit,e,eta,phi) ;
227 if(jet->IsInCone(e,eta,phi) && //is cell in cone
228 jet->AcceptConeDeviation(e,eta,phi)){//if cone does not move too much
229 jet->AddDigit(e,eta,phi,-1) ; //accept new direction
232 }//end of loop over cells
234 //accept all anused cells incide cone
235 //note, that digits might be returned as anused later
236 for(Int_t icell = 0 ; icell < copyDigits->GetEntries() ; icell++){
237 digit = static_cast<AliPHOSDigit *>(copyDigits->At(icell));
238 if(jet->IsInCone(e,eta,phi)){ //is cell in cone
239 CalculateEEtaPhi(digit,e,eta,phi) ;
240 jet->AddDigit(e,eta,phi,digit->GetIndexInList()) ;
244 //Accept Jet with Et > Et_min and remove all belonging digits
245 if(jet->Energy()/TMath::CosH(jet->Eta()) > fEtMin){
247 const Int_t * indxs = jet->Indexs(nIndxs) ;
248 for(Int_t i=0;i<nIndxs;i++){
249 copyDigits->RemoveAt(indxs[i]) ;
251 jet->CalculateAll() ;
252 jets->AddAt(jet,fNJets++);
254 else{ //remove jet and do not touch digits
259 if(energy[index[ind]] < fEtSeed){ // no more digits above threshold left, return from loop
265 //calculate new energy of backrgound
266 Double_t oldTotalEnergy = totalEnergy ;
268 for(Int_t i=0 ; i<copyDigits->GetEntriesFast() ; i++){
269 digit=static_cast<AliPHOSDigit*>(copyDigits->At(index[ind])) ;
271 totalEnergy+=energy[i] ;
273 if(!fMode || (oldTotalEnergy != 0) &&
274 (TMath::Abs(oldTotalEnergy - totalEnergy)/oldTotalEnergy < fPrecBg))
279 copyDigits->Delete() ;
282 //____________________________________________________________________________
283 Double_t AliPHOSJetFinder::Calibrate(const AliPHOSDigit * digit){
284 // if(fPedestals || fGains ){ //use calibration data
285 // if(!fPedestals || !fGains ){
286 // Error("Calibrate","Either Pedestals of Gains not set!") ;
289 // Float_t en=(digit->GetAmp() - fPedestals->Data(digit->GetId)()))*fGains->Data(digit->GetId()) ;
295 // else{ //simulation
296 if(fSimGain==0){ //read simulation parameters
297 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
299 Error("Calibrate","Can not read Calibration parameters") ;
302 const TTask * task = gime->Digitizer() ;
303 if(strcmp(task->IsA()->GetName(),"AliPHOSDigitizer")==0){
304 const AliPHOSDigitizer * dig = static_cast<const AliPHOSDigitizer *>(task) ;
305 fSimGain = dig->GetEMCchannel() ;
306 fSimPedestal = dig->GetEMCpedestal();
310 return fSimPedestal + digit->GetAmp()*fSimGain ;
314 //____________________________________________________________________________
315 void AliPHOSJetFinder::CalculateEEtaPhi(const AliPHOSDigit * d,Double_t &e, Double_t &eta, Double_t &phi){
317 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance("GPS2","") ;
319 geom->RelPosInAlice(d->GetId(), pos) ;
323 //____________________________________________________________________________
324 void AliPHOSJetFinder::Print(Option_t * option){
325 printf("\n --------------- AliPHOSJetFinder --------------- \n") ;
326 printf(" Jets found .........%d \n",fNJets) ;
327 printf(" Seed energy cut ....%f \n",fEtSeed) ;
328 printf(" Cone radius ........%f \n",fConeRad) ;
329 printf(" Minimal cone move ..%f \n",fMinConeMove) ;
330 printf(" Maximal cone move ..%f \n",fMaxConeMove) ;
331 printf("------------------------------------------------- \n") ;