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 //////////////////////////////////////////////////////////////////////////////
26 /* History of cvs commits:
29 * Revision 1.8 2005/05/28 14:19:04 schutz
30 * Compilation warnings fixed by T.P.
34 // --- ROOT system ---
35 #include "TClonesArray.h"
37 #include "TParticle.h"
39 // --- Standard library ---
41 // --- AliRoot header files ---
43 #include "AliPHOSJet.h"
44 #include "AliPHOSGeometry.h"
45 #include "AliPHOSDigit.h"
46 #include "AliPHOSGetter.h"
47 #include "AliPHOSJetFinder.h"
48 #include "AliPHOSDigitizer.h"
50 ClassImp(AliPHOSJetFinder)
53 //____________________________________________________________________________
54 AliPHOSJetFinder::AliPHOSJetFinder():
55 TNamed("AliPHOSJetFinder",""),
70 //Initialize jet parameters
73 //____________________________________________________________________________
74 AliPHOSJetFinder::AliPHOSJetFinder(const AliPHOSJetFinder & jet) :
90 // copy ctor: no implementation yet
91 Fatal("cpy ctor", "not implemented");
94 //____________________________________________________________________________
95 AliPHOSJetFinder::~AliPHOSJetFinder()
108 //____________________________________________________________________________
109 void AliPHOSJetFinder::FindJetsFromParticles(const TClonesArray * plist,TObjArray * jetslist)
111 //Find jets in the case without detector.
114 TIter nextJet(jetslist) ;
119 //In this cicle we find number of jets and define approx. their directions
120 //note, that we do not really add particles to jet (index =-1)
121 while((p=static_cast<TParticle*>(next()))){
122 if(fStatusCode==-999 || p->GetStatusCode()==fStatusCode){
123 if(p->Energy() >= fEtSeed){ //Energetic enough
124 //cout << "p " << p->Energy() << endl ;
125 //cout << "Status "<<fStatusCode<<" "<<p->GetName()<<" " << p->Energy() << " "<<p->Eta()<< " "<<p->Phi()<<endl ;
126 Bool_t startnew = kTRUE ;
127 //Do not start new jet if part of older jet
129 while((jet=static_cast<AliPHOSJet*>(nextJet()))){
131 if(jet->AcceptConeDeviation(p)){
133 //cout << "false" << endl ;
138 //cout << "new " << endl ;
139 jet = new AliPHOSJet() ;
141 // jet = static_cast<AliPHOSJet*>(jetslist->Last()) ;
142 jet->SetConeRadius(fConeRad) ;
143 jet->SetMaxConeMove(fMaxConeMove) ;
144 // jet->SetMinConeMove(fMinConeMove) ;
145 jet->AddParticle(p,-1) ;
149 while((jet=static_cast<AliPHOSJet*>(nextJet()))){
150 if(jet->AcceptConeDeviation(p))
151 jet->AddParticle(p,-1) ; //Just recalculate direction of jet
156 //now calculate directions of jets using collected information
158 while((jet=static_cast<AliPHOSJet*>(nextJet()))){
159 jet->CalculateAll() ;
160 if(jet->Energy() < fEtMin){
161 jetslist->Remove(jet) ;
166 jetslist->Compress() ;
167 //And finally, really add particles to jets
168 for(Int_t iPart=0; iPart<plist->GetEntries();iPart++){
169 p=static_cast<TParticle*>(plist->At(iPart)) ;
170 if(fStatusCode == -999 || p->GetStatusCode()==fStatusCode){
171 Double_t dist = 999999. ; //big distance
173 for(Int_t i=0; i<jetslist->GetEntriesFast();i++){
174 jet=static_cast<AliPHOSJet*>(jetslist->At(i)) ;
175 if(jet->IsInCone(p)){
176 Double_t cdist = jet->DistanceToJet(p);
184 (static_cast<AliPHOSJet*>(jetslist->At(iJet)))->AddParticle(p,iPart); //assign particle to closest jet
188 //Calculate jet parameters
190 while((jet=static_cast<AliPHOSJet*>(nextJet()))){
191 jet->CalculateAll() ;
195 //____________________________________________________________________________
196 void AliPHOSJetFinder::FindJetsFromDigits(const TClonesArray * digits, TObjArray * jets){
197 //Find jets in the case witht detector at the level of digits.
198 if(digits->GetEntries()==0){
199 AliError(Form("No entries in digits list \n")) ;
204 TClonesArray * copyDigits = new TClonesArray(*digits) ;
206 //Remove CPV digits if any
207 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance("GPS2","") ;
209 AliPHOSDigit * digit ;
210 for(iDigit=copyDigits->GetEntries()-1;iDigit>=0;iDigit--){
211 digit=static_cast<AliPHOSDigit *>(copyDigits->At(iDigit)) ;
212 if(!geom->IsInEMC(digit->GetId()))
213 copyDigits->RemoveAt(iDigit) ;
217 copyDigits->Compress() ;
219 Double_t totalEnergy = 0 ;
220 Float_t * energy = new Float_t[copyDigits->GetEntries()] ;
221 //calculate average energy of digits
222 //fill array of energies
223 for(iDigit=0;iDigit<copyDigits->GetEntries();iDigit++){
224 digit=static_cast<AliPHOSDigit *>(copyDigits->At(iDigit)) ;
225 energy[iDigit] = Calibrate(digit) ;
226 totalEnergy+=energy[iDigit] ;
229 //Sort digits in decreasing energy.
230 Int_t * index = new Int_t[copyDigits->GetEntries()] ;
231 TMath::Sort(copyDigits->GetEntries(),energy,index) ;
233 Double_t eAverage = totalEnergy/copyDigits->GetEntries() ;
234 //remove digits below average energy
235 for(iDigit=copyDigits->GetEntries()-1;iDigit>=0;iDigit--){
236 digit=static_cast<AliPHOSDigit *>(copyDigits->At(index[iDigit])) ;
237 if(energy[index[iDigit]] < eAverage)
238 copyDigits->RemoveAt(iDigit) ;
246 while(iIter < 10){//less than 10 iterations
248 //while digits above seed
249 for(Int_t ind=0;ind<copyDigits->GetEntriesFast();ind++){
250 digit=static_cast<AliPHOSDigit*>(copyDigits->At(index[ind])) ;
251 if(energy[index[ind]] > fEtSeed && digit){ //start new jet
252 jet = new AliPHOSJet() ;
254 CalculateEEtaPhi(digit,e,eta,phi) ;
255 jet->AddDigit(e,eta,phi,-1) ;
256 //loop over left digits
257 for(Int_t iDigit = 0 ; iDigit < copyDigits->GetEntries() ; iDigit++){
258 if(iDigit!= ind){ //first digit already in jet
259 digit = static_cast<AliPHOSDigit *>(copyDigits->At(iDigit));
260 CalculateEEtaPhi(digit,e,eta,phi) ;
261 if(jet->IsInCone(eta,phi) && //is cell in cone
262 jet->AcceptConeDeviation(e,eta,phi)){//if cone does not move too much
263 jet->AddDigit(e,eta,phi,-1) ; //accept new direction
266 }//end of loop over cells
268 //accept all anused cells incide cone
269 //note, that digits might be returned as anused later
270 for(Int_t icell = 0 ; icell < copyDigits->GetEntries() ; icell++){
271 digit = static_cast<AliPHOSDigit *>(copyDigits->At(icell));
272 if(jet->IsInCone(eta,phi)){ //is cell in cone
273 CalculateEEtaPhi(digit,e,eta,phi) ;
274 jet->AddDigit(e,eta,phi,digit->GetIndexInList()) ;
278 //Accept Jet with Et > Et_min and remove all belonging digits
279 if(jet->Energy()/TMath::CosH(jet->Eta()) > fEtMin){
281 const Int_t * indxs = jet->Indexs(nIndxs) ;
282 for(Int_t i=0;i<nIndxs;i++){
283 copyDigits->RemoveAt(indxs[i]) ;
285 jet->CalculateAll() ;
286 jets->AddAt(jet,fNJets++);
288 else{ //remove jet and do not touch digits
293 if(energy[index[ind]] < fEtSeed){ // no more digits above threshold left, return from loop
299 //calculate new energy of backrgound
300 Double_t oldTotalEnergy = totalEnergy ;
302 for(Int_t i=0 ; i<copyDigits->GetEntriesFast() ; i++){
303 digit=static_cast<AliPHOSDigit*>(copyDigits->At(index[ind])) ;
305 totalEnergy+=energy[i] ;
307 if(!fMode || (oldTotalEnergy != 0) &&
308 (TMath::Abs(oldTotalEnergy - totalEnergy)/oldTotalEnergy < fPrecBg))
314 copyDigits->Delete() ;
317 //____________________________________________________________________________
318 Double_t AliPHOSJetFinder::Calibrate(const AliPHOSDigit * digit){
319 // if(fPedestals || fGains ){ //use calibration data
320 // if(!fPedestals || !fGains ){
321 // AliError(Form("Either Pedestals of Gains not set!")) ;
324 // Float_t en=(digit->GetAmp() - fPedestals->Data(digit->GetId)()))*fGains->Data(digit->GetId()) ;
330 // else{ //simulation
331 if(fSimGain==0){ //read simulation parameters
332 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
334 AliError(Form("Can not read Calibration parameters")) ;
337 const TTask * task = gime->Digitizer() ;
338 if(strcmp(task->IsA()->GetName(),"AliPHOSDigitizer")==0){
339 const AliPHOSDigitizer * dig = static_cast<const AliPHOSDigitizer *>(task) ;
340 fSimGain = dig->GetEMCchannel() ;
341 fSimPedestal = dig->GetEMCpedestal();
345 return fSimPedestal + digit->GetAmp()*fSimGain ;
349 //____________________________________________________________________________
350 void AliPHOSJetFinder::CalculateEEtaPhi(const AliPHOSDigit * d,Double_t &e, Double_t &eta, Double_t &phi){
351 //Calculate direction of the jet
353 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance("GPS2","") ;
355 geom->RelPosInAlice(d->GetId(), pos) ;
359 //____________________________________________________________________________
360 void AliPHOSJetFinder::Print(const Option_t *) const {
361 //Print parameters of the found jet
362 printf("\n --------------- AliPHOSJetFinder --------------- \n") ;
363 printf(" Jets found .........%d \n",fNJets) ;
364 printf(" Seed energy cut ....%f \n",fEtSeed) ;
365 printf(" Cone radius ........%f \n",fConeRad) ;
366 printf(" Minimal cone move ..%f \n",fMinConeMove) ;
367 printf(" Maximal cone move ..%f \n",fMaxConeMove) ;
368 printf("------------------------------------------------- \n") ;