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 #include <Riostream.h>
21 #include <TClonesArray.h>
25 #include "AliJetHeader.h"
26 #include "AliJetReader.h"
27 #include "AliJetReaderHeader.h"
28 #include "AliFastJetFinder.h"
29 #include "AliFastJetHeaderV1.h"
30 #include "AliJetReaderHeader.h"
31 #include "AliJetReader.h"
32 #include "AliJetUnitArray.h"
33 #include "AliFastJetInput.h"
34 #include "AliESDEvent.h"
37 #include "fastjet/PseudoJet.hh"
38 #include "fastjet/ClusterSequenceArea.hh"
39 #include "fastjet/AreaDefinition.hh"
40 #include "fastjet/JetDefinition.hh"
41 // get info on how fastjet was configured
42 #include "fastjet/config.h"
44 #ifdef ENABLE_PLUGIN_SISCONE
45 #include "fastjet/SISConePlugin.hh"
48 #include<sstream> // needed for internal io
53 #include "AliJetBkg.h"
57 ////////////////////////////////////////////////////////////////////////
59 AliJetBkg::AliJetBkg():
65 // Default constructor
68 //______________________________________________________________________
69 AliJetBkg::AliJetBkg(const AliJetBkg& input):
71 fReader(input.fReader),
72 fHeader(input.fHeader),
73 fInputFJ(input.fInputFJ)
78 //______________________________________________________________________
79 AliJetBkg& AliJetBkg::operator=(const AliJetBkg& source){
80 // Assignment operator.
82 new(this) AliJetBkg(source);
86 //___________________________________________________________________
87 Float_t AliJetBkg::BkgFastJet(){
89 AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
90 Bool_t debug = header->GetDebug(); // debug option
92 if(debug)cout<<"=============== AliJetBkg::BkgFastJet() =========== "<<endl;
93 vector<fastjet::PseudoJet> inputParticles=fInputFJ->GetInputParticles();
95 if(debug)cout<<"printing inputParticles for BKG "<<inputParticles.size()<<endl;
97 for(UInt_t i=0;i<inputParticles.size();i++){
98 // cout<<" "<<inputParticles[i].px()<<" "<<inputParticles[i].py()<<" "<<inputParticles[i].pz()<<endl;
102 double rParamBkg = header->GetRparamBkg(); //Radius for background calculation
103 Double_t rho=CalcRho(inputParticles,rParamBkg,"All");
104 if(debug)cout<<"-------- rho (from all part)="<<rho<<endl;
108 //___________________________________________________________________
109 Float_t AliJetBkg::BkgChargedFastJet(){
111 AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
112 Bool_t debug = header->GetDebug(); // debug option
114 if(debug)cout<<"=============== AliJetBkg::BkgChargedFastJet() =========== "<<endl;
116 vector<fastjet::PseudoJet> inputParticlesCharged=fInputFJ->GetInputParticlesCh();
118 if(debug)cout<<"printing CHARGED inputParticles for BKG "<<inputParticlesCharged.size()<<endl;
120 for(UInt_t i=0;i<inputParticlesCharged.size();i++){
121 // cout<<" "<<inputParticlesCharged[i].px()<<" "<<inputParticlesCharged[i].py()<<" "<<inputParticlesCharged[i].pz()<<endl;
125 double rParam = header->GetRparam();
127 Double_t rho=CalcRho(inputParticlesCharged,rParam,"Charg");
129 cout<<"-------- rho (from CHARGED part)="<<rho<<endl;
135 Float_t AliJetBkg::BkgStat()
137 //background subtraction using statistical method
139 AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
140 Bool_t debug = header->GetDebug(); // debug option
142 if(debug)cout<<"==============AliJetBkg::BkgStat()============="<<endl;
144 // Int_t nTracks= fReader->GetESD()->GetNumberOfTracks();
146 TF1 fun("fun",BkgFunction,0,800,1);
147 Double_t enTot=fun.Eval(nTracks);
148 Double_t accEMCal=2*0.7*110./180*TMath::Pi();//2.68 area of EMCal
149 return enTot/accEMCal;
152 /////////////////////////////////
153 Float_t AliJetBkg::BkgRemoveJetLeading(TClonesArray* fAODJets)
155 // Remove the particles of the
156 // two largest jets using the track references stored in the AODJet from the estimation of new rho.
158 AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
159 Bool_t debug = header->GetDebug(); // debug option
161 if(debug)cout<<"==============AliJetBkg::BkgRemoveJetLeading()============="<<endl;
164 // check if we are reading AOD jets
166 Bool_t fromAod = !strcmp(fReader->ClassName(),"AliJetESDReader");
167 if (fromAod) { refs = fReader->GetReferences(); }
169 //Hard wired Calorimeter area (get it later from the AliJetReaderHeader.h)
170 Double_t accEMCal=2*0.7*110./180*TMath::Pi();//2.68 area of EMCal
172 Int_t nJ=fAODJets->GetEntries(); //this must be the # of jets...
173 if(debug)cout<<"nJets: "<<nJ<<endl;
177 TClonesArray* fUnit = fReader->GetUnitArray();
178 if(fUnit == 0) { cout << "Could not get the momentum array" << endl; return -99; }
180 Int_t nIn = fUnit->GetEntries();
181 if(nIn == 0) { cout << "entries = 0 ; Event empty !!!" << endl ; return -99; }
184 Float_t jetarea1=0.0,jetarea2=0.0;
186 Int_t particlejet1=-99;
187 Int_t particlejet2=-99;
188 TRefArray *refarray1 = 0;
189 TRefArray *refarray2 = 0;
190 Int_t nJettracks1 = 0, nJettracks2 = 0;
196 jet1 = dynamic_cast<AliAODJet*>(fAODJets->At(0));
197 jetarea1=jet1->EffectiveAreaCharged();
198 Float_t jetPhi=jet1->Phi();
199 Float_t jetEta=jet1->Eta();
200 if(jetPhi>1.396 && jetPhi<3.316 && jetEta>-0.7 && jetEta<0.7)acc=1;
201 refarray1=jet1->GetRefTracks();
202 nJettracks1=refarray1->GetEntries();
203 if(debug)cout<<"nJ = 1, acc="<<acc<<" jetarea1="<<jetarea1<<endl;
208 jet1 = dynamic_cast<AliAODJet*>(fAODJets->At(0));
209 jetarea1=jet1->EffectiveAreaCharged();
210 Float_t jetPhi1=jet1->Phi();
211 Float_t jetEta1=jet1->Eta();
212 if(jetPhi1>1.396 && jetPhi1<3.316 && jetEta1>-0.7 && jetEta1<0.7)acc=1;
213 refarray1=jet1->GetRefTracks();
214 nJettracks1=refarray1->GetEntries();
215 if(debug)cout<<"npart = "<<nJettracks1<<endl;
217 jet2 = dynamic_cast<AliAODJet*>(fAODJets->At(1));
218 jetarea2=jet2->EffectiveAreaCharged();
219 Float_t jetPhi2=jet2->Phi();
220 Float_t jetEta2=jet2->Eta();
221 if(jetPhi2>1.396 && jetPhi2<3.316 && jetEta2>-0.7 && jetEta2<0.7)acc1=1;
222 refarray2=jet2->GetRefTracks();
223 nJettracks2=refarray2->GetEntries();
224 if(debug)cout<<"nJ = "<<nJ<<", acc="<<acc<<" acc1="<<acc1<<" jetarea1="<<jetarea1<<" jetarea2="<<jetarea2<<endl;
229 // cout<<" nIn = "<<nIn<<endl;
234 for(Int_t i=0; i<nIn; i++)
236 AliJetUnitArray *uArray = (AliJetUnitArray*)fUnit->At(i);
238 if(uArray->GetUnitEnergy()>0.){
239 eta = uArray->GetUnitEta();
240 phi = uArray->GetUnitPhi();
241 pt = uArray->GetUnitEnergy();
242 // cout<<"ipart = "<<ipart<<" eta="<<eta<<" phi="<<phi<<endl;
243 if(phi>1.396 && phi<3.316 && eta>-0.7 && eta<0.7){
249 for(Int_t ii=0; ii<nJettracks1;ii++){
251 particlejet1 = ((AliJetUnitArray*)refarray1->At(ii))->GetUnitTrackID();
253 if(ipart==particlejet1) {
264 for(Int_t ii=0; ii<nJettracks1;ii++){
265 particlejet1 = ((AliJetUnitArray*)refarray1->At(ii))->GetUnitTrackID();
267 //cout<<"uArr loop = "<<i<<" ipart in uArr (1/2)="<<ipart<<" part in jet="<<ii<<" partID="<<particlejet1<<" sumPt="<<sumPt<<endl;
268 if(ipart==particlejet1) {
275 for(Int_t ii=0; ii<nJettracks2;ii++){
276 particlejet2 = ((AliJetUnitArray*)refarray2->At(ii))->GetUnitTrackID();
277 //cout<<"uArr loop = "<<i<<" ipart in uArr (2/2)="<<ipart<<" part in jet="<<ii<<" partID="<<particlejet2<<" sumPt="<<sumPt<<endl;
278 if(ipart==particlejet2) {
290 }// end unit array loop
293 Float_t areasum = accEMCal-acc*jetarea1-acc1*jetarea2;
294 if(debug)cout<<"pt sum "<<sumPt<<" area "<<areasum<<endl;
296 if(nJ>0) rhoback=sumPt/areasum;
298 if(debug)cout<<" rho from leading jet paricle array removed "<<rhoback<<endl;
307 ////////////////////////////////////////////////////////////////////////
308 Float_t AliJetBkg::BkgFastJetCone(TClonesArray* fAODJets)
311 // Cone background subtraction method applied on the fastjet: REmove the particles of the
312 // two largest jets with the given R from the estimation of new rho.
314 AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
315 Bool_t debug = header->GetDebug(); // debug option
317 if(debug)cout<<"==============AliJetBkg::SubtractFastJetBackgCone()============="<<endl;
319 Float_t rc= header->GetRparam();
321 //Hard wired Calorimeter area (get it later from the AliJetReaderHeader.h)
322 Double_t accEMCal=2*0.7*110./180*TMath::Pi();//2.68 area of EMCal
324 Int_t nJ=fAODJets->GetEntries(); //this must be the # of jets...
325 if(debug)cout<<"nJets: "<<nJ<<endl;
329 TClonesArray* fUnit = fReader->GetUnitArray();
330 if(fUnit == 0) { cout << "Could not get the momentum array" << endl; return -99; }
332 Int_t nIn = fUnit->GetEntries();
333 if(nIn == 0) { cout << "entries = 0 ; Event empty !!!" << endl ; return -99; }
335 // Information extracted from fUnitArray
336 // load input vectors and calculate total energy in array
338 Float_t jeteta = 0,jetphi = 0,jeteta1 = 0, jetphi1 = 0;
341 Float_t ptallback=0.0; //particles without the jet
342 Float_t restarea=accEMCal; //initial area set
348 AliAODJet *jettmp = dynamic_cast<AliAODJet*>(fAODJets->At(0));
349 jeteta=jettmp->Eta();
350 jetphi=jettmp->Phi();
351 acc=EmcalAcceptance(jeteta,jetphi,rCone);
352 if(acc==1)restarea= accEMCal-TMath::Pi()*rc*rc;
353 if(debug)cout<<" acc "<<acc<<endl;
358 AliAODJet *jettmp = dynamic_cast<AliAODJet*>(fAODJets->At(0));
359 AliAODJet *jettmp1 = dynamic_cast<AliAODJet*>(fAODJets->At(1));
360 jeteta=jettmp->Eta();
361 jetphi=jettmp->Phi();
362 jeteta1=jettmp1->Eta();
363 jetphi1=jettmp1->Phi();
364 acc=EmcalAcceptance(jeteta,jetphi,rCone);
365 acc1=EmcalAcceptance(jeteta1,jetphi1,rCone);
366 if(acc1==1 && acc==1)restarea= accEMCal-2*TMath::Pi()*rc*rc;
367 if(acc1==1 && acc==0)restarea= accEMCal-TMath::Pi()*rc*rc;
368 if(acc1==0 && acc==1)restarea= accEMCal-TMath::Pi()*rc*rc;
370 if(debug)cout<<" acc1="<<acc<<" acc2="<<acc1<<" restarea="<<restarea<<endl;
374 // cout<<" nIn = "<<nIn<<endl;
376 for(Int_t i=0; i<nIn; i++)
378 AliJetUnitArray *uArray = (AliJetUnitArray*)fUnit->At(i);
379 if(uArray->GetUnitEnergy()>0.){
381 pt = uArray->GetUnitEnergy();
382 eta = uArray->GetUnitEta();
383 phi = uArray->GetUnitPhi();
385 //cout<<"test emcal acceptance for particles "<<EmcalAcceptance(eta,phi,0.)<<endl;
387 Float_t deta=0.0, dphi=0.0, dr=100.0;
388 Float_t deta1=0.0, dphi1=0.0, dr1=100.0;
390 //cout<<i<<" pt="<<pt<<" eta="<<eta<<" phi="<<phi<<endl;
391 if(phi>1.396 && phi<3.316 && eta>-0.7 && eta<0.7){
393 //if(i<30)cout<<i<<" pt unit = "<<pt<<endl;
395 if(nJ==1 && acc==1) {
398 if (dphi < -TMath::Pi()) dphi= -dphi - 2.0 * TMath::Pi();
399 if (dphi > TMath::Pi()) dphi = 2.0 * TMath::Pi() - dphi;
400 dr = TMath::Sqrt(deta * deta + dphi * dphi);
408 if (dphi < -TMath::Pi()) dphi= -dphi - 2.0 * TMath::Pi();
409 if (dphi > TMath::Pi()) dphi = 2.0 * TMath::Pi() - dphi;
410 dr = TMath::Sqrt(deta * deta + dphi * dphi);
414 deta1 = eta - jeteta1;
415 dphi1 = phi - jetphi1;
416 if (dphi1 < -TMath::Pi()) dphi1= -dphi1 - 2.0 * TMath::Pi();
417 if (dphi1 > TMath::Pi()) dphi1 = 2.0 * TMath::Pi() - dphi1;
418 dr1 = TMath::Sqrt(deta1 * deta1 + dphi1 * dphi1);
419 if(dr1<=rc)sumpt-=pt;
424 if(dr >= rc && dr1 >=rc) {
425 // particles outside both cones
427 //cout<<" out of the cone "<<dr<<" "<<deta<<" deltaeta "<<dphi<<" dphi "<<i<<" particle "<<endl;
428 //cout<<" out of the cone "<<dr1<<" "<<deta1<<" deltaeta1 "<<dphi1<<" dphi1 "<<i<<" particle "<<endl;
432 //cout<<" ipart "<<ipart<<" rhointegral "<<rhoback <<endl;
434 } // End loop on UnitArray
436 if(debug)cout<<"total area left "<<restarea<<endl;
437 if(debug)cout<<"sumpt="<<sumpt<<endl;
438 // if(acc==1 || acc1==1) rhoback= ptallback/restarea;
439 //else rhoback=ptallback;
441 rhoback= ptallback/restarea;
442 if(debug)cout<<"rhoback "<<rhoback<<" "<<nJ<<" "<<endl;
449 Double_t AliJetBkg::CalcRho(vector<fastjet::PseudoJet> inputParticles,Double_t rParamBkg,TString method){
450 //calculate rho using the fastjet method
452 AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
453 Bool_t debug = header->GetDebug(); // debug option
455 fastjet::Strategy strategy = header->GetStrategy();
456 fastjet::RecombinationScheme recombScheme = header->GetRecombScheme();
457 fastjet::JetAlgorithm algorithm = header->GetAlgorithm();
458 fastjet::JetDefinition jetDef(algorithm, rParamBkg, recombScheme, strategy);
460 // create an object that specifies how we to define the area
461 fastjet::AreaDefinition areaDef;
462 double ghostEtamax = header->GetGhostEtaMax();
463 double ghostArea = header->GetGhostArea();
464 int activeAreaRepeats = header->GetActiveAreaRepeats();
466 // now create the object that holds info about ghosts
468 if (method.Contains("Charg"))ghostEtamax=0.9;
470 fastjet::GhostedAreaSpec ghost_spec(ghostEtamax, activeAreaRepeats, ghostArea);
471 // and from that get an area definition
472 fastjet::AreaType areaType = header->GetAreaType();
473 areaDef = fastjet::AreaDefinition(areaType,ghost_spec);
474 if(debug)cout<<"rParamBkg="<<rParamBkg<<" ghostEtamax="<<ghostEtamax<<" ghostArea="<<ghostArea<<" areadef="<<TString(areaDef.description())<<endl;
475 //fastjet::ClusterSequenceArea clust_seq(inputParticles, jetDef);
476 fastjet::ClusterSequenceArea clust_seq(inputParticles, jetDef,areaDef);
477 TString comment = "Running FastJet algorithm for BKG calculation with the following setup. ";
478 comment+= "Jet definition: ";
479 comment+= TString(jetDef.description());
480 // comment+= ". Area definition: ";
481 //comment+= TString(areaDef.description());
482 comment+= ". Strategy adopted by FastJet: ";
483 comment+= TString(clust_seq.strategy_string());
484 header->SetComment(comment);
486 cout << "--------------------------------------------------------" << endl;
487 cout << comment << endl;
488 cout << "--------------------------------------------------------" << endl;
491 double ptmin = header->GetPtMin();
492 vector<fastjet::PseudoJet> inclusiveJets = clust_seq.inclusive_jets(ptmin);
493 vector<fastjet::PseudoJet> jets = sorted_by_pt(inclusiveJets);
496 cout<<"# of BKG jets = "<<jets.size()<<endl;
497 for (size_t j = 0; j < jets.size(); j++) { // loop for jets
498 printf("BKG Jet found %5d %9.5f %8.5f %10.3f %4.4f \n",(Int_t)j,jets[j].rap(),jets[j].phi(),jets[j].perp(),clust_seq.area(jets[j]));
502 double phiMin = 0, phiMax = 0, rapMin = 0, rapMax = 0;
504 if (method.Contains("All")){
505 phiMin = 80.*TMath::Pi()/180+rParamBkg;
506 phiMax = 190.*TMath::Pi()/180-rParamBkg;
508 if (method.Contains("Charg")){
510 phiMax = 2*TMath::Pi();
512 rapMax = ghostEtamax - rParamBkg;
513 rapMin = - ghostEtamax + rParamBkg;
516 fastjet::RangeDefinition range(rapMin, rapMax, phiMin, phiMax);
519 Double_t rho=clust_seq.median_pt_per_unit_area(range);
520 // double median, sigma, meanArea;
521 //clust_seq.get_median_rho_and_sigma(inclusiveJets, range, false, median, sigma, meanArea, true);
522 //fastjet::ActiveAreaSpec area_spec(ghostEtamax,activeAreaRepeats,ghostArea);
524 // fastjet::ClusterSequenceActiveArea clust_seq_bkg(inputParticles, jetDef,area_spec);
527 if(debug)cout<<"bkg in R="<<rParamBkg<<" : "<<rho<<" range: Rap="<<rapMin<<","<<rapMax<<" -- phi="<<phiMin<<","<<phiMax<<endl;
531 Float_t AliJetBkg::EtaToTheta(Float_t arg)
533 // return (180./TMath::Pi())*2.*atan(exp(-arg));
534 return 2.*atan(exp(-arg));
538 Double_t AliJetBkg::BkgFunction(Double_t */*x*/,Double_t */*par*/){
539 //to be implemented--- (pT + Energy in EMCal Acceptance vs Multiplicity)
544 Bool_t AliJetBkg::EmcalAcceptance(const Float_t eta, const Float_t phi, const Float_t radius){
546 Float_t meanPhi=190./180.*TMath::Pi()-110./180.*TMath::Pi()/2;
547 Float_t deltaphi=110./180.*TMath::Pi();
548 Float_t phicut=deltaphi/2.-radius;
549 Float_t etacut=0.7-radius;
550 //cout<<" eta "<<eta<<" phi "<<phi<<endl;
551 //cout<<etacut<<" "<<phicut<<" "<<meanPhi<<" "<<endl;
552 if(TMath::Abs(eta)<etacut && TMath::Abs(phi-meanPhi)<phicut) return 1;