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 "AliPHOSGeometry.h"
34 #include "AliPHOSDigit.h"
35 #include "AliPHOSGetter.h"
36 #include "AliPHOSJetFinder.h"
37 #include "AliPHOSDigitizer.h"
39 ClassImp(AliPHOSJetFinder)
42 //____________________________________________________________________________
43 AliPHOSJetFinder::AliPHOSJetFinder():TNamed("AliPHOSJetFinder","")
45 //Initialize jet parameters
47 fMode = 0 ; //No iterations
48 fStatusCode = -999 ; //no selection
50 fConeRad = 1.; //Radius of jet value?????????
51 fMaxConeMove = 0.15 ; //value???????
52 fMinConeMove = 0.05 ; //value???????
53 fEtSeed = 4. ; //Energy of seed particle value??????????
54 fEtMin = 5.; //minimal energy of jet value??????????
55 fPrecBg = 0.00035 ; //value????????
64 //____________________________________________________________________________
65 AliPHOSJetFinder::~AliPHOSJetFinder()
78 //____________________________________________________________________________
79 void AliPHOSJetFinder::FindJetsFromParticles(const TClonesArray * plist,TObjArray * jetslist)
81 //Find jets in the case without detector.
84 TIter nextJet(jetslist) ;
89 //In this cicle we find number of jets and define approx. their directions
90 //note, that we do not really add particles to jet (index =-1)
91 while((p=static_cast<TParticle*>(next()))){
92 if(fStatusCode==-999 || p->GetStatusCode()==fStatusCode){
93 if(p->Energy() >= fEtSeed){ //Energetic enough
94 //cout << "p " << p->Energy() << endl ;
95 //cout << "Status "<<fStatusCode<<" "<<p->GetName()<<" " << p->Energy() << " "<<p->Eta()<< " "<<p->Phi()<<endl ;
96 Bool_t startnew = kTRUE ;
97 //Do not start new jet if part of older jet
99 while((jet=static_cast<AliPHOSJet*>(nextJet()))){
101 if(jet->AcceptConeDeviation(p)){
103 //cout << "false" << endl ;
108 //cout << "new " << endl ;
109 jet = new AliPHOSJet() ;
111 // jet = static_cast<AliPHOSJet*>(jetslist->Last()) ;
112 jet->SetConeRadius(fConeRad) ;
113 jet->SetMaxConeMove(fMaxConeMove) ;
114 // jet->SetMinConeMove(fMinConeMove) ;
115 jet->AddParticle(p,-1) ;
119 while((jet=static_cast<AliPHOSJet*>(nextJet()))){
120 if(jet->AcceptConeDeviation(p))
121 jet->AddParticle(p,-1) ; //Just recalculate direction of jet
126 //now calculate directions of jets using collected information
128 while((jet=static_cast<AliPHOSJet*>(nextJet()))){
129 jet->CalculateAll() ;
130 if(jet->Energy() < fEtMin){
131 jetslist->Remove(jet) ;
136 jetslist->Compress() ;
137 //And finally, really add particles to jets
138 for(Int_t iPart=0; iPart<plist->GetEntries();iPart++){
139 p=static_cast<TParticle*>(plist->At(iPart)) ;
140 if(fStatusCode == -999 || p->GetStatusCode()==fStatusCode){
141 Double_t dist = 999999. ; //big distance
143 for(Int_t i=0; i<jetslist->GetEntriesFast();i++){
144 jet=static_cast<AliPHOSJet*>(jetslist->At(i)) ;
145 if(jet->IsInCone(p)){
146 Double_t cdist = jet->DistanceToJet(p);
154 (static_cast<AliPHOSJet*>(jetslist->At(iJet)))->AddParticle(p,iPart); //assign particle to closest jet
158 //Calculate jet parameters
160 while((jet=static_cast<AliPHOSJet*>(nextJet()))){
161 jet->CalculateAll() ;
165 //____________________________________________________________________________
166 void AliPHOSJetFinder::FindJetsFromDigits(const TClonesArray * digits, TObjArray * jets){
167 //Find jets in the case witht detector at the level of digits.
168 if(digits->GetEntries()==0){
169 Error("JetsFromDigits","No entries in digits list \n") ;
174 TClonesArray * copyDigits = new TClonesArray(*digits) ;
176 //Remove CPV digits if any
177 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance("GPS2","") ;
179 AliPHOSDigit * digit ;
180 for(iDigit=copyDigits->GetEntries()-1;iDigit>=0;iDigit--){
181 digit=static_cast<AliPHOSDigit *>(copyDigits->At(iDigit)) ;
182 if(!geom->IsInEMC(digit->GetId()))
183 copyDigits->RemoveAt(iDigit) ;
187 copyDigits->Compress() ;
189 Double_t totalEnergy = 0 ;
190 Float_t * energy = new Float_t[copyDigits->GetEntries()] ;
191 //calculate average energy of digits
192 //fill array of energies
193 for(iDigit=0;iDigit<copyDigits->GetEntries();iDigit++){
194 digit=static_cast<AliPHOSDigit *>(copyDigits->At(iDigit)) ;
195 energy[iDigit] = Calibrate(digit) ;
196 totalEnergy+=energy[iDigit] ;
199 //Sort digits in decreasing energy.
200 Int_t * index = new Int_t[copyDigits->GetEntries()] ;
201 TMath::Sort(copyDigits->GetEntries(),energy,index) ;
203 Double_t eAverage = totalEnergy/copyDigits->GetEntries() ;
204 //remove digits below average energy
205 for(iDigit=copyDigits->GetEntries()-1;iDigit>=0;iDigit--){
206 digit=static_cast<AliPHOSDigit *>(copyDigits->At(index[iDigit])) ;
207 if(energy[index[iDigit]] < eAverage)
208 copyDigits->RemoveAt(iDigit) ;
216 while(iIter < 10){//less than 10 iterations
218 //while digits above seed
219 for(Int_t ind=0;ind<copyDigits->GetEntriesFast();ind++){
220 digit=static_cast<AliPHOSDigit*>(copyDigits->At(index[ind])) ;
221 if(energy[index[ind]] > fEtSeed && digit){ //start new jet
222 jet = new AliPHOSJet() ;
224 CalculateEEtaPhi(digit,e,eta,phi) ;
225 jet->AddDigit(e,eta,phi,-1) ;
226 //loop over left digits
227 for(Int_t iDigit = 0 ; iDigit < copyDigits->GetEntries() ; iDigit++){
228 if(iDigit!= ind){ //first digit already in jet
229 digit = static_cast<AliPHOSDigit *>(copyDigits->At(iDigit));
230 CalculateEEtaPhi(digit,e,eta,phi) ;
231 if(jet->IsInCone(eta,phi) && //is cell in cone
232 jet->AcceptConeDeviation(e,eta,phi)){//if cone does not move too much
233 jet->AddDigit(e,eta,phi,-1) ; //accept new direction
236 }//end of loop over cells
238 //accept all anused cells incide cone
239 //note, that digits might be returned as anused later
240 for(Int_t icell = 0 ; icell < copyDigits->GetEntries() ; icell++){
241 digit = static_cast<AliPHOSDigit *>(copyDigits->At(icell));
242 if(jet->IsInCone(eta,phi)){ //is cell in cone
243 CalculateEEtaPhi(digit,e,eta,phi) ;
244 jet->AddDigit(e,eta,phi,digit->GetIndexInList()) ;
248 //Accept Jet with Et > Et_min and remove all belonging digits
249 if(jet->Energy()/TMath::CosH(jet->Eta()) > fEtMin){
251 const Int_t * indxs = jet->Indexs(nIndxs) ;
252 for(Int_t i=0;i<nIndxs;i++){
253 copyDigits->RemoveAt(indxs[i]) ;
255 jet->CalculateAll() ;
256 jets->AddAt(jet,fNJets++);
258 else{ //remove jet and do not touch digits
263 if(energy[index[ind]] < fEtSeed){ // no more digits above threshold left, return from loop
269 //calculate new energy of backrgound
270 Double_t oldTotalEnergy = totalEnergy ;
272 for(Int_t i=0 ; i<copyDigits->GetEntriesFast() ; i++){
273 digit=static_cast<AliPHOSDigit*>(copyDigits->At(index[ind])) ;
275 totalEnergy+=energy[i] ;
277 if(!fMode || (oldTotalEnergy != 0) &&
278 (TMath::Abs(oldTotalEnergy - totalEnergy)/oldTotalEnergy < fPrecBg))
284 copyDigits->Delete() ;
287 //____________________________________________________________________________
288 Double_t AliPHOSJetFinder::Calibrate(const AliPHOSDigit * digit){
289 // if(fPedestals || fGains ){ //use calibration data
290 // if(!fPedestals || !fGains ){
291 // Error("Calibrate","Either Pedestals of Gains not set!") ;
294 // Float_t en=(digit->GetAmp() - fPedestals->Data(digit->GetId)()))*fGains->Data(digit->GetId()) ;
300 // else{ //simulation
301 if(fSimGain==0){ //read simulation parameters
302 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
304 Error("Calibrate","Can not read Calibration parameters") ;
307 const TTask * task = gime->Digitizer() ;
308 if(strcmp(task->IsA()->GetName(),"AliPHOSDigitizer")==0){
309 const AliPHOSDigitizer * dig = static_cast<const AliPHOSDigitizer *>(task) ;
310 fSimGain = dig->GetEMCchannel() ;
311 fSimPedestal = dig->GetEMCpedestal();
315 return fSimPedestal + digit->GetAmp()*fSimGain ;
319 //____________________________________________________________________________
320 void AliPHOSJetFinder::CalculateEEtaPhi(const AliPHOSDigit * d,Double_t &e, Double_t &eta, Double_t &phi){
321 //Calculate direction of the jet
323 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance("GPS2","") ;
325 geom->RelPosInAlice(d->GetId(), pos) ;
329 //____________________________________________________________________________
330 void AliPHOSJetFinder::Print(){
331 //Print parameters of the found jet
332 printf("\n --------------- AliPHOSJetFinder --------------- \n") ;
333 printf(" Jets found .........%d \n",fNJets) ;
334 printf(" Seed energy cut ....%f \n",fEtSeed) ;
335 printf(" Cone radius ........%f \n",fConeRad) ;
336 printf(" Minimal cone move ..%f \n",fMinConeMove) ;
337 printf(" Maximal cone move ..%f \n",fMaxConeMove) ;
338 printf("------------------------------------------------- \n") ;